-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blueprints: plugins are activated with is_admin() false #523
Comments
Hey @akirk 👋 Sorry about that - ideally there won’t be breaking changes out of the blue. Plugin activation was recently refactored from clicking the „activate” link as an admin to calling the activate_plugin() WordPress function. I suspect that same change removed the autologin, which is fine on its own, but I would have preferred to catch it early and communicate accordingly. Thinking about the future, Blueprints could really use a high test coverage - let’s expedite #463 to make it possible. |
To fix, let’s make sure admin is the active user before calling activate_plugin() and activate_theme(). AFAIR adding |
Actually |
Actually I was wrong, is_admin() refers to „are we in wp-admin right now?”: function is_admin() {
if ( isset( $GLOBALS['current_screen'] ) ) {
return $GLOBALS['current_screen']->in_admin();
} elseif ( defined( 'WP_ADMIN' ) ) {
return WP_ADMIN;
}
return false;
} in this case, |
Looking back on the previous implementation of the blueprint step The plugin install and activation were performed by requesting ("visiting") pages under const pluginForm = await playground.request({
url: '/wp-admin/plugin-install.php?tab=upload',
}); WIth the refactor, the step no longer goes through admin screens but invokes PHP and manually loads a minimal WordPress environment. const requiredFiles = [
`${await playground.documentRoot}/wp-load.php`,
`${await playground.documentRoot}/wp-admin/includes/plugin.php`,
];
...
const result = await playground.run({
code: `<?php
${requiredFiles.map((file) => `require_once( '${file}' );`).join('\n')}
$plugin_path = '${pluginPath}';
if (!is_dir($plugin_path)) {
activate_plugin($plugin_path);
return;
}
... A backward-compatible solution would be to ensure that the current user is available before calling
I see, that's solved by PR #524 setting This situation seems possibly relevant to other blueprint steps, many of which are about "admin" actions. They might need to be performed with The The |
Thanks for the analysis! As this issue around |
What I specifically observe: The GlotPress plugin no longer properly initializes and fails to create its database tables. Specifically this section no longer runs:
This code should run upon every plugin load but it is never executed and I suspect this is because
is_admin()
is false when the plugin is activated.The text was updated successfully, but these errors were encountered: