[:it]In questa semplice guida vi faccio vedere come aggiungere permessi personalizzati ad un custom post type in WordPress.
add_filter( 'wpcf_type', 'pwd_add_product_caps', 10, 2);
function pwd_add_product_caps($data, $post_type) {
if($post_type == 'product'){
$args = array(
'capability_type' => 'product',
'capabilities' => array(
'publish_posts' => 'publish_products',
'edit_posts' => 'edit_products',
'edit_others_posts' => 'edit_others_products',
'delete_posts' => 'delete_products',
'delete_others_posts' => 'delete_others_products',
'read_private_posts' => 'read_private_products',
'edit_post' => 'edit_product',
'delete_post' => 'delete_product',
'read_post' => 'read_product',
),
);
$data = array_merge($data, $args);
}
return $data;
}
In questo esempio si aggiungono i permessi di pubblicare/editare/eliminare gli articoli personalizzati ‘product’, che poi potranno essere associati ad un ruolo.
[:en]
add_filter( 'wpcf_type', 'pwd_add_product_caps', 10, 2);function pwd_add_product_caps($data, $post_type) { if($post_type == 'product'){ $args = array( 'capability_type' => 'product', 'capabilities' => array( 'publish_posts' => 'publish_products', 'edit_posts' => 'edit_products', 'edit_others_posts' => 'edit_others_products', 'delete_posts' => 'delete_products', 'delete_others_posts' => 'delete_others_products', 'read_private_posts' => 'read_private_products', 'edit_post' => 'edit_product', 'delete_post' => 'delete_product', 'read_post' => 'read_product', ), ); $data = array_merge($data, $args); } return $data;}[:]