[ 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   * 5.0.0 update routine.
 557   *
 558   * - Make sure the custom visibility is disabled for the default profile field.
 559   * - Create the invitations table.
 560   * - Migrate requests and invitations to the new table.
 561   *
 562   * @since 5.0.0
 563   */
 564  function bp_update_to_5_0() {
 565      /**
 566       * The xProfile component is active by default on new installs, even if it
 567       * might be inactive during this update, we need to set the custom visibility
 568       * for the default field, in case the Administrator decides to reactivate it.
 569       */
 570      global $wpdb;
 571      $bp_prefix = bp_core_get_table_prefix();
 572      $field_id  = $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' ) ) ) );
 573  
 574      $wpdb->insert(
 575          $bp_prefix . 'bp_xprofile_meta',
 576          array(
 577              'object_id'   => $field_id,
 578              'object_type' => 'field',
 579              'meta_key'    => 'allow_custom_visibility',
 580              'meta_value'  => 'disabled'
 581          ),
 582          array(
 583              '%d',
 584              '%s',
 585              '%s',
 586              '%s'
 587          )
 588      );
 589  
 590      bp_core_install_invitations();
 591  
 592      if ( bp_is_active( 'groups' ) ) {
 593          bp_groups_migrate_invitations();
 594      }
 595  }
 596  
 597  /**
 598   * 8.0.0 update routine.
 599   *
 600   * - Edit the `new_avatar` activity type's component to `members`.
 601   * - Upgrade Primary xProfile Group's fields to signup fields.
 602   *
 603   * @since 8.0.0
 604   */
 605  function bp_update_to_8_0() {
 606      global $wpdb;
 607      $bp_prefix = bp_core_get_table_prefix();
 608  
 609      // Update the `new_avatar` activity type's component to `members`.
 610      $wpdb->update(
 611          $bp_prefix . 'bp_activity',
 612          array(
 613              'component' => 'members',
 614          ),
 615          array(
 616              'type' => 'new_avatar',
 617          ),
 618          array(
 619              '%s',
 620          ),
 621          array(
 622              '%s',
 623          )
 624      );
 625  
 626      if ( bp_get_signup_allowed() ) {
 627          // Get the Primary Group's fields.
 628          $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" );
 629  
 630          // Migrate potential signup fields.
 631          if ( $signup_fields ) {
 632              $signup_position = 0;
 633              foreach ( $signup_fields as $signup_field_id ) {
 634                  $signup_position += 1;
 635  
 636                  $wpdb->insert(
 637                      $bp_prefix . 'bp_xprofile_meta',
 638                      array(
 639                          'object_id'   => $signup_field_id,
 640                          'object_type' => 'field',
 641                          'meta_key'    => 'signup_position',
 642                          'meta_value'  => $signup_position,
 643                      ),
 644                      array(
 645                          '%d',
 646                          '%s',
 647                          '%s',
 648                          '%d',
 649                      )
 650                  );
 651              }
 652          }
 653      }
 654  
 655      bp_core_install_nonmember_opt_outs();
 656  }
 657  
 658  /**
 659   * Updates the component field for new_members type.
 660   *
 661   * @since 2.2.0
 662   *
 663   * @global $wpdb
 664   */
 665  function bp_migrate_new_member_activity_component() {
 666      global $wpdb;
 667      $bp = buddypress();
 668  
 669      // Update the component for the new_member type.
 670      $wpdb->update(
 671          // Activity table.
 672          $bp->members->table_name_last_activity,
 673          array(
 674              'component' => $bp->members->id,
 675          ),
 676          array(
 677              'component' => 'xprofile',
 678              'type'      => 'new_member',
 679          ),
 680          // Data sanitization format.
 681          array(
 682              '%s',
 683          ),
 684          // WHERE sanitization format.
 685          array(
 686              '%s',
 687              '%s'
 688          )
 689      );
 690  }
 691  
 692  /**
 693   * Remove all hidden friendship activities.
 694   *
 695   * @since 2.2.0
 696   */
 697  function bp_cleanup_friendship_activities() {
 698      bp_activity_delete( array(
 699          'component'     => buddypress()->friends->id,
 700          'type'          => 'friendship_created',
 701          'hide_sitewide' => true,
 702      ) );
 703  }
 704  
 705  /**
 706   * Update WP pages so that their post_title matches the legacy component directory title.
 707   *
 708   * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
 709   * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
 710   * WP posts with the formerly hardcoded titles.
 711   *
 712   * @since 2.7.0
 713   */
 714  function bp_migrate_directory_page_titles() {
 715      $bp_pages = bp_core_get_directory_page_ids( 'all' );
 716  
 717      $default_titles = bp_core_get_directory_page_default_titles();
 718  
 719      $legacy_titles = array(
 720          'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
 721          'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
 722          'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
 723          'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
 724      );
 725  
 726      foreach ( $bp_pages as $component => $page_id ) {
 727          if ( ! isset( $legacy_titles[ $component ] ) ) {
 728              continue;
 729          }
 730  
 731          $page = get_post( $page_id );
 732          if ( ! $page ) {
 733              continue;
 734          }
 735  
 736          // If the admin has changed the default title, don't touch it.
 737          if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
 738              continue;
 739          }
 740  
 741          // If the saved page title is the same as the legacy title, there's nothing to do.
 742          if ( $legacy_titles[ $component ] == $page->post_title ) {
 743              continue;
 744          }
 745  
 746          // Update the page with the legacy title.
 747          wp_update_post( array(
 748              'ID' => $page_id,
 749              'post_title' => $legacy_titles[ $component ],
 750          ) );
 751      }
 752  }
 753  
 754  /**
 755   * Redirect user to BP's What's New page on first page load after activation.
 756   *
 757   * @since 1.7.0
 758   *
 759   * @internal Used internally to redirect BuddyPress to the about page on activation.
 760   */
 761  function bp_add_activation_redirect() {
 762  
 763      // Bail if activating from network, or bulk.
 764      if ( isset( $_GET['activate-multi'] ) ) {
 765          return;
 766      }
 767  
 768      // Record that this is a new installation, so we show the right
 769      // welcome message.
 770      if ( bp_is_install() ) {
 771          set_transient( '_bp_is_new_install', true, 30 );
 772      }
 773  
 774      // Add the transient to redirect.
 775      set_transient( '_bp_activation_redirect', true, 30 );
 776  }
 777  
 778  /** Signups *******************************************************************/
 779  
 780  /**
 781   * Check if the signups table needs to be created or upgraded.
 782   *
 783   * @since 2.0.0
 784   *
 785   * @global WPDB $wpdb
 786   */
 787  function bp_core_maybe_install_signups() {
 788      global $wpdb;
 789  
 790      // The table to run queries against.
 791      $signups_table = $wpdb->base_prefix . 'signups';
 792  
 793      // Suppress errors because users shouldn't see what happens next.
 794      $old_suppress  = $wpdb->suppress_errors();
 795  
 796      // Never use bp_core_get_table_prefix() for any global users tables.
 797      $table_exists  = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" );
 798  
 799      // Table already exists, so maybe upgrade instead?
 800      if ( true === $table_exists ) {
 801  
 802          // Look for the 'signup_id' column.
 803          $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" );
 804  
 805          // 'signup_id' column doesn't exist, so run the upgrade
 806          if ( empty( $column_exists ) ) {
 807              bp_core_upgrade_signups();
 808          }
 809  
 810      // Table does not exist, and we are a single site, so install the multisite
 811      // signups table using WordPress core's database schema.
 812      } elseif ( ! is_multisite() ) {
 813          bp_core_install_signups();
 814      }
 815  
 816      // Restore previous error suppression setting.
 817      $wpdb->suppress_errors( $old_suppress );
 818  }
 819  
 820  /** Activation Actions ********************************************************/
 821  
 822  /**
 823   * Fire activation hooks and events.
 824   *
 825   * Runs on BuddyPress activation.
 826   *
 827   * @since 1.6.0
 828   */
 829  function bp_activation() {
 830  
 831      // Force refresh theme roots.
 832      delete_site_transient( 'theme_roots' );
 833  
 834      // Add options.
 835      bp_add_options();
 836  
 837      /**
 838       * Fires during the activation of BuddyPress.
 839       *
 840       * Use as of 1.6.0.
 841       *
 842       * @since 1.6.0
 843       */
 844      do_action( 'bp_activation' );
 845  
 846      // @deprecated as of 1.6.0
 847      do_action( 'bp_loader_activate' );
 848  }
 849  
 850  /**
 851   * Fire deactivation hooks and events.
 852   *
 853   * Runs on BuddyPress deactivation.
 854   *
 855   * @since 1.6.0
 856   */
 857  function bp_deactivation() {
 858  
 859      // Force refresh theme roots.
 860      delete_site_transient( 'theme_roots' );
 861  
 862      // Switch to WordPress's default theme if current parent or child theme
 863      // depend on bp-default. This is to prevent white screens of doom.
 864      if ( in_array( 'bp-default', array( get_template(), get_stylesheet() ) ) ) {
 865          switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
 866          update_option( 'template_root',   get_raw_theme_root( WP_DEFAULT_THEME, true ) );
 867          update_option( 'stylesheet_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) );
 868      }
 869  
 870      /**
 871       * Fires during the deactivation of BuddyPress.
 872       *
 873       * Use as of 1.6.0.
 874       *
 875       * @since 1.6.0
 876       */
 877      do_action( 'bp_deactivation' );
 878  
 879      // @deprecated as of 1.6.0
 880      do_action( 'bp_loader_deactivate' );
 881  }
 882  
 883  /**
 884   * Fire uninstall hook.
 885   *
 886   * Runs when uninstalling BuddyPress.
 887   *
 888   * @since 1.6.0
 889   */
 890  function bp_uninstall() {
 891  
 892      /**
 893       * Fires during the uninstallation of BuddyPress.
 894       *
 895       * @since 1.6.0
 896       */
 897      do_action( 'bp_uninstall' );
 898  }


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