Created
December 13, 2014 15:48
-
-
Save NateWr/7d4c44cd407a8c328120 to your computer and use it in GitHub Desktop.
Check if a reservations's email address includes the @ symbol before accepting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Simple Email Validation for Restaurant Reservations | |
* Plugin URI: http://themeofthecrop.com | |
* Description: Check if a reservations's email address includes the @ symbol before accepting. | |
* Version: 1.0 | |
* Author: Theme of the Crop | |
* Author URI: http://themeofthecrop.com | |
* License: GNU General Public License v2.0 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
* Requires at least: 4.0 | |
* Tested up to: 4.01 | |
* | |
* Text Domain: rtbdomain | |
* Domain Path: /languages/ | |
* | |
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU | |
* General Public License as published by the Free Software Foundation; either version 2 of the License, | |
* or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | |
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
* | |
* You should have received a copy of the GNU General Public License along with this program; if not, write | |
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) | |
exit; | |
/** | |
* Check if a reservations's email address includes the @ symbol | |
*/ | |
if ( !function_exists( 'rtbsev_validate_email' ) ) { | |
add_action( 'rtb_validate_booking_submission', 'rtbsev_validate_email' ); | |
function rtbsev_validate_email( $booking ) { | |
// Don't bother with this check if we already have errors attached | |
// to this field. | |
$email_errors = array_filter( $booking->validation_errors, 'rtbsev_error_is_email' ); | |
if ( count( $email_errors ) ) { | |
return; | |
} | |
// Set an error if no @ symbol is found | |
if ( !strpos( $booking->email, '@' ) ) { | |
$booking->validation_errors[] = array( | |
'field' => 'email', | |
'post_variable' => $booking->email, | |
'message' => __( 'Please enter a valid email address so we can confirm your booking.', 'restaurant-reservations' ), | |
); | |
} | |
} | |
} // endif | |
/** | |
* Check if this validation error is attached to the email field | |
*/ | |
if ( !function_exists( 'rtbsev_error_is_email' ) ) { | |
function rtbsev_error_is_email( $error ) { | |
return $error['field'] == 'email'; | |
} | |
} // endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment