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

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

Custom Comment Notifications Fire on each Page Load

well, single.php is the template that’s loaded whenever you visit a page. And since you call comment_notification() there it’s only logical that a notification is sent. You should remove that code from single.php. Hooking into comment_post should be enough.

Custom Query for count_user_posts function

Your filter callback isn’t accepting any arguments from the hook. When you write the callback function you need to include the arguments passed in apply_filters, and in your add_filter() call you need to specify how many of the arguments you’re using: // Accept all 4 arguments provided to callbacks for this filter. function wpse_296863_author_post_count( $count, … Read more

Fetch all data of Users

Actually since you already have the ID you could just loop through and get the meta. https://developer.wordpress.org/reference/functions/get_user_meta/ get_user_meta(ID)

How do I let contributors edit their posts after being approved once?

There is a capability in WordPress called “edit_published_posts”. Contributors do not have this capability by default (refer to the Roles and Capabilities Codex page to see the out-of-box role configurations). You can add this capability to the contributor role with code like this: // get the “contributor” role object $obj_existing_role = get_role( ‘contributor’ ); // … Read more

How to default/force the user’s display_name to their nickname?

You can force this with a hook that activates when the profile is updated. The next step would be to hide the display_name select box, you can do that with some Javascript. add_action( ‘user_profile_update_errors’, ‘wpse7352_set_user_display_name_to_nickname’, 10, 3 ); function wpse7352_set_user_display_name_to_nickname( &$errors, $update, &$user ) { if ( ! empty( $user->nickname ) ) { $user->display_name = … Read more

List Users alphabetically with heading

After a good bit of tinkering I’ve come up with something. It’s certainly not the BEST method, but since there’s not a good way to do it through the core directly without having to do a bunch of array-reordering, I think SQL is a better solution here. Anyways, the SQL is as follows: SELECT users.*, … Read more

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