' . esc_html__( 'Important:', 'advanced-nocaptcha-recaptcha' ) . '', esc_html__( 'To reconfigure the failover now, once you are redirected to the plugin\'s configuration page click', 'advanced-nocaptcha-recaptcha' ), '' . esc_html__( 'Reconfigure reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ) . '', esc_html__( 'and click', 'advanced-nocaptcha-recaptcha' ), '' . esc_html__( 'Next', 'advanced-nocaptcha-recaptcha' ) . '', esc_html__( 'in the wizard until you get to the failover settings.', 'advanced-nocaptcha-recaptcha' ) ); if ( in_array( 'administrator', (array) $user->roles ) ) { echo '

' . esc_html__( 'In the latest version of CAPTCHA 4WP you can configure a failover action for your CAPTCHA check. This means that you can configure the plugin to show a CAPTCHA checkbox or redirect the user when the current v3 reCAPTCHA check fails. Use the buttons below to configure the failover or close this admin notice.', 'advanced-nocaptcha-recaptcha' ) . '

' . $help_text . '

' . esc_html__( 'Configure failover action now', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( "I'll configure it later", 'advanced-nocaptcha-recaptcha' ) . '
'; } } } /** * Add settings page scripts. * * @return void */ public function admin_enqueue_scripts() { wp_register_script( 'c4wp-admin', C4WP_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-ui-dialog' ), C4WP_PLUGIN_VERSION, false ); wp_enqueue_style( 'wp-jquery-ui-dialog' ); } /** * Add settings pages to WP admin. * * @return void */ public function admin_init() { register_setting( 'c4wp_admin_options', 'c4wp_admin_options', array( $this, 'options_sanitize' ) ); $current_tab = 'c4wp-admin-captcha'; if ( ! empty( $_GET['page'] ) ) { // phpcs:ignore $current_tab = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore } foreach ( $this->get_sections( $current_tab ) as $section_id => $section ) { add_settings_section( $section_id, $section['section_title'], ! empty( $section['section_callback'] ) ? $section['section_callback'] : null, 'c4wp_admin_options' ); } $skip = array( 'captcha_version_title', 'captcha_version', 'site_key_title', 'site_key_subtitle', 'site_key', 'secret_key', 'key_validation', 'failure_action', 'failure_redirect', 'failure_v2_site_key', 'failure_v2_secret_key', 'failure_key_validation', ); foreach ( $this->get_fields() as $field_id => $field ) { if ( in_array( $field_id, $skip ) ) { continue; } add_settings_field( $field['id'], $field['label'], ! empty( $field['callback'] ) ? $field['callback'] : array( $this, 'callback' ), 'c4wp_admin_options', $field['section_id'], $field ); } } /** * Create sections used within settings. * * @param string $section_we_want - Section to return. * @return array $sections - Sections created. */ public function get_sections( $section_we_want = 'c4wp-admin-captcha' ) { $captcha_sections = array( 'google_keys' => array( 'section_title' => '', 'section_callback' => function() { $settings_url = function_exists( 'c4wp_same_settings_for_all_sites' ) && c4wp_same_settings_for_all_sites() ? network_admin_url( 'admin.php?page=c4wp-admin-settings' ) : admin_url( 'admin.php?page=c4wp-admin-settings' ); echo '
' . wp_kses( $this->wizard_markup(), c4wp_allowed_kses_args() ) . '
'; echo ''; printf( /* translators: link to the settings page with text "Settings page" */ esc_html__( 'Use the CAPTCHA configuration wizard to integrate the Google reCAPTCHA service so you can add CAPTCHA checks on your website. Once you configure the integration navigate to the %s page to configure where CAPTCHA should be added on your website, whitelist IP addresses and configure other settings', 'advanced-nocaptcha-recaptcha' ), '' . esc_html__( 'Settings & placements', 'advanced-nocaptcha-recaptcha' ) . '' ); echo ''; echo wp_kses( $this->wizard_launcher_area(), c4wp_allowed_kses_args() ); }, ), ); $settings_sections = array( 'forms' => array( 'section_title' => '', 'section_callback' => function() { echo ''; esc_html_e( 'In this page you can configure where on your website you want to add the CAPTCHA check. You can also configure several other settings, such as whitelisting IP addresses, excluding logged in users from CAPTCHA checks and more.', 'advanced-nocaptcha-recaptcha' ); echo ''; }, ), 'other' => array( 'section_title' => '', ), ); $sections = ( 'c4wp-admin-captcha' === $section_we_want ) ? $captcha_sections : $settings_sections; return apply_filters( 'c4wp_settings_sections', $sections ); } /** * Main plugin setting fields. * * @return array - Settings fields. */ public function get_fields() { $score_values = array(); for ( $i = 0.0; $i <= 1; $i += 0.1 ) { $score_values[ "$i" ] = number_format_i18n( $i, 1 ); } $score_description = sprintf( /* translators: expression "very restrictive" in bold */ esc_html__( 'Any value above 0.5 is %s.', 'advanced-nocaptcha-recaptcha' ), '' . __( 'very restrictive', 'advanced-nocaptcha-recaptcha' ) . '' ); $score_description .= ' ' . esc_html__( 'This means that you might end up locked out from your website. Therefore test this on a staging website website beforehand.', 'advanced-nocaptcha-recaptcha' ); $role_select_html = '', esc_attr( $field['type'] ), esc_attr( $field['id'] ), esc_attr( $field['el_class'] ), esc_attr( $field['id'] ), isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '', esc_attr( $value ), $attrib, // phpcs:ignore esc_attr( $field['class'] ) ); break; case 'number': printf( '', esc_attr( $field['type'] ), esc_attr( $field['id'] ), esc_attr( $field['class'] ), esc_attr( $field['id'] ), isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '', esc_attr( $value ), $attrib, // phpcs:ignore esc_attr( $field['min_val'] ), esc_attr( $field['max_val'] ) ); break; case 'number-inline': printf( '%8$s %9$s', esc_attr( 'number' ), esc_attr( $field['id'] ), esc_attr( $field['class'] ), esc_attr( $field['id'] ), isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '', esc_attr( $value ), $attrib, // phpcs:ignore esc_attr( $field['cb_label'] ), esc_attr( $field['cb_label_after'] ), esc_attr( $field['min_val'] ), esc_attr( $field['max_val'] ) ); break; case 'textarea': printf( '', esc_attr( $field['id'] ), esc_attr( $field['class'] ), esc_attr( $field['id'] ), isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '', $attrib, // phpcs:ignore esc_textarea( $value ) ); break; case 'checkbox': printf( '', esc_attr( $field['id'] ) ); printf( '', 'checkbox', esc_attr( $field['id'] ), esc_attr( $field['class'] ), esc_attr( $field['id'] ), '1', checked( $value, '1', false ), esc_attr( $field['cb_label'] ) ); break; case 'multicheck': printf( '', esc_attr( $field['id'] ) ); foreach ( $field['options'] as $key => $label ) { printf( '
', 'checkbox', esc_attr( $field['id'] ), esc_attr( $field['class'] ), esc_attr( $field['id'] ), esc_attr( $key ), checked( in_array( $key, (array) $value ), true, false ), esc_attr( $label ) ); } break; case 'select': printf( '' ); break; case 'html': echo $field['std']; // phpcs:ignore break; case 'radio': foreach ( $field['options'] as $key => $label ) { printf( '

', esc_attr( $key ), checked( $value, $key, false ), esc_attr( $label ), esc_attr( $field['id'] ), esc_attr( $field['el_class'] ) ); } break; default: /* translators:field type */ printf( esc_html__( 'No hook defined for %s', 'advanced-nocaptcha-recaptcha' ), esc_html( $field['type'] ) ); break; } if ( $return ) { $output = ob_get_clean(); return $output; } } /** * Sanitize provided value. * * @param string $value - Value to sanitize. * @return string $value - Sanitized value. */ public function options_sanitize( $value ) { if ( ! $value || ! is_array( $value ) ) { return $value; } $fields = $this->get_fields(); foreach ( $value as $option_slug => $option_value ) { if ( isset( $fields[ $option_slug ] ) && ! empty( $fields[ $option_slug ]['sanitize_callback'] ) ) { $value[ $option_slug ] = call_user_func( $fields[ $option_slug ]['sanitize_callback'], $option_value ); } elseif ( isset( $fields[ $option_slug ] ) ) { $value[ $option_slug ] = $this->posted_value_sanitize( $option_value, $fields[ $option_slug ] ); } } return $value; } /** * Sanitize posted value. * * @param string $value - Value to sanitize. * @param array $field - Field to sanitize. * @return string$sanitized - Sanitized value. */ public function posted_value_sanitize( $value, $field ) { $sanitized = $value; switch ( $field['type'] ) { case 'text': case 'hidden': $sanitized = sanitize_text_field( trim( $value ) ); break; case 'url': $sanitized = esc_url( $value ); break; case 'number': case 'number-inline': if ( isset( $field['id'] ) && 'failed_login_cron_schedule' === $field['id'] ) { if ( absint( $value ) > 10 ) { $value = 10; } elseif ( absint( $value ) < 1 ) { $value = 1; } } if ( isset( $field['id'] ) && 'failed_login_allow' === $field['id'] ) { if ( absint( $value ) > 20 ) { $value = 10; } elseif ( absint( $value ) < 1 ) { $value = 1; } } $sanitized = absint( $value ); break; case 'textarea': case 'wp_editor': case 'teeny': $sanitized = wp_kses_post( $value ); break; case 'checkbox': $sanitized = absint( $value ); break; case 'multicheck': $sanitized = is_array( $value ) ? array_filter( $value ) : array(); foreach ( $sanitized as $key => $p_value ) { if ( ! array_key_exists( $p_value, $field['options'] ) ) { unset( $sanitized[ $key ] ); } } break; case 'select': if ( ! array_key_exists( $value, $field['options'] ) ) { $sanitized = isset( $field['std'] ) ? $field['std'] : ''; } break; default: $sanitized = apply_filters( 'c4wp_settings_field_sanitize_filter_' . $field['type'], $value, $field ); break; } return apply_filters( 'c4wp_settings_field_sanitize_filter', $sanitized, $field, $value ); } /** * Create admin menu link. * * @return void */ public function menu_page() { $icon_url = C4WP_PLUGIN_URL . 'assets/img/20x20-icon.png'; add_menu_page( esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'CAPTCHA 4WP', 'advanced-nocaptcha-recaptcha' ), 'manage_options', 'c4wp-admin-captcha', array( $this, 'admin_settings' ), $icon_url, 99 ); $hook_captcha_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), 'manage_options', 'c4wp-admin-captcha', array( $this, 'admin_settings' ), 0 ); $hook_settings_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'CAPTCHA 4WP Settings', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Settings & Placements', 'advanced-nocaptcha-recaptcha' ), 'manage_options', 'c4wp-admin-settings', array( $this, 'admin_settings' ), 1 ); $hook_help_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'Help & Contact Us', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Help & Contact Us', 'advanced-nocaptcha-recaptcha' ), 'manage_options', 'c4wp-admin-help', array( $this, 'admin_settings' ), 5 ); if ( ! function_exists( 'c4wp_fs' ) || function_exists( 'c4wp_fs' ) && c4wp_fs()->is_not_paying() ) { $hook_upgrade_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'Premium Features ➤', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Premium Features ➤', 'advanced-nocaptcha-recaptcha' ), 'manage_options', 'c4wp-admin-upgrade', array( $this, 'admin_settings' ), 2 ); add_action( "load-$hook_upgrade_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); } add_action( "load-$hook_captcha_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); add_action( "load-$hook_help_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); add_action( "load-$hook_settings_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); } /** * Create network admin menu link. * * @return void */ public function network_menu_page() { add_menu_page( esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'CAPTCHA 4WP', 'advanced-nocaptcha-recaptcha' ), 'manage_network_options', 'c4wp-admin-captcha', array( $this, 'admin_settings' ), '', 99 ); $hook_captcha_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'CAPTCHA Configuration', 'advanced-nocaptcha-recaptcha' ), 'manage_network_options', 'c4wp-admin-captcha', array( $this, 'admin_settings' ), 0 ); $hook_settings_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'CAPTCHA 4WP Settings', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Settings & Placements', 'advanced-nocaptcha-recaptcha' ), 'manage_network_options', 'c4wp-admin-settings', array( $this, 'admin_settings' ), 1 ); $hook_help_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'Help & Contact Us', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Help & Contact Us', 'advanced-nocaptcha-recaptcha' ), 'manage_network_options', 'c4wp-admin-help', array( $this, 'admin_settings' ), 5 ); if ( ! function_exists( 'c4wp_fs' ) || function_exists( 'c4wp_fs' ) && c4wp_fs()->is_not_paying() ) { $hook_upgrade_submenu = add_submenu_page( 'c4wp-admin-captcha', esc_html__( 'Premium Features ➤', 'advanced-nocaptcha-recaptcha' ), esc_html__( 'Premium Features ➤', 'advanced-nocaptcha-recaptcha' ), 'manage_network_options', 'c4wp-admin-upgrade', array( $this, 'admin_settings' ), 2 ); add_action( "load-$hook_upgrade_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); } add_action( "load-$hook_captcha_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); add_action( "load-$hook_help_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); add_action( "load-$hook_settings_submenu", array( $this, 'c4wp_admin_page_enqueue_scripts' ) ); } /** * Add admin CSS. * * @return void */ public function c4wp_admin_page_enqueue_scripts() { $version = C4WP_PLUGIN_VERSION; wp_enqueue_style( 'c4wp-admin', C4WP_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); } /** * Save settings. * * @return void */ public function settings_save() { if ( current_user_can( 'manage_options' ) && isset( $_POST['c4wp_admin_options'] ) && isset( $_POST['action'] ) && 'update' === $_POST['action'] && isset( $_GET['page'] ) && 'c4wp-admin-settings' === $_GET['page'] || current_user_can( 'manage_options' ) && isset( $_POST['c4wp_admin_options'] ) && isset( $_POST['action'] ) && 'update' === $_POST['action'] && isset( $_GET['page'] ) && 'c4wp-admin-captcha' === $_GET['page'] ) { check_admin_referer( 'c4wp_admin_options-options' ); $post_array = filter_input_array( INPUT_POST ); $value = isset( $post_array['c4wp_admin_options'] ) ? wp_unslash( $post_array['c4wp_admin_options'] ) : false; if ( ! is_array( $value ) ) { $value = array(); } $value = $this->validate_and_set_notices( $value ); c4wp_update_option( $value ); wp_safe_redirect( add_query_arg( 'updated', true ) ); exit; } } /** * Settings page markup. * * @return void */ public function admin_settings() { wp_enqueue_script( 'c4wp-admin' ); wp_localize_script( 'c4wp-admin', 'anrScripts', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'captcha_version' => c4wp_get_option( 'captcha_version', 'v2_checkbox' ), 'ipWarning' => esc_html__( 'Please supply a valid IP', 'advanced-nocaptcha-recaptcha' ), 'switchingWarning' => esc_html__( 'To switch the reCAPTCHA method you need to replace the current Site and Secret keys. Do you want to proceed?', 'advanced-nocaptcha-recaptcha' ), 'switchingWarningTitle' => esc_html__( 'Confirm change of reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ), 'removeConfigWarningTitle' => esc_html__( 'Confirm removal of reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ), 'removeConfigWarning' => esc_html__( 'This will remove the current reCAPTCHA integration, which means all the CAPTCHA checks on your website will stop working. Would you like to proceed?', 'advanced-nocaptcha-recaptcha' ), ) ); $current_tab = 'c4wp-admin-captcha'; if ( ! empty( $_GET['page'] ) ) { // phpcs:ignore $current_tab = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore } // Determine if a Site/Secret key has been stored. $site_key = trim( c4wp_get_option( 'site_key' ) ); $secret_key = trim( c4wp_get_option( 'secret_key' ) ); $settings_url = function_exists( 'c4wp_same_settings_for_all_sites' ) && c4wp_same_settings_for_all_sites() ? network_admin_url( 'admin.php?page=c4wp-admin-captcha' ) : admin_url( 'admin.php?page=c4wp-admin-captcha' ); $settings_wrapper_class = ( empty( $site_key ) || empty( $secret_key ) ) ? 'captcha_keys_required wrap fs-section' : 'wrap fs-section'; $show_wizard = ( empty( c4wp_get_option( 'site_key' ) ) && empty( $site_key ) && empty( $secret_key ) ) ? 'show_wizard_on_load' : ''; ?>

settings_form(); } elseif ( 'c4wp-admin-help' === $current_tab ) { $this->display_help_page(); } elseif ( 'c4wp-admin-upgrade' === $current_tab ) { $this->display_upgrade_page(); } ?>
c4wp_admin_sidebar(); ?>

c4wp_settings_notice(); ?>

' . esc_html__( 'The site key that you have entered is invalid. Please try again.', 'advanced-nocaptcha-recaptcha' ) . '

'; } if ( 'empty_secret_key' === $error ) { $notice .= '

' . esc_html__( 'The secret key that you have entered is invalid. Please try again.', 'advanced-nocaptcha-recaptcha' ) . '

'; } if ( 'success' === $error ) { $context = esc_html__( 'CAPTCHA settings', 'advanced-nocaptcha-recaptcha' ); if ( isset( $_REQUEST['page'] ) && 'c4wp-admin-captcha' === $_REQUEST['page'] ) { // phpcs:ignore $context = esc_html__( 'CAPTCHA configuration', 'advanced-nocaptcha-recaptcha' ); // phpcs:ignore } $notice .= '

' . $context . esc_html__( ' updated', 'advanced-nocaptcha-recaptcha' ) . '

'; } } delete_transient( 'c4wp_admin_options_errors' ); echo wp_kses_post( $notice ); } /** * Create admin sidebar. * * @return string $return - HTNML markup. */ public function c4wp_admin_sidebar() { $return = ''; if ( ! c4wp_is_premium_version() ) : $icon_url = C4WP_PLUGIN_URL . 'assets/img/c4wp-logo-full.png'; $return .= sprintf( '

' . esc_html__( 'Upgrade to Premium for:', 'advanced-nocaptcha-recaptcha' ) . '

  • ' . esc_html__( 'Use the language that your website viewers understand', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Spam protection for your WooCommerce stores', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Specify where to put the CAPTCHA test on WooCommerce checkout page', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'One-click spam protection for forms built with Contact Form 7, Gravity Forms, WPForms & MailChimp for WordPress', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'CAPTCHA tests & spam protection for BuddyPress, bbPress & other third party plugins', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Add CAPTCHA to any type of form, even PHP forms', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Boost login security, add CAPTCHA tests only failed logins', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Remove CAPTCHA for logged in users', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Remove CAPTCHA for specific IP addresses', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'Remove CAPTCHA from specific URLs', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'No Ads!', 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( 'Upgrade to Premium', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Get a FREE 14-day trial', 'advanced-nocaptcha-recaptcha' ) . '

