php Gravity Perks // GP填充任何东西//微小的邮件列表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Gravity Perks // GP填充任何东西//微小的邮件列表相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Gravity Perks // GP Populate Anything // Tiny Mailing List
 * http://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * Send an email all users who have submitted Form A when Form B is submitted. This *should not* be used
 * to large numbers of notifications.
 *
 * # Instructions
 *
 * These instructions assume that Form A contains an Email field.
 *
 * 1. Add a Hidden field to Form B.
 * 2. Enable "Populate value dynamically" setting and configure settings (https://gwiz.io/2LgCdZS):
 *    - Type: Gravity Forms Entry
 *    - Form: Select Form A.
 *    - Value Templates / Value: Select Email field.
 * 3. Create a new notification.
 * 4. Set the Sent To / Send to Email value as the merge tag for the Hidden field we added in Step 1 (https://gwiz.io/2CfXccB).
 *
 * That's it. Populate Anything combined with this snippet will populate a comma-delimited list of emails in to the Hidden
 * field. This snippet will parse the comma-delimited list and send a separate copy of the notification to each email.
 *
 * @version  0.2
 * @author   Gravity Wiz <support@gravitywiz.com>
 * @license  GPL-2.0+
 * @link     http://gravitywiz.com/
 *
 * Plugin Name:  GPPA Tiny Mailing List
 * Plugin URI:   http://gravitywiz.com/documentation/gravity-forms-populate-anything/
 * Description:  Send an email all users who have submitted Form A when Form B is submitted.
 * Author:       Gravity Wiz
 * Version:      0.2
 * Author URI:   http://gravitywiz.com
 */
class GPPA_Tiny_Mailing_List {

    public function __construct( $args = array() ) {

        // set our default arguments, parse against the provided arguments, and store for use throughout the class
        $this->_args = wp_parse_args( $args, array(
            'target_form_id'  => false,
            'target_field_id' => false,
            'source_field_id' => false,
        ) );

        // do version check in the init to make sure if GF is going to be loaded, it is already loaded
        add_action( 'init', array( $this, 'init' ) );

    }

    public function init() {

	    add_filter( 'gppa_process_template', array( $this, 'filter_emails_template' ), 10, 6 );

	    add_filter( 'gform_notification', array( $this, 'send_individual_notifications' ), 10, 3 );

    }

    public function filter_emails_template( $value, $field, $template, $object, $populate, $objects ) {
	    if( ! is_array( $field->choices ) && $field->formId == $this->_args['target_form_id'] && $field->id == $this->_args['target_field_id'] ) {
		    $value = implode( ',', wp_list_pluck( $objects, $this->_args['source_field_id'] ) );
	    }
	    return $value;
    }

    public function send_individual_notifications( $notification, $form, $entry ) {
	    global $_gppa_processing_notifications;

	    if( $_gppa_processing_notifications ) {
		    return $notification;
	    }

	    if( ! $this->is_applicable_form( $form ) ) {
	    	return $notification;
	    }

	    $tos = explode( ',', GFCommon::replace_variables( $notification['to'], $form, $entry, false, false, false, 'text' ) );
	    if( count( $tos ) <= 1 ) {
		    return $notification;
	    }

	    $_gppa_processing_notifications = true;

	    foreach( $tos as $to ) {
		    $notification['to'] = $to;
		    GFCommon::send_notification( $notification, $form, $entry );
	    }

	    $_gppa_processing_notifications = false;

	    $notification['to'] = false;

	    return $notification;
    }

    public function is_applicable_form( $form ) {
        $form_id = isset( $form['id'] ) ? $form['id'] : $form;
        return empty( $this->_args['target_form_id'] ) || $form_id == $this->_args['target_form_id'];
    }

}

# Configuration

new GPPA_Tiny_Mailing_List( array(
	'target_form_id' => 177,
	'target_field_id' => 3,
	'source_field_id' => 1,
) );

以上是关于php Gravity Perks // GP填充任何东西//微小的邮件列表的主要内容,如果未能解决你的问题,请参考以下文章

php Gravity Perks // GP条件定价//显示价格标签

php Gravity Perks // GP限制提交//集体应用全局限制

php Gravity Perks // GP电子商务领域//动态设置税额

php Gravity Perks // GP嵌套表单//从值隐藏产品名称

php Gravity Perks // GP通知计划程序//信用卡到期

php Gravity Perks // GP唯一ID //从Gravity PDF中排除唯一ID字段