Hook to use before messages load


Home Forums Front End PM PRO Hook to use before messages load

This topic is: Not Resolved
Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #11158
    Alex Brearley
    Participant

    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.

    #11161
    Shamim Hasan
    Keymaster

    You want a hook when a message is sent or messagebox is loaded?

    #11163
    Alex Brearley
    Participant

    Before messagebox is loaded so that I can hide messages before they are loaded

    #11165
    Shamim Hasan
    Keymaster

    You can use fep_message_query_args filter hook

    #11169
    Alex Brearley
    Participant

    usual question, how many arguments and what are they?

    #11172
    Shamim Hasan
    Keymaster

    it 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

    #11235
    Alex Brearley
    Participant

    This 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?

    #11253
    Shamim Hasan
    Keymaster

    You 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.

    #11300
    Alex Brearley
    Participant

    Thanks – 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.

    #11324
    Shamim Hasan
    Keymaster

    what is $not_post? where it shows children? what is full code you have added?

    #11340
    Alex Brearley
    Participant

    $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

    #11342
    Alex Brearley
    Participant

    I’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?

    #11391
    Shamim Hasan
    Keymaster

    You 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.

    #11393
    Alex Brearley
    Participant

    No, 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?

    #11396
    Shamim Hasan
    Keymaster

    You 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.

Viewing 15 posts - 1 through 15 (of 21 total)

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.