user_login vs. user_nicename

user_nicename is url sanitized version of user_login. In general, if you don’t use any special characters in your login, then your nicename will always be the same as login. But if you enter email address in the login field during registration, then you will see the difference. For instance, if your login is [email protected] then … Read more

How to allow an user role to create a new user under a role which lower than his level only?

Firstly, you need to add the following capabilities to the Doctor and Receptionist role: list_users edit_users create_users delete_users Now we can get to work with controlling which users they can create/edite/delete. Let’s start with a “helper” function that will return which roles a user is allowed to edit: /** * Helper function get getting roles … Read more

How do I display logged-in username IF logged-in?

This seems to do what you need. <?php global $current_user; wp_get_current_user(); ?> <?php if ( is_user_logged_in() ) { echo ‘Username: ‘ . $current_user->user_login . “\n”; echo ‘User display name: ‘ . $current_user->display_name . “\n”; } else { wp_loginout(); } ?>

How do I add a field on the Users profile? For example, country, age etc

You need to use the show_user_profile, edit_user_profile, personal_options_update, and edit_user_profile_update hooks. You can use the following code for adding additional fields in User section Code for adding extra fields in Edit User Section: add_action( ‘show_user_profile’, ‘extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘extra_user_profile_fields’ ); function extra_user_profile_fields( $user ) { ?> <h3><?php _e(“Extra profile information”, “blank”); ?></h3> <table class=”form-table”> … Read more

Editor can create any new user except administrator

It’s actually pretty easy. You need to filter into map_meta_caps and stop editors from creating/editing admins, and remove the administrator role from the ‘editable roles’ array. This class, as a plugin or in your theme’s functions.php file would do it: class JPB_User_Caps { // Add our filters function __construct(){ add_filter( ‘editable_roles’, array($this, ‘editable_roles’)); add_filter( ‘map_meta_cap’, … Read more

If the current user is an administrator or editor

First answer, not WordPress-related because it is just only PHP: Use the logic “OR” operator: <?php if( current_user_can(‘editor’) || current_user_can(‘administrator’) ) { ?> // Stuff here for administrators or editors <?php } ?> If you want to check more than two roles, you can check if the roles of the current user is inside an … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)