Last active
August 6, 2019 08:04
-
-
Save NateWr/6b5464a58b67ae680e0e8044b486668b to your computer and use it in GitHub Desktop.
Check new bookings for blacklisted words in comments for Restaurant Reservations
This file contains hidden or 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: Comment Blacklist for Restaurant Reservations | |
* Plugin URI: http://themeofthecrop.com | |
* Description: Check if a booking includes blacklisted words from Settings > Discussion > Comment Blacklist before accepting it. | |
* 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.1 | |
* | |
* | |
* 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; | |
add_action( 'rtb_validate_booking_submission', function( $booking ) { | |
$blacklist = get_option('blacklist_keys', ''); | |
$words = explode("\n", trim($blacklist)); | |
foreach ($words as $word) { | |
if (strpos($booking->name, $word) !== false) { | |
$booking->validation_errors[] = array( | |
'field' => 'name', | |
'post_variable' => $_POST['rtb-name'], | |
'message' => __( 'The name you entered can not be accepted.', 'restaurant-reservations' ), | |
); | |
} | |
if (strpos($booking->phone, $word) !== false) { | |
$booking->validation_errors[] = array( | |
'field' => 'phone', | |
'post_variable' => $_POST['rtb-phone'], | |
'message' => __( 'The phone number you entered can not be accepted.', 'restaurant-reservations' ), | |
); | |
} | |
if (strpos($booking->message, $word) !== false) { | |
$booking->validation_errors[] = array( | |
'field' => 'message', | |
'post_variable' => $_POST['rtb-message'], | |
'message' => __( 'The message you entered can not be accepted.', 'restaurant-reservations' ), | |
); | |
} | |
} | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment