[ 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          // Version 10.0.0.
 283          if ( $raw_db_version < 13165 ) {
 284              bp_update_to_10_0();
 285          }
 286  
 287          // Version 11.0.0.
 288          if ( $raw_db_version < 13271 ){
 289              bp_update_to_11_0();
 290          }
 291  
 292      }
 293  
 294      /* All done! *************************************************************/
 295  
 296      // Bump the version.
 297      bp_version_bump();
 298  
 299      if ( $switched_to_root_blog ) {
 300          restore_current_blog();
 301      }
 302  }
 303  
 304  /**
 305   * Perform database operations that must take place before the general schema upgrades.
 306   *
 307   * `dbDelta()` cannot handle certain operations - like changing indexes - so we do it here instead.
 308   *
 309   * @since 2.3.0
 310   */
 311  function bp_pre_schema_upgrade() {
 312      global $wpdb;
 313  
 314      $raw_db_version = (int) bp_get_db_version_raw();
 315      $bp_prefix      = bp_core_get_table_prefix();
 316  
 317      // 2.3.0: Change index lengths to account for utf8mb4.
 318      if ( $raw_db_version < 9695 ) {
 319          // Map table_name => columns.
 320          $tables = array(
 321              $bp_prefix . 'bp_activity_meta'       => array( 'meta_key' ),
 322              $bp_prefix . 'bp_groups_groupmeta'    => array( 'meta_key' ),
 323              $bp_prefix . 'bp_messages_meta'       => array( 'meta_key' ),
 324              $bp_prefix . 'bp_notifications_meta'  => array( 'meta_key' ),
 325              $bp_prefix . 'bp_user_blogs_blogmeta' => array( 'meta_key' ),
 326              $bp_prefix . 'bp_xprofile_meta'       => array( 'meta_key' ),
 327          );
 328  
 329          foreach ( $tables as $table_name => $indexes ) {
 330              foreach ( $indexes as $index ) {
 331                  if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", bp_esc_like( $table_name ) ) ) ) {
 332                      $wpdb->query( "ALTER TABLE {$table_name} DROP INDEX {$index}" );
 333                  }
 334              }
 335          }
 336      }
 337  }
 338  
 339  /** Upgrade Routines **********************************************************/
 340  
 341  /**
 342   * Remove unused metadata from database when upgrading from < 1.5.
 343   *
 344   * Database update methods based on version numbers.
 345   *
 346   * @since 1.7.0
 347   */
 348  function bp_update_to_1_5() {
 349  
 350      // Delete old database version options.
 351      delete_site_option( 'bp-activity-db-version' );
 352      delete_site_option( 'bp-blogs-db-version'    );
 353      delete_site_option( 'bp-friends-db-version'  );
 354      delete_site_option( 'bp-groups-db-version'   );
 355      delete_site_option( 'bp-messages-db-version' );
 356      delete_site_option( 'bp-xprofile-db-version' );
 357  }
 358  
 359  /**
 360   * Remove unused metadata from database when upgrading from < 1.6.0.
 361   *
 362   * Database update methods based on version numbers.
 363   *
 364   * @since 1.7.0
 365   */
 366  function bp_update_to_1_6() {
 367  
 368      // Delete possible site options.
 369      delete_site_option( 'bp-db-version'       );
 370      delete_site_option( '_bp_db_version'      );
 371      delete_site_option( 'bp-core-db-version'  );
 372      delete_site_option( '_bp-core-db-version' );
 373  
 374      // Delete possible blog options.
 375      delete_blog_option( bp_get_root_blog_id(), 'bp-db-version'       );
 376      delete_blog_option( bp_get_root_blog_id(), 'bp-core-db-version'  );
 377      delete_site_option( bp_get_root_blog_id(), '_bp-core-db-version' );
 378      delete_site_option( bp_get_root_blog_id(), '_bp_db_version'      );
 379  }
 380  
 381  /**
 382   * Add the notifications component to active components.
 383   *
 384   * Notifications was added in 1.9.0, and previous installations will already
 385   * have the core notifications API active. We need to add the new Notifications
 386   * component to the active components option to retain existing functionality.
 387   *
 388   * @since 1.9.0
 389   */
 390  function bp_update_to_1_9() {
 391  
 392      // Setup hardcoded keys.
 393      $active_components_key      = 'bp-active-components';
 394      $notifications_component_id = 'notifications';
 395  
 396      // Get the active components.
 397      $active_components          = bp_get_option( $active_components_key );
 398  
 399      // Add notifications.
 400      if ( ! in_array( $notifications_component_id, $active_components ) ) {
 401          $active_components[ $notifications_component_id ] = 1;
 402      }
 403  
 404      // Update the active components option.
 405      bp_update_option( $active_components_key, $active_components );
 406  }
 407  
 408  /**
 409   * Perform database updates for BP 1.9.2.
 410   *
 411   * In 1.9, BuddyPress stopped registering its theme directory when it detected
 412   * that bp-default (or a child theme) was not currently being used, in effect
 413   * deprecating bp-default. However, this ended up causing problems when site
 414   * admins using bp-default would switch away from the theme temporarily:
 415   * bp-default would no longer be available, with no obvious way (outside of
 416   * a manual filter) to restore it. In 1.9.2, we add an option that flags
 417   * whether bp-default or a child theme is active at the time of upgrade; if so,
 418   *
 419   * the theme directory will continue to be registered even if the theme is
 420   * deactivated temporarily. Thus, new installations will not see bp-default,
 421   * but legacy installations using the theme will continue to see it.
 422   *
 423   * @since 1.9.2
 424   */
 425  function bp_update_to_1_9_2() {
 426      if ( 'bp-default' === get_stylesheet() || 'bp-default' === get_template() ) {
 427          update_site_option( '_bp_retain_bp_default', 1 );
 428      }
 429  }
 430  
 431  /**
 432   * 2.0 update routine.
 433   *
 434   * - Ensure that the activity tables are installed, for last_activity storage.
 435   * - Migrate last_activity data from usermeta to activity table.
 436   * - Add values for all BuddyPress options to the options table.
 437   *
 438   * @since 2.0.0
 439   */
 440  function bp_update_to_2_0() {
 441  
 442      /* Install activity tables for 'last_activity' ***************************/
 443  
 444      bp_core_install_activity_streams();
 445  
 446      /* Migrate 'last_activity' data ******************************************/
 447  
 448      bp_last_activity_migrate();
 449  
 450      /* Migrate signups data **************************************************/
 451  
 452      if ( ! is_multisite() ) {
 453  
 454          // Maybe install the signups table.
 455          bp_core_maybe_install_signups();
 456  
 457          // Run the migration script.
 458          bp_members_migrate_signups();
 459      }
 460  
 461      /* Add BP options to the options table ***********************************/
 462  
 463      bp_add_options();
 464  }
 465  
 466  /**
 467   * 2.0.1 database upgrade routine.
 468   *
 469   * @since 2.0.1
 470   */
 471  function bp_update_to_2_0_1() {
 472  
 473      // We purposely call this during both the 2.0 upgrade and the 2.0.1 upgrade.
 474      // Don't worry; it won't break anything, and safely handles all cases.
 475      bp_core_maybe_install_signups();
 476  }
 477  
 478  /**
 479   * 2.2.0 update routine.
 480   *
 481   * - Add messages meta table.
 482   * - Update the component field of the 'new members' activity type.
 483   * - Clean up hidden friendship activities.
 484   *
 485   * @since 2.2.0
 486   */
 487  function bp_update_to_2_2() {
 488  
 489      // Also handled by `bp_core_install()`.
 490      if ( bp_is_active( 'messages' ) ) {
 491          bp_core_install_private_messaging();
 492      }
 493  
 494      if ( bp_is_active( 'activity' ) ) {
 495          bp_migrate_new_member_activity_component();
 496  
 497          if ( bp_is_active( 'friends' ) ) {
 498              bp_cleanup_friendship_activities();
 499          }
 500      }
 501  }
 502  
 503  /**
 504   * 2.3.0 update routine.
 505   *
 506   * - Add notifications meta table.
 507   *
 508   * @since 2.3.0
 509   */
 510  function bp_update_to_2_3() {
 511  
 512      // Also handled by `bp_core_install()`.
 513      if ( bp_is_active( 'notifications' ) ) {
 514          bp_core_install_notifications();
 515      }
 516  }
 517  
 518  /**
 519   * 2.5.0 update routine.
 520   *
 521   * - Add emails.
 522   *
 523   * @since 2.5.0
 524   */
 525  function bp_update_to_2_5() {
 526      bp_core_install_emails();
 527  }
 528  
 529  /**
 530   * 2.7.0 update routine.
 531   *
 532   * - Add email unsubscribe salt.
 533   * - Save legacy directory titles to the corresponding WP pages.
 534   * - Add ignore deprecated code option (false for updates).
 535   *
 536   * @since 2.7.0
 537   */
 538  function bp_update_to_2_7() {
 539      bp_add_option( 'bp-emails-unsubscribe-salt', base64_encode( wp_generate_password( 64, true, true ) ) );
 540  
 541      // Update post_titles
 542      bp_migrate_directory_page_titles();
 543  
 544      /*
 545       * Add `parent_id` column to groups table.
 546       * Also handled by `bp_core_install()`.
 547       */
 548      if ( bp_is_active( 'groups' ) ) {
 549          bp_core_install_groups();
 550  
 551          // Invalidate all cached group objects.
 552          global $wpdb;
 553          $bp = buddypress();
 554  
 555          $group_ids = $wpdb->get_col( "SELECT id FROM {$bp->groups->table_name}" );
 556  
 557          foreach ( $group_ids as $group_id ) {
 558              wp_cache_delete( $group_id, 'bp_groups' );
 559          }
 560      }
 561  
 562      // Do not ignore deprecated code for existing installs.
 563      bp_add_option( '_bp_ignore_deprecated_code', false );
 564  }
 565  
 566  /**
 567   * Retuns needed the fullname field ID for an update task.
 568   *
 569   * @since 8.0.0
 570   *
 571   * @return int The fullname field ID.
 572   */
 573  function bp_get_fullname_field_id_for_update() {
 574      /**
 575       * The xProfile component is active by default on new installs, even if it
 576       * might be inactive during this update, we need to set the custom visibility
 577       * for the default field, in case the Administrator decides to reactivate it.
 578       */
 579      global $wpdb;
 580      $bp_prefix = bp_core_get_table_prefix();
 581      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' ) ) ) );
 582  }
 583  
 584  /**
 585   * 5.0.0 update routine.
 586   *
 587   * - Make sure the custom visibility is disabled for the default profile field.
 588   * - Create the invitations table.
 589   * - Migrate requests and invitations to the new table.
 590   *
 591   * @since 5.0.0
 592   */
 593  function bp_update_to_5_0() {
 594      /**
 595       * The xProfile component is active by default on new installs, even if it
 596       * might be inactive during this update, we need to set the custom visibility
 597       * for the default field, in case the Administrator decides to reactivate it.
 598       */
 599      global $wpdb;
 600      $bp_prefix = bp_core_get_table_prefix();
 601      $field_id  = bp_get_fullname_field_id_for_update();
 602  
 603      $wpdb->insert(
 604          $bp_prefix . 'bp_xprofile_meta',
 605          array(
 606              'object_id'   => $field_id,
 607              'object_type' => 'field',
 608              'meta_key'    => 'allow_custom_visibility',
 609              'meta_value'  => 'disabled'
 610          ),
 611          array(
 612              '%d',
 613              '%s',
 614              '%s',
 615              '%s'
 616          )
 617      );
 618  
 619      bp_core_install_invitations();
 620  
 621      if ( bp_is_active( 'groups' ) ) {
 622          bp_groups_migrate_invitations();
 623      }
 624  }
 625  
 626  /**
 627   * 8.0.0 update routine.
 628   *
 629   * - Edit the `new_avatar` activity type's component to `members`.
 630   * - Upgrade Primary xProfile Group's fields to signup fields.
 631   *
 632   * @since 8.0.0
 633   */
 634  function bp_update_to_8_0() {
 635      global $wpdb;
 636      $bp_prefix = bp_core_get_table_prefix();
 637  
 638      // Install welcome email to email list.
 639      add_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' );
 640  
 641      bp_core_install_emails();
 642  
 643      remove_filter( 'bp_email_get_schema', 'bp_core_get_8_0_upgrade_email_schema' );
 644  
 645      // Update the `new_avatar` activity type's component to `members`.
 646      $wpdb->update(
 647          $bp_prefix . 'bp_activity',
 648          array(
 649              'component' => 'members',
 650          ),
 651          array(
 652              'type' => 'new_avatar',
 653          ),
 654          array(
 655              '%s',
 656          ),
 657          array(
 658              '%s',
 659          )
 660      );
 661  
 662      // Check if we need to create default signup fields.
 663      $field_id            = bp_get_fullname_field_id_for_update();
 664      $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 ) );
 665      if ( bp_get_signup_allowed() && ! $has_signup_position ) {
 666          // Get the Primary Group's fields.
 667          $signup_fields = $wpdb->get_col( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE group_id = 1 ORDER BY field_order ASC" );
 668  
 669          // Migrate potential signup fields.
 670          if ( $signup_fields ) {
 671              $signup_position = 0;
 672              foreach ( $signup_fields as $signup_field_id ) {
 673                  $signup_position += 1;
 674  
 675                  $wpdb->insert(
 676                      $bp_prefix . 'bp_xprofile_meta',
 677                      array(
 678                          'object_id'   => $signup_field_id,
 679                          'object_type' => 'field',
 680                          'meta_key'    => 'signup_position',
 681                          'meta_value'  => $signup_position,
 682                      ),
 683                      array(
 684                          '%d',
 685                          '%s',
 686                          '%s',
 687                          '%d',
 688                      )
 689                  );
 690              }
 691          }
 692      }
 693  
 694      bp_core_install_nonmember_opt_outs();
 695  }
 696  
 697  /**
 698   * Select only the emails that need to be installed with version 8.0.
 699   *
 700   * @since 8.0.0
 701   *
 702   * @param array $emails The array of emails schema.
 703   */
 704  function bp_core_get_8_0_upgrade_email_schema( $emails ) {
 705      $new_emails = array();
 706  
 707      if ( isset( $emails['core-user-activation'] ) ) {
 708          $new_emails['core-user-activation'] = $emails['core-user-activation'];
 709      }
 710  
 711      if ( isset( $emails['bp-members-invitation'] ) ) {
 712          $new_emails['bp-members-invitation'] = $emails['bp-members-invitation'];
 713      }
 714  
 715      return $new_emails;
 716  }
 717  
 718  /**
 719   * 10.0.0 update routine.
 720   *
 721   * - Install new BP Emails for membership requests.
 722   *
 723   * @since 10.0.0
 724   */
 725  function bp_update_to_10_0() {
 726  
 727      // Install membership request emails.
 728      add_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' );
 729  
 730      bp_core_install_emails();
 731  
 732      remove_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' );
 733  }
 734  
 735  /**
 736   * Select only the emails that need to be installed with version 10.0.
 737   *
 738   * @since 10.0.0
 739   *
 740   * @param array $emails The array of emails schema.
 741   */
 742  function bp_core_get_10_0_upgrade_email_schema( $emails ) {
 743      $new_emails = array();
 744  
 745      if ( isset( $emails['members-membership-request'] ) ) {
 746          $new_emails['members-membership-request'] = $emails['members-membership-request'];
 747      }
 748  
 749      if ( isset( $emails['members-membership-request-rejected'] ) ) {
 750          $new_emails['members-membership-request-rejected'] = $emails['members-membership-request-rejected'];
 751      }
 752  
 753      return $new_emails;
 754  }
 755  
 756  /**
 757   * 11.0.0 update routine.
 758   *
 759   * - Install new BP Emails for group membership requests which is completed by admin.
 760   *
 761   * @since 11.0.0
 762   */
 763  function bp_update_to_11_0() {
 764  
 765      add_filter( 'bp_email_get_schema', 'bp_core_get_11_0_upgrade_email_schema' );
 766  
 767      bp_core_install_emails();
 768  
 769      remove_filter( 'bp_email_get_schema', 'bp_core_get_11_0_upgrade_email_schema' );
 770  }
 771  
 772  /**
 773   * Select only the emails that need to be installed with version 11.0.
 774   *
 775   * @since 11.0.0
 776   *
 777   * @param array $emails The array of emails schema.
 778   */
 779  function bp_core_get_11_0_upgrade_email_schema( $emails ) {
 780      $new_emails = array();
 781  
 782      if ( isset( $emails['groups-membership-request-accepted-by-admin'] ) ) {
 783          $new_emails['groups-membership-request-accepted-by-admin'] = $emails['groups-membership-request-accepted-by-admin'];
 784      }
 785  
 786      if ( isset( $emails['groups-membership-request-rejected-by-admin'] ) ) {
 787          $new_emails['groups-membership-request-rejected-by-admin'] = $emails['groups-membership-request-rejected-by-admin'];
 788      }
 789  
 790      return $new_emails;
 791  }
 792  
 793  /**
 794   * Updates the component field for new_members type.
 795   *
 796   * @since 2.2.0
 797   *
 798   * @global $wpdb
 799   */
 800  function bp_migrate_new_member_activity_component() {
 801      global $wpdb;
 802      $bp = buddypress();
 803  
 804      // Update the component for the new_member type.
 805      $wpdb->update(
 806          // Activity table.
 807          $bp->members->table_name_last_activity,
 808          array(
 809              'component' => $bp->members->id,
 810          ),
 811          array(
 812              'component' => 'xprofile',
 813              'type'      => 'new_member',
 814          ),
 815          // Data sanitization format.
 816          array(
 817              '%s',
 818          ),
 819          // WHERE sanitization format.
 820          array(
 821              '%s',
 822              '%s'
 823          )
 824      );
 825  }
 826  
 827  /**
 828   * Remove all hidden friendship activities.
 829   *
 830   * @since 2.2.0
 831   */
 832  function bp_cleanup_friendship_activities() {
 833      bp_activity_delete( array(
 834          'component'     => buddypress()->friends->id,
 835          'type'          => 'friendship_created',
 836          'hide_sitewide' => true,
 837      ) );
 838  }
 839  
 840  /**
 841   * Update WP pages so that their post_title matches the legacy component directory title.
 842   *
 843   * As of 2.7.0, component directory titles come from the `post_title` attribute of the corresponding WP post object,
 844   * instead of being hardcoded. To ensure that directory titles don't change for existing installations, we update these
 845   * WP posts with the formerly hardcoded titles.
 846   *
 847   * @since 2.7.0
 848   */
 849  function bp_migrate_directory_page_titles() {
 850      $bp_pages = bp_core_get_directory_page_ids( 'all' );
 851  
 852      $default_titles = bp_core_get_directory_page_default_titles();
 853  
 854      $legacy_titles = array(
 855          'activity' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
 856          'blogs'    => _x( 'Sites', 'component directory title', 'buddypress' ),
 857          'groups'   => _x( 'Groups', 'component directory title', 'buddypress' ),
 858          'members'  => _x( 'Members', 'component directory title', 'buddypress' ),
 859      );
 860  
 861      foreach ( $bp_pages as $component => $page_id ) {
 862          if ( ! isset( $legacy_titles[ $component ] ) ) {
 863              continue;
 864          }
 865  
 866          $page = get_post( $page_id );
 867          if ( ! $page ) {
 868              continue;
 869          }
 870  
 871          // If the admin has changed the default title, don't touch it.
 872          if ( isset( $default_titles[ $component ] ) && $default_titles[ $component ] !== $page->post_title ) {
 873              continue;
 874          }
 875  
 876          // If the saved page title is the same as the legacy title, there's nothing to do.
 877          if ( $legacy_titles[ $component ] == $page->post_title ) {
 878              continue;
 879          }
 880  
 881          // Update the page with the legacy title.
 882          wp_update_post( array(
 883              'ID' => $page_id,
 884              'post_title' => $legacy_titles[ $component ],
 885          ) );
 886      }
 887  }
 888  
 889  /**
 890   * Redirect user to BP's What's New page on first page load after activation.
 891   *
 892   * @since 1.7.0
 893   *
 894   * @internal Used internally to redirect BuddyPress to the about page on activation.
 895   */
 896  function bp_add_activation_redirect() {
 897  
 898      // Bail if activating from network, or bulk.
 899      if ( isset( $_GET['activate-multi'] ) ) {
 900          return;
 901      }
 902  
 903      // Record that this is a new installation, so we show the right
 904      // welcome message.
 905      if ( bp_is_install() ) {
 906          set_transient( '_bp_is_new_install', true, 30 );
 907      }
 908  
 909      // Add the transient to redirect.
 910      set_transient( '_bp_activation_redirect', true, 30 );
 911  }
 912  
 913  /** Signups *******************************************************************/
 914  
 915  /**
 916   * Check if the signups table needs to be created or upgraded.
 917   *
 918   * @since 2.0.0
 919   *
 920   * @global WPDB $wpdb
 921   */
 922  function bp_core_maybe_install_signups() {
 923      global $wpdb;
 924  
 925      // The table to run queries against.
 926      $signups_table = $wpdb->base_prefix . 'signups';
 927  
 928      // Suppress errors because users shouldn't see what happens next.
 929      $old_suppress  = $wpdb->suppress_errors();
 930  
 931      // Never use bp_core_get_table_prefix() for any global users tables.
 932      $table_exists  = (bool) $wpdb->get_results( "DESCRIBE {$signups_table};" );
 933  
 934      // Table already exists, so maybe upgrade instead?
 935      if ( true === $table_exists ) {
 936  
 937          // Look for the 'signup_id' column.
 938          $column_exists = $wpdb->query( "SHOW COLUMNS FROM {$signups_table} LIKE 'signup_id'" );
 939  
 940          // 'signup_id' column doesn't exist, so run the upgrade
 941          if ( empty( $column_exists ) ) {
 942              bp_core_upgrade_signups();
 943          }
 944  
 945      // Table does not exist, and we are a single site, so install the multisite
 946      // signups table using WordPress core's database schema.
 947      } elseif ( ! is_multisite() ) {
 948          bp_core_install_signups();
 949      }
 950  
 951      // Restore previous error suppression setting.
 952      $wpdb->suppress_errors( $old_suppress );
 953  }
 954  
 955  /** Activation Actions ********************************************************/
 956  
 957  /**
 958   * Fire activation hooks and events.
 959   *
 960   * Runs on BuddyPress activation.
 961   *
 962   * @since 1.6.0
 963   */
 964  function bp_activation() {
 965  
 966      // Force refresh theme roots.
 967      delete_site_transient( 'theme_roots' );
 968  
 969      // Add options.
 970      bp_add_options();
 971  
 972      /**
 973       * Fires during the activation of BuddyPress.
 974       *
 975       * Use as of 1.6.0.
 976       *
 977       * @since 1.6.0
 978       */
 979      do_action( 'bp_activation' );
 980  
 981      // @deprecated as of 1.6.0
 982      do_action( 'bp_loader_activate' );
 983  }
 984  
 985  /**
 986   * Fire deactivation hooks and events.
 987   *
 988   * Runs on BuddyPress deactivation.
 989   *
 990   * @since 1.6.0
 991   */
 992  function bp_deactivation() {
 993  
 994      // Force refresh theme roots.
 995      delete_site_transient( 'theme_roots' );
 996  
 997      // Switch to WordPress's default theme if current parent or child theme
 998      // depend on bp-default. This is to prevent white screens of doom.
 999      if ( in_array( 'bp-default', array( get_template(), get_stylesheet() ) ) ) {
1000          switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
1001          update_option( 'template_root',   get_raw_theme_root( WP_DEFAULT_THEME, true ) );
1002          update_option( 'stylesheet_root', get_raw_theme_root( WP_DEFAULT_THEME, true ) );
1003      }
1004  
1005      /**
1006       * Fires during the deactivation of BuddyPress.
1007       *
1008       * Use as of 1.6.0.
1009       *
1010       * @since 1.6.0
1011       */
1012      do_action( 'bp_deactivation' );
1013  
1014      // @deprecated as of 1.6.0
1015      do_action( 'bp_loader_deactivate' );
1016  }
1017  
1018  /**
1019   * Fire uninstall hook.
1020   *
1021   * Runs when uninstalling BuddyPress.
1022   *
1023   * @since 1.6.0
1024   */
1025  function bp_uninstall() {
1026  
1027      /**
1028       * Fires during the uninstallation of BuddyPress.
1029       *
1030       * @since 1.6.0
1031       */
1032      do_action( 'bp_uninstall' );
1033  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1