HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/themes/splash-child/functions.php
<?php

add_action( 'wp_enqueue_scripts', 'stm_enqueue_parent_styles' );

function stm_enqueue_parent_styles() {

    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('stm-theme-style') );

}
function my_footer_shh() {
    remove_filter( 'update_footer', 'core_update_footer' ); 
}

add_action( 'admin_menu', 'my_footer_shh' );

// Admin footer modification
  
function remove_footer_admin () 
{
    echo '';
}
 
add_filter('admin_footer_text', 'remove_footer_admin');



add_action( 'woocommerce_after_single_product_summary', 'bbloomer_custom_action', 5 );
 
function bbloomer_custom_action() {
 global $post;
 $shootin_banner = get_post_meta( $post->ID, 'banner img', true ); 
 $shootin_banner_link = get_post_meta( $post->ID, 'banner link', true ); 
 
  if  (!empty( $shootin_banner )) { ?>
     <p class="center"><a href="<?php echo $shootin_banner_link; ?>"><img src="<?php echo $shootin_banner; ?>" /></a></p>
  <?php
  } else
  {
      
  }
    
}

// display an 'Out of Stock' label on archive pages
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_stock', 10 );
function woocommerce_template_loop_stock() {
    global $product;
    if ( ! $product->managing_stock() && ! $product->is_in_stock() )
        echo 'hello';
}


// Add a second password field to the checkout page in WC 3.x.
add_filter( 'woocommerce_checkout_fields', 'wc_add_confirm_password_checkout', 10, 1 );
function wc_add_confirm_password_checkout( $checkout_fields ) {
    if ( get_option( 'woocommerce_registration_generate_password' ) == 'no' ) {
        $checkout_fields['account']['account_password2'] = array(
                'type'              => 'password',
                'label'             => __( 'Confirm password', 'woocommerce' ),
                'required'          => true,
                'placeholder'       => _x( 'Confirm Password', 'placeholder', 'woocommerce' )
        );
    }

    return $checkout_fields;
}

// Check the password and confirm password fields match before allow checkout to proceed.
add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_password_matches_checkout', 10, 2 );
function wc_check_confirm_password_matches_checkout( $posted ) {
    $checkout = WC()->checkout;
    if ( ! is_user_logged_in() && ( $checkout->must_create_account || ! empty( $posted['createaccount'] ) ) ) {
        if ( strcmp( $posted['account_password'], $posted['account_password2'] ) !== 0 ) {
            wc_add_notice( __( 'Passwords do not match.', 'woocommerce' ), 'error' );
        }
    }
}

/*add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
 
function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_phone']);
    return $fields;
}*/



add_filter( 'woocommerce_default_address_fields' , 'override_default_address_fields' );
function override_default_address_fields( $address_fields ) {

    // @ for postcode
    $address_fields['billing_phone']['label'] = __('Cell Number', 'woocommerce');

    return $address_fields;
}




// function so_27023433_disable_checkout_script(){
//     wp_dequeue_script( 'wc-checkout' );
// }
// add_action( 'wp_enqueue_scripts', 'so_27023433_disable_checkout_script' );
$preview = get_stylesheet_directory() . '/woocommerce/emails/woo-preview-emails.php';

if(file_exists($preview)) {
    require $preview;
}
// add_action('wp_logout','unlog');

add_action('admin_enqueue_scripts', 'myPlugin_jcf_admin_fix');
function myPlugin_jcf_admin_fix(){
  $screen = get_current_screen();
  if ( in_array($screen->id, array('settings_page_jcf_admin', 'settings_page_jcf_fieldset_index')) ) {
    wp_enqueue_script('jquery-migrate');
  }
}

