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.

Revisions

  1. rajucs created this gist Nov 11, 2022.
    38 changes: 38 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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']));
    }
    }