WP_Customize_Nav_Menu_Item_Setting::populate_value() WordPress Method
The WP_Customize_Nav_Menu_Item_Setting::populate_value() is a method used in the WordPress Customizer to populate the value of a given setting. This particular method is used specifically for nav menu item settings. In order to understand how this method works, it is first necessary to understand how the Customizer works. The Customizer is a tool that allows users to change certain aspects of their WordPress site. It is possible to change things like the site's title, tagline, and colors. The Customizer works by first retrieving a list of all the settings that are available to be changed. It then goes through each setting and retrieves the current value for that setting. Finally, it applies the changes that the user has made to the site. The WP_Customize_Nav_Menu_Item_Setting::populate_value() method is used to populate the value of a nav menu item setting. This method is called when the Customizer is first loaded. It is responsible for retrieving the current value of the setting and storing it in the $value property. Once the $value property has been populated, the Customizer can then use that value to apply the changes that the user has made.
WP_Customize_Nav_Menu_Item_Setting::populate_value() #
Ensure that the value is fully populated with the necessary properties.
Description
Translates some properties added by wp_setup_nav_menu_item() and removes others.
See also
Source
File: wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
protected function populate_value() { if ( ! is_array( $this->value ) ) { return; } if ( isset( $this->value['menu_order'] ) ) { $this->value['position'] = $this->value['menu_order']; unset( $this->value['menu_order'] ); } if ( isset( $this->value['post_status'] ) ) { $this->value['status'] = $this->value['post_status']; unset( $this->value['post_status'] ); } if ( ! isset( $this->value['original_title'] ) ) { $this->value['original_title'] = $this->get_original_title( (object) $this->value ); } if ( ! isset( $this->value['nav_menu_term_id'] ) && $this->post_id > 0 ) { $menus = wp_get_post_terms( $this->post_id, WP_Customize_Nav_Menu_Setting::TAXONOMY, array( 'fields' => 'ids', ) ); if ( ! empty( $menus ) ) { $this->value['nav_menu_term_id'] = array_shift( $menus ); } else { $this->value['nav_menu_term_id'] = 0; } } foreach ( array( 'object_id', 'menu_item_parent', 'nav_menu_term_id' ) as $key ) { if ( ! is_int( $this->value[ $key ] ) ) { $this->value[ $key ] = (int) $this->value[ $key ]; } } foreach ( array( 'classes', 'xfn' ) as $key ) { if ( is_array( $this->value[ $key ] ) ) { $this->value[ $key ] = implode( ' ', $this->value[ $key ] ); } } if ( ! isset( $this->value['title'] ) ) { $this->value['title'] = ''; } if ( ! isset( $this->value['_invalid'] ) ) { $this->value['_invalid'] = false; $is_known_invalid = ( ( ( 'post_type' === $this->value['type'] || 'post_type_archive' === $this->value['type'] ) && ! post_type_exists( $this->value['object'] ) ) || ( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) ) ); if ( $is_known_invalid ) { $this->value['_invalid'] = true; } } // Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value. $irrelevant_properties = array( 'ID', 'comment_count', 'comment_status', 'db_id', 'filter', 'guid', 'ping_status', 'pinged', 'post_author', 'post_content', 'post_content_filtered', 'post_date', 'post_date_gmt', 'post_excerpt', 'post_mime_type', 'post_modified', 'post_modified_gmt', 'post_name', 'post_parent', 'post_password', 'post_title', 'post_type', 'to_ping', ); foreach ( $irrelevant_properties as $property ) { unset( $this->value[ $property ] ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.3.0 | Introduced. |