Automattic / vip-support

Manages the VIP Support Users on your site
GNU General Public License v2.0
12 stars 4 forks source link

Don't add roles on init #89

Closed mjangda closed 3 years ago

mjangda commented 3 years ago

add_role can lead to front-end writes which are not ideal. It can lead to undesirable circumstances with other roles being removed if there are intermittent database issues.

We still trigger our upgrade routine on admin_init so new installs will still get the roles (and there's still a chance for the latter issue to trigger but the likelihood is significantly reduced).

Also includes a convenience WP-CLI command to force run the upgrade routine if needed (wp vipsupport reset-roles)

To Test

On a new install (with PR in place):

  1. If you examine the wp_user_roles option in the db, in should not include either of the vip_support_* roles.
  2. Goto wp-admin
  3. This should trigger the upgrade routine
  4. The wp_user_roles option should now have the roles (can also confirm with wp role list.

WP-CLI command:

  1. Run wp vipsupport reset-roles; should result in no changes
  2. Run wp role delete vip_support. Running wp role list should show vip_support role missing.
  3. Run wp vipsupport reset-roles again. `vip_support role should be restored.
mjangda commented 3 years ago

Looks like tests might need some tweaks

nickdaugherty commented 3 years ago

The test setup pain makes me think we should just fold this back into mu-plugins directly (at a later time of course).

mjangda commented 3 years ago

The test setup pain makes me think we should just fold this back into mu-plugins directly (at a later time of course).

Yep, that's been a long-standing task unfortunately.