/** * Set the background color for a single post. * * @since 1.0. * */ function oxford_custom_colors() { if (!is_single()) { return; } printf("\n<!-- Oxford %s -->\n<style type=\"text/css\">\n", __('custom colors', 'oxford')); if (is_single()) { $post_background_color = oxford_get_post_meta('settings', get_the_ID(), 'post-background-color'); if (false !== $post_background_color) { if ($post_background_color = oxford_maybe_hash_hex_color($post_background_color)) { printf('body { background: -moz-linear-gradient(left, #ffffff, #ffffff 900px, %1$s 900px, %1$s); background: -webkit-linear-gradient(left, #ffffff, #ffffff 900px, %1$s 900px, %1$s); background: -o-linear-gradient(left, #ffffff, #ffffff 900px, %1$s 900px, %1$s); background: -ms-linear-gradient(left, #ffffff, #ffffff 900px, %1$s 900px, %1$s); background: linear-gradient(left, #ffffff, #ffffff 900px, %1$s 900px, %1$s); } #content-wrapper { background-color: %1$s; };', $post_background_color); } } } echo "</style>\n\n"; }
/** * Sanitize, validate, and save the meta for post background. * * @since 1.0. * * @param int $post_id The id of the post currently being edited. */ function oxford_post_meta_save($post_id) { // Checks save status $is_autosave = wp_is_post_autosave($post_id); $is_revision = wp_is_post_revision($post_id); $is_valid_nonce = isset($_POST['oxford_nonce']) && wp_verify_nonce($_POST['oxford_nonce'], basename(__FILE__)) ? 'true' : 'false'; // Exits script depending on save status if ($is_autosave || $is_revision || !$is_valid_nonce) { return; } // Sanitize/save Background Color if necessary if (isset($_POST['post-background-color']) && ($sanitized_hex = oxford_maybe_hash_hex_color($_POST['post-background-color']))) { if ('#ffffff' === $sanitized_hex) { oxford_update_post_meta('settings', $post_id, 'post-background-color', null); } else { if ($sanitized_hex !== oxford_get_post_meta('settings', $post_id, 'post-background-color')) { oxford_update_post_meta('settings', $post_id, 'post-background-color', $sanitized_hex); } } } // Sanitize/save Single Column if necessary $single_column = oxford_get_post_meta('settings', $post_id, 'post-single-column'); if (isset($_POST['post-single-column']) && !$single_column) { oxford_update_post_meta('settings', $post_id, 'post-single-column', true); } else { if (!isset($_POST['post-single-column']) && $single_column) { oxford_update_post_meta('settings', $post_id, 'post-single-column', null); } } // If there are no settings, remove the meta entry $post_meta_settings = get_post_meta($post_id, '_oxford-post-settings', true); if (empty($post_meta_settings)) { delete_post_meta($post_id, '_oxford-post-settings'); } }