WP_Customize_Control::active() WordPress Method

The WP_Customize_Control::active() method is used to determine whether a Customizer control is currently active. This is useful when you want to know whether a particular setting is currently being previewed in the Customizer. For example, if you have a theme with a light and dark color scheme, you could use this method to switch between the two schemes based on the active setting. To use this method, simply pass in the name of the setting you want to check. The method will return true if the setting is currently active, or false if it is not. This method is particularly useful for Customizer controls that have multiple settings. For example, if you have a control with a light and dark color scheme, you could use this method to determine which scheme is currently active.

WP_Customize_Control::active() #

Check whether control is active to current Customizer preview.


Return

(bool) Whether the control is active to the current preview.


Top ↑

Source

File: wp-includes/class-wp-customize-control.php

	final public function active() {
		$control = $this;
		$active  = call_user_func( $this->active_callback, $this );

		/**
		 * Filters response of WP_Customize_Control::active().
		 *
		 * @since 4.0.0
		 *
		 * @param bool                 $active  Whether the Customizer control is active.
		 * @param WP_Customize_Control $control WP_Customize_Control instance.
		 */
		$active = apply_filters( 'customize_control_active', $active, $control );

		return $active;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.