Ticket #8198: 8198.patch
File 8198.patch, 21.6 KB (added by , 5 years ago) |
---|
-
src/class-buddypress.php
a b class BuddyPress { 118 118 119 119 // Only run these methods if they haven't been run previously 120 120 if ( null === $instance ) { 121 $instance = new BuddyPress ;121 $instance = new BuddyPress(); 122 122 $instance->constants(); 123 123 $instance->setup_globals(); 124 124 $instance->legacy_constants(); … … class BuddyPress { 141 141 * @see BuddyPress::instance() 142 142 * @see buddypress() 143 143 */ 144 private function __construct() { /* Do nothing here */ } 144 private function __construct() { 145 /* Do nothing here */ } 145 146 146 147 /** 147 148 * A dummy magic method to prevent BuddyPress from being cloned. 148 149 * 149 150 * @since 1.7.0 150 151 */ 151 public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 152 public function __clone() { 153 _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 152 154 153 155 /** 154 156 * A dummy magic method to prevent BuddyPress from being unserialized. 155 157 * 156 158 * @since 1.7.0 157 159 */ 158 public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 160 public function __wakeup() { 161 _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'buddypress' ), '1.7' ); } 159 162 160 163 /** 161 164 * Magic method for checking the existence of a certain custom field. … … class BuddyPress { 166 169 * 167 170 * @return bool 168 171 */ 169 public function __isset( $key ) { return isset( $this->data[$key] ); } 172 public function __isset( $key ) { 173 return isset( $this->data[ $key ] ); } 170 174 171 175 /** 172 176 * Magic method for getting BuddyPress variables. … … class BuddyPress { 177 181 * 178 182 * @return mixed 179 183 */ 180 public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; } 184 public function __get( $key ) { 185 return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null; } 181 186 182 187 /** 183 188 * Magic method for setting BuddyPress variables. … … class BuddyPress { 187 192 * @param string $key Key to set a value for. 188 193 * @param mixed $value Value to set. 189 194 */ 190 public function __set( $key, $value ) { $this->data[$key] = $value; } 195 public function __set( $key, $value ) { 196 $this->data[ $key ] = $value; } 191 197 192 198 /** 193 199 * Magic method for unsetting BuddyPress variables. … … class BuddyPress { 196 202 * 197 203 * @param string $key Key to unset a value for. 198 204 */ 199 public function __unset( $key ) { if ( isset( $this->data[$key] ) ) unset( $this->data[$key] ); } 205 public function __unset( $key ) { 206 if ( isset( $this->data[ $key ] ) ) { 207 unset( $this->data[ $key ] ); 208 } } 200 209 201 210 /** 202 211 * Magic method to prevent notices and errors from invalid method calls. … … class BuddyPress { 208 217 * 209 218 * @return null 210 219 */ 211 public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; } 220 public function __call( $name = '', $args = array() ) { 221 unset( $name, $args ); 222 return null; } 212 223 213 224 /** Private Methods *******************************************************/ 214 225 … … class BuddyPress { 216 227 * Bootstrap constants. 217 228 * 218 229 * @since 1.6.0 219 *220 230 */ 221 231 private function constants() { 222 232 223 233 // Place your custom code (actions/filters) in a file called 224 234 // '/plugins/bp-custom.php' and it will be loaded before anything else. 225 235 if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) ) { 226 require ( WP_PLUGIN_DIR . '/bp-custom.php' );236 require WP_PLUGIN_DIR . '/bp-custom.php'; 227 237 } 228 238 229 239 // Path and URL … … class BuddyPress { 267 277 // /wp-admin/includes/plugin.php file in order to use that function. 268 278 269 279 // get network-activated plugins 270 $plugins = get_site_option( 'active_sitewide_plugins' );280 $plugins = get_site_option( 'active_sitewide_plugins' ); 271 281 272 282 // basename 273 283 $basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php'; … … class BuddyPress { 278 288 $root_blog_id = $current_site->blog_id; 279 289 } 280 290 } 281 282 291 } 283 292 284 293 define( 'BP_ROOT_BLOG', $root_blog_id ); … … class BuddyPress { 297 306 * Component global variables. 298 307 * 299 308 * @since 1.6.0 300 *301 309 */ 302 310 private function setup_globals() { 303 311 304 /** Versions * *********************************************************/312 /** Versions */ 305 313 306 314 $this->version = '6.0.0-alpha'; 307 315 $this->db_version = 12385; 308 316 309 /** Loading * **********************************************************/317 /** Loading */ 310 318 311 319 /** 312 320 * Should deprecated code be loaded? … … class BuddyPress { 316 324 */ 317 325 $this->load_deprecated = false; 318 326 319 /** Toolbar * **********************************************************/327 /** Toolbar */ 320 328 321 329 /** 322 330 * @var string The primary toolbar ID. 323 331 */ 324 332 $this->my_account_menu_id = ''; 325 333 326 /** URIs * *************************************************************/334 /** URIs */ 327 335 328 336 /** 329 337 * @var int The current offset of the URI. … … class BuddyPress { 336 344 */ 337 345 $this->no_status_set = false; 338 346 339 /** Components * *******************************************************/347 /** Components */ 340 348 341 349 /** 342 350 * @var string Name of the current BuddyPress component (primary). … … class BuddyPress { 358 366 */ 359 367 $this->is_single_item = false; 360 368 361 /** Root * *************************************************************/369 /** Root */ 362 370 363 371 /** 364 372 * Filters the BuddyPress Root blog ID. … … class BuddyPress { 369 377 */ 370 378 $this->root_blog_id = (int) apply_filters( 'bp_get_root_blog_id', BP_ROOT_BLOG ); 371 379 372 /** Paths* *************************************************************/380 /** Paths*/ 373 381 374 382 // BuddyPress root directory 375 $this->file 376 $this->basename 377 $this->plugin_dir 378 $this->plugin_url 383 $this->file = constant( 'BP_PLUGIN_DIR' ) . 'bp-loader.php'; 384 $this->basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php'; 385 $this->plugin_dir = trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ); 386 $this->plugin_url = trailingslashit( constant( 'BP_PLUGIN_URL' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) ); 379 387 380 388 // Languages 381 $this->lang_dir 389 $this->lang_dir = $this->plugin_dir . 'bp-languages'; 382 390 383 391 // Templates (theme compatibility) 384 $this->themes_dir 385 $this->themes_url 392 $this->themes_dir = $this->plugin_dir . 'bp-templates'; 393 $this->themes_url = $this->plugin_url . 'bp-templates'; 386 394 387 395 // Themes (for bp-default) 388 396 $this->old_themes_dir = $this->plugin_dir . 'bp-themes'; 389 397 $this->old_themes_url = $this->plugin_url . 'bp-themes'; 390 398 391 /** Theme Compat * *****************************************************/399 /** Theme Compat */ 392 400 393 $this->theme_compat 394 $this->filters 401 $this->theme_compat = new stdClass(); // Base theme compatibility class 402 $this->filters = new stdClass(); // Used when adding/removing filters 395 403 396 /** Users * ************************************************************/404 /** Users */ 397 405 398 406 $this->current_user = new stdClass(); 399 407 $this->displayed_user = new stdClass(); 400 408 401 /** Post types and taxonomies * ****************************************/409 /** Post types and taxonomies */ 402 410 403 411 /** 404 412 * Filters the post type slug for the email component. … … class BuddyPress { 407 415 * 408 416 * @param string $value Email post type slug. 409 417 */ 410 $this->email_post_type 418 $this->email_post_type = apply_filters( 'bp_email_post_type', 'bp-email' ); 411 419 412 420 /** 413 421 * Filters the taxonomy slug for the email type component. … … class BuddyPress { 449 457 * Include required files. 450 458 * 451 459 * @since 1.6.0 452 *453 460 */ 454 461 private function includes() { 455 462 spl_autoload_register( array( $this, 'autoload' ) ); 456 463 457 464 // Load the WP abstraction file so BuddyPress can run on all WordPress setups. 458 require ( $this->plugin_dir . 'bp-core/bp-core-wpabstraction.php' );465 require $this->plugin_dir . 'bp-core/bp-core-wpabstraction.php'; 459 466 460 467 // Setup the versions (after we include multisite abstraction above) 461 468 $this->versions(); 462 469 463 /** Update/Install * ***************************************************/470 /** Update/Install */ 464 471 465 472 // Theme compatibility 466 require ( $this->plugin_dir . 'bp-core/bp-core-template-loader.php' );467 require ( $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php' );473 require $this->plugin_dir . 'bp-core/bp-core-template-loader.php'; 474 require $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php'; 468 475 469 476 // Require all of the BuddyPress core libraries 470 require ( $this->plugin_dir . 'bp-core/bp-core-dependency.php' );471 require ( $this->plugin_dir . 'bp-core/bp-core-actions.php' );472 require ( $this->plugin_dir . 'bp-core/bp-core-caps.php' );473 require ( $this->plugin_dir . 'bp-core/bp-core-cache.php' );474 require ( $this->plugin_dir . 'bp-core/bp-core-cssjs.php' );475 require ( $this->plugin_dir . 'bp-core/bp-core-update.php' );476 require ( $this->plugin_dir . 'bp-core/bp-core-options.php' );477 require ( $this->plugin_dir . 'bp-core/bp-core-taxonomy.php' );478 require ( $this->plugin_dir . 'bp-core/bp-core-filters.php' );479 require ( $this->plugin_dir . 'bp-core/bp-core-attachments.php' );480 require ( $this->plugin_dir . 'bp-core/bp-core-avatars.php' );481 require ( $this->plugin_dir . 'bp-core/bp-core-widgets.php' );482 require ( $this->plugin_dir . 'bp-core/bp-core-template.php' );483 require ( $this->plugin_dir . 'bp-core/bp-core-adminbar.php' );484 require ( $this->plugin_dir . 'bp-core/bp-core-buddybar.php' );485 require ( $this->plugin_dir . 'bp-core/bp-core-catchuri.php' );486 require ( $this->plugin_dir . 'bp-core/bp-core-functions.php' );487 require ( $this->plugin_dir . 'bp-core/bp-core-moderation.php' );488 require ( $this->plugin_dir . 'bp-core/bp-core-loader.php' );489 require ( $this->plugin_dir . 'bp-core/bp-core-customizer-email.php' );490 require ( $this->plugin_dir . 'bp-core/bp-core-rest-api.php' );477 require $this->plugin_dir . 'bp-core/bp-core-dependency.php'; 478 require $this->plugin_dir . 'bp-core/bp-core-actions.php'; 479 require $this->plugin_dir . 'bp-core/bp-core-caps.php'; 480 require $this->plugin_dir . 'bp-core/bp-core-cache.php'; 481 require $this->plugin_dir . 'bp-core/bp-core-cssjs.php'; 482 require $this->plugin_dir . 'bp-core/bp-core-update.php'; 483 require $this->plugin_dir . 'bp-core/bp-core-options.php'; 484 require $this->plugin_dir . 'bp-core/bp-core-taxonomy.php'; 485 require $this->plugin_dir . 'bp-core/bp-core-filters.php'; 486 require $this->plugin_dir . 'bp-core/bp-core-attachments.php'; 487 require $this->plugin_dir . 'bp-core/bp-core-avatars.php'; 488 require $this->plugin_dir . 'bp-core/bp-core-widgets.php'; 489 require $this->plugin_dir . 'bp-core/bp-core-template.php'; 490 require $this->plugin_dir . 'bp-core/bp-core-adminbar.php'; 491 require $this->plugin_dir . 'bp-core/bp-core-buddybar.php'; 492 require $this->plugin_dir . 'bp-core/bp-core-catchuri.php'; 493 require $this->plugin_dir . 'bp-core/bp-core-functions.php'; 494 require $this->plugin_dir . 'bp-core/bp-core-moderation.php'; 495 require $this->plugin_dir . 'bp-core/bp-core-loader.php'; 496 require $this->plugin_dir . 'bp-core/bp-core-customizer-email.php'; 497 require $this->plugin_dir . 'bp-core/bp-core-rest-api.php'; 491 498 492 499 // Maybe load deprecated functionality (this double negative is proof positive!) 493 500 if ( ! bp_get_option( '_bp_ignore_deprecated_code', ! $this->load_deprecated ) ) { 494 require ( $this->plugin_dir . 'bp-core/deprecated/1.2.php' );495 require ( $this->plugin_dir . 'bp-core/deprecated/1.5.php' );496 require ( $this->plugin_dir . 'bp-core/deprecated/1.6.php' );497 require ( $this->plugin_dir . 'bp-core/deprecated/1.7.php' );498 require ( $this->plugin_dir . 'bp-core/deprecated/1.9.php' );499 require ( $this->plugin_dir . 'bp-core/deprecated/2.0.php' );500 require ( $this->plugin_dir . 'bp-core/deprecated/2.1.php' );501 require ( $this->plugin_dir . 'bp-core/deprecated/2.2.php' );502 require ( $this->plugin_dir . 'bp-core/deprecated/2.3.php' );503 require ( $this->plugin_dir . 'bp-core/deprecated/2.4.php' );504 require ( $this->plugin_dir . 'bp-core/deprecated/2.5.php' );505 require ( $this->plugin_dir . 'bp-core/deprecated/2.6.php' );506 require ( $this->plugin_dir . 'bp-core/deprecated/2.7.php' );507 require ( $this->plugin_dir . 'bp-core/deprecated/2.8.php' );508 require ( $this->plugin_dir . 'bp-core/deprecated/2.9.php' );509 require ( $this->plugin_dir . 'bp-core/deprecated/3.0.php' );510 require ( $this->plugin_dir . 'bp-core/deprecated/4.0.php' );501 require $this->plugin_dir . 'bp-core/deprecated/1.2.php'; 502 require $this->plugin_dir . 'bp-core/deprecated/1.5.php'; 503 require $this->plugin_dir . 'bp-core/deprecated/1.6.php'; 504 require $this->plugin_dir . 'bp-core/deprecated/1.7.php'; 505 require $this->plugin_dir . 'bp-core/deprecated/1.9.php'; 506 require $this->plugin_dir . 'bp-core/deprecated/2.0.php'; 507 require $this->plugin_dir . 'bp-core/deprecated/2.1.php'; 508 require $this->plugin_dir . 'bp-core/deprecated/2.2.php'; 509 require $this->plugin_dir . 'bp-core/deprecated/2.3.php'; 510 require $this->plugin_dir . 'bp-core/deprecated/2.4.php'; 511 require $this->plugin_dir . 'bp-core/deprecated/2.5.php'; 512 require $this->plugin_dir . 'bp-core/deprecated/2.6.php'; 513 require $this->plugin_dir . 'bp-core/deprecated/2.7.php'; 514 require $this->plugin_dir . 'bp-core/deprecated/2.8.php'; 515 require $this->plugin_dir . 'bp-core/deprecated/2.9.php'; 516 require $this->plugin_dir . 'bp-core/deprecated/3.0.php'; 517 require $this->plugin_dir . 'bp-core/deprecated/4.0.php'; 511 518 } 512 519 513 520 // Load wp-cli module if PHP 5.4+ 514 521 if ( defined( 'WP_CLI' ) && file_exists( $this->plugin_dir . 'cli/wp-cli-bp.php' ) && version_compare( phpversion(), '5.4.0', '>=' ) ) { 515 require ( $this->plugin_dir . 'cli/wp-cli-bp.php' );522 require $this->plugin_dir . 'cli/wp-cli-bp.php'; 516 523 } 517 524 } 518 525 … … class BuddyPress { 545 552 546 553 // These classes don't have a name that matches their component. 547 554 $irregular_map = array( 548 'BP_Akismet' => 'activity',549 'BP_REST_Activity_Endpoint' => 'activity',555 'BP_Akismet' => 'activity', 556 'BP_REST_Activity_Endpoint' => 'activity', 550 557 551 558 'BP_Admin' => 'core', 552 559 'BP_Attachment_Avatar' => 'core', … … class BuddyPress { 580 587 'BP_REST_Attachments_Member_Avatar_Endpoint' => 'core', 581 588 'BP_REST_Attachments_Group_Avatar_Endpoint' => 'core', 582 589 583 'BP_Core_Friends_Widget' => 'friends',590 'BP_Core_Friends_Widget' => 'friends', 584 591 585 'BP_Group_Extension' => 'groups',586 'BP_Group_Member_Query' => 'groups',587 'BP_REST_Groups_Endpoint' => 'groups',588 'BP_REST_Group_Membership_Endpoint' => 'groups',589 'BP_REST_Group_Invites_Endpoint' => 'groups',590 'BP_REST_Group_Membership_Request_Endpoint' => 'groups',592 'BP_Group_Extension' => 'groups', 593 'BP_Group_Member_Query' => 'groups', 594 'BP_REST_Groups_Endpoint' => 'groups', 595 'BP_REST_Group_Membership_Endpoint' => 'groups', 596 'BP_REST_Group_Invites_Endpoint' => 'groups', 597 'BP_REST_Group_Membership_Request_Endpoint' => 'groups', 591 598 592 'BP_Core_Members_Template' => 'members',593 'BP_Core_Members_Widget' => 'members',594 'BP_Core_Recently_Active_Widget' => 'members',595 'BP_Core_Whos_Online_Widget' => 'members',596 'BP_Registration_Theme_Compat' => 'members',597 'BP_Signup' => 'members',598 'BP_REST_Members_Endpoint' => 'members',599 'BP_Core_Members_Template' => 'members', 600 'BP_Core_Members_Widget' => 'members', 601 'BP_Core_Recently_Active_Widget' => 'members', 602 'BP_Core_Whos_Online_Widget' => 'members', 603 'BP_Registration_Theme_Compat' => 'members', 604 'BP_Signup' => 'members', 605 'BP_REST_Members_Endpoint' => 'members', 599 606 600 'BP_REST_Messages_Endpoint' => 'messages',607 'BP_REST_Messages_Endpoint' => 'messages', 601 608 602 'BP_REST_Notifications_Endpoint' => 'notifications',609 'BP_REST_Notifications_Endpoint' => 'notifications', 603 610 604 'BP_REST_XProfile_Fields_Endpoint' => 'xprofile',605 'BP_REST_XProfile_Field_Groups_Endpoint' => 'xprofile',606 'BP_REST_XProfile_Data_Endpoint' => 'xprofile',611 'BP_REST_XProfile_Fields_Endpoint' => 'xprofile', 612 'BP_REST_XProfile_Field_Groups_Endpoint' => 'xprofile', 613 'BP_REST_XProfile_Data_Endpoint' => 'xprofile', 607 614 ); 608 615 609 616 $component = null; … … class BuddyPress { 612 619 if ( isset( $irregular_map[ $class ] ) ) { 613 620 $component = $irregular_map[ $class ]; 614 621 615 // Next chunk is usually the component name.622 // Next chunk is usually the component name. 616 623 } elseif ( in_array( $class_parts[1], $components, true ) ) { 617 624 $component = $class_parts[1]; 618 625 } … … class BuddyPress { 654 661 * Set up the default hooks and actions. 655 662 * 656 663 * @since 1.6.0 657 *658 664 */ 659 665 private function setup_actions() { 660 666 661 667 // Add actions to plugin activation and deactivation hooks 662 add_action( 'activate_' . $this->basename, 'bp_activation');668 add_action( 'activate_' . $this->basename, 'bp_activation' ); 663 669 add_action( 'deactivate_' . $this->basename, 'bp_deactivation' ); 664 670 665 671 // If BuddyPress is being deactivated, do not add any actions … … class BuddyPress { 679 685 'register_theme_packages', // Register bundled theme packages (bp-themes) 680 686 'load_textdomain', // Load textdomain 681 687 'add_rewrite_tags', // Add rewrite tags 682 'generate_rewrite_rules' // Generate rewrite rules688 'generate_rewrite_rules', // Generate rewrite rules 683 689 ); 684 690 685 691 // Add the actions 686 foreach ( $actions as $class_action ) {692 foreach ( $actions as $class_action ) { 687 693 if ( method_exists( $this, $class_action ) ) { 688 694 add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 ); 689 695 } … … class BuddyPress { 713 719 $versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' ); 714 720 715 721 // 1.6-single exists, so trust it 716 if ( ! empty( $versions['1.6-single'] ) ) {722 if ( ! empty( $versions['1.6-single'] ) ) { 717 723 $this->db_version_raw = (int) $versions['1.6-single']; 718 724 719 // If no 1.6-single exists, use the max of the others725 // If no 1.6-single exists, use the max of the others 720 726 } else { 721 $versions['1.2'] = get_site_option( 722 $versions['1.5-multi'] = get_site_option( 723 $versions['1.6-multi'] = get_site_option( 724 $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 727 $versions['1.2'] = get_site_option( 'bp-core-db-version' ); 728 $versions['1.5-multi'] = get_site_option( 'bp-db-version' ); 729 $versions['1.6-multi'] = get_site_option( '_bp_db_version' ); 730 $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' ); 725 731 726 732 // Remove empty array items 727 733 $versions = array_filter( $versions ); 728 $this->db_version_raw = (int) ( ! empty( $versions ) ) ? (int) max( $versions ) : 0;734 $this->db_version_raw = (int) ( ! empty( $versions ) ) ? (int) max( $versions ) : 0; 729 735 } 730 736 } 731 737 … … class BuddyPress { 765 771 public function register_theme_packages() { 766 772 767 773 // Register the default theme compatibility package 768 bp_register_theme_package( array( 769 'id' => 'legacy', 770 'name' => __( 'BuddyPress Legacy', 'buddypress' ), 771 'version' => bp_get_version(), 772 'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ), 773 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ) 774 ) ); 775 776 bp_register_theme_package( array( 777 'id' => 'nouveau', 778 'name' => __( 'BuddyPress Nouveau', 'buddypress' ), 779 'version' => bp_get_version(), 780 'dir' => trailingslashit( $this->themes_dir . '/bp-nouveau' ), 781 'url' => trailingslashit( $this->themes_url . '/bp-nouveau' ) 782 ) ); 774 bp_register_theme_package( 775 array( 776 'id' => 'legacy', 777 'name' => __( 'BuddyPress Legacy', 'buddypress' ), 778 'version' => bp_get_version(), 779 'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ), 780 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ), 781 ) 782 ); 783 784 bp_register_theme_package( 785 array( 786 'id' => 'nouveau', 787 'name' => __( 'BuddyPress Nouveau', 'buddypress' ), 788 'version' => bp_get_version(), 789 'dir' => trailingslashit( $this->themes_dir . '/bp-nouveau' ), 790 'url' => trailingslashit( $this->themes_url . '/bp-nouveau' ), 791 ) 792 ); 783 793 784 794 // Register the basic theme stack. This is really dope. 785 795 bp_register_template_stack( 'get_stylesheet_directory', 10 ); 786 bp_register_template_stack( 'get_template_directory', 787 bp_register_template_stack( 'bp_get_theme_compat_dir', 796 bp_register_template_stack( 'get_template_directory', 12 ); 797 bp_register_template_stack( 'bp_get_theme_compat_dir', 14 ); 788 798 } 789 799 790 800 /**