• Resolved tahtackle

    (@tahtackle)


    Hi there!

    First off, thank you for this plugin – great work!

    I have an issue though, and the short question is: Can I get debug info about the returned value from the filter?

    Long version of the question:
    I’m trying to send a form to multiple recipients, but I can’t get it to work. I’ve figured out you can do this via commas, but it does not work with my filter.

    This is what I’ve got:

    /** Set the contact form 7 recipients with a filter.
     *  Separate multiple recipients with a comma (,).
     */
    function wpcf7_dynamic_recipient_by_creator_mail($recipients, $args=array()) {
    
        $creators = get_field('product_creators');
        $recipients = '';
        $i = 0;
        foreach($creators as $creator) {
            $i++;
            $mail = get_field('creator_e-mail', $creator);
            $recipients .= $mail . ($i <= sizeof($creators)-1 ? ',' : '');
        }
        //expected:
        //return '1@abc.de,2@abc.de,3@abc.de';
        return $recipients;
    }
    add_filter('wpcf7_creator_recipients', 'wpcf7_dynamic_recipient_by_creator_mail', 10, 2);

    The expected return is what I get when I echo the code on any given page, so the data retrieval part works. The dynamic recipient also works when I return the hard-coded value (and the mail gets sent to all recipients). But when I return the $recipient variable instead,I get a “your mail could not be sent, try later” error.

    Now, my question is somewhere along the lines of: Can I get some debug info on what the return statement got? Because I can’t figure out why it does not work, because all single parts are working as they should.

    Best Regards and thank you for your time,
    Fabian

    • This topic was modified 5 years, 4 months ago by tahtackle.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tahtackle

    (@tahtackle)

    Okay, so I’ve figured out the error is because the filter has no access to the current $post. Trying to figure out how to access that. Pretty sure it’s possible since there are special tags for ID, URL etc, just need to find out how to get them into the filter.

    Thread Starter tahtackle

    (@tahtackle)

    Alright, solved it.

    You can get the current post(id) by calling

    $submission = WPCF7_Submission::get_instance();
    $post_id = (int) $submission->get_meta( 'container_post_id' );

    Sorry for spamming your support forum, but hey, self-solving problems amirite!
    If my solution is kinda wonky or hacky let me know if there is a better way to do this.

    Best,
    Fabian

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Debugging faulty return $recipient;’ is closed to new replies.