I’m creating an in-house plugin that can supply a filtering mechanism utilizing AJAX for any submit sort relying on the configuration, which I’ve saved in a JSON.
When the plugin is loaded, I have to set the callback for the AJAX name, and I set that immediately (I am sticking to OOP):
$gfb = FilterBuilder::get_instance(); $action_filter_reg_instance = new ActionFilterRegistration(); $action_filter_reg_instance->add_action( 'wp_ajax_process_filters', $gfb, 'process_filters_callback' );
That units the callback and it really works high-quality…however that occasion of $gbf is misplaced when the web page that shows the posts masses and I have to set extra properties when the template is loaded.
For example, when the web page that shows the posts masses, I create a brand new FilterBuilder object and cross it the question args that are then saved on the occasion as a property of the category.
When the callback is invoked, it is coping with its personal occasion of a FilterBuilder, so something I outlined within the template doesn’t exist on this class occasion.
This places me in a little bit of a pickle as a result of I wish to have entry to the question args that have been outlined when that exact occasion was created.
I’ve resorted in the interim to make use of transients so I can have a typical place to entry the question args that the template occasion outlined from the callback perform, however this simply feels unsuitable. Moreover, I consider transients have a max size and subsequently this would possibly explode if that restrict is reached.
What different choices are there? Perhaps serializing the template class occasion right into a JSON and cargo it from the callback? That additionally sounds … a bit meh.
I don’t need to use world variables…all for what you suppose can be a sublime method to avoid this concern.
Thanks for taking the time to learn this! 👍🏽