BP_bbP_Support_Topic

Main Buddy-bbPress Support Topic Class.

Defined (1)

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

/buddy-bbpress-support-topic.php  
  1. class BP_bbP_Support_Topic { 
  2.  
  3. // plugin's global vars 
  4. public $globals; 
  5.  
  6. /** 
  7. * The constructor 
  8. * @since 2.0 
  9. * @uses BP_bbP_Support_Topic::setup_globals() to reference some globals 
  10. * @uses BP_bbP_Support_Topic::includes() to includes needed scripts 
  11. * @uses BP_bbP_Support_Topic::setup_actions() to add some key action hooks 
  12. * @uses BP_bbP_Support_Topic::setup_filters() to add some key filters 
  13. */ 
  14. public function __construct() { 
  15. $this->setup_globals(); 
  16. $this->includes(); 
  17. $this->setup_actions(); 
  18. $this->setup_filters(); 
  19.  
  20. /** 
  21. * Sets some globals 
  22. * @since 2.0 
  23. * @access private 
  24. * @uses plugin_basename() to get the plugin's basename 
  25. * @uses plugin_dir_path() to build plugin's path 
  26. * @uses plugin_dir_url() to build plugin's url 
  27. * @uses trailingslashit() to add a slash at the end of url/path 
  28. * @uses apply_filters() to let other plugins or themes override globals 
  29. */ 
  30. private function setup_globals() { 
  31. $this->globals = new stdClass(); 
  32.  
  33. $this->globals->version = '2.1.0'; 
  34.  
  35. $this->globals->file = __FILE__ ; 
  36. $this->globals->basename = apply_filters( 'bpbbpst_plugin_basenname', plugin_basename( $this->globals->file ) ); 
  37. $this->globals->plugin_dir = apply_filters( 'bpbbpst_plugin_dir_path', plugin_dir_path( $this->globals->file ) ); 
  38. $this->globals->plugin_url = apply_filters( 'bpbbpst_plugin_dir_url', plugin_dir_url ( $this->globals->file ) ); 
  39.  
  40. // Includes 
  41. $this->globals->includes_dir = apply_filters( 'bpbbpst_includes_dir', trailingslashit( $this->globals->plugin_dir . 'includes' ) ); 
  42. $this->globals->includes_url = apply_filters( 'bpbbpst_includes_url', trailingslashit( $this->globals->plugin_url . 'includes' ) ); 
  43.  
  44. $this->support_status = array(); 
  45. $this->globals->domain = 'buddy-bbpress-support-topic'; 
  46.  
  47. $this->globals->is_sidebar = false; 
  48.  
  49. // bbPress required version 
  50. $this->globals->required_bbp_version = '2.5'; 
  51. $this->globals->site_bbp_version_ok = version_compare( bbp_get_version(), $this->globals->required_bbp_version, '>=' ); 
  52.  
  53. /** 
  54. * Includes the needed file regarding to context 
  55. * @since 2.0 
  56. * @access private 
  57. * @uses is_admin() to check for WordPress backend 
  58. */ 
  59. private function includes() { 
  60. // includes the plugin functions 
  61. require( $this->globals->includes_dir . 'functions.php' ); 
  62. // includes the plugin widgets 
  63. require( $this->globals->includes_dir . 'widgets.php' ); 
  64.  
  65. // includes the BuddyPress group component 
  66. if( function_exists( 'buddypress' ) ) { 
  67. require( $this->globals->includes_dir . 'buddypress.php' ); 
  68.  
  69. // includes plugin admin class 
  70. if( is_admin() ) { 
  71. require( $this->globals->includes_dir . 'admin.php' ); 
  72.  
  73. /** 
  74. * Registers some key actions to extend bbPress 
  75. * @since 2.0 
  76. * @access private 
  77. * @uses bbp_is_deactivation() to prevent interfering with bbPress deactivation process 
  78. * @uses bbp_is_activation() to prevent interfering with bbPress activation process 
  79. * @uses add_action() to hook to key actions 
  80. * @uses is_admin() to check for WordPress backend 
  81. * @uses do_action_ref_array() to let plugins or themes do stuff once all actions are set 
  82. */ 
  83. private function setup_actions() { 
  84.  
  85. if ( bbp_is_deactivation() || bbp_is_activation() ) { 
  86. return; 
  87.  
  88. // Loads the translation 
  89. add_action( 'bbp_init', array( $this, 'load_textdomain' ), 7 ); 
  90.  
  91. // Loads the admin 
  92. if( is_admin() ) { 
  93. add_action( 'init', 'bpbbpst_admin' ); 
  94.  
  95. if ( ! $this->globals->site_bbp_version_ok ) { 
  96. return; 
  97.  
  98. // Defines support status, doing so in globals avoids strings in it to be translated 
  99. add_action( 'bbp_init', array( $this, 'setup_status' ), 9 ); 
  100.  
  101. // Adding the support control to the topic new/edit form 
  102. add_action( 'bbp_theme_before_topic_form_submit_wrapper', 'bpbbpst_maybe_output_support_field' ); 
  103.  
  104. // setting the support type on front end new topic form submission 
  105. add_action( 'bbp_new_topic_post_extras', 'bpbbpst_save_support_type', 10, 1 ); 
  106.  
  107. // Eventually display some feedback to the user 
  108. add_action( 'bbp_template_notices', 'bpbbpst_template_notices', 10 ); 
  109.  
  110. // Add a checkbox to mark the topic as resolved 
  111. add_action( 'bbp_theme_after_reply_form_subscription', 'bpbbpst_after_reply_form_subscription', 10 ); 
  112.  
  113. // Maybe save the Support status when a reply to a support topic is posted 
  114. add_action( 'bbp_new_reply_post_extras', 'bpbbpst_reply_save_support_type', 10, 1 ); 
  115.  
  116. // sends a notification in case of new support topic for the forum that enabled support feature 
  117. add_action( 'bbp_new_topic', 'bpbbpst_new_support_topic_notify', 10, 4 ); 
  118.  
  119. // updating the support type on front end edit topic form submission 
  120. add_action( 'bbp_edit_topic_post_extras', 'bpbbpst_edit_support_type', 10, 1 ); 
  121.  
  122. // moving a topic needs to adapt with the support settings of the new forum 
  123. add_action( 'bbp_edit_topic', 'bpbbpst_handle_moving_topic', 9, 2 ); 
  124.  
  125. //enqueueing scripts 
  126. add_action( 'bbp_enqueue_scripts', 'bpbbpst_enqueue_scripts' ); 
  127.  
  128. // catching ajax status changes 
  129. add_action( 'wp_ajax_bbp_change_support_status', 'bpbbpst_change_support_status' ); 
  130.  
  131. // adding support mention before topic titles in loops 
  132. add_action( 'bbp_theme_before_topic_title', 'bpbbpst_add_support_mention' ); 
  133.  
  134. // Waits a bit to filter the topic title to let plugin play with get_the_title() 
  135. add_action( 'bbp_head', 'bpbbpst_filter_topic_title', 999 ); 
  136.  
  137. // For Bpbbpst_Support_New_Support widget usage (adds a referer field) 
  138. add_action( 'bpbbpst_output_support_extra_field', 'bpbbpst_referer_extra_field', 10, 1 ); 
  139. add_action( 'bbp_theme_before_reply_content', 'bpbbpst_display_referer_to_moderators' ); 
  140.  
  141. // Register the widgets 
  142. add_action( 'bbp_widgets_init', array( 'Bpbbpst_Support_Stats', 'register_widget' ), 10 ); 
  143. add_action( 'bbp_widgets_init', array( 'Bpbbpst_Support_New_Support', 'register_widget' ), 10 ); 
  144.  
  145. // Neutralize title filter in Sidebar 
  146. add_action( 'dynamic_sidebar_before', 'bpbbpst_set_sidebar_true' ); 
  147. add_action( 'dynamic_sidebar_after', 'bpbbpst_set_sidebar_false' ); 
  148.  
  149. do_action_ref_array( 'bpbbpst_after_setup_actions', array( &$this ) ); 
  150.  
  151. /** 
  152. * Registers the available support status 
  153. * @since 2.0 
  154. * @uses apply_filters() call 'bpbbpst_available_support_status' to add/remove/edit support status 
  155. */ 
  156. public function setup_status() { 
  157. // Available support status 
  158. $this->support_status = apply_filters( 'bpbbpst_available_support_status', array( 
  159. 'topic-not-resolved' => array( 
  160. 'sb-caption' => __( 'Not resolved', 'buddy-bbpress-support-topic' ),  
  161. 'value' => 1,  
  162. 'prefix-title' => __( '[Support request] ', 'buddy-bbpress-support-topic' ),  
  163. 'admin_class' => 'waiting',  
  164. 'dashicon' => array( 'class' => 'bpbbpst-dashicon-no', 'content' => '"\f158"' ),  
  165. ),  
  166. 'topic-resolved' => array( 
  167. 'sb-caption' => __( 'Resolved', 'buddy-bbpress-support-topic' ),  
  168. 'value' => 2,  
  169. 'prefix-title' => __( '[Resolved] ', 'buddy-bbpress-support-topic' ),  
  170. 'admin_class' => 'approved',  
  171. 'dashicon' => array( 'class' => 'bpbbpst-dashicon-yes', 'content' => '"\f147"' ),  
  172. ),  
  173. 'topic-not-support' => array( 
  174. 'sb-caption' => __( 'Not a support topic', 'buddy-bbpress-support-topic' ),  
  175. 'value' => 0,  
  176. 'prefix-title' => '',  
  177. 'admin_class' => 'waiting',  
  178. ),  
  179. )); 
  180.  
  181. /** 
  182. * Registers key filters to extend bbPress 
  183. * @since 2.0 
  184. * @access private 
  185. * @uses add_filter() to filter bbPress at key points 
  186. */ 
  187. private function setup_filters() { 
  188. if ( ! $this->globals->site_bbp_version_ok ) { 
  189. return; 
  190.  
  191. // removes the title filter 
  192. add_filter( 'bbp_get_template_part', 'bpbbpst_topic_is_single', 99, 3 ); 
  193.  
  194. // Displays the support status selectbox in topic front admin links 
  195. add_filter( 'bbp_get_topic_admin_links', 'bpbbpst_support_admin_links', 10, 2 ); 
  196.  
  197. // in case a forum is set as a support only one strip the not a support question status 
  198. add_filter( 'bpbbpst_get_support_status', 'bpbbpst_neutralize_not_support', 1, 1 ); 
  199.  
  200. // For Bpbbpst_Support_New_Support widget usage (forces the user to subscribe to replies) 
  201. add_filter( 'bbp_get_form_topic_subscribed', 'bpbbpst_referer_topic_subscribed', 10, 2 ); 
  202.  
  203. // Use a specific topic template for support only forums 
  204. add_filter( 'bbp_get_form_topic_content', 'bpbbpst_support_topic_template', 100, 1 ); 
  205.  
  206. /** 
  207. * Loads the translation files 
  208. * @since 2.0 
  209. * @uses apply_filters() to let plugins or themes override values 
  210. * @uses get_locale() to get the language of WordPress config 
  211. * @uses load_texdomain() to load the translation at specific places 
  212. * @uses load_plugin_textdomain() to load the translation at regular places 
  213. */ 
  214. public function load_textdomain() { 
  215. // Traditional WordPress plugin locale filter 
  216. $locale = apply_filters( 'plugin_locale', get_locale(), $this->globals->domain ); 
  217.  
  218. // Need custom strings for en_US ? 
  219. if ( empty( $locale ) ) { 
  220. $mofile = $this->globals->domain . '.mo'; 
  221. } else { 
  222. $mofile = sprintf( '%1$s-%2$s.mo', $this->globals->domain, $locale ); 
  223.  
  224. // Setup paths to current locale file 
  225. $mofile_local = trailingslashit( $this->globals->plugin_dir . 'languages' ) . $mofile; 
  226. $mofile_global = WP_LANG_DIR . '/' . $this->globals->domain . '/' . $mofile; 
  227.  
  228. // Look in global /wp-content/languages/buddy-bbpress-support-topics folder 
  229. load_textdomain( $this->globals->domain, $mofile_global ); 
  230.  
  231. // Look in local /wp-content/plugins/buddy-bbpress-support-topics/languages/ folder 
  232. load_textdomain( $this->globals->domain, $mofile_local ); 
  233.  
  234. // Look in global /wp-content/languages/plugins/ 
  235. load_plugin_textdomain( $this->globals->domain );