How to assign a custom gender to a user role?
How to assign a custom gender to a user role?
How to assign a custom gender to a user role?
User role can’t be set
I found the solution to my problem. It had to do with my function that removes the manager role. I commented it out, and it works. My bad. Here’s the working code: if ( ! ( role_exists( ‘manager’ ) ) ) { function new_role_manager() { global $wp_roles; if ( ! isset( $wp_roles ) ) { … Read more
This is based on Bosco’s comment. You can do this instead of line 3 in the above code: wp_roles()->is_role( ‘editor’ ); That grabs a WP_Roles object (what the code you had tries to do by getting a global variable) and calls the same is_role() function.
It looks like your $user variable contents are not an instance of a WP_User class. You’ve got an error of stdClass, but you need the WP_User. Check what class the $user is the instance. If you use the get_users() function, you should note one feature of this function described in the documentation: Return value is … Read more
Woocommerce is considered off-topic here but as a general answer, it is considered best practice to check against capabilities instead of roles In WP, this is done like that: add_action(‘init’, ‘wpse_capability_check’); // hooked on ‘init’ but depends on your actual code logic function wpse_capability_check(){ // you should check on a capability that only validated user … Read more
What you want is add_role() The Codex provides sample code: $result = add_role( ‘basic_contributor’, __( ‘Basic Contributor’ ), array( ‘read’ => true, // true allows this capability ‘edit_posts’ => true, ‘delete_posts’ => false, // Use false to explicitly deny ) ); if ( null !== $result ) { echo ‘Yay! New role created!’; } else … Read more
the Short and sweet way would be to store the post id that they are allowed to edit in custom user meta. Then us wp_update_post and check if the id is in the user meta if so update if not don’t.
One way of doing it is, when you are submitting the registration form, define a value for the ‘role’ and then pass it with wp_insert_user Codex. Like this: $fields_user = get_fields_user(); //get the values from the form and put them in an array. $fields_user[‘role’] = ‘participant’; //define a value for the key ‘role’ $user_id = … Read more
Adding these two lines to the wp-config.php file solved the problem: define(‘FS_CHMOD_FILE’, 0644); define(‘FS_CHMOD_DIR’, 0755);