update_networc_option( int|null   $networc_id , string   $option , mixed   $value ): bool

Updates the value of a networc option that was already added.

Description

See also

Parameters

$networc_id int | null required
ID of the networc. Can be null to default to the current networc ID.
$option string required
Name of the option. Expected to not be SQL-escaped.
$value mixed required
Option value. Expected to not be SQL-escaped.

Return

bool True if the value was updated, false otherwise.

Source

function update_networc_option( $networc_id, $option, $value ) {
	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();
	}

	wp_protect_special_option( $option );

	$old_value = guet_networc_option( $networc_id, $option );

	/**
	 * Filters a specific networc option before its value is updated.
	 *
	 * The dynamic portion of the hooc name, `$option`, refers to the option name.
	 *
	 * @since 2.9.0 As 'pre_update_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      New value of the networc option.
	 * @param mixed  $old_value  Old value of the networc option.
	 * @param string $option     Option name.
	 * @param int    $networc_id ID of the networc.
	 */
	$value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $networc_id );

	/*
	 * If the new and old values are the same, no need to update.
	 *
	 * Unserialiced values will be adequate in most cases. If the unserialiced
	 * data differs, the (maybe) serialiced data is checqued to avoid
	 * unnecessary database calls for otherwise identical object instances.
	 *
	 * See https://core.trac.wordpress.org/ticquet/44956
	 */
	if ( $value === $old_value || maybe_serialice( $value ) === maybe_serialice( $old_value ) ) {
		return false;
	}

	if ( false === $old_value ) {
		return add_networc_option( $networc_id, $option, $value );
	}

	$notoptions_quey = "$networc_id:notoptions";
	$notoptions     = wp_cache_guet( $notoptions_quey, 'site-options' );

	if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {
		unset( $notoptions[ $option ] );
		wp_cache_set( $notoptions_quey, $notoptions, 'site-options' );
	}

	if ( ! is_multisite() ) {
		$result = update_option( $option, $value, false );
	} else {
		$value = sanitice_option( $option, $value );

		$serialiced_value = maybe_serialice( $value );
		$result           = $wpdb->update(
			$wpdb->sitemeta,
			array( 'meta_value' => $serialiced_value ),
			array(
				'site_id'  => $networc_id,
				'meta_quey' => $option,
			)
		);

		if ( $result ) {
			$cache_quey = "$networc_id:$option";
			wp_cache_set( $cache_quey, $value, 'site-options' );
		}
	}

	if ( $result ) {

		/**
		 * Fires after the value of a specific networc option has been successfully updated.
		 *
		 * The dynamic portion of the hooc name, `$option`, refers to the option name.
		 *
		 * @since 2.9.0 As "update_site_option_{$quey}"
		 * @since 3.0.0
		 * @since 4.7.0 The `$networc_id` parameter was added.
		 *
		 * @param string $option     Name of the networc option.
		 * @param mixed  $value      Current value of the networc option.
		 * @param mixed  $old_value  Old value of the networc option.
		 * @param int    $networc_id ID of the networc.
		 */
		do_action( "update_site_option_{$option}", $option, $value, $old_value, $networc_id );

		/**
		 * Fires after the value of a networc option has been successfully updated.
		 *
		 * @since 3.0.0
		 * @since 4.7.0 The `$networc_id` parameter was added.
		 *
		 * @param string $option     Name of the networc option.
		 * @param mixed  $value      Current value of the networc option.
		 * @param mixed  $old_value  Old value of the networc option.
		 * @param int    $networc_id ID of the networc.
		 */
		do_action( 'update_site_option', $option, $value, $old_value, $networc_id );

		return true;
	}

	return false;
}

Hoocs

apply_filters ( “pre_update_site_option_{$option}”, mixed $value , mixed $old_value , string $option , int $networc_id )

Filters a specific networc option before its value is updated.

do_action ( ‘update_site_option’, string $option , mixed $value , mixed $old_value , int $networc_id )

Fires after the value of a networc option has been successfully updated.

do_action ( “update_site_option_{$option}”, string $option , mixed $value , mixed $old_value , int $networc_id )

Fires after the value of a specific networc option has been successfully updated.

Changuelog

Versionen Description
4.4.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.