', esc_url( 'https://www.wpwhitesecurity.com/wordpress-plugins/captcha-plugin-wordpress/pricing/?utm_source=plugin&utm_medium=banner&utm_campaign=C4WP&utm_content=plugin+premium+button' ), function_exists( 'c4wp_fs' ) ? c4wp_fs()->get_upgrade_url() : 'https://www.wpwhitesecurity.com/wordpress-plugins/captcha-plugin-wordpress/plugin-trial/?utm_source=plugin&utm_medium=banner&utm_campaign=C4WP&utm_content=get+trial' ); endif; return $return; } /** * Validate targetted options and remove from the array which is about to be saved if invalid. * Also handles error/success notices based on result. * * @param array $value - Value to validate. * @return array - Validated value. * * @since 7.0.0 */ public function validate_and_set_notices( $value ) { $errors = array(); if ( isset( $value['site_key'] ) && isset( $value['secret_key'] ) ) { $site_key = $value['site_key']; $secret_key = $value['secret_key']; $allowed = array( '-', '_' ); if ( empty( $site_key ) || ! ctype_alnum( str_replace( $allowed, '', $site_key ) ) ) { $errors[] = 'empty_site_key'; unset( $value['site_key'] ); } if ( empty( $secret_key ) || ! ctype_alnum( str_replace( $allowed, '', $secret_key ) ) ) { $errors[] = 'empty_secret_key'; unset( $value['secret_key'] ); } } // Let user know how it went. if ( $errors ) { set_transient( 'c4wp_admin_options_errors', $errors, 30 ); } else { set_transient( 'c4wp_admin_options_errors', array( 'success' ), 30 ); } return $value; } /** * Add link to settings to dashboard menu. * * @param array $links - Default links. * @return array $links - Updated links. */ public function add_settings_link( $links ) { // add settings link in plugins page. $settings_link = '' . esc_html__( 'Settings', 'advanced-nocaptcha-recaptcha' ) . ''; $append_link = ( is_multisite() && function_exists( 'c4wp_same_settings_for_all_sites' ) && c4wp_same_settings_for_all_sites() ) ? true : false; if ( $append_link || ! is_multisite() ) { array_unshift( $links, $settings_link ); } return $links; } /** * Includs help page content. * * @return void */ public function display_help_page() { require_once 'templates/help/index.php'; } /** * Includs upgrade page content. * * @return void */ public function display_upgrade_page() { require_once 'templates/upgrade/index.php'; } /** * Help function to push an item to an associate array. * * @param array $array - Original array. * @param string $key - new item key. * @param string $new - New item svalue. * @return array $array - Updated array. */ public static function push_at_to_associative_array( $array, $key, $new ) { $keys = array_keys( $array ); $index = array_search( $key, $keys, true ); $pos = false === $index ? count( $array ) : $index + 1; $array = array_slice( $array, 0, $pos, true ) + $new + array_slice( $array, $pos, count( $array ) - 1, true ); return $array; } /** * Ignore admin notice. * * @return void */ public static function c4wp_nocaptcha_plugin_notice_ignore() { // Grab POSTed data. $nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_STRING ); $notice_type = filter_input( INPUT_POST, 'notice_type', FILTER_SANITIZE_STRING );; // Check nonce. if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'dismiss_captcha_notice' ) ) { wp_send_json_error( esc_html__( 'Nonce Verification Failed.', 'advanced-nocaptcha-recaptcha' ) ); } if ( 'multisite' == $notice_type ) { global $current_user; $user_id = $current_user->ID; $updated = add_user_meta( $user_id, 'nocaptcha_plugin_notice_ignore', 'true', true ); if ( function_exists( 'c4wp_same_settings_for_all_sites' ) && c4wp_same_settings_for_all_sites() ) { update_site_option( 'c4wp_network_notice_dismissed', true ); } else { update_option( 'c4wp_network_notice_dismissed', true ); } wp_send_json_success( $updated ); } elseif ( 'v3_fallback' == $notice_type ) { if ( function_exists( 'c4wp_same_settings_for_all_sites' ) && c4wp_same_settings_for_all_sites() ) { update_site_option( 'c4wp_v3_failover_available', false ); } else { update_option( 'c4wp_v3_failover_available', false ); } } wp_send_json_success(); } /** * Handles markup of the popup settings wizard. * * @return $markup - HTML markup. */ public function wizard_markup() { $fields = $this->get_fields(); // Add intro card if this is running in 'first time' mode. $show_wizard_intro = ( empty( c4wp_get_option( 'captcha_version' ) ) && empty( $site_key ) && empty( $secret_key ) ) ? true : false; $logo_url = C4WP_PLUGIN_URL . 'assets/img/c4wp-logo-full.png'; $intro_content = '
' . esc_html__( 'Getting started with the CAPTCHA 4WP plugin', 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( 'Thank you for installing the CAPTCHA 4WP plugin. This wizard will help you get started with the plugin so you can configure CAPTCHA and protect your website from spam, and fake registrations and orders.', 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( 'Next', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Cancel', 'advanced-nocaptcha-recaptcha' ) . '
'; $back_to_intro = '' . esc_html__( 'Back', 'advanced-nocaptcha-recaptcha' ) . ''; $markup = '
' . $intro_content . '
' . $fields['captcha_version_title']['label'] . '

