#4148 closed defect (bug) (fixed)
De-activating BP without changing theme first results in fatal error
Reported by: | hnla | Owned by: | |
---|---|---|---|
Milestone: | 1.6 | Priority: | normal |
Severity: | normal | Version: | 1.5.5 |
Component: | Templates | Keywords: | has-patch |
Cc: | hnla |
Description
Although we had added the switch_theme() function in bp-default functions.php to attempt to address issue of WP white screening if a theme not selected before bp de-activation, it in fact does still occur.
Scenario / path to replicate:
De-activate BP - visit front of site you should receive a fatal error ( Call to undefined function bp_site_name() )
Back into dashboard - themes say WP default selected. Rename BP folder to disable get site backup, re-enable and activate BP - do NOT activate a BP theme visit site BP-default will be running!!
So there is an apparent issue with themes not reverting and of BP hanging onto the options entry for 'stylesheet'
Looking at the switcher and it occurred that having this:
if ( !function_exists( 'bp_is_active' ) ) return; // If BuddyPress is not activated, switch back to the default WP theme if ( !defined( 'BP_VERSION' ) ) switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
Had to be wrong, as we were checking if BP active ( no it wasn't ) and effectively exiting.
Changing to this:
// If BuddyPress is not activated, switch back to the default WP theme first if ( ! defined( 'BP_VERSION' ) ) switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); // And then escape from further action if ( ! function_exists( 'bp_is_active' ) ) return;
Cured the issue and I could safely deactivate BP without worrying about theme selection as the theme switcher was now able to run first before we checked if BP active and exited.
Checked in DB and options field was being updated correctly.
Patch reverses order of these two items but maybe it's better simply written as:
if( ! function_exists( 'bp_is_active' ) switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); return;
Do we need to check is_active and version?
Attachments (1)
Change History (9)
#3
@
13 years ago
No longer sure my tests were valid as I seem not to be able to successfully deactivate BP and have theme switching run after all. The whole premise of trying to run this snippet of code from functions is dubious though we can't switch_theme if we have exited from processing and that is overlooking the fact that functions.php is not being parsed if the plugin is deactivated?
One thing I did note of interest? was that The Status theme had grabbed this section of code from functions.php for it's own functions.php yet in Status version we have switch_theme() run first then the check for bp_is_active() follows, and that is the way it would need to run, 'return' inline is effectively die()
#5
@
13 years ago
Ah cool that explains why and this works for Status as it's a child theme and IS still running thus functions.php is parsed and if we didn't have that switch_theme and then bp_is_active check and 'return' we in fact throw a function error, and it does work as expected.
It's just the case that bp-default is within the plugin so in this respect those checks do not ever get to run where running bp-default is concerned, so ideally bp-default should always be run as a child theme with a style.css and function.php acting as a loader function just running a check for bp_version and bp_is_active :)
#6
@
13 years ago
I'm going to put the patch in and then close this ticket. This will help anyone building a theme off of BP-Default.
patch reverses order of switch_theme and bp active check