예제 #1
0
 /**
  * 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);
     }
 }
예제 #2
0
    <h4><?php 
_e('General', 'wp-ultimate-recipe');
?>
</h4>
    <table class="recipe-general-form">
    <?php 
if (!isset($wpurp_user_submission)) {
    ?>
        <tr class="recipe-general-form-title">
            <td class="recipe-general-form-label"><label for="recipe_title"><?php 
    _e('Title', 'wp-ultimate-recipe');
    ?>
</label></td>
            <td class="recipe-general-form-field">
                <input type="text" name="recipe_title" id="recipe_title" value="<?php 
    echo esc_attr($recipe->title());
    ?>
" />
                <span class="recipe-general-form-notes"> <?php 
    _e('(leave blank to use post title)', 'wp-ultimate-recipe');
    ?>
</span>
            </td>
        </tr>
        <?php 
    if (WPUltimateRecipe::option('recipe_alternate_image', '1') == '1') {
        ?>
        <tr class="recipe-general-form-alternate-image">
            <td class="recipe-general-form-label"><label for="recipe_alternate_image"><?php 
        _e('Image', 'wp-ultimate-recipe');
        ?>
<?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'] : '';
예제 #4
0
 /**
  * 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());
     }
 }
        $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);
        }
    }
}
// Successfully migrated to 1.0.8
$migrate_version = '1.0.8';
update_option('wpurp_migrate_version', $migrate_version);
 }
 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]);
 add_post_meta($post->ID, 'recipe_cost', $meta['recipe_cost'][0]);
 add_post_meta($post->ID, 'recipe_user_ratings', $meta['recipe_user_ratings'][0]);