Created
May 1, 2017 09:03
Allow the admin to set any party size when adding or editing bookings.
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: Allow Admin Override of Party Limits for Restaurant Reservations | |
* Plugin URI: http://themeofthecrop.com | |
* Description: Allow the admin to set any party size when adding or editing bookings. | |
* Version: 0.0.1 | |
* 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 | |
* | |
* 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 | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
add_filter( 'rtb_form_party_options', 'aaoplrtb_admin_party_size' ); | |
function aaoplrtb_admin_party_size( $options ) { | |
if ( !is_admin() ) { | |
return $options; | |
} | |
global $rtb_controller; | |
$party_size_min = (int) $rtb_controller->settings->get_setting( 'party-size-min' ); | |
$min = empty( $party_size_min ) ? 1 : $party_size_min; | |
$max = apply_filters( 'rtb_party_size_upper_limit', 100 ); | |
$options = array(); | |
for ( $i = $min; $i <= $max; $i++ ) { | |
$options[$i] = $i; | |
} | |
return $options; | |
} | |
add_action( 'rtb_validate_booking_submission', 'aaoplrtb_allow_any_party_size' ); | |
function aaoplrtb_allow_any_party_size( $booking ) { | |
if ( current_user_can( 'manage_bookings' ) ) { | |
foreach( $booking->validation_errors as $key => $error ) { | |
if ( $error['field'] == 'party' ) { | |
unset( $booking->validation_errors[ $key ] ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment