Yoast\WP\SEO\Abilities\Application

Feature_Status_Updater::set_status │ public │ Yoast 1.0

Enables or disables the feature behind the given option and returns its new status.

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

Хуков нет.

Возвращает

array<string, bool>|WP_Error. The new status, or an error when the input is invalid or the status could not be saved.

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

$Feature_Status_Updater = new Feature_Status_Updater();
$Feature_Status_Updater->set_status( $option_name, $input );
$option_name(строка) (обязательный)
The name of the boolean option that enables the feature.
$input(array<string, bool>) (обязательный)
The input holding the desired enabled status.

Код Feature_Status_Updater::set_status() Yoast 28.8

public function set_status( string $option_name, array $input ) {
	if ( ! isset( $input['enabled'] ) || ! \is_bool( $input['enabled'] ) ) {
		return new WP_Error(
			'yoast_seo_feature_status_invalid_input',
			\__( 'The enabled status is required and must be a boolean.', 'wordpress-seo' ),
			[ 'status' => 400 ],
		);
	}

	$enabled = $input['enabled'];

	if ( $this->options_helper->set( $option_name, $enabled ) !== true ) {
		return new WP_Error(
			'yoast_seo_feature_status_not_saved',
			\__( 'The feature status could not be saved.', 'wordpress-seo' ),
			[ 'status' => 500 ],
		);
	}

	return [ 'enabled' => $enabled ];
}