How to prevent multiple user accounts with the same meta field?

You can use the add_post_meta and update_post_meta filters to accomplish this. If you return anything other than null in these filters the post meta will not be saved. add_filter(‘add_post_metadata’, ‘check_metadata’, 10, 5); function check_metadata($check, $object_id, $meta_key, $meta_value, $prev_value){ /*** Check if the metadata exists via sql ***/ if($exists) { /*** Notify you or something ***/ … Read more

User updating their profile wipes my custom fields

I see two problems in your code. The first one is the user capability level and the second one is how you’re saving the data. You can fix the first one by setting the capability requirement in your saving function higher, some capability that only administrators have. Regarding edit_usercapability, WordPress Capabilities: edit_user vs edit_users The … Read more

Adding user metadata to all users

The problem is that you’re using get_current_user_id();. There’s two reasons this is incorrect: The user being created is not necessarily the current user. For example, if an admin creates the user manually. user_register runs immediately after the user is created, but before the user is logged in. So when user_register runs for somebody registering on … Read more

users joined group count in buddypress

To get the group count, use groups_get_user_groups. Find it in: buddypress\bp-groups\bp-groups-functions.php In the members loop, the member id is provided via: bp_member_user_id() You will need to check the member-loop template to find out how to hook into the loop. Or overload that template in your child theme and add a do_action wherever you want it. … Read more

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