PHP Class WpGears\Plugin

When run in Client mode it will allow adding new jobs to the Queue. When run in worker mode it will execute jobs on the Queue. Worker mode also allows adding new jobs to the queue just like Mlient mode.
Exibir arquivo Open project: 10up/wp-gears Class Usage Examples

Public Properties

Property Type Description
$client The Client object used to enqueue jobs
$client_class client class
$config_prefix Configuration constants are prefixed by WP_GEARS by default. ;w Eg:- WP_GEARS_JOBS_PER_WORKER
$did_enable *
$did_run *
$instance Single instance of the plugin
$jobs_per_worker Number of jobs to execute per worker, Default 1
$worker The Worker object used to execute jobs
$worker_class Custom worker class

Public Methods

Method Description
add ( string $hook, array $args = [], string $priority = 'normal' ) : boolean Adds a new job to the Client with the specified arguments and priority.
build_client ( ) : Client Conditionally builds a new Client object. If the constant WP_GEARS_CLIENT_CLASS is defined it will return an instance of that class.
build_worker ( ) : Worker Conditionally builds a new Worker object. If the constant WP_GEARS_WORKER_CLASS is defined it will return an instance of that class.
enable ( ) Enables the plugin by registering it's clients and workers.
get_client ( ) : Client Returns the Client object used to add jobs. Creates the instance of the client lazily.
get_config ( string $constant, string $default = '', string $config_prefix = '' ) : mixed Helper to pickup config options from Constants with fallbacks.
get_instance ( ) : Plugin Returns the singleton instance of the Plugin. Creates the instance if it is absent.
get_jobs_per_worker ( ) : integer Returns the jobs to execute per worker instance
get_worker ( ) Returns the Worker object used to execute jobs. Creates the instance of the worker lazily.
get_wp_load ( ) : string Returns the path to the wp-load.php file.
has_config ( string $constant ) : boolean Checks if a config option is defined. Empty strings are treated as an undefined config option.
load_wordpress ( ) Tries to load WordPress using wp-load.php. If loading fails an error message is logged and the Script will exit immediately with a status code of 1.
quit ( integer $status_code ) Helper to quit with a status code. When running under PHPUnit it returns the status_code instead of exiting immediately.
run ( ) : integer Starts processing jobs in the Worker.
work ( ) : integer Executes jobs on the current Worker. A Worker will taken up only one job by default. If WP_GEARS_JOBS_PER_WORKER is defined that many jobs will be executed before it exits.

Method Details

add() public method

Adds a new job to the Client with the specified arguments and priority.
public add ( string $hook, array $args = [], string $priority = 'normal' ) : boolean
$hook string The action hook name for the job
$args array Optional arguments for the job
$priority string Optional priority of the job
return boolean true or false depending on the Client

build_client() public method

By default it will detect if Gearman is present and return the Gearman Client else fallback to the Cron Client.
public build_client ( ) : Client
return Client New instance of the Client

build_worker() public method

By default it will detect if Gearman is present and return the Gearman Worker else fallback to the Cron Worker.
public build_worker ( ) : Worker
return Worker New instance of the Worker

enable() public method

Ignored if already enabled
public enable ( )

get_client() public method

Returns the Client object used to add jobs. Creates the instance of the client lazily.
public get_client ( ) : Client
return Client The client instance

get_config() public method

Order of lookup is, 1. Local Property 2. Constant of that name 3. Default specified Eg:- get_config( 'FOO', 'abc', 'MY' ) will look for, 1. Local Property $this->my_foo 2. Constant MY_FOO 3. Defaualt ie:- abc
public get_config ( string $constant, string $default = '', string $config_prefix = '' ) : mixed
$constant string Name of constant to lookup
$default string Optional default
$config_prefix string Optional config prefix, Default is WP_GEARS
return mixed The value of the config

get_instance() public static method

Returns the singleton instance of the Plugin. Creates the instance if it is absent.
public static get_instance ( ) : Plugin
return Plugin instance of Plugin

get_jobs_per_worker() public method

Returns the jobs to execute per worker instance
public get_jobs_per_worker ( ) : integer
return integer Defaults to 1

get_worker() public method

Returns the Worker object used to execute jobs. Creates the instance of the worker lazily.
public get_worker ( )

get_wp_load() public method

Returns the path to the wp-load.php file.
public get_wp_load ( ) : string
return string Path to the wp-load.php file

has_config() public method

Checks if a config option is defined. Empty strings are treated as an undefined config option.
public has_config ( string $constant ) : boolean
$constant string The name of the constant
return boolean True or false depending on whether the config is present

load_wordpress() public method

Tries to load WordPress using wp-load.php. If loading fails an error message is logged and the Script will exit immediately with a status code of 1.
public load_wordpress ( )

quit() public method

Helper to quit with a status code. When running under PHPUnit it returns the status_code instead of exiting immediately.
public quit ( integer $status_code )
$status_code integer The status between 0-255 to quit with.

run() public method

Only one run is permitted.
public run ( ) : integer
return integer The exit status code (only for PHPUnit)

work() public method

This method will exit with the result code based on success/failure of executing the job.
public work ( ) : integer
return integer 0 for success and 1 for failure

Property Details

$client public_oe property

The Client object used to enqueue jobs
public $client

$client_class public_oe property

client class
public $client_class

$config_prefix public_oe property

Configuration constants are prefixed by WP_GEARS by default. ;w Eg:- WP_GEARS_JOBS_PER_WORKER
public $config_prefix

$did_enable public_oe property

*
public $did_enable

$did_run public_oe property

*
public $did_run

$instance public_oe static_oe property

Single instance of the plugin
public static $instance

$jobs_per_worker public_oe property

Number of jobs to execute per worker, Default 1
public $jobs_per_worker

$worker public_oe property

The Worker object used to execute jobs
public $worker

$worker_class public_oe property

Custom worker class
public $worker_class