/** * Checks a post if it has a specific style. * * @since 1.0.0 * @access public * @param string $style The post style to check for. * @param int $post_id The ID of the post to check. * @return bool */ function carelib_has_post_style($style, $post_id = '') { if (empty($post_id)) { $post_id = get_the_ID(); } return carelib_get_post_style($post_id) === $style ? true : false; }
/** * Saves the post style when submitted via the style meta box. * * @since 1.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 carelib_metabox_post_styles_save($post_id, $post = '') { $no = "{$GLOBALS['carelib_prefix']}_post_style_nonce"; $act = "{$GLOBALS['carelib_prefix']}_update_post_style"; // Verify the nonce for the post formats meta box. if (!isset($_POST[$no]) || !wp_verify_nonce($_POST[$no], $act)) { return false; } $input = isset($_POST['carelib-post-style']) ? $_POST['carelib-post-style'] : ''; $current = carelib_get_post_style($post_id); if ($input === $current) { return false; } if (empty($input)) { return carelib_delete_post_style($post_id); } return carelib_set_post_style($post_id, $input); }
/** * Filters the 'stylesheet_uri' and checks if a post has a style that should * overwrite the theme's primary `style.css`. * * @since 1.0.0 * @access public * @param string $stylesheet_uri * @return string */ function carelib_style_filter($stylesheet_uri) { if (!is_singular()) { return $stylesheet_uri; } $style = carelib_get_post_style(get_queried_object_id()); if ($style && ($style_uri = _carelib_locate_theme_file(array($style)))) { $stylesheet_uri = $style_uri; } return $stylesheet_uri; }