• I created a custom post type and used capability_type to add custom capabilities to it. I’m trying to apply the capabilities to the administrator role, but it’s not working. When I run var_dump( current_user_can( 'publish_my_custom_post' ) ); it keeps returning false. Here is the code that adds the capabilities, any idea what’s wrong with it?

    // Hook to call function to add capabilities
    add_action( 'plugins_loaded', 'ca_myplugin_caps'); // tried admin_init also
    
    // Function to assign capabilities.
    function ca_myplugin_caps() {
    
    // Get the administrator role.
    $role = get_role( 'administrator' );
    // Add the capabilities to the role.
    $role->add_cap( 'publish_my_custom_post' );
    }

    [ mod note: do not bump ]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter CliffAscent

    (@cliffascent)

    I also tried on the init hook with no luck.

    Thread Starter CliffAscent

    (@cliffascent)

    I got it to work by using the following code in the installation function of my theme.

    // Get the administrator role.
    $role = get_role( 'administrator' );
    // Add the customposts capabilities to the role.
    $role->add_cap( 'publish_customposts' );
    $role->add_cap( 'edit_others_customposts' );
    $role->add_cap( 'edit_customposts' );
    $role->add_cap( 'edit_published_customposts' );
    $role->add_cap( 'delete_customposts' );
    $role->add_cap( 'delete_others_customposts' );
    $role->add_cap( 'delete_published_customposts' );
    $role->add_cap( 'delete_private_customposts' );
    $role->add_cap( 'edit_private_customposts' );
    $role->add_cap( 'read_private_customposts' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get custom capabilities to apply.’ is closed to new replies.