Display user role Name – not slug

WordPress does not (currently) have a global function (e.g. get_role_name()) for getting the role name (e.g. Shop Manager for shop-manager or maybe shop_manager etc.), but you can easily get (and then display) it like so: $role=”shop-manager”; // the role slug; it’s up to you how to get the value.. $role_name = $role ? wp_roles()->get_names()[ $role … Read more

query users by role

You can use this function: // get users with specified roles function getUsersWithRole( $roles ) { global $wpdb; if ( ! is_array( $roles ) ) $roles = array_walk( explode( “,”, $roles ), ‘trim’ ); $sql=” SELECT ID, display_name FROM ” . $wpdb->users . ‘ INNER JOIN ‘ . $wpdb->usermeta . ‘ ON ‘ . $wpdb->users … Read more

How to target specific user role?

get_role is just going to return information about the role. It isn’t going to tell you if the current user has that role. Use wp_get_current_user with a check something like this: function subscriber_redirection() { global $redirect_to; $user = wp_get_current_user(); if (in_array(‘subscriber’,$user->roles)) { // user has subscriber role if ( !isset( $_GET[‘redirect_to’] ) ) { $redirect_to … Read more

Saving custom profile fields

Ok, I was doing it wrong, here’s a working solution, based on Justin Tadlock’s tutorial. <?php /* Add custom profile fields (call in theme : echo $curauth->fieldname;) */ add_action( ‘show_user_profile’, ‘my_show_extra_profile_fields’ ); add_action( ‘edit_user_profile’, ‘my_show_extra_profile_fields’ ); function my_show_extra_profile_fields( $user ) { ?> <?php if(user_can($user->ID, “paying_member”)) : ?> <h3>Extra profile information</h3> <table class=”form-table”> <tr> <th><label for=”paypal_account”>Paypal</label></th> … Read more

Allow AJAX call to other roles than admin

All the WordPress AJAX calls should be handled by the admin-ajax.php, wether they happen on the frontend or in the backend. To grant the access you have to register the callbackfuntion for the AJAX call add those lines to your file: add_action( ‘wp_ajax_prefix_update_post’, ‘prefix_update_post’ ); add_action( ‘wp_ajax_nopriv_prefix_update_post’, ‘prefix_update_post’ ); Be sure to add some validation … Read more

How to enable a custom post type to custom user role in WordPress

I don’t think the plugin adds the capabilities you are using in add_cap while registering the post type. You can modify the registered post type by adding code to themes functions.php file. You can do something like this. /** * Overwrite args of custom post type registered by plugin */ add_filter( ‘register_post_type_args’, ‘change_capabilities_of_course_document’ , 10, … Read more

How can I restore admin capabilities?

The string below actually represents an array in serialized form. a:1:{s:13:”administrator”;s:1:”1″;} Here: a:1 means an array with a single element s:13 means string and the length of the string followed by Array { “administrator” => “1” } Once that is in the table, you can use the unserialize() function to return it to an array … Read more

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