BBP_Component
bbPress Component Class
Description Description
The bbPress component class is responsible for simplifying the creation of components that share similar behaviors and routines. It is used internally by bbPress to create forums, topics and replies, but can be extended to create other really neat things.
Source Source
File: includes/common/classes.php
class BBP_Component { /** * @var string Unique name (for internal identification) * @internal */ var $name; /** * @var Unique ID (normally for custom post type) */ var $id; /** * @var string Unique slug (used in query string and permalinks) */ var $slug; /** * @var WP_Query The loop for this component */ var $query; /** * @var string The current ID of the queried object */ var $current_id; /** Methods ***************************************************************/ /** * bbPress Component loader * * @since 2.0.0 bbPress (r2700) * * @param array $args Required. Supports these args: * - name: Unique name (for internal identification) * - id: Unique ID (normally for custom post type) * - slug: Unique slug (used in query string and permalinks) * - query: The loop for this component (WP_Query) * - current_id: The current ID of the queried object */ public function __construct( $args = array() ) { if ( empty( $args ) ) { return; } $this->setup_globals( $args ); $this->includes(); $this->setup_actions(); } /** * Component global variables * * @since 2.0.0 bbPress (r2700) * * @access private */ private function setup_globals( $args = array() ) { $this->name = $args['name']; $this->id = apply_filters( 'bbp_' . $this->name . '_id', $args['id'] ); $this->slug = apply_filters( 'bbp_' . $this->name . '_slug', $args['slug'] ); } /** * Include required files * * @since 2.0.0 bbPress (r2700) * * @access private */ private function includes() { do_action( 'bbp_' . $this->name . 'includes' ); } /** * Setup the actions * * @since 2.0.0 bbPress (r2700) * * @access private */ private function setup_actions() { add_action( 'bbp_register_post_types', array( $this, 'register_post_types' ), 10, 2 ); // Register post types add_action( 'bbp_register_taxonomies', array( $this, 'register_taxonomies' ), 10, 2 ); // Register taxonomies add_action( 'bbp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10, 2 ); // Add the rewrite tags add_action( 'bbp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10, 2 ); // Generate rewrite rules // Additional actions can be attached here do_action( 'bbp_' . $this->name . 'setup_actions' ); } /** * Setup the component post types * * @since 2.0.0 bbPress (r2700) */ public function register_post_types() { do_action( 'bbp_' . $this->name . '_register_post_types' ); } /** * Register component specific taxonomies * * @since 2.0.0 bbPress (r2700) */ public function register_taxonomies() { do_action( 'bbp_' . $this->name . '_register_taxonomies' ); } /** * Add any additional rewrite tags * * @since 2.0.0 bbPress (r2700) */ public function add_rewrite_tags() { do_action( 'bbp_' . $this->name . '_add_rewrite_tags' ); } /** * Generate any additional rewrite rules * * @since 2.0.0 bbPress (r2700) */ public function generate_rewrite_rules( $wp_rewrite ) { do_action_ref_array( 'bbp_' . $this->name . '_generate_rewrite_rules', $wp_rewrite ); } }
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Methods Methods
- __construct — bbPress Component loader
- add_rewrite_tags — Add any additional rewrite tags
- generate_rewrite_rules — Generate any additional rewrite rules
- includes — Include required files
- register_post_types — Setup the component post types
- register_taxonomies — Register component specific taxonomies
- setup_actions — Setup the actions
- setup_globals — Component global variables