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

Getting a List of Currently Available Roles on a WordPress Site?

Roles are stored in the global variable $wp_roles. The ideal function is get_editable_roles() from /wp-admin/includes/user.php function get_editable_roles() { global $wp_roles; $all_roles = $wp_roles->roles; $editable_roles = apply_filters(‘editable_roles’, $all_roles); return $editable_roles; } The “editable” part is because it offers other plugins a chance to filter the list in case someone other than admin has ‘edit_users’ privilege (and … Read more

How to change the default registration email ? (plugin and/or non-plugin)

The new user email is sent using the wp_new_user_notification() function. This function is pluggable, which means that you can overwrite it: // Redefine user notification function if ( !function_exists(‘wp_new_user_notification’) ) { function wp_new_user_notification( $user_id, $plaintext_pass=”” ) { $user = new WP_User($user_id); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); $message = sprintf(__(‘New user registration on your blog … Read more

How to check if a user is in a specific role?

If you only need this for current user current_user_can() accepts both roles and capabilities. UPDATE: Passing a role name to current_user_can() is no longer guaranteed to work correctly (see #22624). Instead, you may wish to check user role: $user = wp_get_current_user(); if ( in_array( ‘author’, (array) $user->roles ) ) { //The user has the “author” … 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)