Where is the code that adds a blog to Pro Site Level?

I am attempting to create an action hook that runs after site activation, using some custom meta I will add to the signup page with selected level. The goal is so after a user activates their site via activation email, the hooked function will run and add the new site to the Pro Site at the level passed in via meta. Does this make sense?

So I am trying to find code to grab and how to bring it in from the Pro Sites plugin.

I am using this code snippet someone shared in another thread,

require_once(WP_PLUGIN_DIR . '/pro-sites/pro-sites.php');
$psObj = new ProSites();
$proLevel = $psObj->get_level();

To be able to adjust what people see via their level, so that works. Is there a function I can call in a similar fashion to add a new site to Pro Sites level?

  • DavidM
    • DEV MAN’s Mascot

    Hi @Ryan,

    We've been digging through Pro Sites code and I think something like the following would work for ya:

    add_action( 'wpmu_activate_blog', 'add_level_to_site', 10, 5 );
    function add_level_to_site($blog_id, $user_id, $password, $title, $meta) {
        $p = new ProSites();
        $p->extend($blog_id, $extend, $gateway = false, $level = 1, $amount = false, $expires = false);
    
        //$extend = seconds
        //$level = level id
    }

    Does that sound viable to you?

    PS. please be sure to set the correct level, expires, etc.

    Cheers,
    David

  • Ryan
    • Design Lord, Child of Thor

    OH cool thank you.

    That would require me including the file like I mentioned in the question correct?

    I am going to play with that and see if I can get it to work, thank you for pointing it out!

    Also, could you help/advise on the proper way I would add a piece of meta to hold the chosen level at signup and pass it along to use in that function you shared? That would be most helpful :slight_smile:

    Thank you again!

  • Ryan
    • Design Lord, Child of Thor

    Hey David,

    Say I want to add this site to Pro Sites, via this code, which works thanks :slight_smile:

    $p->extend($blog_id, $extend, $gateway = false, $level = 2, $amount = false, $expires = false);

    What are those parameters supposed to accept? $level will be set from the meta array, which is an int I guess? Is $expires just true/false? All sites signed up will be a 7 day trial. Is $extend the length of time? So

    7 * 86400

    ?

    This make sense?

    Thanks

  • Ryan
    • Design Lord, Child of Thor

    Update here,

    So I am running this code on new site activation,

    $extend = 7 * 86400;
    	$level = $meta['level_choice'];
        $p = new ProSites();
        $p->extend($blog_id, $extend, 'Trial', $level);

    Problem is that I think the default Pro Site settings interfere maybe? Because I only want 7 day trial, but it adds the 7 days to it from the settings. Also, I set the level of the trial to be what they select at signup, and while it appears to work and populate properly, is there a way to alter the message that the notice displays? It always says the days and level name of the settings from the Pro Site setting panel.

    Thoughts?

  • Ryan
    • Design Lord, Child of Thor

    Yeah, the problem is that I need the level to be chosen when they are signing up, which is why I am doing it this way.

    So if they choose level 1, the trial is 7 days at level 1, and they must pay by then.

  • DavidM
    • DEV MAN’s Mascot

    Hi @Ryan,

    Really sorry for the delay here. I was actually asking previously about how you intended to add that code because there's a lot to take into account, as you're seeing.

    I'm not totally sure I understand what you mean about the 7 days added from the settings, but if the 7 days is already being added from the settings page, you wouldn't need to add the 7 days through code, correct?

    Did you maybe want the trial time to be calculated or conditioned upon something else?

    Also, could you let me know specifically which message you're asking about?

    You should be able to change messages through language files, though I'd like to see if another solution may exist.

    Could you maybe provide a screenshot or post the exact text that's displayed? I could then search the code to see what hooks might be available or see if there'e an easier solution.

    Thanks,
    David

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.