ID; $current_screen = get_current_screen(); $notice_nonce = wp_create_nonce( 'dismiss_captcha_notice' ); $logo_img_src = C4WP_PLUGIN_URL . 'assets/img/c4wp-logo-300x300.png'; // General notice in dashboard. if ( current_user_can( 'manage_options' ) && ! get_user_meta( $user_id, 'c4wp_nocaptcha_plugin_notice_ignore') ) { // Add scripts. wp_enqueue_script( 'c4wp-admin' ); echo '

Breaking change:

'. __('Support for adding CAPTCHA on forms by third party plugins has now been moved to Premium only (as it was originally supposed to be). If you have been using any of these features send us an email and we will give you a free 3-months license so you can keep on using the plugin and have enough time to think about ') .' upgrading to Premium.

Dismiss.

'; } } function c4wp_nocaptcha_upgrade_plugin_notice_ignore() { // Grab POSTed data. $nonce = filter_input( INPUT_POST, 'nonce', 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' ) ); } global $current_user; $user_id = $current_user->ID; $updated = add_user_meta( $user_id, 'c4wp_nocaptcha_plugin_notice_ignore', 'true', true ); wp_send_json_success($updated); } function admin_enqueue_scripts() { wp_register_script( 'c4wp-admin', C4WP_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), C4WP_PLUGIN_VERSION, false ); } function admin_init() { register_setting( 'c4wp_admin_options', 'c4wp_admin_options', [ $this, 'options_sanitize' ] ); $current_tab = 'c4wp-admin-captcha'; if( ! empty( $_GET['page'] ) ) { $current_tab = $_GET['page']; } 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' ); } foreach ( $this->get_fields() as $field_id => $field ) { add_settings_field( $field['id'], $field['label'], ! empty( $field['callback'] ) ? $field['callback'] : array( $this, 'callback' ), 'c4wp_admin_options', $field['section_id'], $field ); } } function get_sections( $section_we_want = 'c4wp-admin-captcha' ) { $captcha_sections = [ 'google_keys' => [ '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 ''; printf( /* translators: link to the settings page with text "Settings page" */ esc_html__( 'In this page you can configure the type of reCAPTCHA that you want to use on your website. Once you configure your CAPTCHA, head to the %s to configure where the CAPTCHA should be used, whitelist IP addresses and configure other settings.', 'advanced-nocaptcha-recaptcha' ), '' . esc_html__( 'Settings page', 'advanced-nocaptcha-recaptcha' ) . '' ); echo ''; }, ], ]; $settings_sections = [ 'forms' => [ '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' => [ 'section_title' => '', ], ]; $sections = ( $section_we_want == 'c4wp-admin-captcha' ) ? $captcha_sections : $settings_sections; return apply_filters( 'c4wp_settings_sections', $sections ); } function get_fields() { $score_values = []; 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['class'] ), esc_attr( $field['id'] ), isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '', esc_attr( $value ), $attrib ); 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, 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, 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, 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']; 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['class'] ) ); } break; default: printf( esc_html__( 'No hook defined for %s', 'advanced-nocaptcha-recaptcha' ), esc_html( $field['type'] ) ); break; } } 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; } 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; } else if ( absint( $value ) < 1 ) { $value = 1; } } if ( isset( $field['id'] ) && 'failed_login_allow' == $field['id'] ) { if ( absint( $value ) > 20 ) { $value = 10; } else if ( 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 ); } 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', [ $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', [ $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', [ $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', [ $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', [ $this, 'admin_settings' ], 2 ); add_action( "load-$hook_upgrade_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); } add_action( "load-$hook_captcha_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); add_action( "load-$hook_help_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); add_action( "load-$hook_settings_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); } 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', [ $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', [ $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', [ $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', [ $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', [ $this, 'admin_settings' ], 2 ); add_action( "load-$hook_upgrade_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); } add_action( "load-$hook_captcha_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); add_action( "load-$hook_help_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); add_action( "load-$hook_settings_submenu", [ $this, 'c4wp_admin_page_enqueue_scripts' ] ); } function c4wp_admin_page_enqueue_scripts() { wp_enqueue_style( 'c4wp-admin', C4WP_PLUGIN_URL . 'assets/css/admin.css' ); } 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' ); $value = wp_unslash( $_POST['c4wp_admin_options'] ); if ( ! is_array( $value ) ) { $value = []; } $value = $this->validate_and_set_notices( $value ); c4wp_update_option( $value ); wp_safe_redirect( add_query_arg( 'updated', true ) ); exit; } } function admin_settings() { wp_enqueue_script( 'c4wp-admin' ); wp_localize_script( 'c4wp-admin', 'anrScripts', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'ipWarning' => esc_html__( 'Please supply a valid IP', 'advanced-nocaptcha-recaptcha' ) ) ); $current_tab = 'c4wp-admin-captcha'; if( ! empty( $_GET['page'] ) ) { $current_tab = $_GET['page']; } ?>

settings_form(); } else if ( 'c4wp-admin-help' == $current_tab ) { $this->display_help_page(); } else if ( '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'] ) { $context = esc_html__( 'Captcha configuration', 'advanced-nocaptcha-recaptcha' ); } $notice .= '

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

'; } } delete_transient( 'c4wp_admin_options_errors' ); echo $notice; } 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 Contact Form 7 forms spam protection', 'advanced-nocaptcha-recaptcha' ) . '
  • ' . esc_html__( 'One-click spam protection for Mailchimp for WordPress forms', '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__( 'Find out more', '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/?utm_source=plugin&utm_medium=banner&utm_campaign=C4WP&utm_content=find+out+more+button' ); 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 * @return array * * @since 7.0.0 */ function validate_and_set_notices( $value ) { $errors = []; 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', [ 'success' ], 30 ); } return $value; } function add_settings_link( $links ) { // add settings link in plugins page $settings_link = '' . esc_html__( 'Settings', 'advanced-nocaptcha-recaptcha' ) . ''; array_unshift( $links, $settings_link ); return $links; } function display_help_page() { require_once 'templates/help/index.php'; } function display_upgrade_page() { require_once 'templates/upgrade/index.php'; } 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; } } //END CLASS add_action( 'wp_loaded', array( C4WP_Settings::init(), 'actions_filters' ) );