bp_core_activation_notice

Verify that some BP prerequisites are set up properly, and notify the admin if not.

Description

bp_core_activation_notice(); 

On every Dashboard page, this function checks the following: - that pretty permalinks are enabled. - that every BP component that needs a WP page for a directory has one. - that no WP page has multiple BP components associated with it. The administrator will be shown a notice for each check that fails.


Usage

  1. if ( !function_exists( 'bp_core_activation_notice' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/admin/bp-core-admin-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_activation_notice(); 
  7.  

Defined (1)

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

/bp-core/admin/bp-core-admin-functions.php  
  1. function bp_core_activation_notice() { 
  2. global $wp_rewrite, $wpdb; 
  3.  
  4. // Only the super admin gets warnings. 
  5. if ( ! bp_current_user_can( 'bp_moderate' ) ) { 
  6. return; 
  7.  
  8. // Bail in user admin. 
  9. if ( is_user_admin() ) { 
  10. return; 
  11.  
  12. // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden. 
  13. if ( is_multisite() && bp_core_do_network_admin() && ! bp_is_root_blog() ) { 
  14. return; 
  15.  
  16. // Bail if in network admin, and BuddyPress is not network activated. 
  17. if ( is_network_admin() && ! bp_is_network_activated() ) { 
  18. return; 
  19.  
  20. /** 
  21. * Check to make sure that the blog setup routine has run. This can't 
  22. * happen during the wizard because of the order which the components 
  23. * are loaded. 
  24. */ 
  25. if ( bp_is_active( 'blogs' ) ) { 
  26. $bp =buddypress); 
  27. $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ); 
  28.  
  29. if ( empty( $count ) ) { 
  30.  
  31. // Add notice if no rewrite rules are enabled. 
  32. if ( empty( $wp_rewrite->permalink_structure ) ) { 
  33. 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 ); 
  34.  
  35. // Get BuddyPress instance. 
  36. $bp =buddypress); 
  37.  
  38. /** 
  39. * Check for orphaned BP components (BP component is enabled, no WP page exists). 
  40. */ 
  41. $orphaned_components = array(); 
  42. $wp_page_components = array(); 
  43.  
  44. // Only components with 'has_directory' require a WP page to function. 
  45. foreach( array_keys( $bp->loaded_components ) as $component_id ) { 
  46. if ( !empty( $bp->{$component_id}->has_directory ) ) { 
  47. $wp_page_components[] = array( 
  48. 'id' => $component_id,  
  49. 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id ) 
  50. ); 
  51.  
  52. // Activate and Register are special cases. They are not components but they need WP pages. 
  53. // If user registration is disabled, we can skip this step. 
  54. if ( bp_get_signup_allowed() ) { 
  55. $wp_page_components[] = array( 
  56. 'id' => 'activate',  
  57. 'name' => __( 'Activate', buddypress ) 
  58. ); 
  59.  
  60. $wp_page_components[] = array( 
  61. 'id' => 'register',  
  62. 'name' => __( 'Register', buddypress ) 
  63. ); 
  64.  
  65. // On the first admin screen after a new installation, this isn't set, so grab it to suppress 
  66. // a misleadingerrormessage. 
  67. if ( empty( $bp->pages->members ) ) { 
  68. $bp->pages = bp_core_get_directory_pages(); 
  69.  
  70. foreach( $wp_page_components as $component ) { 
  71. if ( !isset( $bp->pages->{$component['id']} ) ) { 
  72. $orphaned_components[] = $component['name']; 
  73.  
  74. // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is 
  75. // not correctly set up, don't show a nag. (In these cases, it's probably the case that the 
  76. // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292. 
  77. if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) { 
  78. $forum_key = array_search( $bp->forums->name, $orphaned_components ); 
  79. unset( $orphaned_components[$forum_key] ); 
  80. $orphaned_components = array_values( $orphaned_components ); 
  81.  
  82. if ( !empty( $orphaned_components ) ) { 
  83. $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ); 
  84. $notice = sprintf( 
  85. '%1$s <a href="%2$s">%3$s</a>',  
  86. sprintf( 
  87. __( 'The following active BuddyPress Components do not have associated WordPress Pages: %s.', buddypress ),  
  88. '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>' 
  89. ),  
  90. esc_url( $admin_url ),  
  91. __( 'Repair', buddypress ) 
  92. ); 
  93.  
  94.  
  95. // BP components cannot share a single WP page. Check for duplicate assignments, and post a message if found. 
  96. $dupe_names = array(); 
  97. $page_ids = (array)bp_core_get_directory_page_ids(); 
  98. $dupes = array_diff_assoc( $page_ids, array_unique( $page_ids ) ); 
  99.  
  100. if ( !empty( $dupes ) ) { 
  101. foreach( array_keys( $dupes ) as $dupe_component ) { 
  102. $dupe_names[] = $bp->pages->{$dupe_component}->title; 
  103.  
  104. // Make sure that there are no duplicate duplicates :). 
  105. $dupe_names = array_unique( $dupe_names ); 
  106.  
  107. // If there are duplicates, post a message about them. 
  108. if ( !empty( $dupe_names ) ) { 
  109. $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ); 
  110. $notice = sprintf( 
  111. '%1$s <a href="%2$s">%3$s</a>',  
  112. sprintf( 
  113. __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %s.', buddypress ),  
  114. '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $dupe_names ) ) . '</strong>' 
  115. ),  
  116. esc_url( $admin_url ),  
  117. __( 'Repair', buddypress ) 
  118. ); 
  119.