From cc1d2acd80af73b30a1474a03659a2a55ff7ef32 Mon Sep 17 00:00:00 2001 From: Xavier Zalawa Date: Fri, 17 Mar 2017 08:39:13 +0100 Subject: [PATCH] Manage conflict with the new "View Archive" link WordPress adds its own link into the admin bar to go to the archive page of any post types. But its behaviour does not work correctly with Thistle because of the possibility to have a post type without single view (`publicly_queryable => false`). So the Thistle link is kept in favour of the WP one. --- includes/admin.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/admin.php b/includes/admin.php index 28643bb..a4b0931 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -338,3 +338,21 @@ function thistle_redirect_wp_logout( $logout_url, $redirect ) { } } add_filter( 'logout_url', 'thistle_redirect_wp_logout', 10, 2 ); + +if ( ! function_exists( 'thistle_remove_admin_bar_archive_node' ) ) { + /** + * Removes the default archive links ("View Posts") from the admin bar in + * favour of the Thistle one. This choice lets us have + * this helpful link even if the post type has not a single view. + * + * @link https://core.trac.wordpress.org/ticket/34113 + * + * @global WP_Admin_Bar $wp_admin_bar + */ + function thistle_remove_admin_bar_archive_node() { + global $wp_admin_bar; + + $wp_admin_bar->remove_menu( 'archive' ); + } +} +add_action( 'wp_before_admin_bar_render', 'thistle_remove_admin_bar_archive_node' );