Skip to content
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

Activate plugins as if is_admin() #16

Open
JDGrimes opened this issue Jan 30, 2017 · 1 comment
Open

Activate plugins as if is_admin() #16

JDGrimes opened this issue Jan 30, 2017 · 1 comment

Comments

@JDGrimes
Copy link
Owner

I've just run across a plugin that will only be activated properly if the activation hook is called when is_admin() is true. The underlying code is actually risky and ill-conceived. However, that aside, it brought to my attention the fact that WordPress core always activates plugins when is_admin() is true. The question is, should we simulate that in our plugin activation code? After all, the plugin related functions are all currently stored in wp-admin/includes. However, I think it is good not to rely entirely on being in the admin either. It is probably better for the activation routine not to make those kinds of assumptions. But maybe it would be best for us to allow either way to be tested, as in admin and not as in admin.

@JDGrimes JDGrimes added this to the 0.3.0 milestone Jan 30, 2017
@JDGrimes JDGrimes self-assigned this Jan 30, 2017
@JDGrimes
Copy link
Owner Author

Note that I was able to achieve this for my current situation without modifying WPPPB itself. Just add this to tests/phpunit/includes/functions.php:

$loader = WordPoints_PHPUnit_Bootstrap_Loader::instance();
$loader->add_php_file( dirname( __FILE__ ) . '/simulate-admin.php', 'before' );

And then in the simulate-admin.php file:

global $current_screen;

/**
 * The WP_Screen class.
 *
 * @since 1.0.0
 */
require_once ABSPATH . '/wp-admin/includes/class-wp-screen.php';

$current_screen = WP_Screen::get( 'test' );

@JDGrimes JDGrimes removed this from the 0.3.0 milestone Oct 6, 2017
@JDGrimes JDGrimes removed their assignment Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant