[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/admin/ -> bp-core-admin-tools.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Tools panel.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Core
   7   * @since 2.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Render the BuddyPress Tools page.
  15   *
  16   * @since 2.0.0
  17   */
  18  function bp_core_admin_tools() {
  19      ?>
  20      <div class="wrap">
  21  
  22          <h1 class="wp-heading-inline"><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h1>
  23          <hr class="wp-header-end">
  24  
  25          <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Repair', 'buddypress' ), 'tools' ); ?></h2>
  26  
  27          <p><?php esc_html_e( 'BuddyPress keeps track of various relationships between members, groups, and activity items.', 'buddypress' ); ?></p>
  28          <p><?php esc_html_e( 'Occasionally these relationships become out of sync, most often after an import, update, or migration.', 'buddypress' ); ?></p>
  29          <p><?php esc_html_e( 'Use the tools below to manually recalculate these relationships.', 'buddypress' ); ?>
  30          </p>
  31          <p class="attention"><?php esc_html_e( 'Some of these tools create substantial database overhead. Avoid running more than one repair job at a time.', 'buddypress' ); ?></p>
  32  
  33          <h2><?php esc_html_e( 'Activate checkboxe(s) to select the operation(s) to perform', 'buddypress' ); ?></h2>
  34  
  35          <form class="settings" method="post" action="">
  36  
  37              <fieldset>
  38                  <legend class="screen-reader-text"><?php esc_html_e( 'Repair tools', 'buddypress' ); ?></legend>
  39  
  40                  <?php foreach ( bp_admin_repair_list() as $item ) : ?>
  41                      <p>
  42                          <label for="<?php echo esc_attr( str_replace( '_', '-', $item[0] ) ); ?>">
  43                              <input type="checkbox" class="checkbox" name="<?php echo esc_attr( $item[0] ) . '" id="' . esc_attr( str_replace( '_', '-', $item[0] ) ); ?>" value="1" /> <?php echo esc_html( $item[1] ); ?>
  44                          </label>
  45                      </p>
  46                  <?php endforeach; ?>
  47  
  48                  <p class="submit">
  49                      <input class="button-primary" type="submit" name="bp-tools-submit" value="<?php esc_attr_e( 'Repair Items', 'buddypress' ); ?>" />
  50                      <?php wp_nonce_field( 'bp-do-counts' ); ?>
  51                  </p>
  52  
  53              </fieldset>
  54  
  55          </form>
  56  
  57      </div>
  58  
  59      <?php
  60  }
  61  
  62  /**
  63   * Handle the processing and feedback of the admin tools page.
  64   *
  65   * @since 2.0.0
  66   */
  67  function bp_admin_repair_handler() {
  68      if ( ! bp_is_post_request() || empty( $_POST['bp-tools-submit'] ) ) {
  69          return;
  70      }
  71  
  72      check_admin_referer( 'bp-do-counts' );
  73  
  74      // Bail if user cannot moderate.
  75      $capability = bp_core_do_network_admin() ? 'manage_network_options' : 'manage_options';
  76      if ( ! bp_current_user_can( $capability ) ) {
  77          return;
  78      }
  79  
  80      wp_cache_flush();
  81      $messages = array();
  82  
  83      foreach ( (array) bp_admin_repair_list() as $item ) {
  84          if ( isset( $item[2] ) && isset( $_POST[$item[0]] ) && 1 === absint( $_POST[$item[0]] ) && is_callable( $item[2] ) ) {
  85              $messages[] = call_user_func( $item[2] );
  86          }
  87      }
  88  
  89      if ( count( $messages ) ) {
  90          foreach ( $messages as $message ) {
  91              bp_admin_tools_feedback( $message[1] );
  92          }
  93      }
  94  }
  95  add_action( bp_core_admin_hook(), 'bp_admin_repair_handler' );
  96  
  97  /**
  98   * Get the array of the repair list.
  99   *
 100   * @return array
 101   */
 102  function bp_admin_repair_list() {
 103      $repair_list = array();
 104  
 105      // Members:
 106      // - member count
 107      // - last_activity migration (2.0).
 108      $repair_list[20] = array(
 109          'bp-total-member-count',
 110          __( 'Repair total members count.', 'buddypress' ),
 111          'bp_admin_repair_count_members',
 112      );
 113  
 114      $repair_list[25] = array(
 115          'bp-last-activity',
 116          __( 'Repair member "last activity" data.', 'buddypress' ),
 117          'bp_admin_repair_last_activity',
 118      );
 119  
 120      // Friends:
 121      // - user friend count.
 122      if ( bp_is_active( 'friends' ) ) {
 123          $repair_list[0] = array(
 124              'bp-user-friends',
 125              __( 'Repair total friends count for each member.', 'buddypress' ),
 126              'bp_admin_repair_friend_count',
 127          );
 128      }
 129  
 130      // Groups:
 131      // - user group count.
 132      if ( bp_is_active( 'groups' ) ) {
 133          $repair_list[10] = array(
 134              'bp-group-count',
 135              __( 'Repair total groups count for each member.', 'buddypress' ),
 136              'bp_admin_repair_group_count',
 137          );
 138      }
 139  
 140      // Blogs:
 141      // - user blog count.
 142      if ( bp_is_active( 'blogs' ) ) {
 143          $repair_list[90] = array(
 144              'bp-blog-records',
 145              __( 'Repopulate site tracking records.', 'buddypress' ),
 146              'bp_admin_repair_blog_records',
 147          );
 148  
 149          if ( is_multisite() && bp_is_active( 'blogs', 'site-icon' ) ) {
 150              $repair_list[91] = array(
 151                  'bp-blog-site-icons',
 152                  __( 'Repair site tracking site icons/blog avatars synchronization.', 'buddypress' ),
 153                  'bp_admin_repair_blog_site_icons',
 154              );
 155          }
 156      }
 157  
 158      // Emails:
 159      // - reinstall emails.
 160      $repair_list[100] = array(
 161          'bp-reinstall-emails',
 162          __( 'Reinstall emails (delete and restore from defaults).', 'buddypress' ),
 163          'bp_admin_reinstall_emails',
 164      );
 165  
 166      // Invitations:
 167      // - maybe create the database table and migrate any existing group invitations.
 168      $repair_list[110] = array(
 169          'bp-invitations-table',
 170          __( 'Create the database table for Invitations and migrate existing group invitations if needed.', 'buddypress' ),
 171          'bp_admin_invitations_table',
 172      );
 173  
 174      ksort( $repair_list );
 175  
 176      /**
 177       * Filters the array of the repair list.
 178       *
 179       * @since 2.0.0
 180       *
 181       * @param array $repair_list Array of values for the Repair list options.
 182       */
 183      return (array) apply_filters( 'bp_repair_list', $repair_list );
 184  }
 185  
 186  /**
 187   * Recalculate friend counts for each user.
 188   *
 189   * @since 2.0.0
 190   *
 191   * @return array
 192   */
 193  function bp_admin_repair_friend_count() {
 194      global $wpdb;
 195  
 196      if ( ! bp_is_active( 'friends' ) ) {
 197          return;
 198      }
 199  
 200      /* translators: %s: the result of the action performed by the repair tool */
 201      $statement = __( 'Counting the number of friends for each user&hellip; %s', 'buddypress' );
 202      $result    = __( 'Failed!', 'buddypress' );
 203  
 204      $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_friend_count' );";
 205      if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
 206          return array( 1, sprintf( $statement, $result ) );
 207      }
 208  
 209      $bp = buddypress();
 210  
 211      // Walk through all users on the site.
 212      $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
 213  
 214      $updated = array();
 215      if ( $total_users > 0 ) {
 216          $per_query = 500;
 217          $offset = 0;
 218          while ( $offset < $total_users ) {
 219              // Only bother updating counts for users who actually have friendships.
 220              $friendships = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id FROM {$bp->friends->table_name} WHERE is_confirmed = 1 AND ( ( initiator_user_id > %d AND initiator_user_id <= %d ) OR ( friend_user_id > %d AND friend_user_id <= %d ) )", $offset, $offset + $per_query, $offset, $offset + $per_query ) );
 221  
 222              // The previous query will turn up duplicates, so we
 223              // filter them here.
 224              foreach ( $friendships as $friendship ) {
 225                  if ( ! isset( $updated[ $friendship->initiator_user_id ] ) ) {
 226                      BP_Friends_Friendship::total_friend_count( $friendship->initiator_user_id );
 227                      $updated[ $friendship->initiator_user_id ] = 1;
 228                  }
 229  
 230                  if ( ! isset( $updated[ $friendship->friend_user_id ] ) ) {
 231                      BP_Friends_Friendship::total_friend_count( $friendship->friend_user_id );
 232                      $updated[ $friendship->friend_user_id ] = 1;
 233                  }
 234              }
 235  
 236              $offset += $per_query;
 237          }
 238      } else {
 239          return array( 2, sprintf( $statement, $result ) );
 240      }
 241  
 242      return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
 243  }
 244  
 245  /**
 246   * Recalculate group counts for each user.
 247   *
 248   * @since 2.0.0
 249   *
 250   * @return array
 251   */
 252  function bp_admin_repair_group_count() {
 253      global $wpdb;
 254  
 255      if ( ! bp_is_active( 'groups' ) ) {
 256          return;
 257      }
 258  
 259      /* translators: %s: the result of the action performed by the repair tool */
 260      $statement = __( 'Counting the number of groups for each user&hellip; %s', 'buddypress' );
 261      $result    = __( 'Failed!', 'buddypress' );
 262  
 263      $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_group_count' );";
 264      if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
 265          return array( 1, sprintf( $statement, $result ) );
 266      }
 267  
 268      $bp = buddypress();
 269  
 270      // Walk through all users on the site.
 271      $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
 272  
 273      if ( $total_users > 0 ) {
 274          $per_query = 500;
 275          $offset = 0;
 276          while ( $offset < $total_users ) {
 277              // But only bother to update counts for users that have groups.
 278              $users = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 1 AND is_banned = 0 AND user_id > %d AND user_id <= %d", $offset, $offset + $per_query ) );
 279  
 280              foreach ( $users as $user ) {
 281                  BP_Groups_Member::refresh_total_group_count_for_user( $user );
 282              }
 283  
 284              $offset += $per_query;
 285          }
 286      } else {
 287          return array( 2, sprintf( $statement, $result ) );
 288      }
 289  
 290      return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
 291  }
 292  
 293  /**
 294   * Recalculate user-to-blog relationships and useful blog meta data.
 295   *
 296   * @since 2.1.0
 297   *
 298   * @return array
 299   */
 300  function bp_admin_repair_blog_records() {
 301  
 302      /* translators: %s: the result of the action performed by the repair tool */
 303      $statement = __( 'Repopulating Blogs records&hellip; %s', 'buddypress' );
 304  
 305      // Default to failure text.
 306      $result    = __( 'Failed!',   'buddypress' );
 307  
 308      // Default to unrepaired.
 309      $repair    = false;
 310  
 311      // Run function if blogs component is active.
 312      if ( bp_is_active( 'blogs' ) ) {
 313          $repair = bp_blogs_record_existing_blogs();
 314      }
 315  
 316      // Setup success/fail messaging.
 317      if ( true === $repair ) {
 318          $result = __( 'Complete!', 'buddypress' );
 319      }
 320  
 321      // All done!
 322      return array( 0, sprintf( $statement, $result ) );
 323  }
 324  
 325  /**
 326   * Repair site icons/blog avatars synchronization.
 327   *
 328   * @since 7.0.0
 329   *
 330   * @return array
 331   */
 332  function bp_admin_repair_blog_site_icons() {
 333  
 334      /* translators: %s: the result of the action performed by the repair tool */
 335      $statement = __( 'Repairing site icons/blog avatars synchronization&hellip; %s', 'buddypress' );
 336  
 337      if ( ! is_multisite() ) {
 338          return array( 0, sprintf( $statement, __( 'Failed!', 'buddypress' ) ) );
 339       }
 340  
 341      // Run function if blogs component is active.
 342      if ( bp_is_active( 'blogs', 'site-icon' ) ) {
 343          $blog_ids = get_sites(
 344              array(
 345                  'fields'   => 'ids',
 346                  'archived' => 0,
 347                  'mature'   => 0,
 348                  'spam'     => 0,
 349                  'deleted'  => 0,
 350              )
 351          );
 352  
 353          $sizes = array(
 354              array(
 355                  'key'  => 'site_icon_url_full',
 356                  'size' => bp_core_avatar_full_width(),
 357              ),
 358              array(
 359                  'key'  => 'site_icon_url_thumb',
 360                  'size' => bp_core_avatar_thumb_width(),
 361              ),
 362          );
 363  
 364          foreach ( $blog_ids as $blog_id ) {
 365              $site_icon = 0;
 366  
 367              foreach ( $sizes as $size ) {
 368                  $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size['size'] );
 369                  if ( ! $site_icon ) {
 370                      $site_icon = 0;
 371                  }
 372  
 373                  bp_blogs_update_blogmeta( $blog_id, $size['key'], $site_icon );
 374              }
 375          }
 376      }
 377  
 378      // All done!
 379      return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
 380  }
 381  
 382  /**
 383   * Recalculate the total number of active site members.
 384   *
 385   * @since 2.0.0
 386   */
 387  function bp_admin_repair_count_members() {
 388      /* translators: %s: the result of the action performed by the repair tool */
 389      $statement = __( 'Counting the number of active members on the site&hellip; %s', 'buddypress' );
 390      delete_transient( 'bp_active_member_count' );
 391      bp_core_get_active_member_count();
 392      return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
 393  }
 394  
 395  /**
 396   * Repair user last_activity data.
 397   *
 398   * Re-runs the migration from usermeta introduced in BP 2.0.
 399   *
 400   * @since 2.0.0
 401   */
 402  function bp_admin_repair_last_activity() {
 403      /* translators: %s: the result of the action performed by the repair tool */
 404      $statement = __( 'Determining last activity dates for each user&hellip; %s', 'buddypress' );
 405      bp_last_activity_migrate();
 406      return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
 407  }
 408  
 409  /**
 410   * Create the invitations database table if it does not exist.
 411   * Migrate outstanding group invitations if needed.
 412   *
 413   * @since 6.0.0
 414   *
 415   * @return array
 416   */
 417  function bp_admin_invitations_table() {
 418      global $wpdb;
 419  
 420      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
 421      require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 422  
 423      /* translators: %s: the result of the action performed by the repair tool */
 424      $statement = __( 'Creating the Invitations database table if it does not exist&hellip; %s', 'buddypress' );
 425      $result    = __( 'Failed to create table!', 'buddypress' );
 426  
 427      bp_core_install_invitations();
 428  
 429      // Check for existence of invitations table.
 430      $table_name = BP_Invitation_Manager::get_table_name();
 431      $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
 432      if ( ! $wpdb->get_var( $query ) == $table_name ) {
 433          // Early return if table creation failed.
 434          return array( 2, sprintf( $statement, $result ) );
 435      } else {
 436          $result = __( 'Created invitations table!', 'buddypress' );
 437      }
 438  
 439      // Migrate group invitations if needed.
 440      if ( bp_is_active( 'groups' ) ) {
 441          $bp = buddypress();
 442  
 443          /* translators: %s: the result of the action performed by the repair tool */
 444          $migrate_statement = __( 'Migrating group invitations&hellip; %s', 'buddypress' );
 445          $migrate_result    = __( 'Failed to migrate invitations!', 'buddypress' );
 446  
 447          bp_groups_migrate_invitations();
 448  
 449          // Check that there are no outstanding group invites in the group_members table.
 450          $records = $wpdb->get_results( "SELECT id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 0 AND is_banned = 0" );
 451          if ( empty( $records ) ) {
 452              $migrate_result = __( 'Migrated invitations!', 'buddypress' );
 453              return array( 0, sprintf( $statement . ' ' . $migrate_statement , $result, $migrate_result ) );
 454          } else {
 455              return array( 2, sprintf( $statement . ' ' . $migrate_statement , $result, $migrate_result ) );
 456          }
 457      }
 458  
 459      // Return a "create-only" success message.
 460      return array( 0, sprintf( $statement, $result ) );
 461  }
 462  
 463  /**
 464   * Assemble admin notices relating success/failure of repair processes.
 465   *
 466   * @since 2.0.0
 467   *
 468   * @param string      $message Feedback message.
 469   * @param string|bool $class   Unused.
 470   * @return false|Closure
 471   */
 472  function bp_admin_tools_feedback( $message, $class = false ) {
 473      if ( is_string( $message ) ) {
 474          $message = '<p>' . $message . '</p>';
 475          $class = $class ? $class : 'updated';
 476      } elseif ( is_wp_error( $message ) ) {
 477          $errors = $message->get_error_messages();
 478  
 479          switch ( count( $errors ) ) {
 480              case 0:
 481                  return false;
 482  
 483              case 1:
 484                  $message = '<p>' . $errors[0] . '</p>';
 485                  break;
 486  
 487              default:
 488                  $message = '<ul>' . "\n\t" . '<li>' . implode( '</li>' . "\n\t" . '<li>', $errors ) . '</li>' . "\n" . '</ul>';
 489                  break;
 490          }
 491  
 492          $class = $class ? $class : 'error';
 493      } else {
 494          return false;
 495      }
 496  
 497      $message = '<div id="message" class="' . esc_attr( $class ) . ' notice is-dismissible">' . $message . '</div>';
 498      $message = str_replace( "'", "\'", $message );
 499      $lambda  = function() use ( $message ) { echo $message; };
 500  
 501      add_action( bp_core_do_network_admin() ? 'network_admin_notices' : 'admin_notices', $lambda );
 502  
 503      return $lambda;
 504  }
 505  
 506  /**
 507   * Render the Available Tools page.
 508   *
 509   * We register this page on Network Admin as a top-level home for our
 510   * BuddyPress tools. This displays the default content.
 511   *
 512   * @since 2.0.0
 513   */
 514  function bp_core_admin_available_tools_page() {
 515      ?>
 516      <div class="wrap">
 517          <h1 class="wp-heading-inline"><?php esc_html_e( 'Tools', 'buddypress' ) ?></h1>
 518          <hr class="wp-header-end">
 519  
 520          <?php
 521  
 522          /**
 523           * Fires inside the markup used to display the Available Tools page.
 524           *
 525           * @since 2.0.0
 526           */
 527          do_action( 'bp_network_tool_box' ); ?>
 528  
 529      </div>
 530      <?php
 531  }
 532  
 533  /**
 534   * Render an introduction of BuddyPress tools on Available Tools page.
 535   *
 536   * @since 2.0.0
 537   */
 538  function bp_core_admin_available_tools_intro() {
 539      $query_arg = array(
 540          'page' => 'bp-tools'
 541      );
 542  
 543      $page = bp_core_do_network_admin() ? 'admin.php' : 'tools.php' ;
 544      $url  = add_query_arg( $query_arg, bp_get_admin_url( $page ) );
 545      ?>
 546      <div class="card tool-box bp-tools">
 547          <h2><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h2>
 548  
 549          <dl>
 550              <dt><?php esc_html_e( 'Repair Tools', 'buddypress' ) ?></dt>
 551              <dd>
 552                  <?php esc_html_e( 'BuddyPress keeps track of various relationships between users, groups, and activity items. Occasionally these relationships become out of sync, most often after an import, update, or migration.', 'buddypress' ); ?>
 553                  <?php
 554                  printf(
 555                      /* translators: %s: the link to the BuddyPress repair tools */
 556                      esc_html_x( 'Use the %s to repair these relationships.', 'buddypress tools intro', 'buddypress' ),
 557                      '<a href="' . esc_url( $url ) . '">' . esc_html__( 'BuddyPress Repair Tools', 'buddypress' ) . '</a>'
 558                  );
 559                  ?>
 560              </dd>
 561              <dt><?php esc_html_e( 'Manage Opt-outs', 'buddypress' ) ?></dt>
 562              <dd>
 563                  <?php esc_html_e( 'BuddyPress stores opt-out requests from people who are not members of this site, but have been contacted via communication from this site, and wish to opt-out from future communication.', 'buddypress' ); ?>
 564                  <?php
 565                  $url = add_query_arg( 'page', 'bp-optouts', bp_get_admin_url( $page ) );
 566                  printf(
 567                      /* translators: %s: the link to the BuddyPress Nonmember Opt-outs */
 568                      esc_html_x( 'Visit %s to manage your site&rsquo;s opt-out requests.', 'buddypress opt-outs intro', 'buddypress' ),
 569                      '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Nonmember Opt-outs', 'buddypress' ) . '</a>'
 570                  );
 571                  ?>
 572              </dd>
 573          </dl>
 574      </div>
 575      <?php
 576  }
 577  
 578  /**
 579   * Delete emails and restore from defaults.
 580   *
 581   * @since 2.5.0
 582   *
 583   * @return array
 584   */
 585  function bp_admin_reinstall_emails() {
 586      $switched = false;
 587  
 588      // Switch to the root blog, where the email posts live.
 589      if ( ! bp_is_root_blog() ) {
 590          switch_to_blog( bp_get_root_blog_id() );
 591          bp_register_taxonomies();
 592  
 593          $switched = true;
 594      }
 595  
 596      $emails = get_posts( array(
 597          'fields'           => 'ids',
 598          'post_status'      => 'publish',
 599          'post_type'        => bp_get_email_post_type(),
 600          'posts_per_page'   => 200,
 601          'suppress_filters' => false,
 602      ) );
 603  
 604      if ( $emails ) {
 605          foreach ( $emails as $email_id ) {
 606              wp_trash_post( $email_id );
 607          }
 608      }
 609  
 610      // Make sure we have no orphaned email type terms.
 611      $email_types = get_terms( bp_get_email_tax_type(), array(
 612          'fields'                 => 'ids',
 613          'hide_empty'             => false,
 614          'update_term_meta_cache' => false,
 615      ) );
 616  
 617      if ( $email_types ) {
 618          foreach ( $email_types as $term_id ) {
 619              wp_delete_term( (int) $term_id, bp_get_email_tax_type() );
 620          }
 621      }
 622  
 623      require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 624      bp_core_install_emails();
 625  
 626      if ( $switched ) {
 627          restore_current_blog();
 628      }
 629  
 630      return array( 0, __( 'Emails have been successfully reinstalled.', 'buddypress' ) );
 631  }
 632  
 633  /**
 634   * Add notice on the "Tools > BuddyPress" page if more sites need recording.
 635   *
 636   * This notice only shows up in the network admin dashboard.
 637   *
 638   * @since 2.6.0
 639   */
 640  function bp_core_admin_notice_repopulate_blogs_resume() {
 641      $screen = get_current_screen();
 642      if ( 'tools_page_bp-tools-network' !== $screen->id ) {
 643          return;
 644      }
 645  
 646      if ( '' === bp_get_option( '_bp_record_blogs_offset' ) ) {
 647          return;
 648      }
 649  
 650      echo '<div class="error"><p>' . __( 'It looks like you have more sites to record. Resume recording by checking the "Repopulate site tracking records" option.', 'buddypress' ) . '</p></div>';
 651  }
 652  add_action( 'network_admin_notices', 'bp_core_admin_notice_repopulate_blogs_resume' );
 653  
 654  /**
 655   * Add BuddyPress debug info to the WordPress Site Health info screen.
 656   *
 657   * @since 5.0.0
 658   *
 659   * @param  array $debug_info The Site's debug info.
 660   * @return array             The Site's debug info, including the BuddyPress specific ones.
 661   */
 662  function bp_core_admin_debug_information( $debug_info = array() ) {
 663      global $wp_settings_fields;
 664      $active_components = array_intersect_key( bp_core_get_components(), buddypress()->active_components );
 665      $bp_settings       = array();
 666  
 667      foreach ( $wp_settings_fields['buddypress'] as $section => $settings ) {
 668          $prefix       = '';
 669          $component_id = str_replace( 'bp_', '', $section );
 670  
 671          if ( isset( $active_components[ $component_id ]['title'] ) ) {
 672              $prefix = $active_components[ $component_id ]['title'] .': ';
 673          }
 674  
 675          foreach( $settings as $bp_setting ) {
 676              $reverse = (
 677                  strpos( $bp_setting['id'], 'hide' ) !== false ||
 678                  strpos( $bp_setting['id'], 'restrict' ) !== false ||
 679                  strpos( $bp_setting['id'], 'disable' ) !== false
 680              );
 681  
 682              if ( ! isset( $bp_setting['id'] ) || '_bp_theme_package_id' === $bp_setting['id'] ) {
 683                  continue;
 684              }
 685  
 686              $bp_setting_value = bp_get_option( $bp_setting['id'] );
 687              if ( '0' === $bp_setting_value || '1' === $bp_setting_value ) {
 688                  if ( ( $reverse && '0' === $bp_setting_value ) || ( ! $reverse && '1' === $bp_setting_value ) ) {
 689                      $bp_setting_value = __( 'Yes', 'buddypress' );
 690                  } else {
 691                      $bp_setting_value = __( 'No', 'buddypress' );
 692                  }
 693              }
 694  
 695              // Make sure to show the setting is reversed when site info is copied to clipboard.
 696              $bp_settings_id = $bp_setting['id'];
 697              if ( $reverse ) {
 698                  $bp_settings_id = '! ' . $bp_settings_id;
 699              }
 700  
 701              $bp_settings[ $bp_settings_id ] = array(
 702                  'label' => $prefix . $bp_setting['title'],
 703                  'value' => $bp_setting_value,
 704              );
 705          }
 706      }
 707  
 708      $debug_info['buddypress'] = array(
 709          'label'  => __( 'BuddyPress', 'buddypress' ),
 710          'fields' => array_merge(
 711              array(
 712                  'version' => array(
 713                      'label' => __( 'Version', 'buddypress' ),
 714                      'value' => bp_get_version(),
 715                  ),
 716                  'active_components' => array(
 717                      'label' => __( 'Active components', 'buddypress' ),
 718                      'value' => implode( ', ', wp_list_pluck( $active_components, 'title' ) ),
 719                  ),
 720                  'template_pack' => array(
 721                      'label' => __( 'Active template pack', 'buddypress' ),
 722                      'value' => bp_get_theme_compat_name() . ' ' . bp_get_theme_compat_version(),
 723                  ),
 724              ),
 725              $bp_settings
 726          )
 727      );
 728  
 729      return $debug_info;
 730  }
 731  add_filter( 'debug_information', 'bp_core_admin_debug_information' );


Generated: Wed Apr 21 01:01:43 2021 Cross-referenced by PHPXref 0.7.1