Comments (7)
Nice digging! The first option is best imo. An added benefit here is that it can also run during cron jobs, so that guarantees execution within a minute or two as well.
So this is a pattern we often use throughout MU plugins: https://github.com/Automattic/Cron-Control/blob/11991dd41709b2e104c8be03e8a87dd21b49f5d5/includes/class-internal-events.php#L42-L47
IIRC, init
isn't consistent in CLI context but wp_loaded
is. The pattern is the same as your recommendation, just one hook change for consistency. Nice work.
from vip-support.
Could potentially also hook onto some sort of wp-setup hook that is triggered when new sites are created.
from vip-support.
@htdat this might be a good bug to look at!
from vip-support.
Noting that I have been fixing this for myself by adding the administrator role to my user, and then shortly after the vip_support role gets added.
from vip-support.
Sounds like this is not a new issue #58 and #87
As mentioned in #58, this is an issue for new sub-sites too.
A note here is this PR moved the add_role
trigger from init
to admin_init
#89
from vip-support.
There are two solutions like the following:
Hook to init
but only if it's a WP-CLI request
Should we maybe run this on init on the first version < 2 to make sure our users are created properly? What if we ran it on init only when it's a proxied request?
I think we can conditionally run on init
if it's a request is from WP CLI. I chose WP CLI because AFAIK, this plugin is being used via WP CLI as we interact with it mostly via https://admin.wpvip.com/
Basically, changing this line
vip-support/class-vip-support-role.php
Line 67 in 1c47e4c
To:
if ( defined('WP_CLI') && WP_CLI ) {
add_action( 'init', array( $this, 'action_admin_init' ) );
} else {
add_action( 'admin_init', array( $this, 'action_admin_init' ) );
}
I tested on my local site and I confirm that it's working correctly for both single and multinetwork sites (including adding sub-sites).
For VIP Go sites, I could test this https://admin.wpvip.com/#/sites/358/test-subdir-ms-01-preprod.go-vip.co and confirm wp role list --url=http://test-subdir-ms-01-preprod.go-vip.co/new-site
shows up VIP roles after adding a site via both WP CLI or wp-admin UI.
Hook onto an action during wp-setup
Could potentially also hook onto some sort of wp-setup hook that is triggered when new sites are created.
I also looked at this method, and used this code. It works for a new single site or multissite.
add_action( 'wp_install', array( $this, 'action_admin_init' ) );
add_action( 'admin_init', array( $this, 'action_admin_init' ) );
However, for adding sub-sites, it's pretty tricky as it's required to handle switch_to_blog
like this https://developer.wordpress.org/reference/hooks/wp_insert_site/#comment-4878
That make scode a bit more complicated though doable.
Next
I think the WP_CLI approach is good and simple enough for this issue. Would love to hear your opinion on this issue?
from vip-support.
@WPprodigy - thanks for your feedback. I've created PR #91 for this issue.
from vip-support.
Related Issues (20)
- Reassign VIP support users content HOT 1
- VIP Support User login fails w/non @automattic.com email
- Rename CLI command to `vip support`
- Add REST API endpoint for creating/deleting users.
- Don't provide blocked capabilities that no user should have
- Should removing support user delete associated posts? HOT 3
- wp_user_roles missing default roles on new sites HOT 1
- Help info for create-user is improperly displayed
- Add VIP user meta when creating support user HOT 1
- Address login loop with Jetpack SSO
- CLI: Set first and last name when creating user
- Mask Support User email on users list HOT 1
- Notice: Undefined index: display-name
- Don't delete posts when we delete users HOT 2
- Can't connect to JP HOT 2
- Support Email Masking doesn't work in Network setups
- Set Locale when creating a VIP Support User
- Allow disabling automatic support user removal
- VIP Support user creation fails with errors under wp core install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vip-support.