/** * Gets instance of class. * * @return WP_Recipe Instance of the class. */ public static function get_instance() { if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Enqueues scripts. * * @param $queue array List of enqueued Grunticon assets. * @return array Filtered list of enqueued Grunticon assets. */ function __enqueue_scripts($queue) { $wp_recipe = WP_Recipe::get_instance(); $wp_url_util = WP_Url_Util::get_instance(); $wp_grunticon_options = new WP_Grunticon_Options($wp_url_util->convert_absolute_path_to_root_path(realpath(__DIR__ . '/../admin/css/images')), 'svg.css', 'png.css', 'fallback.css', $wp_recipe->get_version()); array_push($queue, $wp_grunticon_options); return $queue; }
/** * Initializes view. */ public function __initialize() { $icon = WP_Image_Util::get_instance()->generate_datauri(realpath(__DIR__ . '/../admin/images/data/recipes.svg')); $slug = WP_Recipe::get_instance()->get_slug(); $labels = array('add_new_item' => _x('Add New Recipe', 'recipe custom post type add new item', $slug), 'all_items' => _x('All Recipes', 'recipe custom post type all items', $slug), 'edit_item' => _x('Edit Recipe', 'recipe custom post type edit item', $slug), 'menu_name' => _x('Recipes', 'recipe custom post type menu name', $slug), 'name' => _x('Recipes', 'recipe custom post type name', $slug), 'new_item' => _x('New Recipe', 'recipe custom post type new item', $slug), 'not_found' => _x('No recipes found', 'recipe custom post type not found', $slug), 'not_found_in_trash' => _x('No recipes found in the trash', 'recipe custom post type not found in trash', $slug), 'search_items' => _x('Search Recipes', 'recipe custom post type search items', $slug), 'singular_name' => _x('Recipe', 'recipe custom post type singular name', $slug), 'view_item' => _x('View Recipe', 'recipe custom post type view item', $slug)); $args = array('description' => _x('A place to collect all your delicious recipes', 'recipe custom post type description', $slug), 'hierarchical' => false, 'labels' => $labels, 'menu_icon' => $icon, 'menu_position' => 5, 'public' => true, 'supports' => array('comments', 'editor', 'revisions', 'thumbnail', 'title')); register_post_type(WP_Recipe_Post_Type::get_instance()->get_post_type(), $args); }
/** * Enqueues styles. */ public function __enqueue_styles() { $wp_enqueue_util = WP_Enqueue_Util::get_instance(); $wp_recipe = WP_Recipe::get_instance(); $handle = $wp_recipe->get_slug() . '-styles'; $relative_path = __DIR__ . '/../site/css/'; $filename = 'wp-recipe.min.css'; $filename_debug = 'wp-recipe.css'; $dependencies = array(); $version = $wp_recipe->get_version(); $options = new WP_Enqueue_Options($handle, $relative_path, $filename, $filename_debug, $dependencies, $version); $wp_enqueue_util->enqueue_style($options); }
/** * Enqueues styles. */ public function __enqueue_styles() { $wp_post_type_util = WP_Post_Type_Util::get_instance(); $wp_recipe = WP_Recipe::get_instance(); $post_type = WP_Recipe_Post_Type::get_instance()->get_post_type(); if ($wp_post_type_util->is_post_type_add_or_edit_screen($post_type)) { $wp_enqueue_util = WP_Enqueue_Util::get_instance(); $handle = $wp_recipe->get_slug() . '-admin-styles'; $relative_path = __DIR__ . '/../admin/css/'; $filename = 'recipe-post-type.min.css'; $filename_debug = 'recipe-post-type.css'; $dependencies = array(); $options = new WP_Enqueue_Options($handle, $relative_path, $filename, $filename_debug, $dependencies, $wp_recipe->get_version()); $wp_enqueue_util->enqueue_style($options); } }
/** * Renders recipe index item. * * @param $recipe_id string Recipe id. */ public function render($recipe_id) { $wp_recipe = WP_Recipe::get_instance(); $post_meta_key = WP_Recipe_Cross_Reference_Posts::get_instance()->get_post_meta_key(); $post_references = get_post_meta($recipe_id, $post_meta_key); if (empty($post_references)) { return; } $permalink = get_permalink($post_references[0]); $title = get_the_title(); $link_title = __('View recipe for', $wp_recipe->get_slug()) . ' ' . $title; echo '<li>'; echo '<a href="' . $permalink . '" rel="bookmark" title="' . $link_title . '">'; echo $title; echo '</a>'; echo '</li>'; }
/** * Renders shortcode. */ public function render() { global $post; echo '<ul class="recipe-controls">'; if (shortcode_exists('pinit')) { echo '<li>'; echo do_shortcode('[pinit]'); echo '</li>'; } $print_link = add_query_arg('print-recipe', '', get_permalink($post->ID)); echo '<li>'; echo '<a class="recipe-print" href="' . $print_link . '">'; echo __('Print Recipe', WP_Recipe::get_instance()->get_slug()); echo '</a>'; echo '</li>'; echo '</ul>'; }
/** * Enqueues bundled scripts. */ private function enqueue_bundled_scripts() { $wp_enqueue_util = WP_Enqueue_Util::get_instance(); $wp_recipe = WP_Recipe::get_instance(); $handle = $wp_recipe->get_slug() . '-scripts'; $relative_path = __DIR__ . '/../site/js/'; $filename = 'bundle.min.js'; $filename_debug = 'bundle.concat.js'; $dependencies = array(); $version = $wp_recipe->get_version(); $styles = array($wp_enqueue_util->get_source_to_enqueue(__DIR__ . '/../site/css/', 'wp-recipe-print.min.css', 'wp-recipe-print.css')); $styles = apply_filters('wp_recipe_enqueue_print_styles', $styles); $data = array('print' => array('styles' => $styles)); $options = new WP_Enqueue_Options($handle, $relative_path, $filename, $filename_debug, $dependencies, $version, true); $localization_name = WP_Recipe_Util::get_instance()->get_id($wp_recipe->get_slug()); $options->set_localization($localization_name, $data); $wp_enqueue_util->enqueue_script($options); }
/** * Enqueues bundled scripts. */ private function enqueue_bundled_scripts() { $wp_enqueue_util = WP_Enqueue_Util::get_instance(); $wp_recipe = WP_Recipe::get_instance(); $wp_recipe_ingredients = WP_Recipe_Ingredients::get_instance(); $wp_recipe_ingredients_group = WP_Recipe_Ingredients_Group::get_instance(); $handle = $wp_recipe->get_slug() . '-admin-script'; $relative_path = __DIR__ . '/../admin/js/'; $filename = 'bundle.min.js'; $filename_debug = 'bundle.concat.js'; $dependencies = array('underscore'); $group_keys = $wp_recipe_ingredients_group->get_keys(); $new_group = array($group_keys['group'] => ''); $data = array('ingredient' => array('classes' => $wp_recipe_ingredients->get_classes(), 'group' => array('classes' => $wp_recipe_ingredients_group->get_classes(), 'keys' => $group_keys, 'markup' => $wp_recipe_ingredients_group->generate_admin_markup($new_group)), 'id' => WP_Recipe_Util::get_instance()->get_id($wp_recipe_ingredients->get_slug()), 'markup' => $wp_recipe_ingredients->generate_admin_markup())); $options = new WP_Enqueue_Options($handle, $relative_path, $filename, $filename_debug, $dependencies, $wp_recipe->get_version(), true); $localization_name = WP_Recipe_Util::get_instance()->get_id($wp_recipe->get_slug()); $options->set_localization($localization_name, $data); $wp_enqueue_util->enqueue_script($options); }
/** * Saves data. */ public function __save() { global $post; if (empty($post) || !array_key_exists('content', $_POST)) { return; } $post_id = $post->ID; $wp_recipe = WP_Recipe::get_instance(); $wp_recipe_util = WP_Recipe_Util::get_instance(); $post_references = WP_Recipe_Cross_Reference_Posts::get_instance(); $recipe_references = WP_Recipe_Cross_Reference_Recipes::get_instance(); /* * Need to grab the content from `$_POST` and not the `global post` because * the `global post` contains the existing post information and the `$_POST` * contains the new information being saved. */ $shortcode = $wp_recipe_util->get_shortcode($wp_recipe->get_slug()); $recipe_ids = $wp_recipe_util->get_shortcode_attribute_values($_POST['content'], $shortcode, 'id'); $post_references->update($post_id, $recipe_ids); $recipe_references->update($post_id, $recipe_ids); }
/** * Gets taxonomy options. */ public function get_taxonomy_options() { $domain = WP_Recipe::get_instance()->get_slug(); return new WP_Taxonomy_Options(__('Course', $domain), __('Courses', $domain), $this->get_slug(), WP_Recipe_Post_Type::get_instance()->get_post_type()); }
/** * Initialize class. */ public function __construct() { $shortcode = WP_Recipe_Util::get_instance()->get_shortcode(WP_Recipe::get_instance()->get_slug()); add_shortcode($shortcode, array($this, '__render')); }
/** * Gets taxonomy options. */ public function get_taxonomy_options() { $domain = WP_Recipe::get_instance()->get_slug(); return new WP_Taxonomy_Options(__('Ingredient', $domain), __('Ingredients', $domain), $this->get_slug(), WP_Recipe_Post_Type::get_instance()->get_post_type(), false); }