/**
  * 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);
 }
 /**
  * Saves data.
  *
  * @param string $post_id Post id.
  */
 public function __save($post_id)
 {
     $post_type = WP_Recipe_Post_Type::get_instance()->get_post_type();
     WP_Recipe_Util::get_instance()->save_meta_box($post_type, $post_id, $this->slug);
 }
 /**
  * Adds a recipe reference to posts using the recipe.
  *
  * @param string $post_id Post id.
  * @param array $recipe_ids_used_in_post Recipe ids used in the post.
  */
 private function add_recipe_reference_to_posts_using_the_recipe($post_id, $recipe_ids_used_in_post)
 {
     $recipe_ids_used_in_post = array_unique($recipe_ids_used_in_post);
     foreach ($recipe_ids_used_in_post as $recipe_id) {
         if (WP_Recipe_Util::get_instance()->recipe_exists($recipe_id)) {
             $this->add_recipe_reference_to_post($post_id, $recipe_id);
         }
     }
 }
 /**
  * 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'));
 }
 /**
  * Adds a post referenced to recipes used in a post.
  *
  * @param string $post_id Post id.
  * @param array $recipe_ids_used_in_post Recipe ids used in the post.
  */
 private function add_post_reference_to_recipes_used_in_post($post_id, $recipe_ids_used_in_post)
 {
     foreach ($recipe_ids_used_in_post as $recipe_id) {
         if (WP_Recipe_Util::get_instance()->recipe_exists($recipe_id) && !$this->is_post_a_recipe_reference($post_id, $recipe_id)) {
             $this->add_post_reference_to_recipe($post_id, $recipe_id);
         }
     }
 }
Пример #8
0
 /**
  * Saves meta box.
  *
  * @param string $post_type Post type to save for. 
  * @param string $post_id Post id.
  * @param string $slug Slug of items to save.
  */
 public function save_meta_box($post_type, $post_id, $slug)
 {
     $wp_post_type_util = WP_Post_Type_Util::get_instance();
     if (!$wp_post_type_util->is_post_type_saving_post_meta($post_type)) {
         return;
     }
     $wp_recipe_util = WP_Recipe_Util::get_instance();
     $nonce = $wp_recipe_util->get_nonce($slug);
     if ($wp_post_type_util->can_save_post_meta($post_id, $slug, $nonce)) {
         $post_meta_key = $wp_recipe_util->get_post_meta_key($slug);
         $id = $wp_recipe_util->get_id($slug);
         update_post_meta($post_id, $post_meta_key, $_POST[$id]);
     }
 }