Git Product home page Git Product logo

Comments (7)

WPprodigy avatar WPprodigy commented on July 21, 2024 2

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.

WPprodigy avatar WPprodigy commented on July 21, 2024

Could potentially also hook onto some sort of wp-setup hook that is triggered when new sites are created.

from vip-support.

mikeyarce avatar mikeyarce commented on July 21, 2024

@htdat this might be a good bug to look at!

from vip-support.

petervibert avatar petervibert commented on July 21, 2024

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.

htdat avatar htdat commented on July 21, 2024

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.

htdat avatar htdat commented on July 21, 2024

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

add_action( 'admin_init', array( $this, 'action_admin_init' ) );

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.

htdat avatar htdat commented on July 21, 2024

@WPprodigy - thanks for your feedback. I've created PR #91 for this issue.

from vip-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.