/** * Saves the single value for the 'Series' meta key, which was set using the custom field series meta box. * * @since 0.3.0 * @access private * @param int $post_id The ID of the current post being saved. * @param object $post The post object currently being saved. * @return void */ function custom_field_series_meta_box_save($post_id, $post) { /* Verify the nonce before proceeding. */ if (!isset($_POST['custom-field-series-nonce']) || !wp_verify_nonce($_POST['custom-field-series-nonce'], basename(__FILE__))) { return $post_id; } /* Get the posted series title and strip all tags from it. */ $new_meta_value = $_POST['custom-field-series']; /* Get the meta key. */ $meta_key = custom_field_series_meta_key(); /* Get the meta value of the custom field key. */ $meta_value = get_post_meta($post_id, $meta_key, true); /* If there is no new meta value but an old value exists, delete it. */ if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) { delete_post_meta($post_id, $meta_key, $meta_value); } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) { add_post_meta($post_id, $meta_key, $new_meta_value, true); } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $meta_value !== $new_meta_value) { update_post_meta($post_id, $meta_key, $new_meta_value); } }
/** * Saves the single value for the 'Series' meta key, which was set using the custom field series meta box. * * @since 0.3.0 * @access private * @param int $post_id The ID of the current post being saved. * @param object $post The post object currently being saved. * @return void */ function custom_field_series_meta_box_save($post_id, $post) { /* Verify the nonce before proceeding. */ if (!isset($_POST['custom-field-series-nonce']) || !wp_verify_nonce($_POST['custom-field-series-nonce'], basename(__FILE__))) { return $post_id; } /* Check if the current user has permission to edit the post. */ if (!current_user_can('edit_post_meta', $post_id)) { return $post_id; } /* Get the posted series title and strip all tags from it. */ $new_meta_value = isset($_POST['custom-field-series']) ? strip_tags($_POST['custom-field-series']) : ''; /* Get the meta key. */ $meta_key = custom_field_series_meta_key(); /* Get the meta value of the custom field key. */ $meta_value = get_post_meta($post_id, $meta_key, true); /* If a new meta value was added and there was no previous value, add it. */ if ($new_meta_value && '' == $meta_value) { add_post_meta($post_id, $meta_key, $new_meta_value, true); } elseif ($new_meta_value && $new_meta_value != $meta_value) { update_post_meta($post_id, $meta_key, $new_meta_value); } elseif ('' == $new_meta_value && $meta_value) { delete_post_meta($post_id, $meta_key, $meta_value); } }