• Hi all,
    i’ve been trying to do something that shoudl be easy, but with no luck. I hope that someone can help me.

    This is what I’ve in mind

    1) create a custom post type with custom capabilities writing code in functionts.php

    2) manage capabilities on the fly (give or revoke) of this post type with Members plugin (or others like user role editor… they are quite the same for what I woudl like to do.. don’t?)

    This is how I do it

    1) Custom Post Type “Eventi” just written in functions.php
    (singular and plural are in Italian)

    function events() {
    
    $labels = array(
    'name' => 'Eventi',
    'singular_name' => 'Evento',
    'add_new' =>  'Aggiungi Nuovo',
    'add_new_item' => 'Aggiungi Nuovo Evento',
    'edit_item' => 'Modifica Evento',
    'new_item' => 'Nuovo Evento',
    'view_item' => 'Vedi Evento',
    'search_items' => 'Cerca Evento',
    'not_found' => 'Nessun Evento Trovato',
    'not_found_in_trash' => 'Nessun Evento trovato nel Cestino',
    'parent_item_colon' => ''
    );
    $args = array(
    'labels' => $labels,
    'public' => true,
    'show_ui' => true,
    'menu_position' => 4,
    'menu_icon' => get_bloginfo('stylesheet_directory').'/images/events-icon.gif', // 16px16
    'capability_type' => array('evento', 'eventi'),
    'capabilities' => array(
    				'publish_posts' => 'publish_eventi',
    				'edit_posts' => 'edit_eventi',
    				'edit_others_posts' => 'edit_others_eventi',
    				'delete_posts' => 'delete_eventi',
    				'delete_others_posts' => 'delete_others_eventi',
    				'read_private_posts' => 'read_private_eventi',
    				'edit_post' => 'edit_evento',
    				'delete_post' => 'delete_evento',
    				'read_post' => 'read_evento',
    			),
    'map_meta_cap' => true,
    'hierarchical' => false,
    'rewrite' => array("slug" => "evento"),
    '_builtin' => false,
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author', 'page-attributes' ));
    register_post_type( 'events' , $args );
    
    $labelcatg = array(
        'name' => _x( 'Tipi Evento', 'taxonomy general name' ),
        'singular_name' => _x( 'Tipo Evento', 'taxonomy singular name' ),
        'search_items' =>  __( 'Cerca Tipi Evento' ),
        'all_items' => __( 'Tutti i Tipi Evento' ),
        'parent_item' => __( 'Tipo Evento Padre' ),
        'parent_item_colon' => __( 'Tipo Evento Padre:' ),
        'edit_item' => __( 'Modifica Tipo Evento' ),
        'update_item' => __( 'Aggiorna Tipo Evento' ),
        'add_new_item' => __( 'Aggiungi Tipo Evento' ),
        'new_item_name' => __( 'Nuovo Tipo Evento' ),
      );
    register_taxonomy('tipievento','events',array(
        'hierarchical' => true,
        'labels' => $labelcatg,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'tipoevento' ),
      ));
    
    register_taxonomy_for_object_type('post_tag', 'events');
    register_taxonomy_for_object_type('zone', 'events');
    
    }
    
    	add_action('init', 'events');

    Then I install Members Plugin and I go to roles admi page to apply the capabilities i’ve created to some roles.

    but, sadly, the custom post type capabilities are not there!
    Where am I wrong?

    http://wordpress.org/extend/plugins/members/

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

    (@bluantinoo)

    This is really odd.
    same code (with some additional taxonomy), for another custom post type, a few lines above in the very same functions.php and it works, capabilities are visibile in Members interface.

    this is the working code. What’s happening?

    function professionisti() {
    $labels = array(
    'name' => 'Professionisti',
    'singular_name' => 'Professionista',
    'add_new' =>  'Aggiungi Nuovo',
    'add_new_item' => 'Aggiungi Nuovo Professionista',
    'edit_item' => 'Modifica Professionista',
    'new_item' => 'Nuovo Professionista',
    'view_item' => 'Vedi Professionista',
    'search_items' => 'Cerca Professionista',
    'not_found' => 'Nessun Professionista Trovato',
    'not_found_in_trash' => 'Nessun Professionista trovato nel Cestino',
    'parent_item_colon' => ''
    );
    $args = array(
    'labels' => $labels,
    'public' => true,
    'show_ui' => true,
    'menu_position' => 3,
    'menu_icon' => get_bloginfo('stylesheet_directory').'/images/author.png', // 16px16
    'capability_type' => array('professionista', 'professionisti'),
    'capabilities' => array(
    				'publish_posts' => 'publish_professionisti',
    				'edit_posts' => 'edit_professionisti',
    				'edit_others_posts' => 'edit_others_professionisti',
    				'delete_posts' => 'delete_professionisti',
    				'delete_others_posts' => 'delete_others_professionisti',
    				'read_private_posts' => 'read_private_professionisti',
    				'edit_post' => 'edit_professionista',
    				'delete_post' => 'delete_professionista',
    				'read_post' => 'read_professionista',
    			),
    'map_meta_cap' => true,
    'hierarchical' => false,
    'rewrite'         => array(
    					'slug'		 	=> 'psicologo',
    					'with_front'	=> false
    				),
    '_builtin' => false,
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author', 'page-attributes'));
    register_post_type( 'professionisti' , $args );
    
     $labelcat = array(
         'name' => _x( 'Professioni', 'taxonomy general name' ),
         'singular_name' => _x( 'Professione', 'taxonomy singular name' ),
         'search_items' =>  __( 'Cerca Professione' ),
         'all_items' => __( 'Tutte le Professioni' ),
         'parent_item' => __( 'Professione Padre' ),
         'parent_item_colon' => __( 'Professione Padre:' ),
         'edit_item' => __( 'Modifica Professione' ),
         'update_item' => __( 'Aggiorna Professione' ),
         'add_new_item' => __( 'Aggiungi Professione' ),
         'new_item_name' => __( 'Nuova Professione' ),
       );
     register_taxonomy('professioni','professionisti',array(
         'hierarchical' => true,
         'labels' => $labelcat,
         'show_ui' => true,
         'query_var' => true,
         'rewrite' => array( 'slug' => 'professione' ),
       ));
    
       $labelcatb = array(
         'name' => _x( 'Aree di Competenza', 'taxonomy general name' ),
         'singular_name' => _x( 'Area', 'taxonomy singular name' ),
         'search_items' =>  __( 'Cerca Area' ),
         'all_items' => __( 'Tutte le Aree' ),
         'parent_item' => __( 'Area Padre' ),
         'parent_item_colon' => __( 'Area Padre:' ),
         'edit_item' => __( 'Modifica Area' ),
         'update_item' => __( 'Aggiorna Area' ),
         'add_new_item' => __( 'Aggiungi Area' ),
         'new_item_name' => __( 'Nuova Area' ),
       );
     register_taxonomy('aree','professionisti',array(
         'hierarchical' => true,
         'labels' => $labelcatb,
         'show_ui' => true,
         'query_var' => true,
         'rewrite' => array( 'slug' => 'area' ),
       ));
    
        $labelcatc = array(
         'name' => _x( 'Zone Geografiche', 'taxonomy general name' ),
         'singular_name' => _x( 'Zona', 'taxonomy singular name' ),
         'search_items' =>  __( 'Cerca Zona' ),
         'all_items' => __( 'Tutte le Zone' ),
         'parent_item' => __( 'Zona Padre' ),
         'parent_item_colon' => __( 'Zona Padre:' ),
         'edit_item' => __( 'Modifica Zona' ),
         'update_item' => __( 'Aggiorna Zona' ),
         'add_new_item' => __( 'Aggiungi Zona' ),
         'new_item_name' => __( 'Nuova Zona' ),
       ); 	
    
     register_taxonomy('zone','professionisti',array(
         'hierarchical' => true,
         'labels' => $labelcatc,
         'show_ui' => true,
         'query_var' => true,
         'rewrite' => array( 'slug' => 'psicologi-psicoterapeuti', 'hierarchical' => true ),
       ));
    
    register_taxonomy_for_object_type('post_tag', 'professionisti');
    }
    
    add_action('init', 'professionisti');

    Are you sure that with that code you will see the capabilities in Members without make the Add New Capabilities from the plugin?

    Thread Starter bluantinoo

    (@bluantinoo)

    @somtam,
    you’re right.
    actually that mapping does not create capabilites.

    after that I need to create them with some other plugin like “Members” “User Role Editor” or “Map Cap”

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type, Capabilities and Members plugin’ is closed to new replies.