Tag Info

New answers tagged

1

First, you should know that current_user_can() only accepts capabilities, not roles, so you are using it wrong and you can end up with unexpected results. That being said, to exlude users form WP_User_Query you can use the exclude parameter: // Get current user data $user = wp_get_current_user(); // Check if current user is a subscriber if( ! empty( $user ...


-1

Following should works for you:- if( current_user_can('read')) { $exclude_user = array(); $exclude_user[] =get_current_user_id(); $args = array( 'role' => 'subscriber', 'exclude' => $exclude_user ); $user_query = new WP_User_Query( $args); foreach ( $user_query->results as $user ) { $mail=$user->user_email; ...


2

You can try using wp_insert_post_data for the task. Something like: function assign_new_post_to_specific_author( $data , $postarr ) { // Where author_ID is the ID of the author you want to assign the new post $data['post_author'] = author_ID; return $data; } add_filter( 'wp_insert_post_data', 'assign_new_post_to_specific_author', '99', 2 ); ...


0

Doing forms with separate PHP files isn't exactly the WordPress way. I'm fully aware that this isn't an answer to your concrete question, but below is an minimal example on how to do it differently - maybe in the future at least. You need to fill the gaps in the code to make this work. If finished upload the plug-in to wp-content/plugins/ and activate it. To ...


0

I feel like this is close. Just not firing correctly. add_action( 'woocommerce_order_status_completed', 'gt_add_user_to_group' ); function gt_add_user_to_group( $order_id ) { $order = new WC_Order( $order_id ); $coupon_codes = $order->get_used_coupons(); // Returns array of coupon codes $user_id = $order->get_user_id(); $items = ...


0

You have destroyed a significant section of your database. Unless you have a backup you cannot get it back. What happened when you changed the varchar to an int was that every entry not recognized as an integer was converted to 0. You can see that in your screenshot. That is not reversible. Data was lost. In the future: Make a backup Don't mess with ...


0

For me Hameedullah Khan answer worked well. I've made just a little fix because my new fields have broken the page layout. So in the jquery code I've added jQuery(document).ready(function($) { field = $('#custom_user_field_row').remove(); field.insertBefore('#password'); ...


0

Using plugins like Paid Memberships PRO or s2member would be easiest solution for your purpose. You can create new user group and there capabilities. After that you can select which user group can see your post.


2

You can use the set_user_role hook, that will only fire when the user role changes: add_action( 'set_user_role', function( $user_id, $role, $old_roles ) { // Your code ... }, 10, 3 ); If you want to restrict this to a profile update, you can use: add_action( 'set_user_role', function( $user_id ) { add_action( 'profile_update', function( ...


0

I got it to work by first checking if the user was logged in using: is_user_logged_in().


0

You can try to inject an autocomplete attribute into the form element on that page. There is a dedicated action for that: user_edit_form_tag. add_action( 'user_edit_form_tag', function() { print ' autocomplete="off"'; }); If that doesn't help – and it looks like the new IE has a bug here – you could try the solution from this Stack Overflow answer. ...


0

After some further research I have used WP_List_Table class for this. I had to add buttons and links myself to make it look like users.php but it wasn't much of work.


0

Ok i solved with this way: // Redirect guest users function login_redirect() { global $pagenow; // If user is not loged in and not in the login page if(!is_user_logged_in() && $pagenow != 'wp-login.php') auth_redirect(); } add_action( 'wp', 'login_redirect' );


4

Wait for the action plugins_loaded before you create the class instance. The pluggable functions are loaded at this time. From wp-settings.php: /** * Fires once activated plugins have loaded. * * Pluggable functions are also available at this point in the loading order. * * @since 1.5.0 */ do_action( 'plugins_loaded' ); I would even wait for ...


1

I think the use of meta_query is in order: $user_query = new WP_User_Query( array( 'meta_query'=> array( array( 'key'=> 'birthday', 'compare' => 'NOT EXISTS' ) ) ) ); Basically, this looks for all users where the meta key of birthday doesn't have a value ...



Top 50 recent answers are included