On this page
wp_admin_bar_customize_menu( WP_Admin_Bar $wp_admin_bar )
Adds the “Customize” link to the Toolbar.
Parameters
$wp_admin_barWP_Admin_Bar Required-
The WP_Admin_Bar instance.
Source
File: wp-includes/admin-bar.php. View all references
function wp_admin_bar_customize_menu( $wp_admin_bar ) {
global $wp_customize;
// Don't show if a block theme is activated and no plugins use the customizer.
if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) {
return;
}
// Don't show for users who can't access the customizer or when in the admin.
if ( ! current_user_can( 'customize' ) || is_admin() ) {
return;
}
// Don't show if the user cannot edit a given customize_changeset post currently being previewed.
if ( is_customize_preview() && $wp_customize->changeset_post_id()
&& ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() )
) {
return;
}
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( is_customize_preview() && $wp_customize->changeset_uuid() ) {
$current_url = remove_query_arg( 'customize_changeset_uuid', $current_url );
}
$customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
if ( is_customize_preview() ) {
$customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url );
}
$wp_admin_bar->add_node(
array(
'id' => 'customize',
'title' => __( 'Customize' ),
'href' => $customize_url,
'meta' => array(
'class' => 'hide-if-no-customize',
),
)
);
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_is_block_theme() wp-includes/theme.php | Returns whether the active theme is a block-based theme or not. |
| is_customize_preview() wp-includes/theme.php | Whether the site is being previewed in the Customizer. |
| wp_customize_url() wp-includes/theme.php | Returns a URL to load the Customizer. |
| is_ssl() wp-includes/load.php | Determines if SSL is used. |
| remove_query_arg() wp-includes/functions.php | Removes an item or items from a query string. |
| WP_Admin_Bar::add_node() wp-includes/class-wp-admin-bar.php | Adds a node to the menu. |
| has_action() wp-includes/plugin.php | Checks if any action has been registered for a hook. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| is_admin() wp-includes/load.php | Determines whether the current request is for an administrative interface page. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
| add_action() wp-includes/plugin.php | Adds a callback function to an action hook. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_admin_bar_customize_menu