/bp-core/admin/bp-core-admin-functions.php

  1. <?php 
  2. /** 
  3. * BuddyPress Common Admin Functions. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage CoreAdministration 
  7. * @since 2.3.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** Menu **********************************************************************/ 
  14.  
  15. /** 
  16. * Initializes the wp-admin area "BuddyPress" menus and sub menus. 
  17. * 
  18. */ 
  19. function bp_core_admin_menu_init() { 
  20. add_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 ); 
  21.  
  22. /** 
  23. * In BP 1.6, the top-level admin menu was removed. For backpat, this function 
  24. * keeps the top-level menu if a plugin has registered a menu into the old 
  25. * 'bp-general-settings' menu. 
  26. * 
  27. * The old "bp-general-settings" page was renamed "bp-components". 
  28. * 
  29. * @global array $_parent_pages 
  30. * @global array $_registered_pages 
  31. * @global array $submenu 
  32. * 
  33. * @since 1.6.0 
  34. */ 
  35. function bp_core_admin_backpat_menu() { 
  36. global $_parent_pages, $_registered_pages, $submenu; 
  37.  
  38. // If there's no bp-general-settings menu (perhaps because the current 
  39. // user is not an Administrator), there's nothing to do here. 
  40. if ( ! isset( $submenu['bp-general-settings'] ) ) { 
  41. return; 
  42.  
  43. /** 
  44. * By default, only the core "Help" submenu is added under the top-level BuddyPress menu. 
  45. * This means that if no third-party plugins have registered their admin pages into the 
  46. * 'bp-general-settings' menu, it will only contain one item. Kill it. 
  47. */ 
  48. if ( 1 != count( $submenu['bp-general-settings'] ) ) { 
  49. return; 
  50.  
  51. // This removes the top-level menu. 
  52. remove_submenu_page( 'bp-general-settings', 'bp-general-settings' ); 
  53. remove_menu_page( 'bp-general-settings' ); 
  54.  
  55. // These stop people accessing the URL directly. 
  56. unset( $_parent_pages['bp-general-settings'] ); 
  57. unset( $_registered_pages['toplevel_page_bp-general-settings'] ); 
  58. add_action( bp_core_admin_hook(), 'bp_core_admin_backpat_menu', 999 ); 
  59.  
  60. /** 
  61. * This tells WP to highlight the Settings > BuddyPress menu item,  
  62. * regardless of which actual BuddyPress admin screen we are on. 
  63. * 
  64. * The conditional prevents the behaviour when the user is viewing the 
  65. * backpat "Help" page, the Activity page, or any third-party plugins. 
  66. * 
  67. * @global string $plugin_page 
  68. * @global array $submenu 
  69. * 
  70. * @since 1.6.0 
  71. */ 
  72. function bp_core_modify_admin_menu_highlight() { 
  73. global $plugin_page, $submenu_file; 
  74.  
  75. // This tweaks the Settings subnav menu to show only one BuddyPress menu item. 
  76. if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) ) { 
  77. $submenu_file = 'bp-components'; 
  78.  
  79. // Network Admin > Tools. 
  80. if ( in_array( $plugin_page, array( 'bp-tools', 'available-tools' ) ) ) { 
  81. $submenu_file = $plugin_page; 
  82.  
  83. /** 
  84. * Generates markup for a fallback top-level BuddyPress menu page, if the site is running 
  85. * a legacy plugin which hasn't been updated. If the site is up to date, this page 
  86. * will never appear. 
  87. * 
  88. * @see bp_core_admin_backpat_menu() 
  89. * 
  90. * @since 1.6.0 
  91. * 
  92. * @todo Add convenience links into the markup once new positions are finalised. 
  93. */ 
  94. function bp_core_admin_backpat_page() { 
  95. $url = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' ); 
  96. $settings_url = add_query_arg( 'page', 'bp-components', $url ); ?> 
  97.  
  98. <div class="wrap"> 
  99. <h2><?php _e( 'Why have all my BuddyPress menus disappeared?', 'buddypress' ); ?></h2> 
  100.  
  101. <p><?php _e( "Don't worry! We've moved the BuddyPress options into more convenient and easier to find locations. You're seeing this page because you are running a legacy BuddyPress plugin which has not been updated.", 'buddypress' ); ?></p> 
  102. <p><?php printf( __( 'Components, Pages, Settings, and Forums, have been moved to <a href="%s">Settings > BuddyPress</a>. Profile Fields has been moved into the <a href="%s">Users</a> menu.', 'buddypress' ), esc_url( $settings_url ), bp_get_admin_url( 'users.php?page=bp-profile-setup' ) ); ?></p> 
  103. </div> 
  104.  
  105. <?php 
  106.  
  107. /** Notices *******************************************************************/ 
  108.  
  109. /** 
  110. * Print admin messages to admin_notices or network_admin_notices. 
  111. * 
  112. * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow 
  113. * boxes. 
  114. * 
  115. * @since 1.5.0 
  116. * 
  117. */ 
  118. function bp_core_print_admin_notices() { 
  119.  
  120. // Only the super admin should see messages. 
  121. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  122. return; 
  123.  
  124. // On multisite installs, don't show on a non-root blog, unless 
  125. // 'do_network_admin' is overridden. 
  126. if ( is_multisite() && bp_core_do_network_admin() && ! bp_is_root_blog() ) { 
  127. return; 
  128.  
  129. $notice_types = array(); 
  130. foreach ( buddypress()->admin->notices as $notice ) { 
  131. $notice_types[] = $notice['type']; 
  132. $notice_types = array_unique( $notice_types ); 
  133.  
  134. foreach ( $notice_types as $type ) { 
  135. $notices = wp_list_filter( buddypress()->admin->notices, array( 'type' => $type ) ); 
  136. printf( '<div id="message" class="fade %s">', sanitize_html_class( $type ) ); 
  137.  
  138. foreach ( $notices as $notice ) { 
  139. printf( '<p>%s</p>', $notice['message'] ); 
  140.  
  141. printf( '</div>' ); 
  142. add_action( 'admin_notices', 'bp_core_print_admin_notices' ); 
  143. add_action( 'network_admin_notices', 'bp_core_print_admin_notices' ); 
  144.  
  145. /** 
  146. * Add an admin notice to the BP queue. 
  147. * 
  148. * Messages added with this function are displayed in BuddyPress's general purpose admin notices 
  149. * box. It is recommended that you hook this function to admin_init, so that your messages are 
  150. * loaded in time. 
  151. * 
  152. * @since 1.5.0 
  153. * 
  154. * @param string $notice The notice you are adding to the queue. 
  155. * @param string $type The notice type; optional. Usually either "updated" or "error". 
  156. */ 
  157. function bp_core_add_admin_notice( $notice = '', $type = 'updated' ) { 
  158.  
  159. // Do not add if the notice is empty. 
  160. if ( empty( $notice ) ) { 
  161. return; 
  162.  
  163. // Double check the object before referencing it. 
  164. if ( ! isset( buddypress()->admin->notices ) ) { 
  165. buddypress()->admin->notices = array(); 
  166.  
  167. // Add the notice. 
  168. buddypress()->admin->notices[] = array( 
  169. 'message' => $notice,  
  170. 'type' => $type,  
  171. ); 
  172.  
  173. /** 
  174. * Verify that some BP prerequisites are set up properly, and notify the admin if not. 
  175. * 
  176. * On every Dashboard page, this function checks the following: 
  177. * - that pretty permalinks are enabled. 
  178. * - that every BP component that needs a WP page for a directory has one. 
  179. * - that no WP page has multiple BP components associated with it. 
  180. * The administrator will be shown a notice for each check that fails. 
  181. * 
  182. * @global WPDB $wpdb WordPress DB object 
  183. * @global WP_Rewrite $wp_rewrite 
  184. * 
  185. * @since 1.2.0 
  186. */ 
  187. function bp_core_activation_notice() { 
  188. global $wp_rewrite, $wpdb; 
  189.  
  190. // Only the super admin gets warnings. 
  191. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  192. return; 
  193.  
  194. // Bail in user admin. 
  195. if ( is_user_admin() ) { 
  196. return; 
  197.  
  198. // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden. 
  199. if ( is_multisite() && bp_core_do_network_admin() && ! bp_is_root_blog() ) { 
  200. return; 
  201.  
  202. // Bail if in network admin, and BuddyPress is not network activated. 
  203. if ( is_network_admin() && ! bp_is_network_activated() ) { 
  204. return; 
  205.  
  206. /** 
  207. * Check to make sure that the blog setup routine has run. This can't 
  208. * happen during the wizard because of the order which the components 
  209. * are loaded. 
  210. */ 
  211. if ( bp_is_active( 'blogs' ) ) { 
  212. $bp = buddypress(); 
  213. $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ); 
  214.  
  215. if ( empty( $count ) ) { 
  216. bp_blogs_record_existing_blogs(); 
  217.  
  218. // Add notice if no rewrite rules are enabled. 
  219. if ( empty( $wp_rewrite->permalink_structure ) ) { 
  220. bp_core_add_admin_notice( sprintf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ), 'error' ); 
  221.  
  222. // Get BuddyPress instance. 
  223. $bp = buddypress(); 
  224.  
  225. /** 
  226. * Check for orphaned BP components (BP component is enabled, no WP page exists). 
  227. */ 
  228. $orphaned_components = array(); 
  229. $wp_page_components = array(); 
  230.  
  231. // Only components with 'has_directory' require a WP page to function. 
  232. foreach( array_keys( $bp->loaded_components ) as $component_id ) { 
  233. if ( !empty( $bp->{$component_id}->has_directory ) ) { 
  234. $wp_page_components[] = array( 
  235. 'id' => $component_id,  
  236. 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id ) 
  237. ); 
  238.  
  239. // Activate and Register are special cases. They are not components but they need WP pages. 
  240. // If user registration is disabled, we can skip this step. 
  241. if ( bp_get_signup_allowed() ) { 
  242. $wp_page_components[] = array( 
  243. 'id' => 'activate',  
  244. 'name' => __( 'Activate', 'buddypress' ) 
  245. ); 
  246.  
  247. $wp_page_components[] = array( 
  248. 'id' => 'register',  
  249. 'name' => __( 'Register', 'buddypress' ) 
  250. ); 
  251.  
  252. // On the first admin screen after a new installation, this isn't set, so grab it to suppress 
  253. // a misleading error message. 
  254. if ( empty( $bp->pages->members ) ) { 
  255. $bp->pages = bp_core_get_directory_pages(); 
  256.  
  257. foreach( $wp_page_components as $component ) { 
  258. if ( !isset( $bp->pages->{$component['id']} ) ) { 
  259. $orphaned_components[] = $component['name']; 
  260.  
  261. // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is 
  262. // not correctly set up, don't show a nag. (In these cases, it's probably the case that the 
  263. // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292. 
  264. if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) { 
  265. $forum_key = array_search( $bp->forums->name, $orphaned_components ); 
  266. unset( $orphaned_components[$forum_key] ); 
  267. $orphaned_components = array_values( $orphaned_components ); 
  268.  
  269. if ( !empty( $orphaned_components ) ) { 
  270. $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ); 
  271. $notice = sprintf( 
  272. '%1$s <a href="%2$s">%3$s</a>',  
  273. sprintf( 
  274. __( 'The following active BuddyPress Components do not have associated WordPress Pages: %s.', 'buddypress' ),  
  275. '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>' 
  276. ),  
  277. esc_url( $admin_url ),  
  278. __( 'Repair', 'buddypress' ) 
  279. ); 
  280.  
  281. bp_core_add_admin_notice( $notice ); 
  282.  
  283. // BP components cannot share a single WP page. Check for duplicate assignments, and post a message if found. 
  284. $dupe_names = array(); 
  285. $page_ids = (array)bp_core_get_directory_page_ids(); 
  286. $dupes = array_diff_assoc( $page_ids, array_unique( $page_ids ) ); 
  287.  
  288. if ( !empty( $dupes ) ) { 
  289. foreach( array_keys( $dupes ) as $dupe_component ) { 
  290. $dupe_names[] = $bp->pages->{$dupe_component}->title; 
  291.  
  292. // Make sure that there are no duplicate duplicates :). 
  293. $dupe_names = array_unique( $dupe_names ); 
  294.  
  295. // If there are duplicates, post a message about them. 
  296. if ( !empty( $dupe_names ) ) { 
  297. $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ); 
  298. $notice = sprintf( 
  299. '%1$s <a href="%2$s">%3$s</a>',  
  300. sprintf( 
  301. __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %s.', 'buddypress' ),  
  302. '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $dupe_names ) ) . '</strong>' 
  303. ),  
  304. esc_url( $admin_url ),  
  305. __( 'Repair', 'buddypress' ) 
  306. ); 
  307.  
  308. bp_core_add_admin_notice( $notice ); 
  309.  
  310. /** 
  311. * Redirect user to BuddyPress's What's New page on activation. 
  312. * 
  313. * @since 1.7.0 
  314. * 
  315. * @internal Used internally to redirect BuddyPress to the about page on activation. 
  316. * 
  317. */ 
  318. function bp_do_activation_redirect() { 
  319.  
  320. // Bail if no activation redirect. 
  321. if ( ! get_transient( '_bp_activation_redirect' ) ) { 
  322. return; 
  323.  
  324. // Delete the redirect transient. 
  325. delete_transient( '_bp_activation_redirect' ); 
  326.  
  327. // Bail if activating from network, or bulk. 
  328. if ( isset( $_GET['activate-multi'] ) ) { 
  329. return; 
  330.  
  331. $query_args = array( 'page' => 'bp-about' ); 
  332. if ( get_transient( '_bp_is_new_install' ) ) { 
  333. $query_args['is_new_install'] = '1'; 
  334. delete_transient( '_bp_is_new_install' ); 
  335.  
  336. // Redirect to BuddyPress about page. 
  337. wp_safe_redirect( add_query_arg( $query_args, bp_get_admin_url( 'index.php' ) ) ); 
  338.  
  339. /** UI/Styling ****************************************************************/ 
  340.  
  341. /** 
  342. * Output the tabs in the admin area. 
  343. * 
  344. * @since 1.5.0 
  345. * 
  346. * @param string $active_tab Name of the tab that is active. Optional. 
  347. */ 
  348. function bp_core_admin_tabs( $active_tab = '' ) { 
  349. $tabs_html = ''; 
  350. $idle_class = 'nav-tab'; 
  351. $active_class = 'nav-tab nav-tab-active'; 
  352.  
  353. /** 
  354. * Filters the admin tabs to be displayed. 
  355. * 
  356. * @since 1.9.0 
  357. * 
  358. * @param array $value Array of tabs to output to the admin area. 
  359. */ 
  360. $tabs = apply_filters( 'bp_core_admin_tabs', bp_core_get_admin_tabs( $active_tab ) ); 
  361.  
  362. // Loop through tabs and build navigation. 
  363. foreach ( array_values( $tabs ) as $tab_data ) { 
  364. $is_current = (bool) ( $tab_data['name'] == $active_tab ); 
  365. $tab_class = $is_current ? $active_class : $idle_class; 
  366. $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>'; 
  367.  
  368. echo $tabs_html; 
  369.  
  370. /** 
  371. * Fires after the output of tabs for the admin area. 
  372. * 
  373. * @since 1.5.0 
  374. */ 
  375. do_action( 'bp_admin_tabs' ); 
  376.  
  377. /** 
  378. * Get the data for the tabs in the admin area. 
  379. * 
  380. * @since 2.2.0 
  381. * 
  382. * @param string $active_tab Name of the tab that is active. Optional. 
  383. * @return string 
  384. */ 
  385. function bp_core_get_admin_tabs( $active_tab = '' ) { 
  386. $tabs = array( 
  387. '0' => array( 
  388. 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components' ), 'admin.php' ) ),  
  389. 'name' => __( 'Components', 'buddypress' ) 
  390. ),  
  391. '1' => array( 
  392. 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ),  
  393. 'name' => __( 'Pages', 'buddypress' ) 
  394. ),  
  395. '2' => array( 
  396. 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ),  
  397. 'name' => __( 'Options', 'buddypress' ) 
  398. ),  
  399. ); 
  400.  
  401. // If forums component is active, add additional tab. 
  402. if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) { 
  403.  
  404. // Enqueue thickbox. 
  405. wp_enqueue_script( 'thickbox' ); 
  406. wp_enqueue_style( 'thickbox' ); 
  407.  
  408. $tabs['3'] = array( 
  409. 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup' ), 'admin.php' ) ),  
  410. 'name' => __( 'Forums', 'buddypress' ) 
  411. ); 
  412.  
  413. /** 
  414. * Filters the tab data used in our wp-admin screens. 
  415. * 
  416. * @since 2.2.0 
  417. * 
  418. * @param array $tabs Tab data. 
  419. */ 
  420. return apply_filters( 'bp_core_get_admin_tabs', $tabs ); 
  421.  
  422. /** Help **********************************************************************/ 
  423.  
  424. /** 
  425. * Adds contextual help to BuddyPress admin pages. 
  426. * 
  427. * @since 1.7.0 
  428. * @todo Make this part of the BP_Component class and split into each component. 
  429. * 
  430. * @param string $screen Current screen. 
  431. */ 
  432. function bp_core_add_contextual_help( $screen = '' ) { 
  433.  
  434. $screen = get_current_screen(); 
  435.  
  436. switch ( $screen->id ) { 
  437.  
  438. // Component page. 
  439. case 'settings_page_bp-components' : 
  440.  
  441. // Help tabs. 
  442. $screen->add_help_tab( array( 
  443. 'id' => 'bp-comp-overview',  
  444. 'title' => __( 'Overview', 'buddypress' ),  
  445. 'content' => bp_core_add_contextual_help_content( 'bp-comp-overview' ),  
  446. ) ); 
  447.  
  448. // Help panel - sidebar links. 
  449. $screen->set_help_sidebar( 
  450. '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 
  451. '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/">Managing Components</a>', 'buddypress' ) . '</p>' . 
  452. '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 
  453. ); 
  454. break; 
  455.  
  456. // Pages page. 
  457. case 'settings_page_bp-page-settings' : 
  458.  
  459. // Help tabs. 
  460. $screen->add_help_tab( array( 
  461. 'id' => 'bp-page-overview',  
  462. 'title' => __( 'Overview', 'buddypress' ),  
  463. 'content' => bp_core_add_contextual_help_content( 'bp-page-overview' ),  
  464. ) ); 
  465.  
  466. // Help panel - sidebar links. 
  467. $screen->set_help_sidebar( 
  468. '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 
  469. '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/#settings-buddypress-pages">Managing Pages</a>', 'buddypress' ) . '</p>' . 
  470. '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 
  471. ); 
  472.  
  473. break; 
  474.  
  475. // Settings page. 
  476. case 'settings_page_bp-settings' : 
  477.  
  478. // Help tabs. 
  479. $screen->add_help_tab( array( 
  480. 'id' => 'bp-settings-overview',  
  481. 'title' => __( 'Overview', 'buddypress' ),  
  482. 'content' => bp_core_add_contextual_help_content( 'bp-settings-overview' ),  
  483. ) ); 
  484.  
  485. // Help panel - sidebar links. 
  486. $screen->set_help_sidebar( 
  487. '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 
  488. '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/#settings-buddypress-settings">Managing Settings</a>', 'buddypress' ) . '</p>' . 
  489. '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 
  490. ); 
  491.  
  492. break; 
  493.  
  494. // Profile fields page. 
  495. case 'users_page_bp-profile-setup' : 
  496.  
  497. // Help tabs. 
  498. $screen->add_help_tab( array( 
  499. 'id' => 'bp-profile-overview',  
  500. 'title' => __( 'Overview', 'buddypress' ),  
  501. 'content' => bp_core_add_contextual_help_content( 'bp-profile-overview' ),  
  502. ) ); 
  503.  
  504. // Help panel - sidebar links. 
  505. $screen->set_help_sidebar( 
  506. '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' . 
  507. '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/extended-profiles/">Managing Profile Fields</a>', 'buddypress' ) . '</p>' . 
  508. '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>' 
  509. ); 
  510.  
  511. break; 
  512. add_action( 'load-settings_page_bp-components', 'bp_core_add_contextual_help' ); 
  513. add_action( 'load-settings_page_bp-page-settings', 'bp_core_add_contextual_help' ); 
  514. add_action( 'load-settings_page_bp-settings', 'bp_core_add_contextual_help' ); 
  515. add_action( 'load-users_page_bp-profile-setup', 'bp_core_add_contextual_help' ); 
  516.  
  517. /** 
  518. * Renders contextual help content to contextual help tabs. 
  519. * 
  520. * @since 1.7.0 
  521. * 
  522. * @param string $tab Current help content tab. 
  523. * @return string 
  524. */ 
  525. function bp_core_add_contextual_help_content( $tab = '' ) { 
  526.  
  527. switch ( $tab ) { 
  528. case 'bp-comp-overview' : 
  529. $retval = __( 'By default, all but four of the BuddyPress components are enabled. You can selectively enable or disable any of the components by using the form below. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ); 
  530. break; 
  531.  
  532. case 'bp-page-overview' : 
  533. $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. You can change the page associations for each active component by using the form below.', 'buddypress' ); 
  534. break; 
  535.  
  536. case 'bp-settings-overview' : 
  537. $retval = __( 'Extra configuration settings are provided and activated. You can selectively enable or disable any setting by using the form on this screen.', 'buddypress' ); 
  538. break; 
  539.  
  540. case 'bp-profile-overview' : 
  541. $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Any fields in the first group will appear on the signup page.', 'buddypress' ); 
  542. break; 
  543.  
  544. default: 
  545. $retval = false; 
  546. break; 
  547.  
  548. // Wrap text in a paragraph tag. 
  549. if ( !empty( $retval ) ) { 
  550. $retval = '<p>' . $retval . '</p>'; 
  551.  
  552. return $retval; 
  553.  
  554. /** Separator *****************************************************************/ 
  555.  
  556. /** 
  557. * Add a separator to the WordPress admin menus. 
  558. * 
  559. * @since 1.7.0 
  560. * 
  561. */ 
  562. function bp_admin_separator() { 
  563.  
  564. // Bail if BuddyPress is not network activated and viewing network admin. 
  565. if ( is_network_admin() && ! bp_is_network_activated() ) { 
  566. return; 
  567.  
  568. // Bail if BuddyPress is network activated and viewing site admin. 
  569. if ( ! is_network_admin() && bp_is_network_activated() ) { 
  570. return; 
  571.  
  572. // Prevent duplicate separators when no core menu items exist. 
  573. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  574. return; 
  575.  
  576. // Bail if there are no components with admin UI's. Hardcoded for now, until 
  577. // there's a real API for determining this later. 
  578. if ( ! bp_is_active( 'activity' ) && ! bp_is_active( 'groups' ) ) { 
  579. return; 
  580.  
  581. global $menu; 
  582.  
  583. $menu[] = array( '', 'read', 'separator-buddypress', '', 'wp-menu-separator buddypress' ); 
  584.  
  585. /** 
  586. * Tell WordPress we have a custom menu order. 
  587. * 
  588. * @since 1.7.0 
  589. * 
  590. * @param bool $menu_order Menu order. 
  591. * @return bool Always true. 
  592. */ 
  593. function bp_admin_custom_menu_order( $menu_order = false ) { 
  594.  
  595. // Bail if user cannot see admin pages. 
  596. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  597. return $menu_order; 
  598.  
  599. return true; 
  600.  
  601. /** 
  602. * Move our custom separator above our custom post types. 
  603. * 
  604. * @since 1.7.0 
  605. * 
  606. * @param array $menu_order Menu Order. 
  607. * @return array Modified menu order. 
  608. */ 
  609. function bp_admin_menu_order( $menu_order = array() ) { 
  610.  
  611. // Bail if user cannot see admin pages. 
  612. if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) ) { 
  613. return $menu_order; 
  614.  
  615. // Initialize our custom order array. 
  616. $bp_menu_order = array(); 
  617.  
  618. // Menu values. 
  619. $last_sep = is_network_admin() ? 'separator1' : 'separator2'; 
  620.  
  621. /** 
  622. * Filters the custom admin menus. 
  623. * 
  624. * @since 1.7.0 
  625. * 
  626. * @param array $value Empty array. 
  627. */ 
  628. $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() ); 
  629.  
  630. // Bail if no components have top level admin pages. 
  631. if ( empty( $custom_menus ) ) { 
  632. return $menu_order; 
  633.  
  634. // Add our separator to beginning of array. 
  635. array_unshift( $custom_menus, 'separator-buddypress' ); 
  636.  
  637. // Loop through menu order and do some rearranging. 
  638. foreach ( (array) $menu_order as $item ) { 
  639.  
  640. // Position BuddyPress menus above appearance. 
  641. if ( $last_sep == $item ) { 
  642.  
  643. // Add our custom menus. 
  644. foreach( (array) $custom_menus as $custom_menu ) { 
  645. if ( array_search( $custom_menu, $menu_order ) ) { 
  646. $bp_menu_order[] = $custom_menu; 
  647.  
  648. // Add the appearance separator. 
  649. $bp_menu_order[] = $last_sep; 
  650.  
  651. // Skip our menu items. 
  652. } elseif ( ! in_array( $item, $custom_menus ) ) { 
  653. $bp_menu_order[] = $item; 
  654.  
  655. // Return our custom order. 
  656. return $bp_menu_order; 
  657.  
  658. /** Utility *****************************************************************/ 
  659.  
  660. /** 
  661. * When using a WP_List_Table, get the currently selected bulk action. 
  662. * 
  663. * WP_List_Tables have bulk actions at the top and at the bottom of the tables,  
  664. * and the inputs have different keys in the $_REQUEST array. This function 
  665. * reconciles the two values and returns a single action being performed. 
  666. * 
  667. * @since 1.7.0 
  668. * 
  669. * @return string 
  670. */ 
  671. function bp_admin_list_table_current_bulk_action() { 
  672.  
  673. $action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; 
  674.  
  675. // If the bottom is set, let it override the action. 
  676. if ( ! empty( $_REQUEST['action2'] ) && $_REQUEST['action2'] != "-1" ) { 
  677. $action = $_REQUEST['action2']; 
  678.  
  679. return $action; 
  680.  
  681. /** Menus *********************************************************************/ 
  682.  
  683. /** 
  684. * Register meta box and associated JS for BuddyPress WP Nav Menu. 
  685. * 
  686. * @since 1.9.0 
  687. */ 
  688. function bp_admin_wp_nav_menu_meta_box() { 
  689. if ( ! bp_is_root_blog() ) { 
  690. return; 
  691.  
  692. add_meta_box( 'add-buddypress-nav-menu', __( 'BuddyPress', 'buddypress' ), 'bp_admin_do_wp_nav_menu_meta_box', 'nav-menus', 'side', 'default' ); 
  693.  
  694. add_action( 'admin_print_footer_scripts', 'bp_admin_wp_nav_menu_restrict_items' ); 
  695.  
  696. /** 
  697. * Build and populate the BuddyPress accordion on Appearance > Menus. 
  698. * 
  699. * @since 1.9.0 
  700. * 
  701. * @global $nav_menu_selected_id 
  702. */ 
  703. function bp_admin_do_wp_nav_menu_meta_box() { 
  704. global $nav_menu_selected_id; 
  705.  
  706. $walker = new BP_Walker_Nav_Menu_Checklist( false ); 
  707. $args = array( 'walker' => $walker ); 
  708.  
  709. $post_type_name = 'buddypress'; 
  710.  
  711. $tabs = array(); 
  712.  
  713. $tabs['loggedin']['label'] = __( 'Logged-In', 'buddypress' ); 
  714. $tabs['loggedin']['pages'] = bp_nav_menu_get_loggedin_pages(); 
  715.  
  716. $tabs['loggedout']['label'] = __( 'Logged-Out', 'buddypress' ); 
  717. $tabs['loggedout']['pages'] = bp_nav_menu_get_loggedout_pages(); 
  718.  
  719. ?> 
  720.  
  721. <div id="buddypress-menu" class="posttypediv"> 
  722. <h4><?php _e( 'Logged-In', 'buddypress' ) ?></h4> 
  723. <p><?php _e( '<em>Logged-In</em> links are relative to the current user, and are not visible to visitors who are not logged in.', 'buddypress' ) ?></p> 
  724.  
  725. <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-loggedin" class="tabs-panel tabs-panel-active"> 
  726. <ul id="buddypress-menu-checklist-loggedin" class="categorychecklist form-no-clear"> 
  727. <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $tabs['loggedin']['pages'] ), 0, (object) $args );?> 
  728. </ul> 
  729. </div> 
  730.  
  731. <h4><?php _e( 'Logged-Out', 'buddypress' ) ?></h4> 
  732. <p><?php _e( '<em>Logged-Out</em> links are not visible to users who are logged in.', 'buddypress' ) ?></p> 
  733.  
  734. <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-loggedout" class="tabs-panel tabs-panel-active"> 
  735. <ul id="buddypress-menu-checklist-loggedout" class="categorychecklist form-no-clear"> 
  736. <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $tabs['loggedout']['pages'] ), 0, (object) $args );?> 
  737. </ul> 
  738. </div> 
  739.  
  740. <?php 
  741. $removed_args = array( 
  742. 'action',  
  743. 'customlink-tab',  
  744. 'edit-menu-item',  
  745. 'menu-item',  
  746. 'page-tab',  
  747. '_wpnonce',  
  748. ); 
  749. ?> 
  750.  
  751. <p class="button-controls"> 
  752. <span class="list-controls"> 
  753. <a href="<?php 
  754. echo esc_url( add_query_arg( 
  755. array( 
  756. $post_type_name . '-tab' => 'all',  
  757. 'selectall' => 1,  
  758. ),  
  759. remove_query_arg( $removed_args ) 
  760. ) ); 
  761. ?>#buddypress-menu" class="select-all"><?php _e( 'Select All', 'buddypress' ); ?></a> 
  762. </span> 
  763. <span class="add-to-menu"> 
  764. <input type="submit"<?php if ( function_exists( 'wp_nav_menu_disabled_check' ) ) : wp_nav_menu_disabled_check( $nav_menu_selected_id ); endif; ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'buddypress' ); ?>" name="add-custom-menu-item" id="submit-buddypress-menu" /> 
  765. <span class="spinner"></span> 
  766. </span> 
  767. </p> 
  768. </div><!-- /#buddypress-menu --> 
  769.  
  770. <?php 
  771.  
  772. /** 
  773. * In admin emails list, for non-en_US locales, add notice explaining how to reinstall emails. 
  774. * 
  775. * If BuddyPress installs before its translations are in place, tell people how to reinstall 
  776. * the emails so they have their contents in their site's language. 
  777. * 
  778. * @since 2.5.0 
  779. */ 
  780. function bp_admin_email_maybe_add_translation_notice() { 
  781. if ( get_current_screen()->post_type !== bp_get_email_post_type() || get_locale() === 'en_US' ) { 
  782. return; 
  783.  
  784. // If user can't access BP Tools, there's no point showing the message. 
  785. if ( ! current_user_can( buddypress()->admin->capability ) ) { 
  786. return; 
  787.  
  788. if ( bp_core_do_network_admin() ) { 
  789. $admin_page = 'admin.php'; 
  790. } else { 
  791. $admin_page = 'tools.php'; 
  792.  
  793. bp_core_add_admin_notice( 
  794. sprintf( 
  795. __( 'Are your emails in the wrong language? Go to <a href="%s">BuddyPress Tools and run the "reinstall emails"</a> tool.', 'buddypress' ),  
  796. esc_url( add_query_arg( 'page', 'bp-tools', bp_get_admin_url( $admin_page ) ) ) 
  797. ),  
  798. 'updated' 
  799. ); 
  800. add_action( 'admin_head-edit.php', 'bp_admin_email_maybe_add_translation_notice' ); 
  801.  
  802. /** 
  803. * In emails editor, add notice linking to token documentation on Codex. 
  804. * 
  805. * @since 2.5.0 
  806. */ 
  807. function bp_admin_email_add_codex_notice() { 
  808. if ( get_current_screen()->post_type !== bp_get_email_post_type() ) { 
  809. return; 
  810.  
  811. bp_core_add_admin_notice( 
  812. sprintf( 
  813. __( 'Phrases wrapped in braces <code>{{ }}</code> are email tokens. <a href="%s">Learn about tokens on the BuddyPress Codex</a>.', 'buddypress' ),  
  814. esc_url( 'https://codex.buddypress.org/emails/email-tokens/' ) 
  815. ),  
  816. 'error' 
  817. ); 
  818. add_action( 'admin_head-post.php', 'bp_admin_email_add_codex_notice' ); 
  819.  
  820. /** 
  821. * Display metabox for email taxonomy type. 
  822. * 
  823. * Shows the term description in a list, rather than the term name itself. 
  824. * 
  825. * @since 2.5.0 
  826. * 
  827. * @param WP_Post $post Post object. 
  828. * @param array $box { 
  829. * Tags meta box arguments. 
  830. * 
  831. * @type string $id Meta box ID. 
  832. * @type string $title Meta box title. 
  833. * @type callable $callback Meta box display callback. 
  834. * } 
  835. */ 
  836. function bp_email_tax_type_metabox( $post, $box ) { 
  837. $r = array( 
  838. 'taxonomy' => bp_get_email_tax_type() 
  839. ); 
  840.  
  841. $tax_name = esc_attr( $r['taxonomy'] ); 
  842. $taxonomy = get_taxonomy( $r['taxonomy'] ); 
  843. ?> 
  844. <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> 
  845. <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> 
  846. <?php 
  847. $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; 
  848. echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
  849. ?> 
  850. <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> 
  851. <?php wp_terms_checklist( $post->ID, array( 'taxonomy' => $tax_name, 'walker' => new BP_Walker_Category_Checklist ) ); ?> 
  852. </ul> 
  853. </div> 
  854.  
  855. <p><?php esc_html_e( 'Choose when this email will be sent.', 'buddypress' ); ?></p> 
  856. </div> 
  857. <?php 
  858.  
  859. /** 
  860. * Custom metaboxes used by our 'bp-email' post type. 
  861. * 
  862. * @since 2.5.0 
  863. */ 
  864. function bp_email_custom_metaboxes() { 
  865. // Remove default 'Excerpt' metabox and replace with our own. 
  866. remove_meta_box( 'postexcerpt', null, 'normal' ); 
  867. add_meta_box( 'postexcerpt', __( 'Plain text email content', 'buddypress' ), 'bp_email_plaintext_metabox', null, 'normal', 'high' ); 
  868. add_action( 'add_meta_boxes_' . bp_get_email_post_type(), 'bp_email_custom_metaboxes' ); 
  869.  
  870. /** 
  871. * Customized version of the 'Excerpt' metabox for our 'bp-email' post type. 
  872. * 
  873. * We are using the 'Excerpt' metabox as our plain-text email content editor. 
  874. * 
  875. * @since 2.5.0 
  876. * 
  877. * @param WP_Post $post 
  878. */ 
  879. function bp_email_plaintext_metabox( $post ) { 
  880. ?> 
  881.  
  882. <label class="screen-reader-text" for="excerpt"><?php 
  883. /** translators: accessibility text */ 
  884. _e( 'Plain text email content', 'buddypress' ); 
  885. ?></label><textarea rows="5" cols="40" name="excerpt" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea> 
  886.  
  887. <p><?php _e( 'Most email clients support HTML email. However, some people prefer to receive plain text email. Enter a plain text alternative version of your email here.', 'buddypress' ); ?></p> 
  888.  
  889. <?php 
  890.  
  891. /** 
  892. * Restrict various items from view if editing a BuddyPress menu. 
  893. * 
  894. * If a person is editing a BP menu item, that person should not be able to 
  895. * see or edit the following fields: 
  896. * 
  897. * - CSS Classes - We use the 'bp-menu' CSS class to determine if the 
  898. * menu item belongs to BP, so we cannot allow manipulation of this field to 
  899. * occur. 
  900. * - URL - This field is automatically generated by BP on output, so this 
  901. * field is useless and can cause confusion. 
  902. * 
  903. * Note: These restrictions are only enforced if JavaScript is enabled. 
  904. * 
  905. * @since 1.9.0 
  906. */ 
  907. function bp_admin_wp_nav_menu_restrict_items() { 
  908. ?> 
  909. <script type="text/javascript"> 
  910. jQuery( '#menu-to-edit').on( 'click', 'a.item-edit', function() { 
  911. var settings = jQuery(this).closest( '.menu-item-bar' ).next( '.menu-item-settings' ); 
  912. var css_class = settings.find( '.edit-menu-item-classes' ); 
  913.  
  914. if( css_class.val().indexOf( 'bp-menu' ) === 0 ) { 
  915. css_class.attr( 'readonly', 'readonly' ); 
  916. settings.find( '.field-url' ).css( 'display', 'none' ); 
  917. }); 
  918. </script> 
  919. <?php 
  920.  
  921. /** 
  922. * Add "Mark as Spam/Ham" button to user row actions. 
  923. * 
  924. * @since 2.0.0 
  925. * 
  926. * @param array $actions User row action links. 
  927. * @param object $user_object Current user information. 
  928. * @return array $actions User row action links. 
  929. */ 
  930. function bp_core_admin_user_row_actions( $actions, $user_object ) { 
  931.  
  932. // Setup the $user_id variable from the current user object. 
  933. $user_id = 0; 
  934. if ( !empty( $user_object->ID ) ) { 
  935. $user_id = absint( $user_object->ID ); 
  936.  
  937. // Bail early if user cannot perform this action, or is looking at themselves. 
  938. if ( current_user_can( 'edit_user', $user_id ) && ( bp_loggedin_user_id() !== $user_id ) ) { 
  939.  
  940. // Admin URL could be single site or network. 
  941. $url = bp_get_admin_url( 'users.php' ); 
  942.  
  943. // If spammed, create unspam link. 
  944. if ( bp_is_user_spammer( $user_id ) ) { 
  945. $url = add_query_arg( array( 'action' => 'ham', 'user' => $user_id ), $url ); 
  946. $unspam_link = wp_nonce_url( $url, 'bp-spam-user' ); 
  947. $actions['ham'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $unspam_link ), esc_html__( 'Not Spam', 'buddypress' ) ); 
  948.  
  949. // If not already spammed, create spam link. 
  950. } else { 
  951. $url = add_query_arg( array( 'action' => 'spam', 'user' => $user_id ), $url ); 
  952. $spam_link = wp_nonce_url( $url, 'bp-spam-user' ); 
  953. $actions['spam'] = sprintf( '<a class="submitdelete" href="%1$s">%2$s</a>', esc_url( $spam_link ), esc_html__( 'Spam', 'buddypress' ) ); 
  954.  
  955. // Create a "View" link. 
  956. $url = bp_core_get_user_domain( $user_id ); 
  957. $actions['view'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $url ), esc_html__( 'View', 'buddypress' ) ); 
  958.  
  959. // Return new actions. 
  960. return $actions; 
  961.  
  962. /** 
  963. * Catch requests to mark individual users as spam/ham from users.php. 
  964. * 
  965. * @since 2.0.0 
  966. */ 
  967. function bp_core_admin_user_manage_spammers() { 
  968.  
  969. // Print our inline scripts on non-Multisite. 
  970. add_action( 'admin_footer', 'bp_core_admin_user_spammed_js' ); 
  971.  
  972. $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false; 
  973. $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false; 
  974. $mode = isset( $_POST['mode'] ) ? $_POST['mode'] : false; 
  975.  
  976. // If this is a multisite, bulk request, stop now! 
  977. if ( 'list' == $mode ) { 
  978. return; 
  979.  
  980. // Process a spam/ham request. 
  981. if ( ! empty( $action ) && in_array( $action, array( 'spam', 'ham' ) ) ) { 
  982.  
  983. check_admin_referer( 'bp-spam-user' ); 
  984.  
  985. $user_id = ! empty( $_REQUEST['user'] ) ? intval( $_REQUEST['user'] ) : false; 
  986.  
  987. if ( empty( $user_id ) ) { 
  988. return; 
  989.  
  990. $redirect = wp_get_referer(); 
  991.  
  992. $status = ( $action == 'spam' ) ? 'spam' : 'ham'; 
  993.  
  994. // Process the user. 
  995. bp_core_process_spammer_status( $user_id, $status ); 
  996.  
  997. $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect ); 
  998.  
  999. wp_redirect( $redirect ); 
  1000.  
  1001. // Display feedback. 
  1002. if ( ! empty( $updated ) && in_array( $updated, array( 'marked-spam', 'marked-ham' ) ) ) { 
  1003.  
  1004. if ( 'marked-spam' === $updated ) { 
  1005. $notice = __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ); 
  1006. } else { 
  1007. $notice = __( 'User removed from spam.', 'buddypress' ); 
  1008.  
  1009. bp_core_add_admin_notice( $notice ); 
  1010.  
  1011. /** 
  1012. * Inline script that adds the 'site-spammed' class to spammed users. 
  1013. * 
  1014. * @since 2.0.0 
  1015. */ 
  1016. function bp_core_admin_user_spammed_js() { 
  1017. ?> 
  1018. <script type="text/javascript"> 
  1019. jQuery( document ).ready( function($) { 
  1020. $( '.row-actions .ham' ).each( function() { 
  1021. $( this ).closest( 'tr' ).addClass( 'site-spammed' ); 
  1022. }); 
  1023. }); 
  1024. </script> 
  1025. <?php 
  1026.  
  1027. /** 
  1028. * Catch and process an admin notice dismissal. 
  1029. * 
  1030. * @since 2.7.0 
  1031. */ 
  1032. function bp_core_admin_notice_dismiss_callback() { 
  1033. if ( ! current_user_can( 'install_plugins' ) ) { 
  1034. wp_send_json_error(); 
  1035.  
  1036. if ( empty( $_POST['nonce'] ) || empty( $_POST['notice_id'] ) ) { 
  1037. wp_send_json_error(); 
  1038.  
  1039. $notice_id = wp_unslash( $_POST['notice_id'] ); 
  1040.  
  1041. if ( ! wp_verify_nonce( $_POST['nonce'], 'bp-dismissible-notice-' . $notice_id ) ) { 
  1042. wp_send_json_error(); 
  1043.  
  1044. bp_update_option( "bp-dismissed-notice-$notice_id", 1 ); 
  1045.  
  1046. wp_send_json_success(); 
  1047. add_action( 'wp_ajax_bp_dismiss_notice', 'bp_core_admin_notice_dismiss_callback' ); 
  1048.  
  1049. /** 
  1050. * Add a "buddypress" class to body element of wp-admin. 
  1051. * 
  1052. * @since 2.8.0 
  1053. * 
  1054. * @param string $classes CSS classes for the body tag in the admin, a comma separated string. 
  1055. * 
  1056. * @return string 
  1057. */ 
  1058. function bp_core_admin_body_classes( $classes ) { 
  1059. return $classes . ' buddypress'; 
  1060. add_filter( 'admin_body_class', 'bp_core_admin_body_classes' ); 
.