jilllynndesign
Forum Replies Created
-
AuthorPosts
-
jilllynndesignParticipant
Found the solution! FacetWP includes this documentation:
Pass authentication data through REST API requests:
https://facetwp.com/pass-authentication-data-through-rest-api-requests/I needed to add the following code and now things work as they should:
/* Please note that caching may interfere with the NONCE, causing ajax requests to fail. Please DISABLE CACHING for facet pages, or set the cache expiration to < 12 hours! */ add_action( 'wp_footer', function() { ?> <script> (function($) { $(function() { FWP.hooks.addFilter('facetwp/ajax_settings', function(settings) { settings.headers = { 'X-WP-Nonce': FWP_JSON.nonce }; return settings; }); }); })(jQuery); </script> <?php }, 100 );
jilllynndesignParticipantAh, so it should show MY user id when I’m viewing.
jilllynndesignParticipantI haven’t yet, but you’ve pointed me in the right direction. If I can make get_current_user_id() return the same user number as UPT()->get_user_id(), then the Send Message link should work on filtering/pagination, correct?
jilllynndesignParticipantAh, get_current_user_id() is returning 0 when filtering/pagination is in use. It returns correctly on page load/refresh.
jilllynndesignParticipantYes, UPT()->get_user_id() is returning the correct user id.
And, I added an else statement which is echoing whether filters/pagination are used.
I’m attaching two screenshots in case that helps.
Here is the relevant code:
<?php echo UPT()->get_user_id(); ?><br> <?php if ( fep_current_user_can( 'send_new_message_to', UPT()->get_user_id() )) { ?> <a class="text-link" href="<?php echo fep_query_url('newmessage', array('fep_to' => UPT()->get_user_id() ) ); ?>">Send Message</a> <?php } else { ?> This is an else statement test <?php } ?>
Attachments:You must be logged in to view attached files.jilllynndesignParticipantHey Shamin – I have one more thing regarding the FacetWP + Send Message link integration I was hoping you could help me with.
The Send Message link that looks like this…
<?php if ( fep_current_user_can( 'send_new_message_to', UPT()->get_user_id() )) { ?> <a class="text-link" href="<?php echo fep_query_url('newmessage', array('fep_to' => UPT()->get_user_id() ) ); ?>">Send Message</a> <?php } ?>
…works great on page refresh. BUT, when used in conjunction with FacetWP’s pagination or filtering, it doesn’t show up.
I need to wrap it in ‘facet-loaded’. Here’s an example using this to reinitialize Jetpack’s Lazy Load after an ajax refresh:
<script> (function($) { $(document).on('facetwp-loaded', function() { jetpackLazyImagesModule( $ ); }); })(jQuery); </script>
Can you help me figure out what needs to be included for Front End PM to reinitialize after an ajax refresh?
October 27, 2020 at 1:50 am in reply to: Add a message when user has unchecked “Allow others to send me messages” #41537jilllynndesignParticipantWorks perfectly. Thank you!
October 20, 2020 at 8:28 pm in reply to: Don’t show users in New Message TO dropdown if messages not allowed by user #41459jilllynndesignParticipantThat worked perfectly. Thank you!!
jilllynndesignParticipantNevermind, I figured it out! I had to login as a different user to test it out. Then I could see the ‘Send Message’ link on my other user.
Apparently, you can’t message yourself hence the link not showing up. LOL 🙂
Thank you SO MUCH for your help, and sorry for the troubles!
jilllynndesignParticipantSorry, I included the wrong code. Here’s the correct one I’m using:
<?php if ( fep_current_user_can( 'send_new_message_to', UPT()->get_user_id() )) { ?> <a class="text-link" href="<?php echo fep_query_url('newmessage', array('fep_to' => UPT()->get_user_id() ) ); ?>">Send Message</a> <?php } ?>
jilllynndesignParticipantThat hides the link for everyone. But the link doesn’t display if the receiver has unchecked “Allow others to send me messages?” in Settings.
<?php if ( fep_current_user_can( 'send_new_message_to', $attendee_id )) { ?> <a class="text-link" href="<?php echo fep_query_url('newmessage', array('fep_to' => UPT()->get_user_id() ) ); ?>">Send Message</a> <?php } ?>
jilllynndesignParticipantThanks for the tip on the back ticks!
If receiver has unchecked “Allow others to send me messages?” in Settings, I want to disable/hide:
<a class="text-link" href="<?php echo fep_query_url('newmessage', array('fep_to' => $attendee_display_name ) ); ?>">Send Message</a>
jilllynndesignParticipantUh, my code keeps getting cut off and I can’t seem to Edit my reply.
<?php
$attendee_info = get_userdata(UPT()->get_user_id());
$attendee_display_name = $attendee_info->user_nicename;
} ?><?php if (fep_current_user_can( ‘send_new_message’ )) { ?>
$attendee_display_name ) ); ?>”>Send Message
<?php } ?>jilllynndesignParticipantI added the PHP but it isn’t working to remove the link. Here’s the entire code:
<?php
$attendee_info = get_userdata(UPT()->get_user_id());
$attendee_display_name = $attendee_info->user_nicename;
} ?><?php if (fep_current_user_can( ‘send_new_message’ )) { ?>
$attendee_display_name ) ); ?>”>Send Message
<?php } ?>The get_userdata(UPT()->get_user_id()); comes from FacetWP’s User Post Type plugin as I’m using it to create an attendee listing.
-
AuthorPosts