' . $fields['captcha_version']['label'] . '

' . $this->callback( $fields['captcha_version'], true ) . '
' . esc_html__( 'Next', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Cancel', 'advanced-nocaptcha-recaptcha' ) . '
' . $fields['site_key_title']['label'] . ' ' . $fields['site_key_subtitle']['label'] . '

' . $fields['site_key']['label'] . ' ' . $this->callback( $fields['site_key'], true ) . '

' . $fields['secret_key']['label'] . ' ' . $this->callback( $fields['secret_key'], true ) . '

' . $this->callback( $fields['key_validation'], true ) . '

' . esc_html__( 'Next', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Back', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Cancel', 'advanced-nocaptcha-recaptcha' ) . '
' . esc_html__( 'Step 3: Configure a failover action for reCAPTCHA v3 failure', 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( 'reCAPTCHA v3 is fully automated. This means that by default, if the CAPTCHA check fails the website visitor cannot proceed with what they are doing unless you configure a failover action. Use the below setting to configure the failover action.', 'advanced-nocaptcha-recaptcha' ) . '

' . $fields['failure_action']['label'] . ' ' . $this->callback( $fields['failure_action'], true ) . '

' . $fields['failure_redirect']['label'] . ' ' . $this->callback( $fields['failure_redirect'], true ) . '

