[buddypress-trac] [BuddyPress Trac] #7140: Class autoloading needs to check if the component is active before including the class

buddypress-trac noreply at wordpress.org
Fri Jun 24 17:34:37 UTC 2016


#7140: Class autoloading needs to check if the component is active before
including the class
--------------------------+--------------------
 Reporter:  r-a-y         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  2.6.1
Component:  Core          |     Version:  2.6.0
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |
--------------------------+--------------------
Changes (by r-a-y):

 * severity:  normal => major


Old description:

> For some people that have the groups component disabled, the
> `BP_Group_Extension` class is still loaded, causing a fatal error in some
> instances:
> https://buddypress.org/support/topic/fatal-error-
> on-a-buddypress-2-6-0-upgrade/#post-255171
>
> The problem is `class_exists()` calls are no longer relevant with class
> autoloading.  This causes the class to be loaded, but calls to component
> functions will result in a fatal error.
>
> For example:
>
> `Fatal error: Call to undefined function bp_get_current_group_id() in
> /wp-content/plugins/buddypress/bp-groups/classes/class-bp-group-
> extension.php on line 484 `
>

> To duplicate the problem, disable the groups component and add the
> following to `wp-content/plugins/bp-custom.php`:
>
> {{{#!php
> add_action( 'bp_include', function() {
>         if ( class_exists( 'BP_Group_Extension' ) ) {
>                 class My_Group_Extension extends BP_Group_Extension {
>                 }
>
>                 bp_register_group_extension( 'My_Group_Extension' );
>         }
> }, 99 );
> }}}
>
> Load a page on the frontend and you should get the same fatal error has
> referenced above.
>
> Attached patch is an attempt to fix this issue.  Note the ugliness to
> check if PHPUnit is in use.

New description:

 For some people that have the groups component disabled, the
 `BP_Group_Extension` class is still loaded, causing a fatal error in some
 instances:
 https://buddypress.org/support/topic/fatal-error-
 on-a-buddypress-2-6-0-upgrade/#post-255171

 The problem is `class_exists()` calls are no longer relevant with class
 autoloading.  This causes the class to be loaded, but calls to component
 functions will result in a fatal error.

 For example:

 `Fatal error: Call to undefined function bp_get_current_group_id() in /wp-
 content/plugins/buddypress/bp-groups/classes/class-bp-group-extension.php
 on line 484 `


 To duplicate the problem, disable the groups component and add the
 following to `wp-content/plugins/bp-custom.php`:

 {{{#!php
 add_action( 'bp_include', function() {
         if ( class_exists( 'BP_Group_Extension' ) ) {
                 class My_Group_Extension extends BP_Group_Extension {
                 }

                 bp_register_group_extension( 'My_Group_Extension' );
         }
 }, 99 );
 }}}

 Load a page on the frontend and you should get the same fatal error as
 referenced above.

 Attached patch is an attempt to fix this issue.  Note the ugliness to
 check if PHPUnit is in use.

--

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7140#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list