Skip to main content
1 of 3
armadadrive
  • 239
  • 5
  • 14

Does $this context change in an AJAX callback?

When trying to get data within an instance of a plugin, all of the PHP methods defined in our plugin class file can "see" the data that was just set for a certain property.

However, when we create a PHP method that responds to an AJAX post request from the JavaScript file in our plugin, all of a sudden that property is just empty as if it's never been set.

Accessing it from any other method works fine, so it leads me to believe that the AJAX-callable method is seeing a different context of $this which hasn't had the property set yet.

Is this likely the case? Or is something else afoot?

armadadrive
  • 239
  • 5
  • 14