Monday, 8 March 2021

Wp: If User Role This Then Echo This

 if ( current_user_can( 'manage_options' ) ) {
    echo 'Admin';
} else if ( current_user_can( 'edit_pages' ) ) {
    echo 'Editor';
} else if ( current_user_can( 'publish_posts' ) ) {
    echo 'Author';
} else if ( current_user_can( 'read' ) ) {
    echo 'Subscriber';
}
//// or Not tested
foreach ( $comment_users as $user_id ) {
    wp23234_show_user_role( $user_id );
}

function wp23234_show_user_role( $user_id ) {
    $data  = get_userdata( $user_id );
    $roles = $data->roles;

    if ( in_array( $roles, 'administrator' ) ) {
        echo 'Administrator';
    } else if ( in_array( $roles, 'editor' ) ) {
        echo 'Editor';
    } else if ( in_array( $roles, 'author' ) ) {
        echo 'Author';
    } else if ( in_array ( $roles, 'subscriber' ) ) {
        echo 'Subscriber';
    }
}
/// Or Switch
<?php
global $current_user; 
get_currentuserinfo();
switch (true)  {
 case ( user_can( $current_user, "subscriber") ):
   // Show Role
   // Show Subscriber Image
 break;
 case ( user_can( $current_user, "contributor") ):
   // Show Role
   // Show Contributor Image
 break;
 case ( user_can( $current_user, "administrator") ):
   // Show Role
   // Show Administrator Image
 break;
}
?>
///
<?php
global $current_user; 
get_currentuserinfo();
switch (true)  {
 case ( user_can( $current_user, "subscriber") ):
   echo '<img src="http:www.impho.com/images/001.jpg">';
 break;
 case ( user_can( $current_user, "contributor") ):
   echo '<img src="http:www.impho.com/images/002.jpg">';
 break;
 case ( user_can( $current_user, "administrator") ):
  echo '<img src="http:www.impho.com/images/003.jpg">';
 break;
}
?>

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...