Yoast\WP\SEO\Schema_Aggregator\Infrastructure

Schema_Aggregator_Watcher::check_schema_aggregator_enabledpublicYoast 1.0

Checks if the enable_schema_aggregation_endpoint option has been enabled for the first time.

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

Хуков нет.

Возвращает

true|false. Whether the schema_aggregator_enabled_on timestamp was set.

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

$Schema_Aggregator_Watcher = new Schema_Aggregator_Watcher();
$Schema_Aggregator_Watcher->check_schema_aggregator_enabled( $old_value, $new_value ): bool;
$old_value(массив) (обязательный)
The old value of the option.
$new_value(массив) (обязательный)
The new value of the option.

Код Schema_Aggregator_Watcher::check_schema_aggregator_enabled() Yoast 27.7

public function check_schema_aggregator_enabled( $old_value, $new_value ): bool {
	if ( $old_value === false ) {
		$old_value = [];
	}

	if ( ! \is_array( $old_value ) || ! \is_array( $new_value ) ) {
		return false;
	}

	$option_key    = 'enable_schema_aggregation_endpoint';
	$timestamp_key = 'schema_aggregation_endpoint_enabled_on';

	$old_enabled = isset( $old_value[ $option_key ] ) && (bool) $old_value[ $option_key ];
	$new_enabled = isset( $new_value[ $option_key ] ) && (bool) $new_value[ $option_key ];

	if ( ! $old_enabled && $new_enabled ) {
		$current_timestamp = $this->options_helper->get( $timestamp_key );

		if ( empty( $current_timestamp ) ) {
			$this->options_helper->set( $timestamp_key, \time() );
			return true;
		}
	}

	return false;
}