diff --git a/.distignore b/.distignore index 7dacb1d..f242837 100644 --- a/.distignore +++ b/.distignore @@ -4,7 +4,6 @@ /.wordpress-org /node_modules /tests -/vendor # Files to ignore /.* diff --git a/.gitattributes b/.gitattributes index 541a824..0324b53 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,6 @@ /.wordpress-org export-ignore /node_modules export-ignore /tests export-ignore -/vendor export-ignore /.* export-ignore /CHANGELOG.md export-ignore diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index ffdb3b6..597a51b 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -35,11 +35,21 @@ jobs: if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci --no-optional + - name: Install Composer dependencies and dump autoload + run: | + composer install --no-dev --optimize-autoloader + composer dump-autoload + - name: Build plugin run: | npm run build + - name: Install SVN + run: | + sudo apt-get update + sudo apt-get install subversion + - name: Generate ZIP file uses: 10up/action-wordpress-plugin-build-zip@stable env: - SLUG: mailchimp + SLUG: mailchimp \ No newline at end of file diff --git a/.github/workflows/wordpress-plugin-asset-update.yml b/.github/workflows/wordpress-plugin-asset-update.yml index c923dd2..da145a7 100644 --- a/.github/workflows/wordpress-plugin-asset-update.yml +++ b/.github/workflows/wordpress-plugin-asset-update.yml @@ -20,6 +20,11 @@ jobs: node-version-file: .nvmrc cache: npm + - name: Install Composer dependencies and dump autoload + run: | + composer install --no-dev --optimize-autoloader + composer dump-autoload + - name: Build run: | npm ci --no-optional diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index b37771b..903301a 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -8,6 +8,7 @@ jobs: tag: name: New release runs-on: ubuntu-latest + if: ${{ !github.event.release.prerelease }} # Skip job if it is a pre-release steps: - name: Checkout code @@ -19,6 +20,11 @@ jobs: node-version-file: '.nvmrc' cache: 'npm' + - name: Install Composer dependencies and dump autoload + run: | + composer install --no-dev --optimize-autoloader + composer dump-autoload + - name: Build run: | npm ci --no-optional @@ -34,12 +40,11 @@ jobs: SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} SLUG: mailchimp - - name: Upload release asset - uses: actions/upload-release-asset@v1.0.2 + - name: Attach the wordpress.org plugin files to the Github release + uses: softprops/action-gh-release@v2 + with: + files: ${{ steps.deploy.outputs.zip-path }} + body: | + This release contains the latest updates for the WordPress plugin. env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ${{ steps.deploy.outputs.zip-path }} - asset_name: mailchimp.zip - asset_content_type: application/zip diff --git a/.gitignore b/.gitignore index 62369c7..10f5851 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ tests/cypress/reports tests/cypress/downloads mailchimp.zip + +# IDE +.vscode \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e0419ce..6c1739e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file, per [the Ke ## [Unreleased] - TBD +## [1.6.3] - 2025-01-30 +### Added +- Transform the `mailchimp_sf_shortcode` shortcode to the Mailchimp List Subscribe Form block (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#84](https://github.com/mailchimp/wordpress/pull/84)). + +### Removed +- Deprecated Sopresto code (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#98](https://github.com/mailchimp/wordpress/pull/98)). + +### Fixed +- Fatal PHP error that would occur when the phone merge field was set to US format, but the merge field was not included in the Mailchimp plugin (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#108](https://github.com/mailchimp/wordpress/pull/108)). +- Bug causing merge fields on the Mailchimp WP admin page to incorrectly display as not required when they were, in fact, required (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#109](https://github.com/mailchimp/wordpress/pull/109)). +- Fix an issue that allows a user to select merge fields that were not selected as visible in the Mailchimp account (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#110](https://github.com/mailchimp/wordpress/pull/110)). +- Bug causing all new subscribers to receive a double opt-in email (props Nathan Tetzlaff, [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). +- Bug causing contacts with any Mailchimp status (subscribed, unsubscribed, pending, etc.) to be able to submit the sign-up form even if "Update Existing Subscriber?" was disabled (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). +- Pending contacts will now still be required to confirm their original confirmation email if they try to update their contact while "Update Existing Subscribers?" and "Double Opt-in" are both enabled (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). + +### Security +- Bump `nanoid` from 3.3.7 to 3.3.8 (props [@dependabot](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh) via [#111](https://github.com/mailchimp/wordpress/pull/111)). + +### Developer +- Add autoloading using composer (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#95](https://github.com/mailchimp/wordpress/pull/95)). +- Updated GitHub Action step for generating the release assets (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#97](https://github.com/mailchimp/wordpress/pull/97)). + ## [1.6.2] - 2024-11-12 **Note that this release bumps the WordPress minimum version from 6.1 to 6.3.** @@ -192,6 +214,7 @@ All notable changes to this project will be documented in this file, per [the Ke - Security and various other improvements [Unreleased]: https://github.com/mailchimp/wordpress/compare/main...develop +[1.6.3]: https://github.com/mailchimp/wordpress/compare/1.6.2...1.6.3 [1.6.2]: https://github.com/mailchimp/wordpress/compare/1.6.1...1.6.2 [1.6.1]: https://github.com/mailchimp/wordpress/compare/1.6.0...1.6.1 [1.6.0]: https://github.com/mailchimp/wordpress/tree/1.6.0 diff --git a/CREDITS.md b/CREDITS.md index 5d1bb25..4e7da9b 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -12,7 +12,7 @@ The following individuals are responsible for curating the list of issues, respo Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc. -[Mailchimp (@mailchimp)](https://github.com/mailchimp), [Crowd Favorite (@crowdfavorite)](https://github.com/crowdfavorite), [Matthew Richmond (@bigdawggi)](https://github.com/bigdawggi), [Devin Reams (@devinreams)](https://github.com/devinreams), [Alex King (@alexkingorg)](https://github.com/alexkingorg), [Jesse (@jessedp)](https://github.com/jessedp), [Andrew Ellis](awellis@me.com), [Evan Anderson (@ejdanderson)](https://github.com/ejdanderson), [Webb Henderson (@emerywebster)](https://github.com/emerywebster), [Steven Mathias (@ssmathias)](https://github.com/ssmathias), [Jonathan D. Johnson (@jondavidjohn)](https://github.com/jondavidjohn), [Ross Tweedie (@digitales)](https://github.com/digitales), [(@mcwill)](https://github.com/mcwill), [Andrew Austin (@andrewjaustin)](https://github.com/andrewjaustin), [Marc Queralt i Bassa (@MarcQueralt)](https://github.com/MarcQueralt), [Chris Mospaw (@mospaw)](https://github.com/mospaw), [Jonas Stensved (@jstensved)](https://github.com/jstensved), [netboy](netboy@netboy.pl), [Lenin](lenin@tasawr.com), [Bauke Zwaan (@baukezwaan)](https://github.com/baukezwaan), [Jascha Ehrenreich (@jaeh)](https://github.com/jaeh), [Chris Wilcoxson (@slushman)](https://github.com/slushman), [Luke Watts (@thisislawatts)](https://github.com/thisislawatts), [Glenn Ansley (@glennansley)](https://github.com/glennansley), [SiteGround](http://www.siteground.com/wordpress-hosting.htm), [Peter Kahoun](http://kahi.cz/), [Jan Lund](), [Michael Jaekel](), [Ιωάννης Δημοφέρλιας (John Dimoferlias)](), [Tomás Nader](), [Claudia Mansilla](http://cricava.com/), [Helen Urbanik](http://www.motomaania.ee/), [Maxime Toulliou](http://www.maximetoulliou.com/), [שגיב בית](http://www.sagive.co.il), [Okostobi](), [Stefan Des](http://www.stefandes.com), [백선기 (SK Baek)](), [Alexander Roterud aka Defrag](http://www.tigerpews.com), [Filip Stas](http://suddenelfilio.net/), [Maria Manoela Porto](), [Tiago Faria](http://xroot.org), [Alexandru Armin Roșu](), [Илья](http://fatcow.com), [Sebastian Johnsson](http://www.agiley.se/), [Hakan E.](http://kazancexpert.com/), [Josh Grosser (@jgrosser-intuit)](https://github.com/jgrosser-intuit), [10up (@10up)](https://github.com/10up), [Nate Conley (@nateconley)](https://github.com/nateconley), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Eddie Shrake (@eddieshrake)](https://github.com/eddieshrake), [Sumit Bagthariya (@qasumitbagthariya)](https://github.com/qasumitbagthariya), [Vikram Moparthy (@vikrampm1)](https://github.com/vikrampm1), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [GitHub Dependabot (@dependabot)](https://github.com/apps/dependabot), [Jer Clarke (@jerclarke)](https://github.com/jerclarke). +[Mailchimp (@mailchimp)](https://github.com/mailchimp), [Crowd Favorite (@crowdfavorite)](https://github.com/crowdfavorite), [Matthew Richmond (@bigdawggi)](https://github.com/bigdawggi), [Devin Reams (@devinreams)](https://github.com/devinreams), [Alex King (@alexkingorg)](https://github.com/alexkingorg), [Jesse (@jessedp)](https://github.com/jessedp), [Andrew Ellis](awellis@me.com), [Evan Anderson (@ejdanderson)](https://github.com/ejdanderson), [Webb Henderson (@emerywebster)](https://github.com/emerywebster), [Steven Mathias (@ssmathias)](https://github.com/ssmathias), [Jonathan D. Johnson (@jondavidjohn)](https://github.com/jondavidjohn), [Ross Tweedie (@digitales)](https://github.com/digitales), [(@mcwill)](https://github.com/mcwill), [Andrew Austin (@andrewjaustin)](https://github.com/andrewjaustin), [Marc Queralt i Bassa (@MarcQueralt)](https://github.com/MarcQueralt), [Chris Mospaw (@mospaw)](https://github.com/mospaw), [Jonas Stensved (@jstensved)](https://github.com/jstensved), [netboy](netboy@netboy.pl), [Lenin](lenin@tasawr.com), [Bauke Zwaan (@baukezwaan)](https://github.com/baukezwaan), [Jascha Ehrenreich (@jaeh)](https://github.com/jaeh), [Chris Wilcoxson (@slushman)](https://github.com/slushman), [Luke Watts (@thisislawatts)](https://github.com/thisislawatts), [Glenn Ansley (@glennansley)](https://github.com/glennansley), [SiteGround](http://www.siteground.com/wordpress-hosting.htm), [Peter Kahoun](http://kahi.cz/), [Jan Lund](), [Michael Jaekel](), [Ιωάννης Δημοφέρλιας (John Dimoferlias)](), [Tomás Nader](), [Claudia Mansilla](http://cricava.com/), [Helen Urbanik](http://www.motomaania.ee/), [Maxime Toulliou](http://www.maximetoulliou.com/), [שגיב בית](http://www.sagive.co.il), [Okostobi](), [Stefan Des](http://www.stefandes.com), [백선기 (SK Baek)](), [Alexander Roterud aka Defrag](http://www.tigerpews.com), [Filip Stas](http://suddenelfilio.net/), [Maria Manoela Porto](), [Tiago Faria](http://xroot.org), [Alexandru Armin Roșu](), [Илья](http://fatcow.com), [Sebastian Johnsson](http://www.agiley.se/), [Hakan E.](http://kazancexpert.com/), [Josh Grosser (@jgrosser-intuit)](https://github.com/jgrosser-intuit), [10up (@10up)](https://github.com/10up), [Nate Conley (@nateconley)](https://github.com/nateconley), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Eddie Shrake (@eddieshrake)](https://github.com/eddieshrake), [Sumit Bagthariya (@qasumitbagthariya)](https://github.com/qasumitbagthariya), [Vikram Moparthy (@vikrampm1)](https://github.com/vikrampm1), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [GitHub Dependabot (@dependabot)](https://github.com/apps/dependabot), [Jer Clarke (@jerclarke)](https://github.com/jerclarke), [Max Garceau (@MaxwellGarceau)](https://github.com/MaxwellGarceau), [Nathan Tetzlaff](). ## Libraries diff --git a/composer.json b/composer.json index 2f2b77a..9965490 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,14 @@ "10up/phpcs-composer": "^3.0", "sirbrillig/phpcs-changed": "^2.11" }, + "autoload": { + "psr-4": { + "Mailchimp\\WordPress\\": "src/" + }, + "classmap": [ + "includes" + ] + }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true @@ -26,4 +34,4 @@ "scripts": { "lint": "phpcs --standard=./phpcs.xml -p -s ." } -} +} \ No newline at end of file diff --git a/includes/blocks/mailchimp/index.js b/includes/blocks/mailchimp/index.js index 98b1f18..3538f28 100644 --- a/includes/blocks/mailchimp/index.js +++ b/includes/blocks/mailchimp/index.js @@ -6,6 +6,17 @@ import Icon from './icon'; registerBlockType(metadata, { icon: Icon, + transforms: { + from: [ + { + type: 'shortcode', + tag: 'mailchimpsf_form', + attributes: { + // No attributes, but attributes property is required + }, + }, + ], + }, edit: BlockEdit, save: () => null, }); diff --git a/mailchimp.php b/mailchimp.php index f9870e5..34464dc 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -4,7 +4,7 @@ * Plugin URI: https://mailchimp.com/help/connect-or-disconnect-list-subscribe-for-wordpress/ * Description: Add a Mailchimp signup form block, widget or shortcode to your WordPress site. * Text Domain: mailchimp - * Version: 1.6.2 + * Version: 1.6.3 * Requires at least: 6.3 * Requires PHP: 7.0 * PHP tested up to: 8.3 @@ -34,8 +34,38 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// Check if the autoload file exists +if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { + require_once __DIR__ . '/vendor/autoload.php'; +} else { + add_action( + 'admin_notices', + function () { + ?> +
+

