0

I would like to disable the "+Add Category Button" under the Category metabox so that anyone creating a post has to choose only from the list of existing categories.

  1. I did check out another post, which literally has the same question, How To Remove The "+ Add New Category" Link From A Category Metabox But the accepted answer doesn't make sense because he references Line 345-367, which are not relevant lines (maybe because of WP updates, things might have changed). So I am confused.

  2. I installed the 'User Role Editor' plugin and removed the 'manage_categories' capability for the 'Editor' which worked. But I would like to remove it for ALL users including admin, superadmin. So I tried changing the theme's functions.php as:

    add_action( 'add_meta_boxes', 'isa_remove_categories_meta_box' )
    function isa_remove_categories_meta_box() {
    
    remove_meta_box( 'categorydiv', 'post', 'side' );// remove the Categories box
    
    }
    

    But, this makes the entire Category box disappear. Is there anything I can use to replace the 'categorydiv' to make only the '+Add New Category' disappear?

Or, can someone point me out to what the accepted answer from the other post meant by lines 345-367? I can try that as well.

  • as the OP in the question you link to mentions, I use "CSS hacks to hide it" when I want this. – Paul 'Sparrow Hawk' Biron Mar 10 '17 at 17:05
  • Can you please expand on how to go about with CSS hacks? Which CSS files would I have to modify? – Ashwin Baskaran Mar 10 '17 at 17:11
  • the answer to that other question also mentions "Currently there is no hook available to filter the output". About 10 days ago I opened a Trac ticket and requested that such a filter be added (admittedly, for a different reason). It doesn't appear that the core team has even reviewed that ticket, but maybe if you (and others) commented on it saying it would be useful to you as well, they'll act on it. – Paul 'Sparrow Hawk' Biron Mar 10 '17 at 17:12
  • In your plugin/theme add the following #category-adder { display: none ;} to any CSS you enqueue on admin_enqueue_scripts – Paul 'Sparrow Hawk' Biron Mar 10 '17 at 17:21
1

I installed the 'User Role Editor' plugin and removed the 'manage_categories' capability for the 'Editor' which worked. But I would like to remove it for ALL users including admin, superadmin.

If removing the 'manage_categories' capability from the editor role provides the functionality you want, then you can remove the 'manage_categories' capability from all user roles fairly easily either by using an existing plugin, or writing a new plugin that upon activation removes the capability from all the user roles. Here's the code that would be necessary to remove the capability from each role (actually, it explicitly sets the capability to false).

register_activation_hook( __FILE__, 'wpse_259647_remove_manage_categories_cap' );
function wpse_259647_remove_manage_categories_cap() {
  $roles = wp_roles();
  foreach( $roles->role_names as $slug => $name ) {
    $role = get_role( $slug );
    $role->add_cap( 'manage_categories', false );
  }
}

This won't remove the capability from "super admins" though since "super admins" technically aren't a role or a capability.

If you want to explicitly revoke the manage_categories capability from all users, you could do that too.

register_activation_hook( __FILE__, 'wpse_259647_remove_manage_categories_cap' );
function wpse_259647_remove_manage_categories_cap() {
  $users = get_users();
  foreach( $users as $user ) {
    $user->add_cap( 'manage_categories', false );
  }
}

This may still not remove the capability from "super admins" though, because WordPress treats them differently than other users.

| improve this answer | |
0

If you are building your own taxonomy you can set the capabilities when registering the taxonomy. For example...

<?php
    register_taxonomy(
        'members_tax',
        'post',
        array(
            'label'             => __( 'Members' ),
            'hierarchical'      => true,
            'rewrite'           => array( 'slug' => 'members-tax' ),
            'capabilities'      => array(
                'assign_terms' => 'manage_options',
                'edit_terms'   => 'god',
                'manage_terms' => 'god',
            ),
            'show_in_nav_menus' => false,
        )
    );

If you want only the administrator to be able to add or edit change god to administrator. It removes the "Add New Members Category" from the metabox on new posts page and removes the link on the menu bar under posts.

This comes from this gist https://gist.github.com/ChrisFlannagan/4cd3bfd0e853cda3d3f7898c59428ac2

| improve this answer | |
  • Follow up. If you want any user to be assign terms remove the 'assign_terms' => 'manage_options', – CDToad Aug 7 '19 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.