4
4
5
5
use WP_CLI ;
6
6
use WP_CLI \Context ;
7
+ use WP_CLI \Fetchers \User ;
7
8
use WP_Session_Tokens ;
8
9
9
10
/**
@@ -39,12 +40,29 @@ public function process( $config ) {
39
40
40
41
// Bootstrap the WordPress administration area.
41
42
WP_CLI ::add_wp_hook (
42
- 'init ' ,
43
+ 'plugins_loaded ' ,
44
+ function () use ( $ config ) {
45
+ if ( isset ( $ config ['user ' ] ) ) {
46
+ $ fetcher = new User ();
47
+ $ user = $ fetcher ->get_check ( $ config ['user ' ] );
48
+ $ admin_user_id = $ user ->ID ;
49
+ } else {
50
+ // TODO: Add logic to find an administrator user.
51
+ $ admin_user_id = 1 ;
52
+ }
53
+
54
+ $ this ->log_in_as_admin_user ( $ admin_user_id );
55
+ },
56
+ defined ( 'PHP_INT_MIN ' ) ? PHP_INT_MIN : -2147483648 , // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
57
+ 0
58
+ );
59
+
60
+ WP_CLI ::add_wp_hook (
61
+ 'wp_loaded ' ,
43
62
function () {
44
- $ this ->log_in_as_admin_user ();
45
63
$ this ->load_admin_environment ();
46
64
},
47
- defined ( 'PHP_INT_MIN ' ) ? PHP_INT_MIN : - 2147483648 , // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
65
+ defined ( 'PHP_INT_MAX ' ) ? PHP_INT_MAX : 2147483648 , // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_maxFound
48
66
0
49
67
);
50
68
}
@@ -56,12 +74,11 @@ function () {
56
74
* A lot of premium plugins/themes have their custom update routines locked
57
75
* behind an is_admin() call.
58
76
*
77
+ * @param int<1, max> $admin_user_id to log in as
78
+ *
59
79
* @return void
60
80
*/
61
- private function log_in_as_admin_user () {
62
- // TODO: Add logic to find an administrator user.
63
- $ admin_user_id = 1 ;
64
-
81
+ private function log_in_as_admin_user ( $ admin_user_id ) {
65
82
wp_set_current_user ( $ admin_user_id );
66
83
67
84
$ expiration = time () + DAY_IN_SECONDS ;
0 commit comments