From ee72143cbb2dd7bca206037cc1fa23528e50b0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E6=B4=BE=E5=A4=87=E6=A1=88?= <130886204+modiqi@users.noreply.github.com> Date: Sun, 6 Apr 2025 22:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=87=B31.1.5=20=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了访客模式、自定义水印文本、自定义文章类型、权限管理等 --- css/style.css | 10 +- languages/lelms-copyright-zh_CN.mo | Bin 3287 -> 7333 bytes languages/lelms-copyright-zh_CN.po | 388 +++++++++++++++++++------- languages/lelms-copyright.pot | 228 +++++++++++++-- lelms-copyright.php | 432 +++++++++++++++++++++++++++-- 5 files changed, 902 insertions(+), 156 deletions(-) diff --git a/css/style.css b/css/style.css index 4144a32..f0ee3b1 100644 --- a/css/style.css +++ b/css/style.css @@ -1,5 +1,5 @@ #lelms-watermark { - position: fixed; + position: fixed; top: 0; left: 0; width: 100%; @@ -15,8 +15,8 @@ } /* Allow form elements to interact */ -input, textarea, select, button, -[contenteditable="true"], +input, textarea, select, button, +[contenteditable="true"], a, button { pointer-events: auto !important; user-select: auto !important; @@ -26,11 +26,11 @@ a, button { #lelms-watermark { display: none !important; } - + body * { display: none !important; } - + body:after { content: "Printing is disabled"; display: block !important; diff --git a/languages/lelms-copyright-zh_CN.mo b/languages/lelms-copyright-zh_CN.mo index 11a53c067fa0b5ae4212f5dfc943dd27bfd4020d..2e015818b5992fa46f0d7682e8b654a55048f7e1 100644 GIT binary patch literal 7333 zcmbtXS#TUj8E%NV1Ox~KLI}`t5+cXim3+oo$0Uwy$0j}$OTh#JVzk@Rjx(Cs%*J>7r*$M^r;^QU{}9AUVg!TkX4k`FWXBJjyM_``MjBaGq4&ft&63;;g|{3~!i z@IS!Sz~YZGwhX8P7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LSOd3VJG7-SOaUB##V`U3;S{vNMOefz zUg(CG;0P4q8axd%G7bk-nl{2b^t+$~4#RvHgT_Jbn(Onh z0(lu;P8(;KEfh^?)ZrAyf)2~zBFuyzp|SoM*1}XP!!*DKXl$fGV}nUEFF@l0t7cv| z^9D37vSVgrFXstaF1z)o?(Z%~k92VA!=7SL>>C(K$!!`5{hJNKn?fej=%Xuqf%_ z_UnO2JV=6^M_?oJh#Px{\n" "Language-Team: \n" @@ -20,44 +20,156 @@ msgstr "" msgid "Adds watermark with username and prevents unauthorized screenshots" msgstr "" -#: lelms-copyright.php:146 +#: lelms-copyright.php:395 +msgid "Advanced" +msgstr "" + +#: lelms-copyright.php:85 +msgid "Advanced Settings" +msgstr "" + +#: lelms-copyright.php:513 +msgid "An error occurred while resetting settings." +msgstr "" + +#: lelms-copyright.php:247 +msgid "Apply only protection features (no watermark) to non-logged-in users." +msgstr "" + +#: lelms-copyright.php:496 +msgid "Are you sure you want to reset all settings to defaults?" +msgstr "" + +#: lelms-copyright.php:232 msgid "Block printing of the page to protect your content." msgstr "" -#: lelms-copyright.php:131 +#: lelms-copyright.php:206 msgid "Choose the color of the watermark text." msgstr "" -#: lelms-copyright.php:53 +#: lelms-copyright.php:216 +msgid "" +"Choose the type of watermark to display for logged-in users (overridden by " +"custom watermark if enabled)." +msgstr "" + +#: lelms-copyright.php:101 +msgid "" +"Configure advanced options to exclude specific post types or user roles from " +"watermark and protection." +msgstr "" + +#: lelms-copyright.php:66 msgid "Copyright" msgstr "" -#: lelms-copyright.php:75 +#: lelms-copyright.php:260 +msgid "Custom Watermark Text" +msgstr "" + +#: lelms-copyright.php:415 +msgid "Custom Watermark: Enable and set a custom text." +msgstr "" + +#: lelms-copyright.php:95 msgid "" "Customize the watermark appearance and protection settings to secure your " "content." msgstr "" -#: lelms-copyright.php:121 +#: lelms-copyright.php:196 msgid "Define the font size of the watermark text in pixels." msgstr "" -#: lelms-copyright.php:151 +#: lelms-copyright.php:237 msgid "Disable copying of text and right-click menus outside of form fields." msgstr "" -#: lelms-copyright.php:149 +#: lelms-copyright.php:252 +msgid "" +"Display the custom watermark text (defined below) for non-logged-in users." +msgstr "" + +#: lelms-copyright.php:389 +msgid "Document" +msgstr "" + +#: lelms-copyright.php:220 +msgid "Email" +msgstr "" + +#: lelms-copyright.php:235 msgid "Enable Copy Protection" msgstr "" -#: lelms-copyright.php:139 +#: lelms-copyright.php:255 +msgid "Enable Custom Watermark" +msgstr "" + +#: lelms-copyright.php:225 msgid "Enable DevTools Protection" msgstr "" -#: lelms-copyright.php:144 +#: lelms-copyright.php:240 +msgid "Enable for Guests" +msgstr "" + +#: lelms-copyright.php:230 msgid "Enable Print Protection" msgstr "" +#: lelms-copyright.php:242 +msgid "" +"Enable protection features for non-logged-in users. Additional options will " +"appear when checked." +msgstr "" + +#: lelms-copyright.php:245 +msgid "Enable Protection Only for Guests" +msgstr "" + +#: lelms-copyright.php:262 +msgid "" +"Enter custom watermark text (applies if \"Enable Custom Watermark\" or " +"\"Show Custom Watermark for Guests\" is checked). If empty, \"Custom " +"Watermark\" will be used." +msgstr "" + +#: lelms-copyright.php:285 +msgid "Excluded Post Types" +msgstr "" + +#: lelms-copyright.php:291 +msgid "Excluded User Roles" +msgstr "" + +#: lelms-copyright.php:509 +msgid "Failed to reset settings." +msgstr "" + +#: lelms-copyright.php:417 +msgid "For support, visit" +msgstr "" + +#: lelms-copyright.php:331 +msgid "Guest (Not Logged In)" +msgstr "" + +#: lelms-copyright.php:414 +msgid "" +"Guest Mode: Enable protection and/or custom watermark for non-logged-in " +"users." +msgstr "" + +#: lelms-copyright.php:396 +msgid "Help" +msgstr "" + +#: lelms-copyright.php:409 +msgid "How to Use LeLMS Copyright" +msgstr "" + #. Author URI of the plugin msgid "https://lelms.com" msgstr "" @@ -70,7 +182,7 @@ msgstr "" msgid "LeLMS Copyright" msgstr "" -#: lelms-copyright.php:52 lelms-copyright.php:207 +#: lelms-copyright.php:65 msgid "LeLMS Copyright Settings" msgstr "" @@ -78,56 +190,126 @@ msgstr "" msgid "LeLMS.com" msgstr "" -#: lelms-copyright.php:141 +#: lelms-copyright.php:219 +msgid "Nickname" +msgstr "" + +#: lelms-copyright.php:227 msgid "" "Prevent users from opening browser developer tools (e.g., F12 or " "Ctrl+Shift+I)." msgstr "" -#: lelms-copyright.php:212 +#: lelms-copyright.php:413 +msgid "" +"Protection Features: Enable options to block DevTools, printing, and copying." +msgstr "" + +#: lelms-copyright.php:421 +msgid "Reset to Defaults" +msgstr "" + +#: lelms-copyright.php:420 msgid "Save Changes" msgstr "" -#: lelms-copyright.php:126 +#: lelms-copyright.php:287 +msgid "Select post types where watermark and protection should not apply." +msgstr "" + +#: lelms-copyright.php:293 +msgid "Select user roles exempt from watermark and protection." +msgstr "" + +#: lelms-copyright.php:201 msgid "Set the distance between each watermark in pixels." msgstr "" -#: lelms-copyright.php:136 +#: lelms-copyright.php:211 msgid "" "Set the rotation angle of the watermark text in degrees (e.g., -45 for " "diagonal)." msgstr "" -#: lelms-copyright.php:116 +#: lelms-copyright.php:191 msgid "" "Set the transparency of the watermark (0 = fully transparent, 1 = fully " "opaque)." msgstr "" -#: lelms-copyright.php:228 +#: lelms-copyright.php:394 +msgid "Settings" +msgstr "" + +#: lelms-copyright.php:506 +msgid "" +"Settings have been reset to defaults. Please refresh the page to see the " +"changes." +msgstr "" + +#: lelms-copyright.php:250 +msgid "Show Custom Watermark for Guests" +msgstr "" + +#: lelms-copyright.php:390 +msgid "Support" +msgstr "" + +#: lelms-copyright.php:576 msgid "This action is disabled on this site." msgstr "" -#: lelms-copyright.php:134 +#: lelms-copyright.php:410 +msgid "" +"This plugin adds a watermark and protection features to your WordPress site. " +"Here’s how to configure it:" +msgstr "" + +#: lelms-copyright.php:221 +msgid "Timestamp" +msgstr "" + +#: lelms-copyright.php:257 +msgid "Use a custom watermark text instead of the selected watermark type." +msgstr "" + +#: lelms-copyright.php:218 +msgid "Username" +msgstr "" + +#: lelms-copyright.php:388 +#, php-format +msgid "Version: %s" +msgstr "" + +#: lelms-copyright.php:209 msgid "Watermark Angle" msgstr "" -#: lelms-copyright.php:129 +#: lelms-copyright.php:204 msgid "Watermark Color" msgstr "" -#: lelms-copyright.php:113 +#: lelms-copyright.php:188 msgid "Watermark Opacity" msgstr "" -#: lelms-copyright.php:65 +#: lelms-copyright.php:78 msgid "Watermark Settings" msgstr "" -#: lelms-copyright.php:119 +#: lelms-copyright.php:412 +msgid "Watermark Settings: Adjust opacity, size, spacing, color, and angle." +msgstr "" + +#: lelms-copyright.php:194 msgid "Watermark Size (px)" msgstr "" -#: lelms-copyright.php:124 +#: lelms-copyright.php:199 msgid "Watermark Spacing (px)" msgstr "" + +#: lelms-copyright.php:214 +msgid "Watermark Type" +msgstr "" diff --git a/lelms-copyright.php b/lelms-copyright.php index 2b1b21b..3c8eec2 100644 --- a/lelms-copyright.php +++ b/lelms-copyright.php @@ -3,7 +3,7 @@ * Plugin Name: LeLMS Copyright * Plugin URI: https://wenpai.org/plugins/lelms-copyright * Description: Adds watermark with username and prevents unauthorized screenshots - * Version: 1.1.1 + * Version: 1.1.5 * Author: LeLMS.com * Author URI: https://lelms.com * License: GPL v2 or later @@ -14,11 +14,15 @@ * Domain Path: /languages */ -// Prevent direct access if (!defined('ABSPATH')) { exit; } +define('LELMS_COPYRIGHT_VERSION', '1.1.5'); +define('LELMS_COPYRIGHT_DIR_URL', plugin_dir_url(__FILE__)); +define('LELMS_COPYRIGHT_DIR_PATH', plugin_dir_path(__FILE__)); +define('LELMS_COPYRIGHT_BASENAME', plugin_basename(__FILE__)); + class LELMS_Copyright { private $options; @@ -33,7 +37,15 @@ class LELMS_Copyright { 'watermark_angle' => -45, 'enable_devtools_protection' => 'yes', 'enable_print_protection' => 'yes', - 'enable_copy_protection' => 'yes' + 'enable_copy_protection' => 'yes', + 'enable_for_guests' => 'no', + 'enable_guest_protection_only' => 'no', + 'enable_guest_custom_watermark' => 'no', + 'enable_custom_watermark' => 'no', + 'custom_watermark_text' => '', + 'watermark_type' => 'username', + 'excluded_post_types' => array(), + 'excluded_roles' => array(), ); $this->options = wp_parse_args(get_option('lelms_copyright_options', array()), $defaults); @@ -45,6 +57,7 @@ class LELMS_Copyright { } add_action('admin_menu', array($this, 'add_admin_menu')); add_action('admin_init', array($this, 'register_settings')); + add_action('wp_ajax_lelms_reset_options', array($this, 'reset_options')); } public function add_admin_menu() { @@ -67,6 +80,13 @@ class LELMS_Copyright { 'lelms-copyright' ); + add_settings_section( + 'lelms_copyright_advanced_section', + __('Advanced Settings', 'lelms-copyright'), + array($this, 'advanced_section_description'), + 'lelms-copyright-advanced' + ); + $this->add_settings_fields(); } @@ -76,6 +96,12 @@ class LELMS_Copyright { echo '

