How to get a users list by who created them?

I’ve found it. /*** Adding extra field to get the the user who creates the another user during ADD NEW USER ***/ function custom_user_profile_fields($user){ if(is_object($user)) $created_by = esc_attr( get_the_author_meta( ‘created_by’, $user->ID ) ); else $created_by = null; ?> <h3>Extra profile information</h3> <table class=”form-table”> <tr> <th><label for=”created_by”>Created By</label></th> <td> <input type=”text” class=”regular-text” name=”created_by” value=”<?php echo $created_by; … Read more

The Simple and Correct Way to Add User Meta

Trying to detect when a UI was triggered, is indeed the wrong general approach (unless you want to tie to the UI). A proper one will be to hook on the user_register action. add_action( ‘user_register’, ‘wpse223196_registration_save’, 10, 1 ); function wpse223196_registration_save( $user_id ) { add_user_meta($user_id, ‘score’, 5); }

How do I retrieve a users’ last 5 posts?

Basically, when you want get posts, you should think about WP_Query. It’s already in the docs for your question. You can get posts by an author like this $query = new WP_Query( array( ‘author’ => AUTHOR_ID, ‘posts_per_page’ => 5 ) ); You can even get posts by more than one author, like this $query = … Read more

How redirect after registration?

You can use register_new_user hook which is the last hook before WordPress perform the redirect to check your email page. In the callback function you will get user ID, using it get the user data and check if user belongs to specific role. Example:- function wpse_228545_register_redirect( $user_id ) { $user_data = get_userdata($user_id); //Get the user … Read more

get_users meta_query: REGEXP not working for matching new lines

I found the problem and also fixed a bug in the regex. Final code: ‘meta_query’ => array( array( ‘key’ => ‘my_meta_field’, ‘value’ => “(^|\n|\r\n)99999($|\n|\r\n)”, ‘compare’ => ‘REGEXP’, ), ), The problem here was WordPress was adding extra backslashes on the special characters. By wrapping the expression in double quotes, this problem was solved. Also added … Read more

Log out users from every where

Firstly if you’d just like everyone to have to log in again you can void all of your cookies at once by changing your cookie hashes in your wordpress config file. The lines that look like this: define(‘AUTH_KEY’, ‘:u(rb=Ys8*2x^rVisqX(9=10a*.euPdYEBo6p_ZBB2CDG|rv~Ju)sh+6@=L6p_:l’); define(‘SECURE_AUTH_KEY’, ‘-`<iUz(4olJ`m&}1kA*{v&OX;Kq?W+!7ppF!tWb}cM<R=d<s=(oL]]04%AA@juZB’); define(‘LOGGED_IN_KEY’, ‘$KA]84n3ZT}v6m7c:r+!6l}R||)<_$3GxJ%F6Y?MopvxydJ@PRcmZ0-Hyq(EuEZt’); define(‘NONCE_KEY’, ‘qT=]!^BARWEMUD(G6]#~q$PAv-N[#^uE991w7HJNN<*mXavH)@o0TkFKVFUNIDN#’); define(‘AUTH_SALT’, ‘c W#7TWk{L1+n0A+^:|FHYL#-;*#<8U :v%>~S!45$bbYM09Iwe;@=uk^xeJd_D`’); define(‘SECURE_AUTH_SALT’, ‘h3&dgYcQE0uTaxd5bX$&1wC]yKP^?W8#q#>IJ*)ggf_Rc+6f+oZa?#JVS[HmO?=O’); define(‘LOGGED_IN_SALT’, ‘_L:n)>u>-31YK_ftTp_ZV>-y)qG)so|sOoWgYC9Ju!q_!%f.60g?I~]~lNZ6&o!0’); define(‘NONCE_SALT’, ‘.KI_*}ONxh/uwZv~!qYqOW+OL;?qvgaEqayN8>i+B.WY$e}+M9.Xqxwlf+?v … Read more

Restrict submitters from wp-admin [duplicate]

This is possible, drop this code into your theme’s functions.php file: add_action( ‘init’, ‘wpse_244614_no_dashboard_for_subscriber’ ); function wpse_244614_no_dashboard_for_subscriber() { $to = ‘https://google.com/’; $is_subscriber = current_user_can( ‘subscriber’ ); $in_backend = is_admin(); $doing_ajax = defined( ‘DOING_AJAX’ ) && DOING_AJAX; if ( $is_subscriber && $in_backend && ! $doing_ajax ) { wp_redirect( $to ); exit; } } Now whenever a … Read more