/** * Add the recipe display to the bottom of a singular recipe's content. * * @since 1.2.0 * * @param string $content The TinyMCE content. */ public function append_recipe($content) { if (!$this->can_append_recipe()) { return $content; } ob_start(); echo '<div class="simmer-recipe-description" itemprop="description">'; echo $content; echo '</div><!-- .simmer-recipe-description -->'; do_action('simmer_before_recipe', get_the_ID()); simmer_get_template_part('recipe'); do_action('simmer_after_recipe', get_the_ID()); return ob_get_clean(); }
/** * Build the [recipe] shortcode. * * This shortcode allows users to embed recipes * in their posts & pages. * * @since 1.0.0 * * @param array $args The available args. * 'id' => A recipe ID. * @return object The recipe HTML. */ public function display_shortcode($args) { global $post; // Set the default args. $defaults = array('id' => 0); // Parse the user args, if any. $args = shortcode_atts($defaults, $args); // Setup the $post object for setup_postdata(). $post = get_post($args['id']); // If no recipe exists with the passed ID, bail. if (is_null($post)) { return; } ob_start(); setup_postdata($post); /** * Allow others to execute code before including the template file. * * @since 1.0.0 */ do_action('simmer_before_recipe_shortcode', $post); // Include the template file. simmer_get_template_part('recipe', 'shortcode'); /** * Allow others to execute code after including the template file. * * @since 1.0.0 */ do_action('simmer_after_recipe_shortcode', $post); // Reset the $post global. wp_reset_postdata(); return ob_get_clean(); }