capability, 'advanced-copy-settings', [$this, 'settings_page_html'] ); } public function register_settings() { register_setting($this->option_group, 'advacoco_enabled', [ 'default' => 1, 'sanitize_callback' => 'intval' ]); register_setting($this->option_group, 'advacoco_snippet_length', [ 'default' => 100, 'sanitize_callback' => [$this, 'sanitize_snippet_length'] ]); register_setting($this->option_group, 'advacoco_prefix_text', [ 'default' => 'This excerpt was copied from', 'sanitize_callback' => 'sanitize_text_field' ]); register_setting($this->option_group, 'advacoco_suffix_text', [ 'default' => 'learn more at:', 'sanitize_callback' => 'sanitize_text_field' ]); register_setting($this->option_group, 'advacoco_domain_text', [ 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ]); register_setting($this->option_group, 'advacoco_exclude_pages', [ 'default' => '', 'sanitize_callback' => 'sanitize_textarea_field' ]); register_setting($this->option_group, 'advacoco_min_chars', [ 'default' => 20, 'sanitize_callback' => [$this, 'sanitize_min_chars'] ]); } public function sanitize_snippet_length($value) { $value = intval($value); return max(10, min(500, $value)); } public function sanitize_min_chars($value) { $value = intval($value); return max(1, min(100, $value)); } public function settings_page_html() { if (!current_user_can($this->capability)) { wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'advanced-content-copy')); } ?>

option_group); ?>
>

should_exclude_page()) { return; } // Register and enqueue the main script wp_register_script( 'advacoco-frontend', ADVACOCO_PLUGIN_URL . 'assets/js/advanced-content-copy.js', [], ADVACOCO_VERSION, true ); // Prepare settings for JavaScript $settings = [ 'snippetLength' => intval(get_option('advacoco_snippet_length', 100)), 'minChars' => intval(get_option('advacoco_min_chars', 20)), 'prefix' => get_option('advacoco_prefix_text', 'This excerpt was copied from'), 'suffix' => get_option('advacoco_suffix_text', 'learn more at:'), 'domain' => get_option('advacoco_domain_text', '') ?: get_bloginfo('name'), 'postUrl' => get_permalink() ]; // Localize the script with settings wp_localize_script('advacoco-frontend', 'advacocoSettings', $settings); // Enqueue the script wp_enqueue_script('advacoco-frontend'); } public function should_exclude_page() { $exclude_pages = trim(get_option('advacoco_exclude_pages', '')); if (empty($exclude_pages)) { return false; } $current_id = get_the_ID(); $current_slug = get_post_field('post_name', $current_id); $excluded = array_map('trim', explode(',', $exclude_pages)); return in_array($current_id, $excluded) || in_array($current_slug, $excluded); } } } new ADVACOCO_Plugin();