BP_bbP_ST_Admin

Loads Buddy-bbPress Support Topic plugin admin area.

Defined (1)

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

/includes/admin.php  
  1. class BP_bbP_ST_Admin { 
  2.  
  3. /** 
  4. * The admin loader 
  5. * @since 2.0 
  6. * @uses BP_bbP_ST_Admin::setup_actions() to add some key hooks 
  7. * @uses BP_bbP_ST_Admin::maybe_activate() to eventually load the welcome screen 
  8. */ 
  9. public function __construct() { 
  10. $this->setup_actions(); 
  11. $this->maybe_activate(); 
  12.  
  13. /** 
  14. * Setup the admin hooks, actions and filters 
  15. * @since 2.0 
  16. * @access private 
  17. * @uses bbp_is_deactivation() to prevent interfering with bbPress deactivation process 
  18. * @uses bbp_is_activation() to prevent interfering with bbPress activation process 
  19. * @uses add_action() To add various actions 
  20. * @uses add_filter() To add various filters 
  21. * @uses bpbbpst_is_bbp_required_version_ok() to check if bbPress required version is ok 
  22. */ 
  23. private function setup_actions() { 
  24.  
  25. if ( bbp_is_deactivation() || bbp_is_activation() ) { 
  26. return; 
  27.  
  28. // Welcome Screen 
  29. add_action( 'bbp_admin_menu', array( $this, 'welcome_screen_register' ) ); 
  30. add_action( 'bbp_admin_head', array( $this, 'welcome_screen_css' ) ); 
  31. add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); 
  32.  
  33. // Bail if bbPress required version doesn't match our need 
  34. if ( ! bpbbpst_is_bbp_required_version_ok() ) { 
  35. add_action( 'bbp_admin_notices', array( $this, 'admin_notices' ) ); 
  36. return; 
  37.  
  38. // forums metabox 
  39. add_action( 'bbp_forum_attributes_metabox', array( $this, 'forum_meta_box_register' ), 10 ); 
  40. add_action( 'bbp_forum_attributes_metabox_save', array( $this, 'forum_meta_box_save' ), 10, 1 ); 
  41.  
  42. // Action to edit users query to only get forum moderators ( Keymasters+moderators ) 
  43. add_action( 'pre_get_users', array( $this, 'filter_user_query' ), 10, 1 ); 
  44.  
  45. // enqueues a js script to hide show recipients 
  46. add_action( 'load-post.php', array( $this, 'enqueue_forum_js' ) ); 
  47. add_action( 'load-post-new.php', array( $this, 'enqueue_forum_js' ) ); 
  48.  
  49. // topics metabox 
  50. add_action( 'bbp_topic_metabox', array( $this, 'topic_meta_box' ), 10, 1 ); 
  51. add_action( 'bbp_topic_attributes_metabox_save', array( $this, 'topic_meta_box_save' ), 10, 2 ); 
  52.  
  53. // moving a topic from the admin 
  54. add_action( 'save_post', array( $this, 'topic_moved' ), 9, 2 ); 
  55.  
  56. // topics list columns 
  57. add_filter( 'bbp_admin_topics_column_headers', array( $this, 'topics_admin_column' ), 10, 1 ); 
  58. add_action( 'bbp_admin_topics_column_data', array( $this, 'topics_column_data' ), 10, 2 ); 
  59.  
  60. // topics list filter by support status 
  61. add_action( 'restrict_manage_posts', array( $this, 'topics_admin_support_filter' ), 11 ); 
  62. add_filter( 'bbp_request', array( $this, 'topics_admin_support_request' ), 11, 1 ); 
  63.  
  64. // topics bulk edit 
  65. add_action( 'bulk_edit_custom_box', array( $this, 'bulk_topics_support' ), 10, 2 ); 
  66. add_action( 'load-edit.php', array( $this, 'bulk_update_support' ) ); 
  67.  
  68. // Dashboard right now bbPress widget 
  69. add_action( 'bbp_dashboard_widget_right_now_table_end', array( $this, 'dashboard_widget' ) ); 
  70.  
  71. // At a glance Dashboard widget 
  72. add_action( 'bbp_dashboard_at_a_glance', array( $this, 'dashboard_at_a_glance' ), 10, 2 ); 
  73.  
  74. /** 
  75. * Display a notice to give the admin some feedback 
  76. * @since 2.0 
  77. * @uses bpbbpst_get_plugin_version() to get plugin's version 
  78. * @uses bpbbpst_bbp_required_version() to get bbPress required version 
  79. * @return string HTML output 
  80. */ 
  81. public function admin_notices() { 
  82. ?> 
  83. <div id="message" class="error fade"> 
  84. <p><?php printf( esc_html__( 'Version %s of Buddy-bbPress Support Topic requires version %s of bbPress to be activated. Please upgrade bbPress.', 'buddy-bbpress-support-topic' ), bpbbpst_get_plugin_version(), bpbbpst_bbp_required_version() ); ?></p> 
  85. </div> 
  86. <?php 
  87.  
  88. /** 
  89. * Registers a new metabox in Forum's edit form (admin) 
  90. * @since 2.0 
  91. * @global $post_ID 
  92. * @uses bbp_is_forum_category() to check if the forum is a category 
  93. * @uses add_meta_box() to add the metabox to forum edit screen 
  94. * @uses bbp_get_forum_post_type() to get forum post type 
  95. */ 
  96. public function forum_meta_box_register() { 
  97. global $post_ID; 
  98.  
  99. if ( bbp_is_forum_category( $post_ID ) ) { 
  100. return; 
  101.  
  102. add_meta_box ( 
  103. 'bpbbpst_forum_settings',  
  104. __( 'Support settings', 'buddy-bbpress-support-topic' ),  
  105. array( &$this, 'forum_meta_box_display' ),  
  106. bbp_get_forum_post_type(),  
  107. 'normal',  
  108. 'low' 
  109. ); 
  110.  
  111.  
  112. /** 
  113. * Displays the content for the metabox 
  114. * @since 2.0 
  115. * @param object $forum the forum object 
  116. * @uses bpbbpst_get_forum_support_setting() to get forum support setting 
  117. * @uses bpbbpst_display_forum_setting_options() to list the available support settings 
  118. * @uses bpbbpst_checklist_moderators() to list the bbPress keymasters and moderators 
  119. * @uses do_action_ref_array() call 'bpbbpst_forum_support_options' to add your custom forum support settings 
  120. */ 
  121. public function forum_meta_box_display( $forum = false ) { 
  122. if ( empty( $forum->ID ) ) { 
  123. return; 
  124.  
  125. $support_feature = bpbbpst_get_forum_support_setting( $forum->ID ); 
  126.  
  127. $mailing_list_style = ''; 
  128. if ( 3 === (int) $support_feature ) { 
  129. $mailing_list_style = 'style="display:none"'; 
  130.  
  131. $support_only_style = 'style="display:none"'; 
  132.  
  133. if ( 2 === (int) $support_feature ) { 
  134. $support_only_style = ''; 
  135.  
  136. bpbbpst_display_forum_setting_options( $support_feature ); 
  137. ?> 
  138. <div class="bpbbpst-mailing-list" <?php echo $mailing_list_style;?>> 
  139. <h4><?php _e( 'Who should receive an email notification when a new support topic is posted ?', 'buddy-bbpress-support-topic' );?></h4> 
  140.  
  141. <?php bpbbpst_checklist_moderators( $forum->ID );?> 
  142. </div> 
  143.  
  144. <?php do_action_ref_array( 'bpbbpst_forum_support_options', array( $forum->ID, $mailing_list_style ) ); ?> 
  145.  
  146. <div class="bpbbpst-support-guides" <?php echo $support_only_style;?>> 
  147. <h4><?php _e( 'New Topic form extras', 'buddy-bbpress-support-topic' );?></h4> 
  148. <label class="screen-reader-text" for="support-topic-intro"><?php esc_html_e( 'New Topic Guide', 'buddy-bbpress-support-topic' ); ?></label> 
  149. <textarea rows="3" cols="40" name="_bpbbpst_support_topic[intro]" id="support-topic-intro" style="width:100%"><?php echo bpbbpst_get_forum_support_topic_intro( $forum->ID );?></textarea> 
  150. <p class="description"><?php printf( esc_html__( 'Use this field to insert some instructions above the new topic form. Allowed tags are: %s', 'buddy-bbpress-support-topic' ), join( ', ', array_keys( (array) wp_kses_allowed_html( 'forum' ) ) ) ); ?></p> 
  151.  
  152. <label class="screen-reader-text" for="support-topic-tpl"><?php esc_html_e( 'New Topic Template', 'buddy-bbpress-support-topic' ); ?></label> 
  153. <textarea rows="3" cols="40" name="_bpbbpst_support_topic[tpl]" id="support-topic-tpl" style="width:100%"><?php echo bpbbpst_get_forum_support_topic_template( $forum->ID );?></textarea> 
  154. <p class="description"><?php esc_html_e( 'The text added within this field will be used as a template for the content of new topics.', 'buddy-bbpress-support-topic' ); ?></p> 
  155. </div> 
  156. <?php 
  157.  
  158. do_action_ref_array( 'bpbbpst_forum_support_options_after_guides', array( $forum->ID, $support_only_style ) ); 
  159.  
  160. /** 
  161. * Saves the forum metabox datas 
  162. * @since 2.0 
  163. * @param integer $forum_id the forum id 
  164. * @uses bbp_is_forum_category() to check if forum is a category 
  165. * @uses update_post_meta() to save the forum support setting 
  166. * @uses delete_post_meta() to eventually delete a setting if needed 
  167. * @uses do_action() call 'bpbbpst_forum_settings_updated' to save your custom forum support settings 
  168. * @return integer the forum id 
  169. */ 
  170. public function forum_meta_box_save( $forum_id = 0 ) { 
  171. $support_feature = false; 
  172. $is_forum_category = bbp_is_forum_category( $forum_id ); 
  173.  
  174. if ( ! empty( $_POST['_bpbbpst_forum_settings'] ) ) { 
  175. $support_feature = absint( $_POST['_bpbbpst_forum_settings'] ); 
  176.  
  177. // Forum is not a category, save the support metas 
  178. if ( ! empty( $support_feature ) && ! $is_forum_category ) { 
  179. update_post_meta( $forum_id, '_bpbbpst_forum_settings', $support_feature ); 
  180.  
  181. if ( 3 === (int) $support_feature ) { 
  182. delete_post_meta( $forum_id, '_bpbbpst_support_recipients' ); 
  183. delete_post_meta( $forum_id, '_bpbbpst_support_topic_intro' ); 
  184. delete_post_meta( $forum_id, '_bpbbpst_support_topic_tpl' ); 
  185. } else { 
  186. $recipients = ! empty( $_POST['_bpbbpst_support_recipients'] ) ? array_map( 'intval', $_POST['_bpbbpst_support_recipients'] ) : false ; 
  187.  
  188. if ( ! empty( $recipients ) && is_array( $recipients ) && count( $recipients ) > 0 ) { 
  189. update_post_meta( $forum_id, '_bpbbpst_support_recipients', $recipients ); 
  190. } else { 
  191. delete_post_meta( $forum_id, '_bpbbpst_support_recipients' ); 
  192.  
  193. if ( 2 === (int) $support_feature ) { 
  194. if ( ! empty( $_POST['_bpbbpst_support_topic']['intro'] ) ) { 
  195. update_post_meta( $forum_id, '_bpbbpst_support_topic_intro', wp_unslash( $_POST['_bpbbpst_support_topic']['intro'] ) ); 
  196. } else { 
  197. delete_post_meta( $forum_id, '_bpbbpst_support_topic_intro' ); 
  198.  
  199. if ( ! empty( $_POST['_bpbbpst_support_topic']['tpl'] ) ) { 
  200. update_post_meta( $forum_id, '_bpbbpst_support_topic_tpl', wp_unslash( $_POST['_bpbbpst_support_topic']['tpl'] ) ); 
  201. } else { 
  202. delete_post_meta( $forum_id, '_bpbbpst_support_topic_tpl' ); 
  203. } else if ( ! empty( $_POST['_bpbbpst_support_topic'] ) ) { 
  204. delete_post_meta( $forum_id, '_bpbbpst_support_topic_intro' ); 
  205. delete_post_meta( $forum_id, '_bpbbpst_support_topic_tpl' ); 
  206.  
  207. do_action( 'bpbbpst_forum_settings_updated', $forum_id, $support_feature ); 
  208.  
  209. // Check for support metas to eventually remove them 
  210. } else if ( $is_forum_category ) { 
  211. $support_feature = get_post_meta( $forum_id, '_bpbbpst_forum_settings', true ); 
  212.  
  213. if ( ! empty( $support_feature ) ) { 
  214. delete_post_meta( $forum_id, '_bpbbpst_forum_settings' ); 
  215. delete_post_meta( $forum_id, '_bpbbpst_support_recipients' ); 
  216. delete_post_meta( $forum_id, '_bpbbpst_support_topic_intro' ); 
  217. delete_post_meta( $forum_id, '_bpbbpst_support_topic_tpl' ); 
  218.  
  219. return $forum_id; 
  220.  
  221. /** 
  222. * Adds a js to WordPress scripts queue 
  223. * @since 2.0 
  224. * @uses get_current_screen() to be sure we are in forum post screen 
  225. * @uses bbp_get_forum_post_type() to get the forum post type 
  226. * @uses wp_enqueue_script() to add the js to WordPress queue 
  227. * @uses bpbbpst_get_plugin_url() to build the path to plugin's js folder 
  228. * @uses bpbbpst_get_plugin_version() to get plugin's version 
  229. */ 
  230. public function enqueue_forum_js() { 
  231.  
  232. if ( ! isset( get_current_screen()->post_type ) || ( bbp_get_forum_post_type() != get_current_screen()->post_type ) ) { 
  233. return; 
  234.  
  235. wp_enqueue_script( 'bpbbpst-forum-js', bpbbpst_get_plugin_url( 'js' ) . 'bpbbpst-forum.js', array( 'jquery' ), bpbbpst_get_plugin_version(), true ); 
  236.  
  237. /** 
  238. * Hooks pre_get_users to build a cutom meta_query to list forum moderators 
  239. * First checks for who arguments to be sure we're requesting forum moderators 
  240. * @since 2.0 
  241. * @global object $wpdb (the database class) 
  242. * @global integer the current blog id 
  243. * @param object $query the user query arguments 
  244. * @uses bbp_get_keymaster_role() to get keymaster role 
  245. * @uses bbp_get_moderator_role() to get moderator role 
  246. */ 
  247. public function filter_user_query( $query = false ) { 
  248. global $wpdb; 
  249.  
  250. if ( empty( $query->query_vars['who'] ) || 'bpbbpst_moderators' != $query->query_vars['who'] ) { 
  251. return; 
  252.  
  253. $unset = array_fill_keys( array( 
  254. 'who',  
  255. 'blog_id', // to avoid the extra meta query in multisite 
  256. 'meta_key', // to make sure no primary meta query is set 
  257. 'meta_value', // to make sure no primary meta query is set 
  258. 'meta_compare' // to make sure no primary meta query is set 
  259. ), false ); 
  260.  
  261. // Unset the query vars before adding our meta query one 
  262. $query->query_vars = array_diff_key( $query->query_vars, $unset ); 
  263.  
  264. // Set current blog 
  265. $blog_id = get_current_blog_id(); 
  266.  
  267. // Set meta key 
  268. $meta_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; 
  269.  
  270. // Set meta query 
  271. $query->query_vars['meta_query'] = array( 
  272. 'relation' => 'OR',  
  273. array( 
  274. 'key' => $meta_key,  
  275. 'value' => bbp_get_keymaster_role(),  
  276. 'compare' => 'LIKE' 
  277. ),  
  278. array( 
  279. 'key' => $meta_key,  
  280. 'value' => bbp_get_moderator_role(),  
  281. 'compare' => 'LIKE' 
  282. ),  
  283. ); 
  284.  
  285. /** 
  286. * Adds a selectbox to update the support status to topic attributes metabox 
  287. * @since 2.0 
  288. * @param integer $topic_id the topic id 
  289. * @uses bbp_get_topic_forum_id() to get the parent forum id 
  290. * @uses bpbbpst_get_forum_support_setting() to get the support setting of the parent forum 
  291. * @uses get_post_meta() to get the previuosly stored topic support status 
  292. * @uses bpbbpst_get_selectbox() to build the support status selectbox 
  293. */ 
  294. public function topic_meta_box( $topic_id = 0 ) { 
  295. // Since 2.0, we first need to check parent forum has support for support :) 
  296. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  297.  
  298. if ( empty( $forum_id ) ) { 
  299. return false; 
  300.  
  301. if ( 3 == bpbbpst_get_forum_support_setting( $forum_id ) ) { 
  302. return false; 
  303.  
  304. $support_status = get_post_meta( $topic_id, '_bpbbpst_support_topic', true ); 
  305.  
  306. if ( empty( $support_status ) ) { 
  307. $support_status = 0; 
  308. ?> 
  309. <p> 
  310. <strong class="label"><?php _e( 'Support:', 'buddy-bbpress-support-topic' ); ?></strong> 
  311. <label class="screen-reader-text" for="parent_id"><?php _e( 'Support', 'buddy-bbpress-support-topic' ); ?></label> 
  312. <?php echo bpbbpst_get_selectbox( $support_status, $topic_id);?> 
  313. </p> 
  314. <?php 
  315.  
  316. /** 
  317. * Saves support status for the topic (admin) 
  318. * @since 2.0 
  319. * @param integer $topic_id the topic id 
  320. * @param integer $forum_id the parent forum id 
  321. * @uses wp_verify_nonce() for security reason 
  322. * @uses delete_post_meta() to eventually delete the support status 
  323. * @uses update_post_meta() to save the support status 
  324. * @uses do_action() call 'bpbbpst_topic_meta_box_save' to perform custom actions for the topic support 
  325. * @return integer the topic id 
  326. */ 
  327. public function topic_meta_box_save( $topic_id = 0, $forum_id = 0 ) { 
  328.  
  329. if ( ! isset( $_POST['_support_status'] ) || $_POST['_support_status'] === false ) { 
  330. return $topic_id; 
  331.  
  332. $new_status = intval( $_POST['_support_status'] ); 
  333.  
  334. if ( $new_status !== false && ! empty( $_POST['_wpnonce_bpbbpst_support_status'] ) && wp_verify_nonce( $_POST['_wpnonce_bpbbpst_support_status'], 'bpbbpst_support_status') ) { 
  335.  
  336. if ( empty( $new_status ) ) { 
  337. delete_post_meta( $topic_id, '_bpbbpst_support_topic' ); 
  338. } else { 
  339. update_post_meta( $topic_id, '_bpbbpst_support_topic', $new_status ); 
  340.  
  341. do_action( 'bpbbpst_topic_meta_box_save', $new_status ); 
  342.  
  343.  
  344. return $topic_id; 
  345.  
  346. /** 
  347. * Handles the support status in case a topic moved to another forum (admin) 
  348. * In case a topic moves to another forum, we need to check the new parent forum 
  349. * support setting to eventually delete the support status or create it. 
  350. * @since 2.0 
  351. * @param integer $topic_id the topic id 
  352. * @param object $topic the topic object 
  353. * @uses get_current_screen() to make sure we're editing a topic from admin 
  354. * @uses bbp_get_topic_post_type() to get topic post type 
  355. * @uses bbp_is_post_request() to make sure we're playing with a post request 
  356. * @uses wp_verify_nonce() for security reasons 
  357. * @uses current_user_can() to check for current user's capability 
  358. * @uses bpbbpst_handle_moving_topic() to handle topic move 
  359. */ 
  360. public function topic_moved( $topic_id = 0, $topic = false ) { 
  361. if ( ! isset( get_current_screen()->post_type ) || ( bbp_get_topic_post_type() != get_current_screen()->post_type ) ) { 
  362. return $topic_id; 
  363.  
  364. // Bail if doing an autosave 
  365. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 
  366. return $topic_id; 
  367.  
  368. // Bail if not a post request 
  369. if ( ! bbp_is_post_request() ) { 
  370. return $topic_id; 
  371.  
  372. // Nonce check 
  373. if ( empty( $_POST['bbp_topic_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) { 
  374. return $topic_id; 
  375.  
  376. // Bail if current user cannot edit this topic 
  377. if ( !current_user_can( 'edit_topic', $topic_id ) ) { 
  378. return $topic_id; 
  379.  
  380. // Get the forum ID 
  381. $forum_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 
  382.  
  383. if ( empty( $forum_id ) ) { 
  384. return $topic_id; 
  385.  
  386. if ( $the_topic = wp_is_post_revision( $topic_id ) ) { 
  387. $topic_id = $the_topic; 
  388.  
  389. bpbbpst_handle_moving_topic( $topic_id, $forum_id ); 
  390.  
  391. /** 
  392. * Registers a new column to topics admin list to show support status 
  393. * @since 2.0 
  394. * @param array $columns the registered columns 
  395. * @return array the columns with the support one 
  396. */ 
  397. public function topics_admin_column( $columns = array() ) { 
  398. $columns['buddy_bbp_st_support'] = __( 'Support', 'buddy-bbpress-support-topic' ); 
  399.  
  400. return $columns; 
  401.  
  402. /** 
  403. * Displays the support status of each topic row 
  404. * @since 2.0 
  405. * @param string $column the column id 
  406. * @param integer $topic_id the topic id 
  407. * @uses bpbbpst_add_support_mention() to output the topic support status 
  408. */ 
  409. public function topics_column_data( $column = '', $topic_id = 0 ) { 
  410. if ( $column == 'buddy_bbp_st_support' && ! empty( $topic_id ) ) { 
  411. bpbbpst_add_support_mention( $topic_id ); 
  412.  
  413. /** 
  414. * Adds a selectbox to allow filtering topics by status (admin) 
  415. * @since 2.0 
  416. * @uses get_current_screen() to be sure we're on topic admin list 
  417. * @uses bbp_get_topic_post_type() to get topic post type 
  418. * @uses bpbbpst_get_selectbox() to output the support status selectbox 
  419. */ 
  420. public function topics_admin_support_filter() { 
  421. if ( get_current_screen()->post_type == bbp_get_topic_post_type() ) { 
  422.  
  423. $selected = empty( $_GET['_support_status'] ) ? -1 : intval( $_GET['_support_status'] ); 
  424. //displays the selectbox to filter by support status 
  425. echo bpbbpst_get_selectbox( $selected , 'adminlist' ); 
  426.  
  427. /** 
  428. * Filters bbPress query to include a support status meta query 
  429. * @since 2.0 
  430. * @param array $query_vars the bbPress query vars 
  431. * @uses is_admin() to check we're in WordPress backend 
  432. * @return array the query vars with a support meta query 
  433. */ 
  434. public function topics_admin_support_request( $query_vars = array() ) { 
  435. if ( ! is_admin() ) { 
  436. return $query_vars; 
  437.  
  438. if ( empty( $_GET['_support_status'] ) ) { 
  439. return $query_vars; 
  440.  
  441. $support_status = intval( $_GET['_support_status'] ); 
  442.  
  443. if ( ! empty( $query_vars['meta_key'] ) ) { 
  444.  
  445. if ( $support_status == -1 ) { 
  446. return $query_vars; 
  447.  
  448. unset( $query_vars['meta_value'], $query_vars['meta_key'] ); 
  449.  
  450. $query_vars['meta_query'] = array( 
  451. array( 
  452. 'key' => '_bpbbpst_support_topic',  
  453. 'value' => $support_status,  
  454. 'compare' => '=' 
  455. ),  
  456. array( 
  457. 'key' => '_bbp_forum_id',  
  458. 'value' => intval( $_GET['bbp_forum_id'] ),  
  459. 'compare' => '=' 
  460. ); 
  461.  
  462. } else { 
  463.  
  464. if ( $support_status == -1 ) { 
  465. return $query_vars; 
  466.  
  467. $query_vars['meta_key'] = '_bpbbpst_support_topic'; 
  468. $query_vars['meta_value'] = $support_status; 
  469.  
  470.  
  471. return $query_vars; 
  472.  
  473. /** 
  474. * Adds an inline edit part to topics row to allow support bulk edit 
  475. * @since 2.0 
  476. * @param string $column_name the colum name id 
  477. * @param string $post_type the post type id 
  478. * @uses bpbbpst_get_support_status() to get available support statuses 
  479. * @return string html output 
  480. */ 
  481. public function bulk_topics_support( $column_name = '', $post_type = '' ) { 
  482. if ( $column_name != 'buddy_bbp_st_support' ) { 
  483. return; 
  484.  
  485. $all_status = bpbbpst_get_support_status(); 
  486.  
  487. if ( empty( $all_status ) || ! is_array( $all_status ) ) { 
  488. return; 
  489. ?> 
  490. <fieldset class="inline-edit-col-right"> 
  491. <div class="inline-edit-col"> 
  492. <div class="inline-edit-group"> 
  493. <label class="alignleft"> 
  494. <span class="title"><?php _e( 'Support' ); ?></span> 
  495. <select name="_support_status"> 
  496. <?php foreach ( $all_status as $status ) : ?> 
  497. <option value="<?php echo $status['value'];?>"><?php echo $status['sb-caption']; ?></option> 
  498. <?php endforeach ; ?> 
  499. </select> 
  500. </label> 
  501. </div> 
  502. </div> 
  503. </fieldset> 
  504. <?php 
  505.  
  506. /** 
  507. * Bulk update support statuses for selected topics 
  508. * @since 2.0 
  509. * @uses wp_parse_id_list() to sanitize list of topic ids 
  510. * @uses bbp_get_topic_forum_id() to get the forum parent id 
  511. * @uses bpbbpst_get_forum_support_setting() to get forum parent support setting 
  512. * @uses update_post_meta() to update the support statuses for selected topic ids 
  513. * @return boolean true 
  514. */ 
  515. public function bulk_update_support() { 
  516.  
  517. if ( ! isset( $_GET['bulk_edit'] ) ) { 
  518. return; 
  519.  
  520. if ( ! isset( $_GET['post_type'] ) || $_GET['post_type'] != bbp_get_topic_post_type() ) { 
  521. return; 
  522.  
  523. if ( ! isset( $_GET['_support_status'] ) ) { 
  524. return; 
  525.  
  526. if ( ! isset( $_GET['post'] ) ) { 
  527. return; 
  528.  
  529. $topic_ids = wp_parse_id_list( $_GET['post'] ); 
  530.  
  531. $support_status = intval( $_GET['_support_status'] ); 
  532.  
  533. foreach ( $topic_ids as $topic_id ) { 
  534. // we need to check the topic belongs to a support featured forum 
  535. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  536.  
  537. if ( empty( $forum_id ) || ( 3 == bpbbpst_get_forum_support_setting( $forum_id ) && 0 != $support_status ) ) { 
  538. continue; 
  539.  
  540. if ( 2 == bpbbpst_get_forum_support_setting( $forum_id ) && 0 == $support_status ) { 
  541. continue; 
  542.  
  543. update_post_meta( $topic_id, '_bpbbpst_support_topic', $support_status ); 
  544.  
  545. return true; 
  546.  
  547. /** 
  548. * Extends bbPress right now Dashboard widget to display support statistics 
  549. * bbPress Right now Dashboard widget seems to disappear in 2.6 
  550. * @since 2.0 
  551. * @uses bpbbpst_support_statistics() to build the support statistics 
  552. * @uses current_user_can() to check for current user's capability 
  553. * @uses add_query_arg() to build links to topic admin list filtered by support status 
  554. * @uses bbp_get_topic_post_type() to get the topic post type 
  555. * @uses get_admin_url() to get the admin url 
  556. * @return string html output 
  557. */ 
  558. public function dashboard_widget() { 
  559. $support_statistics = bpbbpst_support_statistics(); 
  560.  
  561. if ( empty( $support_statistics['total_support'] ) ) { 
  562. return false; 
  563.  
  564. $status_stats = $support_statistics['allstatus']; 
  565.  
  566. if ( ! is_array( $status_stats ) || count( $status_stats ) < 1 ) { 
  567. return false; 
  568.  
  569. ?> 
  570. <div class="table table_content" style="margin-top:40px"> 
  571. <p class="sub"><?php _e( 'Support topics', 'bbpress' ); ?></p> 
  572. <table> 
  573. <tr class="first"> 
  574.  
  575. <td class="first b b-topics"><span class="total-count"><?php echo $support_statistics['percent']; ?></span></td> 
  576. <td class="t topics"><?php _e( 'Resolved so far', 'buddy-bbpress-support-topic' ); ?></td> 
  577.  
  578. </tr> 
  579.  
  580. <?php foreach ( $status_stats as $key => $stat ) : ?> 
  581.  
  582. <tr class="first"> 
  583.  
  584. <?php 
  585. $num = $stat['stat']; 
  586. $text = $stat['label']; 
  587. $class = $stat['admin_class']; 
  588.  
  589. if ( current_user_can( 'publish_topics' ) ) { 
  590. $link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type(), '_support_status' => $key ), get_admin_url( null, 'edit.php' ) ); 
  591. $num = '<a href="' . $link . '" class="' . $class . '">' . $num . '</a>'; 
  592. $text = '<a href="' . $link . '" class="' . $class . '">' . $text . '</a>'; 
  593. ?> 
  594.  
  595. <td class="first b b-topic_tags"><?php echo $num; ?></td> 
  596. <td class="t topic_tags"><?php echo $text; ?></td> 
  597.  
  598. </tr> 
  599.  
  600. <?php endforeach ; ?> 
  601.  
  602. </table> 
  603.  
  604. </div> 
  605. <?php 
  606.  
  607. /** 
  608. * Register custom elements in the at a glance Dashboard Widget 
  609. * This is appearing in bbPress 2.6 
  610. * @since 2.0 
  611. * @param array $elements list of shortcut links 
  612. * @param array $stats bbPress stats 
  613. * @return array same elements with plugin's ones if needed 
  614. */ 
  615. public function dashboard_at_a_glance( $elements = array(), $stats = array() ) { 
  616. if ( empty( $elements ) || empty( $stats['topic_count'] ) ) { 
  617. return $elements; 
  618.  
  619. $support_statistics = bpbbpst_support_statistics(); 
  620.  
  621. if ( empty( $support_statistics['total_support'] ) ) { 
  622. return $elements; 
  623.  
  624. $status_stats = $support_statistics['allstatus']; 
  625.  
  626. if ( ! is_array( $status_stats ) || count( $status_stats ) < 1 ) { 
  627. return $elements; 
  628.  
  629. foreach ( (array) $status_stats as $key => $stat ) { 
  630. $link = add_query_arg( array( 'post_type' => bbp_get_topic_post_type(), '_support_status' => $key ), get_admin_url( null, 'edit.php' ) ); 
  631. $text = sprintf( '%d %s', $stat['stat'], $stat['label'] ); 
  632. $class = array( $stat['admin_class'] ); 
  633.  
  634. if ( ! empty( $stat['dashicon']['class'] ) ) { 
  635. $class[] = $stat['dashicon']['class']; 
  636.  
  637. $elements[] = '<a href="' . esc_url( $link ) . '" class="' . join( ' ', $class ) . '">' . esc_html( $text ) . '</a>'; 
  638.  
  639. return $elements; 
  640.  
  641. /** 
  642. * Check for welcome screen transient to eventually redirect admin to welcome screen 
  643. * @since 2.0 
  644. * @uses get_transient() to get the transient created on plugin's activation 
  645. * @uses delete_transient() to remove it 
  646. * @uses is_network_admin() to check for network admin area 
  647. * @uses wp_safe_redirect() to redirect admin to welcome screen 
  648. * @uses add_query_arg() to build the link to the welcome screen 
  649. * @uses admin_url() to get admin url 
  650. */ 
  651. public function maybe_activate() { 
  652.  
  653. if ( ! get_transient( '_bpbbst_welcome_screen' ) ) { 
  654. return; 
  655.  
  656. // Delete the redirect transient 
  657. delete_transient( '_bpbbst_welcome_screen' ); 
  658.  
  659. // Bail if activating from network, or bulk 
  660. if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { 
  661. return; 
  662.  
  663. wp_safe_redirect( add_query_arg( array( 'page' => 'bpbbst-about' ), admin_url( 'index.php' ) ) ); 
  664.  
  665. /** 
  666. * Adds a submenu to dashboard page to register the welcome screen 
  667. * @since 2.0 
  668. * @uses add_dashboard_page() to build the dashboard submenu 
  669. * @uses get_option() to get db version 
  670. * @uses bpbbpst_get_plugin_version() to get plugin's version 
  671. * @uses update_option() to eventually update db version 
  672. * @uses do_action() call 'bpbbpst_upgrade' to perform custom actions once the plugin has been upgraded 
  673. */ 
  674. public function welcome_screen_register() { 
  675.  
  676. $this->about_page = add_dashboard_page( 
  677. __( 'Welcome to Buddy-bbPress Support Topic', 'buddy-bbpress-support-topic' ),  
  678. __( 'Welcome to Buddy-bbPress Support Topic', 'buddy-bbpress-support-topic' ),  
  679. 'manage_options',  
  680. 'bpbbst-about',  
  681. array( &$this, 'welcome_screen_display' ) 
  682. ); 
  683.  
  684. // do not upgrade version if required is not ok 
  685. if ( ! bpbbpst_is_bbp_required_version_ok() ) { 
  686. return; 
  687.  
  688. $db_version = get_option( 'bp-bbp-st-version' ); 
  689. $plugin_version = bpbbpst_get_plugin_version(); 
  690.  
  691. if ( empty( $db_version ) || $plugin_version != $db_version ) { 
  692. update_option( 'bp-bbp-st-version', $plugin_version ); 
  693.  
  694. do_action( 'bpbbpst_upgrade', $plugin_version, $db_version ); 
  695.  
  696. /** 
  697. * Displays the welcome screen of the plugin 
  698. * @since 2.0 
  699. * @uses bpbbpst_get_plugin_version() to get plugin's version 
  700. * @uses bpbbpst_get_plugin_url() to get plugin's url 
  701. * @uses bpbbpst_bbp_required_version() to get bbPress required version 
  702. * @uses esc_url() to sanitize urls 
  703. * @uses admin_url() to build the admin url of welcome screen 
  704. * @uses add_query_arg() to add arguments to the admin url 
  705. * @return string html 
  706. */ 
  707. public function welcome_screen_display() { 
  708. $display_version = bpbbpst_get_plugin_version(); 
  709. $plugin_url = bpbbpst_get_plugin_url(); 
  710. $bbpress_required = sprintf( '<strong>bbPress %s</strong>', bpbbpst_bbp_required_version() ); 
  711. ?> 
  712. <div class="wrap about-wrap"> 
  713. <h1><?php printf( __( 'Buddy-bbPress Support Topic %s', 'buddy-bbpress-support-topic' ), $display_version ); ?></h1> 
  714.  
  715. <?php if ( ! bpbbpst_is_bbp_required_version_ok() ) :?> 
  716. <div class="about-text"><?php printf( esc_html__( 'Ouch! Buddy-bbPress Support Topic %s requires at least %s, see below why it might be a great idea to upgrade bbPress ;)', 'buddy-bbpress-support-topic' ), $display_version, $bbpress_required ); ?></div> 
  717. <?php else : ?> 
  718. <div class="about-text"><?php printf( esc_html__( 'Thank you for using the latest version of Buddy-bbPress Support Topic (%s). Support only forums got some nice improvements!', 'buddy-bbpress-support-topic' ), $display_version ); ?></div> 
  719. <?php endif; ?> 
  720.  
  721. <div class="bpbbpst-badge"> 
  722. <div class="badge"></div> 
  723. <div class="badge-text"><?php esc_html_e( 'Support', 'buddy-bbpress-support-topic' ); ?></div> 
  724. </div> 
  725.  
  726. <h2 class="nav-tab-wrapper wp-clearfix"> 
  727. <a class="nav-tab nav-tab-active" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bpbbst-about' ), 'index.php' ) ) ); ?>"> 
  728. <?php esc_html_e( 'What's New', 'buddy-bbpress-support-topic' ); ?> 
  729. </a> 
  730. </h2> 
  731.  
  732. <div class="headline-feature feature-section one-col"> 
  733. <h2><?php esc_html_e( 'Guidelines & support topic templates for your support only forums.', 'buddy-bbpress-support-topic' ); ?></h2> 
  734.  
  735. <div class="featured-image"> 
  736. <img src="https://cldup.com/0iNnnWZw5d.png" alt="<?php esc_attr_e( 'Guidelines and Support topic template', 'buddy-bbpress-support-topic' ); ?>"> 
  737. </div> 
  738.  
  739. <p><?php esc_html_e( 'Providing the right answer often requires to have all needed informations about an issue. Support only forums can now use some guidelines and/or a support topic template to help the user describe the issue the best way.', 'buddy-bbpress-support-topic' ); ?></p> 
  740. </div> 
  741.  
  742. <div class="feature-section two-col"> 
  743. <div class="col"> 
  744. <h3><?php esc_html_e( 'Guidelines', 'buddy-bbpress-support-topic' ); ?></h3> 
  745.  
  746. <p><?php esc_html_e( 'They are displayed before the topic form to let the user know about the specific rules to observe for the support forum he will post his topic into.', 'buddy-bbpress-support-topic' ); ?></p> 
  747.  
  748. <h3><?php esc_html_e( 'Support topic templates', 'buddy-bbpress-support-topic' ); ?></h3> 
  749.  
  750. <p><?php esc_html_e( 'Just like guidelines, each forum can include a specific topic template to display a checklist or some specific advices into the content area of the topic form.', 'buddy-bbpress-support-topic' ); ?></p> 
  751. </div> 
  752. <div class="col"> 
  753. <div class="media-container"> 
  754. <img src="https://cldup.com/3SOgj-v0ny.png" alt="<?php esc_attr_e( 'Guidelines and Support topic template inside the topic form', 'buddy-bbpress-support-topic' ); ?>"> 
  755. </div> 
  756. </div> 
  757. </div> 
  758.  
  759. <div class="clear"></div> 
  760.  
  761. <hr> 
  762.  
  763. <div class="feature-section two-col"> 
  764. <div class="col"> 
  765. <div class="media-container"> 
  766. <img src="https://cldup.com/3t2XlLbz1b.png" alt="<?php esc_attr_e( 'reply checkbox', 'buddy-bbpress-support-topic' ); ?>"> 
  767. </div> 
  768. </div> 
  769. <div class="col"> 
  770. <h3><?php esc_html_e( 'Mark this topic as resolved!', 'buddy-bbpress-support-topic' ); ?></h3> 
  771.  
  772. <p><?php esc_html_e( 'The reply to the topic you are about to post is fixing the issue? Great job, you can now directly mark the support topic as resolved by activating the corresponding checkbox.', 'buddy-bbpress-support-topic' ); ?></p> 
  773. </div> 
  774. </div> 
  775.  
  776. <div class="clear"></div> 
  777.  
  778. <hr> 
  779.  
  780. <h3 class="wp-people-group"><?php printf( esc_html__( 'Many thanks to %s contributors', 'buddy-bbpress-support-topic' ), $display_version ); ?></h3> 
  781.  
  782. <p class="wp-credits-list"> 
  783. <a href="https://profiles.wordpress.org/danieliser">danieliser</a>,  
  784. <a href="https://profiles.wordpress.org/imath">imath</a>. 
  785. </p> 
  786. <?php 
  787.  
  788. /** 
  789. * Outputs some css rules if on welcome screen or on dashboard (at a glance widget) 
  790. * @since 2.0 
  791. * @uses remove_submenu_page() to remove the page from dashoboard menu 
  792. * @uses bpbbpst_get_plugin_url() to get the plugin url 
  793. * @uses get_current_screen() to check current page is the welcome screen 
  794. * @uses bpbbpst_get_support_status() to get all available support status 
  795. * @uses sanitize_html_class() to sanitize the clases 
  796. * @uses sanitize_text_field() to sanitize the content 
  797. * @return string css rules 
  798. */ 
  799. public function welcome_screen_css() { 
  800. // Avoid a notice in network administration 
  801. if ( is_network_admin() ) { 
  802. return; 
  803.  
  804. remove_submenu_page( 'index.php', 'bpbbst-about'); 
  805.  
  806. if ( $this->about_page == get_current_screen()->id ) { 
  807. ?> 
  808. <style type="text/css" media="screen"> 
  809. /*<![CDATA[*/ 
  810.  
  811. .about-wrap .bpbbpst-badge .badge { 
  812. font: normal 150px/1 'dashicons' !important; 
  813. /* Better Font Rendering =========== */ 
  814. -webkit-font-smoothing: antialiased; 
  815. -moz-osx-font-smoothing: grayscale; 
  816.  
  817. color: #333; 
  818. display: inline-block; 
  819. content:''; 
  820.  
  821. .about-wrap .bpbbpst-badge .badge:before{ 
  822. content: "\f488"; 
  823.  
  824. .bpbbpst-badge { 
  825. background-color: #FFF; 
  826. width: 150px; 
  827. -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, .2); 
  828. box-shadow: 0 1px 3px rgba(0, 0, 0, .2); 
  829.  
  830. .bpbbpst-badge .badge-text { 
  831. color:#333; 
  832. font-size: 14px; 
  833. text-align: center; 
  834. font-weight: 600; 
  835. margin: 5px 0 0; 
  836. height: 30px; 
  837. text-rendering: optimizeLegibility; 
  838.  
  839. .about-wrap .bpbbpst-badge { 
  840. position: absolute; 
  841. top: 0; 
  842. right: 0; 
  843. body.rtl .about-wrap .bpbbpst-badge { 
  844. right: auto; 
  845. left: 0; 
  846.  
  847. /*]]>*/ 
  848. </style> 
  849. <?php 
  850. } else if ( 'dashboard' == get_current_screen()->id ) { 
  851. ?> 
  852. <style type="text/css" media="screen"> 
  853. /*<![CDATA[*/ 
  854.  
  855. <?php foreach ( (array) bpbbpst_get_support_status() as $status ) : ?> 
  856.  
  857. <?php if ( empty( $status['dashicon']['class'] ) || empty( $status['dashicon']['content'] ) ) : continue ; endif ;?> 
  858.  
  859. #dashboard_right_now a.<?php echo sanitize_html_class( $status['dashicon']['class'] ) ;?>:before { 
  860. content: <?php echo sanitize_text_field( $status['dashicon']['content'] ) ;?>; 
  861.  
  862. <?php endforeach ;?> 
  863.  
  864. /*]]>*/ 
  865. </style> 
  866. <?php 
  867.  
  868. /** 
  869. * Adds a custom link to the welcome screen in plugin's list for our row 
  870. * @since 2.0 
  871. * @param array $links the plugin links 
  872. * @param string $file the plugin in row 
  873. * @uses plugin_basename() to get plugin's basename 
  874. * @uses bbpress() to get bbPress main instance 
  875. * @uses add_query_arg() to build the url to our welcome screen 
  876. * @uses admin_url() to get admin url to dashoboard 
  877. * @uses esc_html__() to sanitize translated string 
  878. * @return array the plugin links 
  879. */ 
  880. public function modify_plugin_action_links( $links = array(), $file = '' ) { 
  881. // Do not touch to links in network admin 
  882. if ( is_network_admin() ) { 
  883. return $links; 
  884.  
  885. // Return normal links if not BuddyPress 
  886. if ( plugin_basename( bbpress()->extend->bpbbpst->globals->file ) != $file ) { 
  887. return $links; 
  888.  
  889. // Add a few links to the existing links array 
  890. return array_merge( $links, array( 
  891. 'about' => '<a href="' . add_query_arg( array( 'page' => 'bpbbst-about' ), admin_url( 'index.php' ) ) . '">' . esc_html__( 'About', 'buddy-bbpress-support-topic' ) . '</a>' 
  892. ) ); 
  893.  
  894.