reCaptcha by BestWebSoft Shortcode

Below, you’ll find a detailed guide on how to add the reCaptcha by BestWebSoft Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the reCaptcha by BestWebSoft Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the reCaptcha by BestWebSoft Plugin and the shortcodes it provides:

Plugin Icon
reCaptcha by BestWebSoft

"reCaptcha by BestWebSoft is a robust WordPress plugin. The plugin, also known as google-captcha, provides an added layer of security for your website by preventing spam and abuse from bots."

★★★★✩ (379) Active Installs: 200000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [bws_google_captcha]

reCaptcha by BestWebSoft [bws_google_captcha] Shortcode

The BWS Google Captcha shortcode is a security feature that adds Google’s reCAPTCHA to your website. It verifies if interactions are human-operated, protecting against spam and bots.

Shortcode: [bws_google_captcha]

Examples and Usage

Basic example – A simple usage of the shortcode to display Google Captcha on your WordPress site.

[bws_google_captcha]

PHP Function Code

In case you have difficulties debugging what causing issues with [bws_google_captcha] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'bws_google_captcha', 'gglcptch_display' );

Shortcode PHP function:

function gglcptch_display( $content = false ) {
		global $gglcptch_options, $gglcptch_count, $gglcptch_plugin_info;

		if ( empty( $gglcptch_options ) ) {
			register_gglcptch_settings();
		}

		if ( ! gglcptch_allowlisted_ip() || ( isset( $_GET['action'] ) && 'gglcptch-test-keys' == $_GET['action'] ) ) {

			if ( ! $gglcptch_count ) {
				$gglcptch_count = 1;
			}

			$content .= '<div class="gglcptch gglcptch_' . $gglcptch_options['recaptcha_version'] . '">';

			if ( $gglcptch_options['hide_badge'] && 'v2' != $gglcptch_options['recaptcha_version'] ) {
				$content .= sprintf(
					'<div class="google-captcha-notice">%s<a href="https://policies.google.com/privacy" target="_blank">%s</a>%s<a href="https://policies.google.com/terms" target="_blank">%s</a>%s</div>',
					__( 'This site is protected by reCAPTCHA and the Google ', 'google-captcha' ),
					__( 'Privacy Policy', 'google-captcha' ),
					__( ' and ', 'google-captcha' ),
					__( 'Terms of Service', 'google-captcha' ),
					__( ' apply.', 'google-captcha' )
				);
			}
			if ( ! $gglcptch_options['private_key'] || ! $gglcptch_options['public_key'] ) {
				if ( current_user_can( 'manage_options' ) ) {
					$content .= sprintf(
						'<strong>%s <a target="_blank" href="https://www.google.com/recaptcha/admin#list">%s</a> %s <a target="_blank" href="%s">%s</a>.</strong>',
						__( 'To use reCaptcha you must get the keys from', 'google-captcha' ),
						__( 'here', 'google-captcha' ),
						__( 'and enter them on the', 'google-captcha' ),
						admin_url( '/admin.php?page=google-captcha.php' ),
						__( 'plugin setting page', 'google-captcha' )
					);
				}
				$content .= '</div>';
				$gglcptch_count++;
				return $content;
			}

			$api_url = gglcptch_get_api_url();

			/* generating random id value in case of getting content with pagination plugin for not getting duplicate id values */
			$id = mt_rand();
			if ( isset( $gglcptch_options['recaptcha_version'] ) && in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) ) {
				$content .= '<div id="gglcptch_recaptcha_' . $id . '" class="gglcptch_recaptcha"></div>
				<noscript>
					<div style="width: 302px;">
						<div style="width: 302px; height: 422px; position: relative;">
							<div style="width: 302px; height: 422px; position: absolute;">
								<iframe src="https://www.google.com/recaptcha/api/fallback?k=' . $gglcptch_options['public_key'] . '" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
							</div>
						</div>
						<div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;">
							<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea>
						</div>
					</div>
				</noscript>';
				$deps = ( ! empty( $gglcptch_options['disable_submit'] ) ) ? array( 'gglcptch_pre_api' ) : array( 'jquery' );
			} elseif ( isset( $gglcptch_options['recaptcha_version'] ) &&  'v3' == $gglcptch_options['recaptcha_version'] ) {
			    $content .= '<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" /><br /><div class="gglcptch_error_text">' . __( 'The reCAPTCHA verification period has expired. Please reload the page.', 'google-captcha' ) . '</div>';
            }
			$content .= '</div>';
			$gglcptch_count++;

			/* register reCAPTCHA script */
			if ( ! wp_script_is( 'gglcptch_api', 'registered' ) ) {

                if ( isset( $gglcptch_options['recaptcha_version'] ) && 'v3' == $gglcptch_options['recaptcha_version'] ) {
                    wp_register_script( 'gglcptch_api', $api_url, false, null, false );
                } else {
                    wp_register_script( 'gglcptch_api', $api_url, $deps, $gglcptch_plugin_info['Version'], true );
                }
				add_action( 'wp_footer', 'gglcptch_add_scripts' );
				if (
					$gglcptch_options['login_form'] ||
					$gglcptch_options['reset_pwd_form'] ||
					$gglcptch_options['registration_form']
				) {
					add_action( 'login_footer', 'gglcptch_add_scripts' );
				}
			}
			if (
                ( ! isset( $_SERVER['REQUEST_URI'] ) ) ||
                ( ! strstr( $_SERVER['REQUEST_URI'], '/wp-login.php' ) ) ||
				( '/wp-login.php?action=register' == $_SERVER['REQUEST_URI'] && $gglcptch_options['registration_form'] ) ||
				( '/wp-login.php?action=lostpassword' == $_SERVER['REQUEST_URI'] && $gglcptch_options['reset_pwd_form'] ) ||
				( '/wp-login.php' == $_SERVER['REQUEST_URI'] && $gglcptch_options['login_form'] ) ||
                ( strstr( $_SERVER['REQUEST_URI'], '/wp-login.php' ) && strstr( $_SERVER['REQUEST_URI'], 'loggedout' ) && $gglcptch_options['login_form'] )
			) {
				gglcptch_add_styles();
			}
		} elseif ( ! empty( $gglcptch_options['allowlist_message'] ) ) {
			$content .= '<label class="gglcptch_allowlist_message" style="display: block;">' . $gglcptch_options['allowlist_message'] . '</label>';
		}

		return $content;
	}

Code file location:

google-captcha/google-captcha/google-captcha.php

Conclusion

Now that you’ve learned how to embed the reCaptcha by BestWebSoft Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *