WordPress,通过wpcf7_before_send_mail钩子将posted_data从联系人表单7传递到Fe


WordPress, Passing posted_data from Contact Form 7 via wpcf7_before_send_mail hook to FeedBurner

我正在开发一个WordPress插件,该插件使用联系人表单7 wpcf7_before_send_mail操作挂钩来获取在CF7中输入的电子邮件,如果用户选择了一个复选框,则将该电子邮件传递给MailChimp和FeedBurner。

MailChimp部分正在工作,因为我可以使用API传递订阅。然而,根据我的研究,订阅FeedBurner的唯一方法似乎是使用他们的表单,这对于我几个月开发的这个插件的一个更简单的版本来说效果很好,但似乎每当我通过wpcf7_before_send_mail钩子回显任何内容(如隐藏表单)时,它都会杀死CF7。以下是我的代码的相关部分:

add_action( 'wpcf7_before_send_mail', 'before_send_mail' );
function before_send_mail($wpcf7) {
    if (is_array($wpcf7->posted_data["subscribe"])){
    $subscribe_news = in_array ('Newsletter',$wpcf7->posted_data["subscribe"]);
    $subscribe_blog = in_array ('Blog',$wpcf7->posted_data["subscribe"]);
    }
    $subscribe_email = $wpcf7->posted_data["your-email"];  
    $subscribe_email = $wpcf7->posted_data["your-email"];       
    if($subscribe_news){ ktmcf7_submit_mailchimp($subscribe_email); }
    if($subscribe_blog){ ktmcf7_submit_feedburner($subscribe_email); }    
    }
function ktmcf7_submit_feedburner($subscribe_email){
    $options = get_option( 'ktm_singlesub_options' );
    ?>
    <script>
        alert('feedburner');
        window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo $options['feedburner_id'] ?>', 'popup5', 'scrollbars=yes,width=550,height=520');
    </script>
    <form name="form2" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popup5" >
        <input type="hidden" name="email" value="<?php echo $subscribe_email ?>" />
        <input type="hidden" value="<?php echo $options['feedburner_id'] ?>" name="uri"/>
        <input type="hidden" name="loc" value="en_US"/>
        <!-- input type="submit" value="Subscribe2" style="visibility:hidden;height:5px;" / -->
    </form>
    <script>
        document.form2.submit();
    </script>

再次,我尝试了几种不同的方式从这个钩子输出到浏览器(echo、var_dump等,每次arrouw都会无限旋转。我如何解决这个问题?除了使用表单之外,还有其他方法可以向Feedburner提交订阅吗?网站上说API不再可用,但有秘密后门吗?

谢谢。

理论上,您不希望输出表单,而是希望使用HTTP post将表单变量提交到FeedBurners端点,使用wp_函数发布HTTP post。

以下代码实现了一个WordPress插件,该插件将从Contact Form 7的wpcf7_before_send_mail事件处理程序发出HTTPPOST:

function wpcf7_do_something (&$WPCF7_ContactForm) {
    $url = 'http://your-end-point';
    $email = $WPCF7_ContactForm->posted_data['email'];    
    $post_data = array(
         'email' => urlencode($email),
         'feedburner_id' => urlencode($feedburner_id));
    $result = wp_remote_post( $url, array( 'body' => $post_data ) );
}
add_action("wpcf7_before_send_mail", "wpcf7_do_something");

上面的代码可以像广告中所说的那样工作,但请记住,您可能也需要处理CSRF令牌。https://en.wikipedia.org/wiki/Cross-site_request_forgery