ez_rk_test
<?php
// Conservare per sapere come si fa.
// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
// ----- ----- ----- ----- ----- //
// add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' );
// add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
// add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2' );
// ----- ----- ----- ----- ----- //
// add_menu_page('News e Press', 'News e Press', $ez_capability, 'edit.php?&cat=1', '', 'dashicons-admin-post', 113 );
// add_submenu_page('edit.php?&cat=1', 'Tutte le News', 'Tutte le News', $ez_capability, 'edit.php?&cat=1' );
// add_submenu_page('edit.php?&cat=1', 'Aggiungi News', 'Aggiungi News', $ez_capability, 'post-new.php' );
// ----- ----- ----- ----- ----- //
// Per abilitare all'utente Editor la modifica del frontend menu del tema - NB: bisogna pure aggiungergli la capabilities
// add_menu_page( 'Menu', 'Menu', 'edit_others_posts', 'nav-menus.php', '', '', 150 ); // abilita accesso alla modifica del menu del tema gorghi
// ----- ----- DEBUG ----- ----- //
// Visualizza l'array Global
if (!function_exists('ez_debug_test')):
function ez_debug_test() {
if ( !is_admin())
return;
$current_user = get_userdata( 2 );
global $wp_user, $pagenow;
if ( current_user_can('manage_options') ) { // ONLY DO THIS FOR ADMIN
if( $pagenow == 'index.php' ) { // PRINTS ON DASHBOARD
// echo '--- current_user ---<pre>'; print_r( $current_user ); echo '</pre>';
// echo '---GLOBAL wp_user ---<pre>'; print_r( $wp_user ); echo '</pre>';
}
}
}
add_action( 'admin_notices', 'ez_debug_test' );
endif;
// ----- ----- TEST ----- ----- //
function ez_add_remove_caps() {
// gets the author role
$editor = get_role( 'editor' );
$editor ->add_cap( 'edit_theme_options' );
$editor ->remove_cap( 'delete_pages' );
$editor ->remove_cap( 'delete_others_pages' );
$editor ->remove_cap( 'delete_published_pages' );
$editor ->remove_cap( 'delete_private_pages' );
}
//add_action( 'admin_init', 'ez_add_remove_caps');
// ----- ----- TEST ----- ----- //
function ez_new_user_cap() {
$user_id = 3;
$user = new WP_User( $user_id );
$caps = array(
'edit_theme_options',
'manage_categories',
'publish_pages',
'edit_pages',
'edit_others_pages',
'edit_published_pages',
'upload_files',
'publish_posts',
'edit_others_posts',
'delete_others_posts',
'edit_published_posts',
'delete_published_posts',
'edit_posts',
'delete_posts',
'read',
);
foreach ( $caps as $cap ) {
$user ->add_cap( $cap );
}
}
//add_action( 'admin_init', 'ez_new_user_cap');
// ----- ----- ROLE e CAPABILITIES ----- ----- //
//Da lanciare una volta sola per la creazione del Role
//remove_role( 'gorghi_editor' );
//add_action( 'admin_init', 'ez_add_custom_role'); //Decommentare UNA sola volta
function ez_add_custom_role() {
if ( !is_admin())
return;
$result = add_role(
'gorghi_editor',
'Gorghi Editor',
array(
'edit_theme_options' => true,
'manage_categories' => true,
'publish_pages' => true,
'edit_pages' => true,
'edit_others_pages' => true,
'edit_published_pages' => true,
'upload_files' => true,
'publish_posts' => true,
'edit_others_posts' => true,
'delete_others_posts' => true,
'edit_published_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'delete_posts' => true,
'read' => true,
)
);
if ( null !== $result ) {
echo 'Role Gorghi Editor CREATO!!!';
}
else {
echo 'Oh... Role Gorghi Editor esistente';
}
}
?>