Events Calendar Pro fatal error Call to undefined function get_current_screen()

Home Forums Calendar Products Events Calendar PRO Events Calendar Pro fatal error Call to undefined function get_current_screen()

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #625407
    tuberb
    Participant

    I am just getting started with Events Calendar Pro for a new site. At the moment I am building an import-export script to load event data from the client’s old system into tribe_events post types along with some other non-tribe fields associated with the events (SEO meta-data, Advanced Custom Fields fields, etc.)

    I was trying to run my script to dump out events created within the plugin so that I can see how tribe structures the fields, and I would then be able to load them in appropriately. My script is calling tribe_get_events to retrieve the events, and then dumps all the data out to a csv file (the same script works fine with other post types, for which I do a regular get_posts call).

    When I switched the get_posts call to a tribe_get_events call, I get the following (when Debug is turned on; without Debug on I got a blank screen):

    Fatal error: Call to undefined function get_current_screen() in /../public_html/wp-content/plugins/the-events-calendar/lib/tribe-event-query.class.php on line 285

    I googled around a bit, and after a bit of trial and error, I added the line:

    require_once(ABSPATH . ‘wp-admin/includes/screen.php’);

    at line 24 in the tribe-event-query.class.php script (I am running the current version of the plugin, 3.7).

    That fixed the problem for me, and it might be nice if you added the same code in your next release, so that I do not have to patch things myself.

    Thanks,

    Barry

    #639626
    Barry
    Member

    Hi Barry,

    Could you share your custom code/give me an idea of when it runs (is it within the admin environment, which action is triggering the main body of code you’ve written, etc)?

    tribe_get_events() is in widespread use in the community and fatal errors relating to the get_current_screen() function generally do not occur, so I’m wondering if perhaps the context in which you are using tribe_get_events() is in some way atypical. It may not be of course, but it would be ideal if you could give me enough to replicate this in the first instance.

    Thanks!

     

    #642556
    tuberb
    Participant

    The code is written like a standalone plugin, runs in the Admin environment, and is attached to a menu option under tools.

    I ended up moving the require_once statement inside my script right before the call to tribe_get_events(), and that seems to have fixed the problem for me, so I no longer have a modified version of the plugin script.

    So I guess I’m all set.

    Barry

    #650587
    Barry
    Member

    Hi Barry,

    OK, great you’ve got a working solution 🙂

    Since this doesn’t crop up under ordinary conditions, as it were, we’re not going to be in a position to make any changes to our plugin code to work around this – at least not without some further information.

    If you do want us to consider making such a change though definitely do share your code as we’d need to consider if the problem is a failing in our code or simply an order-of-operations issue (some core WordPress functions cannot normally be called until a certain point in the lifetime of the request, for instance).

    So, I’ll leave this open in case you want to explore that and share your code – but if I don’t hear back from you in a few weeks I’ll assume you’re all set and close the thread.

    Thanks again 🙂

    #723474
    Barry
    Member

    Hi! It’s been a while so I’m going to go ahead and close this thread. If we can help with anything else, though, please don’t hesitate to create new threads as needed. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Events Calendar Pro fatal error Call to undefined function get_current_screen()’ is closed to new replies.