Tag Info

Hot answers tagged

5

There is no one answer, because both have pros and cons depending on what you want to store and why. A (probably non-exhaustive) list of differences to consider for a choice: Capabilities are designed to check if a user can do something or not. user_can and current_user_can are there to help you to check user permissions. You can implement that with user ...


3

You can just call get_user_meta without specifying a key, and it will return all MetaValues for the user. $userdata = get_user_meta( $userID ); You may have to do a mapping for displaytitles of the Metavalue, as they are returned in an array, where the keys are the databasevalues of your metakeys. For example, you may get ...


3

This is not a simple answer, so first you will need to include one more filter to allow you to grab both the make the meta_query interact with the main query via an OR instead of a AND, check my sample of code: add_filter('user_search_columns', 'q166419_user_search_columns' , 10, 3); function q166419_user_search_columns($search_columns, $search, $this){ ...


2

If you're looking to get in to instant notifications without suffering from backlog, I'd looking in to both Node.js and Socket.io. You should be able to work with them both pretty easily and integrate w/ WordPress. The sample chat application on the Socket.io site isn't a far cry from what you'd be doing. Basically an event is triggered on your LAMP/LNMP ...


2

Try this /* Save selected data */ add_action( 'personal_options_update', 'save_user_fields' ); add_action( 'edit_user_profile_update', 'save_user_fields' ); function save_user_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'country', $_POST['country'] ); } add_action( ...


2

You could simply use the get_blogs_of_user() function: echo count( get_blogs_of_user( $user_ID ) ); instead of your custom SQL query.


2

The difference is that capabilities are part of the access permission system of the site, which utilize and can be changed by the built-in tools and APIs that are designed to handle permissions. You can create your own permission scheme but then it will not be easy to override with tools or code that expect access permissions to be handled in capabilities. ...


2

There is no tax_query parameter for the WP_User_Query class. Since you've tagged the question with user-meta I can only assume you store the ID (or even the term name itself?) of a particular shop-category term as a user meta entry. In this case you would need something like this: // The 'WP_User_Query' arguments array $args = array( 'role' ...


1

Well, you comparing the results of the email_exists function with $current_user->ID. If email exists, email_exists() return the ID of the user using that email or false if the email doesn't exists. Imaging you are checking a email not being using, email_exists() return false and this if will validate: elseif(email_exists(esc_attr( $_POST['email'] ) ) != ...


1

User Capabilities will allow you set site-wide access settings for a specific User/User Account Type whereas the meta-data allows you to make settings individually for each Post/Page or anything that supports Meta in Wordpress. In other words, Capabilities are part of ACL (Access Control Layer) whereas Meta is best when used for Data Presentation. User ...


1

You can store the ratings as user meta. When a rating is added, add it to the user's ratings using add_user_meta(): add_user_meta( $user_id, '_ratings', $rating, false ); The last parameter tells it to add the current rating to the meta as a new item, not to replace the existing. All ratings can then be retrieved using get_user_meta(): get_user_meta( ...


1

Two options. The first will keep you away from custom SQL, and should be a lot more efficient than what you currently have. It runs two queries, one to get the user ID with the highest hourly rate, and then again to get the lowest. You need one more query to update the user meta cache & then you're home free: $query = new WP_User_Query; $users = array( ...


1

Try this: $yoursearchquery = 'This is my search'; $users = new WP_User_Query(array( 'search' => $yoursearchquery, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'shoe_size', 'value' => $yoursearchquery, 'compare' => 'LIKE' ), array( 'key' ...


1

In general your problem is that you check the condition on the front end but not on the backend. You have to check if a user is a allowed to upload a file before moving it to the uploads directory and adding it as an attachment. If the limitation you put are kind of nice to have it might be enough to limit upload in the UI, but if it has business or law ...


1

This will do what you want, and both functions should be placed within your fucntions.php file. The my_random_string() function accepts arguments, so you can add data before/after the string, as well as change the length of the string and the characters that are used to generate the string. /** * Generate a string of random characters * * @param array ...


1

If I understand problem correctly, you want to store name of multiple files in user meta field. add_user_meta function has fourth argument $unique which is false by default that means for each call to add_user_meta a new key-value pair is added, even if key already exists. add_user_meta has less clarification then the add_post_meta that does exactly same ...


1

You can use get_current_user_id() - if a user is not logged in, the value will be 0: <a href="http://example.com/uid=<?php echo get_current_user_id() ?>">...</a>


1

What is the exact meta_key and meta_value for the field I created using the function custom_user_profile_fields ? created_by and some user ID, for example: $args = array( 'meta_key' => 'created_by', 'meta_value' => 123, ) You could use a meta_query for more complex searches. $args = array( 'meta_query' => ...


1

Edit the user in phpmyadmin, enter the password as text in the user_pass field and there is a “Function” column with drop down boxes. On this field just select MD5 in the function column. When you save it phpMyAdmin will automatically md5 hash it for you.


1

I could only find the following core code references for the meta-box-order_ string: /wp-admin/includes/ajax-actions.php: update_user_option($user->ID, "meta-box-order_$page", $order, true); and /wp-admin/includes/template.php: ... get_user_option( "meta-box-order_$page" ) ... that's related to the ordering of meta-boxes. I doubt your ...


1

Please add following condition. $mailSent = get_user_meta($us_id, 'mail_sent', true); if($mailSent){ update_user_meta($us_id, 'mail_sent', 'mail sent'); }else{ $borrower_mail=wp_mail($to, $subject, $body); }


1

Try this: global $current_user; $user_id = $current_user->ID; // current user ID $meta = get_user_meta( $user_id, 'title', 'Manager' ); // subject meta if($meta != '') // updates meta if exists update_user_meta($user_id, 'title', 'Manager'); else // creates new meta if not exists add_user_meta($user_id, 'title', 'Manager');


1

After experimenting with birgire's comment (huge thanks), I put together a relatively simple regular expression that seems to be solid: SELECT * FROM wp_usermeta WHERE meta_key REGEXP('^wp_([[:digit]]+_)?capabilities$') The prefix can be easily added / changed without breaking the expression. It also requires at least 1 number and an underscore for any ...


1

Your query is wrong because your third argument to TIMESTAMPDIFF is incorrect. You should be using meta_value instead of SELECT meta_value. SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_wp_kc_last_active_time' AND TIMESTAMPDIFF( second, now(), TIMESTAMP(meta_value) ) > 5184000; Try that and see if the results start looking correct. I just ...


1

I've found these errors in your code: The saving proccess of custom user fields is hooked to registration but not to update user profile actions. You are using update_usermeta, a obsolete function, use update_user_meta instead. You are using get_the_author_meta with $user->ID without checking before if $user is an object, which generate errors on new ...


1

Well if you want to do this yourself first you'll have to make sure that the form supports enctype: /** Add Encryption Type to User Forms to allow Uploads **/ function profile_form_edit( ) { echo ' enctype="multipart/form-data"'; } add_action( 'user_edit_form_tag' , 'profile_form_edit' ); Then you're going to have to add a new field that allows users ...


1

As noted at the codex page for get_user_meta(): NOTE If the meta value does not exist and $single is true the function will return an empty string. If $single is false an empty array is returned. So I would suggest to do the check like this: ! empty( $themeta ) Regrading your other question, you can save the array by simply doing it like ...


1

If anyone should be faced with this problem, check if you have defined a callback function to set the user_login on pre_user_login. This filter is applied inside the wp_insert_user()-function and produced a same username again. Therefore the nicename was changed by adding a "-2". So, my problem was that I reset the user_logins again and again, instead of ...


1

It looks like you're using wrong parameters, please try this instead (untested): $q = new WP_User_Query( array( 'role' => 'contributor', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'first_meta', 'value' => '2', ), ...


1

As @Milo indicated. Be careful with sending too many emails or your IP will be banned/blacklisted. Personally I would prefer to create a table as email queue and send them with interval with WP Cron API. By default wp_mail() uses php mail() which is not much reliable and could end up in the Spam folder. Using SMTP for sending email is more reliable way ...



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