[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/ -> bp-core-update.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Updater.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Updater
   7   * @since 1.6.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Is this a fresh installation of BuddyPress?
  15   *
  16   * If there is no raw DB version, we infer that this is the first installation.
  17   *
  18   * @since 1.7.0
  19   *
  20   * @return bool True if this is a fresh BP install, otherwise false.
  21   */
  22  function bp_is_install() {
  23      return ! bp_get_db_version_raw();
  24  }
  25  
  26  /**
  27   * Is this a BuddyPress update?
  28   *
  29   * Determined by comparing the registered BuddyPress version to the version
  30   * number stored in the database. If the registered version is greater, it's
  31   * an update.
  32   *
  33   * @since 1.6.0
  34   *
  35   * @return bool True if update, otherwise false.
  36   */
  37  function bp_is_update() {
  38  
  39      // Current DB version of this site (per site in a multisite network).
  40      $current_db   = bp_get_option( '_bp_db_version' );
  41      $current_live = bp_get_db_version();
  42  
  43      // Compare versions (cast as int and bool to be safe).
  44      $is_update = (bool) ( (int) $current_db < (int) $current_live );
  45  
  46      // Return the product of version comparison.
  47      return $is_update;
  48  }
  49  
  50  /**
  51   * Determine whether BuddyPress is in the process of being activated.
  52   *
  53   * @since 1.6.0
  54   *
  55   * @param string $basename BuddyPress basename.
  56   * @return bool True if activating BuddyPress, false if not.
  57   */
  58  function bp_is_activation( $basename = '' ) {
  59      $bp     = buddypress();
  60      $action = false;
  61  
  62      if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) ) {
  63          $action = $_REQUEST['action'];
  64      } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) ) {
  65          $action = $_REQUEST['action2'];
  66      }
  67  
  68      // Bail if not activating.
  69      if ( empty( $action ) || !in_array( $action, array( 'activate', 'activate-selected' ) ) ) {
  70          return false;
  71      }
  72  
  73      // The plugin(s) being activated.
  74      if ( $action == 'activate' ) {
  75          $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
  76      } else {
  77          $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  78      }
  79  
  80      // Set basename if empty.
  81      if ( empty( $basename ) && !empty( $bp->basename ) ) {
  82          $basename = $bp->basename;
  83      }
  84  
  85      // Bail if no basename.
  86      if ( empty( $basename ) ) {
  87          return false;
  88      }
  89  
  90      // Is BuddyPress being activated?
  91      return in_array( $basename, $plugins );
  92  }
  93  
  94  /**
  95   * Determine whether BuddyPress is in the process of being deactivated.
  96   *
  97   * @since 1.6.0
  98   *
  99   * @param string $basename BuddyPress basename.
 100   * @return bool True if deactivating BuddyPress, false if not.
 101   */
 102  function bp_is_deactivation( $basename = '' ) {
 103      $bp     = buddypress();
 104      $action = false;
 105  
 106      if ( ! empty( $_REQUEST['action'] ) && ( '-1' != $_REQUEST['action'] ) ) {
 107          $action = $_REQUEST['action'];
 108      } elseif ( ! empty( $_REQUEST['action2'] ) && ( '-1' != $_REQUEST['action2'] ) ) {
 109          $action = $_REQUEST['action2'];
 110      }
 111  
 112      // Bail if not deactivating.
 113      if ( empty( $action ) || !in_array( $action, array( 'deactivate', 'deactivate-selected' ) ) ) {
 114          return false;
 115      }
 116  
 117      // The plugin(s) being deactivated.
 118      if ( 'deactivate' == $action ) {
 119          $plugins = isset( $_GET['plugin'] ) ? array( $_GET['plugin'] ) : array();
 120      } else {
 121          $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
 122      }
 123  
 124      // Set basename if empty.
 125      if ( empty( $basename ) && !empty( $bp->basename ) ) {
 126          $basename = $bp->basename;
 127      }
 128  
 129      // Bail if no basename.
 130      if ( empty( $basename ) ) {
 131          return false;
 132      }
 133  
 134      // Is bbPress being deactivated?
 135      return in_array( $basename, $plugins );
 136  }
 137  
 138  /**
 139   * Update the BP version stored in the database to the current version.
 140   *
 141   * @since 1.6.0
 142   */
 143  function bp_version_bump() {
 144      bp_update_option( '_bp_db_version', bp_get_db_version() );
 145  }
 146  
 147  /**
 148   * Set up the BuddyPress updater.
 149   *
 150   * @since 1.6.0
 151   */
 152  function bp_setup_updater() {
 153  
 154      // Are we running an outdated version of BuddyPress?
 155      if ( ! bp_is_update() ) {
 156          return;
 157      }
 158  
 159      bp_version_updater();
 160  }
 161  
 162  /**
 163   * Initialize an update or installation of BuddyPress.
 164   *
 165   * BuddyPress's version updater looks at what the current database version is,
 166   * and runs whatever other code is needed - either the "update" or "install"
 167   * code.
 168   *
 169   * This is most often used when the data schema changes, but should also be used
 170   * to correct issues with BuddyPress metadata silently on software update.
 171   *
 172   * @since 1.7.0
 173   */
 174  function bp_version_updater() {
 175  
 176      // Get the raw database version.
 177      $raw_db_version = (int) bp_get_db_version_raw();
 178  
 179      /**
 180       * Filters the default components to activate for a new install.
 181       *
 182       * @since 1.7.0
 183       *
 184       * @param array $value Array of default components to activate.
 185       */
 186      $default_components = apply_filters( 'bp_new_install_default_components', array(
 187          'activity'      => 1,
 188          'members'       => 1,
 189          'settings'      => 1,
 190          'xprofile'      => 1,
 191          'notifications' => 1,
 192      ) );
 193  
 194      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
 195      require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
 196      $switched_to_root_blog = false;
 197  
 198      // Make sure the current blog is set to the root blog.
 199      if ( ! bp_is_root_blog() ) {
 200          switch_to_blog( bp_get_root_blog_id() );
 201          bp_register_taxonomies();
 202  
 203          $switched_to_root_blog = true;
 204      }
 205  
 206      // Install BP schema and activate only Activity and XProfile.
 207      if ( bp_is_install() ) {
 208  
 209          // Apply schema and set Activity and XProfile components as active.
 210          bp_core_install( $default_components );
 211          bp_update_option( 'bp-active-components', $default_components );
 212          bp_core_add_page_mappings( $default_components, 'delete' );
 213          bp_core_install_emails();
 214  
 215      // Upgrades.
 216      } else {
 217  
 218          // Run the schema install to update tables.
 219          bp_core_install();
 220  
 221          // Version 1.5.0.
 222          if ( $raw_db_version < 1801 ) {
 223              bp_update_to_1_5();
 224              bp_core_add_page_mappings( $default_components, 'delete' );
 225          }
 226  
 227          // Version 1.6.0.
 228          if ( $raw_db_version < 6067 ) {
 229              bp_update_to_1_6();
 230          }
 231  
 232          // Version 1.9.0.
 233          if ( $raw_db_version < 7553 ) {
 234              bp_update_to_1_9();
 235          }
 236  
 237          // Version 1.9.2.
 238          if ( $raw_db_version < 7731 ) {
 239              bp_update_to_1_9_2();
 240          }
 241  
 242          // Version 2.0.0.
 243          if ( $raw_db_version < 7892 ) {
 244              bp_update_to_2_0();
 245          }
 246  
 247          // Version 2.0.1.
 248          if ( $raw_db_version < 8311 ) {
 249              bp_update_to_2_0_1();
 250          }
 251  
 252          // Version 2.2.0.
 253          if ( $raw_db_version < 9181 ) {
 254              bp_update_to_2_2();
 255          }
 256  
 257          // Version 2.3.0.
 258          if ( $raw_db_version < 9615 ) {
 259              bp_update_to_2_3();
 260          }
 261  
 262          // Version 2.5.0.
 263          if ( $raw_db_version < 10440 ) {
 264              bp_update_to_2_5();
 265          }
 266  
 267          // Version 2.7.0.
 268          if ( $raw_db_version < 11105 ) {
 269              bp_update_to_2_7();
 270          }
 271  
 272          // Version 5.0.0.
 273          if ( $raw_db_version < 12385 ) {
 274              bp_update_to_5_0();
 275          }
 276  
 277          // Version 8.0.0.
 278          if ( $raw_db_version < 12850 ) {
 279              bp_update_to_8_0();
 280          }
 281      }
 282  
 283      /* All done! *************************************************************/
 284  
 285      // Bump the version.
 286      bp_version_bump();
 287  
 288      if ( $switched_to_root_blog ) {
 289          restore_current_blog();
 290      }
 291  }
 292  
 293  /**
 294   * Perform database operations that must take place before the general schema upgrades.
 295   *
 296   * `dbDelta()` cannot handle certain operations - like changing indexes - so we do it here instead.
 297   *
 298   * @since 2.3.0
 299   */
 300  function bp_pre_schema_upgrade() {
 301      global $wpdb;
 302  
 303      $raw_db_version = (int) bp_get_db_version_raw();
 304      $bp_prefix      = bp_core_get_table_prefix();
 305  
 306      // 2.3.0: Change index lengths to account for utf8mb4.
 307      if ( $raw_db_version < 9695 ) {
 308          // Map table_name => columns.
 309          $tables = array(
 310              $bp_prefix . 'bp_activity_meta'       => array( 'meta_key' ),
 311              $bp_prefix . 'bp_groups_groupmeta'    => array( 'meta_key' ),
 312              $bp_prefix . 'bp_messages_meta'       => array( 'meta_key' ),
 313              $bp_prefix . 'bp_notifications_meta'  => array( 'meta_key' ),
 314              $bp_prefix . 'bp_user_blogs_blogmeta' => array( 'meta_key' ),
 315              $bp_prefix . 'bp_xprofile_meta'       => array( 'meta_key' ),
 316          );
 317  
 318          foreach ( $tables as $table_name => $indexes ) {
 319              foreach ( $indexes as $index ) {
 320                  if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", bp_esc_like( $table_name ) ) ) ) {
 321                      $wpdb->query( "ALTER TABLE {$table_name} DROP INDEX {$index}" );
 322                  }
 323              }
 324          }
 325      }
 326  }
 327  
 328  /** Upgrade Routines **********************************************************/
 329  
 330  /**
 331   * Remove unused metadata from database when upgrading from < 1.5.
 332   *
 333   * Database update methods based on version numbers.
 334   *
 335   * @since 1.7.0
 336   */
 337  function bp_update_to_1_5() {
 338  
 339      // Delete old database version options.
 340      delete_site_option( 'bp-activity-db-version' );
 341      delete_site_option( 'bp-blogs-db-version'    );
 342      delete_site_option( 'bp-friends-db-version'  );
 343      delete_site_option( 'bp-groups-db-version'   );
 344      delete_site_option( 'bp-messages-db-version' );
 345      delete_site_option( 'bp-xprofile-db-version' );
 346  }
 347  
 348  /**
 349   * Remove unused metadata from database when upgrading from < 1.6.0.
 350   *
 351   * Database update methods based on version numbers.
 352   *
 353   * @since 1.7.0
 354   */
 355  function bp_update_to_1_6() {
 356  
 357      // Delete possible site options.
 358      delete_site_option( 'bp-db-version'       );
 359      delete_site_option( '_bp_db_version'      );
 360      delete_site_option( 'bp-core-db-version'  );
 361      delete_site_option( '_bp-core-db-version' );
 362  
 363      // Delete possible blog options.
 364      delete_blog_option( bp_get_root_blog_id(), 'bp-db-version'       );
 365      delete_blog_option( bp_get_root_blog_id(), 'bp-core-db-version'  );
 366      delete_site_option( bp_get_root_blog_id(), '_bp-core-db-version' );
 367      delete_site_option( bp_get_root_blog_id(), '_bp_db_version'      );
 368  }
 369  
 370  /**
 371   * Add the notifications component to active components.
 372   *
 373   * Notifications was added in 1.9.0, and previous installations will already
 374   * have the core notifications API active. We need to add the new Notifications
 375   * component to the active components option to retain existing functionality.
 376   *
 377   * @since 1.9.0
 378   */
 379  function bp_update_to_1_9() {
 380  
 381      // Setup hardcoded keys.
 382      $active_components_key      = 'bp-active-components';
 383      $notifications_component_id = 'notifications';
 384  
 385      // Get the active components.
 386      $active_components          = bp_get_option( $active_components_key );
 387  
 388      // Add notifications.
 389      if ( ! in_array( $notifications_component_id, $active_components ) ) {
 390          $active_components[ $notifications_component_id ] = 1;
 391      }
 392  
 393      // Update the active components option.
 394      bp_update_option( $active_components_key, $active_components );
 395  }
 396  
 397  /**
 398   * Perform database updates for BP 1.9.2.
 399   *
 400   * In 1.9, BuddyPress stopped registering its theme directory when it detected
 401   * that bp-default (or a child theme) was not currently being used, in effect
 402   * deprecating bp-default. However, this ended up causing problems when site
 403   * admins using bp-default would switch away from the theme temporarily:
 404   * bp-default would no longer be available, with no obvious way (outside of
 405   * a manual filter) to restore it. In 1.9.2, we add an option that flags
 406   * whether bp-default or a child theme is active at the time of upgrade; if so,
 407   *
 408   * the theme directory will continue to be registered even if the theme is
 409   * deactivated temporarily. Thus, new installations will not see bp-default,
 410   * but legacy installations using the theme will continue to see it.
 411   *
 412   * @since 1.9.2
 413   */
 414  function bp_update_to_1_9_2() {
 415      if ( 'bp-default' === get_stylesheet() || 'bp-default' === get_template() ) {
 416          update_site_option( '_bp_retain_bp_default', 1 );
 417      }
 418  }
 419  
 420  /**
 421   * 2.0 update routine.
 422   *
 423   * - Ensure that the activity tables are installed, for last_activity storage.
 424   * - Migrate last_activity data from usermeta to activity table.
 425   * - Add values for all BuddyPress options to the options table.
 426   *
 427   * @since 2.0.0
 428   */
 429  function bp_update_to_2_0() {
 430  
 431      /* Install activity tables for 'last_activity' ***************************/
 432  
 433      bp_core_install_activity_streams();
 434  
 435      /* Migrate 'last_activity' data ******************************************/
 436  
 437      bp_last_activity_migrate();
 438  
 439      /* Migrate signups data **************************************************/
 440  
 441      if ( ! is_multisite() ) {
 442  
 443          // Maybe install the signups table.
 444          bp_core_maybe_install_signups();
 445  
 446          // Run the migration script.
 447          bp_members_migrate_signups();
 448      }
 449  
 450      /* Add BP options to the options table ***********************************/
 451  
 452      bp_add_options();
 453  }
 454  
 455  /**
 456   * 2.0.1 database upgrade routine.
 457   *
 458   * @since 2.0.1
 459   */
 460  function bp_update_to_2_0_1() {
 461  
 462      // We purposely call this during both the 2.0 upgrade and the 2.0.1 upgrade.
 463      // Don't worry; it won't break anything, and safely handles all cases.
 464      bp_core_maybe_install_signups();
 465  }
 466  
 467  /**
 468   * 2.2.0 update routine.
 469   *
 470   * - Add messages meta table.
 471   * - Update the component field of the 'new members' activity type.
 472   * - Clean up hidden friendship activities.
 473   *
 474   * @since 2.2.0
 475   */
 476  function bp_update_to_2_2() {
 477  
 478      // Also handled by `bp_core_install()`.
 479      if ( bp_is_active( 'messages' ) ) {
 480          bp_core_install_private_messaging();
 481      }
 482  
 483      if ( bp_is_active( 'activity' ) ) {
 484          bp_migrate_new_member_activity_component();
 485  
 486          if ( bp_is_active( 'friends' ) ) {
 487              bp_cleanup_friendship_activities();
 488          }
 489      }
 490  }
 491  
 492  /**
 493   * 2.3.0 update routine.
 494   *
 495   * - Add notifications meta table.
 496   *
 497   * @since 2.3.0
 498   */
 499  function bp_update_to_2_3() {
 500  
 501      // Also handled by `bp_core_install()`.
 502      if ( bp_is_active( 'notifications' ) ) {
 503          bp_core_install_notifications();
 504      }
 505  }
 506  
 507  /**
 508   * 2.5.0 update routine.
 509   *
 510   * - Add emails.
 511   *
 512   * @since 2.5.0
 513   */
 514  function bp_update_to_2_5() {
 515      bp_core_install_emails();
 516  }
 517  
 518  /**
 519   * 2.7.0 update routine.
 520   *
 521   * - Add email unsubscribe salt.
 522   * - Save legacy directory titles to the corresponding WP pages.
 523   * - Add ignore deprecated code option (false for updates).
 524   *
 525   * @since 2.7.0
 526   */
 527  function bp_update_to_2_7() {
 528      bp_add_option( 'bp-emails-unsubscribe-salt', base64_encode( wp_generate_password( 64, true, true ) ) );
 529  
 530      // Update post_titles
 531      bp_migrate_directory_page_titles();
 532  
 533      /*
 534       * Add `parent_id` column to groups table.
 535       * Also handled by `bp_core_install()`.
 536       */
 537      if ( bp_is_active( 'groups' ) ) {
 538          bp_core_install_groups();
 539  
 540          // Invalidate all cached group objects.
 541          global $wpdb;
 542          $bp = buddypress();
 543  
 544          $group_ids = $wpdb->get_col( "SELECT id FROM {$bp->groups->table_name}" );
 545  
 546          foreach ( $group_ids as $group_id ) {
 547              wp_cache_delete( $group_id, 'bp_groups' );
 548          }
 549      }
 550  
 551      // Do not ignore deprecated code for existing installs.
 552      bp_add_option( '_bp_ignore_deprecated_code', false );
 553  }
 554  
 555  /**
 556   * Retuns needed the fullname field ID for an update task.
 557   *
 558   * @since 8.0.0
 559   *
 560   * @return int The fullname field ID.
 561   */
 562  function bp_get_fullname_field_id_for_update() {
 563      /**
 564       * The xProfile component is active by default on new installs, even if it
 565       * might be inactive during this update, we need to set the custom visibility
 566       * for the default field, in case the Administrator decides to reactivate it.
 567       */
 568      global $wpdb;
 569      $bp_prefix = bp_core_get_table_prefix();
 570      return (int) $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE name = %s", addslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) );
 571  }
 572  
 573  /**
 574   * 5.0.0 update routine.
 575   *
 576   * - Make sure the custom visibility is disabled for the default profile field.
 577   * - Create the invitations table.
 578   * - Migrate requests and invitations to the new table.
 579   *
 580   * @since 5.0.0
 581   */
 582  function bp_update_to_5_0() {
 583      /**
 584       * The xProfile component is active by default on new installs, even if it
 585       * might be inactive during this update, we need to set the custom visibility
 586       * for the default field, in case the Administrator decides to reactivate it.
 587       */
 588      global $wpdb;
 589      $bp_prefix = bp_core_get_table_prefix();
 590      $field_id  = bp_get_fullname_field_id_for_update();
 591  
 592      $wpdb->insert(
 593          $bp_prefix . 'bp_xprofile_meta',
 594          array(
 595              'object_id'   => $field_id,
 596              'object_type' => 'field',
 597              'meta_key'    => 'allow_custom_visibility',
 598              'meta_value'  => 'disabled'
 599          ),
 600          array(
 601              '%d',
 602              '%s',
 603              '%s',
 604              '%s'
 605          )
 606      );
 607  
 608      bp_core_install_invitations();
 609  
 610      if ( bp_is_active( 'groups' ) ) {
 611          bp_groups_migrate_invitations();
 612      }
 613  }
 614  
 615  /**
 616   * 8.0.0 update routine.
 617   *
 618   * - Edit the `new_avatar` activity type's component to `members`.
 619   * - Upgrade Primary xProfile Group's fields to signup fields.
 620   *
 621   * @since 8.0.0
 622   */
 623  function bp_update_to_8_0() {
 624      global $wpdb;
 625      $bp_prefix = bp_core_get_table_prefix();
 626  
 627      // Install welcome email to email list.
 628      add_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' );
 629  
 630      bp_core_install_emails();
 631  
 632      remove_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' );
 633  
 634      // Update the `new_avatar` activity type's component to `members`.
 635      $wpdb->update(
 636          $bp_prefix . 'bp_activity',
 637          array(
 638              'component' => 'members',
 639          ),
 640          array(
 641              'type' => 'new_avatar',
 642          ),
 643          array(
 644              '%s',
 645          ),
 646          array(
 647              '%s',
 648          )
 649      );
 650  
 651      // Check if we need to create default signup fields.
 652      $field_id            = bp_get_fullname_field_id_for_update();
 653      $has_signup_position = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$bp_prefix}bp_xprofile_meta WHERE meta_key = 'signup_position' AND object_type = 'field' AND object_id = %d", $field_id ) );
 654      if ( bp_get_signup_allowed() && ! $has_signup_position ) {
 655          // Get the Primary Group's fields.
 656          $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" );
 657  
 658          // Migrate potential signup fields.
 659          if ( $signup_fields ) {
 660              $signup_position = 0;
 661              foreach ( $signup_fields as $signup_field_id ) {
 662                  $signup_position += 1;
 663  
 664                  $wpdb->insert(
 665                      $bp_prefix . 'bp_xprofile_meta',
 666                      array(
 667                          'object_id'   => $signup_field_id,
 668                          'object_type' => 'field',
 669                          'meta_key'    => 'signup_position',
 670                          'meta_value'  => $signup_position,
 671                      ),
 672                      array(
 673                          '%d',
 674                          '%s',
 675                          '%s',
 676                          '%d',
 677                      )
 678                  );
 679              }
 680          }
 681      }
 682  
 683      bp_core_install_nonmember_opt_outs();
 684  }
 685  
 686  /**
 687   * Select only the emails that need to be installed with version 8.0.
 688   *
 689   * @since 8.0.0
 690   *
 691   * @param array $emails The array of emails schema.
 692   */
 693  function bp_core_get_8_0_upgrade_email_schema( $emails ) {
 694      $new_emails = array();
 695  
 696      if ( isset( $emails['core-user-activation'] ) ) {
 697          $new_emails['core-user-activation'] = $emails['core-user-activation'];
 698      }
 699  
 700      if ( isset( $emails['bp-members-invitation'] ) ) {
 701          $new_emails['bp-members-invitation'] = $emails['bp-members-invitation'];
 702      }
 703  
 704      return $new_emails;
 705  }
 706  
 707  /**
 708   * Updates the component field for new_members type.
 709   *
 710   * @since 2.2.0
 711   *
 712   * @global $wpdb
 713   */
 714  function bp_migrate_new_member_activity_component() {
 715      global $wpdb;
 716      $bp = buddypress();
 717  
 718      // Update the component for the new_member type.
 719      $wpdb->update(
 720          // Activity table.
 721          $bp->members->table_name_last_activity,
 722          array(
 723              'component' => $bp->members->id,
 724          ),
 725          array(
 726              'component' => 'xprofile',
 727              'type'      => 'new_member',
 728          ),
 729          // Data sanitization format.
 730          array(
 731              '%s',
 732          ),
 733          // WHERE sanitization format.
 734          array(
 735              '%s',
 736              '%s'
 737          )
 738      );
 739  }
 740  
 741  /**
 742   * Remove all hidden friendship activities.
 743   *
 744   * @since 2.2.0
 745   */
 746  function bp_cleanup_friendship_activities() {
 747      bp_activity_delete( array(
 748          'component'     => buddypress()->friends->id,
 749          'type'          => 'friendship_created',
 750          'hide_sitewide' => true,
 751      ) );
 752  }
 753  
 754  /**
 755   * Update WP pages so that their post_title matches the legacy component directory title.
 756   *
 757   * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
 758   * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
 759   * WP posts with the formerly hardcoded titles.
 760   *
 761   * @since 2.7.0
 762   */
 763  function bp_migrate_directory_page_titles() {
 764      $bp_pages = bp_core_get_directory_page_ids( 'all' );
 765  
 766      $default_titles = bp_core_get_directory_page_default_titles();
 767  
 768      $legacy_titles = array(
 769          'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
 770          'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
 771          'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
 772          'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
 773      );
 774  
 775      foreach ( $bp_pages as $component => $page_id ) {
 776          if ( ! isset( $legacy_titles[ $component ] ) ) {
 777              continue;
 778          }
 779  
 780          $page = get_post( $page_id );
 781          if ( ! $page ) {
 782              continue;
 783          }
 784  
 785          // If the admin has changed the default title, don't touch it.
 786          if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
 787              continue;
 788          }
 789  
 790          // If the saved page title is the same as the legacy title, there's nothing to do.
 791          if ( $legacy_titles[ $component ] == $page->post_title ) {
 792              continue;
 793          }
 794  
 795          // Update the page with the legacy title.
 796          wp_update_post( array(
 797              'ID' => $page_id,
 798              'post_title' => $legacy_titles[ $component ],
 799          ) );
 800      }
 801  }
 802  
 803  /**
 804   * Redirect user to BP's What's New page on first page load after activation.
 805   *
 806   * @since 1.7.0
 807   *
 808   * @internal Used internally to redirect BuddyPress to the about page on activation.
 809   */
 810  function bp_add_activation_redirect() {
 811  
 812      // Bail if activating from network, or bulk.
 813      if ( isset( $_GET['activate-multi'] ) ) {
 814          return;
 815      }
 816  
 817      // Record that this is a new installation, so we show the right
 818      // welcome message.
 819      if ( bp_is_install() ) {
 820          set_transient( '_bp_is_new_install', true, 30 );
 821      }
 822  
 823      // Add the transient to redirect.
 824      set_transient( '_bp_activation_redirect', true, 30 );
 825  }
 826  
 827  /** Signups *******************************************************************/
 828  
 829  /**
 830   * Check if the signups table needs to be created or upgraded.
 831   *
 832   * @since 2.0.0
 833   *
 834   * @global WPDB $wpdb
 835   */
 836  function bp_core_maybe_install_signups() {
 837      global $wpdb;
 838  
 839      // The table to run queries against.
 840      $signups_table = $wpdb->base_prefix . 'signups';
 841  
 842      // Suppress errors because users shouldn't see what happens next.
 843      $old_suppress  = $wpdb->suppress_errors();
 844  
 845      // Never use bp_core_get_table_prefix() for any global users tables.
 846      $table_exists  = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" );
 847  
 848      // Table already exists, so maybe upgrade instead?
 849      if ( true === $table_exists ) {
 850  
 851          // Look for the 'signup_id' column.
 852          $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" );
 853  
 854          // 'signup_id' column doesn't exist, so run the upgrade
 855          if ( empty( $column_exists ) ) {
 856              bp_core_upgrade_signups();
 857          }
 858  
 859      // Table does not exist, and we are a single site, so install the multisite
 860      // signups table using WordPress core's database schema.
 861      } elseif ( ! is_multisite() ) {
 862          bp_core_install_signups();
 863      }
 864  
 865      // Restore previous error suppression setting.
 866      $wpdb->suppress_errors( $old_suppress );
 867  }
 868  
 869  /** Activation Actions ********************************************************/
 870  
 871  /**
 872   * Fire activation hooks and events.
 873   *
 874   * Runs on BuddyPress activation.
 875   *
 876   * @since 1.6.0
 877   */
 878  function bp_activation() {
 879  
 880      // Force refresh theme roots.
 881      delete_site_transient( 'theme_roots' );
 882  
 883      // Add options.
 884      bp_add_options();
 885  
 886      /**
 887       * Fires during the activation of BuddyPress.
 888       *
 889       * Use as of 1.6.0.
 890       *
 891       * @since 1.6.0
 892       */
 893      do_action( 'bp_activation' );
 894  
 895      // @deprecated as of 1.6.0
 896      do_action( 'bp_loader_activate' );
 897  }
 898  
 899  /**
 900   * Fire deactivation hooks and events.
 901   *
 902   * Runs on BuddyPress deactivation.
 903   *
 904   * @since 1.6.0
 905   */
 906  function bp_deactivation() {
 907  
 908      // Force refresh theme roots.
 909      delete_site_transient( 'theme_roots' );
 910  
 911      // Switch to WordPress's default theme if current parent or child theme
 912      // depend on bp-default. This is to prevent white screens of doom.
 913      if ( in_array( 'bp-default', array( get_template(), get_stylesheet() ) ) ) {
 914          switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
 915          update_option( 'template_root',   get_raw_theme_root( WP_DEFAULT_THEME, true ) );
 916          update_option( 'stylesheet_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) );
 917      }
 918  
 919      /**
 920       * Fires during the deactivation of BuddyPress.
 921       *
 922       * Use as of 1.6.0.
 923       *
 924       * @since 1.6.0
 925       */
 926      do_action( 'bp_deactivation' );
 927  
 928      // @deprecated as of 1.6.0
 929      do_action( 'bp_loader_deactivate' );
 930  }
 931  
 932  /**
 933   * Fire uninstall hook.
 934   *
 935   * Runs when uninstalling BuddyPress.
 936   *
 937   * @since 1.6.0
 938   */
 939  function bp_uninstall() {
 940  
 941      /**
 942       * Fires during the uninstallation of BuddyPress.
 943       *
 944       * @since 1.6.0
 945       */
 946      do_action( 'bp_uninstall' );
 947  }


Generated: Fri Jul 30 01:01:42 2021 Cross-referenced by PHPXref 0.7.1