/** * 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); } }
_e("<strong>Use the TAB key</strong> while adding instructions, 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-notes-container"> <h4><?php _e('Recipe notes', 'wp-ultimate-recipe'); ?> </h4> <?php $options = array('textarea_rows' => 7); if (isset($wpurp_user_submission)) { $options['media_buttons'] = false; } wp_editor($recipe->notes(), 'recipe_notes', $options); ?> </div> <?php $custom_fields_addon = WPUltimateRecipe::addon('custom-fields'); if ($custom_fields_addon && (!isset($wpurp_user_submission) || WPUltimateRecipe::option('recipe_fields_in_user_submission', '1') == '1')) { $custom_fields = $custom_fields_addon->get_custom_fields(); $custom_fields_in_user_submission = WPUltimateRecipe::option('recipe_fields_user_submission', array_keys($custom_fields)); if (count($custom_fields) > 0) { ?> <div class="recipe-custom-fields-container"> <h4><?php _e('Custom Fields', 'wp-ultimate-recipe'); ?> </h4> <table class="recipe-general-form">
} $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">'; $post_content .= htmlentities($searchable_recipe); $post_content .= '</div>'; wp_update_post(array('ID' => $recipe->ID(), 'post_content' => $post_content)); update_post_meta($recipe->ID(), 'wpurp_text_search', time()); } } else { // Finished migrating, all recipes have a full text search update_option('wpurp_cron_migrate_version', '2.3.0'); }