Created
July 3, 2016 09:31
-
-
Save AndreaBarghigiani/be27a1ec81a46f9c0c9956b27ea8ffa9 to your computer and use it in GitHub Desktop.
Articolo: "Tutto quello che Devi Sapere sui Ruoli degli Utenti WordPress" (https://skillsandmore.org/wordpress-ruoli/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Per Ruolo | |
function aggiungi_capability() { | |
// prendo il ruolo author | |
$ruolo = get_role( 'author' ); | |
//Aggiungo la mia Capability | |
$role->add_cap( 'aggiungi_prodotto' ); | |
} | |
add_action( 'admin_init', 'aggiungi_capability'); | |
//Per Utente | |
$user = new WP_User( $user_id ); | |
$user->add_cap( 'can_edit_posts'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Aggiungi un Ruolo ad un Utente | |
$user_id = 3; | |
$ruolo = 'shop_manager'; | |
$user_id = wp_update_user( array( 'ID' => $user_id, 'role' => $ruolo ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Controlla la capability di un utente loggato | |
if( current_user_can('edit_others_posts') ){ | |
echo "Puoi modificare gli articoli degli altri"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Controlla un dato utente | |
if ( user_can( 6, 'edit_others_posts' ) ) { | |
// Fai qualcosa | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Crea un Ruolo Personalizzato | |
$aggiungi_ruolo = add_role( | |
'shop_manager', | |
__( 'Shop Manager' ), | |
array( | |
'edit_product' => true, // true ci attiva la capability | |
'delete_shop_coupon_terms' => true, | |
'read_shop_order' => false, // false la disattiva | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment