Yoast_Network_Admin::handle_update_options_request()publicYoast 1.0

Handles a request to update plugin network options.

This method works similar to how option updates are handled in wp-admin/options.php and wp-admin/network/settings.php.

Метод класса: Yoast_Network_Admin{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$Yoast_Network_Admin = new Yoast_Network_Admin();
$Yoast_Network_Admin->handle_update_options_request();

Код Yoast_Network_Admin::handle_update_options_request() Yoast 22.4

public function handle_update_options_request() {
	// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: Nonce verification will happen in verify_request below.
	if ( ! isset( $_POST['network_option_group'] ) || ! is_string( $_POST['network_option_group'] ) ) {
		return;
	}

	// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: Nonce verification will happen in verify_request below.
	$option_group = sanitize_text_field( wp_unslash( $_POST['network_option_group'] ) );

	if ( empty( $option_group ) ) {
		return;
	}

	$this->verify_request( "{$option_group}-network-options" );

	$whitelist_options = Yoast_Network_Settings_API::get()->get_whitelist_options( $option_group );

	if ( empty( $whitelist_options ) ) {
		add_settings_error( $option_group, 'settings_updated', __( 'You are not allowed to modify unregistered network settings.', 'wordpress-seo' ), 'error' );

		$this->terminate_request();
		return;
	}

	// phpcs:disable WordPress.Security.NonceVerification -- Nonce verified via `verify_request()` above.
	foreach ( $whitelist_options as $option_name ) {
		$value = null;
		if ( isset( $_POST[ $option_name ] ) ) {
			// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: Adding sanitize_text_field around this will break the saving of settings because it expects a string: https://github.com/Yoast/wordpress-seo/issues/12440.
			$value = wp_unslash( $_POST[ $option_name ] );
		}

		WPSEO_Options::update_site_option( $option_name, $value );
	}
	// phpcs:enable WordPress.Security.NonceVerification

	$settings_errors = get_settings_errors();
	if ( empty( $settings_errors ) ) {
		add_settings_error( $option_group, 'settings_updated', __( 'Settings Updated.', 'wordpress-seo' ), 'updated' );
	}

	$this->terminate_request();
}