Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyskoczilova/9480fc93984f52c467aaeed78bf22679 to your computer and use it in GitHub Desktop.
Save vyskoczilova/9480fc93984f52c467aaeed78bf22679 to your computer and use it in GitHub Desktop.
Restaurant Reservations - add reCaptcha
<?php // don't copy this line
/**
* @snippet Add reCaptcha to Restaurant Reservations plugin
* @sourceCS https://kybernaut.cz/?p=2992
* @sourceEN https://kybernaut.cz/?p=2998
* @author Karolína Vyskočilová (https://kybernaut.cz)
* @testedwith WordPress 5.2
* @requires https://wordpress.org/plugins/invisible-recaptcha/
*/
// -------------------
// Check if both required plugins are activated.
if ( in_array('restaurant-reservations/restaurant-reservations.php', apply_filters('active_plugins', get_option('active_plugins'))) && in_array('invisible-recaptcha/invisible-recaptcha.php', apply_filters('active_plugins', get_option('active_plugins'))) ){
add_action( 'rtb_booking_form_after_fields', 'kbnt_google_invre_render_widget_action' );
add_action( 'rtb_validate_booking_submission', 'kbnt_rtb_validate_booking_submission' );
}
// Include reCaptcha field.
function kbnt_google_invre_render_widget_action() {
do_action('google_invre_render_widget_action');
}
// Valide reCaptcha field.
function kbnt_rtb_validate_booking_submission( $booking ) {
$is_valid = apply_filters('google_invre_is_valid_request_filter', true);
if ( ! $is_valid ) {
$booking->validation_errors[] = array(
'field' => 'name',
'error_msg' => 'Robot Allert',
'message' => __( 'You shall not pass, robot.' ),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment