MS_Addon_Bbpress

The Membership 2 MS Addon Bbpress class.

Defined (1)

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

/app/addon/bbpress/class-ms-addon-bbpress.php  
  1. class MS_Addon_Bbpress extends MS_Addon { 
  2.  
  3. /** 
  4. * The Add-on ID 
  5. * @since 1.0.0 
  6. */ 
  7. const ID = 'bbpress'; 
  8.  
  9. /** 
  10. * Checks if the current Add-on is enabled 
  11. * @since 1.0.0 
  12. * @return bool 
  13. */ 
  14. static public function is_active() { 
  15. if ( ! self::bbpress_active() 
  16. && MS_Model_Addon::is_enabled( self::ID ) 
  17. ) { 
  18. $model = MS_Factory::load( 'MS_Model_Addon' ); 
  19. $model->disable( self::ID ); 
  20.  
  21. return MS_Model_Addon::is_enabled( self::ID ); 
  22.  
  23. /** 
  24. * Returns the Add-on ID (self::ID). 
  25. * @since 1.0.1.0 
  26. * @return string 
  27. */ 
  28. public function get_id() { 
  29. return self::ID; 
  30.  
  31. /** 
  32. * Initializes the Add-on. Always executed. 
  33. * @since 1.0.0 
  34. */ 
  35. public function init() { 
  36. // Always remove bbpress from MS_Rule_CptGroup_Model. 
  37. $this->add_filter( 
  38. 'ms_rule_cptgroup_model_get_excluded_content',  
  39. 'exclude_bbpress_cpts' 
  40. ); 
  41.  
  42. if ( self::is_active() ) { 
  43. $this->add_filter( 
  44. 'ms_controller_protection_tabs',  
  45. 'rule_tabs' 
  46. ); 
  47.  
  48. MS_Factory::load( 'MS_Addon_Bbpress_Rule' ); 
  49.  
  50. /** 
  51. * Registers the Add-On 
  52. * @since 1.0.0 
  53. * @param array $list The Add-Ons list. 
  54. * @return array The updated Add-Ons list. 
  55. */ 
  56. public function register( $list ) { 
  57. $list[ self::ID ] = (object) array( 
  58. 'name' => __( 'bbPress Integration', 'membership2' ),  
  59. 'description' => __( 'Enable bbPress rules integration.', 'membership2' ),  
  60. 'icon' => 'dashicons dashicons-format-chat',  
  61. ); 
  62.  
  63. if ( ! self::bbpress_active() ) { 
  64. $list[ self::ID ]->description .= sprintf( 
  65. '<br /><b>%s</b>',  
  66. __( 'Activate bbPress to use this Add-on', 'membership2' ) 
  67. ); 
  68. $list[ self::ID ]->action = '-'; 
  69.  
  70. return $list; 
  71.  
  72. /** 
  73. * Returns true, when the BuddyPress plugin is activated. 
  74. * @since 1.0.0 
  75. * @return bool 
  76. */ 
  77. static public function bbpress_active() { 
  78. return class_exists( 'bbPress' ); 
  79.  
  80. /** 
  81. * Add bbpress rule tabs in membership level edit. 
  82. * @since 1.0.0 
  83. * @filter ms_controller_membership_get_tabs 
  84. * @param array $tabs The current tabs. 
  85. * @param int $membership_id The membership id to edit 
  86. * @return array The filtered tabs. 
  87. */ 
  88. public function rule_tabs( $tabs ) { 
  89. $rule = MS_Addon_Bbpress_Rule::RULE_ID; 
  90. $tabs[ $rule ] = true; 
  91.  
  92. return $tabs; 
  93.  
  94. /** 
  95. * Exclude BBPress custom post type from MS_Rule_CptGroup_Model. 
  96. * @since 1.0.0 
  97. * @filter ms_rule_cptgroup_model_get_excluded_content 
  98. * @param array $excluded The current excluded ctps. 
  99. * @return array The filtered excluded ctps. 
  100. */ 
  101. public function exclude_bbpress_cpts( $excluded ) { 
  102. $excluded = array_merge( 
  103. $excluded,  
  104. MS_Addon_Bbpress_Rule_Model::get_bb_cpt() 
  105. ); 
  106.  
  107. return $excluded; 
  108.