'; } + public function advanced_section_description() { + echo '

'; + esc_html_e('Configure advanced options to exclude specific post types or user roles from watermark and protection.', 'lelms-copyright'); + echo '

'; + } + public function sanitize_options($input) { $sanitized = array(); $defaults = array( @@ -86,7 +112,15 @@ class LELMS_Copyright { 'watermark_angle' => -45, 'enable_devtools_protection' => 'yes', 'enable_print_protection' => 'yes', - 'enable_copy_protection' => 'yes' + 'enable_copy_protection' => 'yes', + 'enable_for_guests' => 'no', + 'enable_guest_protection_only' => 'no', + 'enable_guest_custom_watermark' => 'no', + 'enable_custom_watermark' => 'no', + 'custom_watermark_text' => '', + 'watermark_type' => 'username', + 'excluded_post_types' => array(), + 'excluded_roles' => array(), ); $sanitized['watermark_opacity'] = min(max(floatval($input['watermark_opacity']), 0), 1); @@ -97,12 +131,53 @@ class LELMS_Copyright { $sanitized['enable_devtools_protection'] = isset($input['enable_devtools_protection']) ? 'yes' : 'no'; $sanitized['enable_print_protection'] = isset($input['enable_print_protection']) ? 'yes' : 'no'; $sanitized['enable_copy_protection'] = isset($input['enable_copy_protection']) ? 'yes' : 'no'; + $sanitized['enable_for_guests'] = isset($input['enable_for_guests']) ? 'yes' : 'no'; + $sanitized['enable_guest_protection_only'] = isset($input['enable_guest_protection_only']) ? 'yes' : 'no'; + $sanitized['enable_guest_custom_watermark'] = isset($input['enable_guest_custom_watermark']) ? 'yes' : 'no'; + $sanitized['enable_custom_watermark'] = isset($input['enable_custom_watermark']) ? 'yes' : 'no'; + $sanitized['custom_watermark_text'] = sanitize_text_field($input['custom_watermark_text']); + $sanitized['watermark_type'] = in_array($input['watermark_type'], ['username', 'nickname', 'email', 'timestamp']) ? $input['watermark_type'] : 'username'; + $sanitized['excluded_post_types'] = array_map('sanitize_key', (array) $input['excluded_post_types']); + $sanitized['excluded_roles'] = array_map('sanitize_key', (array) $input['excluded_roles']); return wp_parse_args($sanitized, $defaults); } + public function should_apply_protection() { + $enable_for_guests = $this->options['enable_for_guests'] === 'yes'; + if (!is_user_logged_in() && !$enable_for_guests) { + return false; + } + + $user = wp_get_current_user(); + $user_roles = $user && $user->roles ? $user->roles : array('guest'); + if (array_intersect($user_roles, (array) $this->options['excluded_roles'])) { + return false; + } + + $post_type = get_post_type() ?: 'page'; + if (in_array($post_type, (array) $this->options['excluded_post_types'])) { + return false; + } + + return true; + } + + public function should_apply_watermark() { + if (!$this->should_apply_protection()) { + return false; + } + + $is_guest = !is_user_logged_in(); + if ($is_guest) { + return $this->options['enable_for_guests'] === 'yes' && $this->options['enable_guest_custom_watermark'] === 'yes'; + } else { + return true; + } + } + public function add_watermark_container() { - if (is_user_logged_in()) { + if ($this->should_apply_watermark()) { echo '
'; } } @@ -135,6 +210,17 @@ class LELMS_Copyright { 'type' => 'number', 'description' => __('Set the rotation angle of the watermark text in degrees (e.g., -45 for diagonal).', 'lelms-copyright') ), + 'watermark_type' => array( + 'title' => __('Watermark Type', 'lelms-copyright'), + 'type' => 'select', + 'description' => __('Choose the type of watermark to display for logged-in users (overridden by custom watermark if enabled).', 'lelms-copyright'), + 'options' => array( + 'username' => __('Username', 'lelms-copyright'), + 'nickname' => __('Nickname', 'lelms-copyright'), + 'email' => __('Email', 'lelms-copyright'), + 'timestamp' => __('Timestamp', 'lelms-copyright'), + ), + ), 'enable_devtools_protection' => array( 'title' => __('Enable DevTools Protection', 'lelms-copyright'), 'type' => 'checkbox', @@ -149,7 +235,32 @@ class LELMS_Copyright { 'title' => __('Enable Copy Protection', 'lelms-copyright'), 'type' => 'checkbox', 'description' => __('Disable copying of text and right-click menus outside of form fields.', 'lelms-copyright') - ) + ), + 'enable_for_guests' => array( + 'title' => __('Enable Guest Mode', 'lelms-copyright'), + 'type' => 'checkbox', + 'description' => __('Enable protection features for non-logged-in users. Additional options will appear when checked.', 'lelms-copyright') + ), + 'enable_guest_protection_only' => array( + 'title' => __('Enable Protection Only for Guests', 'lelms-copyright'), + 'type' => 'checkbox', + 'description' => __('Apply only protection features (no watermark) to non-logged-in users.', 'lelms-copyright') + ), + 'enable_guest_custom_watermark' => array( + 'title' => __('Show Custom Watermark for Guests', 'lelms-copyright'), + 'type' => 'checkbox', + 'description' => __('Display the custom watermark text (defined below) for non-logged-in users.', 'lelms-copyright') + ), + 'enable_custom_watermark' => array( + 'title' => __('Enable Custom Watermark', 'lelms-copyright'), + 'type' => 'checkbox', + 'description' => __('Use a custom watermark text instead of the selected watermark type.', 'lelms-copyright') + ), + 'custom_watermark_text' => array( + 'title' => __('Custom Watermark Text', 'lelms-copyright'), + 'type' => 'text', + 'description' => __('Enter custom watermark text (applies if "Enable Custom Watermark" or "Show Custom Watermark for Guests" is checked). If empty, "LeLMS Copyright" will be used.', 'lelms-copyright') + ), ); foreach ($fields as $key => $field) { @@ -163,18 +274,71 @@ class LELMS_Copyright { 'key' => $key, 'type' => $field['type'], 'attrs' => isset($field['attrs']) ? $field['attrs'] : '', - 'description' => $field['description'] // Pass the description to the callback + 'description' => $field['description'], + 'options' => isset($field['options']) ? $field['options'] : array(), + ) + ); + } + + $advanced_fields = array( + 'excluded_post_types' => array( + 'title' => __('Excluded Post Types', 'lelms-copyright'), + 'type' => 'checkbox_group', + 'description' => __('Select post types where watermark and protection should not apply.', 'lelms-copyright'), + 'options' => $this->get_public_post_types(), + ), + 'excluded_roles' => array( + 'title' => __('Excluded User Roles', 'lelms-copyright'), + 'type' => 'checkbox_group', + 'description' => __('Select user roles exempt from watermark and protection.', 'lelms-copyright'), + 'options' => $this->get_user_roles(), + ), + ); + + foreach ($advanced_fields as $key => $field) { + add_settings_field( + $key, + $field['title'], + array($this, 'render_field'), + 'lelms-copyright-advanced', + 'lelms_copyright_advanced_section', + array( + 'key' => $key, + 'type' => $field['type'], + 'description' => $field['description'], + 'options' => $field['options'], ) ); } } + private function get_public_post_types() { + $post_types = get_post_types(array('public' => true), 'objects'); + $options = array(); + foreach ($post_types as $post_type) { + $options[$post_type->name] = $post_type->label; + } + return $options; + } + + private function get_user_roles() { + global $wp_roles; + $roles = $wp_roles->roles; + $options = array(); + foreach ($roles as $role => $details) { + $options[$role] = $details['name']; + } + $options['guest'] = __('Guest (Not Logged In)', 'lelms-copyright'); + return $options; + } + public function render_field($args) { $key = $args['key']; $type = $args['type']; - $value = isset($this->options[$key]) ? $this->options[$key] : ''; + $value = $this->options[$key]; $attrs = isset($args['attrs']) ? $args['attrs'] : ''; $description = isset($args['description']) ? $args['description'] : ''; + $options = isset($args['options']) ? $args['options'] : array(); if ($type === 'checkbox') { printf( @@ -183,6 +347,23 @@ class LELMS_Copyright { $attrs, checked($value, 'yes', false) ); + } elseif ($type === 'select') { + printf(''; + } elseif ($type === 'checkbox_group') { + $value = (array) $value; + foreach ($options as $opt_value => $opt_label) { + printf( + '
', + esc_attr($key), + esc_attr($opt_value), + checked(in_array($opt_value, $value), true, false), + esc_html($opt_label) + ); + } } else { printf( '', @@ -193,10 +374,9 @@ class LELMS_Copyright { ); } - // Output the description below the field if ($description) { echo '

