Wrong add_template_part implementation and handling of filters
-
The following implementation seems wrong to me regarding the handling of the filters. The output of the filters is added to the $output variable which seems to be correct. But in the end this variable is not used, but ob_get_clean() is returned. Instead ob_end_clean() should be called and $output should be returned. Current workaround: Use echo in the filter methods, but that’s not how filters should be used.
protected function add_template_part( $ic_posts, $singles = false ) { if ( $singles ) { setup_postdata( $ic_posts ); } else { $ic_posts->the_post(); } $output = ''; ob_start(); $output .= apply_filters( 'posts_in_page_pre_loop', '' ); require ( $file_path = self::has_theme_template() ) ? $file_path // use template file in theme : POSTSPAGE_DIR . '/posts_loop_template.php'; // use default plugin template file $output .= ob_get_contents(); $output .= apply_filters( 'posts_in_page_post_loop', '' ); return ob_get_clean(); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Wrong add_template_part implementation and handling of filters’ is closed to new replies.