Does meta-data need to be sanitized?

Yes, it’s a good practice to sanitize input and escape output. It’s important to use the correct function, though, so that you don’t inadvertently mess up your data. Since it’s for a URL, use esc_url_raw() (it is specifically for db usage). (Note: it may seem odd using a function with the “esc_” stem for sanitizing, … Read more

Displaying field value in new column in users view on wordpress

Use this function to register a new column in the users table: function users_custom_columns( $column ) { $column[‘security_answer’] = ‘Security Answer’; return $column; } add_filter( ‘manage_users_columns’, ‘users_custom_columns’ ); And this function to display the new custom column: function display_users_custom_columns( $val, $column_name, $user_id ) { switch ($column_name) { case ‘security_answer’ : return get_user_meta( $user_id, ‘meta_key’, true); … Read more

get_results not returning anything

$wpdb->get_results() returns an array on success, so you can’t simply echo $result;. Instead, you can use foreach to loop through the results and display whatever the data that you want to display: $results = $wpdb->get_results( $q ); foreach ( $results as $row ) { echo $row->meta_value . ‘<br />’; } But I can see that … Read more

Difference between last_name and user_lastname

Short answer to “Which property am I supposed to use“: Use first_name and last_name. Longer answer: The properties first_name, user_firstname, last_name and user_lastname are defined in the WP_User class, and despite the different names (i.e. one with user_ and the other without that prefix): Both first_name and user_firstname use the value of the first_name meta. … Read more

Shortcode to update user meta

Basically, you can’t show the button and update the meta at the same moment. This has to be done in two separate requests as follows: Show the button whereever you want. It needs to be a form that submits to the same page (or an ajax call to another URL, but let’s keep it simple … Read more

How to combine two get_users() array?

Edit: to clarify, the answer to How can I merge them together for results? Is that you really can’t, not without a lot of custom SQL and using filters. The complexity of going that route far outweighs any perceived benefits and wouldn’t be very future-proof. I’d recommend using the solution below and putting it all … Read more

How to get user meta fields that have just been updated?

For anyone else with this issue, the fix was simple. I changed the hook and most importantly, I changed the priority so my action comes later. Default wordpress priority was 10, so I set priority to 11 and it works. add_action( ‘profile_update’, ‘BB_WP_SYNC_update_BB_profile’, 11, 2); And my function changed due to the different hook: function … Read more

Fetch user related data

I use this function on functions.php in all my development websites function imp($a){ echo ‘<pre>’; print_r($a); echo ‘</pre>’; die(); } now just use imp($user); where you are using get_user_meta ($user->ID). you will have all the info about the $user, maybe this will tell you the answer you need… You will find inside an object with … Read more

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