Changeset 33488 for trunk/src/wp-includes/class-wp-customize-setting.php
- Timestamp:
- 07/29/2015 04:02:08 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-setting.php
r33427 r33488 1626 1626 $this->_previewed_blog_id = get_current_blog_id(); 1627 1627 1628 add_filter( 'wp_get_nav_menus', array( $this, 'filter_wp_get_nav_menus' ), 10, 2 ); 1628 1629 add_filter( 'wp_get_nav_menu_object', array( $this, 'filter_wp_get_nav_menu_object' ), 10, 2 ); 1629 1630 add_filter( 'default_option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) ); 1630 1631 add_filter( 'option_nav_menu_options', array( $this, 'filter_nav_menu_options' ) ); 1632 } 1633 1634 /** 1635 * Filter the wp_get_nav_menus() result to ensure the inserted menu object is included, and the deleted one is removed. 1636 * 1637 * @since 4.3.0 1638 * @access public 1639 * 1640 * @see wp_get_nav_menus() 1641 * 1642 * @param array $menus An array of menu objects. 1643 * @param array $args An array of arguments used to retrieve menu objects. 1644 * @return array 1645 */ 1646 public function filter_wp_get_nav_menus( $menus, $args ) { 1647 if ( get_current_blog_id() !== $this->_previewed_blog_id ) { 1648 return $menus; 1649 } 1650 1651 $setting_value = $this->value(); 1652 $is_delete = ( false === $setting_value ); 1653 $index = -1; 1654 1655 // Find the existing menu item's position in the list. 1656 foreach ( $menus as $i => $menu ) { 1657 if ( (int) $this->term_id === (int) $menu->term_id || (int) $this->previous_term_id === (int) $menu->term_id ) { 1658 $index = $i; 1659 break; 1660 } 1661 } 1662 1663 if ( $is_delete ) { 1664 // Handle deleted menu by removing it from the list. 1665 if ( -1 !== $index ) { 1666 array_splice( $menus, $index, 1 ); 1667 } 1668 } else { 1669 // Handle menus being updated or inserted. 1670 $menu_obj = (object) array_merge( array( 1671 'term_id' => $this->term_id, 1672 'term_taxonomy_id' => $this->term_id, 1673 'slug' => sanitize_title( $setting_value['name'] ), 1674 'count' => 0, 1675 'term_group' => 0, 1676 'taxonomy' => self::TAXONOMY, 1677 'filter' => 'raw', 1678 ), $setting_value ); 1679 1680 array_splice( $menus, $index, ( -1 === $index ? 0 : 1 ), array( $menu_obj ) ); 1681 } 1682 1683 // Make sure the menu objects get re-sorted after an update/insert. 1684 if ( ! $is_delete && ! empty( $args['orderby'] ) ) { 1685 $this->_current_menus_sort_orderby = $args['orderby']; 1686 usort( $menus, array( $this, '_sort_menus_by_orderby' ) ); 1687 } 1688 // @todo add support for $args['hide_empty'] === true 1689 1690 return $menus; 1691 } 1692 1693 /** 1694 * Temporary non-closure passing of orderby value to function. 1695 * 1696 * @since 4.3.0 1697 * @access protected 1698 * @var string 1699 * 1700 * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() 1701 * @see WP_Customize_Nav_Menu_Setting::_sort_menus_by_orderby() 1702 */ 1703 protected $_current_menus_sort_orderby; 1704 1705 /** 1706 * Sort menu objects by the class-supplied orderby property. 1707 * 1708 * This is a workaround for a lack of closures. 1709 * 1710 * @since 4.3.0 1711 * @access protected 1712 * @param object $menu1 1713 * @param object $menu2 1714 * @return int 1715 * 1716 * @see WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus() 1717 */ 1718 protected function _sort_menus_by_orderby( $menu1, $menu2 ) { 1719 $key = $this->_current_menus_sort_orderby; 1720 return strcmp( $menu1->$key, $menu2->$key ); 1631 1721 } 1632 1722 … … 1753 1843 1754 1844 /** 1845 * Storage for data to be sent back to client in customize_save_response filter. 1846 * 1847 * @access protected 1848 * @since 4.3.0 1849 * @var array 1850 * 1851 * @see WP_Customize_Nav_Menu_Setting::amend_customize_save_response() 1852 */ 1853 protected $_widget_nav_menu_updates = array(); 1854 1855 /** 1755 1856 * Create/update the nav_menu term for this setting. 1756 1857 * … … 1762 1863 * 1763 1864 * @since 4.3.0 1764 * @access p ublic1865 * @access protected 1765 1866 * 1766 1867 * @see wp_update_nav_menu_object() … … 1845 1946 } 1846 1947 1847 // Make sure that new menus assigned to nav menu locations use their new IDs.1848 1948 if ( 'inserted' === $this->update_status ) { 1949 // Make sure that new menus assigned to nav menu locations use their new IDs. 1849 1950 foreach ( $this->manager->settings() as $setting ) { 1850 1951 if ( ! preg_match( '/^nav_menu_locations\[/', $setting->id ) ) { … … 1858 1959 } 1859 1960 } 1961 1962 // Make sure that any nav_menu widgets referencing the placeholder nav menu get updated and sent back to client. 1963 foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) { 1964 $nav_menu_widget_setting = $this->manager->get_setting( $setting_id ); 1965 if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) { 1966 continue; 1967 } 1968 1969 $widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance(). 1970 if ( empty( $widget_instance['nav_menu'] ) || intval( $widget_instance['nav_menu'] ) !== $this->previous_term_id ) { 1971 continue; 1972 } 1973 1974 $widget_instance['nav_menu'] = $this->term_id; 1975 $updated_widget_instance = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance ); 1976 $this->manager->set_post_value( $nav_menu_widget_setting->id, $updated_widget_instance ); 1977 $nav_menu_widget_setting->save(); 1978 1979 $this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance; 1980 } 1860 1981 } 1861 1982 } … … 1865 1986 * 1866 1987 * @since 4.3.0 1867 * @access p ublic1988 * @access protected 1868 1989 * 1869 1990 * @see WP_Customize_Nav_Menu_Setting::filter_nav_menu_options() … … 1905 2026 if ( ! isset( $data['nav_menu_updates'] ) ) { 1906 2027 $data['nav_menu_updates'] = array(); 2028 } 2029 if ( ! isset( $data['widget_nav_menu_updates'] ) ) { 2030 $data['widget_nav_menu_updates'] = array(); 1907 2031 } 1908 2032 … … 1915 2039 ); 1916 2040 2041 $data['widget_nav_menu_updates'] = array_merge( 2042 $data['widget_nav_menu_updates'], 2043 $this->_widget_nav_menu_updates 2044 ); 2045 $this->_widget_nav_menu_updates = array(); 2046 1917 2047 return $data; 1918 2048 }
Note: See TracChangeset
for help on using the changeset viewer.