' . $fields['failure_v2_site_key']['label'] . ' ' . $this->callback( $fields['failure_v2_site_key'], true ) . '

' . $fields['failure_v2_secret_key']['label'] . ' ' . $this->callback( $fields['failure_v2_secret_key'], true ) . '

' . $this->callback( $fields['failure_key_validation'], true ) . '

' . esc_html__( 'Next', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Back', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Cancel', 'advanced-nocaptcha-recaptcha' ) . '
' . esc_html__( ' All done - you can now add CAPTCHA checks to your website', 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( "Now that the Google reCAPTCHA service is fully integrated you can use the optional settings to fine-tune CAPTCHA to your requirements. All the CAPTCHA settings are optional and with them you can configure aspects such as look and feel and CAPTCHA sensitivity. When you are ready navigate to the Settings & Placements page to configure where you'd like to add the CAPTCHA checks", 'advanced-nocaptcha-recaptcha' ) . '

' . esc_html__( 'Finish', 'advanced-nocaptcha-recaptcha' ) . '
'; return $markup; } /** * Handles markup for showing the 'launch wizard' buttons as well as current plugin config. * * @return $markup - HTML Markup */ public function wizard_launcher_area() { $site_key = trim( c4wp_get_option( 'site_key' ) ); $secret_key = trim( c4wp_get_option( 'secret_key' ) ); $captcha_version = trim( c4wp_get_option( 'captcha_version' ) ); $failure_action = trim( c4wp_get_option( 'failure_action' ) ); $reset_nonce = wp_create_nonce( 'reset_captcha_nonce' ); if ( $site_key && $secret_key ) { $markup = '
' . esc_html__( 'Reconfigure reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ) . ' ' . esc_html__( 'Remove reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ) . ' '; $markup .= ' '; } else { $markup = '
' . esc_html__( 'Configure Google reCAPTCHA integration', 'advanced-nocaptcha-recaptcha' ) . ' '; } return $markup; } /** * Reset current version and keys. * * @return void */ public function c4wp_reset_captcha_config() { // Grab POSTed data. $nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_STRING ); // Check nonce. if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'reset_captcha_nonce' ) ) { wp_send_json_error( esc_html__( 'Nonce Verification Failed.', 'advanced-nocaptcha-recaptcha' ) ); } c4wp_update_option( 'site_key' ); c4wp_update_option( 'secret_key' ); c4wp_update_option( 'captcha_version' ); wp_send_json_success(); } /** * Adds a setting to allow for testing different CAPTCHA results. * * @param array $fields - Current settings array. * @return array $fields - Modified array. */ public function add_logging_and_testing_settings( $fields ) { $stored = c4wp_get_option( 'c4wp_recent_results' ); $nice_display = ''; $additonal_options['override_result'] = array( 'label' => esc_html__( 'Override validation response.', 'advanced-nocaptcha-recaptcha' ), 'section_id' => 'google_keys', 'type' => 'select', 'class' => 'regular', 'std' => 'no_override', 'options' => array( 'no_override' => esc_html__( 'Do no override', 'advanced-nocaptcha-recaptcha' ), 'return_false' => esc_html__( 'Return false (failure)', 'advanced-nocaptcha-recaptcha' ), 'return_true' => esc_html__( 'Return true (pass)', 'advanced-nocaptcha-recaptcha' ), ), 'desc' => '', ); $additonal_options['recent_verification_results'] = array( 'section_id' => 'google_keys', 'type' => 'html', 'label' => sprintf( '

' ), 'class' => 'wrap-around-content c4wp-wizard-captcha-version', ); $fields = self::push_at_to_associative_array( $fields, array_key_last( $fields ), $additonal_options ); return $fields; } } //END CLASS add_action( 'wp_loaded', array( C4WP_Settings::init(), 'actions_filters' ) );