Replies
- Lefteris on December 11, 2022 at 9:39 pm in reply to: [Resolved] Send email to user that has been inactive for 2 months (adding a question) #47584
Hello Ravi
After some research in sql and change in my original code, i now need to just retrieve with a SQL query the latest post from each author so that i can use authors ID and published post_date of the post.
I’ve executed this
$posts = $wpdb->get_results( "SELECT post_author, post_title, post_date FROM ( SELECT * FROM $wpdb->posts ORDER BY post_date DESC ) X WHERE post_status='publish' AND post_type='post' GROUP BY post_author" );
but for some reason it just returns me all earliest posts of all authors and i cant figure out why?
Could you help me please 🙂
- Lefteris on December 10, 2022 at 10:16 am in reply to: [Resolved] Send PUT remote request with BuddyPress checkbox #47572
Hello Brajesh,
Thank you for your help 🙂
1. The end point looks like this https://ibb.co/y6Dv0t52. I am not sure how can i do that, could you please point out the code?
– add a fallback playlist id or return at the beginning (unfortunately it is not possible to add a fallback playlist but what you mean by return at the beginning?)
– make sure to check if ‘103’ exists in the $old_values/$new_values (i believe there is no need for this, since the ‘103’ will be always there)Thank you very much
- Lefteris on December 8, 2022 at 5:19 pm in reply to: [Resolved] Send PUT remote request with BuddyPress checkbox #47561
Hello Brajesh,
Thank you so much for your help 🙂
1. Some specific playlists are related with specific users, that is why i have this condition at the beginning.
2. After i have added the body parameter under the $dataPut it seems that i am one step better.
Now when i activate the checkbox i get to see the change triggered at the endpoint (which is good,it means that my security headers are working + PUT is also working), but after if i inactivate the checkbox it doesn’t set'is_enabled' => 'false'
. After some tests, i have realized that it doesn’t matter what state the checkbox is. If i just save the field it always sends'is_enabled' => 'true'
. I am not sure where the problem is.I believe that there is no mistake in the conditions
$old_values[103]['value'] !== $new_values[103]['value'] && empty( $new_values[103]['value'] )
and i double checked that the checkbox ID is 103.The code
function checkbox( $user_id, $posted_field_ids, $old_values, $new_values ) { if ( $user_id == 12 ) { $playlistId = 462; // The ID of the playlist of the user. } $argsPut = array( 'method' => 'PUT', 'headers' => array( 'Authorization' => 'Bearer {{32-CHARACTER ALPHANUMERIC KEY}}', 'Content-Type' => 'application/json', ), ) ; if ($old_values[103]['value'] !== $new_values[103]['value'] && !empty( $new_values[103]['value'] )) { $dataPut = wp_json_encode( array( 'is_enabled' => 'true' ) ); $argsPut['body'] = $dataPut; $request = wp_remote_request( 'https://endpoint/api/' . $playlistId, $argsPut ) ; // i am sure that i am doing something wrong with wp_remote_request if( is_wp_error( $request ) ) { return false; // Bail early } } elseif ($old_values[103]['value'] !== $new_values[103]['value'] && empty( $new_values[103]['value'] )) { $dataPut = wp_json_encode( array( 'is_enabled' => 'false' ) ); $argsPut['body'] = $dataPut; $request = wp_remote_request( 'https://endpoint/api/' . $playlistId, $argsPut ) ; if( is_wp_error( $request ) ) { return false; // Bail early } } } add_action( 'xprofile_updated_profile', 'checkbox', 10, 4 );
- Lefteris on November 28, 2022 at 3:15 pm in reply to: [Resolved] Hook when profile fields are updated from specific group. #47469
Thank you so much Ravi,
It works as it should!
- Lefteris on October 4, 2022 at 11:17 am in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46776
Hello Brajesh,
Thank you very much for your help. I do appreciate your time 🙂
I think i will just try to hide the tab with some css for the unwanted roles.Best Regards,
Lefteris - Lefteris on October 3, 2022 at 2:42 pm in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46765
Hello Brajesh,
Thank you for your help 🙂
I tested your code but still the problem remains. When the logged in user is ‘author’ and he visits a profile page of a ‘subscriber’, the nav_item is getting removed from his own profile dropdown menu.
Following, when a ‘subscriber’ visits a profile page of an ‘author’ he can see the nav_item registered on his own profile dropdown menu.Best Regards,
Lefteris - Lefteris on September 29, 2022 at 2:12 pm in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46705
Hello Brajesh,
Thank you very much for your reply 🙂
My theme is using a profile dropdown menu very similar like in your website https://ibb.co/641Q022.
I would like to create this tab just for 3 user roles (for example ‘editor’, ‘administrator’, ‘author’).
So basically everybody can see this tab on those 3 users profile,but only those 3 user roles have it.
But when the logged in user is ‘author’ and he visits a profile page of a ‘subscriber’, the nav_item is getting removed from his own profile dropdown menu.If you wish i can give you access to a stage site of mine to see the result.Please let me know.
Best Regards,
Lefteris - Lefteris on September 28, 2022 at 9:22 am in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46681
Hello Brajesh,
I am sorry for bothering. Could you check my comment above? How could i fix your code to work properly?
Best Regards,
Lefteris - Lefteris on September 22, 2022 at 2:34 pm in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46612
Hello Brajesh,
Thank you very much for your kind help.
I will cleanup the second part as you mentioned. However my main problem is about the certain roles tab creation.
Your code works correct as expected but there is one problem. When the user with role ‘editor’ visits a profile page of a user that is not in the ΄allowed roles΄ (for example with role ‘subscriber’) then the nav_item is getting removed also for him (that it shouldn’t, since he is with role ‘editor’).
I can see that because my theme has a drop-down profile menu in the right top corner section of the page, so this item is getting removed for the current logged in user. https://cdn2.wpbeginner.com/wp-content/uploads/2020/04/creating-a-submenu-1.png
I hope you could understand what i am trying to say 🙂
Best Regards,
Lefteris- This reply was modified 2 years, 2 months ago by Lefteris.
- Lefteris on September 22, 2022 at 8:09 am in reply to: [Resolved] Create a tab (nav_item) that can display custom post type items of user. #46607
Hello Brajesh,
Did you managed to have a check on the condition that i am trying to figure out (register the nav_tab only for specific roles)?
Best Regards,
Lefteris