skip to Main Content

I have a WordPress website for a client that uses a custom theme and a number of plugins in combination to create an events calendar where logged in users can purchase tickets for paid events and register for free RSVP-required events. To accomplish this, I am using the following six plugins in combination:

  • The Events Calendar
  • Events Calendar Pro
  • Event Tickets
  • Event Tickets Plus
  • WooCommerce
  • WooCommerce Stripe Gateway

The website was established in 2015. In the last 4 years, those plugins have seen extensive updates, and as a result, at a certain point the custom site I built around those plugins started experiencing deprecation issues, and attempts to upgrade caused performance failure. After consulting with support, it became necessary to pull a duplicate copy of the site onto a development server so that I could do the work to upgrade the install so all the latest versions of all of these plugins can be running and working properly.

Everything was going well with the upgrade work until I noticed that one of the plugins seems to be generating the following error in the console in Chrome:

POST https://pcapolar.codewordserver.com/wp-admin/admin-ajax.php 400 (Bad Request)
send @ jquery.js?ver=1.12.4-wp:4
ajax @ jquery.js?ver=1.12.4-wp:4
n.<computed> @ jquery.js?ver=1.12.4-wp:4
r.length.e.checkAvailability @ frontend-ticket-form.min.js?ver=4.11.1:1
r.length.e.init @ frontend-ticket-form.min.js?ver=4.11.1:1
(anonymous) @ frontend-ticket-form.min.js?ver=4.11.1:1
(anonymous) @ frontend-ticket-form.min.js?ver=4.11.1:1

Loading the same page in Edge generated the following console error:

HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax
(XHR)POST - https://pcapolar.codewordserver.com/wp-admin/admin-ajax.php

The error occurs only under very specific circumstances — when a single event page displays the frontend form for a paid ticket. The error doesn’t occur when the front end paid ticket form is not output, for example when there is a registered RSVP form with no payment component, when there is no ticket component to the event, or when a user who is not an active member views an affected page such that all information about details of the event and buying tickets is excluded from the output via theme template files. Despite the console error generated, it appears that ajax works fine and all of the functionality works exactly as expected. If you weren’t looking at the console, you’d never know there was a problem.

In order to rule out an issue with my custom theme or a conflict with another plugin, I activated the default Twenty Twenty theme and deactivated all other plugins except the 6 I listed that are required to use ticketed event process. The error remained present under these circumstances

After going back and forth with Modern Tribe (the plugin developers) support desk, they report the error cannot be replicated. So I tried myself to install a clean copy of WordPress with a new database, then install only those 6 plugins while running the default Twenty Twenty theme. I did this on the same server under the same cPanel account as the dev site with the error, just at different subdomains. On the clean install, the error was NOT present. But when I then pointed the clean WordPress install to a duplicate copy of the database I’m using for the dev site I’m working on, the error shows up again. From that, I can only conclude there is something going on in my database that is making this error happen, but Modern Tribe support are telling me that since the error can’t be reproduced by them, there isn’t anything they can do to help.

Starting over with a clean install for this site isn’t really an option, there is so much data collected over the last 4 years from ticket purchase and membership transactions that we really can’t lose. I need to find the faulty data and clean it, but I feel out of my depth here. Any help or suggestions on how to resolve this are welcome.


Edited to add:

I found this code in the javascript file references by the error message in the console. Am I looking in the right place?

/**
     * Check tickets availability.
     *
     * @since 4.9
     *
     * @return void
     */
    obj.checkAvailability = function() {
        // We're checking availability for all the tickets at once.
        var params = {
            action  : 'ticket_availability_check',
            tickets : obj.getTickets(),
        };

        $.post(
            TribeTicketOptions.ajaxurl,
            params,
            function( response ) {
                var success = response.success;

                // Bail if we don't get a successful response.
                if ( ! success ) {
                    return;
                }

                // Get the tickets response with availability.
                var tickets = response.data.tickets;

                // Make DOM updates.
                obj.updateAvailability( tickets );

            }
        );

        // Repeat every 60 (filterable via tribe_tickets_availability_check_interval ) seconds
        if ( 0 < TribeTicketOptions.availability_check_interval ) {
            setTimeout( obj.checkAvailability, TribeTicketOptions.availability_check_interval );
        }
    }

Edited to add:

Then I ran a string search for ticket_availability and found the following. It looks like it might be related, but I’m a bit over my head in interpreting. Am I on the right track yet?

