/** * Saves the user-selected post stylesheet on the 'save_post' hook. * * @since 0.2.0 * @access public * @param int $post_id The ID of the current post being saved. * @param object $post The post object currently being saved. */ function post_stylesheets_meta_box_save($post_id, $post = '') { /* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */ if (!is_object($post)) { $post = get_post(); } /* Verify the nonce before proceeding. */ if (!isset($_POST['post-stylesheets-nonce']) || !wp_verify_nonce($_POST['post-stylesheets-nonce'], basename(__FILE__))) { return; } /* Check if the post type supports 'post-stylesheets'. */ if (!post_type_supports($post->post_type, 'post-stylesheets')) { return; } /* Get the meta key. */ $meta_key = post_stylesheets_get_meta_key(); /* Get the previous post stylesheet. */ $meta_value = get_post_stylesheet($post_id); /* Get the submitted post stylesheet. */ $new_meta_value = $_POST['post-stylesheets']; /* 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_stylesheet($post_id); } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) { set_post_stylesheet($post_id, $new_meta_value); } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $meta_value !== $new_meta_value) { set_post_stylesheet($post_id, $new_meta_value); } }
/** * Saves the user-selected post stylesheet on the 'save_post' hook. * * @since 0.2.0 * @access private * @param int $post_id The ID of the current post being saved. * @param object $post The post object currently being saved. */ function post_stylesheets_meta_box_save($post_id, $post) { /* Verify the nonce before proceeding. */ if (!isset($_POST['post-stylesheets-nonce']) || !wp_verify_nonce($_POST['post-stylesheets-nonce'], basename(__FILE__))) { return; } /* Check if the post type supports 'post-stylesheets'. */ if (!post_type_supports($post->post_type, 'post-stylesheets')) { return; } /* Get the meta key. */ $meta_key = post_stylesheets_get_meta_key(); /* Get the previous post stylesheet. */ $meta_value = get_post_stylesheet($post_id); /* Get the submitted post stylesheet. */ $new_meta_value = $_POST['post-stylesheets']; /* 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_stylesheet($post_id); } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) { set_post_stylesheet($post_id, $new_meta_value); } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $meta_value !== $new_meta_value) { set_post_stylesheet($post_id, $new_meta_value); } }