Alex Brearley
Forum Replies Created
-
AuthorPosts
-
Alex BrearleyParticipant
I appreciate sending a message afterwards forces the cache to be reset but this does not meet the requirements – I would like messages to be hidden and then made visible based on a business logic status change and not when a message happens to be sent. Desired behaviour:
1. General message exchange, some messages read and some unread.
2. business process reaches a particular status and message are all hidden and the unread message count has unread hidden messages removed.
3. business process reaches another status and message are unhidden and the unread message count now includes the count of those previously hidden messages.Currently, If I move the business process to a state where they are supposed to be hidden, the messages are hidden and the unread count seems to be correct. However, when I move the process to the state where messages are visible again, they don’t get shown until I send another message to that user again.
Alex BrearleyParticipantHiding on send won’t work as the act of hiding is the result of some business logic that is asynchronous to the act of sending a message in the first instance. Would it be possible to mark messages as read when they are hidden or somehow force the cached message count to be refreshed once the messages are hidden?
Alex BrearleyParticipantyes, you are right about $args :/ I’ve removed the child code for the time being. The child messages show if you chose the option to show each email rather than email thread. I have gone back to only showing email thread which resolves the issue.
I now have the following code but am still seeing the unread hidden messages being included in the count.
$this->loader->wp_add_filter('fep_message_query_args', array( $this->fep, 'cmdu_hide_message' ), 10, 2); $this->loader->wp_add_filter('fep_message_count_query_args', array( $this->fep, 'cmdu_hide_message' ), 10, 2);
public function cmdu_hide_message($args, $user_id) { // Admin users can see all if (! current_user_can('administrator')) { $args['post__not_in'] = $this->hide_mes_id(); } return $args; }
And inside private function hide_mes_id()
$not_post = array(); foreach ($findrefs as $ref) { array_push($not_post, $ref->mes_id); /* * $child_args = array( * 'post_parent' => $ref->mes_id, * 'post_type' => 'any', * 'numberposts' => - 1, * 'post_status' => 'any' * ); * $children = get_children($child_args); * * foreach ($children as $child) { * * array_push($not_post, $child); * } */ } return $not_post;
Alex 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?
Alex BrearleyParticipantExcellent, thank you
Alex 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?
Alex 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
Alex 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.
Alex BrearleyParticipantI can see what the issue is, should be if ( (‘send_reply’ === $cap) and not if ( (‘send_reply’ !== $cap)
I have also used wp_get_post_parent_id to get parent ID’s of reply messages to check those as well
Alex BrearleyParticipantSo I’ve tested this out and not quite what I wanted. If I attempt to view the first (parent) message, I get an error saying I do not have permission to view the message – what I wanted was to be able to view the message but not reply (read-only). Also, it has no affect on the children of the first message/post i.e. if I click on a reply message, I can view and reply again.
Alex 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?
Alex BrearleyParticipantusual question, how many arguments and what are they?
Alex BrearleyParticipantBefore messagebox is loaded so that I can hide messages before they are loaded
Alex BrearleyParticipantWorked in child theme. Turned out to be a typo in my wp_add_filter function that meant the num of args was not being passed – doh!
Alex BrearleyParticipantShould add this error occurs on every page load of the website – not when specifically using FEP
-
AuthorPosts