Return all users with a specific meta key

You can use the just the meta_key argument, the result will be similar to using the EXISTS sql statement. <?php $users = get_users(array( ‘meta_key’ => ‘your_meta_key’, )); Alternatively, you can use an empty string for meta_value (the default) and > for meta_compare. The result is the same (probably because meta_value gets ignored if its empty!). … Read more

How to obtain the user ID of the current profile being edited in WP-Admin?

There is a global variable called … $user_id available on that page. Always. From user-edit.php: $user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( ‘IS_PROFILE_PAGE’ ) ) define( ‘IS_PROFILE_PAGE’, ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; elseif ( ! $user_id && ! IS_PROFILE_PAGE ) … Read more

how to use joomla password format in wordpress?

First of all you need to find out which hashing algorithm has been used on the Joomla site to store the passwords. Joomla – different to Worpdress – ships with a variety of hashing algorithms. If you have found out how the hashes have been generated, you can port the hashing function over into wordpress … Read more

How to check username/password without signing in the user

There is a function in the user.php of the core files called wp_authenticate_username_password that seems like what you’re looking for. If you want to avoid throwing in the $user object (you probably only have the username + password), then just throw null as 1st function argument in: $check = wp_authenticate_username_password( NULL, ‘some_username’, ‘#thepassw0rd’ ); You … Read more

Execute a function when admin changes the user role

You can use the set_user_role hook, that will only fire when the user role changes: add_action( ‘set_user_role’, function( $user_id, $role, $old_roles ) { // Your code … }, 10, 3 ); If you want to restrict this to a profile update, you can use: add_action( ‘set_user_role’, function( $user_id ) { add_action( ‘profile_update’, function( $user_id ) … Read more

Prevent trash/delete action on specific post types

Here’s another approach using the map_meta_cap filter that’s applied within the map_meta_cap() function within the has_cap() method of the WP_User class (PHP 5.4+): add_filter( ‘map_meta_cap’, function ( $caps, $cap, $user_id, $args ) { // Nothing to do if( ‘delete_post’ !== $cap || empty( $args[0] ) ) return $caps; // Target the payment and transaction post … Read more

How can I query all users who registered today?

Few months ago, I updated the Codex for get_users() and WP_User_Query, regarding the date_query support on the user’s registration date, in WordPress 4.1+. Then I also added a simple example on how to find users that registered during the last 12 hours. But the current question is how to find users that registered today. We … Read more

Why does get_users suddenly return duplicates?

Seems like a silly question, but are there exactly 2 users in the database? Or are there more. The only thing I can see happening is because you are setting to 3, it’s looping back through. Another thing to try is checking the peterpanpan user, to see if he has the custom_role twice in his … Read more

Change the author slug from nickname to ID

Surprised to see this unanswered for this long. This is pretty simple to do with a simple block of code: function set_my_nice_name() { global $wpdb; $user_table = $wpdb->prefix . ‘users’; $wpdb->query(“UPDATE $user_table SET `user_nicename`=`ID`”); } add_action(‘init’, ‘set_my_nice_name’); This works because the visible portion of an author slug (or profile slug in BuddyPress) uses the user_nicename … Read more

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