Created
February 11, 2016 17:01
-
-
Save jamesmehorter/83c7bfd3af93fc4b3197 to your computer and use it in GitHub Desktop.
Add the current post ID to the Customize admin menu URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add the current post ID to the Customize admin menu URL | |
* | |
* @internal Called via wp_before_admin_bar_render action | |
* | |
* @param null | |
* | |
* @return null | |
*/ | |
function pmc_add_post_id_to_customizer_url(){ | |
global $wp_admin_bar, $post; | |
$customize_node = $wp_admin_bar->get_node( 'customize' ); | |
if ( is_object( $customize_node ) ) { | |
// Remove the existing Customizer node | |
$wp_admin_bar->remove_node( 'customize' ); | |
// Add the Customize Menu back to the admin bar | |
$wp_admin_bar->add_menu( array( | |
'id' => 'customize', | |
'title' => __( 'Customize' ), | |
// Add &post_id=XXXX to the Admin Bar Customizer URL | |
'href' => add_query_arg( | |
'post_id', | |
$post->ID, | |
$customize_node->href | |
), | |
'meta' => array( | |
'class' => 'hide-if-no-customize', | |
), | |
) ); | |
} | |
} | |
add_action( 'wp_before_admin_bar_render', 'pmc_add_post_id_to_customizer_url', 10, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment