BBP_Admin

Loads bbPress plugin admin area.

Defined (1)

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

/includes/admin/admin.php  
  1. class BBP_Admin { 
  2.  
  3. /** Directory *************************************************************/ 
  4.  
  5. /** 
  6. * @var string Path to the bbPress admin directory 
  7. */ 
  8. public $admin_dir = ''; 
  9.  
  10. /** URLs ******************************************************************/ 
  11.  
  12. /** 
  13. * @var string URL to the bbPress admin directory 
  14. */ 
  15. public $admin_url = ''; 
  16.  
  17. /** 
  18. * @var string URL to the bbPress images directory 
  19. */ 
  20. public $images_url = ''; 
  21.  
  22. /** 
  23. * @var string URL to the bbPress admin styles directory 
  24. */ 
  25. public $styles_url = ''; 
  26.  
  27. /** 
  28. * @var string URL to the bbPress admin css directory 
  29. */ 
  30. public $css_url = ''; 
  31.  
  32. /** 
  33. * @var string URL to the bbPress admin js directory 
  34. */ 
  35. public $js_url = ''; 
  36.  
  37. /** Capability ************************************************************/ 
  38.  
  39. /** 
  40. * @var bool Minimum capability to access Tools and Settings 
  41. */ 
  42. public $minimum_capability = 'keep_gate'; 
  43.  
  44. /** Separator *************************************************************/ 
  45.  
  46. /** 
  47. * @var bool Whether or not to add an extra top level menu separator 
  48. */ 
  49. public $show_separator = false; 
  50.  
  51. /** Functions *************************************************************/ 
  52.  
  53. /** 
  54. * The main bbPress admin loader 
  55. * @since bbPress (r2515) 
  56. * @uses BBP_Admin::setup_globals() Setup the globals needed 
  57. * @uses BBP_Admin::includes() Include the required files 
  58. * @uses BBP_Admin::setup_actions() Setup the hooks and actions 
  59. */ 
  60. public function __construct() { 
  61. $this->setup_globals(); 
  62. $this->includes(); 
  63. $this->setup_actions(); 
  64.  
  65. /** 
  66. * Admin globals 
  67. * @since bbPress (r2646) 
  68. * @access private 
  69. */ 
  70. private function setup_globals() { 
  71. $bbp = bbpress(); 
  72. $this->admin_dir = trailingslashit( $bbp->includes_dir . 'admin' ); // Admin path 
  73. $this->admin_url = trailingslashit( $bbp->includes_url . 'admin' ); // Admin url 
  74. $this->images_url = trailingslashit( $this->admin_url . 'images' ); // Admin images URL 
  75. $this->styles_url = trailingslashit( $this->admin_url . 'styles' ); // Admin styles URL 
  76. $this->css_url = trailingslashit( $this->admin_url . 'css' ); // Admin css URL 
  77. $this->js_url = trailingslashit( $this->admin_url . 'js' ); // Admin js URL 
  78.  
  79. /** 
  80. * Include required files 
  81. * @since bbPress (r2646) 
  82. * @access private 
  83. */ 
  84. private function includes() { 
  85. require( $this->admin_dir . 'tools.php' ); 
  86. require( $this->admin_dir . 'converter.php' ); 
  87. require( $this->admin_dir . 'settings.php' ); 
  88. require( $this->admin_dir . 'functions.php' ); 
  89. require( $this->admin_dir . 'metaboxes.php' ); 
  90. require( $this->admin_dir . 'forums.php' ); 
  91. require( $this->admin_dir . 'topics.php' ); 
  92. require( $this->admin_dir . 'replies.php' ); 
  93. require( $this->admin_dir . 'users.php' ); 
  94.  
  95. /** 
  96. * Setup the admin hooks, actions and filters 
  97. * @since bbPress (r2646) 
  98. * @access private 
  99. * @uses add_action() To add various actions 
  100. * @uses add_filter() To add various filters 
  101. */ 
  102. private function setup_actions() { 
  103.  
  104. // Bail to prevent interfering with the deactivation process 
  105. if ( bbp_is_deactivation() ) 
  106. return; 
  107.  
  108. /** General Actions ***************************************************/ 
  109.  
  110. add_action( 'bbp_admin_menu', array( $this, 'admin_menus' ) ); // Add menu item to settings menu 
  111. add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); // Add some general styling to the admin area 
  112. add_action( 'bbp_admin_notices', array( $this, 'activation_notice' ) ); // Add notice if not using a bbPress theme 
  113. add_action( 'bbp_register_admin_style', array( $this, 'register_admin_style' ) ); // Add green admin style 
  114. add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) ); // Add settings 
  115. add_action( 'bbp_activation', array( $this, 'new_install' ) ); // Add menu item to settings menu 
  116. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Add enqueued CSS 
  117. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Add enqueued JS 
  118. add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget_right_now' ) ); // Forums 'Right now' Dashboard widget 
  119. add_action( 'admin_bar_menu', array( $this, 'admin_bar_about_link' ), 15 ); // Add a link to bbPress about page to the admin bar 
  120.  
  121. /** Ajax **************************************************************/ 
  122.  
  123. // No _nopriv_ equivalent - users must be logged in 
  124. add_action( 'wp_ajax_bbp_suggest_topic', array( $this, 'suggest_topic' ) ); 
  125. add_action( 'wp_ajax_bbp_suggest_user', array( $this, 'suggest_user' ) ); 
  126.  
  127. /** Filters ***********************************************************/ 
  128.  
  129. // Modify bbPress's admin links 
  130. add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 ); 
  131.  
  132. // Map settings capabilities 
  133. add_filter( 'bbp_map_meta_caps', array( $this, 'map_settings_meta_caps' ), 10, 4 ); 
  134.  
  135. // Hide the theme compat package selection 
  136. add_filter( 'bbp_admin_get_settings_sections', array( $this, 'hide_theme_compat_packages' ) ); 
  137.  
  138. // Allow keymasters to save forums settings 
  139. add_filter( 'option_page_capability_bbpress', array( $this, 'option_page_capability_bbpress' ) ); 
  140.  
  141. /** Network Admin *****************************************************/ 
  142.  
  143. // Add menu item to settings menu 
  144. add_action( 'network_admin_menu', array( $this, 'network_admin_menus' ) ); 
  145.  
  146. /** Dependencies ******************************************************/ 
  147.  
  148. // Allow plugins to modify these actions 
  149. do_action_ref_array( 'bbp_admin_loaded', array( &$this ) ); 
  150.  
  151. /** 
  152. * Add the admin menus 
  153. * @since bbPress (r2646) 
  154. * @uses add_management_page() To add the Recount page in Tools section 
  155. * @uses add_options_page() To add the Forums settings page in Settings 
  156. * section 
  157. */ 
  158. public function admin_menus() { 
  159.  
  160. $hooks = array(); 
  161.  
  162. // These are later removed in admin_head 
  163. if ( current_user_can( 'bbp_tools_page' ) ) { 
  164. if ( current_user_can( 'bbp_tools_repair_page' ) ) { 
  165. $hooks[] = add_management_page( 
  166. __( 'Repair Forums', 'bbpress' ),  
  167. __( 'Forum Repair', 'bbpress' ),  
  168. $this->minimum_capability,  
  169. 'bbp-repair',  
  170. 'bbp_admin_repair' 
  171. ); 
  172.  
  173. if ( current_user_can( 'bbp_tools_import_page' ) ) { 
  174. $hooks[] = add_management_page( 
  175. __( 'Import Forums', 'bbpress' ),  
  176. __( 'Forum Import', 'bbpress' ),  
  177. $this->minimum_capability,  
  178. 'bbp-converter',  
  179. 'bbp_converter_settings' 
  180. ); 
  181.  
  182. if ( current_user_can( 'bbp_tools_reset_page' ) ) { 
  183. $hooks[] = add_management_page( 
  184. __( 'Reset Forums', 'bbpress' ),  
  185. __( 'Forum Reset', 'bbpress' ),  
  186. $this->minimum_capability,  
  187. 'bbp-reset',  
  188. 'bbp_admin_reset' 
  189. ); 
  190.  
  191. // Fudge the highlighted subnav item when on a bbPress admin page 
  192. foreach ( $hooks as $hook ) { 
  193. add_action( "admin_head-$hook", 'bbp_tools_modify_menu_highlight' ); 
  194.  
  195. // Forums Tools Root 
  196. add_management_page( 
  197. __( 'Forums', 'bbpress' ),  
  198. __( 'Forums', 'bbpress' ),  
  199. $this->minimum_capability,  
  200. 'bbp-repair',  
  201. 'bbp_admin_repair' 
  202. ); 
  203.  
  204. // Are settings enabled? 
  205. if ( ! bbp_settings_integration() && current_user_can( 'bbp_settings_page' ) ) { 
  206. add_options_page( 
  207. __( 'Forums', 'bbpress' ),  
  208. __( 'Forums', 'bbpress' ),  
  209. $this->minimum_capability,  
  210. 'bbpress',  
  211. 'bbp_admin_settings' 
  212. ); 
  213.  
  214. // These are later removed in admin_head 
  215. if ( current_user_can( 'bbp_about_page' ) ) { 
  216.  
  217. // About 
  218. add_dashboard_page( 
  219. __( 'Welcome to bbPress', 'bbpress' ),  
  220. __( 'Welcome to bbPress', 'bbpress' ),  
  221. $this->minimum_capability,  
  222. 'bbp-about',  
  223. array( $this, 'about_screen' ) 
  224. ); 
  225.  
  226. // Credits 
  227. add_dashboard_page( 
  228. __( 'Welcome to bbPress', 'bbpress' ),  
  229. __( 'Welcome to bbPress', 'bbpress' ),  
  230. $this->minimum_capability,  
  231. 'bbp-credits',  
  232. array( $this, 'credits_screen' ) 
  233. ); 
  234.  
  235. // Bail if plugin is not network activated 
  236. if ( ! is_plugin_active_for_network( bbpress()->basename ) ) 
  237. return; 
  238.  
  239. add_submenu_page( 
  240. 'index.php',  
  241. __( 'Update Forums', 'bbpress' ),  
  242. __( 'Update Forums', 'bbpress' ),  
  243. 'manage_network',  
  244. 'bbp-update',  
  245. array( $this, 'update_screen' ) 
  246. ); 
  247.  
  248. /** 
  249. * Add the network admin menus 
  250. * @since bbPress (r3689) 
  251. * @uses add_submenu_page() To add the Update Forums page in Updates 
  252. */ 
  253. public function network_admin_menus() { 
  254.  
  255. // Bail if plugin is not network activated 
  256. if ( ! is_plugin_active_for_network( bbpress()->basename ) ) 
  257. return; 
  258.  
  259. add_submenu_page( 
  260. 'upgrade.php',  
  261. __( 'Update Forums', 'bbpress' ),  
  262. __( 'Update Forums', 'bbpress' ),  
  263. 'manage_network',  
  264. 'bbpress-update',  
  265. array( $this, 'network_update_screen' ) 
  266. ); 
  267.  
  268. /** 
  269. * If this is a new installation, create some initial forum content. 
  270. * @since bbPress (r3767) 
  271. * @return type 
  272. */ 
  273. public static function new_install() { 
  274. if ( !bbp_is_install() ) 
  275. return; 
  276.  
  277. bbp_create_initial_content(); 
  278.  
  279. /** 
  280. * Register the settings 
  281. * @since bbPress (r2737) 
  282. * @uses add_settings_section() To add our own settings section 
  283. * @uses add_settings_field() To add various settings fields 
  284. * @uses register_setting() To register various settings 
  285. * @todo Put fields into multidimensional array 
  286. */ 
  287. public static function register_admin_settings() { 
  288.  
  289. // Bail if no sections available 
  290. $sections = bbp_admin_get_settings_sections(); 
  291. if ( empty( $sections ) ) 
  292. return false; 
  293.  
  294. // Are we using settings integration? 
  295. $settings_integration = bbp_settings_integration(); 
  296.  
  297. // Loop through sections 
  298. foreach ( (array) $sections as $section_id => $section ) { 
  299.  
  300. // Only proceed if current user can see this section 
  301. if ( ! current_user_can( $section_id ) ) 
  302. continue; 
  303.  
  304. // Only add section and fields if section has fields 
  305. $fields = bbp_admin_get_settings_fields_for_section( $section_id ); 
  306. if ( empty( $fields ) ) 
  307. continue; 
  308.  
  309. // Toggle the section if core integration is on 
  310. if ( ( true === $settings_integration ) && !empty( $section['page'] ) ) { 
  311. $page = $section['page']; 
  312. } else { 
  313. $page = 'bbpress'; 
  314.  
  315. // Add the section 
  316. add_settings_section( $section_id, $section['title'], $section['callback'], $page ); 
  317.  
  318. // Loop through fields for this section 
  319. foreach ( (array) $fields as $field_id => $field ) { 
  320.  
  321. // Add the field 
  322. if ( ! empty( $field['callback'] ) && !empty( $field['title'] ) ) { 
  323. add_settings_field( $field_id, $field['title'], $field['callback'], $page, $section_id, $field['args'] ); 
  324.  
  325. // Register the setting 
  326. register_setting( $page, $field_id, $field['sanitize_callback'] ); 
  327.  
  328. /** 
  329. * Maps settings capabilities 
  330. * @since bbPress (r4242) 
  331. * @param array $caps Capabilities for meta capability 
  332. * @param string $cap Capability name 
  333. * @param int $user_id User id 
  334. * @param mixed $args Arguments 
  335. * @uses get_post() To get the post 
  336. * @uses apply_filters() Calls 'bbp_map_meta_caps' with caps, cap, user id and 
  337. * args 
  338. * @return array Actual capabilities for meta capability 
  339. */ 
  340. public static function map_settings_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 
  341.  
  342. // What capability is being checked? 
  343. switch ( $cap ) { 
  344.  
  345. // BuddyPress 
  346. case 'bbp_settings_buddypress' : 
  347. if ( ( is_plugin_active( 'buddypress/bp-loader.php' ) && defined( 'BP_VERSION' ) && bp_is_root_blog() ) && is_super_admin() ) { 
  348. $caps = array( bbpress()->admin->minimum_capability ); 
  349. } else { 
  350. $caps = array( 'do_not_allow' ); 
  351.  
  352. break; 
  353.  
  354. // Akismet 
  355. case 'bbp_settings_akismet' : 
  356. if ( ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) && is_super_admin() ) { 
  357. $caps = array( bbpress()->admin->minimum_capability ); 
  358. } else { 
  359. $caps = array( 'do_not_allow' ); 
  360.  
  361. break; 
  362.  
  363. // bbPress 
  364. case 'bbp_about_page' : // About and Credits 
  365. case 'bbp_tools_page' : // Tools Page 
  366. case 'bbp_tools_repair_page' : // Tools - Repair Page 
  367. case 'bbp_tools_import_page' : // Tools - Import Page 
  368. case 'bbp_tools_reset_page' : // Tools - Reset Page 
  369. case 'bbp_settings_page' : // Settings Page 
  370. case 'bbp_settings_users' : // Settings - Users 
  371. case 'bbp_settings_features' : // Settings - Features 
  372. case 'bbp_settings_theme_compat' : // Settings - Theme compat 
  373. case 'bbp_settings_root_slugs' : // Settings - Root slugs 
  374. case 'bbp_settings_single_slugs' : // Settings - Single slugs 
  375. case 'bbp_settings_user_slugs' : // Settings - User slugs 
  376. case 'bbp_settings_per_page' : // Settings - Per page 
  377. case 'bbp_settings_per_rss_page' : // Settings - Per RSS page 
  378. $caps = array( bbpress()->admin->minimum_capability ); 
  379. break; 
  380.  
  381. return apply_filters( 'bbp_map_settings_meta_caps', $caps, $cap, $user_id, $args ); 
  382.  
  383. /** 
  384. * Register the importers 
  385. * @since bbPress (r2737) 
  386. * @uses apply_filters() Calls 'bbp_importer_path' filter to allow plugins 
  387. * to customize the importer script locations. 
  388. */ 
  389. public function register_importers() { 
  390.  
  391. // Leave if we're not in the import section 
  392. if ( !defined( 'WP_LOAD_IMPORTERS' ) ) 
  393. return; 
  394.  
  395. // Load Importer API 
  396. require_once( ABSPATH . 'wp-admin/includes/import.php' ); 
  397.  
  398. // Load our importers 
  399. $importers = apply_filters( 'bbp_importers', array( 'bbpress' ) ); 
  400.  
  401. // Loop through included importers 
  402. foreach ( $importers as $importer ) { 
  403.  
  404. // Allow custom importer directory 
  405. $import_dir = apply_filters( 'bbp_importer_path', $this->admin_dir . 'importers', $importer ); 
  406.  
  407. // Compile the importer path 
  408. $import_file = trailingslashit( $import_dir ) . $importer . '.php'; 
  409.  
  410. // If the file exists, include it 
  411. if ( file_exists( $import_file ) ) { 
  412. require( $import_file ); 
  413.  
  414. /** 
  415. * Admin area activation notice 
  416. * Shows a nag message in admin area about the theme not supporting bbPress 
  417. * @since bbPress (r2743) 
  418. * @uses current_user_can() To check notice should be displayed. 
  419. */ 
  420. public function activation_notice() { 
  421. // @todo - something fun 
  422.  
  423. /** 
  424. * Add Settings link to plugins area 
  425. * @since bbPress (r2737) 
  426. * @param array $links Links array in which we would prepend our link 
  427. * @param string $file Current plugin basename 
  428. * @return array Processed links 
  429. */ 
  430. public static function modify_plugin_action_links( $links, $file ) { 
  431.  
  432. // Return normal links if not bbPress 
  433. if ( plugin_basename( bbpress()->file ) !== $file ) { 
  434. return $links; 
  435.  
  436. // New links to merge into existing links 
  437. $new_links = array(); 
  438.  
  439. // Settings page link 
  440. if ( current_user_can( 'bbp_settings_page' ) ) { 
  441. $new_links['settings'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbpress' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'bbpress' ) . '</a>'; 
  442.  
  443. // About page link 
  444. if ( current_user_can( 'bbp_about_page' ) ) { 
  445. $new_links['about'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) ) . '">' . esc_html__( 'About', 'bbpress' ) . '</a>'; 
  446.  
  447. // Add a few links to the existing links array 
  448. return array_merge( $links, $new_links ); 
  449.  
  450. /** 
  451. * Add the 'Right now in Forums' dashboard widget 
  452. * @since bbPress (r2770) 
  453. * @uses wp_add_dashboard_widget() To add the dashboard widget 
  454. */ 
  455. public static function dashboard_widget_right_now() { 
  456. wp_add_dashboard_widget( 'bbp-dashboard-right-now', __( 'Right Now in Forums', 'bbpress' ), 'bbp_dashboard_widget_right_now' ); 
  457.  
  458. /** 
  459. * Add a link to bbPress about page to the admin bar 
  460. * @since bbPress (r5136) 
  461. * @param WP_Admin_Bar $wp_admin_bar 
  462. */ 
  463. public function admin_bar_about_link( $wp_admin_bar ) { 
  464. if ( is_user_logged_in() ) { 
  465. $wp_admin_bar->add_menu( array( 
  466. 'parent' => 'wp-logo',  
  467. 'id' => 'bbp-about',  
  468. 'title' => esc_html__( 'About bbPress', 'bbpress' ),  
  469. 'href' => add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) 
  470. ) ); 
  471.  
  472. /** 
  473. * Enqueue any admin scripts we might need 
  474. * @since bbPress (r4260) 
  475. */ 
  476. public function enqueue_scripts() { 
  477. wp_enqueue_script( 'suggest' ); 
  478.  
  479. // Get the version to use for JS 
  480. $version = bbp_get_version(); 
  481.  
  482. // Post type checker (only topics and replies) 
  483. if ( 'post' === get_current_screen()->base ) { 
  484. switch( get_current_screen()->post_type ) { 
  485. case bbp_get_reply_post_type() : 
  486. case bbp_get_topic_post_type() : 
  487.  
  488. // Enqueue the common JS 
  489. wp_enqueue_script( 'bbp-admin-common-js', $this->js_url . 'common.js', array( 'jquery' ), $version ); 
  490.  
  491. // Topics admin 
  492. if ( bbp_get_topic_post_type() === get_current_screen()->post_type ) { 
  493. wp_enqueue_script( 'bbp-admin-topics-js', $this->js_url . 'topics.js', array( 'jquery' ), $version ); 
  494.  
  495. // Replies admin 
  496. } elseif ( bbp_get_reply_post_type() === get_current_screen()->post_type ) { 
  497. wp_enqueue_script( 'bbp-admin-replies-js', $this->js_url . 'replies.js', array( 'jquery' ), $version ); 
  498.  
  499. break; 
  500.  
  501. /** 
  502. * Enqueue any admin scripts we might need 
  503. * @since bbPress (r5224) 
  504. */ 
  505. public function enqueue_styles() { 
  506. wp_enqueue_style( 'bbp-admin-css', $this->css_url . 'admin.css', array( 'dashicons' ), bbp_get_version() ); 
  507.  
  508. /** 
  509. * Remove the individual recount and converter menus. 
  510. * They are grouped together by h2 tabs 
  511. * @since bbPress (r2464) 
  512. * @uses remove_submenu_page() To remove menu items with alternat navigation 
  513. */ 
  514. public function admin_head() { 
  515. remove_submenu_page( 'tools.php', 'bbp-repair' ); 
  516. remove_submenu_page( 'tools.php', 'bbp-converter' ); 
  517. remove_submenu_page( 'tools.php', 'bbp-reset' ); 
  518. remove_submenu_page( 'index.php', 'bbp-about' ); 
  519. remove_submenu_page( 'index.php', 'bbp-credits' ); 
  520.  
  521. /** 
  522. * Registers the bbPress admin color scheme 
  523. * Because wp-content can exist outside of the WordPress root there is no 
  524. * way to be certain what the relative path of the admin images is. 
  525. * We are including the two most common configurations here, just in case. 
  526. * @since bbPress (r2521) 
  527. * @uses wp_admin_css_color() To register the color scheme 
  528. */ 
  529. public function register_admin_style () { 
  530.  
  531. // RTL and/or minified 
  532. $suffix = is_rtl() ? '-rtl' : ''; 
  533. //$suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  534.  
  535. // Mint 
  536. wp_admin_css_color( 
  537. 'bbp-mint',  
  538. esc_html_x( 'Mint', 'admin color scheme', 'bbpress' ),  
  539. $this->styles_url . 'mint' . $suffix . '.css',  
  540. array( '#4f6d59', '#33834e', '#5FB37C', '#81c498' ),  
  541. array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' ) 
  542. ); 
  543.  
  544. // Evergreen 
  545. wp_admin_css_color( 
  546. 'bbp-evergreen',  
  547. esc_html_x( 'Evergreen', 'admin color scheme', 'bbpress' ),  
  548. $this->styles_url . 'evergreen' . $suffix . '.css',  
  549. array( '#324d3a', '#446950', '#56b274', '#324d3a' ),  
  550. array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' ) 
  551. ); 
  552.  
  553. // Bail if already using the fresh color scheme 
  554. if ( 'fresh' === get_user_option( 'admin_color' ) ) { 
  555. return; 
  556.  
  557. // Force 'colors-fresh' dependency 
  558. global $wp_styles; 
  559. $wp_styles->registered[ 'colors' ]->deps[] = 'colors-fresh'; 
  560.  
  561. /** 
  562. * Hide theme compat package selection if only 1 package is registered 
  563. * @since bbPress (r4315) 
  564. * @param array $sections Forums settings sections 
  565. * @return array 
  566. */ 
  567. public function hide_theme_compat_packages( $sections = array() ) { 
  568. if ( count( bbpress()->theme_compat->packages ) <= 1 ) 
  569. unset( $sections['bbp_settings_theme_compat'] ); 
  570.  
  571. return $sections; 
  572.  
  573. /** 
  574. * Allow keymaster role to save Forums settings 
  575. * @since bbPress (r4678) 
  576. * @param string $capability 
  577. * @return string Return 'keep_gate' capability 
  578. */ 
  579. public function option_page_capability_bbpress( $capability = 'manage_options' ) { 
  580. $capability = 'keep_gate'; 
  581. return $capability; 
  582.  
  583. /** Ajax ******************************************************************/ 
  584.  
  585. /** 
  586. * Ajax action for facilitating the forum auto-suggest 
  587. * @since bbPress (r4261) 
  588. * @uses get_posts() 
  589. * @uses bbp_get_topic_post_type() 
  590. * @uses bbp_get_topic_id() 
  591. * @uses bbp_get_topic_title() 
  592. */ 
  593. public function suggest_topic() { 
  594. global $wpdb; 
  595.  
  596. // Bail early if no request 
  597. if ( empty( $_REQUEST['q'] ) ) { 
  598. wp_die( '0' ); 
  599.  
  600. // Bail if user cannot moderate - only moderators can change hierarchy 
  601. if ( ! current_user_can( 'moderate' ) ) { 
  602. wp_die( '0' ); 
  603.  
  604. // Check the ajax nonce 
  605. check_ajax_referer( 'bbp_suggest_topic_nonce' ); 
  606.  
  607. // Try to get some topics 
  608. $topics = get_posts( array( 
  609. 's' => $wpdb->esc_like( $_REQUEST['q'] ),  
  610. 'post_type' => bbp_get_topic_post_type() 
  611. ) ); 
  612.  
  613. // If we found some topics, loop through and display them 
  614. if ( ! empty( $topics ) ) { 
  615. foreach ( (array) $topics as $post ) { 
  616. printf( esc_html__( '%s - %s', 'bbpress' ), bbp_get_topic_id( $post->ID ), bbp_get_topic_title( $post->ID ) . "\n" ); 
  617. die(); 
  618.  
  619. /** 
  620. * Ajax action for facilitating the topic and reply author auto-suggest 
  621. * @since bbPress (r5014) 
  622. */ 
  623. public function suggest_user() { 
  624. global $wpdb; 
  625.  
  626. // Bail early if no request 
  627. if ( empty( $_REQUEST['q'] ) ) { 
  628. wp_die( '0' ); 
  629.  
  630. // Bail if user cannot moderate - only moderators can change authorship 
  631. if ( ! current_user_can( 'moderate' ) ) { 
  632. wp_die( '0' ); 
  633.  
  634. // Check the ajax nonce 
  635. check_ajax_referer( 'bbp_suggest_user_nonce' ); 
  636.  
  637. // Try to get some users 
  638. $users_query = new WP_User_Query( array( 
  639. 'search' => '*' . $wpdb->esc_like( $_REQUEST['q'] ) . '*',  
  640. 'fields' => array( 'ID', 'user_nicename' ),  
  641. 'search_columns' => array( 'ID', 'user_nicename', 'user_email' ),  
  642. 'orderby' => 'ID' 
  643. ) ); 
  644.  
  645. // If we found some users, loop through and display them 
  646. if ( ! empty( $users_query->results ) ) { 
  647. foreach ( (array) $users_query->results as $user ) { 
  648. printf( esc_html__( '%s - %s', 'bbpress' ), bbp_get_user_id( $user->ID ), bbp_get_user_nicename( $user->ID, array( 'force' => $user->user_nicename ) ) . "\n" ); 
  649. die(); 
  650.  
  651. /** About *****************************************************************/ 
  652.  
  653. /** 
  654. * Output the about screen 
  655. * @since bbPress (r4159) 
  656. */ 
  657. public function about_screen() { 
  658.  
  659. list( $display_version ) = explode( '-', bbp_get_version() ); ?> 
  660.  
  661. <div class="wrap about-wrap"> 
  662. <h1><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1> 
  663. <div class="about-text"><?php printf( esc_html__( 'Thank you for updating! bbPress %s is bundled up and ready to weather the storm of users in your community!', 'bbpress' ), $display_version ); ?></div> 
  664. <div class="bbp-badge"><?php printf( esc_html__( 'Version %s', 'bbpress' ), $display_version ); ?></div> 
  665.  
  666. <h2 class="nav-tab-wrapper"> 
  667. <a class="nav-tab nav-tab-active" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbp-about' ), 'index.php' ) ) ); ?>"> 
  668. <?php esc_html_e( 'What’s New', 'bbpress' ); ?> 
  669. </a><a class="nav-tab" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbp-credits' ), 'index.php' ) ) ); ?>"> 
  670. <?php esc_html_e( 'Credits', 'bbpress' ); ?> 
  671. </a> 
  672. </h2> 
  673.  
  674. <div class="changelog"> 
  675. <h3><?php esc_html_e( 'Forum Subscriptions', 'bbpress' ); ?></h3> 
  676.  
  677. <div class="feature-section col two-col"> 
  678. <div class="last-feature"> 
  679. <h4><?php esc_html_e( 'Subscribe to Forums', 'bbpress' ); ?></h4> 
  680. <p><?php esc_html_e( 'Now your users can subscribe to new topics in specific forums.', 'bbpress' ); ?></p> 
  681. </div> 
  682.  
  683. <div> 
  684. <h4><?php esc_html_e( 'Manage Subscriptions', 'bbpress' ); ?></h4> 
  685. <p><?php esc_html_e( 'Your users can manage all of their subscriptions in one convenient location.', 'bbpress' ); ?></p> 
  686. </div> 
  687. </div> 
  688. </div> 
  689.  
  690. <div class="changelog"> 
  691. <h3><?php esc_html_e( 'Converters', 'bbpress' ); ?></h3> 
  692.  
  693. <div class="feature-section col one-col"> 
  694. <div class="last-feature"> 
  695. <p><?php esc_html_e( 'We’re all abuzz about the hive of new importers, AEF, Drupal, FluxBB, Kunena Forums for Joomla, MyBB, Phorum, PHPFox, PHPWind, PunBB, SMF, Xenforo and XMB. Existing importers are now sweeter than honey with improved importing stickies, topic tags, forum categories and the sting is now gone if you need to remove imported users.', 'bbpress' ); ?></p> 
  696. </div> 
  697. </div> 
  698.  
  699. <div class="feature-section col three-col"> 
  700. <div> 
  701. <h4><?php esc_html_e( 'Theme Compatibility', 'bbpress' ); ?></h4> 
  702. <p><?php esc_html_e( 'Better handling of styles and scripts in the template stack.', 'bbpress' ); ?></p> 
  703. </div> 
  704.  
  705. <div> 
  706. <h4><?php esc_html_e( 'Polyglot support', 'bbpress' ); ?></h4> 
  707. <p><?php esc_html_e( 'bbPress fully supports automatic translation updates.', 'bbpress' ); ?></p> 
  708. </div> 
  709.  
  710. <div class="last-feature"> 
  711. <h4><?php esc_html_e( 'User capabilities', 'bbpress' ); ?></h4> 
  712. <p><?php esc_html_e( 'Roles and capabilities have been swept through, cleaned up, and simplified.', 'bbpress' ); ?></p> 
  713. </div> 
  714. </div> 
  715. </div> 
  716.  
  717. <div class="return-to-dashboard"> 
  718. <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbpress' ), 'options-general.php' ) ) ); ?>"><?php esc_html_e( 'Go to Forum Settings', 'bbpress' ); ?></a> 
  719. </div> 
  720.  
  721. </div> 
  722.  
  723. <?php 
  724.  
  725. /** 
  726. * Output the credits screen 
  727. * Hardcoding this in here is pretty janky. It's fine for 2.2, but we'll 
  728. * want to leverage api.wordpress.org eventually. 
  729. * @since bbPress (r4159) 
  730. */ 
  731. public function credits_screen() { 
  732.  
  733. list( $display_version ) = explode( '-', bbp_get_version() ); ?> 
  734.  
  735. <div class="wrap about-wrap"> 
  736. <h1><?php printf( esc_html__( 'Welcome to bbPress %s', 'bbpress' ), $display_version ); ?></h1> 
  737. <div class="about-text"><?php printf( esc_html__( 'Thank you for updating! bbPress %s is waxed, polished, and ready for you to take it for a lap or two around the block!', 'bbpress' ), $display_version ); ?></div> 
  738. <div class="bbp-badge"><?php printf( esc_html__( 'Version %s', 'bbpress' ), $display_version ); ?></div> 
  739.  
  740. <h2 class="nav-tab-wrapper"> 
  741. <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbp-about' ), 'index.php' ) ) ); ?>" class="nav-tab"> 
  742. <?php esc_html_e( 'What’s New', 'bbpress' ); ?> 
  743. </a><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbp-credits' ), 'index.php' ) ) ); ?>" class="nav-tab nav-tab-active"> 
  744. <?php esc_html_e( 'Credits', 'bbpress' ); ?> 
  745. </a> 
  746. </h2> 
  747.  
  748. <p class="about-description"><?php esc_html_e( 'bbPress is created by a worldwide swarm of busy, busy bees.', 'bbpress' ); ?></p> 
  749.  
  750. <h4 class="wp-people-group"><?php esc_html_e( 'Project Leaders', 'bbpress' ); ?></h4> 
  751. <ul class="wp-people-group " id="wp-people-group-project-leaders"> 
  752. <li class="wp-person" id="wp-person-matt"> 
  753. <a href="http://profiles.wordpress.org/matt"><img src="http://0.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60?s=60" class="gravatar" alt="Matt Mullenweg" /></a> 
  754. <a class="web" href="http://profiles.wordpress.org/matt">Matt Mullenweg</a> 
  755. <span class="title"><?php esc_html_e( 'Founding Developer', 'bbpress' ); ?></span> 
  756. </li> 
  757. <li class="wp-person" id="wp-person-johnjamesjacoby"> 
  758. <a href="http://profiles.wordpress.org/johnjamesjacoby"><img src="http://0.gravatar.com/avatar/81ec16063d89b162d55efe72165c105f?s=60" class="gravatar" alt="John James Jacoby" /></a> 
  759. <a class="web" href="http://profiles.wordpress.org/johnjamesjacoby">John James Jacoby</a> 
  760. <span class="title"><?php esc_html_e( 'Lead Developer', 'bbpress' ); ?></span> 
  761. </li> 
  762. <li class="wp-person" id="wp-person-jmdodd"> 
  763. <a href="http://profiles.wordpress.org/jmdodd"><img src="http://0.gravatar.com/avatar/6a7c997edea340616bcc6d0fe03f65dd?s=60" class="gravatar" alt="Jennifer M. Dodd" /></a> 
  764. <a class="web" href="http://profiles.wordpress.org/jmdodd">Jennifer M. Dodd</a> 
  765. <span class="title"><?php esc_html_e( 'Feature Developer', 'bbpress' ); ?></span> 
  766. </li> 
  767. <li class="wp-person" id="wp-person-netweb"> 
  768. <a href="http://profiles.wordpress.org/netweb"><img src="http://0.gravatar.com/avatar/97e1620b501da675315ba7cfb740e80f?s=60" class="gravatar" alt="Stephen Edgar" /></a> 
  769. <a class="web" href="http://profiles.wordpress.org/netweb">Stephen Edgar</a> 
  770. <span class="title"><?php esc_html_e( 'Converter Specialist', 'bbpress' ); ?></span> 
  771. </li> 
  772. </ul> 
  773.  
  774. <h4 class="wp-people-group"><?php esc_html_e( 'Contributing Developers', 'bbpress' ); ?></h4> 
  775. <ul class="wp-people-group " id="wp-people-group-contributing-developers"> 
  776. <li class="wp-person" id="wp-person-jaredatch"> 
  777. <a href="http://profiles.wordpress.org/jaredatch"><img src="http://0.gravatar.com/avatar/e341eca9e1a85dcae7127044301b4363?s=60" class="gravatar" alt="Jared Atchison" /></a> 
  778. <a class="web" href="http://profiles.wordpress.org/jaredatch">Jared Atchison</a> 
  779. <span class="title"><?php esc_html_e( 'Bug Testing', 'bbpress' ); ?></span> 
  780. </li> 
  781. <li class="wp-person" id="wp-person-gautamgupta"> 
  782. <a href="http://profiles.wordpress.org/gautamgupta"><img src="http://0.gravatar.com/avatar/b0810422cbe6e4eead4def5ae7a90b34?s=60" class="gravatar" alt="Gautam Gupta" /></a> 
  783. <a class="web" href="http://profiles.wordpress.org/gautamgupta">Gautam Gupta</a> 
  784. <span class="title"><?php esc_html_e( 'Feature Developer', 'bbpress' ); ?></span> 
  785. </li> 
  786. </ul> 
  787.  
  788. <h4 class="wp-people-group"><?php esc_html_e( 'Core Contributors to bbPress 2.5', 'bbpress' ); ?></h4> 
  789. <p class="wp-credits-list"> 
  790. <a href="http://profiles.wordpress.org/alex-ye">alex-ye</a>,  
  791. <a href="http://profiles.wordpress.org/alexvorn2">alexvorn2</a>,  
  792. <a href="http://profiles.wordpress.org/aliso">aliso</a>,  
  793. <a href="http://profiles.wordpress.org/boonebgorges">boonebgorges</a>,  
  794. <a href="http://profiles.wordpress.org/daveshine">daveshine</a>,  
  795. <a href="http://profiles.wordpress.org/DJPaul">DJPaul</a>,  
  796. <a href="http://profiles.wordpress.org/ethitter">ethitter</a>,  
  797. <a href="http://profiles.wordpress.org/fanquake">fanquake</a>,  
  798. <a href="http://profiles.wordpress.org/GargajCNS">GargajCNS</a>,  
  799. <a href="http://profiles.wordpress.org/GautamGupta">GautamGupta</a>,  
  800. <a href="http://profiles.wordpress.org/imath">imath</a>,  
  801. <a href="http://profiles.wordpress.org/jkudish">jkudish</a>,  
  802. <a href="http://profiles.wordpress.org/kobenland">kobenland</a>,  
  803. <a href="http://profiles.wordpress.org/lakrisgubben">lakrisgubben</a>,  
  804. <a href="http://profiles.wordpress.org/loki_racer">loki_racer</a>,  
  805. <a href="http://profiles.wordpress.org/mamaduka">mamaduka</a>,  
  806. <a href="http://profiles.wordpress.org/Maty">Maty</a>,  
  807. <a href="http://profiles.wordpress.org/mercime">mercime</a>,  
  808. <a href="http://profiles.wordpress.org/mordauk">mordauk</a>,  
  809. <a href="http://profiles.wordpress.org/mrcl">mrcl</a>,  
  810. <a href="http://profiles.wordpress.org/MZAWeb">MZAWeb</a>,  
  811. <a href="http://profiles.wordpress.org/r-a-y">r-a-y</a>,  
  812. <a href="http://profiles.wordpress.org/strangerstudios">strangerstudios</a>,  
  813. <a href="http://profiles.wordpress.org/thebrandonallen">thebrandonallen</a>,  
  814. <a href="http://profiles.wordpress.org/tlovett1">tlovett1</a>,  
  815. <a href="http://profiles.wordpress.org/wpdennis">wpdennis</a>,  
  816. </p> 
  817.  
  818. <div class="return-to-dashboard"> 
  819. <a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'bbpress' ), 'options-general.php' ) ) ); ?>"><?php esc_html_e( 'Go to Forum Settings', 'bbpress' ); ?></a> 
  820. </div> 
  821.  
  822. </div> 
  823.  
  824. <?php 
  825.  
  826. /** Updaters **************************************************************/ 
  827.  
  828. /** 
  829. * Update all bbPress forums across all sites 
  830. * @since bbPress (r3689) 
  831. * @global WPDB $wpdb 
  832. * @uses get_blog_option() 
  833. * @uses wp_remote_get() 
  834. */ 
  835. public static function update_screen() { 
  836.  
  837. // Get action 
  838. $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?> 
  839.  
  840. <div class="wrap"> 
  841. <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div> 
  842. <h2><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></h2> 
  843.  
  844. <?php 
  845.  
  846. // Taking action 
  847. switch ( $action ) { 
  848. case 'bbp-update' : 
  849.  
  850. // Run the full updater 
  851. bbp_version_updater(); ?> 
  852.  
  853. <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p> 
  854. <a class="button" href="index.php?page=bbp-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a> 
  855.  
  856. <?php 
  857.  
  858. break; 
  859.  
  860. case 'show' : 
  861. default : ?> 
  862.  
  863. <p><?php esc_html_e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p> 
  864. <p><a class="button" href="index.php?page=bbp-update&action=bbp-update"><?php esc_html_e( 'Update Forum', 'bbpress' ); ?></a></p> 
  865.  
  866. <?php break; 
  867.  
  868. } ?> 
  869.  
  870. </div><?php 
  871.  
  872. /** 
  873. * Update all bbPress forums across all sites 
  874. * @since bbPress (r3689) 
  875. * @global WPDB $wpdb 
  876. * @uses get_blog_option() 
  877. * @uses wp_remote_get() 
  878. */ 
  879. public static function network_update_screen() { 
  880. global $wpdb; 
  881.  
  882. // Get action 
  883. $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?> 
  884.  
  885. <div class="wrap"> 
  886. <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div> 
  887. <h2><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></h2> 
  888.  
  889. <?php 
  890.  
  891. // Taking action 
  892. switch ( $action ) { 
  893. case 'bbpress-update' : 
  894.  
  895. // Site counter 
  896. $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0; 
  897.  
  898. // Get blogs 5 at a time 
  899. $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A ); 
  900.  
  901. // No blogs so all done! 
  902. if ( empty( $blogs ) ) : ?> 
  903.  
  904. <p><?php esc_html_e( 'All done!', 'bbpress' ); ?></p> 
  905. <a class="button" href="update-core.php?page=bbpress-update"><?php esc_html_e( 'Go Back', 'bbpress' ); ?></a> 
  906.  
  907. <?php 
  908.  
  909. // Still have sites to loop through 
  910. else : ?> 
  911.  
  912. <ul> 
  913.  
  914. <?php foreach ( (array) $blogs as $details ) : 
  915.  
  916. $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); ?> 
  917.  
  918. <li><?php echo $siteurl; ?></li> 
  919.  
  920. <?php 
  921.  
  922. // Get the response of the bbPress update on this site 
  923. $response = wp_remote_get( 
  924. trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbp-update&action=bbp-update',  
  925. array( 'timeout' => 30, 'httpversion' => '1.1' ) 
  926. ); 
  927.  
  928. // Site errored out, no response? 
  929. if ( is_wp_error( $response ) ) 
  930. wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>', 'bbpress' ), $siteurl, $response->get_error_message() ) ); 
  931.  
  932. // Switch to the new blog 
  933. switch_to_blog( $details[ 'blog_id' ] ); 
  934.  
  935. $basename = bbpress()->basename; 
  936.  
  937. // Run the updater on this site 
  938. if ( is_plugin_active_for_network( $basename ) || is_plugin_active( $basename ) ) { 
  939. bbp_version_updater(); 
  940.  
  941. // restore original blog 
  942. restore_current_blog(); 
  943.  
  944. // Do some actions to allow plugins to do things too 
  945. do_action( 'after_bbpress_upgrade', $response ); 
  946. do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] ); 
  947.  
  948. endforeach; ?> 
  949.  
  950. </ul> 
  951.  
  952. <p> 
  953. <?php esc_html_e( 'If your browser doesn’t start loading the next page automatically, click this link:', 'bbpress' ); ?> 
  954. <a class="button" href="update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ); ?>"><?php esc_html_e( 'Next Forums', 'bbpress' ); ?></a> 
  955. </p> 
  956. <script type='text/javascript'> 
  957. <!-- 
  958. function nextpage() { 
  959. location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>'; 
  960. setTimeout( 'nextpage()', 250 ); 
  961. //--> 
  962. </script><?php 
  963.  
  964. endif; 
  965.  
  966. break; 
  967.  
  968. case 'show' : 
  969. default : ?> 
  970.  
  971. <p><?php esc_html_e( 'You can update all the forums on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.', 'bbpress' ); ?></p> 
  972. <p><a class="button" href="update-core.php?page=bbpress-update&action=bbpress-update"><?php esc_html_e( 'Update Forums', 'bbpress' ); ?></a></p> 
  973.  
  974. <?php break; 
  975.  
  976. } ?> 
  977.  
  978. </div><?php