| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | * @param string $recaptcha_response The reCAPTCHA response. |
| 72 | 72 | * @param string $plugin_action The action to verify the reCAPTCHA response for. |
| 73 | 73 | * @return bool|WP_Error |
| 74 | 74 | */ |
| 75 | - public function verify_recaptcha( $recaptcha_response, $plugin_action ) { | |
| 75 | + public function verify( $recaptcha_response, $plugin_action ) { | |
| 76 | 76 | |
| 77 | 77 | // Don't run if the reCAPTCHA or scripts are disabled. |
| 78 | 78 | if ( ! $this->settings->has_recaptcha_site_and_secret_keys() || $this->settings->scripts_disabled() ) { |
| 79 | 79 | return true; |
| @@ -126,8 +126,57 @@ | ||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // If here, the submission looks genuine. Continue the request. |
| 129 | 129 | return true; |
| 130 | + | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Attaches the reCAPTCHA v3 invisible-badge attributes to the given submit | |
| 135 | + * button element within an existing DOM tree, so that the challenge is | |
| 136 | + * executed when the button is clicked and the form is submitted via the | |
| 137 | + * `convertKitRecaptchaFormSubmit` callback. | |
| 138 | + * | |
| 139 | + * @since 3.3.7 | |
| 140 | + * | |
| 141 | + * @param ConvertKit_HTML_Parser $parser Parser wrapping the DOM (unused). | |
| 142 | + * @param DOMElement $button <button> element to attach attributes to. | |
| 143 | + * @param string $plugin_action Plugin action string. | |
| 144 | + */ | |
| 145 | + public function attach_to_form_button_dom( $parser, $button, $plugin_action ) { | |
| 146 | + | |
| 147 | + unset( $parser ); | |
| 148 | + | |
| 149 | + $button->setAttribute( 'data-sitekey', esc_attr( $this->settings->recaptcha_site_key() ) ); | |
| 150 | + $button->setAttribute( 'data-callback', 'convertKitRecaptchaFormSubmit' ); | |
| 151 | + $button->setAttribute( 'data-action', $plugin_action ); | |
| 152 | + $button->setAttribute( 'class', trim( $button->getAttribute( 'class' ) . ' g-recaptcha' ) ); | |
| 153 | + | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * Returns the HTML for a submit button with reCAPTCHA v3 invisible-badge | |
| 158 | + * attributes attached, used by templates that don't have a DOM parser | |
| 159 | + * available (e.g. the Restrict Content tag view). | |
| 160 | + * | |
| 161 | + * @since 3.3.7 | |
| 162 | + * | |
| 163 | + * @param string $label Button's visible label. | |
| 164 | + * @param string $plugin_action Plugin action string. | |
| 165 | + * @param string[] $css_classes CSS classes for the button. | |
| 166 | + * @return string | |
| 167 | + */ | |
| 168 | + public function get_submit_button_html( $label, $plugin_action, $css_classes = array() ) { | |
| 169 | + | |
| 170 | + $css_classes[] = 'g-recaptcha'; | |
| 171 | + | |
| 172 | + return sprintf( | |
| 173 | + '<input type="submit" class="%1$s" value="%2$s" data-sitekey="%3$s" data-callback="convertKitRecaptchaFormSubmit" data-action="%4$s" />', | |
| 174 | + esc_attr( implode( ' ', $css_classes ) ), | |
| 175 | + esc_attr( $label ), | |
| 176 | + esc_attr( $this->settings->recaptcha_site_key() ), | |
| 177 | + esc_attr( $plugin_action ) | |
| 178 | + ); | |
| 130 | 179 | |
| 131 | 180 | } |
| 132 | 181 | |
| 133 | 182 | } |