Skip to content

Instantly share code, notes, and snippets.

@rajucs
Created November 11, 2022 18:23
Show Gist options
  • Save rajucs/66faa6879bf1e2000985af2395c3daff to your computer and use it in GitHub Desktop.
Save rajucs/66faa6879bf1e2000985af2395c3daff to your computer and use it in GitHub Desktop.
Add shortcode to wppb boilerplate
public function __construct()
{
$this->actions = array();
$this->filters = array();
$this->shortcodes = array();
}
/**
* 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, $priority = 10, $accepted_args = 2)
{
$this->shortcodes = $this->add($this->shortcodes, $tag, $component, $callback, $priority, $accepted_args);
}
public function run()
{
foreach ($this->filters as $hook) {
add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
}
foreach ($this->actions as $hook) {
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']));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment