Auto pro sites credits in signup

Good day team
Is it possible to give users auto credits for pro sites when they sign up?
At sign up so I don't have to do it manually for each customer
Carpe diem
Robert

  • robertvideo

    what really do you work for burger king and not WPMU???
    Pro-sites does not have credits? OH REALLY I guess I made it all up
    if you dont know what you are talking about why waste me time and give me VERY BAD info
    Im totally insulted by you misguided reply
    I 100% suggest you stop offering help when you dont know the product
    credit is 100% part of pro-sites

  • Vaughan

    Hi,

    It wasn't my intention to insult you.

    I've actually never used the bulk update feature before. So I wasn't aware of that. I apologise.

    The only options available are in the Bulk upgrade settings, where you can select the cost for x amount of credits which the member can purchase.

    Currently, there is no ability to assign credits during sign up, however, I will certainly add this to the features list & ask one of our SLS guys to see if there's a custom function which could be used to achieve this.

    Thanks

      • Tyler Postle

        Hey again Robert,

        Been awhile since we last spoke, I didn't realize Dominos Pizza was offering to have their developers look at customers website issues now :p

        As Vaughan alluded to, this isn't currently possible but we have flagged it for one of our SLS staff(coding experts) to take a look at and see if there is a realtively quick custom solution we can provide you, otherwise it would be something that you need to hire a developer for. We do have a members only jobs board for such situations if it comes to that: https://premium.wpmudev.org/wordpress-development/

        I do want to remind you from our last conversation where I mentioned if you continue to insult our staff then you would be permanently banned from our support, please keep that in mind. I realize we made a mistake on the first reply as Vaughan didn't know the credits module you were referring too but he did apologise for that and then flagged it for one of our developers since it requires a custom solution to auto-apply credits.

        One of us will reply back here once it has been looked into. Note that SLS deal with more advanced tickets so their responses can take longer than your typical support ticket. If you would rather not wait for our developer's feedback and you want to just hire someone right away then that's fine too, let us know and we'll call off our dev.

        Hope you have a great rest of your day/night.

        Cheers,
        Tyler

  • Mahlamusa

    Hello Robert,

    I hope you are doing great today and thank you for your patience so far. I am sorry for the late reply regarding this issue.

    I have written a code snippet to help you achieve this. I have tried various hooks to execute the during the initialization of WordPress but most of them do not seem to work as expected. The 'wpmu_activate_blog' filter seems to be the best option for executing the code.

    You can use the 'wpmu_activate_blog' filter as follows:

    add_filter('wpmu_activate_blog','callback_function_to_add_credits');
    function callback_function_to_add_credits(){
             update_user_meta( $user_id, 'supporter_credits', $new_credits_amount );
    }

    Please note that you have to get the '$user_id' and assign a value to '$new_credits_amount' which will be the number of credits you are assigning. You can add the above code snippet to your theme's functions.php file or create a .php file and upload it to 'wp-content/mu-plugins'.

    You may simply copy the following code and paste it to a new .php file, save it and upload the .php file to your website in the folder '/wp-content/mu-plugins/'. this will make sure the plugin will be executed automatically on your website without the need to activate it.

    <?php
    /*
    Plugin Name: Auto Credit on Signup
    */
    
    class Auto_Credits{
    	function __construct(){
    		if(is_multisite()){
    			add_filter('wpmu_activate_blog', array(&$this, 'auto_credits'), 10, 5);
    		}
    	}	
    
    	function auto_credits() {
    
    		$uid = get_current_user_id();
    		$credits = 100;
    		$old_credits = get_user_meta( $uid, "supporter_credits", true );
    		if ( empty( $old_credits ) || $old_credits < 0 ) {
    			$old_credits = 0;
    		}
    		$new_credits = $old_credits + $credits;
    		if ( empty( $new_credits ) || $new_credits < 0 ) {
    			$new_credits = 0;
    		}
    		error_log("Applying auto credits for user: $uid, credits: $credits, old credits: $old_credits, new credits: $new_credits");
    		update_user_meta( $uid, 'supporter_credits', $new_credits );
    	}
    }
    
    new Auto_Credits;

    Please note that this code will only execute when a new blog is activated since it is hooked to 'wpmu_activate_blog' filter. If it is a paid Pro Sites level this will occur after a successful payment regardless of which payment gateway was used. If you wish to try other action hooks or filters you may try adding the following lines of code inside the '__construct()' function:

    add_filter('wpmu_signup_user_notification', array(&$this, 'auto_credits'), 10, 3);
    add_filter('wpmu_signup_blog_notification', array(&$this, 'auto_credits'), 10, 3);
    add_filter('wpmu_activate_user', array(&$this,'auto_credits'), 10, 3);
    add_action('signup_finished', array(&$this,'auto_credits'), 10, 3 );
    add_action('supporter_payment_processed', array(&$this,'auto_credits'), 10, 3 );

    Add below or above the line:
    add_filter('wpmu_activate_blog', array(&$this, 'auto_credits'), 10, 5);

    So you will have the '__construct()' function look like this:

    function __construct(){
    		if(is_multisite()){
    			    add_filter('wpmu_activate_blog', array(&$this, 'auto_credits'), 10, 5);
                add_filter('wpmu_signup_user_notification', array(&$this, 'auto_credits'), 10, 3);
                add_filter('wpmu_signup_blog_notification', array(&$this, 'auto_credits'), 10, 3);
                add_filter('wpmu_activate_user', array(&$this,'auto_credits'), 10, 3);
                add_action('signup_finished', array(&$this,'auto_credits'), 10, 3 );
                add_action('supporter_payment_processed', array(&$this,'auto_credits'), 10, 3 );
    		}
    }

    I hope this helps you achieve your goals. If you need further help with this issue let us know, we are always happy to help you.

    I hope you enjoy your day further.

    Cheers,
    Mahlamusa