/** * 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); } }
</a> </div> <div class="recipe-form-notes"> <?php _e("<strong>Use the TAB key</strong> while adding ingredients, it will automatically create new fields. <strong>Don't worry about empty lines</strong>, these will be ignored.", 'wp-ultimate-recipe'); ?> </div> </div> <div class="recipe-instructions-container"> <h4><?php _e('Instructions', 'wp-ultimate-recipe'); ?> </h4> <?php $instructions = $recipe->instructions(); ?> <table id="recipe-instructions"> <thead> <tr class="instruction-group instruction-group-first"> <td> </td> <td colspan="2"> <strong><?php _e('Group', 'wp-ultimate-recipe'); ?> :</strong> <span class="instruction-groups-disabled"><?php echo __('Main Instructions', 'wp-ultimate-recipe') . ' ' . __('(this label is not shown)', 'wp-ultimate-recipe'); ?> </span> <?php
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); $post_content .= '<div class="wpurp-searchable-recipe" style="display:none">';