GC_Customize_Nav_Menus::filter_gc_nav_menu_args()
最后更新于:2021-11-27 04:14:09
GC_Customize_Nav_Menus::filter_gc_nav_menu_args( array$args)Keep track of the arguments that are being passed to gc_nav_menu().
参数
- $args
-
(array) (Required) An array containing gc_nav_menu() arguments.
响应
(array) Arguments.
源文件
文件: gc-includes/class-gc-customize-nav-menus.php
public function filter_gc_nav_menu_args( $args ) {
/*
* The following conditions determine whether or not this instance of
* gc_nav_menu() can use selective refreshed. A gc_nav_menu() can be
* selective refreshed if...
*/
$can_partial_refresh = (
// ...if gc_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated),
! empty( $args['echo'] )
&&
// ...and if the fallback_cb can be serialized to JSON, since it will be included in the placement context data,
( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) )
&&
// ...and if the walker can also be serialized to JSON, since it will be included in the placement context data as well,
( empty( $args['walker'] ) || is_string( $args['walker'] ) )
// ...and if it has a theme location assigned or an assigned menu to display,
&& (
! empty( $args['theme_location'] )
||
( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) )
)
&&
// ...and if the nav menu would be rendered with a wrapper container element (upon which to attach data-* attributes).
(
! empty( $args['container'] )
||
( isset( $args['items_wrap'] ) && '<' === substr( $args['items_wrap'], 0, 1 ) )
)
);
$args['can_partial_refresh'] = $can_partial_refresh;
$exported_args = $args;
// Empty out args which may not be JSON-serializable.
if ( ! $can_partial_refresh ) {
$exported_args['fallback_cb'] = '';
$exported_args['walker'] = '';
}
/*
* Replace object menu arg with a term_id menu arg, as this exports better
* to JS and is easier to compare hashes.
*/
if ( ! empty( $exported_args['menu'] ) && is_object( $exported_args['menu'] ) ) {
$exported_args['menu'] = $exported_args['menu']->term_id;
}
ksort( $exported_args );
$exported_args['args_hmac'] = $this->hash_nav_menu_args( $exported_args );
$args['customize_preview_nav_menus_args'] = $exported_args;
$this->preview_nav_menu_instance_args[ $exported_args['args_hmac'] ] = $exported_args;
return $args;
}