From 6f00415043174037fbd38f55747659eefc6fa645 Mon Sep 17 00:00:00 2001 From: picocodes Date: Fri, 17 Jun 2022 10:37:26 +0300 Subject: [PATCH] 1.0.1 release changes --- includes/class-hizzle-recaptcha.php | 153 +++++++++++++------------ includes/integrations/base.php | 167 +++++++++++++--------------- includes/integrations/cf7.php | 4 +- includes/integrations/comment.php | 2 +- includes/integrations/login.php | 2 +- includes/settings.php | 30 ++--- languages/hizzle-recaptcha.pot | 62 ++++++----- phpcs.xml.dist | 78 +++++++++++++ plugin.php | 10 +- readme.txt | 7 +- 10 files changed, 294 insertions(+), 221 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/includes/class-hizzle-recaptcha.php b/includes/class-hizzle-recaptcha.php index e81d722..17dc829 100644 --- a/includes/class-hizzle-recaptcha.php +++ b/includes/class-hizzle-recaptcha.php @@ -20,7 +20,7 @@ class Hizzle_reCAPTCHA { * * @var string */ - public static $version = '1.0.0'; + public static $version = '1.0.1'; /** * Loaded integrations. @@ -93,9 +93,8 @@ public function load_integrations() { // Ensure that it is available. if ( isset( $available_integrations[ $integration ] ) ) { require_once $available_integrations[ $integration ]['file']; - self::$integrations[ $integration ] = new $available_integrations[ $integration ]['class']; + self::$integrations[ $integration ] = new $available_integrations[ $integration ]['class'](); } - } } @@ -108,7 +107,7 @@ public function load_integrations() { public function maybe_add_scripts() { if ( self::$load_scripts && $this->show_captcha() ) { $url = apply_filters( 'hizzle_recaptcha_api_url', 'https://www.google.com/recaptcha/api.js' ); - wp_enqueue_script( 'recaptcha', $url, array(), false, true ); + wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } } @@ -141,18 +140,18 @@ public function display_settings_page() { $saved_settings = $this->maybe_save_settings(); $enabled_integrations = $this->get_enabled_integrations(); $available_integrations = wp_list_pluck( $this->get_available_integrations(), 'name' ); - $settings = array( - 'site_key' => array( + $settings = array( + 'site_key' => array( 'type' => 'text', 'label' => __( 'Site Key', 'hizzle-recaptcha' ), 'default' => '', ), - 'secret_key' => array( + 'secret_key' => array( 'type' => 'text', 'label' => __( 'Secret Key', 'hizzle-recaptcha' ), 'default' => '', ), - 'hide_logged_in' => array( + 'hide_logged_in' => array( 'type' => 'checkbox', 'label' => __( 'Hide from logged in users', 'hizzle-recaptcha' ), 'label2' => __( 'If checked, logged in users will not see the reCAPTCHA checkbox', 'hizzle-recaptcha' ), @@ -206,90 +205,90 @@ protected function get_available_integrations() { $integrations = apply_filters( 'hizzle_recaptcha_available_integrations', array( - 'login' => array( - 'name' => __( 'Login Form', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Login_Integration', - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/login.php', + 'login' => array( + 'name' => __( 'Login Form', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Login_Integration', + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/login.php', ), - 'registration' => array( - 'name' => __( 'Registration Form', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Registration_Integration', - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/registration.php', + 'registration' => array( + 'name' => __( 'Registration Form', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Registration_Integration', + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/registration.php', ), - 'resetpass' => array( - 'name' => __( 'Reset Password Form', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Resetpass_Integration', - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/resetpass.php', + 'resetpass' => array( + 'name' => __( 'Reset Password Form', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Resetpass_Integration', + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/resetpass.php', ), - 'lostpassword' => array( - 'name' => __( 'Lost Password Form', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Lost_Password_Integration', - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/lostpassword.php', + 'lostpassword' => array( + 'name' => __( 'Lost Password Form', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Lost_Password_Integration', + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/lostpassword.php', ), - 'comment' => array( - 'name' => __( 'Comment Form', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Comment_Integration', - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/comment.php', + 'comment' => array( + 'name' => __( 'Comment Form', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Comment_Integration', + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/comment.php', ), - 'woocommerce' => array( - 'name' => __( 'WooCommerce Checkout', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_WooCommerce_Integration', - 'installed' => function_exists( 'WC' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/woocommerce.php', + 'woocommerce' => array( + 'name' => __( 'WooCommerce Checkout', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_WooCommerce_Integration', + 'installed' => function_exists( 'WC' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/woocommerce.php', ), - 'noptin' => array( - 'name' => __( 'Noptin Newsletter Forms', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Noptin_Integration', - 'installed' => function_exists( 'noptin' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/noptin.php', + 'noptin' => array( + 'name' => __( 'Noptin Newsletter Forms', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Noptin_Integration', + 'installed' => function_exists( 'noptin' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/noptin.php', ), - 'bbpress-reply' => array( - 'name' => __( 'New Reply (bbPress)', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_bbPress_Reply_Integration', - 'installed' => function_exists( 'bbpress' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/bbpress-reply.php', + 'bbpress-reply' => array( + 'name' => __( 'New Reply (bbPress)', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_bbPress_Reply_Integration', + 'installed' => function_exists( 'bbpress' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/bbpress-reply.php', ), - 'bbpress-topic' => array( - 'name' => __( 'New Topic (bbPress)', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_bbPress_Topic_Integration', - 'installed' => function_exists( 'bbpress' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/bbpress-topic.php', + 'bbpress-topic' => array( + 'name' => __( 'New Topic (bbPress)', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_bbPress_Topic_Integration', + 'installed' => function_exists( 'bbpress' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/bbpress-topic.php', ), - 'buddypress' => array( - 'name' => __( 'New Topic (BuddyPress)', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_BuddyPress_Integration', - 'installed' => function_exists( 'buddypress' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/buddypress.php', + 'buddypress' => array( + 'name' => __( 'New Topic (BuddyPress)', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_BuddyPress_Integration', + 'installed' => function_exists( 'buddypress' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/buddypress.php', ), - 'cf7' => array( - 'name' => __( 'Contact Form 7', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_CF7_Integration', - 'installed' => function_exists( 'wpcf7' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/cf7.php', + 'cf7' => array( + 'name' => __( 'Contact Form 7', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_CF7_Integration', + 'installed' => function_exists( 'wpcf7' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/cf7.php', ), - 'mailchimp' => array( - 'name' => __( 'Mailchimp for WordPress', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_Mailchimp_Integration', - 'installed' => defined( 'MC4WP_VERSION' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/mailchimp.php', + 'mailchimp' => array( + 'name' => __( 'Mailchimp for WordPress', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_Mailchimp_Integration', + 'installed' => defined( 'MC4WP_VERSION' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/mailchimp.php', ), - 'wpforms' => array( - 'name' => __( 'WPForms', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_WPForms_Integration', - 'installed' => function_exists( 'wpforms' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforms.php', + 'wpforms' => array( + 'name' => __( 'WPForms', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_WPForms_Integration', + 'installed' => function_exists( 'wpforms' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforms.php', ), 'wpforo_new_topic' => array( - 'name' => __( 'New Topic (wpForo)', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_WPforo_Topic_Integration', - 'installed' => function_exists( 'WPF' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforo_new_topic.php', + 'name' => __( 'New Topic (wpForo)', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_WPforo_Topic_Integration', + 'installed' => function_exists( 'WPF' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforo_new_topic.php', ), - 'wpforo_reply' => array( - 'name' => __( 'New Reply (wpForo)', 'hizzle-recaptcha' ), - 'class' => 'Hizzle_reCAPTCHA_WPforo_Reply_Integration', - 'installed' => function_exists( 'WPF' ), - 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforo_reply.php', + 'wpforo_reply' => array( + 'name' => __( 'New Reply (wpForo)', 'hizzle-recaptcha' ), + 'class' => 'Hizzle_reCAPTCHA_WPforo_Reply_Integration', + 'installed' => function_exists( 'WPF' ), + 'file' => plugin_dir_path( __FILE__ ) . 'integrations/wpforo_reply.php', ), ) ); diff --git a/includes/integrations/base.php b/includes/integrations/base.php index 92f1f24..7e5a4fa 100644 --- a/includes/integrations/base.php +++ b/includes/integrations/base.php @@ -21,24 +21,9 @@ class Hizzle_reCAPTCHA_Integration { * @since 1.0.0 */ public function get_html() { - Hizzle_reCAPTCHA::$load_scripts = true; - - $data = array( - 'sitekey' => hizzle_recaptcha_get_option( 'site_key' ), - 'theme' => 'light', - 'size' => 'normal', - 'tabindex' => '0', - ); - - $_data = ''; - - foreach ( apply_filters( 'hizzle_recaptcha_data', $data ) as $key => $value ) { - $key = sanitize_key( $key ); - $value = esc_attr( $value ); - $_data .= "data-$key='$value'"; - } - - return "
"; + ob_start(); + $this->display(); + return ob_get_clean(); } /** @@ -47,98 +32,102 @@ public function get_html() { * @since 1.0.0 */ public function display() { - Hizzle_reCAPTCHA::$load_scripts = true; - - $data = array( - 'sitekey' => hizzle_recaptcha_get_option( 'site_key' ), - 'theme' => 'light', - 'size' => 'normal', - 'tabindex' => '0', - ); - - $_data = ''; - - foreach ( apply_filters( 'hizzle_recaptcha_data', $data ) as $key => $value ) { - $key = sanitize_key( $key ); - $value = esc_attr( $value ); - $_data .= "data-$key='$value'"; - } - - echo "
"; + Hizzle_reCAPTCHA::$load_scripts = true; + + $attributes = array( + 'class' => 'g-recaptcha hizzle-recaptcha', + 'style' => 'max-width: 100%; overflow: hidden; margin-top: 10px; margin-bottom: 10px;', + 'data-sitekey' => hizzle_recaptcha_get_option( 'site_key' ), + 'data-theme' => 'light', + 'data-size' => 'normal', + 'data-tabindex' => '0', + ); + + echo ' $value ) { + printf( + ' %s="%s"', + esc_attr( $key ), + esc_attr( $value ) + ); + } + + echo '>'; } - /** + /** * Checks if the reCAPTCHA was validated. * * @since 1.0.0 - * @return true|WP_Error + * @return true|WP_Error */ protected function is_valid() { - if ( Hizzle_reCAPTCHA::$is_valid ) { - return true; - } - - if ( empty( $_POST['g-recaptcha-response'] ) ) { - return new WP_Error( 'token_not_found', __( "Please verify that you're not a robot.", 'hizzle-recaptcha' ) ); - } - - $result = wp_remote_post( - 'https://www.google.com/recaptcha/api/siteverify', - array( - 'body' => array( - 'secret' => hizzle_recaptcha_get_option( 'secret_key' ), - 'response' => wp_unslash( $_POST['g-recaptcha-response'] ), - ) - ) - ); - - // Site not reachable. - if ( is_wp_error( $result ) ) { - return true; - } - - $result = json_decode( wp_remote_retrieve_body( $result ), true ); - - if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'] ) && ! in_array( 'invalid-input-secret', $result['error-codes'] ) ) { - return new WP_Error( 'invalid_token', __( "Unable to verify that you're not a robot. Please try again.", 'hizzle-recaptcha' ) ); - } - - Hizzle_reCAPTCHA::$is_valid = true; - return true; + if ( Hizzle_reCAPTCHA::$is_valid ) { + return true; + } + + if ( empty( $_POST['g-recaptcha-response'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing + return new WP_Error( 'token_not_found', __( "Please verify that you're not a robot.", 'hizzle-recaptcha' ) ); + } + + $result = wp_remote_post( + 'https://www.google.com/recaptcha/api/siteverify', + array( + 'body' => array( + 'secret' => hizzle_recaptcha_get_option( 'secret_key' ), + 'response' => wp_unslash( $_POST['g-recaptcha-response'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing + ), + ) + ); + + // Site not reachable. + if ( is_wp_error( $result ) ) { + return true; + } + + $result = json_decode( wp_remote_retrieve_body( $result ), true ); + + if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { + return new WP_Error( 'invalid_token', __( "Unable to verify that you're not a robot. Please try again.", 'hizzle-recaptcha' ) ); + } + + Hizzle_reCAPTCHA::$is_valid = true; + return true; } - /** + /** * Verifies the token and adds a WP Error if its invalid. * * @since 1.0.0 * @param WP_Error $validation_error */ public function add_wp_error_if_invalid( $validation_error ) { - $error = $this->is_valid(); - - if ( is_wp_error( $error ) ) { - $validation_error->add( 'hizzle_recaptcha', esc_html( $error->get_error_message() ) ); - } - - return $validation_error; - } - - /** + $error = $this->is_valid(); + + if ( is_wp_error( $error ) ) { + $validation_error->add( 'hizzle_recaptcha', esc_html( $error->get_error_message() ) ); + } + + return $validation_error; + } + + /** * Verifies the token and returns a WP Error if its invalid. * * @since 1.0.0 * @param mixed $result - * @return WP_Error + * @return WP_Error */ public function return_wp_error_if_invalid( $result ) { - $error = $this->is_valid(); - - if ( is_wp_error( $error ) ) { - return $error; - } - - return $result; - } + $error = $this->is_valid(); + + if ( is_wp_error( $error ) ) { + return $error; + } + + return $result; + } } diff --git a/includes/integrations/cf7.php b/includes/integrations/cf7.php index be3077b..e4a8f55 100644 --- a/includes/integrations/cf7.php +++ b/includes/integrations/cf7.php @@ -64,11 +64,11 @@ public function append_html( $content = '' ) { */ public function verify_token( $result ) { - if ( empty( $_POST['_wpcf7'] ) ) { + if ( empty( $_POST['_wpcf7'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing return $result; } - $cf7_text = do_shortcode( '[contact-form-7 id="' . $_POST['_wpcf7'] . '"]' ); + $cf7_text = do_shortcode( '[contact-form-7 id="' . $_POST['_wpcf7'] . '"]' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( false === strpos( $cf7_text, 'hizzle-recaptcha' ) ) { return $result; diff --git a/includes/integrations/comment.php b/includes/integrations/comment.php index 31b187f..233044c 100644 --- a/includes/integrations/comment.php +++ b/includes/integrations/comment.php @@ -46,7 +46,7 @@ public function verify_token() { if ( is_wp_error( $error ) ) { wp_die( '

' . esc_html( $error->get_error_message() ) . '

', - __( 'Comment Submission Failure, Click the BACK button on your browser and try again.', 'hizzle-recaptcha' ), + esc_html__( 'Comment Submission Failure, Click the BACK button on your browser and try again.', 'hizzle-recaptcha' ), array( 'response' => 400, 'back_link' => true, diff --git a/includes/integrations/login.php b/includes/integrations/login.php index 64ad8c1..12c9853 100644 --- a/includes/integrations/login.php +++ b/includes/integrations/login.php @@ -34,7 +34,7 @@ public function __construct() { */ public function confirm_login( $user ) { - if ( is_wp_error( $user ) || defined( 'XMLRPC_REQUEST' ) || empty( $_POST['log'] ) || empty( $_POST['pwd'] ) ) { + if ( is_wp_error( $user ) || defined( 'XMLRPC_REQUEST' ) || empty( $_POST['log'] ) || empty( $_POST['pwd'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing return $user; } diff --git a/includes/settings.php b/includes/settings.php index 9fc7a30..7b96446 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -3,8 +3,10 @@ $title"; + printf( + '

%s

', + esc_html( get_admin_page_title() ) + ); // Fire a hook before printing the settings page. do_action( 'hizzle_recaptcha_settings_page_top' ); @@ -12,14 +14,14 @@ if ( false === $saved_settings ) { printf( '

%s

', - __( 'Could not save your settings. Please try again.', 'hizzle-recaptcha' ) + esc_html__( 'Could not save your settings. Please try again.', 'hizzle-recaptcha' ) ); } if ( true === $saved_settings ) { printf( '

%s

', - __( 'Your settings have been saved.', 'hizzle-recaptcha' ) + esc_html__( 'Your settings have been saved.', 'hizzle-recaptcha' ) ); } @@ -43,32 +45,32 @@ .notice:not(.hizzle-recaptcha-notice), div.error:not(.hizzle-recaptcha-notice), div.updated:not(.hizzle-recaptcha-notice) { - display: none!important; + display: none!important; }

- - + +

$args ) : ?>