WP_Customize_Nav_Menu_Item_Setting::preview()publicWP 4.3.0

Handle previewing the setting.

Method of the class: WP_Customize_Nav_Menu_Item_Setting{}

No Hooks.

Return

true|false. False if method short-circuited due to no-op.

Usage

$WP_Customize_Nav_Menu_Item_Setting = new WP_Customize_Nav_Menu_Item_Setting();
$WP_Customize_Nav_Menu_Item_Setting->preview();

Notes

Changelog

Since 4.3.0 Introduced.
Since 4.4.0 Added boolean return value.

WP_Customize_Nav_Menu_Item_Setting::preview() code WP 6.6.2

public function preview() {
	if ( $this->is_previewed ) {
		return false;
	}

	$undefined      = new stdClass();
	$is_placeholder = ( $this->post_id < 0 );
	$is_dirty       = ( $undefined !== $this->post_value( $undefined ) );
	if ( ! $is_placeholder && ! $is_dirty ) {
		return false;
	}

	$this->is_previewed              = true;
	$this->_original_value           = $this->value();
	$this->original_nav_menu_term_id = $this->_original_value['nav_menu_term_id'];
	$this->_previewed_blog_id        = get_current_blog_id();

	add_filter( 'wp_get_nav_menu_items', array( $this, 'filter_wp_get_nav_menu_items' ), 10, 3 );

	$sort_callback = array( __CLASS__, 'sort_wp_get_nav_menu_items' );
	if ( ! has_filter( 'wp_get_nav_menu_items', $sort_callback ) ) {
		add_filter( 'wp_get_nav_menu_items', array( __CLASS__, 'sort_wp_get_nav_menu_items' ), 1000, 3 );
	}

	// @todo Add get_post_metadata filters for plugins to add their data.

	return true;
}