From ee36079405160bcca6554f4e7fa1dc8b5f6d4ecb Mon Sep 17 00:00:00 2001 From: Sophia Atkinson Date: Sun, 29 Jun 2025 23:33:54 -0700 Subject: [PATCH] Added color picker to the settings page and and added that you can set the titles for the buttons to! --- assets/js/cw-color-picker.js | 3 + assets/js/cw-color-picker.min.js | 1 + content-warning.php | 157 ++++++++++++++++++------------- 3 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 assets/js/cw-color-picker.js create mode 100644 assets/js/cw-color-picker.min.js diff --git a/assets/js/cw-color-picker.js b/assets/js/cw-color-picker.js new file mode 100644 index 0000000..3d6bf88 --- /dev/null +++ b/assets/js/cw-color-picker.js @@ -0,0 +1,3 @@ +jQuery(document).ready(function ($) { + $('.wp-color-picker').wpColorPicker(); +}); \ No newline at end of file diff --git a/assets/js/cw-color-picker.min.js b/assets/js/cw-color-picker.min.js new file mode 100644 index 0000000..103443c --- /dev/null +++ b/assets/js/cw-color-picker.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(o){o(".wp-color-picker").wpColorPicker()}); \ No newline at end of file diff --git a/content-warning.php b/content-warning.php index 11139bf..444b18d 100644 --- a/content-warning.php +++ b/content-warning.php @@ -2,7 +2,7 @@ /** * Plugin Name: Better Content Warning * Description: Blocks access to content behind a content warning popup with optional trigger warnings. - * Version: 1.0 + * Version: 1.1 * Author: Sophia Atkinson * Author URI: https://sophia.wtf * Text Domain: better-content-warning @@ -16,7 +16,7 @@ // Add metabox add_action( 'add_meta_boxes', function () { - add_meta_box('cw_meta_box', 'Better Content Warning', 'cw_meta_box_callback', ['post', 'page'], 'side', 'high'); + add_meta_box('cw_meta_box', 'Better Content Warning', 'cw_meta_box_callback', ['post', 'page'], 'side', 'high'); } ); @@ -46,8 +46,8 @@ add_action( if (!current_user_can('edit_post', $post_id)) { return; } - update_post_meta($post_id, '_cw_enabled', isset($_POST['cw_enabled']) ? 'on' : ''); - update_post_meta($post_id, '_cw_warnings', sanitize_text_field($_POST['cw_warnings'])); + update_post_meta($post_id, '_cw_enabled', isset($_POST['cw_enabled']) ? 'on' : ''); + update_post_meta($post_id, '_cw_warnings', sanitize_text_field($_POST['cw_warnings'])); } ); @@ -62,30 +62,31 @@ add_filter( return $content; } - $enabled = get_post_meta(get_the_ID(), '_cw_enabled', true); + $enabled = get_post_meta(get_the_ID(), '_cw_enabled', true); if ($enabled !== 'on') { return $content; } - $post_id = get_the_ID(); - $warnings = trim(get_post_meta($post_id, '_cw_warnings', true)); - $prefix = get_option('cw_prefix', 'Content Warning'); - $default = get_option('cw_default_message', 'This post contains content that may be triggering to some people, Continue forward at your discretion.'); - $button = get_option('cw_button_text', 'Continue'); - $cookie_duration = 180; - $exit_button = get_option('cw_exit_button_text', 'Exit'); + $post_id = get_the_ID(); + $warnings = trim(get_post_meta($post_id, '_cw_warnings', true)); + $prefix = get_option('cw_prefix', 'Content Warning'); + $default = get_option('cw_default_message', 'This post contains content that may be triggering to some people, Continue forward at your discretion.'); + $continue_button = get_option('cw_button_text', 'Continue'); + $exit_button = get_option('cw_exit_button_text', 'Exit'); + $exit_button_title = esc_attr(get_option('cw_exit_button_title', 'No shame in exiting <3')); + $continue_button_title = esc_attr(get_option('cw_continue_button_title', 'Lets get this party started /s')); + $cookie_duration = 180; + $header = esc_html($prefix); + $warning = $warnings ? esc_html($warnings) : esc_html($default); - $header = esc_html($prefix); - $warning = $warnings ? esc_html($warnings) : esc_html($default); - - ob_start(); - ?> + ob_start(); + ?>

- +
- +
- ' . $content . ''; + ' . $content . ''; } ); // Add styles add_action( 'wp_head', function () { - $bg = esc_attr(get_option('cw_bg_color', '#1E1F22')); - $overlay_bg = esc_attr(get_option('cw_overlay_bg_color', '#2E3035')); - $font = esc_attr(get_option('cw_font_size', '1.1em')); - $btn = esc_attr(get_option('cw_button_color', '#9E93DC')); - $btn_hover = esc_attr(get_option('cw_button_hover_color', '#8179d5')); - echo " + $bg = esc_attr(get_option('cw_bg_color', '#1E1F22')); + $overlay_bg = esc_attr(get_option('cw_overlay_bg_color', '#2E3035')); + $font = esc_attr(get_option('cw_font_size', '1.1em')); + $btn = esc_attr(get_option('cw_button_color', '#9E93DC')); + $btn_hover = esc_attr(get_option('cw_button_hover_color', '#8179d5')); + echo "