Show content only if member left a comment

Check if the user has left a comment // the user may have commented on *any* post define( ‘CHECK_GLOBAL_FOR_COMMENTS’, TRUE ); // // some more code // function memberviparea( $atts, $content = null ) { $post_id = 0; // if the user have to left a comment explicit on this post, get the post ID … Read more

Set a maximum upload count for users on a specific user role

I’m not really sure which is the real problem with code you posted, however I cant understand why use 2 functions when one is enough… add_filter( ‘wp_handle_upload_prefilter’, ‘limit_uploads_for_user_roles’ ); function limit_uploads_for_user_roles( $file ) { $user = wp_get_current_user(); // add the role you want to limit in the array $limit_roles = array(‘contributor’); $filtered = apply_filters( ‘limit_uploads_for_roles’, … Read more

How to get users by a custom field / by user meta data?

What is the exact meta_key and meta_value for the field I created using the function custom_user_profile_fields ? created_by and some user ID, for example: $args = array( ‘meta_key’ => ‘created_by’, ‘meta_value’ => 123, ) You could use a meta_query for more complex searches. $args = array( ‘meta_query’ => array( array( ‘key’ => ‘created_by’, ‘compare’ => … Read more

How to display the user that published a pending post?

The reason that get_the_modified_author() is not working is that it relies on being used within the WordPress loop. wp_get_recent_posts() does not set up a global post object. Here is a complete example based on your original code that replaces get_the_modified_author() with some simple code to get the name of the last person who edited the … Read more

Add extra field to users

your function never defines a value for that field so when you check if its equal to 1 you never get true. try this: add_action( ‘show_user_profile’, ‘module_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘module_user_profile_fields’ ); function module_user_profile_fields( $user ) { ?> <h3>Module Options</h3> <table class=”form-table”> <tr> <th><label for=”module_activation”>Module Activation</label></th> <td> <input id=”module_activation” name=”module_activation” type=”checkbox” value=”1″ <?php if ( … Read more

Force display name as full name

This is set during user registration. You can change the value per filter ‘user_register’. Sample code, not tested: /* Plugin Name: First name plus last name as default display name. */ add_action( ‘user_register’, ‘wpse_67444_first_last_display_name’ ); function wpse_67444_first_last_display_name( $user_id ) { $data = get_userdata( $user_id ); // check if these data are available in your real … Read more

How can I get users email (and additional data) from the rest API?

To add the user’s email address in the REST API response, register an additional field to the user object and add the email address: register_rest_field( ‘user’, ‘user_email’, [ ‘get_callback’ => static function (array $user): string { return get_userdata($user[‘id’])->user_email; }, ] ); Please note, however, that this is strongly discouraged because anyone can then see the … Read more

Limiting the number of users

As you can see in the WordPress Option Reference, there’s an option called users_can_register. You can – per default – set it in your (network-)sites settings. 1 => Yes 0 => No As usual: There’s a filter to intercept that from a plugin. “option_{$option_name}” So you can simply attach a callback to this filter and … Read more

Create a global variable for use in all templates

You’ll also have to fill the variable, e.g. function userinfo_global() { global $users_info; $users_info = wp_get_current_user(); } add_action( ‘init’, ‘userinfo_global’ ); And you should then be able to use $users_info everywhere in global context. Keep in mind that some template pars (header.php, footer.php, those used via get_template_part) are not in global scope by default, so … Read more

Best way to send users password?

You shouldn’t have to send them passwords. That’s a bad idea. Instead, make sure your web server has email setup properly and your user accounts have the correct email addresses. Then all you’ll have to do is send them the link to the Forgot Password link provided by WordPress by default. It looks like this: … Read more

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