Skip to content

Instantly share code, notes, and snippets.

@giucu91
Last active March 27, 2019 10:59
Show Gist options
  • Save giucu91/9eafcfc78739fc5f5114e306be4dad35 to your computer and use it in GitHub Desktop.
Save giucu91/9eafcfc78739fc5f5114e306be4dad35 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Really Simple Captcha for Strong Testimonials
* Plugin URI: https://strongtestimonials.com
* Description: Add Really Simple Captcha to Strong Testimonials.
* Author: MachoThemes
* Author URI: https://www.machothemes.com/
* Version: 1.0.0
* Requires: 4.6 or higher
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Requires PHP: 5.6
*/
/**
* Print form catpcha.
*/
function strsc_wpmtst_form_captcha() {
$form_options = get_option( 'wpmtst_form_options' );
if ( ! isset( $form_options['captcha'] ) || ! $form_options['captcha'] ) {
return;
}
if ( 'really-simple-captcha' !== $form_options['captcha'] ) {
return;
}
/**
* Only display Captcha label if properly configured.
*/
$captcha_html = apply_filters( 'wpmtst_add_captcha', $form_options['captcha'] );
if ( ! $captcha_html ) {
return;
}
$invisible = wpmtst_form_captcha_invisible();
$errors = WPMST()->form->get_form_errors();
/**
* To display or not to display.
*/
if ( $invisible && 'captcha-pro' == $form_options['captcha'] ) {
echo '<div class="form-field wpmtst-captcha">';
echo $captcha_html;
echo '</div>';
} elseif ( $invisible ) {
echo $captcha_html;
} else {
?>
<div class="form-field wpmtst-captcha">
<?php if ( wpmtst_get_form_message( 'captcha' ) ) : ?>
<label for="wpmtst_captcha"><?php wpmtst_form_message( 'captcha' ); ?></label><span class="required symbol"></span>
<?php endif; ?>
<div>
<?php echo $captcha_html; ?>
<?php if ( isset( $errors['captcha'] ) ) : ?>
<p><label class="error"><?php echo esc_html( $errors['captcha'] ); ?></label></p>
<?php endif; ?>
</div>
</div>
<?php
}
}
add_action( 'wpmtst_form_after_fields', 'strsc_wpmtst_form_captcha', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment