\AllSpark

A pretty good base class for WordPress plugins

Summary

Methods
Properties
Constants
addUI()
getInstance()
No public properties found
No constants found
add_action()
add_filter()
listen_for_ajax_action()
$updateBlockWP
$updateUseCustom
$settings_url
N/A
No private methods found
No private properties found
N/A

Properties

$updateBlockWP

$updateBlockWP

Flag to block checking WP for updates to this plugin.

$updateUseCustom

$updateUseCustom

Flag to enable checking for updates in a custom plugin repository

$settings_url

$settings_url

Override the settings_url in your subclass to automatically enable a settings link in the plugin list Example:

protected $settings_url = "espn-feed";

public function admin_menu(){
  $self = $this;

  $ret = add_options_page( 'My Plugin', 'My Plugin', 'moderate_comments', $this->settings_url, function() use($self){
     $self->addUI('ui/admin.php');
  });
}

Methods

addUI()

addUI(string $path, boolean $isRelativePath)

Provides a hack to allow using closures for UI inclusion (which dramatically improves code readability).

If you're on PHP < 5.4, you can do something like the following:

$self = $this;

add_some_menu_page('name', function() use ($self){
   $self->addUI('path-to-ui-file.php');
});

And references to $this in that file will refer to the plugin object. Once we make PHP 5.4 a dependency for this project, it'll be trivial to replace $self with $this in all the relevant locations and clean up the code a little.

Parameters

string $path

The relative path of the UI file you wish to embed

boolean $isRelativePath

[optional] True if we should treat the $path parameter as relative to the implementing plugin (the least-surprising behaviour)

getInstance()

getInstance() : \AllSpark

Returns the singleton instance of this plugin class

Returns

\AllSpark

The singleton instance

add_action()

add_action(string $name, string $callback, int $priority, int $accepted_args)

Attaches a method on the current object to a WordPress hook. By default, the method name is the same as the hook name. In some cases, this behavior may not be desirable and can be overridden.

Parameters

string $name

The name of the action you wish to hook into

string $callback

[optional] The class method you wish to be called for this hook

int $priority

[optional] Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the filter.

int $accepted_args

[optional] The number of arguments the hooked function accepts. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run.

add_filter()

add_filter(string $name, string $callback, int $priority, int $accepted_args)

Attaches a method on the current object to a WordPress hook. By default, the method name is the same as the hook name. In some cases, this behavior may not be desirable and can be overridden.

Parameters

string $name

The name of the action you wish to hook into

string $callback

[optional] The class method you wish to be called for this hook

int $priority

[optional] Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the filter.

int $accepted_args

[optional] The number of arguments the function(s) accept(s). In WordPress 1.5.1 and newer hooked functions can take extra arguments that are set when the matching apply_filters() call is run.

listen_for_ajax_action()

listen_for_ajax_action(string $name, boolean $must_be_logged_in)

Attaches a method on the current object to a WordPress ajax hook. The method name is ajax_[foo] where `foo` is the action name

Parameters

string $name

The name of the action you wish to hook into

boolean $must_be_logged_in

[optional] A flag to indicate whether the user must be currently logged on the admin side in order for the call to work. Defaults to true