• Resolved amdh

    (@amdh)


    Hi

    i registered custom post type like this but in browser it says that you don’t have permission to create “taqrir”. whats the problem?

    
    function Taqrir() {
    	$labels = array();
    	$capabilities = array(
    		'edit_post'             => 'edit_taqrir',
    		'read_post'             => 'read_taqrir',
    		'delete_post'           => 'delete_taqrir',
    		'edit_posts'            => 'edit_taqrir',
    		'edit_others_posts'     => 'edit_others_taqrir',
    		'publish_posts'         => 'publish_taqrir',
    		'read_private_posts'    => 'read_private_taqrir',
    	);
    	$args = array(
    		'label'                 => 'Taqrir',
    		'description'           => '',
    		'labels'                => $labels,
    		'supports'              => array( 'title', 'editor', 'comments' ),
    		'taxonomies'            => array( 'post_tag'),
    		'hierarchical'          => true,
    		'public'                => true,
    		'show_ui'               => true,
    		'show_in_menu'          => true,
    		'menu_position'         => 5,
    		'menu_icon'             => 'dashicons-admin-customizer',
    		'show_in_admin_bar'     => true,
    		'show_in_nav_menus'     => true,
    		'can_export'            => true,
    		'has_archive'           => 'taqrir',
    		'exclude_from_search'   => false,
    		'publicly_queryable'    => true,
    		'capability_type'       => $capabilities,
    		'map_meta_cap'          => true,
    	);
    	register_post_type( 'taqrir', $args );
    
    }
    add_action( 'init', 'Taqrir', 0 );
    
    
    • This topic was modified 6 years, 2 months ago by amdh.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The capabilities parameter only indicates which capability should be checked, not which capabilities the post type has. So until you assign your user or your user role with the edit_taqrir capability, it will continue to say that it is not allowed, because that’s what you coded it to do.

    Thread Starter amdh

    (@amdh)

    I’ve assigned capabilities with this code but the problem persists:

    
    function add_theme_caps() {
        $admins = get_role( 'administrator' );
        $admins->add_cap( 'edit_taqrir' ); 
        $admins->add_cap( 'read_taqrir' ); 
        $admins->add_cap( 'delete_taqrir' ); 
        $admins->add_cap( 'edit_others_taqrir' ); 
        $admins->add_cap( 'publish_taqrir' ); 
        $admins->add_cap( 'read_private_taqrir' ); 
    }
    add_action( 'admin_init', 'add_theme_caps');
    
    Thread Starter amdh

    (@amdh)

    and when i show current user capabilities, this is the output:

    
    Array
    (
        [switch_themes] => 1
        [edit_themes] => 1
        [activate_plugins] => 1
        [edit_plugins] => 1
        [edit_users] => 1
        [edit_files] => 1
        [manage_options] => 1
        [moderate_comments] => 1
        [manage_categories] => 1
        [manage_links] => 1
        [upload_files] => 1
        [import] => 1
        [unfiltered_html] => 1
        [edit_posts] => 1
        [edit_others_posts] => 1
        [edit_published_posts] => 1
        [publish_posts] => 1
        [edit_pages] => 1
        [read] => 1
        [level_10] => 1
        [level_9] => 1
        [level_8] => 1
        [level_7] => 1
        [level_6] => 1
        [level_5] => 1
        [level_4] => 1
        [level_3] => 1
        [level_2] => 1
        [level_1] => 1
        [level_0] => 1
        [edit_others_pages] => 1
        [edit_published_pages] => 1
        [publish_pages] => 1
        [delete_pages] => 1
        [delete_others_pages] => 1
        [delete_published_pages] => 1
        [delete_posts] => 1
        [delete_others_posts] => 1
        [delete_published_posts] => 1
        [delete_private_posts] => 1
        [edit_private_posts] => 1
        [read_private_posts] => 1
        [delete_private_pages] => 1
        [edit_private_pages] => 1
        [read_private_pages] => 1
        [delete_users] => 1
        [create_users] => 1
        [unfiltered_upload] => 1
        [edit_dashboard] => 1
        [update_plugins] => 1
        [delete_plugins] => 1
        [install_plugins] => 1
        [update_themes] => 1
        [install_themes] => 1
        [update_core] => 1
        [list_users] => 1
        [remove_users] => 1
        [promote_users] => 1
        [edit_theme_options] => 1
        [delete_themes] => 1
        [export] => 1
        [copy_posts] => 1
        [lfb_manager] => 1
        [edit_taqrir] => 1
        [read_taqrir] => 1
        [delete_taqrir] => 1
        [edit_others_taqrir] => 1
        [publish_taqrir] => 1
        [read_private_taqrir] => 1
        [administrator] => 1
    )
    
    • This reply was modified 6 years, 2 months ago by amdh.
    Thread Starter amdh

    (@amdh)

    is there any answer?

    You only have to add the capabilities once.
    Perhaps you can find your answer here https://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types

    Thread Starter amdh

    (@amdh)

    thanks.
    it solved my problem.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post type capabilities’ is closed to new replies.