'accelvia_sanitize_options', ) ); } add_action('admin_init', 'accelvia_register_settings'); /** * Sanitize and validate all plugin options. * * @param array $input Raw input from the settings form. * @return array Sanitized options. */ function accelvia_sanitize_options($input) { $sanitized = array(); // Checkboxes – cast to '1' or '0'. $checkboxes = array( 'enable_protection', 'disable_right_click', 'disable_shortcuts', 'disable_text_selection', 'disable_image_drag', 'disable_copy', 'skip_admins', ); foreach ($checkboxes as $key) { $sanitized[$key] = !empty($input[$key]) ? '1' : '0'; } // Notification type – whitelist. $allowed_types = array('alert', 'toast'); $sanitized['notification_type'] = (isset($input['notification_type']) && in_array($input['notification_type'], $allowed_types, true)) ? $input['notification_type'] : 'toast'; // Notification message – sanitize text. $sanitized['notification_message'] = isset($input['notification_message']) ? sanitize_text_field($input['notification_message']) : __('This content is protected by Accelvia.', 'accelvia-content-protection'); // Protected post types – array of sanitized slugs. if (!empty($input['protected_post_types']) && is_array($input['protected_post_types'])) { $sanitized['protected_post_types'] = array_map('sanitize_key', $input['protected_post_types']); } else { $sanitized['protected_post_types'] = array('post', 'page'); } // Excluded page IDs – comma-separated integers. $sanitized['excluded_page_ids'] = ''; if (!empty($input['excluded_page_ids'])) { $raw_ids = preg_split('/[\s,]+/', trim($input['excluded_page_ids'])); $clean_ids = array_filter(array_map('absint', $raw_ids)); $sanitized['excluded_page_ids'] = implode(',', $clean_ids); } return $sanitized; } /** * Enqueue admin assets only on the plugin's settings page. * * @param string $hook Current admin page hook suffix. */ function accelvia_enqueue_admin_assets($hook) { if ('settings_page_accelvia-protection' !== $hook) { return; } wp_enqueue_style( 'accelvia-admin-css', ACCELVIA_PLUGIN_URL . 'assets/css/admin.css', array(), ACCELVIA_VERSION ); wp_enqueue_script( 'accelvia-admin-js', ACCELVIA_PLUGIN_URL . 'assets/js/admin.js', array(), ACCELVIA_VERSION, true ); } add_action('admin_enqueue_scripts', 'accelvia_enqueue_admin_assets'); /** * Render the full settings page HTML. */ function accelvia_render_settings_page() { if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have permission to access this page.', 'accelvia-content-protection')); } $options = get_option(ACCELVIA_OPTION_KEY, array()); // Merge with defaults to ensure all keys exist. $defaults = array( 'enable_protection' => '0', 'disable_right_click' => '1', 'disable_shortcuts' => '1', 'disable_text_selection' => '0', 'disable_image_drag' => '1', 'disable_copy' => '0', 'notification_type' => 'toast', 'notification_message' => __('This content is protected by Accelvia.', 'accelvia-content-protection'), 'skip_admins' => '1', 'protected_post_types' => array('post', 'page'), 'excluded_page_ids' => '', ); $options = wp_parse_args($options, $defaults); // Get all public post types. $post_types = get_post_types(array('public' => true), 'objects'); ?>