Skip to:
Content
Pages
Categories
Search
Top
Bottom

Mark Particular Messages as Read

  • @creativesinside

    Participant

    We want to automatically mark a few messages as read based on their subject so that they do not show up in the unread_count number of messages.

    I have come up with this but I am not sure if I am even on the right path.

    function markcommentreadplease(){
    if ($message->subject == "comment on your post") { ?>
    <script type="text/javascript">
    jQuery($messages_new_message).removeClass("unread").addClass("read"); 
    </script><?php }}

    Or

    function markcommentreadplease(){
    if ($message->subject == "comment on your post") { ?>
    <script type="text/javascript">
    jQuery(this).removeClass("unread").addClass("read"); 
    </script><?php }}
    
    add_action( 'messages_new_message', 'markcommentreadplease' );

    Any ideas?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @henrywright

    Moderator

    The messages_mark_thread_read() function will mark a message thread as read. It accepts the thread ID. So, to mark read all new private messages if they have a given subject, you could do this:

    function creativesinside_mark_read( $message ) {
    
        // Be sure we're working with an array.
        if ( is_object( $message ) ) {
            $args = (array) $message;
        } else {
            $args = $message;
        }
    
        // Mark as read.
        if ( $args['subject'] == 'comment on your post' ) {
            messages_mark_thread_read( $args['thread_id'] );
        }
    }
    add_action( 'messages_message_sent', 'creativesinside_mark_read' );

    @creativesinside

    Participant

    You my friend are beautiful! 😀 😀

    Worked like a charm. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Mark Particular Messages as Read’ is closed to new replies.
Skip to toolbar