Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/12/2011 11:31:48 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Move shortcodes into object variable, and add php5 constructor. This allows bbPress plugins to filter existing shortcodes, and/or add new ones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-shortcodes.php

    r3132 r3143  
    1919class BBP_Shortcodes {
    2020
     21    /** Vars ******************************************************************/
     22
     23    /**
     24     * @var array Shortcode => function
     25     */
     26    var $codes;
     27
     28    /** Functions *************************************************************/
     29
    2130    /**
    2231     * Add the register_shortcodes action to bbp_init
     
    2736     */
    2837    function BBP_Shortcodes() {
     38        $this->__construct();
     39    }
     40
     41    /**
     42     * Add the register_shortcodes action to bbp_init
     43     *
     44     * @since bbPress (r3031)
     45     *
     46     * @uses add_action
     47     */
     48    function __construct() {
     49        $this->_setup_globals();
    2950        $this->_add_shortcodes();
     51    }
     52
     53    /**
     54     * Shortcode globals
     55     *
     56     * @since bbPress (r3143)
     57     * @access private
     58     */
     59    function _setup_globals() {
     60
     61        // Setup the shortcodes
     62        $this->codes = apply_filters( 'bbp_shortcodes', array(
     63
     64            /** Forums ********************************************************/
     65
     66            // Forum Index
     67            'bbp-forum-index'  => array( $this, 'display_forum_index' ),
     68
     69            'bbp-single-forum' => array( $this, 'display_forum'       ),
     70
     71            /** Topics ********************************************************/
     72
     73            // Topic index
     74            'bbp-topic-index'  => array( $this, 'display_topic_index' ),
     75
     76            // Topic form
     77            'bbp-topic-form'   => array( $this, 'display_topic_form'  ),
     78
     79            // Specific topic - pass an 'id' attribute
     80            'bbp-single-topic' => array( $this, 'display_topic'       ),
     81
     82            /** Topic Tags ****************************************************/
     83
     84            // All topic tags in a cloud
     85            'bbp-topic-tags' => array( $this, 'display_topic_tags'    ),
     86
     87            // Topics of tag Tag
     88            'bbp-topic-tag'  => array( $this, 'display_topics_of_tag' ),
     89
     90            /** Replies *******************************************************/
     91
     92            // Reply form
     93            'bbp-reply-form' => array( $this, 'display_reply_form'    )
     94        ) );
    3095    }
    3196
     
    40105    function _add_shortcodes() {
    41106
    42         /** Forums ************************************************************/
    43 
    44         // Forum Index
    45         add_shortcode( 'bbp-forum-index',  array( $this, 'display_forum_index' ) );
    46 
    47         // Specific forum - pass an 'id' attribute
    48         add_shortcode( 'bbp-single-forum', array( $this, 'display_forum'       ) );
    49 
    50         /** Topics ************************************************************/
    51 
    52         // Topic index
    53         add_shortcode( 'bbp-topic-index',  array( $this, 'display_topic_index'  ) );
    54 
    55         // Topic form
    56         add_shortcode( 'bbp-topic-form',   array( $this, 'display_topic_form'   ) );
    57 
    58         // Specific topic - pass an 'id' attribute
    59         add_shortcode( 'bbp-single-topic', array( $this, 'display_topic'        ) );
    60 
    61         /** Topic Tags ********************************************************/
    62 
    63         // All topic tags in a cloud
    64         add_shortcode( 'bbp-topic-tags', array( $this, 'display_topic_tags'    ) );
    65 
    66         // Topics of tag Tag
    67         add_shortcode( 'bbp-topic-tag',  array( $this, 'display_topics_of_tag' ) );
    68 
    69         /** Replies ***********************************************************/
    70 
    71         // Reply form
    72         add_shortcode( 'bbp-reply-form', array( $this, 'display_reply_form' ) );
     107        // Loop through the shortcodes
     108        foreach( $this->codes as $code => $function )
     109
     110            // Add each shortcode
     111            add_shortcode( $code, $function );
    73112
    74113        // Custom shortcodes
Note: See TracChangeset for help on using the changeset viewer.