BBP_Component

BbPress Component Class.

Defined (1)

The class is defined in the following location(s).

/includes/common/classes.php  
  1. class BBP_Component { 
  2.  
  3. /** 
  4. * @var string Unique name (for internal identification) 
  5. * @internal 
  6. */ 
  7. var $name; 
  8.  
  9. /** 
  10. * @var Unique ID (normally for custom post type) 
  11. */ 
  12. var $id; 
  13.  
  14. /** 
  15. * @var string Unique slug (used in query string and permalinks) 
  16. */ 
  17. var $slug; 
  18.  
  19. /** 
  20. * @var WP_Query The loop for this component 
  21. */ 
  22. var $query; 
  23.  
  24. /** 
  25. * @var string The current ID of the queried object 
  26. */ 
  27. var $current_id; 
  28.  
  29.  
  30. /** Methods ***************************************************************/ 
  31.  
  32. /** 
  33. * bbPress Component loader 
  34. * @since bbPress (r2700) 
  35. * @param mixed $args Required. Supports these args: 
  36. * - name: Unique name (for internal identification) 
  37. * - id: Unique ID (normally for custom post type) 
  38. * - slug: Unique slug (used in query string and permalinks) 
  39. * - query: The loop for this component (WP_Query) 
  40. * - current_id: The current ID of the queried object 
  41. * @uses BBP_Component::setup_globals() Setup the globals needed 
  42. * @uses BBP_Component::includes() Include the required files 
  43. * @uses BBP_Component::setup_actions() Setup the hooks and actions 
  44. */ 
  45. public function __construct( $args = '' ) { 
  46. if ( empty( $args ) ) 
  47. return; 
  48.  
  49. $this->setup_globals( $args ); 
  50. $this->includes(); 
  51. $this->setup_actions(); 
  52.  
  53. /** 
  54. * Component global variables 
  55. * @since bbPress (r2700) 
  56. * @access private 
  57. * @uses apply_filters() Calls 'bbp_{@link BBP_Component::name}_id' 
  58. * @uses apply_filters() Calls 'bbp_{@link BBP_Component::name}_slug' 
  59. */ 
  60. private function setup_globals( $args = '' ) { 
  61. $this->name = $args['name']; 
  62. $this->id = apply_filters( 'bbp_' . $this->name . '_id', $args['id'] ); 
  63. $this->slug = apply_filters( 'bbp_' . $this->name . '_slug', $args['slug'] ); 
  64.  
  65. /** 
  66. * Include required files 
  67. * @since bbPress (r2700) 
  68. * @access private 
  69. * @uses do_action() Calls 'bbp_{@link BBP_Component::name}includes' 
  70. */ 
  71. private function includes() { 
  72. do_action( 'bbp_' . $this->name . 'includes' ); 
  73.  
  74. /** 
  75. * Setup the actions 
  76. * @since bbPress (r2700) 
  77. * @access private 
  78. * @uses add_action() To add various actions 
  79. * @uses do_action() Calls 
  80. * 'bbp_{@link BBP_Component::name}setup_actions' 
  81. */ 
  82. private function setup_actions() { 
  83. add_action( 'bbp_register_post_types', array( $this, 'register_post_types' ), 10, 2 ); // Register post types 
  84. add_action( 'bbp_register_taxonomies', array( $this, 'register_taxonomies' ), 10, 2 ); // Register taxonomies 
  85. add_action( 'bbp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10, 2 ); // Add the rewrite tags 
  86. add_action( 'bbp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10, 2 ); // Generate rewrite rules 
  87.  
  88. // Additional actions can be attached here 
  89. do_action( 'bbp_' . $this->name . 'setup_actions' ); 
  90.  
  91. /** 
  92. * Setup the component post types 
  93. * @since bbPress (r2700) 
  94. * @uses do_action() Calls 'bbp_{@link BBP_Component::name}_register_post_types' 
  95. */ 
  96. public function register_post_types() { 
  97. do_action( 'bbp_' . $this->name . '_register_post_types' ); 
  98.  
  99. /** 
  100. * Register component specific taxonomies 
  101. * @since bbPress (r2700) 
  102. * @uses do_action() Calls 'bbp_{@link BBP_Component::name}_register_taxonomies' 
  103. */ 
  104. public function register_taxonomies() { 
  105. do_action( 'bbp_' . $this->name . '_register_taxonomies' ); 
  106.  
  107. /** 
  108. * Add any additional rewrite tags 
  109. * @since bbPress (r2700) 
  110. * @uses do_action() Calls 'bbp_{@link BBP_Component::name}_add_rewrite_tags' 
  111. */ 
  112. public function add_rewrite_tags() { 
  113. do_action( 'bbp_' . $this->name . '_add_rewrite_tags' ); 
  114.  
  115. /** 
  116. * Generate any additional rewrite rules 
  117. * @since bbPress (r2700) 
  118. * @uses do_action() Calls 'bbp_{@link BBP_Component::name}_generate_rewrite_rules' 
  119. */ 
  120. public function generate_rewrite_rules( $wp_rewrite ) { 
  121. do_action_ref_array( 'bbp_' . $this->name . '_generate_rewrite_rules', $wp_rewrite );