/** * Handles saving of recipes */ public function save($id, $post) { if ($post->post_type == 'recipe') { if (!isset($_POST['recipe_meta_box_nonce']) || !wp_verify_nonce($_POST['recipe_meta_box_nonce'], 'recipe')) { return $id; } $recipe = new WPURP_Recipe($post); $searchable_recipe = $recipe->title(); $searchable_recipe .= ' - '; $searchable_recipe .= $recipe->description(); $searchable_recipe .= ' - '; if ($recipe->has_ingredients()) { $previous_group = null; foreach ($recipe->ingredients() as $ingredient) { $group = isset($ingredient['group']) ? $ingredient['group'] : ''; if ($group !== $previous_group && $group) { $searchable_recipe .= $group . ': '; $previous_group = $group; } $searchable_recipe .= $ingredient['ingredient']; if (trim($ingredient['notes']) !== '') { $searchable_recipe .= ' (' . $ingredient['notes'] . ')'; } $searchable_recipe .= ', '; } } if ($recipe->has_instructions()) { $previous_group = null; foreach ($recipe->instructions() as $instruction) { $group = isset($instruction['group']) ? $instruction['group'] : ''; if ($group !== $previous_group && $group) { $searchable_recipe .= $group . ': '; $previous_group = $group; } $searchable_recipe .= $instruction['description'] . '; '; } } $searchable_recipe .= ' - '; $searchable_recipe .= $recipe->notes(); // Prevent shortcodes $searchable_recipe = str_replace('[', '(', $searchable_recipe); $searchable_recipe = str_replace(']', ')', $searchable_recipe); $post_content = preg_replace("/<div class=\"wpurp-searchable-recipe\"[^<]*<\\/div>/", "", $post->post_content); // Backwards compatibility $post_content = preg_replace("/\\[wpurp-searchable-recipe\\][^\\[]*\\[\\/wpurp-searchable-recipe\\]/", "", $post_content); $post_content .= '[wpurp-searchable-recipe]'; $post_content .= htmlentities($searchable_recipe); $post_content .= '[/wpurp-searchable-recipe]'; remove_action('save_post', array($this, 'save'), 15, 2); wp_update_post(array('ID' => $recipe->ID(), 'post_content' => $post_content)); update_post_meta($recipe->ID(), 'wpurp_text_search_3', time()); add_action('save_post', array($this, 'save'), 15, 2); } }
public function excerpt_filter($content) { $ignore_query = !in_the_loop() || !is_main_query(); if (apply_filters('wpurp_recipe_content_loop_check', $ignore_query)) { return $content; } if (get_post_type() == 'recipe') { remove_filter('get_the_excerpt', array($this, 'excerpt_filter'), 10); $recipe = new WPURP_Recipe(get_post()); $excerpt = $recipe->excerpt(); $post_content = $recipe->post_content(); $post_content = trim(preg_replace("/\\[wpurp-searchable-recipe\\][^\\[]*\\[\\/wpurp-searchable-recipe\\]/", "", $post_content)); if ($post_content == '' && empty($excerpt)) { $content = $recipe->description(); } else { if ($content == '') { $content = get_the_excerpt(); } } $content = apply_filters('wpurp_output_recipe_excerpt', $content, $recipe); add_filter('get_the_excerpt', array($this, 'excerpt_filter'), 10); } return $content; }
<?php // Recipe should never be null. Construct just allows easy access to WPURP_Recipe functions in IDE. if (is_null($recipe)) { $recipe = new WPURP_Recipe(0); } if (!isset($required_fields)) { $required_fields = array(); } ?> <script> function autoSuggestTag(id, type) { <?php if (WPUltimateRecipe::option('disable_ingredient_autocomplete', '') !== '1') { ?> jQuery('#' + id).suggest("<?php echo get_bloginfo('wpurl'); ?> /wp-admin/admin-ajax.php?action=ajax-tag-search&tax=" + type); <?php } ?> } </script> <input type="hidden" name="recipe_meta_box_nonce" value="<?php echo wp_create_nonce('recipe'); ?> " /> <div class="recipe-general-container"> <h4><?php
<?php $args = array('post_type' => 'recipe', 'post_status' => 'any', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 100, 'meta_query' => array(array('key' => 'wpurp_text_search', 'compare' => 'NOT EXISTS'))); $query = new WP_Query($args); if ($query->have_posts()) { $posts = $query->posts; foreach ($posts as $post) { $recipe = new WPURP_Recipe($post); $searchable_recipe = $recipe->title(); $searchable_recipe .= ' - '; $searchable_recipe .= $recipe->description(); $searchable_recipe .= ' - '; if ($recipe->has_ingredients()) { $previous_group = null; foreach ($recipe->ingredients() as $ingredient) { $group = isset($ingredient['group']) ? $ingredient['group'] : ''; if ($group !== $previous_group && $group) { $searchable_recipe .= $group . ': '; $previous_group = $group; } $searchable_recipe .= $ingredient['ingredient']; if (trim($ingredient['notes']) !== '') { $searchable_recipe .= ' (' . $ingredient['notes'] . ')'; } $searchable_recipe .= ', '; } } if ($recipe->has_instructions()) { $previous_group = null; foreach ($recipe->instructions() as $instruction) { $group = isset($instruction['group']) ? $instruction['group'] : '';
/** * Handles saving of recipes */ public function save($id, $post) { if ($post->post_type == 'recipe') { if (!isset($_POST['recipe_meta_box_nonce']) || !wp_verify_nonce($_POST['recipe_meta_box_nonce'], 'recipe')) { return $id; } $recipe = new WPURP_Recipe($post); $fields = $recipe->fields(); // Make sure the recipe_title meta is present if (!isset($_POST['recipe_title'])) { $_POST['recipe_title'] = $recipe->title(); } else { if ($_POST['recipe_title'] == '') { $_POST['recipe_title'] = $post->post_title; } } // TODO Refactor saving of fields foreach ($fields as $field) { $old = get_post_meta($recipe->ID(), $field, true); $new = isset($_POST[$field]) ? $_POST[$field] : null; // Field specific adjustments if (isset($new) && $field == 'recipe_ingredients') { $ingredients = array(); $non_empty_ingredients = array(); foreach ($new as $ingredient) { if (trim($ingredient['ingredient']) != '') { $term = term_exists($ingredient['ingredient'], 'ingredient'); if ($term === 0 || $term === null) { $term = wp_insert_term($ingredient['ingredient'], 'ingredient'); } if (is_wp_error($term)) { if (isset($term->error_data['term_exists'])) { $term_id = intval($term->error_data['term_exists']); } else { var_dump($term); } } else { $term_id = intval($term['term_id']); } $ingredient['ingredient_id'] = $term_id; $ingredients[] = $term_id; $ingredient['amount_normalized'] = $this->normalize_amount($ingredient['amount']); $non_empty_ingredients[] = $ingredient; } } wp_set_post_terms($recipe->ID(), $ingredients, 'ingredient'); $new = $non_empty_ingredients; } elseif (isset($new) && $field == 'recipe_instructions') { $non_empty_instructions = array(); foreach ($new as $instruction) { if ($instruction['description'] != '' || isset($instruction['image']) && $instruction['image'] != '') { $non_empty_instructions[] = $instruction; } } $new = $non_empty_instructions; } elseif (isset($new) && $field == 'recipe_servings') { update_post_meta($recipe->ID(), 'recipe_servings_normalized', $this->normalize_servings($new)); } elseif (isset($new) && $field == 'recipe_rating') { $term_name = intval($new) == 1 ? $new . ' ' . __('star', 'wp-ultimate-recipe') : $new . ' ' . __('stars', 'wp-ultimate-recipe'); wp_set_post_terms($recipe->ID(), $term_name, 'rating'); } // Update or delete meta data if changed if (isset($new) && $new != $old) { update_post_meta($recipe->ID(), $field, $new); if ($field == 'recipe_ingredients' && WPUltimateRecipe::is_addon_active('nutritional-information') && WPUltimateRecipe::option('nutritional_information_notice', '1') == '1' && current_user_can(WPUltimateRecipe::option('nutritional_information_capability', 'manage_options'))) { $notice = '<strong>' . $_POST['recipe_title'] . ':</strong> <a href="' . admin_url('edit.php?post_type=recipe&page=wpurp_nutritional_information&limit_by_recipe=' . $recipe->ID()) . '">' . __('Update the Nutritional Information', 'wp-ultimate-recipe') . '</a>'; WPUltimateRecipe::get()->helper('notices')->add_admin_notice($notice); } } elseif ($new == '' && $old) { delete_post_meta($recipe->ID(), $field, $old); } } $this->update_recipe_terms($recipe->ID()); } }
$query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); global $post; $servings = get_post_meta($post->ID, 'user-menus-global-servings', true); $recipes = get_post_meta($post->ID, 'user-menus-recipe-ids'); $recipes = isset($recipes[0]) ? $recipes[0] : null; if (!is_null($recipes) && count($recipes) > 0) { $migrated_recipes = array(); $order = array(); $nbrRecipes = 0; $unitSystem = 0; foreach ($recipes as $recipe_id) { if (get_post_type($recipe_id) == 'recipe') { $recipe = new WPURP_Recipe($recipe_id); $servings_original = $recipe->servings_normalized(); if ($servings_original < 1) { $servings_original = 1; } $migrated = array('id' => $recipe_id, 'name' => $recipe->title(), 'link' => $recipe->link(), 'servings_original' => $servings_original, 'servings_wanted' => $servings); $migrated_recipes[] = $migrated; $order[] = strval($nbrRecipes); $nbrRecipes++; } } update_post_meta($post->ID, 'user-menus-recipes', $migrated_recipes); update_post_meta($post->ID, 'user-menus-order', $order); update_post_meta($post->ID, 'user-menus-nbrRecipes', $nbrRecipes); update_post_meta($post->ID, 'user-menus-unitSystem', $unitSystem); }
<?php // Recipe should never be null. Construct just allows easy access to WPURP_Recipe functions in IDE. if (is_null($recipe)) { $recipe = new WPURP_Recipe(0); } if (!isset($required_fields)) { $required_fields = array(); } ?> <script> function autoSuggestTag(id, type) { jQuery('#' + id).suggest("<?php echo get_bloginfo('wpurl'); ?> /wp-admin/admin-ajax.php?action=ajax-tag-search&tax=" + type); } </script> <input type="hidden" name="recipe_meta_box_nonce" value="<?php echo wp_create_nonce('recipe'); ?> " /> <div class="recipe-general-container"> <h4><?php _e('General', 'wp-ultimate-recipe'); ?> </h4> <table class="recipe-general-form"> <?php if (!isset($wpurp_user_submission)) {
} wp_set_post_terms($post->ID, $ingredient_terms, 'ingredient'); } add_post_meta($post->ID, 'recipe_ingredients', $new_ingredients); // Instructions $instructions = unserialize($meta['recipe_instructions'][0]); if ($instructions !== false) { foreach ($instructions as $instruction) { if ($instruction['image'] != '') { $update_image = array('ID' => $instruction['image'], 'post_parent' => $post->ID); wp_update_post($update_image); } } } add_post_meta($post->ID, 'recipe_instructions', $instructions); $recipe_object = new WPURP_Recipe($recipe_id); // Recipe Title add_post_meta($post->ID, 'recipe_title', $recipe_object->title()); // Servings add_post_meta($post->ID, 'recipe_servings', $meta['recipe_servings'][0]); $servings = WPUltimateRecipe::get()->helper('recipe_save')->normalize_servings($meta['recipe_servings'][0]); add_post_meta($post->ID, 'recipe_servings_normalized', $servings); // Other metadata add_post_meta($post->ID, 'recipe_servings_type', $meta['recipe_servings_type'][0]); add_post_meta($post->ID, 'recipe_description', $meta['recipe_description'][0]); add_post_meta($post->ID, 'recipe_prep_time', $meta['recipe_prep_time'][0]); add_post_meta($post->ID, 'recipe_cook_time', $meta['recipe_cook_time'][0]); add_post_meta($post->ID, 'recipe_passive_time', $meta['recipe_passive_time'][0]); add_post_meta($post->ID, 'recipe_prep_time_text', $meta['recipe_prep_time_text'][0]); add_post_meta($post->ID, 'recipe_cook_time_text', $meta['recipe_cook_time_text'][0]); add_post_meta($post->ID, 'recipe_passive_time_text', $meta['recipe_passive_time_text'][0]);