X_get_view() not working on admin-ajax request

Hello!

I have an admin-ajax request that uses x_get_view() function to render content and send it back. But after I updated PRO theme to the latest version, it stopped working.
After some research I found that x_get_view() function that is needed is placed in /pro/framework/functions/frontend/view_routing.php but now, after update, all “frontend” files don’t loading on admin-ajax requests because there is this condition:
if ( ! is_admin() ) { $this->boot_context('front_end'); }
and all admin-ajax requests don’t pass this condition. Usually there is another condition for such cases: wp_doing_ajax()
So when I added this to the code:
if ( ! is_admin() || wp_doing_ajax() ) { $this->boot_context('front_end'); }
everything worked as expected and now x_get_view() is working in admin-ajax requests again. But since I don’t want to edit parent theme, would you please update pro/functions.php file with wp_doing_ajax() condition in patch? Or is there another way?

Hey @mercurycreative,

Thank you for explaining the situation. I will forward this to our development team and if your proposed code will not have conflicts with any feature in our themes and builders, they’ll most probably implement that.

Please stay tuned.

Thanks.

Hello! Just checking in on this ticket. Are there any updates? Thanks!

Hi @mercurycreative,

I checked the issue tracker and the code is still being reviewed, our development team has some reservation adding the condition. One of our development team members might be in contact with you if needed.

Thank you.

Hi @mercurycreative,

A few cycles ago we refactored how the theme files boot to make sure code wasn’t being included on paths where it wasn’t needed. I understand your request, but this isn’t something we want to make part of the theme considering it will effect the performance of all AJAX calls, and we never use the front end functions in ajax handlers.

There is however a way you can make this work without modifying Pro directly. This code will instruct the theme to boot the front end similar to what you are doing:

add_action('after_setup_theme', function() {
  if ( wp_doing_ajax() && function_exists('x_bootstrap') ) {
    x_bootstrap()->boot_context('front_end');
  }
});

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.