Home › Forums › Front End PM PRO › Hook to use before messages load
- This topic has 20 replies, 2 voices, and was last updated 6 years, 10 months ago by Shamim Hasan.
-
AuthorPosts
-
February 16, 2018 at 7:37 pm #11158Alex BrearleyParticipant
Hi Shamim,
Which hook is best to use to do something before messages in the inbox are loaded? I would like to create a function that hides a message based on business logic by changing the message post status to pending review from published. I can use the wordpress functions to do that, just want to make sure I use the correct FEP hook.
February 16, 2018 at 9:14 pm #11161Shamim HasanKeymasterYou want a hook when a message is sent or messagebox is loaded?
February 16, 2018 at 9:18 pm #11163Alex BrearleyParticipantBefore messagebox is loaded so that I can hide messages before they are loaded
February 16, 2018 at 9:21 pm #11165Shamim HasanKeymasterYou can use
fep_message_query_args
filter hookFebruary 16, 2018 at 11:24 pm #11169Alex BrearleyParticipantusual question, how many arguments and what are they?
February 17, 2018 at 11:21 am #11172Shamim HasanKeymasterit mainly pass 2 arguments ($args, $user_id). In $args there are lots of data as array. you can add or remove any data from here. Full list can be found in https://codex.wordpress.org/Class_Reference/WP_Query#Parameters
As you are working with code, better way to search the hook in code, so that you will get clear idea what is passing and how is passing. fep_message_query_args filter located in class-fep-message.php
February 19, 2018 at 8:04 pm #11235Alex BrearleyParticipantThis isn’t quite what I’m looking for. What I want to do is prevent a particular message being displayed in the inbox based on parent message ID. I think this function is high level filter for posts to display. Do you have any other ideas how I could do this?
February 19, 2018 at 9:01 pm #11253Shamim HasanKeymasterYou can use that filter like
add_filter( 'fep_message_query_args', function( $args ){ $args['post__not_in'] = array( 1,2,3); return $args; });
Where 1,2,3 is your parent messages ids.
February 20, 2018 at 2:07 pm #11300Alex BrearleyParticipantThanks – I also added
$args = array(
‘post_parent’ => $ref->mes_id,
‘post_type’ => ‘any’,
‘numberposts’ => – 1,
‘post_status’ => ‘any’
);
$children = get_children($args);foreach ($children as $child) {
array_push($not_post, $child);
}As it worked for the parent message but all the children were still shown.
February 20, 2018 at 5:48 pm #11324Shamim HasanKeymasterwhat is $not_post? where it shows children? what is full code you have added?
February 20, 2018 at 9:57 pm #11340Alex BrearleyParticipant$not_post = array();
foreach ($findrefs as $ref) {
array_push($not_post, $ref->mes_id);$args = array(
‘post_parent’ => $ref->mes_id,
‘post_type’ => ‘any’,
‘numberposts’ => – 1,
‘post_status’ => ‘any’
);
$children = get_children($args);foreach ($children as $child) {
array_push($not_post, $child);
}
}$args[‘post__not_in’] = $not_post;
$findrefs is an object that contains a list of parent message id
February 20, 2018 at 10:00 pm #11342Alex BrearleyParticipantI’ve also noticed that New message count and the New message banner that appears in the header is still showing even though the messages that are new are the ones I have hidden i.e. when I click on the messagebox I correctly get ‘No messages found. Try different filter.’ due to the messages being hidden, the MessageBox button still shows a count of messages unread (all hidden) and the banner in the header is also showing unread messages, again, all of which are hidden.
Is there a hook to adjust the number of unread messages count to take into account the messages that have been hidden?
February 21, 2018 at 4:27 pm #11391Shamim HasanKeymasterYou are overriding variable $args. Please change your arguments name to something else. Also you do not need to provide child messages ids.
count is cached for performance. Please use same function in hook
fep_message_count_query_args
also. It will be hard to maintain count properly if you do not invalid cache when ref ids change for any user.February 21, 2018 at 4:45 pm #11393Alex BrearleyParticipantNo, I’m not overriding $args – as per your snippet above, I return $args at the end and my code is updating 1 element of the $args array as per your snippet. From testing, using your code example, just passing the parent message ID did not hide the children replies which is why I then added in the message ID’s of the children as well.
Please can you expand on your statement about the cached message count. How do I use the hook to change it and maintain the count cache?
February 21, 2018 at 5:31 pm #11396Shamim HasanKeymasterYou have added
$args = array(
‘post_parent’ => $ref->mes_id,
‘post_type’ => ‘any’,
‘numberposts’ => – 1,
‘post_status’ => ‘any’
);
here you have declared $args which override original $args.In messagebox no child messages is shown, so where child messages shown?
Use your same function in both hook i have given, which will cache proper count.
-
AuthorPosts
You need to purchase ‘Front End PM PRO’ to create topic in this support forum.
If you already purchased ‘Front End PM PRO’ please LOGIN.