WP_Customize_Nav_Menu_Item_Setting::__construct()publicWP 4.3.0

Constructor.

Any supplied $args override class property defaults.

Method of the class: WP_Customize_Nav_Menu_Item_Setting{}

No Hooks.

Return

null. Nothing (null).

Usage

$WP_Customize_Nav_Menu_Item_Setting = new WP_Customize_Nav_Menu_Item_Setting();
$WP_Customize_Nav_Menu_Item_Setting->__construct( $manager, $id, $args );
$manager(WP_Customize_Manager) (required)
Customizer bootstrap instance.
$id(string) (required)
A specific ID of the setting. Can be a theme mod or option name.
$args(array)
Setting arguments.
Default: array()

Changelog

Since 4.3.0 Introduced.

WP_Customize_Nav_Menu_Item_Setting::__construct() code WP 6.6.2

public function __construct( WP_Customize_Manager $manager, $id, array $args = array() ) {
	if ( empty( $manager->nav_menus ) ) {
		throw new Exception( 'Expected WP_Customize_Manager::$nav_menus to be set.' );
	}

	if ( ! preg_match( self::ID_PATTERN, $id, $matches ) ) {
		throw new Exception( "Illegal widget setting ID: $id" );
	}

	$this->post_id = (int) $matches['id'];
	add_action( 'wp_update_nav_menu_item', array( $this, 'flush_cached_value' ), 10, 2 );

	parent::__construct( $manager, $id, $args );

	// Ensure that an initially-supplied value is valid.
	if ( isset( $this->value ) ) {
		$this->populate_value();
		foreach ( array_diff( array_keys( $this->default ), array_keys( $this->value ) ) as $missing ) {
			throw new Exception( "Supplied nav_menu_item value missing property: $missing" );
		}
	}
}