Overview

Namespaces

  • Varunsridharan
    • WordPress

Classes

  • Ajaxer
  • Overview
  • Namespace
  • Class

Class Ajaxer

Class Ajaxer

Abstract
Namespace: Varunsridharan\WordPress
Package: Varunsridharan\WordPress
Author: Varun Sridharan varunsridharan23@gmail.com
Since: 1.0
Located at src/Ajaxer.php
Methods summary
public
# __construct( )

Ajaxer constructor.

Ajaxer constructor.

final protected string
# ajax_slug( $action )

Returns Modified Ajax Action Slug

Returns Modified Ajax Action Slug

Parameters

$action

Returns

string
final public
# ajax_request_single( )

Triggers A Callback to a ajax request

Triggers A Callback to a ajax request

Hook

ajax_before_{ajax_action}

ajax_after_{ajax_action}

if method not exists then below hook fires


ajax_{ajax_action} ajax_action will be replaced with {$this->action}-action from url


final protected string
# extract_action_slug( $action )

Extracts Action Without Prefix / Surfix ($this->action_prefix | $this->action_surfix)

Extracts Action Without Prefix / Surfix ($this->action_prefix | $this->action_surfix)

Parameters

$action

Returns

string
protected
# trigger_ajax_callback( $action )

Triggers A AjaxCallback

Triggers A AjaxCallback

Parameters

$action

Hook

ajax_before_{ajax_action}

ajax_after_{ajax_action} if method not exists then below hook fires


ajax_{ajax_action}
final public
# ajax_request( )

Handles Multiple Ajax Requests.

Handles Multiple Ajax Requests.

protected string
# request_type( string|array $type = null )

Checks / Returns the type of request method for the current request.

Checks / Returns the type of request method for the current request.

Parameters

$type

The type of request you want to check. If an array this method will return true if the request matches any type.

Returns

string
public string|boolean|boolean
# is_get( )

Checks if Current Request Method Is GET

Checks if Current Request Method Is GET

Returns

string|boolean|boolean
public string|boolean|boolean
# is_post( )

Checks if Current Request Method Is POST

Checks if Current Request Method Is POST

Returns

string|boolean|boolean
protected boolean
# has( string $key = '', string $type = 'GET' )

Checks if given key exists in given request global array ($_GET/$_POST/$_REQUEST)

Checks if given key exists in given request global array ($_GET/$_POST/$_REQUEST)

Parameters

$key
$type

Returns

boolean
public boolean
# has_get( $key )

Parameters

$key

Returns

boolean
public boolean
# has_post( $key )

Parameters

$key

Returns

boolean
public boolean
# has_request( $key )

Parameters

$key

Returns

boolean
public boolean|mixed
# get( string $key = '', boolean $default = false )

Returns give key's value from $_GET

Returns give key's value from $_GET

Parameters

$key
$default

Returns

boolean|mixed
public boolean|mixed
# post( string $key = '', boolean $default = false )

Returns give key's value from $_GET

Returns give key's value from $_GET

Parameters

$key
$default

Returns

boolean|mixed
public boolean|mixed
# request( string $key = '', boolean $default = false )

Returns give key's value from $_REQUEST

Returns give key's value from $_REQUEST

Parameters

$key
$default

Returns

boolean|mixed
protected array
# error_message( boolean|string $error_title = false, boolean|string $error_message = false )

Parameters

$error_title
$error_message

Returns

array
protected array
# success_message( boolean|string $success_title = false, boolean|string $success_message = false )

Parameters

$success_title
$success_message

Returns

array
public
# json_error( mixed $data = null, null $status_code = null )

Parameters

$data
$status_code
public
# json_success( mixed $data = null, null $status_code = null )

Parameters

$data
$status_code
protected boolean|mixed
# validate( string $key, string|boolean $error_title = false, string|boolean $error_message = false, string $type = 'GET' )

Parameters

$key
$error_title
$error_message
$type

Returns

boolean|mixed
public
# error( string|boolean $error_title = false, string|boolean $error_message = false, array $args = array() )

Sends WP Error.

Sends WP Error.

Parameters

$error_title
$error_message
$args
public
# success( boolean|string $success_title = false, boolean|string $success_message = false, array $args = array() )

Parameters

$success_title
$success_message
$args
public boolean|mixed
# validate_post( string $key, string|boolean $error_title = false, string|boolean $error_message = false )

Parameters

$key
$error_title
$error_message

Returns

boolean|mixed
public boolean|mixed
# validate_get( string $key, string|boolean $error_title = false, string|boolean $error_message = false )

Parameters

$key
$error_title
$error_message

Returns

boolean|mixed
public boolean|mixed
# validate_request( string $key, string|boolean $error_title = false, string|boolean $error_message = false )

Parameters

$key
$error_title
$error_message

Returns

boolean|mixed
public boolean
# is_logged_in( )

Checks if user is logged in.

Checks if user is logged in.

Returns

boolean
Properties summary
protected string $action_prefix

Ajax Action Prefix

Ajax Action Prefix

Example

for wordpress_show_popup wordpress is the prefix
# ''
protected string $action_surfix

Ajax Action Surfix

Ajax Action Surfix

Example

for wordpress_show_popup_data data is the surfix
# ''
protected string $action

Action Name provide value if all ajax requests runs in a single action key.

Action Name provide value if all ajax requests runs in a single action key.

# ''
protected array $actions

Array of ajax actions

Array of ajax actions

Example

array('ajax_action_1' => true,'ajax_action_2' => false) if value set to true then it runs for both loggedout / logged in users if value set to false then it runs only for the logged in user


array('ajax_action_1' => array('auth' => false,'callback' => array(CLASSNAME,METHODNAME))) if auth value set to true then it runs for both loggedout / logged in users if auth value set to false then it runs only for the logged in user callback can either be a string,array or a actual dynamic function.


# array()
protected boolean $is_single

Set to true if plugin's ajax runs in a single action OR Set a custom key so convert plugin-slug=ajax-action into your-key=ajax-action

Set to true if plugin's ajax runs in a single action OR Set a custom key so convert plugin-slug=ajax-action into your-key=ajax-action

Example

Single Ajax Action : admin-ajax.php?action=plugin-slug&plugin-slug-action=ajax-action&param1=value1&param2=value=2 Multiple Ajax Actions : admin-ajax.php?action=plugin-slug-ajax-action1&param1=value1=param2=value2


Single Ajax Action : admin-ajax.php?action=plugin-slug&custom-key-action=ajax-action&param1=value1&param2=value=2

     Multiple Ajax Actions:
        admin-ajax.php?action=plugin-slug-ajax-action1&param1=value1=param2=value2

# false
API documentation generated by ApiGen