+ composer install, 2: Support URL, e.g., https://wordpress.org/support/plugin/mailchimp/. */ + __( 'The composer autoload file is not found or not readable. Please contact support if you\'re a user. Please run %1$s if you\'re a developer in a development environment.', 'mailchimp' ), + 'composer install', + 'https://wordpress.org/support/plugin/mailchimp/' + ) + ); + ?> +

+
+ get_option( 'mc_sopresto_public_key' ), - 'hash' => sha1( get_option( 'mc_sopresto_public_key' ) . get_option( 'mc_sopresto_secret_key' ) ), - ); - - $url = 'https://sopresto.socialize-this.com/mailchimp/exchange'; - $args = array( - 'method' => 'POST', - 'timeout' => 500, - 'redirection' => 5, - 'httpversion' => '1.0', - 'user-agent' => 'Mailchimp WordPress Plugin/' . get_bloginfo( 'url' ), - 'body' => $body, - ); - - // post to sopresto - $key = wp_remote_post( $url, $args ); - if ( ! is_wp_error( $key ) && 200 === $key['response']['code'] ) { - $key = json_decode( $key['body'] ); - try { - $api = new MailChimp_API( $key->response ); - } catch ( Exception $e ) { - $msg = '' . $e->getMessage() . ''; - mailchimp_sf_global_msg( $msg ); - return; - } - - $verify = mailchimp_sf_verify_key( $api ); - - // something went wrong with the key that we had - if ( is_wp_error( $verify ) ) { - return; - } - - delete_option( 'mc_sopresto_public_key' ); - delete_option( 'mc_sopresto_secret_key' ); - delete_option( 'mc_sopresto_user' ); - } -} - /** * Update merge fields * @@ -391,13 +367,13 @@ function mailchimp_sf_needs_upgrade() { /** * Deletes all Mailchimp options + * + * TODO: The options names should be moved to a config file + * or to a class dedicated to options **/ function mailchimp_sf_delete_setup() { $options = array( 'mc_user_id', - 'mc_sopresto_user', - 'mc_sopresto_public_key', - 'mc_sopresto_secret_key', 'mc_use_javascript', 'mc_use_datepicker', 'mc_use_unsub_link', @@ -904,14 +880,18 @@ function mailchimp_sf_signup_submit() { $url = 'lists/' . $list_id . '/members/' . md5( strtolower( $email ) ); $status = mailchimp_sf_check_status( $url ); - // If update existing is turned off and the subscriber exists, error out. - if ( get_option( 'mc_update_existing' ) === false && 'subscribed' === $status ) { - $msg = esc_html__( 'This email address is already subscribed to the list.', 'mailchimp' ); + // If update existing is turned off and the subscriber is not new, error out. + $is_new_subscriber = false === $status; + if ( ! get_option( 'mc_update_existing' ) && ! $is_new_subscriber ) { + $msg = esc_html__( 'This email address has already been subscribed to this list.', 'mailchimp' ); $error = new WP_Error( 'mailchimp-update-existing', $msg ); mailchimp_sf_global_msg( '' . $msg . '' ); return false; } + // TODO: If get_option( 'mc_update_existing' ) && 'unsubscribed' === $status then + // make an API request to fetch Mailchimp hosted sign up form and display to user + $body = mailchimp_sf_subscribe_body( $merge, $igs, $email_type, $email, $status, get_option( 'mc_double_optin' ) ); $retval = $api->post( $url, $body, 'PUT' ); @@ -940,12 +920,12 @@ function mailchimp_sf_signup_submit() { * Cleans up merge fields and interests to make them * API 3.0-friendly. * - * @param [type] $merge Merge fields - * @param [type] $igs Interest groups - * @param string $email_type Email type - * @param string $email Email - * @param string $status Status - * @param bool $double_optin Whether this is double optin + * @param [type] $merge Merge fields + * @param [type] $igs Interest groups + * @param string $email_type Email type + * @param string $email Email + * @param string|false $status Status The subscription status ('subscribed', 'unsubscribed', 'pending', etc.) or false if an error occurred. + * @param string $double_optin Whether double opt-in is enabled. "1" for enabled and "" for disabled. * @return stdClass */ function mailchimp_sf_subscribe_body( $merge, $igs, $email_type, $email, $status, $double_optin ) { @@ -953,27 +933,29 @@ function mailchimp_sf_subscribe_body( $merge, $igs, $email_type, $email, $status $body->email_address = $email; $body->email_type = $email_type; $body->merge_fields = $merge; + if ( ! empty( $igs ) ) { $body->interests = $igs; } - if ( 'subscribed' !== $status ) { - // single opt-in that covers new subscribers - if ( false === ! $status && $double_optin ) { - $body->status = 'subscribed'; - } else { - // anyone else - $body->status = 'pending'; - } + // Early return for already subscribed users + if ( 'subscribed' === $status ) { + return $body; } + + // Subscribe the email immediately unless double opt-in is enabled + // "unsubscribed" and "subscribed" existing emails have been excluded at this stage + // "pending" emails should follow double opt-in rules + $body->status = $double_optin ? 'pending' : 'subscribed'; + return $body; } /** - * Check status. + * Check the status of a subscriber in the list. * - * @param string $endpoint Endpoint. - * @return string + * @param string $endpoint API endpoint to check the status. + * @return string|false The subscription status ('subscribed', 'unsubscribed', 'pending', etc.) or false if the API returned 404 or an error occurred. */ function mailchimp_sf_check_status( $endpoint ) { $endpoint .= '?fields=status'; @@ -1003,32 +985,72 @@ function mailchimp_sf_merge_submit( $mv ) { $opt_val = isset( $_POST[ $opt ] ) ? map_deep( stripslashes_deep( $_POST[ $opt ] ), 'sanitize_text_field' ) : ''; - // Handle phone number logic - if ( isset( $mv_var['options']['phone_format'] ) && 'phone' === $mv_var['type'] && 'US' === $mv_var['options']['phone_format'] ) { - $opt_val = mailchimp_sf_merge_validate_phone( $opt_val, $mv_var ); - if ( is_wp_error( $opt_val ) ) { - return $opt_val; - } - } elseif ( is_array( $opt_val ) && 'address' === $mv_var['type'] ) { // Handle address logic - $validate = mailchimp_sf_merge_validate_address( $opt_val, $mv_var ); - if ( is_wp_error( $validate ) ) { - return $validate; - } + switch ( $mv_var['type'] ) { + /** + * US Phone validation + * + * - Merge field is phone + * - Merge field is "included" in the Mailchimp admin options + * - Phone format is set in Mailchimp account + * - Phone format is US in Mailchimp account + */ + case 'phone': + if ( + 'on' === get_option( $opt ) + && isset( $mv_var['options']['phone_format'] ) + && 'US' === $mv_var['options']['phone_format'] + ) { + $opt_val = mailchimp_sf_merge_validate_phone( $opt_val, $mv_var ); + if ( is_wp_error( $opt_val ) ) { + return $opt_val; + } + } + break; - if ( $validate ) { - $merge->$tag = $validate; - } - continue; + /** + * Address validation + * + * - Merge field is address + * - Merge field is "included" in the Mailchimp admin options + * - Merge field is an array (address contains multiple elements) + */ + case 'address': + if ( 'on' === get_option( $opt ) && is_array( $opt_val ) ) { + $validate = mailchimp_sf_merge_validate_address( $opt_val, $mv_var ); + if ( is_wp_error( $validate ) ) { + return $validate; + } - } elseif ( is_array( $opt_val ) ) { - $keys = array_keys( $opt_val ); - $val = new stdClass(); - foreach ( $keys as $key ) { - $val->$key = $opt_val[ $key ]; - } - $opt_val = $val; + if ( $validate ) { + $merge->$tag = $validate; + } + } + break; + + /** + * Handle generic array values + * + * Not sure what this does or is for + * + * - Merge field is an array, not specifically phone or address + */ + default: + if ( is_array( $opt_val ) ) { + $keys = array_keys( $opt_val ); + $val = new stdClass(); + foreach ( $keys as $key ) { + $val->$key = $opt_val[ $key ]; + } + $opt_val = $val; + } + break; } + /** + * Required fields + * + * If the field is required and empty, return an error + */ if ( 'Y' === $mv_var['required'] && trim( $opt_val ) === '' ) { /* translators: %s: field name */ $message = sprintf( esc_html__( 'You must fill in %s.', 'mailchimp' ), esc_html( $mv_var['name'] ) ); diff --git a/package-lock.json b/package-lock.json index c7ff583..3203c76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mailchimp/wordpress", - "version": "1.6.2", + "version": "1.6.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mailchimp/wordpress", - "version": "1.6.2", + "version": "1.6.3", "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/block-editor": "^13.2.0", @@ -18107,9 +18107,9 @@ "dev": true }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "funding": [ { "type": "github", diff --git a/package.json b/package.json index bc75b71..f21f8f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mailchimp/wordpress", - "version": "1.6.2", + "version": "1.6.3", "description": "Add a Mailchimp signup form widget to your WordPress site.", "homepage": "https://github.com/mailchimp/wordpress", "bugs": { diff --git a/readme.txt b/readme.txt index 828dab1..13d03dc 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: Mailchimp Tags: mailchimp, email, newsletter, signup, marketing Tested up to: 6.7 -Stable tag: 1.6.2 +Stable tag: 1.6.3 License: GPL-2.0-or-later License URI: https://spdx.org/licenses/GPL-2.0-or-later.html @@ -81,6 +81,17 @@ If you are upgrading to version 1.2.1 and you used the widget in your sidebar pr == Changelog == += 1.6.3 - 2025-01-30 = +* **Added:** Transform the `mailchimp_sf_shortcode` shortcode to the Mailchimp List Subscribe Form block (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#84](https://github.com/mailchimp/wordpress/pull/84)). +* **Removed:** Deprecated Sopresto code (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter) via [#98](https://github.com/mailchimp/wordpress/pull/98)). +* **Fixed:** Fatal PHP error that would occur when the phone merge field was set to US format, but the merge field was not included in the Mailchimp plugin (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#108](https://github.com/mailchimp/wordpress/pull/108)). +* **Fixed:** Bug causing merge fields on the Mailchimp WP admin page to incorrectly display as not required when they were, in fact, required (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#109](https://github.com/mailchimp/wordpress/pull/109)). +* **Fixed:** Fix an issue that allows a user to select merge fields that were not selected as visible in the Mailchimp account (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#110](https://github.com/mailchimp/wordpress/pull/110)). +* **Fixed:** Bug causing all new subscribers to receive a double opt-in email (props Nathan Tetzlaff, [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). +* **Fixed:** Bug causing contacts with any Mailchimp status (subscribed, unsubscribed, pending, etc.) to be able to submit the sign-up form even if "Update Existing Subscriber?" was disabled (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). +* **Fixed:** Pending contacts will now still be required to confirm their original confirmation email if they try to update their contact while "Update Existing Subscribers?" and "Double Opt-in" are both enabled (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). +* **Security:** Bump `nanoid` from 3.3.7 to 3.3.8 (props [@dependabot](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh) via [#111](https://github.com/mailchimp/wordpress/pull/111)). + = 1.6.2 - 2024-11-12 = **Note that this release bumps the WordPress minimum version from 6.1 to 6.3.** diff --git a/tests/cypress/e2e/connect.test.js b/tests/cypress/e2e/connect.test.js index 89c71bf..eecbb4d 100644 --- a/tests/cypress/e2e/connect.test.js +++ b/tests/cypress/e2e/connect.test.js @@ -23,6 +23,18 @@ describe('Admin can connect to "Mailchimp" Account', () => { cy.get('#mailchimp_sf_oauth_connect').click(); cy.wait(6000); + // Accept cookie consent popup window (if present) + cy.popup().then(($popup) => { + const acceptButtonSelector = '#onetrust-accept-btn-handler'; + + // Check if the accept button is visible and click it + if ($popup.find(acceptButtonSelector).length > 0 && $popup.find(acceptButtonSelector).is(':visible')) { + $popup.find(acceptButtonSelector).click(); + } else { + cy.log('Cookie consent popup not found or not visible.'); + } + }); + cy.popup() .find('input#username') .clear() diff --git a/views/setup_page.php b/views/setup_page.php index d1f1fcd..b2e64d4 100644 --- a/views/setup_page.php +++ b/views/setup_page.php @@ -6,7 +6,6 @@ */ $user = get_option( 'mc_user' ); -/* TODO MC SOPRESTO USER INFO */ // If we have an API Key, see if we need to change the lists and its options mailchimp_sf_change_list_if_necessary(); @@ -300,10 +299,10 @@ function ( $ele ) { - +