Skip to content

Error activating JetPack#917

Merged
scribu merged 1 commit intomasterfrom
pagenow
Dec 17, 2013
Merged

Error activating JetPack#917
scribu merged 1 commit intomasterfrom
pagenow

Conversation

@scribu
Copy link
Copy Markdown
Member

@scribu scribu commented Dec 17, 2013

Fresh install of WordPress 3.8 and JetPack 2.7

When I try to

wp plugin activate jetpack

I get the following response:

Fatal error: Cannot redeclare class Featured_Content in /public_html/wp-content/plugins/jetpack/modules/theme-tools/featured-content.php on line 24

Activating the plugin from the interface works just fine.

@scribu
Copy link
Copy Markdown
Member

scribu commented Dec 16, 2013

Confirmed with Jetpack 2.7.

@tierra
Copy link
Copy Markdown

tierra commented Dec 16, 2013

This happens since it's also included by Twenty Fourteen, but WP-CLI tries to activate Jetpack after the theme is loaded instead of before the theme as core does, at least, as far as I can tell. I'm not sure how to fix this for WP-CLI.

@westonruter
Copy link
Copy Markdown
Contributor

Either the class name in Jetpack or Twenty Fourteen (or both!) should get a prefix.

/cc @blobaugh

@tierra
Copy link
Copy Markdown

tierra commented Dec 16, 2013

Themes should be able to expect that plugins are loaded first, and this is just one side effect of potentially many more issues caused by a theme being loaded before a plugin is activated. So this is something that should be fixed in WP-CLI if at all possible, regardless of changes in Jetpack or Twenty Fourteen.

@scribu
Copy link
Copy Markdown
Member

scribu commented Dec 16, 2013

I don't think that's the problem. In the normal case, both WP and WP-CLI load themes after plugins. When activating plugins, both WP and WP-CLI load functions.php before the call to activate_plugin().

How I checked:

a) added a var_dump(__FILE__) at the top of the active theme's functions.php
b) added an exit call right before the call to activate_plugin() in wp-admin/plugins.php
c) tried to activate a plugin

@tierra
Copy link
Copy Markdown

tierra commented Dec 17, 2013

Looks like you're right, Jetpack doesn't even include the Featured_Content class unless the plugins_loaded hook is fired (and it's not during activation at all).

I'm not sure how this is being included and conflicting with Twenty Fourteen then (but it certainly is, and only when using WP-CLI to activate Jetpack, not when activating from wp-admin).

@scribu
Copy link
Copy Markdown
Member

scribu commented Dec 17, 2013

I think I've got it: the problem doesn't happen in wp-admin because the theme checks the $pagenow global (which I think WP-CLI doesn't set):

if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
    require get_template_directory() . '/inc/featured-content.php';
}

scribu pushed a commit that referenced this pull request Dec 17, 2013
Error activating JetPack
@scribu scribu merged commit a84b632 into master Dec 17, 2013
@scribu scribu deleted the pagenow branch December 17, 2013 13:35
@filtered
Copy link
Copy Markdown
Author

Thanks for the patch @scribu. Also the suggestion made by @tierra to switch the theme to twentythirteen, activate jetpack, and then switch back to twentyfourteen works as an immediate stop gap measure if upgrading wp-cli is difficult in your enviroment.

wp theme activate twentythirteen
wp plugin install jetpack --activate
wp theme activate twentyfourteen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants