コード例 #1
0
 /**
  * Update an existing instruction.
  *
  * @since 1.3.0
  *
  * @param int   $instruction_id The ID for the instruction to update.
  * @param array $args {
  *     The updated instruction values.
  *
  *     @type int    $recipe_id   The recipe ID.
  *     @type string $description The instruction description.
  *     @type bool   $is_heading' Whether the instruction is a heading.
  *     @type int    $order       The instruction order number.
  * }
  * @return int|bool $result The instruction ID or false on failure.
  */
 public function update_instruction($instruction_id, $args)
 {
     $exists = simmer_get_recipe_instruction($instruction_id);
     if (!$exists) {
         return false;
     }
     $item_args = array();
     if (isset($args['recipe_id'])) {
         $recipe_id = absint($args['recipe_id']);
         if ($recipe_id) {
             $item_args['recipe_id'] = $recipe_id;
         }
     }
     if (isset($args['order'])) {
         if (is_numeric($args['order'])) {
             $item_args['recipe_item_order'] = absint($args['order']);
         }
     }
     if (!empty($item_args)) {
         simmer_update_recipe_item($instruction_id, $item_args);
     }
     if (isset($args['description'])) {
         if (!empty($args['description'])) {
             simmer_update_recipe_item_meta($instruction_id, 'description', $args['description']);
         } else {
             simmer_delete_recipe_item_meta($instruction_id, 'description');
         }
     }
     if (isset($args['is_heading'])) {
         simmer_update_recipe_item_meta($instruction_id, 'is_heading', (bool) $args['is_heading']);
     }
     return $instruction_id;
 }
コード例 #2
0
 /**
  * Update an existing ingredient.
  *
  * @since 1.3.0
  *
  * @param int   $ingredient_id The ID for the ingredient to update.
  * @param array $args {
  *     The updated ingredient values.
  *
  *     @type int    $recipe_id   The recipe ID.
  *     @type float  $amount      The ingredient amount.
  *     @type string $unit        Optional. The ingredient unit.
  *     @type string $description Optional. The ingredient description.
  *     @type bool   $is_heading  Whether the ingredient is a heading.
  *     @type int    $order       Optional. The ingredient order number.
  * }
  * @return int|bool $result The ingredient ID or false on failure.
  */
 public function update_ingredient($ingredient_id, $args)
 {
     $exists = simmer_get_recipe_ingredient($ingredient_id);
     if (!$exists) {
         return false;
     }
     $item_args = array();
     if (isset($args['recipe_id'])) {
         $recipe_id = absint($args['recipe_id']);
         if ($recipe_id) {
             $item_args['recipe_id'] = $recipe_id;
         }
     }
     if (isset($args['order'])) {
         if (is_numeric($args['order'])) {
             $item_args['recipe_item_order'] = absint($args['order']);
         }
     }
     if (!empty($item_args)) {
         simmer_update_recipe_item($ingredient_id, $item_args);
     }
     if (isset($args['amount'])) {
         $amount = floatval($args['amount']);
         if ($amount) {
             simmer_update_recipe_item_meta($ingredient_id, 'amount', $amount);
         } else {
             simmer_delete_recipe_item_meta($ingredient_id, 'amount');
         }
     }
     if (isset($args['unit'])) {
         $unit = sanitize_text_field($args['unit']);
         if (!empty($unit)) {
             simmer_update_recipe_item_meta($ingredient_id, 'unit', $unit);
         } else {
             simmer_delete_recipe_item_meta($ingredient_id, 'unit');
         }
     }
     if (isset($args['description'])) {
         if (!empty($args['description'])) {
             simmer_update_recipe_item_meta($ingredient_id, 'description', $args['description']);
         } else {
             simmer_delete_recipe_item_meta($ingredient_id, 'description');
         }
     }
     if (isset($args['is_heading'])) {
         simmer_update_recipe_item_meta($ingredient_id, 'is_heading', (bool) $args['is_heading']);
     }
     return $ingredient_id;
 }