function grfwp_reviews_shortcode($atts) { // We must disable the automatic append to content filter while we're // rendering the shortcode to prevent it from displaying twice global $grfwp_controller; remove_action('the_content', array($grfwp_controller, 'append_to_content')); $output = grfwp_print_reviews(shortcode_atts(array('review' => null, 'category' => null, 'random' => false, 'limit' => null, 'cycle' => false, 'excerpt' => false), $atts)); // Restore the_content filter add_action('the_content', array($grfwp_controller, 'append_to_content')); return $output; }
/** * Transform review $content variable to output review * @since 0.1 */ function append_to_content($content) { global $post; if (!in_the_loop() || !is_main_query() || is_search() || GRFWP_REVIEW_POST_TYPE !== $post->post_type) { return $content; } // Allow overrides to disable the automatic append to content filter if (!apply_filters('grfwp_append_to_content', true)) { return $content; } // We must disable this filter while we're rendering the reiew in order // to prevent it from falling into a recursive loop with each review's // content. remove_action('the_content', array($this, 'append_to_content')); $args = array('review' => $post->ID); $args = apply_filters('grfwp_post_content_args', $args); $content = grfwp_print_reviews($args); // Restore this filter add_action('the_content', array($this, 'append_to_content')); return $content; }