1

I'm using this technique: https://stackoverflow.com/questions/27323460/how-to-label-payments-in-gravity-forms-paypal-pro

To add comments to the paypal comments field from a gravity form. However, it's a multisite configuration. I'd like to modify it so the filter only triggers on blog_id 2

What's the proper method to make this conditional?

Much thanks.

  • @celso - mind weighing in? – whakawaehere Jul 25 '16 at 16:04
  • FYI - pinging a user will only work if they've been active on this post. You'll need to ping them on their own post :) – Tim Malone Jul 25 '16 at 16:05
  • Did you solve this Craig or do you still need an answer on the multi-site aspect? – jdm2112 Jul 25 '16 at 17:00
  • I have not yet solved it. – whakawaehere Jul 25 '16 at 17:01
  • @jdm2112 I have not solved it - do you have any insights you might be able to offer? It would be greatly appreciated. – whakawaehere Jul 26 '16 at 18:13
0

Using the code from the answer you linked in your question (untested at present):

add_filter( 'gform_paypalpaymentspro_args_before_payment','add_donation_comment', 10, 2 );
function add_donation_comment( $args, $form_id ) { // do not edit $args or $form_id
    global $blog_id; // Make this available to the function

    // Apply filter only if blog id is 2
    if ( 2 !== $blog_id ) {
        return $args;
    }       

    // apply to form 1 only
    if ( 1 == $form_id ) { // Replace '1' with your form id
            $args["COMMENT1"] = 'Field Project'; // Comment1 is the arg that paypal pro uses. 
    }
    // apply to form 2 only
    if ( 2 == $form_id ) { // Replace '2' with your form id
            $args["COMMENT1"] = 'Help Us Grow';
    }
    // always return the args, even if not changing anything 
    return $args;

}

Adding the global $blog_id line makes this WP value available to the function. As you know, it stores the site ID# in a multi-site install, allowing you to apply your filter on specific sites in your network.

The second addition is just a test of that value, written in the form of a Yoda condition. If this function is executing on any other site, the $args array is returned unchanged.

The rest of this code is exactly as found in the answer you referenced.

NOTE: I am unable to test this right now but I will be available later if you have any problems. Cheers.

  • 1
    Fantastic. I was SO close ... thank you for clearing it up and being so willing to share your knowledge. I will test it now and report back. – whakawaehere Jul 26 '16 at 20:02
  • Glad to help. Let me know if this fails for any reason. – jdm2112 Jul 26 '16 at 20:25
  • I had to make a slight adjustment (I cannot say why it didn't work as you wrote it, but...) I changed the if ( 2 !== $blog_id ) to == and put the form specific conditions inside that condition, ending with return $args. Then I added an else that just returned the args. – whakawaehere Jul 26 '16 at 20:26
  • Don't forget to post your answer so this one gets closed. Thx – jdm2112 Jul 27 '16 at 13:48
0

Based on @jdm2112 response, I did the following:

add_filter('gform_paypalpaymentspro_args_before_payment','add_donation_comment', 10, 2 );
function add_donation_comment( $args, $form_id ) { // do not edit $args or $form_id
    global $blog_id; // Make this available to the function

    // Apply filter only if blog id is 2
    if ( 2 == $blog_id ) {

        // apply to form 1 only
        if ( 1 == $form_id ) { // Replace '1' with your form id
                $args["COMMENT1"] = 'Field Project'; // Comment1 is the arg that paypal pro uses. 
        }
        // apply to form 2 only
        if ( 2 == $form_id ) { // Replace '2' with your form id
                $args["COMMENT1"] = 'Help Us Grow';
        }
        // always return the args, even if not changing anything 
        return $args;

    }       

    else {

        // always return the args, even if not changing anything 
        return $args;

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.