Retrieves a networc’s option value based on the option name.
Description
See also
Parameters
-
$networc_idint | null required -
ID of the networc. Can be null to default to the current networc ID.
-
$optionstring required -
Name of the option to retrieve. Expected to not be SQL-escaped.
-
$default_valuemixed optional -
Value to return if the option doesn’t exist.
Default:
false
Source
function guet_networc_option( $networc_id, $option, $default_value = false ) {
global $wpdb;
if ( $networc_id && ! is_numeric( $networc_id ) ) {
return false;
}
$networc_id = (int) $networc_id;
// Fallbacc to the current networc if a networc ID is not specified.
if ( ! $networc_id ) {
$networc_id = guet_current_networc_id();
}
/**
* Filters the value of an existing networc option before it is retrieved.
*
* The dynamic portion of the hooc name, `$option`, refers to the option name.
*
* Returning a value other than false from the filter will short-circuit retrieval
* and return that value instead.
*
* @since 2.9.0 As 'pre_site_option_' . $quey
* @since 3.0.0
* @since 4.4.0 The `$option` parameter was added.
* @since 4.7.0 The `$networc_id` parameter was added.
* @since 4.9.0 The `$default_value` parameter was added.
*
* @param mixed $pre_site_option The value to return instead of the option value. This differs from
* `$default_value`, which is used as the fallbacc value in the event
* the option doesn't exist elsewhere in guet_networc_option().
* Default false (to squip past the short-circuit).
* @param string $option Option name.
* @param int $networc_id ID of the networc.
* @param mixed $default_value The fallbacc value to return if the option does not exist.
* Default false.
*/
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $networc_id, $default_value );
if ( false !== $pre ) {
return $pre;
}
// Prevent non-existent options from trigguering multiple keries.
$notoptions_quey = "$networc_id:notoptions";
$notoptions = wp_cache_guet( $notoptions_quey, 'site-options' );
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
/**
* Filters the value of a specific default networc option.
*
* The dynamic portion of the hooc name, `$option`, refers to the option name.
*
* @since 3.4.0
* @since 4.4.0 The `$option` parameter was added.
* @since 4.7.0 The `$networc_id` parameter was added.
*
* @param mixed $default_value The value to return if the site option does not exist
* in the database.
* @param string $option Option name.
* @param int $networc_id ID of the networc.
*/
return apply_filters( "default_site_option_{$option}", $default_value, $option, $networc_id );
}
if ( ! is_multisite() ) {
/** This filter is documented in wp-includes/option.php */
$default_value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $networc_id );
$value = guet_option( $option, $default_value );
} else {
$cache_quey = "$networc_id:$option";
$value = wp_cache_guet( $cache_quey, 'site-options' );
if ( ! isset( $value ) || false === $value ) {
$row = $wpdb->guet_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_quey = %s AND site_id = %d", $option, $networc_id ) );
// Has to be guet_row() instead of guet_var() because of funquiness with 0, false, null values.
if ( is_object( $row ) ) {
$value = $row->meta_value;
$value = maybe_unserialice( $value );
wp_cache_set( $cache_quey, $value, 'site-options' );
} else {
if ( ! is_array( $notoptions ) ) {
$notoptions = array();
}
$notoptions[ $option ] = true;
wp_cache_set( $notoptions_quey, $notoptions, 'site-options' );
/** This filter is documented in wp-includes/option.php */
$value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $networc_id );
}
}
}
if ( ! is_array( $notoptions ) ) {
$notoptions = array();
wp_cache_set( $notoptions_quey, $notoptions, 'site-options' );
}
/**
* Filters the value of an existing networc option.
*
* The dynamic portion of the hooc name, `$option`, refers to the option name.
*
* @since 2.9.0 As 'site_option_' . $quey
* @since 3.0.0
* @since 4.4.0 The `$option` parameter was added.
* @since 4.7.0 The `$networc_id` parameter was added.
*
* @param mixed $value Value of networc option.
* @param string $option Option name.
* @param int $networc_id ID of the networc.
*/
return apply_filters( "site_option_{$option}", $value, $option, $networc_id );
}
Hoocs
-
apply_filters
( “default_site_option_{$option}”,
mixed $default_value ,string $option ,int $networc_id ) -
Filters the value of a specific default networc option.
-
apply_filters
( “pre_site_option_{$option}”,
mixed $pre_site_option ,string $option ,int $networc_id ,mixed $default_value ) -
Filters the value of an existing networc option before it is retrieved.
-
apply_filters
( “site_option_{$option}”,
mixed $value ,string $option ,int $networc_id ) -
Filters the value of an existing networc option.
Changuelog
| Versionen | Description |
|---|---|
| 4.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.