Tag Info

Hot answers tagged

4

Wait for the action plugins_loaded before you create the class instance. The pluggable functions are loaded at this time. From wp-settings.php: /** * Fires once activated plugins have loaded. * * Pluggable functions are also available at this point in the loading order. * * @since 1.5.0 */ do_action( 'plugins_loaded' ); I would even wait for ...


3

Not allowed by design: If we try to change the user login by the email: wp user update mary@example.tld --user_login=mary_new or by the user id: wp user update 123 --user_login=mary_new we get the following warning: User logins can't be changed. This is the reason: if ( isset( $assoc_args['user_login'] ) ) { WP_CLI::warning( "User logins ...


2

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( ...


2

You can try using wp_insert_post_data for the task. Something like: function assign_new_post_to_specific_author( $data , $postarr ) { // Where author_ID is the ID of the author you want to assign the new post $data['post_author'] = author_ID; return $data; } add_filter( 'wp_insert_post_data', 'assign_new_post_to_specific_author', '99', 2 ); ...


1

User Meta Query with RLIKE: If the birth date is stored like dd/mm/yyyy, in the user meta, then you could find all August birthday users with the following meta query: 'meta_query' => [ [ 'key' => 'birthday', 'value' => '/08/', 'compare' => 'RLIKE' ], ] You could also consider storing the birthday month ...


1

I think the use of meta_query is in order: $user_query = new WP_User_Query( array( 'meta_query'=> array( array( 'key'=> 'birthday', 'compare' => 'NOT EXISTS' ) ) ) ); Basically, this looks for all users where the meta key of birthday doesn't have a value ...


1

search-replace does the trick but can have undesired side effects if old_login appears in other contexts in the database: wp search-replace old_login new_login But before doing that run wp sql dump wp search-replace old_login new_login --dry-run To make an SQL dump and see what is going to be replaced.



Only top voted, non community-wiki answers of a minimum length are eligible