From c1f2725be985c4ea929a8cccf280ea635fad5613 Mon Sep 17 00:00:00 2001 From: Sergey Romaneko Date: Wed, 24 Oct 2012 15:24:36 +0300 Subject: [PATCH] Shortcodes API: delete() clear() exist() methods added --- monstra/engine/shortcodes.php | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/monstra/engine/shortcodes.php b/monstra/engine/shortcodes.php index 9222f28..dbccc5a 100644 --- a/monstra/engine/shortcodes.php +++ b/monstra/engine/shortcodes.php @@ -56,7 +56,7 @@ /** - * Add shortcode + * Add new shortcode * * * function returnSiteUrl() { @@ -79,6 +79,59 @@ if (is_callable($callback_function)) Shortcode::$shortcode_tags[$shortcode] = $callback_function; } + + /** + * Remove a specific registered shortcode. + * + * + * Shortcode::delete('shortcode_name'); + * + * + * @param string $shortcode Shortcode tag. + */ + pubic static function delete($shortcode) { + + // Redefine vars + $shortcode = (string) $shortcode; + + // Delete shortcode + if (Shortcode::exist($shortcode)) unset(Shortcode::$shortcode_tags[$shortcode]); + } + + + /** + * Remove all registered shortcodes. + * + * + * Shortcode::clear(); + * + * + */ + public static function clear() { + Shortcode::$shortcode_tags = array(); + } + + + /** + * Check if a shortcode has been registered. + * + * + * if (Shortcode::exist('shortcode_name')) { + * // do something... + * } + * + * + * @param string $shortcode Shortcode tag. + */ + pulbic static function exist($shortcode) { + + // Redefine vars + $shortcode = (string) $shortcode; + + // Check shortcode + return array_key_exists($shortcode, Shortcode::$shortcode_tags); + } + /** * Parse a string, and replace any registered shortcodes within it with the result of the mapped callback.