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


Generated: Thu Oct 21 01:00:54 2021 Cross-referenced by PHPXref 0.7.1