Skip to content

Commit

Permalink
wip bring wpenv and local env closer together to reduce duplication a…
Browse files Browse the repository at this point in the history
…nd conflicts
  • Loading branch information
iandunn committed May 1, 2023
1 parent 0e428bd commit 41a33b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .wp-env/mu-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ function is_special_user( $user_id ) {
}

require_once __DIR__ . '/pub/mu-plugins/loader.php';
// needs to work in both envs
// wpmupluginsdir constant - wont in local tests b/c points to $_tests_dir
// rel path doesn't work b/c wpenv maps to different dir than what actually exists on FS when checking repo directly

// wpenv web
// wpenv test
// local web
// local test

// this is getting too time consuming
// should maybe just use wpenv like everyone else, but it doesn't work well for me

// Enable dummy provider for convenience when running locally.
add_filter( 'two_factor_providers', function( $providers ) {
Expand Down Expand Up @@ -43,4 +54,4 @@ function is_special_user( $user_id ) {
add_action( 'wp_install', function() {
update_option( 'template', 'wporg-support' );
update_option( 'stylesheet', 'wporg-support' );
} );
} );
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ WordPress.org-specific customizations for the Two Factor plugin

## Setup

TODO: a lot of this isn't needed for wp-env users, so maybe branch the instructions based on which env they want to use

1. Set up a local WP site.
1. Add this code to your `wp-config.php`:
```php
define( 'WP_ENVIRONMENT_TYPE', 'local' );

// TODO can remove all this and include .wpenv/muplugin.php instead
// Mimic w.org for testing wporg-two-factor
global $supes, $super_admins;
<!-- global $supes, $super_admins;
$supes = array(
'your_username'
);
Expand All @@ -19,12 +22,14 @@ WordPress.org-specific customizations for the Two Factor plugin
function is_special_user( $user_id ) {
$user = get_userdata( $user_id );
return in_array( $user->user_login, $GLOBALS['supes'], true );
}
} -->
```
1. Install and build the `wporg-mu-plugins` repository.
1. `git clone https://github.com/WordPress/wporg-mu-plugins.git --branch build wp-content/mu-plugins/pub`
1. Add this code to your `wp-content/mu-plugins/0-sandbox.php`:
```php
require_once WPMU_PLUGIN_DIR. '/wporg-mu-plugins/mu-plugins/loader.php';
require_once WPMU_PLUGIN_DIR . '/wporg-mu-plugins/mu-plugins/loader.php';

/// replace all this w/ just loading wpenv

// Enable dummy provider for convenience when testing locally.
add_filter( 'two_factor_providers', function( $providers ) {
Expand Down
16 changes: 15 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ function _manually_load_plugin() {
// Mimic w.org capes.php.
$GLOBALS['super_admins'] = array();

require_once dirname( __DIR__, 3 ) . '/mu-plugins//wporg-mu-plugins/mu-plugins/loader.php';
// $wp_content_dir = dirname( __DIR__, 3 ); // Not `WP_CONTENT_DIR` because that would be the $_tests_dir, which may be different.
// $is_wp_env = defined( 'WP_ENV' );
// exists? need to add custom to wpenv.json? or diff way to detect

// don't need this is setup env to match, update instructions

// won't need this if get local env setup to match docker env, and update readme to document that
// if ( ! function_exists( 'wporg_encrypt' ) ) {
// try {
// require_once dirname( __DIR__, 3 ) . '/mu-plugins/wporg-mu-plugins/mu-plugins/loader.php';
// } catch ( Exception $exception ) {
// die( 'ERROR: not load wporg-mu-plugins. See README for setup instructions.' );
// }
// }

require dirname( __DIR__, 2 ) . '/two-factor/two-factor.php';
require dirname( __DIR__ ) . '/wporg-two-factor.php';
}
Expand Down

0 comments on commit 41a33b7

Please sign in to comment.