diff --git a/CHANGELOG.md b/CHANGELOG.md index 58201a8..ae06306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v4.2.2 +## 03/04/2020 + +1. [](#improved) + * Added second `$options` parameter to `ShortcodeCore->registerAllShortcodes()`, key `ignore` can be used to ignore class names / files from being loaded +1. [](#bugfix) + * Fix shortcodes which do not override `init()` method, added deprecation notice instead [#82](https://github.com/getgrav/grav-plugin-shortcode-core/issues/82) + * Fixed error message showing up when updating older versions (<4.2.0) of the plugin [#84](https://github.com/getgrav/grav-plugin-shortcode-core/issues/84) + # v4.2.1 ## 02/14/2020 diff --git a/blueprints.yaml b/blueprints.yaml index c7e5664..2231d25 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Shortcode Core -version: 4.2.1 +version: 4.2.2 description: "This plugin provides the core functionality for shortcode plugins" icon: code author: diff --git a/classes/Shortcode.php b/classes/Shortcode.php new file mode 100644 index 0000000..10cd16f --- /dev/null +++ b/classes/Shortcode.php @@ -0,0 +1,7 @@ +isDot()) { + if ($file->isDot() || \in_array($file->getBasename('.php'), $ignore, true)) { continue; } $this->registerShortcode($file->getFilename(), $directory); diff --git a/classes/shortcodes/Shortcode.php b/classes/shortcodes/Shortcode.php index 69ff388..a3c9e30 100644 --- a/classes/shortcodes/Shortcode.php +++ b/classes/shortcodes/Shortcode.php @@ -36,7 +36,15 @@ public function __construct() /** * Initialize shortcode handler */ - abstract public function init(); + public function init() + { + user_error(__METHOD__ . '() method will be abstract in the future, please override it!', E_USER_DEPRECATED); + + // FIXME: This code had to be put back because of some plugins do not properly initialize themselves. + $this->shortcode->getHandlers()->add('u', static function(ShortcodeInterface $shortcode) { + return $shortcode->getContent(); + }); + } /** * Returns the name of the class if required diff --git a/shortcode-core.php b/shortcode-core.php index de7ea16..8979049 100644 --- a/shortcode-core.php +++ b/shortcode-core.php @@ -103,6 +103,10 @@ public function onPageContentProcessed(Event $e) $this->processShortcodes($e['page'], 'processContent'); } + /** + * @param PageInterface $page + * @param string $type + */ protected function processShortcodes(PageInterface $page, $type = 'processContent') { $meta = []; $config = $this->mergeConfig($page); @@ -141,6 +145,10 @@ protected function processShortcodes(PageInterface $page, $type = 'processConten } } + /** + * @param PageInterface $page + * @return \Grav\Common\Data\Data + */ protected function getConfig(PageInterface $page) { $config = $this->mergeConfig($page); @@ -200,7 +208,7 @@ public function onPageContent(Event $event) */ public function onShortcodeHandlers() { - $this->shortcodes->registerAllShortcodes(__DIR__ . '/classes/shortcodes'); + $this->shortcodes->registerAllShortcodes(__DIR__ . '/classes/shortcodes', ['ignore' => ['Shortcode', 'ShortcodeObject']]); // Add custom shortcodes directory if provided $custom_shortcodes = $this->config->get('plugins.shortcode-core.custom_shortcodes'); @@ -214,12 +222,7 @@ public function onShortcodeHandlers() */ public function onTwigInitialized() { - $this->grav['twig']->twig()->addFilter( - new \Twig_SimpleFilter( - 'shortcodes', - [$this->shortcodes, 'processShortcodes'] - ) - ); + $this->grav['twig']->twig()->addFilter(new \Twig_SimpleFilter('shortcodes', [$this->shortcodes, 'processShortcodes'])); $this->grav['twig']->twig_vars['shortcode'] = new ShortcodeTwigVar(); } }