{eac}Doojigger Using Doojigger

EarthAsylum Consulting WordPress eacDoojigger

Using the methods, filters, and actions provided by {eac}Doojigger.

Document Header

Homepage:https://eacDoojigger.earthasylum.com/
Author:EarthAsylum Consulting
Last Updated:2-Mar-2024
Contributors:earthasylum, kevinburkholder Requires {eac}Doojigger:2.5
WordPress URI:https://wordpress.org/plugins/search/earthasylum/
GitHub URI:https://github.com/EarthAsylum/docs.eacDoojigger/wiki/

Description

{eac}Doojigger provides many useful methods and hooks which can be accessed from your custom plugins or extensions, as well as from your theme functions or any code in WordPress.

Method Access

Public methods in eacDoojigger.class.php (including abstract classes) may be accessed by using the global eacDoojigger() function.

eacDoojigger()->{methodName}(...$arguments);

From within your derivative plugin, simply use $this and from within your extensions, you may use $this or $this->plugin *.

$this->{methodName}(...$arguments);
$this->plugin->{methodName}(...$arguments);

For example, to write an entry to the debugging log...

eacDoojigger()->logDebug( $myVariable, 'Logging myVariable' );
$this->logDebug( $myVariable, 'Logging myVariable' );
$this->plugin->logDebug( $myVariable, 'Logging myVariable' );

To access a plugin option...

eacDoojigger()->get_option( 'my_option_name' );
$this->get_option( 'my_option_name' );
$this->plugin->get_option( 'my_option_name' );

To invoke a plugin action...

eacDoojigger()->do_action( 'my_action_name', $arg1, $arg2, ... );
$this->do_action( 'my_action_name', $arg1, $arg2, ... );
$this->plugin->do_action( 'my_action_name', $arg1, $arg2, ... );

To invoke a method in a plugin extension, use callMethod()...

eacDoojigger()->callMethod( [ {extensionName}, {extensionMethodName} ], ...$arguments )
$this->callMethod( [ {extensionName}, {extensionMethodName} ], ...$arguments )
$this->plugin->callMethod( [ {extensionName}, {extensionMethodName} ], ...$arguments )

* Version 2.0.1 of {eac}Doojigger...

  • Removed some method calling restrictions in extensions so that $this->plugin is no longer necessary as long as the method name is unique. Extensions can now simply use $this->{methodName}(...$arguments); to access eacDoojigger.class.php methods.

  • Invoking methods in extensions may be done by accessing the extension directly (by class name) via $this->{extension_name}->{methodName}(...$arguments);. For example, if you have an extension class named 'myAwesomeExtension', you may invoke its public methods using:

    $this->myAwesomeExtension->{methodName}(...$arguments);
    
    eacDoojigger()->myAwesomeExtension->{methodName}(...$arguments);
  • You may also test for and retrieve an extension object using $this->isExtension(extension_name):

    if ($myExtension = $this->isExtension('myAwesomeExtension')) { $myExtension->{methodName}(...$arguments); }

    if ($myExtension = eacDoojigger()->isExtension('myAwesomeExtension')) { $myExtension->{methodName}(...$arguments); }

Filters and Shortcodes

{eac}Doojigger (and derivatives) provides a front-end filter and a shortcode that gives access to (nearly) all public methods in the plugin and extensions, WordPress options, and blog info.

The filter and shortcode name is the plugin class name ('eacDoojigger'). Arguments include:

  • method='{methodName}' or method='{extension.methodName}'
  • option='{optionName}'
  • bloginfo='{bloginfoName}'
  • args='...', to pass a list of arguments/values.
  • default='...', to set a default value.
  • index='...', to index an item from an array returned by the called method.

Filter Examples:

\apply_filters('eacDoojigger', null, [ method='getVariable' args='session_manager' ]);  //  expecting session manager stored variable
\apply_filters('eacDoojigger', null, [ method='session.sessionId' ]);                   //  expecting session id from session extension
\apply_filters('eacDoojigger', null, [ method='_SERVER' args='server_name' ]);          //  expecting server name from $_SERVER
\apply_filters('eacDoojigger', null, [ method='getPluginValue' args='PluginSlug' ]);    //  expecting plugin slug
\apply_filters('eacDoojigger', null, [ option='siteEnvironment' ]);                     //  expecting siteEnvironment
\apply_filters('eacDoojigger', null, [ option='blogdescription' ]);                     //  expecting WordPress blogdescription
\apply_filters('eacDoojigger', null, [ option='woocommerce_cybersource_credit_card_settings' index='description' default='not installed' ]);    //  expecting cybersource description
\apply_filters('eacDoojigger', null, [ bloginfo='name' ]);                              //  expecting WordPress Site Title

Shortcode Examples:

['eacDoojigger' method='getVariable' args='session_manager']    //  expecting session manager stored variable
['eacDoojigger' method='session.sessionId']                     //  expecting session id from session extension
['eacDoojigger' method='_SERVER' args='server_name']            //  expecting server name from $_SERVER
['eacDoojigger' method='getPluginValue' args='PluginSlug']      //  expecting plugin slug
['eacDoojigger' option='siteEnvironment']                       //  expecting siteEnvironment
['eacDoojigger' option='blogdescription']                       //  expecting WordPress blogdescription
['eacDoojigger' option='woocommerce_cybersource_credit_card_settings' index='description' default='not installed']  //  expecting cybersource description
['eacDoojigger' bloginfo='name' ]                               //  expecting WordPress Site Title

Filters, Options, and Transients

When using class methods to access filters and actions, options, and transients, all names are prefixed with the plugin name ('eacDoojigger_*). These functions are extended wrappers around WordPress methods...

  • $this->add_filter(...) rather than add_filter(...)
  • $this->add_option(...) rather than add_option(...)
  • $this->add_network_option(...) rather than add_network_option(...)
  • $this->add_site_option(...) rather than add_site_option(...)
  • $this->set_transient(...) rather than set_transient(...)
  • $this->set_site_transient(...) rather than set_site_transient(...)

See the Multi-Site Network section for other important differences.

Table Names

For custom table names, use $this->prefixTableName('my_table_name') to ensure uniqueness of your table name(s). This will prefixed your table name with the lower-case plugin name ('eacdoojigger_*).

Front-end, Back-end, Network Determination

In WordPress, ajax requests always return true for is_admin() and false for is_network_admin(). {eac}Doojigger digs a little deeper and returns the correct response for $this->is_admin() and $this->is_network_admin(). It also sets static variables to make repeated checks faster as well as including a few additional methods...

Static variable / method Value / response
static::CONTEXT_IS_BACKEND Set to true when request is for/from an administrator (backend) page
static::CONTEXT_IS_FRONTEND Set to true when request is not for/from an administrator (backend) page
static::CONTEXT_IS_NETWORK Set to true when request is for/from a network administrator page
$this->is_backend() Returns static::CONTEXT_IS_BACKEND
$this->is_frontend() Returns static::CONTEXT_IS_FRONTEND
$this->is_admin() Set to static::CONTEXT_IS_BACKEND on load, can be overriden
$this->is_network_admin() Set to static::CONTEXT_IS_NETWORK on load, can be overriden
Top