[wp-trac] [WordPress Trac] #62074: wp_admin_bar_new_content_menu issue
WordPress Trac
noreply at wordpress.org
Wed Sep 18 14:02:01 UTC 2024
#62074: wp_admin_bar_new_content_menu issue
-----------------------------+-----------------------------
Reporter: markuscode | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
A came across actions that been used for menus and realise that "+ New"
content area at the top bar in admin panel are cannot be replaced or
removed.
For example I need to hide or replace ability to add new custom post type.
Now there is now way to do that.
Suggesting add some filter to the loop
**File: "wp-includes/admin-bar.php"**
**Function "wp_admin_bar_new_content_menu"**
**Before:**
{{{#!php
<?php
foreach ( $cpts as $cpt ) {
if ( ! current_user_can( $cpt->cap->create_posts ) ) {
continue;
}
$key = 'post-new.php?post_type=' . $cpt->name;
$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' .
$cpt->name );
}
}}}
**After:**
{{{#!php
<?php
foreach ( $cpts as $cpt ) {
if ( ! current_user_can( $cpt->cap->create_posts ) ) {
continue;
}
$key = 'post-new.php?post_type=' . $cpt->name;
if ( ! apply_filters(
"show_new_content_{$cpt->name}_in_admin_bar",true, $key, $cpt ) ) {
continue;
}
$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' .
$cpt->name );
}
}}}
Usage Example:
{{{#!php
<?php add_filter( "show_new_content_my_post_type_in_admin_bar",
"__return_false", 999 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62074>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list