{eac}Doojigger: Using Doojigger

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

Document Header

Homepage:https://eacDoojigger.earthasylum.com/ Author:EarthAsylum Consulting Last Updated:10-Nov-2022 Contributors:Kevin Burkholder Requires {eac}Doojigger:2.0


{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.


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


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 execute 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 execute a method in a plugin extension, use callMethod()...

eacDoojigger()->callMethod( [ {extensionName}, {extensionMethodName} ], ...$arguments )
$this->callMethod( [ {extensionName}, {extensionMethodName} ], ...$arguments )
$this->plugin->callMethod( [ {extensionName}, {extensionMethodName} ], ...$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
How To


Clone an {eac}Doojigger Extension

Let's say you want to use the session manager included with {eac}Doojigger as an extension to your own plugin (myAwesomePlugin).

Create session_manager.extension.class.php in your myAwesomePlugin Extensions folder:

namespace myAwesomeNamespace\Extensions;

if ( class_exists('\EarthAsylumConsulting\Extensions\session_extension') )
    return new \EarthAsylumConsulting\Extensions\session_extension($this);

This works for extensions included with {eac}Doojiger but what about extension plugins? Let's try eacMetaPixel to add Facebook tracking to your plugin...

(almost the same but the auto-loader may not know where to find the extension if it hasn't been loaded yet.)

Create metapixel.extension.php in your myAwesomePlugin Extensions folder:

namespace myAwesomeNamespace\Extensions;

if ( class_exists('\EarthAsylumConsulting\Extensions\metapixel_extension') )
    return new metapixel_extension($this);
if ( file_exists(WP_PLUGIN_DIR.'/eacmetapixel/Extensions/metapixel.extension.php') )
    return require(WP_PLUGIN_DIR.'/eacmetapixel/Extensions/metapixel.extension.php');

This will load the metapixel extension, if it is installed, whether or not it is activated.

In both, the extension will be loaded by and will extend your plugin. Extension settings will be added to your options page and those settings will be stored with your plugin settings, prefixed with your plugin name.


    Write a Reply or Comment

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>