Skip to content

Commit

Permalink
Added shortcode support
Browse files Browse the repository at this point in the history
Started with Devin's code from DevinVinson#262 (comment)
  • Loading branch information
garretthunter authored Feb 26, 2018
1 parent 60940a9 commit 3b79c7b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion plugin-name/includes/class-plugin-name-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct() {

$this->actions = array();
$this->filters = array();
$this->shortcodes = array();

}

Expand Down Expand Up @@ -81,6 +82,18 @@ public function add_filter( $hook, $component, $callback, $priority = 10, $accep
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}

/**
* Add a new shortcode to the collection to be registered with WordPress
*
* @since 1.0.0
* @param string $tag The name of the new shortcode.
* @param object $component A reference to the instance of the object on which the shortcode is defined.
* @param string $callback The name of the function that defines the shortcode.
*/
public function add_shortcode( $tag, $component, $callback) {
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback);
}

/**
* A utility function that is used to register the actions and hooks into a single
* collection.
Expand All @@ -95,7 +108,7 @@ public function add_filter( $hook, $component, $callback, $priority = 10, $accep
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
private function add( $hooks, $hook, $component, $callback, $priority = 10, $accepted_args = 2 ) {

$hooks[] = array(
'hook' => $hook,
Expand Down Expand Up @@ -124,6 +137,11 @@ public function run() {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}

foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) );

}

}

}

0 comments on commit 3b79c7b

Please sign in to comment.