/** * Checks a post if it has a specific style. * * @since 3.0.0 * @access public * @param int $post_id * @return bool */ function hybrid_has_post_style($style, $post_id = '') { if (!$post_id) { $post_id = get_the_ID(); } return $style === hybrid_get_post_style($post_id) ? true : false; }
/** * Saves the post style when submitted via the style meta box. * * @since 3.0.0 * @access public * @param int $post_id The ID of the current post being saved. * @param object $post The post object currently being saved. * @return void|int */ function hybrid_save_post_style($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['hybrid-post-style-nonce']) || !wp_verify_nonce($_POST['hybrid-post-style-nonce'], basename(__FILE__))) { return; } // Get the previous post style. $meta_value = hybrid_get_post_style($post_id); // Get the submitted post style. $new_meta_value = isset($_POST['hybrid-post-style']) ? sanitize_text_field($_POST['hybrid-post-style']) : ''; // If there is no new meta value but an old value exists, delete it. if ('' == $new_meta_value && $meta_value) { hybrid_delete_post_style($post_id); } elseif ($meta_value !== $new_meta_value) { hybrid_set_post_style($post_id, $new_meta_value); } }