// add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
// function logout_without_confirm($action, $result)
// {
//     /**
//      * Allow logout without confirmation
//      */
//     if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
//         $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://shootin.namanmodi.me/';
//         $location = str_replace('&amp;', '&', wp_logout_url($redirect_to));
//         header("Location: $location");
//         die;
//     }
// }
add_action('woocommerce_order_status_changed', 'backorder_status_custom_notification', 10, 4);
function backorder_status_custom_notification( $order_id, $from_status, $to_status, $order ) {

   if( $order->has_status( 'backorder' )) {

        // Getting all WC_emails objects
        $email_notifications = WC()->mailer()->get_emails();

        // Customizing Heading and subject In the WC_email processing Order object
        $email_notifications['WC_Email_Customer_Processing_Order']->heading = __('Your processing Back order','woocommerce');
        $email_notifications['WC_Email_Customer_Processing_Order']->subject = 'Your {site_title} processing Back order receipt from {order_date}';

        // Sending the customized email
        $email_notifications['WC_Email_Customer_Processing_Order']->trigger( $order_id );
    }

}

function Upcoming_Event(){
    $args = array( 'post_type' => 'product', 'posts_per_page' => 3,'product_cat' => 'events', 'orderby'     =>  'date', 'order'=>'ASC');
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product;
    $thumbnail = get_the_post_thumbnail_url();
    ?>
    
    <div class="center-on-mobile wpb_column vc_column_container vc_col-sm-4"><div class="vc_column-inner "><div class="wpb_wrapper">
    <div class="wpb_single_image wpb_content_element vc_align_left  vc_custom_1527578519466  center-on-mobile">
        
        <figure class="wpb_wrapper vc_figure">
            <div class="vc_single_image-wrapper   vc_box_border_grey"><a href="<?php echo the_permalink(); ?>"><img width="374" height="258" src="<?php echo $thumbnail; ?>" class="vc_single_image-img attachment-full" alt="" sizes="(max-width: 374px) 100vw, 374px"></a></div>
        </figure>
    </div>
<h4 style="text-transform: uppercase;color: #2d2c2c;text-align: left;font-family:Roboto Condensed;font-weight:700;font-style:normal;text-align:center" class="vc_custom_heading center-on-mobile vc_custom_1527578546208"><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a><br>
</h4>

    <div class="wpb_text_column wpb_content_element  vc_custom_1525685151981">
        <div class="wpb_wrapper">
            <p class="fooevents-shortcode-date1" style="text-align:center;"><b>START DATE : </b><?php echo get_post_meta(get_the_ID(), 'WooCommerceEventsDate', true); ?></p>
            <?php //the_excerpt(); ?>

        </div>
    </div>
</div></div></div>

    <?php
    endwhile;
          
    wp_reset_query();
}



add_shortcode( 'Upcoming', 'Upcoming_Event' );