'; - echo esc_html($description); // Use esc_html to safely output the translated description + echo esc_html($description); echo '

'; } } @@ -204,36 +384,240 @@ class LELMS_Copyright { public function options_page() { ?>
-

+

+ + + +

+
+ +
- -
+ +
+
+ +
+ + +
+
+ + +
+ + + + +
+
+ should_apply_protection()) { + $style_url = plugins_url('css/style.css', __FILE__); + $script_url = plugins_url('js/watermark.js', __FILE__); + + if (!file_exists(plugin_dir_path(__FILE__) . 'css/style.css')) { + error_log('LeLMS Copyright: CSS file not found at ' . plugin_dir_path(__FILE__) . 'css/style.css'); + } + if (!file_exists(plugin_dir_path(__FILE__) . 'js/watermark.js')) { + error_log('LeLMS Copyright: JS file not found at ' . plugin_dir_path(__FILE__) . 'js/watermark.js'); + } + + wp_enqueue_style('lelms-copyright', $style_url, array(), '1.1.5'); + wp_enqueue_script('lelms-copyright', $script_url, array('jquery'), '1.1.5', true); + + $user = is_user_logged_in() ? wp_get_current_user() : null; + $watermark_text = ''; + $is_guest = !is_user_logged_in(); + + if ($this->should_apply_watermark()) { + if ($is_guest) { + $watermark_text = !empty($this->options['custom_watermark_text']) ? $this->options['custom_watermark_text'] : 'LeLMS Copyright'; + } else { + if ($this->options['enable_custom_watermark'] === 'yes') { + $watermark_text = !empty($this->options['custom_watermark_text']) ? $this->options['custom_watermark_text'] : 'LeLMS Copyright'; + } else { + switch ($this->options['watermark_type']) { + case 'username': + $watermark_text = $user ? '@' . $user->user_login : ''; + break; + case 'nickname': + $watermark_text = $user ? $user->display_name : ''; + break; + case 'email': + $watermark_text = $user ? $user->user_email : ''; + break; + case 'timestamp': + $watermark_text = current_time('Y-m-d H:i:s'); + break; + } + } + } + } - $current_user = wp_get_current_user(); wp_localize_script('lelms-copyright', 'lelmsData', array( - 'username' => '@' . $current_user->user_login, + 'username' => $watermark_text, 'options' => $this->options, - 'warningMessage' => __('This action is disabled on this site.', 'lelms-copyright') + 'warningMessage' => __('This action is disabled on this site.', 'lelms-copyright'), + 'isGuest' => $is_guest, )); } } + + public function reset_options() { + check_ajax_referer('lelms_reset_nonce', 'nonce'); + if (!current_user_can('manage_options')) { + wp_send_json_error('Permission denied'); + } + + $defaults = array( + 'watermark_opacity' => 0.1, + 'watermark_size' => 20, + 'watermark_spacing' => 150, + 'watermark_color' => '#000000', + 'watermark_angle' => -45, + 'enable_devtools_protection' => 'yes', + 'enable_print_protection' => 'yes', + 'enable_copy_protection' => 'yes', + 'enable_for_guests' => 'no', + 'enable_guest_protection_only' => 'no', + 'enable_guest_custom_watermark' => 'no', + 'enable_custom_watermark' => 'no', + 'custom_watermark_text' => '', + 'watermark_type' => 'username', + 'excluded_post_types' => array(), + 'excluded_roles' => array(), + ); + + update_option('lelms_copyright_options', $defaults); + wp_send_json_success('Settings reset to defaults'); + } } new LELMS_Copyright(); -// Integrate UpdatePulse Server for updates using PUC v5.3 require_once plugin_dir_path(__FILE__) . 'lib/plugin-update-checker/plugin-update-checker.php'; use YahnisElsts\PluginUpdateChecker\v5p3\PucFactory;