rules = new LCP_Paywall_Rules(); add_action('admin_menu', array($this, 'add_menu_pages')); add_action('admin_init', array($this, 'register_settings')); add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets')); add_action('wp_ajax_lcp_save_rules', array($this, 'ajax_save_rules')); add_action('wp_ajax_lcp_get_taxonomy_terms', array($this, 'ajax_get_taxonomy_terms')); add_action('wp_ajax_lcp_save_settings', array($this, 'ajax_save_settings')); } public function add_menu_pages() { add_menu_page( 'LCP Paywall', 'LCP Paywall', 'manage_options', 'lcp-paywall', array($this, 'render_rules_page'), 'dashicons-lock', 30 ); add_submenu_page( 'lcp-paywall', 'Paywall Settings', 'Settings', 'manage_options', 'lcp-paywall-settings', array($this, 'render_settings_page') ); } public function register_settings() { register_setting('lcp_paywall_options', 'lcp_paywall_rules'); register_setting('lcp_paywall_settings', 'lcp_paywall_settings'); } public function enqueue_admin_assets($hook) { if (!in_array($hook, array('toplevel_page_lcp-paywall', 'lcp-paywall_page_lcp-paywall-settings'))) { return; } wp_enqueue_style('lcp-paywall-admin'); // Enqueue WordPress editor assets if ($hook === 'lcp-paywall_page_lcp-paywall-settings') { wp_enqueue_editor(); } // Enqueue Sortable.js wp_enqueue_script( 'sortablejs', 'https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js', array(), '1.15.0', true ); wp_enqueue_script( 'lcp-paywall-admin', LCP_PAYWALL_URL . 'assets/js/admin.js', array('sortablejs'), LCP_PAYWALL_VERSION, true ); wp_localize_script('lcp-paywall-admin', 'lcpPaywall', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('lcp_paywall_nonce'), 'operators' => $this->rules->get_operators(), 'conditions' => $this->rules->get_conditions(), 'valueTypes' => $this->rules->get_value_types(), )); } public function render_rules_page() { if (!current_user_can('manage_options')) { return; } $post_types = get_post_types(array('public' => true), 'objects'); $current_rules = $this->rules->get_rules(); ?>

rules->get_default_post_type_settings($post_type->name); ?>

labels->name); ?>

name]['rules'])) { foreach ($current_rules[$post_type->name]['rules'] as $rule) { $this->render_rule_template($post_type, $rule); } } ?>

Paywall Nag Message

Configure the message that will be shown to users when content is locked.

'lcp_nag_message', 'media_buttons' => true, 'textarea_rows' => 10, 'teeny' => false ) ); ?>

rules->save_rules($rules)) { wp_send_json_success('Rules saved successfully'); } else { wp_send_json_error('Failed to save rules'); } } public function ajax_get_taxonomy_terms() { if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } check_ajax_referer('lcp_paywall_nonce', 'nonce'); $taxonomy = isset($_POST['taxonomy']) ? sanitize_text_field($_POST['taxonomy']) : ''; if (!$taxonomy) { wp_send_json_error('Invalid taxonomy'); } $terms = $this->rules->get_terms_for_taxonomy($taxonomy); wp_send_json_success($terms); } public function ajax_save_settings() { if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized'); } check_ajax_referer('lcp_paywall_nonce', 'nonce'); $nag_message = isset($_POST['nag_message']) ? wp_kses_post(stripslashes($_POST['nag_message'])) : ''; $settings = array( 'nag_message' => $nag_message ); if (update_option('lcp_paywall_settings', $settings)) { wp_send_json_success('Settings saved successfully'); } else { wp_send_json_error('Failed to save settings'); } } }