public function ticket_availability( $tickets = array() ) {

        $response  = array( 'html' => '' );
        $tickets   = tribe_get_request_var( 'tickets', array() );

        // Bail if we receive no tickets
        if ( empty( $tickets ) ) {
            wp_send_json_error( $response );
        }

        /** @var Tribe__Tickets__Tickets_Handler $tickets_handler */
        $tickets_handler = tribe( 'tickets.handler' );

        /** @var Tribe__Tickets__Editor__Template $tickets_editor */
        $tickets_editor = tribe( 'tickets.editor.template' );

        // Parse the tickets and create the array for the response
        foreach ( $tickets as $ticket_id ) {
            $ticket = Tribe__Tickets__Tickets::load_ticket_object( $ticket_id );

            if (
                ! $ticket instanceof Tribe__Tickets__Ticket_Object
                || empty( $ticket->ID )
            ) {
                continue;
            }

            $available = $tickets_handler->get_ticket_max_purchase( $ticket->ID );

            $response['tickets'][ $ticket_id ]['available'] = $available;

            // If there are no more available we will send the template part HTML to update the DOM
            if ( 0 === $available ) {
                $response['tickets'][ $ticket_id ]['unavailable_html'] = $tickets_editor->template( 'blocks/tickets/quantity-unavailable', $ticket, false );
            }
        }

        wp_send_json_success( $response );
    }

The weird thing is that this function is filed to a folder called Blocks, which implied it works with Gutenberg, which I have disabled via the Classic Editor plugin.

4

Answers


  1. Chosen as BEST ANSWER

    The advice I received from the plugin developers after a great deal of back and forth was to add the following to my theme's functions.php file:

    add_filter( 'tribe_tickets_availability_check_interval', function( $interval) { return 0; } );

    This resolves the console issue, does not generate additional errors, and does not interfere with any expected functionality in all tests performed thus far.


  2. StackOverflow powers that be, forgive me but this was too much to fit in a comment.

    I apologize, but this is more of a debug process than a strict answer.

    The admin-ajax.php file only has 3 scenarios to return a 400 error.

    • If the user is logged in, and the ajax function hasn’t been added to the wp_ajax_{function_name} action. (line #164)
    • The user is NOT logged in, and the ajax function hasn’t been added to the wp_ajax_nopriv_{function_name} action. (line #179)
    • No action was sent in the request. (line #32)

    You’ll need to figure out which of these is causing your error. If you’re not sure how to do this, an easy way is to temporarily edit your admin-ajax.php file. Before you see this:

    // Require an action parameter
    if ( empty( $_REQUEST['action'] ) ) {
        wp_die( '0', 400 );
    }
    

    Add in the following (again, before the above lines)

    ob_start();
    print( '<pre>'. print_r($_REQUEST, true) .'</pre>' );
    wp_mail( '[email protected]', 'Debug Results', ob_get_clean() );
    

    This will email you (semi-nicely) formatted dump of the $_REQUEST. If there’s no action, you’ll know that for some reason the “front end form for a paid ticket” function isn’t being added, and Modern Tribe could probably help you out with that.

    If the action is set, you can add a similar line down below at line 164 or 179 and repeat the above, but with print( '<pre>'. print_r($action, true) .'</pre>' ); instead. If either of these get emailed to you when you submit the form, you’ll know which ajax hook isn’t being added, and again Modern Tribe could probably help you from there.

    Also note, that modifying core WP files is generally bad practice and you should revert these changes when you’re done debugging. (There’s ways to hook into file instead, but for ease/speed of diagnostics, go ahead and temporarily edit it, as these aren’t permanent changes, and it’s on a development site, so you shouldn’t have to worry)

    Beyond the above, you’ll probably need to hire a developer look at it, there’s not much more that someone on Stack Overflow can do without having direct access to your database and files.

    Login or Signup to reply.
  3. I am having the same problem and I think the problem is Tribe__Editor::should_load_blocks when the classic editor plugin is active.

    To bypass this error I add this code to my theme functions.php file

    add_action( 'xxx', tribe_callback( 'tickets.editor.blocks.tickets', 'register' ) );
    do_action( 'xxx' );
    
    

    I hope this works for you.

    Login or Signup to reply.
  4. Wanted to update everyone that with the release of Event Tickets 4.11.4 and Event Tickets Plus 4.11.3, this issue has been completely resolved on the plugin side. So apparently this was not just an issue with my site only. Thank you to everyone who contributed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search