• Resolved 3pepe3

    (@3pepe3)


    Hello,

    I’m trying to map the capability create_posts for posts, pages and custom posts.

    So I’m doing this :

    function fix_capability_create(){
    	$post_types = get_post_types( array(),'objects' );
    	foreach ( $post_types as $post_type ) {
    		$cap = "create_".$post_type->name;
    		$post_type->cap->create_posts = $cap;
    	}
    }
    add_action( 'init', 'fix_capability_create',100);

    In the “user role editor” I can’t see the new cap create_posts or “create_”.$post_type->name (create_books).

    In user role editor if I add the cap create_books then everything works like a charm… but this is a tedious task for each projects and more when we have several post_types created by cpt-onomies.

    Any idea ? I was trying “map_meta_cap( $cap, 1);” or ” $role->add_cap( $cap ); ” (yes, $role was defined) but without success.

    thanks in advance.
    Pepe

    https://www.ads-software.com/plugins/user-role-editor/

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

    (@3pepe3)

    uppppppppppppp….. actually I forgot to activate the theme.
    So the capability is mapped and working as expected.

    code:

    function fix_capability_create(){
    	$post_types = get_post_types( array(),'objects' );
    	foreach ( $post_types as $post_type ) {
    		$cap = "create_".$post_type->name;
    		$post_type->cap->create_posts = $cap;
    		map_meta_cap( $cap, 1);
    	}
    }
    add_action( 'init', 'fix_capability_create',100);

    the action was init and not admin_init or anything else because init at priority 100 prevents the display of “add new” on admin bar, sidebar, etc (in all the wp interface).

    thanks
    Pepe

    Thread Starter 3pepe3

    (@3pepe3)

    So i will close the topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘create_posts capability not mapped.’ is closed to new replies.