• jbeninger

    (@jbeninger)


    I’m providing a limited set of shortcodes to a client, so I needed Shortcode Reference’s functionality, but didn’t want the default WP shortcodes cluttering up the list.

    I’ve added the following filter which will only include documentation for the shortcodes I want. Feel free to add it to the plugin code.

    @@ -50,7 +50,16 @@ class ShortcodeReferenceService {
                            global $shortcode_tags;
                            
                            self::$references = array();
    -                       foreach($shortcode_tags as $tag => $function) {
    +                       
    +                       /**
    +                        * Filter the list of shortcodes that will appear in the Shortcode Reference metabox
    +                        * 
    +                        * @param array shortcode_tags array Shortcodes in the same format as the $shortcode_tags global (tag =
    +       */
    +                       $documented_tags = apply_filters('shortcode_reference', $shortcode_tags);
    +                       
    +                       
    +                       foreach($documented_tags as $tag => $function) {
                                    $name = $tag.'_Reflection';
                                    $$name = new ShortcodeReference($tag);
                                    self::$references[$tag] = $$name;

    Usage

    add_filter('shortcode_reference', 'clientprefix_filter_shortcode_reference');
    function clientprefix_filter_shortcode_reference($shortcodes) {
      $result = [];
      
      foreach ($shortcodes as $tag => $fn) {
        if (preg_match('/^clientprefix-/', $tag)) {
          $result[$tag] = $fn;
        }
      }
      
      return $result;
    }

    Thanks for this simple-yet-effective plugin!

  • The topic ‘Request: Shortcode filter (Patch Included)’ is closed to new replies.