WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
класс не описан

Yoast_Feature_Toggle{} Yoast 1.0

Class representing a feature toggle.

Хуков нет.

Возвращает

Null. Ничего.

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

$Yoast_Feature_Toggle = new Yoast_Feature_Toggle();
// use class methods

Методы

  1. __construct( array $args )
  2. __get( $key )
  3. __isset( $key )
  4. is_enabled()

Код Yoast_Feature_Toggle{} Yoast 15.1.1

<?php
class Yoast_Feature_Toggle {

	/**
	 * Feature toggle identifier.
	 *
	 * @var string
	 */
	protected $name = '';

	/**
	 * Name of the setting the feature toggle is associated with.
	 *
	 * @var string
	 */
	protected $setting = '';

	/**
	 * Feature toggle label.
	 *
	 * @var string
	 */
	protected $label = '';

	/**
	 * URL to learn more about the feature.
	 *
	 * @var string
	 */
	protected $read_more_url = '';

	/**
	 * Label for the learn more link.
	 *
	 * @var string
	 */
	protected $read_more_label = '';

	/**
	 * Additional help content for the feature.
	 *
	 * @var string
	 */
	protected $extra = '';

	/**
	 * Additional content to be rendered after the toggle.
	 *
	 * @var string
	 */
	protected $after = '';

	/**
	 * Value to specify the feature toggle order.
	 *
	 * @var string
	 */
	protected $order = 100;

	/**
	 * Constructor.
	 *
	 * Sets the feature toggle arguments.
	 *
	 * @param array $args {
	 *     Feature toggle arguments.
	 *
	 *     @type string $name            Required. Feature toggle identifier.
	 *     @type string $setting         Required. Name of the setting the feature toggle is associated with.
	 *     @type string $label           Required. Feature toggle label.
	 *     @type string $read_more_url   URL to learn more about the feature. Default empty string.
	 *     @type string $read_more_label Label for the learn more link. Default empty string.
	 *     @type string $extra           Additional help content for the feature. Default empty string.
	 *     @type int    $order           Value to specify the feature toggle order. A lower value indicates
	 *                                   a higher priority. Default 100.
	 * }
	 *
	 * @throws InvalidArgumentException Thrown when a required argument is missing.
	 */
	public function __construct( array $args ) {
		$required_keys = [ 'name', 'setting', 'label' ];

		foreach ( $required_keys as $key ) {
			if ( empty( $args[ $key ] ) ) {
				/* translators: %s: argument name */
				throw new InvalidArgumentException( sprintf( __( '%s is a required feature toggle argument.', 'wordpress-seo' ), $key ) );
			}
		}

		foreach ( $args as $key => $value ) {
			if ( property_exists( $this, $key ) ) {
				$this->$key = $value;
			}
		}
	}

	/**
	 * Magic isset-er.
	 *
	 * @param string $key Key to check whether a value for it is set.
	 *
	 * @return bool True if set, false otherwise.
	 */
	public function __isset( $key ) {
		return isset( $this->$key );
	}

	/**
	 * Magic getter.
	 *
	 * @param string $key Key to get the value for.
	 *
	 * @return mixed Value for the key, or null if not set.
	 */
	public function __get( $key ) {
		if ( isset( $this->$key ) ) {
			return $this->$key;
		}

		return null;
	}

	/**
	 * Checks whether the feature for this toggle is enabled.
	 *
	 * @return bool True if the feature is enabled, false otherwise.
	 */
	public function is_enabled() {
		return (bool) WPSEO_Options::get( $this->setting );
	}
}