translate_user_role doesn’t work

Please note that translate_user_role doesn’t work in the front-end currently. Here is a workaround, you can place this in your theme: add_action( ‘init’, ‘load_admin_textdomain_in_front’ ) function load_admin_textdomain_in_front() { if ( ! is_admin() ) { load_textdomain( ‘default’, WP_LANG_DIR . ‘/admin-‘ . get_locale() . ‘.mo’ ); } }

List users of specific role instead of removing them with specific role

To fetch users from a specific role, you can use the role parameter of the get_users function. Each role has a specific ID; for WordPress’ native roles, these are administrator, editor, author, contributor and subscriber. In your case, you would want to fetch only subscriber users: $allUsers = get_users( array( ‘orderby’ => ‘post_count’, ‘order’ => … Read more

How to update user role totals

You’ll also need to export the old site’s options table which is usually called wp_options and import it to new one. Cause in the options table aka wp_options table there is a row field called wp_user_roles and it holds the role values of the site.

Removing Admin Bar Node Based on Role

WP_User has a roles array. Get the current user with wp_get_current_user() and check if your role is in the array. add_action( ‘admin_bar_menu’, ‘remove_new_content_menu’, PHP_INT_MAX ); function remove_new_content_menu( $wp_admin_bar ) { // get the current user $user = wp_get_current_user(); // define roles that cannot see the `new content` button $blacklisted_roles = array(‘grocery’, ‘subscriber’); // remove the … Read more

Select dropdown with 2 choices from foreach

You can use in_array to check if the name of the role is either customer or shop_manager add_action(‘register_form’, ‘myplugin_register_form’); function myplugin_register_form() { global $wp_roles; echo ‘<select name=”role” class=”input”>’; foreach ($wp_roles->roles as $key => $value): if ( in_array( $key, array(‘customer’, ‘shop_manager’) ) ) echo ‘<option value=”‘ . $key . ‘”>’ . $value[‘name’] . ‘</option>’; endforeach; echo … Read more

How can I add the ability for a user to add/edit administrators?

Make sure you’re adding and removing roles on plugin activation/deactivation. add_role() only adds a role if it doesn’t already exist. So if you already added the developer role without the capability to add administrators, calling add_role() again won’t re-add the role. You have to remove the role first. <?php /** * Plugin Name: Stackexchange Sample … Read more

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