Skip to content

Commit

Permalink
4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravity Forms authored and remcotolsma committed Dec 24, 2018
1 parent f2977c9 commit 1a41e57
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 25 deletions.
4 changes: 4 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.5 | 2018-12-19
- Fixed new tags not being added when updating existing list member.


# 4.4 | 2018-10-29
- Added support for MailChimp contact tags.

Expand Down
45 changes: 39 additions & 6 deletions class-gf-mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class GFMailChimp extends GFFeedAddOn {
*
* @since 1.0
* @access protected
* @var object $api If available, contains an instance of the Mailchimp API library.
* @var GF_MailChimp_API $api If available, contains an instance of the Mailchimp API library.
*/
public $api = null;

Expand Down Expand Up @@ -410,7 +410,7 @@ public function feed_settings_fields() {
'tooltip' => sprintf(
'<h6>%s</h6>%s',
esc_html__( 'Tags', 'gravityformsmailchimp' ),
esc_html__( 'Associate tags to your MailChimp contacts with a comma separated list. (e.g. new lead, Gravity Forms, web source)', 'gravityformsmailchimp' )
esc_html__( 'Associate tags to your MailChimp contacts with a comma separated list (e.g. new lead, Gravity Forms, web source). Commas within a merge tag value will be created as a single tag.', 'gravityformsmailchimp' )
),
),
array(
Expand Down Expand Up @@ -1194,11 +1194,19 @@ public function process_feed( $feed, $entry, $form ) {
'ip_signup' => rgar( $entry, 'ip' ),
'vip' => rgars( $feed, 'meta/markAsVIP' ) ? true : false,
'note' => rgars( $feed, 'meta/note' ),
'tags' => array(),
);

// Get existing tags.
$existing_tags = $member ? wp_list_pluck( $member['tags'], 'name' ) : array();

// Add tags to subscription.
if ( ! empty( $tags ) ) {
$subscription['tags'] = $tags;
$subscription['tags'] = $member ? array_merge( $existing_tags, $tags ) : $tags;
$subscription['tags'] = array_unique( $subscription['tags'] );
} else {
$subscription['tags'] = $member ? $existing_tags : $subscription['tags'];
$subscription['tags'] = array_unique( $subscription['tags'] );
}

// Prepare transaction type for filter.
Expand Down Expand Up @@ -1262,6 +1270,13 @@ public function process_feed( $feed, $entry, $form ) {
unset( $subscription['vip'] );
}

// Remove tags from subscription object.
$tags = $subscription['tags'];
unset( $subscription['tags'] );
foreach ( $tags as &$tag ) {
$tag = array( 'name' => $tag, 'status' => 'active' );
}

// Remove note from the subscription object and process any merge tags.
$note = GFCommon::replace_variables( $subscription['note'], $form, $entry, false, true, false, 'text' );
unset( $subscription['note'] );
Expand Down Expand Up @@ -1289,13 +1304,31 @@ public function process_feed( $feed, $entry, $form ) {
$this->log_error( __METHOD__ . '(): Field errors when attempting subscription: ' . print_r( $e->getErrors(), true ) );
}

return;
return $entry;

}

try {

// Log the subscriber tags to be added or updated.
$this->log_debug( __METHOD__ . "(): Subscriber tags to be {$action}: " . print_r( $tags, true ) );

// Update tags.
$this->api->update_member_tags( $list_id, $subscription['email_address'], $tags );

// Log that the subscriber tags was added or updated.
$this->log_debug( __METHOD__ . "(): Subscriber tags successfully {$action}." );

} catch ( Exception $e ) {

// Log that subscription could not be added or updated.
$this->add_feed_error( sprintf( esc_html__( 'Unable to add/update subscriber tags: %s', 'gravityformsmailchimp' ), $e->getMessage() ), $feed, $entry, $form );

}

if ( ! $note ) {
// Abort as there is no note to process.
return;
return $entry;
}

try {
Expand All @@ -1309,7 +1342,7 @@ public function process_feed( $feed, $entry, $form ) {
// Log that the note could not be added.
$this->add_feed_error( sprintf( esc_html__( 'Unable to add note to subscriber: %s', 'gravityformsmailchimp' ), $e->getMessage() ), $feed, $entry, $form );

return;
return $entry;

}

Expand Down
55 changes: 44 additions & 11 deletions includes/class-gf-mailchimp-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public function __construct( $api_key = '' ) {
* @since 4.0
* @access public
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function account_details() {

Expand All @@ -73,9 +74,10 @@ public function account_details() {
* @param string $list_id MailChimp list ID.
* @param string $category_id Interest category ID.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function get_interest_category_interests( $list_id, $category_id ) {

Expand All @@ -91,9 +93,10 @@ public function get_interest_category_interests( $list_id, $category_id ) {
*
* @param string $list_id MailChimp list ID.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws Exception
*/
public function get_list( $list_id ) {

Expand All @@ -109,9 +112,10 @@ public function get_list( $list_id ) {
*
* @param array $params List request parameters.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function get_lists( $params ) {

Expand All @@ -127,9 +131,10 @@ public function get_lists( $params ) {
*
* @param string $list_id MailChimp list ID.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function get_list_interest_categories( $list_id ) {

Expand All @@ -146,9 +151,10 @@ public function get_list_interest_categories( $list_id ) {
* @param string $list_id MailChimp list ID.
* @param string $email_address Email address.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function get_list_member( $list_id, $email_address ) {

Expand All @@ -167,9 +173,10 @@ public function get_list_member( $list_id, $email_address ) {
*
* @param string $list_id MailChimp list ID.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function get_list_merge_fields( $list_id ) {

Expand All @@ -187,9 +194,10 @@ public function get_list_merge_fields( $list_id ) {
* @param string $email_address Email address.
* @param array $subscription Subscription details.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function update_list_member( $list_id, $email_address, $subscription ) {

Expand All @@ -200,6 +208,30 @@ public function update_list_member( $list_id, $email_address, $subscription ) {

}

/**
* Update tags for a MailChimp list member.
*
* @since Unknown
* @access public
*
* @param string $list_id MailChimp list ID.
* @param string $email_address Email address.
* @param array $tags Member tags.
*
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function update_member_tags( $list_id, $email_address, $tags ) {

// Prepare subscriber hash.
$subscriber_hash = md5( strtolower( $email_address ) );

return $this->process_request( 'lists/' . $list_id . '/members/' . $subscriber_hash . '/tags', array( 'tags' => $tags ), 'POST' );

}

/**
* Add a note to the MailChimp list member.
*
Expand All @@ -210,9 +242,10 @@ public function update_list_member( $list_id, $email_address, $subscription ) {
* @param string $email_address Email address.
* @param string $note The note to be added to the member.
*
* @uses GF_MailChimp_API::process_request()
* @uses GF_MailChimp_API::process_request()
*
* @return array
* @throws GF_MailChimp_Exception|Exception
*/
public function add_member_note( $list_id, $email_address, $note ) {

Expand All @@ -234,7 +267,7 @@ public function add_member_note( $list_id, $email_address, $note ) {
* @param string $method Request method. Defaults to GET.
* @param string $return_key Array key from response to return. Defaults to null (return full response).
*
* @throws GF_MailChimp_Exception If API request returns an error, exception is thrown.
* @throws GF_MailChimp_Exception|Exception If API request returns an error, exception is thrown.
*
* @return array
*/
Expand Down Expand Up @@ -308,7 +341,7 @@ private function process_request( $path = '', $data = array(), $method = 'GET',
// Get the response code.
$response_code = wp_remote_retrieve_response_code( $response );

if ( $response_code != 200 ) {
if ( ! in_array( $response_code, array( 200, 204 ) ) ) {

// If status code is set, throw exception.
if ( isset( $response['body']['status'] ) && isset( $response['body']['title'] ) ) {
Expand Down
Binary file modified languages/gravityformsmailchimp-ar.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-ca.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-da_DK.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-de_DE.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-de_DE_formal.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-en_AU.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-en_GB.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-es_ES.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-fi.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-fr_CA.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-fr_FR.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-hu_HU.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-it_IT.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-ja.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-nb_NO.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-nl_BE.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-nl_NL.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-pt_BR.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-pt_PT.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-ru_RU.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-sv_SE.mo
Binary file not shown.
Binary file modified languages/gravityformsmailchimp-zh_CN.mo
Binary file not shown.
17 changes: 11 additions & 6 deletions languages/gravityformsmailchimp.pot
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright 2009-2018 Rocketgenius, Inc.
msgid ""
msgstr ""
"Project-Id-Version: Gravity Forms MailChimp Add-On 4.4\n"
"Project-Id-Version: Gravity Forms MailChimp Add-On 4.5\n"
"Report-Msgid-Bugs-To: https://www.gravtiyforms.com\n"
"POT-Creation-Date: 2018-10-29 19:28:36+00:00\n"
"POT-Creation-Date: 2018-12-19 13:46:11+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -109,8 +109,9 @@ msgstr ""

#: class-gf-mailchimp.php:413
msgid ""
"Associate tags to your MailChimp contacts with a comma separated list. "
"(e.g. new lead, Gravity Forms, web source)"
"Associate tags to your MailChimp contacts with a comma separated list (e.g. "
"new lead, Gravity Forms, web source). Commas within a merge tag value will "
"be created as a single tag."
msgstr ""

#: class-gf-mailchimp.php:420
Expand Down Expand Up @@ -172,11 +173,15 @@ msgstr ""
msgid "Unable to check if email address is already used by a member: %s"
msgstr ""

#: class-gf-mailchimp.php:1285
#: class-gf-mailchimp.php:1300
msgid "Unable to add/update subscriber: %s"
msgstr ""

#: class-gf-mailchimp.php:1310
#: class-gf-mailchimp.php:1325
msgid "Unable to add/update subscriber tags: %s"
msgstr ""

#: class-gf-mailchimp.php:1343
msgid "Unable to add note to subscriber: %s"
msgstr ""

Expand Down
4 changes: 2 additions & 2 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Plugin Name: Gravity Forms MailChimp Add-On
Plugin URI: https://www.gravityforms.com
Description: Integrates Gravity Forms with MailChimp, allowing form submissions to be automatically sent to your MailChimp account
Version: 4.4
Version: 4.5
Author: rocketgenius
Author URI: https://www.rocketgenius.com
License: GPL-2.0+
Expand All @@ -34,7 +34,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**/

define( 'GF_MAILCHIMP_VERSION', '4.4' );
define( 'GF_MAILCHIMP_VERSION', '4.5' );

// If Gravity Forms is loaded, bootstrap the Mailchimp Add-On.
add_action( 'gform_loaded', array( 'GF_MailChimp_Bootstrap', 'load' ), 5 );
Expand Down

0 comments on commit 1a41e57

Please sign in to comment.