Allow roles below admin to add subscribers only

This first step to making this happen is add the capability to create_users to a given role. You do this be calling get_role, then using the add_cap method. This only needs to be done once. Here’s an example that does it on plugin activation. <?php register_activation_hook( __FILE__, ‘wpse42003_activation’ ); function wpse42003_activation() { foreach( array( ‘editor’, … Read more

Is it possible to add new user Roles?

Yes. WordPress has robust built-in Roles and Capabilities system desgined to do exactly what you are looking for. To add a new role, use the add_role() function in your theme’s functions.php or a plug-in like so: $role = add_role( ‘event_manager’, ‘Event Manager’, array( ‘read’ => true, // True allows that capability ) ); if ( … Read more

Temporary capability for current_user_can()

Yes, just filter ‘user_has_cap’. You get an array with the current capabilities that you can change without touching the database. Sample Code add_filter( ‘user_has_cap’, ‘wpse_53230_catch_cap’, 10, 3 ); /** * See WP_User::has_cap() in wp-includes/capabilities.php * * @param array $allcaps Existing capabilities for the user * @param string $caps Capabilities provided by map_meta_cap() * @param array … Read more

wp_update_user not updating

Im using remove_role and then add_role to upgrade a user from one role to another. Here is a function that checks all user within the user role subscriber and upgrade them to editor every hour. /** * Add a cron job that will update * Subscribers to editors. Runs hourly */ add_action(‘check_user_role’, ‘upgrade_user’); function run_check_user_role() … Read more

add_role() run only once?

The user roles and capabilities are saved in the database so once you have you have used add_role() its saved and then next load WordPress will know that role just like the built in roles. Now if you look at the function add_role() more specifically at line 141 you will see that it only saves … Read more

How do I programmatically set default role for new users?

This allows plugins to easily hijack the default role while they’re active. // Hijack the option, the role will follow! add_filter(‘pre_option_default_role’, function($default_role){ // You can also add conditional tags here and return whatever return ‘subscriber’; // This is changed return $default_role; // This allows default }); I use it to make sure some plugins that … Read more

Reset default roles and capabilities

I use User Role Editor. You can delete added roles, and reset roles from the plugin page. To reset the administator role, you can, as of WP 3.4+, add define(‘URE_SHOW_ADMIN_ROLE’, 1); to your wp-config.php file. After having done so, you need to go to Users > User Role Editor and click “Reset”.

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