Changeset 36889 for trunk/src/wp-includes/class-wp-customize-nav-menus.php
- Timestamp:
- 03/09/2016 12:08:51 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r36836 r36889 823 823 824 824 /** 825 * Nav menu args used for each instance, keyed by the args HMAC. 826 * 827 * @since 4.3.0 828 * @access public 829 * @var array 830 */ 831 public $preview_nav_menu_instance_args = array(); 832 833 /** 825 834 * Filter arguments for dynamic nav_menu selective refresh partials. 826 835 * … … 863 872 add_filter( 'wp_nav_menu_args', array( $this, 'filter_wp_nav_menu_args' ), 1000 ); 864 873 add_filter( 'wp_nav_menu', array( $this, 'filter_wp_nav_menu' ), 10, 2 ); 874 add_filter( 'wp_footer', array( $this, 'export_preview_data' ), 1 ); 875 add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) ); 865 876 } 866 877 … … 882 893 * selective refreshed if... 883 894 */ 884 $can_ selective_refresh = (895 $can_partial_refresh = ( 885 896 // ...if wp_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated), 886 897 ! empty( $args['echo'] ) … … 905 916 ) 906 917 ); 907 908 if ( ! $can_selective_refresh ) { 909 return $args; 910 } 918 $args['can_partial_refresh'] = $can_partial_refresh; 911 919 912 920 $exported_args = $args; 921 922 // Empty out args which may not be JSON-serializable. 923 if ( ! $can_partial_refresh ) { 924 $exported_args['fallback_cb'] = ''; 925 $exported_args['walker'] = ''; 926 } 913 927 914 928 /* … … 924 938 925 939 $args['customize_preview_nav_menus_args'] = $exported_args; 926 940 $this->preview_nav_menu_instance_args[ $exported_args['args_hmac'] ] = $exported_args; 927 941 return $args; 928 942 } … … 943 957 */ 944 958 public function filter_wp_nav_menu( $nav_menu_content, $args ) { 945 if ( ! empty( $args->customize_preview_nav_menus_args )) {959 if ( isset( $args->customize_preview_nav_menus_args['can_partial_refresh'] ) && $args->customize_preview_nav_menus_args['can_partial_refresh'] ) { 946 960 $attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ); 947 961 $attributes .= ' data-customize-partial-type="nav_menu_instance"'; … … 988 1002 * 989 1003 * @since 4.3.0 990 * @deprecated 4.5.0 Obsolete991 1004 * @access public 992 1005 */ 993 1006 public function export_preview_data() { 994 _deprecated_function( __METHOD__, '4.5.0' ); 1007 1008 // Why not wp_localize_script? Because we're not localizing, and it forces values into strings. 1009 $exports = array( 1010 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, 1011 ); 1012 printf( '<script>var _wpCustomizePreviewNavMenusExports = %s;</script>', wp_json_encode( $exports ) ); 1013 } 1014 1015 /** 1016 * Export any wp_nav_menu() calls during the rendering of any partials. 1017 * 1018 * @since 4.5.0 1019 * @access public 1020 * 1021 * @param array $response Response. 1022 * @return array Response. 1023 */ 1024 public function export_partial_rendered_nav_menu_instances( $response ) { 1025 $response['nav_menu_instance_args'] = $this->preview_nav_menu_instance_args; 1026 return $response; 995 1027 } 996 1028
Note: See TracChangeset
for help on using the changeset viewer.