'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => 'never', ) ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_settings_group', 'nsc3ppm_notify_email', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_email', 'default' => get_option( 'admin_email' ), ) ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_settings_group', 'nsc3ppm_notify_frequency', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => 'do_not_notify', ) ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_settings_group', 'nsc3ppm_sample_percentage', array( 'type' => 'integer', 'sanitize_callback' => 'intval', 'default' => 10, ) ); // Register new setting for enabling/disabling the plugin. // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_settings_group', 'nsc3ppm_monitoring_enabled', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, ) ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_csp_settings_group', 'nsc3ppm_enable_csp_rules', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, ) ); // phpcs:ignore PluginCheck.CodeAnalysis.SettingSanitization.register_settingDynamic register_setting( 'nsc3ppm_csp_settings_group', 'nsc3ppm_allowed_hostnames', array( 'type' => 'string', 'sanitize_callback' => array( $this, 'nsc3ppm_sanitize_hostnames' ), 'default' => '', ) ); // Add the settings section. add_settings_section( 'nsc3ppm_settings_section', 'Request Interceptor Settings', array( $this, 'nsc3ppm_settings_section_callback' ), 'nsc3ppm_settings_page_slug' ); add_settings_section( 'nsc3ppm_block_settings_section', 'Configure Allowed Hostnames for CSP', array( $this, 'nsc3ppm_block_settings_section_callback' ), 'nsc3ppm_block_settings_page_slug' ); // Add the new field for enabling/disabling the plugin. add_settings_field( 'nsc3ppm_monitoring_enabled', '3rd Party Monitoring', array( $this, 'nsc3ppm_monitoring_enabled_field_callback' ), 'nsc3ppm_settings_page_slug', 'nsc3ppm_settings_section' ); // Add existing settings fields. add_settings_field( 'nsc3ppm_data_retention', 'Data Retention Period', array( $this, 'nsc3ppm_data_retention_field_callback' ), 'nsc3ppm_settings_page_slug', 'nsc3ppm_settings_section' ); add_settings_field( 'nsc3ppm_notify_email', 'Notification Email', array( $this, 'nsc3ppm_notify_email_field_callback' ), 'nsc3ppm_settings_page_slug', 'nsc3ppm_settings_section' ); add_settings_field( 'nsc3ppm_notify_frequency', 'Notification Frequency', array( $this, 'nsc3ppm_notify_frequency_field_callback' ), 'nsc3ppm_settings_page_slug', 'nsc3ppm_settings_section' ); add_settings_field( 'nsc3ppm_sample_percentage', 'Sample Percentage', array( $this, 'nsc3ppm_sample_percentage_field_callback' ), 'nsc3ppm_settings_page_slug', 'nsc3ppm_settings_section' ); add_settings_field( 'nsc3ppm_enable_csp_rules', 'Enable CSP Rules', array( $this, 'nsc3ppm_enable_csp_rules_callback' ), 'nsc3ppm_block_settings_page_slug', 'nsc3ppm_block_settings_section' ); add_settings_field( 'nsc3ppm_allowed_hostnames', 'Allowed Hostnames (one per line)', array( $this, 'nsc3ppm_allowed_hostnames_callback' ), 'nsc3ppm_block_settings_page_slug', 'nsc3ppm_block_settings_section' ); } public function nsc3ppm_settings_section_callback() { echo '

Configure settings for the Request Interceptor. Please be aware that "3rd Party Monitoring" is enabled, that it will add some load to your server. We recommend to have it only enabled for a certain amount of time on productive systems.
For continuous monitoring without the impact on your server load, consider using tools such as Cookie Scanner.

'; } public function nsc3ppm_block_settings_section_callback() { echo '

Add the allowed hostnames. Once activated only hostnames specified in this textarea are allowd. If the text area is empty only the hostname of this blog is allowed (_self). This is a powerful tool. Test carefully! Many payment provider need to load scripts from their domain.

'; } public function nsc3ppm_data_retention_field_callback() { $current = get_option( 'nsc3ppm_data_retention', 'never' ); ?>

Choose how long intercepted request data should be kept.

E-mail address to notify when new hostnames are detected. Defaults to the admin e-mail.

Choose whether to get notified when a new hostname is detected. Default is "Do not notify".

Only intercept requests on this percentage of page views (e.g., 10 means 10% of page views are sampled). Default is 100%.

Toggle to enable or disable the monitoring of 3rd Party requests.

Check to enable the addition of CSP rules to your site headers.

Enter one hostname per line. For example: example.com