// Add the code below to your theme's functions.php file to add a confirm password field on the register form under My Accounts.
add_filter('woocommerce_registration_errors', 'registration_errors_validation', 10,3);
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
    global $woocommerce;
    extract( $_POST );
    if ( strcmp( $password, $password2 ) !== 0 ) {
        return new WP_Error( 'registration-error', __( 'Passwords do not match.', 'woocommerce' ) );
    }
    return $reg_errors;
}
add_action( 'woocommerce_register_form', 'wc_register_form_password_repeat' );
function wc_register_form_password_repeat() {
    ?>
    <p class="form-row form-row-wide">
        <label for="reg_password2"><?php _e( 'Confirm password', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="password" class="input-text" name="password2" id="reg_password2" value="<?php if ( ! empty( $_POST['password2'] ) ) echo esc_attr( $_POST['password2'] ); ?>" />
    </p>
    <?php
}

add_action( 'wp_logout', 'auto_redirect_external_after_logout');
function auto_redirect_external_after_logout(){
  wp_redirect( 'https://shootinschool.com/' );
  exit();
}

/*add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );

function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields['meta_key'] = array(
        'label' => __( 'Call Number' ),
        'value' => get_post_meta( $order->id, 'billing_billing_phone', true ),
    );
    return $fields;
}*/

class GFLimitCheckboxes {

    private $form_id;
    private $field_limits;
    private $output_script;

    function __construct($form_id, $field_limits) {

        $this->form_id = $form_id;
        $this->field_limits = $this->set_field_limits($field_limits);

        add_filter("gform_pre_render_$form_id", array(&$this, 'pre_render'));
        add_filter("gform_validation_$form_id", array(&$this, 'validate'));

    }

    function pre_render($form) {

        $script = '';
        $output_script = false;

        foreach($form['fields'] as $field) {

            $field_id = $field['id'];
            $field_limits = $this->get_field_limits($field['id']);

            if( !$field_limits                                          // if field limits not provided for this field
                || RGFormsModel::get_input_type($field) != 'checkbox'   // or if this field is not a checkbox
                || !isset($field_limits['max'])        // or if 'max' is not set for this field
                )
                continue;

            $output_script = true;
            $max = $field_limits['max'];
            $selectors = array();

            foreach($field_limits['field'] as $checkbox_field) {
                $selectors[] = "#field_{$form['id']}_{$checkbox_field} .gfield_checkbox input:checkbox";
            }

            $script .= "jQuery(\"" . implode(', ', $selectors) . "\").checkboxLimit({$max});";

        }

        GFFormDisplay::add_init_script($form['id'], 'limit_checkboxes', GFFormDisplay::ON_PAGE_RENDER, $script);

        if($output_script):
            ?>

            <script type="text/javascript">
            jQuery(document).ready(function($) {
                $.fn.checkboxLimit = function(n) {

                    var checkboxes = this;

                    this.toggleDisable = function() {

                        // if we have reached or exceeded the limit, disable all other checkboxes
                        if(this.filter(':checked').length >= n) {
                            var unchecked = this.not(':checked');
                            unchecked.prop('disabled', true);
                        }
                        // if we are below the limit, make sure all checkboxes are available
                        else {
                            this.prop('disabled', false);
                        }

                    }

                    // when form is rendered, toggle disable
                    checkboxes.bind('gform_post_render', checkboxes.toggleDisable());

                    // when checkbox is clicked, toggle disable
                    checkboxes.click(function(event) {

                        checkboxes.toggleDisable();

                        // if we are equal to or below the limit, the field should be checked
                        return checkboxes.filter(':checked').length <= n;
                    });

                }
            });
            </script>

            <?php
        endif;

        return $form;
    }

    function validate($validation_result) {

        $form = $validation_result['form'];
        $checkbox_counts = array();

        // loop through and get counts on all checkbox fields (just to keep things simple)
        foreach($form['fields'] as $field) {

            if( RGFormsModel::get_input_type($field) != 'checkbox' )
                continue;

            $field_id = $field['id'];
            $count = 0;

            foreach($_POST as $key => $value) {
                if(strpos($key, "input_{$field['id']}_") !== false)
                    $count++;
            }

            $checkbox_counts[$field_id] = $count;

        }

        // loop through again and actually validate
        foreach($form['fields'] as &$field) {

            if(!$this->should_field_be_validated($form, $field))
                continue;

            $field_id = $field['id'];
            $field_limits = $this->get_field_limits($field_id);

            $min = isset($field_limits['min']) ? $field_limits['min'] : false;
            $max = isset($field_limits['max']) ? $field_limits['max'] : false;

            $count = 0;
            foreach($field_limits['field'] as $checkbox_field) {
                $count += rgar($checkbox_counts, $checkbox_field);
            }

            if($count < $min) {
                $field['failed_validation'] = true;
                $field['validation_message'] = sprintf( _n('You must select at least %s item.', 'You must select at least %s items.', $min), $min );
                $validation_result['is_valid'] = false;
            }
            else if($count > $max) {
                $field['failed_validation'] = true;
                $field['validation_message'] = sprintf( _n('You may only select %s item.', 'You may only select %s items.', $max), $max );
                $validation_result['is_valid'] = false;
            }

        }

        $validation_result['form'] = $form;

        return $validation_result;
    }

    function should_field_be_validated($form, $field) {

        if( $field['pageNumber'] != GFFormDisplay::get_source_page( $form['id'] ) )
            return false;

        // if no limits provided for this field
        if( !$this->get_field_limits($field['id']) )
            return false;

        // or if this field is not a checkbox
        if( RGFormsModel::get_input_type($field) != 'checkbox' )
            return false;

        // or if this field is hidden
        if( RGFormsModel::is_field_hidden($form, $field, array()) )
            return false;

        return true;
    }

    function get_field_limits($field_id) {

        foreach($this->field_limits as $key => $options) {
            if(in_array($field_id, $options['field']))
                return $options;
        }

        return false;
    }

    function set_field_limits($field_limits) {

        foreach($field_limits as $key => &$options) {

            if(isset($options['field'])) {
                $ids = is_array($options['field']) ? $options['field'] : array($options['field']);
            } else {
                $ids = array($key);
            }

            $options['field'] = $ids;

        }

        return $field_limits;
    }

}

new GFLimitCheckboxes(6, array(
    3 => array(
       'min' => 2,
        'max' => 2
        ),
    15 => array(
        'min' => 2,
        'max' => 2
        ),
    20 => array(
        'min' => 2,
        'max' => 2
        ),
    21 => array(
        'min' => 2,
        'max' => 2
        ),
     17 => array(
        'min' => 2,
        'max' => 2
        ),
    4 => array(
        'min' => 3,
        'max' => 3
        ),
    18 => array(
        'min' => 3,
        'max' => 3
        ),
    19 => array(
        'min' => 3,
        'max' => 3
        ),
    23 => array(
        'min' => 3,
        'max' => 3
        ),
     24 => array(
        'min' => 3,
        'max' => 3
        ),
     25 => array(
        'min' => 3,
        'max' => 3
        ),

    106 => array(
        'min' => 4,
        'max' => 4
        ),
     103 => array(
        'min' => 4,
        'max' => 4
        ),

    111 => array(
        'min' => 4,
        'max' => 4
        ),
    107 => array(
        'min' => 4,
        'max' => 4
        ),
    108 => array(
        'min' => 4,
        'max' => 4
        ),
    112 => array(
        'min' => 4,
        'max' => 4
        )
    ));
    function remove_image_zoom_support() {
    remove_theme_support( 'wc-product-gallery-zoom' );
}
add_action( 'wp', 'remove_image_zoom_support', 100 );
add_action( 'after_setup_theme', 'tu_disable_wc_lightbox', 20 );
function tu_disable_wc_lightbox() {
    remove_theme_support( 'wc-product-gallery-lightbox' );
}

add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
    if ( 'name' === $field->type && $field->isRequired ) {
        GFCommon::log_debug( __METHOD__ . '(): Running.' );
        // Input values.
        $prefix = rgar( $value, $field->id . '.2' );
        $first  = rgar( $value, $field->id . '.3' );
        $middle = rgar( $value, $field->id . '.4' );
        $last   = rgar( $value, $field->id . '.6' );
        $suffix = rgar( $value, $field->id . '.8' );
 
        $name_field = array( '2' => $prefix, '3' => $first, '4' => $middle, '6' => $last, '8' => $suffix );
 
        foreach ( $name_field as $input_number => $input_value ) {
            if ( empty( $input_value ) && ! $field->get_input_property( $input_number, 'isHidden' ) ) {
                $field->set_input_validation_state( $input_number, false ); // Only for Gravity Forms 2.5.10 or higher.
                $result['is_valid'] = false;
                $result['message']  = empty( $field->errorMessage ) ? __( 'This field is required. Please enter a complete name.', 'gravityforms' ) : $field->errorMessage;
                GFCommon::log_debug( __METHOD__ . "(): Empty input: {$field->id}.{$input_number}" );
            }
        }
    }
    GFCommon::log_debug( __METHOD__ . '(): Returning validation result.' );
    return $result;
}, 10, 4 );

function enqueue_custom_scripts() {
    wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');