• First, thanks to Milan, the plugin author, for this brilliant initiave. I’m hoping bbpress will include a digest feature like bbPress Digest in the future.

    The hack to add / edit the message body is fairly simple. Again, it’s a hack, it may not be the most ingenious or embelished solution, but it works.

    The file that needs editing is bbpress-digest/inc/event.php

    My first step was to comment out line 188:
    // $item_placeholder = _x( '%1$s: %2$s', '1. Topic title 2. Topic URL', 'bbp-digest' );

    The $item_placeholder is a template for the message body. I wanted to include topics and replies in different text blocks and so the place holder variable was discarded.

    The bulk of the hack comes right after that, beginning with the foreach loop, on line 195.

    foreach ( $topic_ids as $topic_id ) {
      $all_topics_list .= sprintf( $item_placeholder, bbp_get_topic_title( $topic_id ), bbp_get_topic_last_reply_url( $topic_id ) );
      }

    In a few words, what I did was to replace the place holder variable inside the printf with a number of bbpress functions, formatting the message body in the string variable $all_topics_list:

    /* Go through all topics */
    				foreach ( $topic_ids as $topic_id ) {
    
    					if (bbp_is_reply($topic_id)) {
    					$reply_title = html_entity_decode(strip_tags(bbp_get_reply_title($topic_id)), ENT_NOQUOTES, 'UTF-8');
    					$reply_content = html_entity_decode(strip_tags(bbp_get_reply_content($topic_id)), ENT_NOQUOTES, 'UTF-8');
    					$reply_content = preg_replace( '/<br\s*\/?>/is', PHP_EOL, $reply_content  );
    					$reply_content = preg_replace( '/(?:<\/p>\s*<p>)/ism', PHP_EOL . PHP_EOL, $reply_content  );
    					$reply_content = html_entity_decode( strip_tags( $reply_content  ), ENT_NOQUOTES, 'UTF-8' );
    					$reply_author = bbp_get_reply_author_display_name($topic_id);
    					$reply_url = bbp_get_reply_permalink($topic_id);
    					$reply_date = bbp_get_reply_post_date($topic_id);
    					$lineprint = "-------------------";
    					$all_topics_list .= "$reply_title\n\nAuthor: $reply_author \n\nDate: $reply_date \n\n$reply_content \n\nGo to reply: $reply_url \n\n$lineprint \n\n";
    					}
    
    					if (bbp_is_topic($topic_id)) {
    					$topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8');
    					$topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8');
    					$topic_content = preg_replace( '/<br\s*\/?>/is', PHP_EOL, $topic_content  );
    					$topic_content = preg_replace( '/(?:<\/p>\s*<p>)/ism', PHP_EOL . PHP_EOL, $topic_content  );
    					$topic_content = html_entity_decode( strip_tags( $topic_content  ), ENT_NOQUOTES, 'UTF-8' );
    					$topic_author = bbp_get_topic_author_display_name($topic_id);
    					$topic_url = bbp_get_topic_permalink($topic_id);
    					$lineprint = "-------------------";
    					$all_topics_list .= "Topic: $topic_title\n\nAuthor: $topic_author \n\nDate: $topic_date \n\n$topic_content \n\nGo to topic: $topic_url \n\n$lineprint \n\n";
    					}
    
    				}

    Of course you may use a different set of bbpress functions in your template, according to your needs. There’s a very comprehensive list of bbpress functions on Hookr.io that will certainly come in handy.
    https://hookr.io/plugins/bbpress/2.5.8/functions/#index=a

    Right at the beginning of the foreach loop I added a conditional statement to include replies in the digest. And after that, a second conditinal for the topics post type.

    if (bbp_is_reply($topic)) {
    // your functions here
    $all_topicslist . = " $my_bbp_function_set "; //
    }

    The last step was to change the posts query function “get_topics()”. On line 288, change the value for the post_type parameter to include the reply post type:

    'post_type'      => array( bbp_get_topic_post_type(),bbp_get_reply_post_type() ), // bbPress topic & reply types

    The author used a meta query with “_bbp_last_active_time” topic meta to establish the time period refrence in his query. Because “_bbp_last_active_time” is exclusive for topics, keeping it in the query would exclude the reply post type. My way around this was to use date_query, keeping the set $time value as a time reference and “date” as the “orderby” value.

    See below what the edited query looks like, with the original meta query commented out.

    /* Setup arguments for topic query */
    		$topic_args = array(
    			'post_type'      => array( bbp_get_topic_post_type(),bbp_get_reply_post_type() ), // bbPress topic  & reply types
    			'posts_per_page' => -1, // All topics
    		//	'meta_key'       => '_bbp_last_active_time',
    			'fields'         => 'ids',
    			'orderby'        => 'date', // Order by _bbp_last_active_time (ie. from newest to oldest)
    			'post_status'    => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ), // All public statuses
    
    			'date_query' => array(
         array(
               'after' => '$time'
               )
         )
    
    		/*	'meta_query'     => array(
    				array(
    					'key' => '_bbp_last_active_time',
    					'value' => date( 'Y-m-d H:i:s', $time ), // Only active for period we are quering, last 24 hours or last 7 days, plus passed time since full hour
    					'compare' => '>',
    					'type' => 'DATETIME',
    				)
    			)
    		*/
    		);

    I hope this helps other plugin users like me and encourages Milan to keep up his good work. IMO this the best bbPress Digest plugin out there, really unmatched in its simplicity and performance.

    And it was really worth taking the time in hacking it a bit. I certainly hope the author can develop it further and keep it up to date. ??

    https://www.ads-software.com/plugins/bbpress-digest/

Viewing 1 replies (of 1 total)
  • Thread Starter Jo?o Miguel

    (@babaloo)

    Did I say “Mission Accomplished”?

    Sorry, but the date_query above is messed up! It will return all content in the forum’s history. The correct the date query is:

    'date_query' => array(
    array(
    'after' => date( 'Y-m-d H:i:s', $time ),
    'compare' => '>',
    'type' => 'DATETIME',
               )
         )

Viewing 1 replies (of 1 total)
  • The topic ‘[solved] Message Body Hack’ is closed to new replies.