SLP_BaseClass_AJAX
extends SLPlus_BaseClass_Object
in package
A base class that helps add-on packs separate AJAX functionality.
Add on packs should include and extend this class.
This allows the main plugin to only include this file in AJAX mode.
Table of Contents
Properties
- $addon : SLP_BaseClass_Addon
- $addon : mixed
- $formdata : array<string|int, mixed>
- $formdata_defaults : array<string|int, mixed>
- $formdata_set : bool
- $query_params : array<string|int, mixed>
- $query_params : mixed
- $query_params_valid : array<string|int, string>
- $short_action : string
- $slplus : SLPlus
- $uses_slplus : bool
- $valid_actions : array<string|int, string>
- $formdata : mixed
- $formdata_defaults : mixed
- $query_params_valid : mixed
- $slplus : mixed
- $uses_slplus : mixed
- $valid_actions : mixed
- $formdata_set : mixed
- $set_query_params_done : mixed
- $short_action : mixed
Methods
- __construct() : mixed
- __get() : SLPlus_BaseClass_Object
- __isset() : bool
- add_ajax_hooks() : mixed
- Override this with the WordPress AJAX hooks you want to invoke.
- do_ajax_startup() : mixed
- Things we want our add on packs to do when they start in AJAX mode.
- get_instance() : SLPlus_BaseClass_Object
- Return an instance of the object which is also registered to the slplus global less the SLP_ part.
- initialize() : mixed
- Instantiate the admin panel object.
- is_valid_ajax_action() : mixed
- Return true if the AJAX action is one we process.
- sanitize_query_params() : mixed|string
- A less aggressive query param processor.
- send_JSON_response() : mixed
- Output a JSON response based on the incoming data and die.
- set_properties() : mixed
- Set our properties.
- set_QueryParams() : mixed
- Set incoming query and request parameters into object properties.
Properties
$addon
public
SLP_BaseClass_Addon
$addon
This addon pack.
$addon
public
mixed
$addon
$formdata
public
array<string|int, mixed>
$formdata
Form data that comes into the AJAX request in the formdata variable.
$formdata_defaults
public
array<string|int, mixed>
$formdata_defaults
The formdata default values.
$formdata_set read-only
public
bool
$formdata_set
Has the formdata been set already?
$query_params
public
array<string|int, mixed>
$query_params
$query_params
public
mixed
$query_params
= array()
$query_params_valid
public
array<string|int, string>
$query_params_valid
Array of valid AJAX query parameters
$short_action read-only
public
string
$short_action
The shortened (csl_ajax prefix dropped) AJAX action.
$slplus
public
SLPlus
$slplus
$uses_slplus
public
bool
$uses_slplus
Set to true (default) if the object needs access to the SLPlus plugin object.
$valid_actions
public
array<string|int, string>
$valid_actions
What AJAX actions are valid for this add on to process? Override in the extended class if not serving the default SLP actions: csl_ajax_onload csl_ajax_search
$formdata
protected
mixed
$formdata
= array()
$formdata_defaults
protected
mixed
$formdata_defaults
= array()
$query_params_valid
protected
mixed
$query_params_valid
= array()
$slplus
protected
mixed
$slplus
$uses_slplus
protected
mixed
$uses_slplus
= \true
$valid_actions
protected
mixed
$valid_actions
= array('csl_ajax_onload', 'csl_ajax_search')
$formdata_set
private
mixed
$formdata_set
= \false
$set_query_params_done
private
mixed
$set_query_params_done
= \false
$short_action
private
mixed
$short_action
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
__get()
public
__get(string $property) : SLPlus_BaseClass_Object
Parameters
- $property : string
Return values
SLPlus_BaseClass_Object__isset()
public
__isset(string $property) : bool
Parameters
- $property : string
Return values
booladd_ajax_hooks()
Override this with the WordPress AJAX hooks you want to invoke.
public
add_ajax_hooks() : mixed
example: add_action('wp_ajax_csl_ajax_search' , array( $this,'csl_ajax_search' )) // For logged in users add_action('wp_ajax_nopriv_csl_ajax_search' , array( $this,'csl_ajax_search' )) // Not logged-in users
do_ajax_startup()
Things we want our add on packs to do when they start in AJAX mode.
public
do_ajax_startup() : mixed
Add methods named process_{short_action_name} to the extended class, or override this method.
Tags
get_instance()
Return an instance of the object which is also registered to the slplus global less the SLP_ part.
public
static get_instance([bool $no_global = false ][, mixed $params = array() ]) : SLPlus_BaseClass_Object
TODO: PHP7.4 and PHP8.0 the static instance variable returns an object matching $class TODO: PHP8.1 the static instance continually returns the FIRST object (SLP_Admin_Helper) every time -- it is like PHP8.1 static instance is bound to base_class-object versus the calling class object
Parameters
- $no_global : bool = false
-
set to true to skip assigning object to SLP global as a property.
- $params : mixed = array()
-
object init params
Return values
SLPlus_BaseClass_Objectinitialize()
Instantiate the admin panel object.
public
initialize() : mixed
Sets short_action property. Calls do_ajax_startup.
- sets Query Params (formdata)
- Calls process_{short_action} if method exists.
is_valid_ajax_action()
Return true if the AJAX action is one we process.
public
is_valid_ajax_action() : mixed
TODO: add a "source" parameter as well and set to "slp" then check that to make sure we only process SLP requests
sanitize_query_params()
A less aggressive query param processor.
public
sanitize_query_params( $str) : mixed|string
We need to keep & as & for query strings. We also need to allow some form posts to send allowed HTML tags (layout settings).
Parameters
Return values
mixed|stringsend_JSON_response()
Output a JSON response based on the incoming data and die.
public
send_JSON_response(array<string|int, mixed> $data) : mixed
Used for AJAX processing in WordPress where a remote listener expects JSON data.
Parameters
- $data : array<string|int, mixed>
-
named array of keys and values to turn into JSON data
set_properties()
Set our properties.
public
set_properties([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
set_QueryParams()
Set incoming query and request parameters into object properties.
public
set_QueryParams() : mixed