/** * 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); } }
?> </td> </tr> <?php } ?> </table> </div> <div class="recipe-ingredients-container"> <h4><?php _e('Ingredients', 'wp-ultimate-recipe'); ?> </h4> <?php $ingredients = $recipe->ingredients(); ?> <table id="recipe-ingredients"> <thead> <tr class="ingredient-group ingredient-group-first"> <td> </td> <td><strong><?php _e('Group', 'wp-ultimate-recipe'); ?> :</strong></td> <td colspan="2"> <span class="ingredient-groups-disabled"><?php echo __('Main Ingredients', 'wp-ultimate-recipe') . ' ' . __('(this label is not shown)', 'wp-ultimate-recipe'); ?> </span> <?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'] : '';