/** * Add special Simmer classes for recipes. * * @since 1.2.0 * @see post_class() * * @param array $classes The existing classes as generated by WordPress. * @param string|array $class Optional. Any custom classes passed by the post_class() function. * @param int|bool $recipe_id Optional. The current recipe ID. * @return array $classes The newly generated recipe classes. */ public function add_recipe_classes($classes, $class = '', $recipe_id = false) { if (simmer_get_object_type() !== get_post_type($recipe_id) || !$recipe_id) { return $classes; } $classes[] = 'simmer-recipe'; // Check for ingredients and add the appropriate classes. $ingredients = simmer_get_the_ingredients(); if (!empty($ingredients)) { $classes[] = 'simmer-has-ingredients'; $classes[] = 'simmer-ingredients-' . zeroise(count($ingredients), 2); } else { $classes[] = 'simmer-no-ingredients'; } // Check for instructions and add the appropriate classes. $instructions = simmer_get_the_instructions(); if (!empty($instructions)) { $classes[] = 'simmer-has-instructions'; $classes[] = 'simmer-instructions-' . zeroise(count($instructions), 2); } else { $classes[] = 'simmer-no-instructions'; } /** * Filter the recipe classes. * * @since 1.2.0 * * @param array $classes The generated recipe classes. * @param string $class Optional. Additional classes to to add, passed by the post_class function. * @param int $recipe_id Optional. The current recipe's ID. */ $classes = apply_filters('simmer_recipe_classes', $classes, $class, $recipe_id); return $classes; }
/** * Add the modal markup to the admin footer. * * @since 1.2.0 */ public function add_modal() { $current_screen = get_current_screen(); // Only load the modal when editing or creating a new recipe. if ('post' == $current_screen->base && $current_screen->post_type == simmer_get_object_type()) { include_once plugin_dir_path(__FILE__) . 'views/meta-boxes/bulk-add.php'; } }
/** * Get the front-end running. * * @since 1.3.0 */ public function __construct() { // Load the necessary files. $this->load_files(); /** * Load the styles class. */ $this->styles = new Simmer_Frontend_Styles(); /** * Load the scripts class. */ $this->scripts = new Simmer_Frontend_Scripts(); /** * Load the HTML classes class. */ $this->html_classes = new Simmer_Frontend_HTML_Classes(); // Add the necessary actions. $this->add_actions(); // Add the necessary filters. $this->add_filters(); // Store the simmer object type for reuse. $this->cpt = simmer_get_object_type(); }
<?php /** * The Recipe Base settings field. * * @since 1.0.0 * * @package Simmer\Settings */ ?> <code><?php echo esc_url(trailingslashit(home_url('/') . get_option('simmer_archive_base', simmer_get_archive_base()))); ?> </code> <input id="simmer_recipe_base" name="simmer_recipe_base" type="text" class="regular-text code" value="<?php echo sanitize_title(get_option('simmer_recipe_base', simmer_get_object_type())); ?> " />
/** * 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 (!is_singular(simmer_get_object_type())) { 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(); }
<span class="screen-reader-text"><?php _e('Close', 'simmer'); ?> </span> </button> </div> <div class="simmer-shortcode-modal-content"> <p class="simmer-shortcode-help"><?php _e('Select or search for a recipe name.', 'simmer'); ?> </p> <?php $recipes = get_posts(array('post_type' => simmer_get_object_type(), 'posts_per_page' => -1, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false)); ?> <?php if ($recipes) { ?> <select id="simmer_shortcode_recipe" name="simmer_shortcode_recipe" style="width: 100%"> <option value="0"><?php _e('Choose a recipe...', 'simmer'); ?> </option> <?php foreach ($recipes as $recipe) {
/** * Register the category taxonomy. * * @since 1.0.0 */ public function register_category_taxonomy() { $args = array('show_tagcloud' => false, 'show_admin_column' => true, 'hierarchical' => true, 'rewrite' => array('slug' => trailingslashit(simmer_get_archive_base()) . get_option('simmer_category_base', 'category'), 'with_front' => false)); /** * Filter the taxonomy args. * * @since 1.0.0 * @see register_taxonomy() for the available args. * * @param array $args { * The arguments that define the taxonomy's * labels and functionality. * } */ $args = apply_filters('simmer_register_category_args', $args); // Finally register the taxonomy. register_taxonomy(simmer_get_category_taxonomy(), simmer_get_object_type(), $args); /* * Better safe than sorry. * * @link http://codex.wordpress.org/Function_Reference/register_taxonomy#Usage */ register_taxonomy_for_object_type(simmer_get_category_taxonomy(), simmer_get_object_type()); }
/** * Display the widget on the front end. * * @since 1.1.0 * * @param array $args The sidebar args for the instance. * @param array $instance The instance and its settings. */ public function widget($args, $instance) { if (!isset($args['widget_id'])) { $widget_id = $this->id; } else { $widget_id = $args['widget_id']; } $sidebar_id = $args['id']; // Output the wrapper. echo $args['before_widget']; /** * Filter the settings for the instance. * * @since 1.1.0 * * @param array $instance The instance's settings. * @param string $widget_id The instance's ID. * @param string $sidebar_id The ID of the sidebar in which the instance is located. */ $instance = apply_filters('simmer_recent_recipes_widget_settings', $instance, $widget_id, $sidebar_id); /** * Filter the title for the instance. * * @since 1.1.0 * * @param string $title The instance's title. * @param string $widget_id The instance's ID. * @param string $sidebar_id The ID of the sidebar in which the instance is located. */ $title = apply_filters('simmer_recent_recipes_widget_title', $instance['title'], $widget_id, $sidebar_id); if ($title) { echo $args['before_title'] . $title . $args['after_title']; } // Set the recipe query args. $query_args = array('posts_per_page' => (int) $instance['number'], 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false); /** * Filter the recipe query args for the instance. * * @since 1.1.0 * * @param array $query_args The instance's recipe query args. * @param string $widget_id The instance's ID. * @param string $sidebar_id The ID of the sidebar in which the instance is located. */ $query_args = apply_filters('simmer_recent_recipes_widget_query_args', $query_args, $widget_id, $sidebar_id); // Override the above filter to ensure recipes are always queried. $query_args['post_type'] = simmer_get_object_type(); // Try to get the recipes. $recent_recipes = new WP_Query($query_args); /** * Execute before displaying the widget. * * @since 1.1.0 * * @param string $widget_id The instance's ID. * @param string $sidebar_id The ID of the sidebar in which the instance is located. */ do_action('simmer_before_recent_recipes_widget', $widget_id, $sidebar_id); // Output the main markup. include plugin_dir_path(__FILE__) . 'html/recent-recipes-widget.php'; /** * Execute after displaying the widget. * * @since 1.1.0 * * @param string $widget_id The instance's ID. * @param string $sidebar_id The ID of the sidebar in which the instance is located. */ do_action('simmer_after_recent_recipes_widget', $widget_id, $sidebar_id); // Close the wrapper. echo $args['after_widget']; }
/** * Add the published recipe count to the "At a Glance" dashboard widget. * * @since 1.3.3 * * @param array $elements The current at-a-glance items. * @return array $elements The new at-a-glance items. */ public function add_glance_recipe_count($elements) { $post_type = simmer_get_object_type(); // Get the number of recipes. $num_posts = wp_count_posts($post_type); if ($num_posts && $num_posts->publish) { $text = _n('%s Recipe', '%s Recipes', $num_posts->publish, 'simmer'); $text = sprintf($text, number_format_i18n($num_posts->publish)); $post_type_object = get_post_type_object($post_type); if ($post_type_object && current_user_can($post_type_object->cap->edit_posts)) { $text = sprintf('<a class="simmer-recipe-count" href="edit.php?post_type=%1$s">%2$s</a>', $post_type, $text); } else { $text = sprintf('<span class="simmer-recipe-count">%2$s</span>', $post_type, $text); } $elements[] = $text; } return $elements; }
/** * Remove a recipe's items when it is deleted. * * @since 1.3.0 * * @param int $recipe_id The recipe ID. */ public function delete_recipe_items($recipe_id) { if (!current_user_can('delete_posts')) { return; } if (simmer_get_object_type() !== get_post_type($recipe_id)) { return; } $items = simmer_get_recipe_items($recipe_id); foreach ($items as $item) { simmer_delete_recipe_item($item->recipe_item_id); } }