Skip to content

Commit

Permalink
Add option to change the shortcode namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nbejansen committed Mar 31, 2022
1 parent f5b2c7a commit 8209f17
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions framework/Traits/HasShortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

trait HasShortcodes
{
/**
* The shortcode namespace.
*
* @var ?string
*/
protected $shortcode_namespace = null;

/**
* Add namespaced shortcode.
*
* @param callable|string $callback
*/
public function add_shortcode(string $tag, $callback): void
public function add_shortcode(string $tag, $callback, $namespaced = true): void
{
if (is_string($callback)) {
$callback = [$this, $callback];
Expand All @@ -21,6 +28,11 @@ public function add_shortcode(string $tag, $callback): void
$app = $this;
}

add_shortcode($app->namespace($tag, '_'), $callback);
add_shortcode(
$this->shortcode_namespace
? $this->shortcode_namespace . '_' . $tag
: $app->namespace($tag, '_'),
$callback
);
}
}

0 comments on commit 8209f17

Please sign in to comment.