From 20d281d27db48a39fc8cf0054816f9eceeedb771 Mon Sep 17 00:00:00 2001 From: Max Garceau Date: Wed, 18 Dec 2024 17:22:09 -0500 Subject: [PATCH 01/56] Add transform for shortcodes to block --- includes/blocks/mailchimp/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/blocks/mailchimp/index.js b/includes/blocks/mailchimp/index.js index 98b1f18..01eb104 100644 --- a/includes/blocks/mailchimp/index.js +++ b/includes/blocks/mailchimp/index.js @@ -6,6 +6,14 @@ import Icon from './icon'; registerBlockType(metadata, { icon: Icon, + transforms: { + from: [ + { + type: 'shortcode', + tag: 'mailchimpsf_form', + }, + ], + }, edit: BlockEdit, save: () => null, }); From 1bedf6d4e294bac40c245918125109c05840f2bd Mon Sep 17 00:00:00 2001 From: Max Garceau Date: Thu, 19 Dec 2024 10:07:15 -0500 Subject: [PATCH 02/56] Fix JS error by adding attributes property --- includes/blocks/mailchimp/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/blocks/mailchimp/index.js b/includes/blocks/mailchimp/index.js index 01eb104..3538f28 100644 --- a/includes/blocks/mailchimp/index.js +++ b/includes/blocks/mailchimp/index.js @@ -11,6 +11,9 @@ registerBlockType(metadata, { { type: 'shortcode', tag: 'mailchimpsf_form', + attributes: { + // No attributes, but attributes property is required + }, }, ], }, From 9689fc92399377b1d02866a2adde0d541b3a555e Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 19 Dec 2024 10:53:23 -0700 Subject: [PATCH 03/56] Try fixing our E2E tests by installing SVN --- .github/workflows/build-release-zip.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index ffdb3b6..d389693 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -39,6 +39,11 @@ jobs: 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: From baafa893ea37426add8dd2fc35ce7f860c0aaa1f Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 19 Dec 2024 10:54:35 -0700 Subject: [PATCH 04/56] Update branch name for testing --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 65c8ffa..9e1bff8 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -11,7 +11,7 @@ on: jobs: build: - uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@develop + uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@enhancement/shortcode-conversion-to-block cypress: needs: build From 0b93ec334a1583378fb2daa393b60a1614c20cf0 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 19 Dec 2024 10:59:52 -0700 Subject: [PATCH 05/56] Ensure we install svn in our workflows that need it, as this no longer comes with the latest ubuntu version --- .github/workflows/build-release-zip.yml | 5 +++++ .github/workflows/wordpress-plugin-asset-update.yml | 5 +++++ .github/workflows/wordpress-plugin-deploy.yml | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index ffdb3b6..d389693 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -39,6 +39,11 @@ jobs: 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: diff --git a/.github/workflows/wordpress-plugin-asset-update.yml b/.github/workflows/wordpress-plugin-asset-update.yml index c923dd2..12a9bfb 100644 --- a/.github/workflows/wordpress-plugin-asset-update.yml +++ b/.github/workflows/wordpress-plugin-asset-update.yml @@ -25,6 +25,11 @@ jobs: npm ci --no-optional npm run build + - name: Install SVN + run: | + sudo apt-get update + sudo apt-get install subversion + - name: WordPress.org plugin asset/readme update uses: 10up/action-wordpress-plugin-asset-update@stable env: diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index b37771b..f2a9dff 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -24,6 +24,11 @@ jobs: npm ci --no-optional npm run build + - name: Install SVN + run: | + sudo apt-get update + sudo apt-get install subversion + - name: WordPress Plugin Deploy id: deploy uses: 10up/action-wordpress-plugin-deploy@stable From 7828cc0ea5654dc376f6d0ef9a441c27af8c1421 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 19 Dec 2024 11:00:52 -0700 Subject: [PATCH 06/56] Switch branch back now that we've tested things --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9e1bff8..65c8ffa 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -11,7 +11,7 @@ on: jobs: build: - uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@enhancement/shortcode-conversion-to-block + uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@develop cypress: needs: build From 6392fbf349fff05aa4cb4654cd6317117b2a0f21 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 26 Dec 2024 15:44:26 -0500 Subject: [PATCH 07/56] Add composer autoload --- .github/workflows/build-release-zip.yml | 7 ++++++- .github/workflows/wordpress-plugin-deploy.yml | 7 ++++++- composer.json | 13 ++++++++++++- mailchimp.php | 11 +++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index d389693..597a51b 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -35,6 +35,11 @@ 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 @@ -47,4 +52,4 @@ jobs: - 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-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index f2a9dff..3e8db49 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -19,6 +19,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 @@ -47,4 +52,4 @@ jobs: upload_url: ${{ github.event.release.upload_url }} asset_path: ${{ steps.deploy.outputs.zip-path }} asset_name: mailchimp.zip - asset_content_type: application/zip + asset_content_type: application/zip \ No newline at end of file diff --git a/composer.json b/composer.json index 2f2b77a..f05059f 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,17 @@ "10up/phpcs-composer": "^3.0", "sirbrillig/phpcs-changed": "^2.11" }, + "autoload": { + "psr-4": { + "Mailchimp\\WordPress\\": "src/" + }, + "classmap": [ + "includes" + ], + "files": [ + "includes/admin/admin-notices.php" + ] + }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true @@ -26,4 +37,4 @@ "scripts": { "lint": "phpcs --standard=./phpcs.xml -p -s ." } -} +} \ No newline at end of file diff --git a/mailchimp.php b/mailchimp.php index f9870e5..703c1bc 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -34,6 +34,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +// Define the path to the Composer autoload file +$autoloadFile = __DIR__ . '/vendor/autoload.php'; + +// Check if the autoload file exists +if ( ! file_exists( $autoloadFile ) ) { + die( 'Composer autoload file not found. Run `composer install` to generate it.' ); +} + +// Include the autoload file +require_once $autoloadFile; + // Version constant for easy CSS refreshes define( 'MCSF_VER', '1.6.2' ); From 23a81c60db63bfa376a9a9515651f38ef4dc8076 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 26 Dec 2024 16:07:13 -0500 Subject: [PATCH 08/56] Fix linter errors --- composer.json | 3 --- mailchimp.php | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f05059f..9965490 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,6 @@ }, "classmap": [ "includes" - ], - "files": [ - "includes/admin/admin-notices.php" ] }, "config": { diff --git a/mailchimp.php b/mailchimp.php index 703c1bc..ced0045 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -35,15 +35,15 @@ */ // Define the path to the Composer autoload file -$autoloadFile = __DIR__ . '/vendor/autoload.php'; +$autoload_file = __DIR__ . '/vendor/autoload.php'; // Check if the autoload file exists -if ( ! file_exists( $autoloadFile ) ) { +if ( ! file_exists( $autoload_file ) ) { die( 'Composer autoload file not found. Run `composer install` to generate it.' ); } // Include the autoload file -require_once $autoloadFile; +require_once $autoload_file; // Version constant for easy CSS refreshes define( 'MCSF_VER', '1.6.2' ); From 69d6e85750c33e4c33a5a41c084dc5530984a89b Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 11:46:53 -0500 Subject: [PATCH 09/56] Replace github release action --- .github/workflows/wordpress-plugin-deploy.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index f2a9dff..a994a42 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -39,12 +39,11 @@ jobs: SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} SLUG: mailchimp - - name: Upload release asset - uses: actions/upload-release-asset@v1.0.2 + - name: Create 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 From 213f72f94e0c683ec5f7a0afa0836cb350cfc20b Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 11:48:06 -0500 Subject: [PATCH 10/56] Comment out WP deploy and add workflow dispatch for testing --- .github/workflows/wordpress-plugin-deploy.yml | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index a994a42..1c6047c 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -3,6 +3,7 @@ name: Deploy to WordPress.org on: release: types: [published] + workflow_dispatch: # TODO: Delete after testing is complete jobs: tag: @@ -29,15 +30,17 @@ jobs: sudo apt-get update sudo apt-get install subversion - - name: WordPress Plugin Deploy - id: deploy - uses: 10up/action-wordpress-plugin-deploy@stable - with: - generate-zip: true - env: - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SLUG: mailchimp + # TODO: Uncomment after testing is complete + + # - name: WordPress Plugin Deploy + # id: deploy + # uses: 10up/action-wordpress-plugin-deploy@stable + # with: + # generate-zip: true + # env: + # SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + # SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + # SLUG: mailchimp - name: Create GitHub Release uses: softprops/action-gh-release@v2 From d74be4fd931f6ad6f0580b0cec5a3c81eb9f33d8 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 12:03:46 -0500 Subject: [PATCH 11/56] Add dummy credentials to avoid real deploy --- .github/workflows/wordpress-plugin-deploy.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index 1c6047c..b829c4d 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -30,17 +30,17 @@ jobs: sudo apt-get update sudo apt-get install subversion - # TODO: Uncomment after testing is complete + # TODO: Revert dummy changes after testing is successful - # - name: WordPress Plugin Deploy - # id: deploy - # uses: 10up/action-wordpress-plugin-deploy@stable - # with: - # generate-zip: true - # env: - # SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - # SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - # SLUG: mailchimp + - name: WordPress Plugin Deploy (dummy credentials used) + id: deploy + uses: 10up/action-wordpress-plugin-deploy@stable + with: + generate-zip: true + env: + SVN_USERNAME: "dummy-user" + SVN_PASSWORD: "dummy-pass" + SLUG: dummy-slug - name: Create GitHub Release uses: softprops/action-gh-release@v2 From a242041e22763e8d62c0e4b8963537a992bc630b Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 12:12:46 -0500 Subject: [PATCH 12/56] Add continue on error --- .github/workflows/wordpress-plugin-deploy.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index b829c4d..53271c8 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -32,15 +32,16 @@ jobs: # TODO: Revert dummy changes after testing is successful - - name: WordPress Plugin Deploy (dummy credentials used) + - name: WordPress Plugin Deploy (dummy credentials used) # TODO: Rename after testing id: deploy uses: 10up/action-wordpress-plugin-deploy@stable with: generate-zip: true env: - SVN_USERNAME: "dummy-user" - SVN_PASSWORD: "dummy-pass" - SLUG: dummy-slug + SVN_USERNAME: "dummy-user" # TODO: Revert after testing + SVN_PASSWORD: "dummy-pass" # TODO: Revert after testing + SLUG: dummy-slug # TODO: Revert after testing + continue-on-error: true # TODO: Remove after testing - name: Create GitHub Release uses: softprops/action-gh-release@v2 From 1f42bcc25f6d8846c2d628abc511dfcfe097505d Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 12:46:33 -0500 Subject: [PATCH 13/56] Generate zip file outside of deploy to WP.org --- .github/workflows/wordpress-plugin-deploy.yml | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index 53271c8..478063a 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -32,21 +32,33 @@ jobs: # TODO: Revert dummy changes after testing is successful - - name: WordPress Plugin Deploy (dummy credentials used) # TODO: Rename after testing + # - name: WordPress Plugin Deploy (dummy credentials used) # TODO: Rename after testing + # id: deploy + # uses: 10up/action-wordpress-plugin-deploy@stable + # with: + # generate-zip: true + # env: + # SVN_USERNAME: "dummy-user" # TODO: Revert after testing + # SVN_PASSWORD: "dummy-pass" # TODO: Revert after testing + # SLUG: dummy-slug # TODO: Revert after testing + # continue-on-error: true # TODO: Remove after testing + + # TODO: Delete this after done testing + # Generate the WordPress Plugin zip file without deploying + - name: Generate Plugin Zip File (skip deploy to WordPress.org) id: deploy - uses: 10up/action-wordpress-plugin-deploy@stable - with: - generate-zip: true + run: | + # Create a zip file for the plugin + mkdir -p build + zip -r build/mailchimp.zip . -x "*.git*" "node_modules/*" "tests/*" env: - SVN_USERNAME: "dummy-user" # TODO: Revert after testing - SVN_PASSWORD: "dummy-pass" # TODO: Revert after testing - SLUG: dummy-slug # TODO: Revert after testing - continue-on-error: true # TODO: Remove after testing + SLUG: mailchimp - - name: Create GitHub Release + - name: Update GitHub release with built plugin files uses: softprops/action-gh-release@v2 with: - files: ${{ steps.deploy.outputs.zip-path }} + # files: ${{ steps.deploy.outputs.zip-path }} # TODO: Revert this after testing + files: build/mailchimp.zip # TODO: Remove this after testing body: | This release contains the latest updates for the WordPress plugin. env: From 7f05287ed1c818ffce11e20d77310599120ae686 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 13:20:23 -0500 Subject: [PATCH 14/56] Remove testing workarounds --- .github/workflows/wordpress-plugin-deploy.yml | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index 478063a..1578438 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -3,7 +3,6 @@ name: Deploy to WordPress.org on: release: types: [published] - workflow_dispatch: # TODO: Delete after testing is complete jobs: tag: @@ -29,36 +28,21 @@ jobs: run: | sudo apt-get update sudo apt-get install subversion - - # TODO: Revert dummy changes after testing is successful - # - name: WordPress Plugin Deploy (dummy credentials used) # TODO: Rename after testing - # id: deploy - # uses: 10up/action-wordpress-plugin-deploy@stable - # with: - # generate-zip: true - # env: - # SVN_USERNAME: "dummy-user" # TODO: Revert after testing - # SVN_PASSWORD: "dummy-pass" # TODO: Revert after testing - # SLUG: dummy-slug # TODO: Revert after testing - # continue-on-error: true # TODO: Remove after testing - - # TODO: Delete this after done testing - # Generate the WordPress Plugin zip file without deploying - - name: Generate Plugin Zip File (skip deploy to WordPress.org) + - name: WordPress Plugin Deploy id: deploy - run: | - # Create a zip file for the plugin - mkdir -p build - zip -r build/mailchimp.zip . -x "*.git*" "node_modules/*" "tests/*" + uses: 10up/action-wordpress-plugin-deploy@stable + with: + generate-zip: true env: + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} SLUG: mailchimp - name: Update GitHub release with built plugin files uses: softprops/action-gh-release@v2 with: - # files: ${{ steps.deploy.outputs.zip-path }} # TODO: Revert this after testing - files: build/mailchimp.zip # TODO: Remove this after testing + files: ${{ steps.deploy.outputs.zip-path }} body: | This release contains the latest updates for the WordPress plugin. env: From d2e39e5652b4ca5f36d2d4ea022f5042af286427 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 13:26:23 -0500 Subject: [PATCH 15/56] Rename last job step --- .github/workflows/wordpress-plugin-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index 1578438..b043697 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -39,7 +39,7 @@ jobs: SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} SLUG: mailchimp - - name: Update GitHub release with built plugin files + - name: Attach the wordpress.org plugin files to the Github release uses: softprops/action-gh-release@v2 with: files: ${{ steps.deploy.outputs.zip-path }} From fd48a2b3ef608b7ffba66a904173c4945dfb083b Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 13:37:22 -0500 Subject: [PATCH 16/56] Add test workflow file --- ...eploy-test-softprops-gh-release-action.yml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml diff --git a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml new file mode 100644 index 0000000..17817cd --- /dev/null +++ b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml @@ -0,0 +1,64 @@ +# TODO: THIS WORKFLOW FILE IS TO TEST ISSUE #60 "Resolve release deploy action warnings" +# DELETE AFTER TESTING IS COMPLETE. THIS WORKFLOW FILE IS UNNECESSARY. + +name: (delete after testing is done) - Test "Deploy to WordPress.org" + +on: + workflow_dispatch: # TODO: Delete after testing is complete + +jobs: + tag: + name: New release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup node version and npm cache + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Build + run: | + npm ci --no-optional + npm run build + + - name: Install SVN + run: | + sudo apt-get update + sudo apt-get install subversion + + # TESTING: COMMENTED OUT TO AVOID DEPLOY TO WORDPRESS.ORG DURING TESTING + + # - name: WordPress Plugin Deploy + # id: deploy + # uses: 10up/action-wordpress-plugin-deploy@stable + # with: + # generate-zip: true + # env: + # SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + # SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + # SLUG: mailchimp + + # TESTING: Generate the WordPress Plugin zip file without deploying + - name: Generate Plugin Zip File For Testing (skip deploy to WordPress.org) + id: deploy + run: | + # Create a zip file for the plugin + mkdir -p build + zip -r build/mailchimp.zip . -x "*.git*" "node_modules/*" "tests/*" + env: + SLUG: mailchimp + + - name: Update GitHub release with built plugin files + uses: softprops/action-gh-release@v2 + with: + # files: ${{ steps.deploy.outputs.zip-path }} # TESTING: Original zip file source + files: build/mailchimp.zip # TESTING: Get zip file from generate plugin step + body: | + This release contains the latest updates for the WordPress plugin. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From afd3387830f5f5f321a12884530d0b5e88c27fbf Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 13:43:27 -0500 Subject: [PATCH 17/56] Pass tag in test workflow file --- ...lugin-deploy-test-softprops-gh-release-action.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml index 17817cd..1b9428e 100644 --- a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml +++ b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml @@ -4,7 +4,16 @@ name: (delete after testing is done) - Test "Deploy to WordPress.org" on: - workflow_dispatch: # TODO: Delete after testing is complete +# TESTING: Commented out to avoid running on the published event by mistake +# release: +# types: [published] + +# TESTING: Draft a release and then run the workflow file manually + workflow_dispatch: + inputs: + tag: + description: 'The tag for the release (e.g., v1.0.0)' + required: true jobs: tag: @@ -58,6 +67,7 @@ jobs: with: # files: ${{ steps.deploy.outputs.zip-path }} # TESTING: Original zip file source files: build/mailchimp.zip # TESTING: Get zip file from generate plugin step + tag_name: ${{ github.event.inputs.tag }} # Pass the tag from workflow_dispatch input body: | This release contains the latest updates for the WordPress plugin. env: From f1e2bc6799ecff6bdca130b6787b903a9904ffb1 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 14:01:03 -0500 Subject: [PATCH 18/56] Remove whitespace and blank line --- .github/workflows/wordpress-plugin-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index b043697..30881c0 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -28,7 +28,7 @@ jobs: run: | sudo apt-get update sudo apt-get install subversion - + - name: WordPress Plugin Deploy id: deploy uses: 10up/action-wordpress-plugin-deploy@stable @@ -46,4 +46,4 @@ jobs: body: | This release contains the latest updates for the WordPress plugin. env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 81873de703d97c53bc6600850d79dfc51a9fb097 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Fri, 27 Dec 2024 14:02:50 -0500 Subject: [PATCH 19/56] Add back blank line --- .github/workflows/wordpress-plugin-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index 30881c0..e16c0b3 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -46,4 +46,4 @@ jobs: body: | This release contains the latest updates for the WordPress plugin. env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 4852c4b2e65b62b0070d09d0fe564b0d839804b4 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Sat, 28 Dec 2024 12:58:06 -0500 Subject: [PATCH 20/56] Remove sopresto code --- mailchimp.php | 59 +------------------------------------------- views/setup_page.php | 1 - 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index f9870e5..e1f1787 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -75,8 +75,6 @@ */ function mailchimp_sf_plugin_init() { - // Remove Sopresto check. If user does not have API key, make them authenticate. - if ( get_option( 'mc_list_id' ) && get_option( 'mc_merge_field_migrate' ) !== '1' && mailchimp_sf_get_api() !== false ) { mailchimp_sf_update_merge_fields(); } @@ -217,7 +215,7 @@ function mailchimp_sf_request_handler() { } // erase auth information - $options = array( 'mc_api_key', 'mailchimp_sf_access_token', 'mc_datacenter', 'mailchimp_sf_auth_error', 'mailchimp_sf_waiting_for_login', 'mc_sopresto_user', 'mc_sopresto_public_key', 'mc_sopresto_secret_key' ); + $options = array( 'mc_api_key', 'mailchimp_sf_access_token', 'mc_datacenter', 'mailchimp_sf_auth_error', 'mailchimp_sf_waiting_for_login' ); mailchimp_sf_delete_options( $options ); break; case 'change_form_settings': @@ -261,58 +259,6 @@ function mailchimp_sf_request_handler() { } add_action( 'init', 'mailchimp_sf_request_handler' ); -/** - * Migrate Sopresto - * - * @return void - */ -function mailchimp_sf_migrate_sopresto() { - $sopresto = get_option( 'mc_sopresto_secret_key' ); - if ( ! $sopresto ) { - return; - } - - // Talk to Sopresto, make exchange, delete old sopresto things. - $body = array( - 'public_key' => 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 * @@ -395,9 +341,6 @@ function mailchimp_sf_needs_upgrade() { 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', diff --git a/views/setup_page.php b/views/setup_page.php index d1f1fcd..7fe3a16 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(); From 1be18502bf39adc0c4f1b1ebae24f8df65c2f873 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Sat, 28 Dec 2024 13:01:57 -0500 Subject: [PATCH 21/56] Add note --- mailchimp.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mailchimp.php b/mailchimp.php index e1f1787..31185e6 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -337,6 +337,9 @@ 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( From 19896b15ca1bb8120780a576805808ccf664c4f4 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Sat, 28 Dec 2024 13:13:19 -0500 Subject: [PATCH 22/56] Remove trailing whitespace --- mailchimp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index 31185e6..57f8813 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -337,7 +337,7 @@ 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 **/ From 11f276238509c6e08043d79e18851fec1d9c87fa Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 15:30:53 -0500 Subject: [PATCH 23/56] Add admin notice when composer autoload is not present --- mailchimp.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index ced0045..b0fd890 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -34,16 +34,36 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// Define the path to the Composer autoload file -$autoload_file = __DIR__ . '/vendor/autoload.php'; - // Check if the autoload file exists -if ( ! file_exists( $autoload_file ) ) { - die( 'Composer autoload file not found. Run `composer install` to generate it.' ); -} +if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { + require_once __DIR__ . '/vendor/autoload.php'; +} else { + add_action( + 'admin_notices', + function() { + ?> +
+

+ 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/' + ) + ); + ?> +

+
+ Date: Thu, 2 Jan 2025 15:37:11 -0500 Subject: [PATCH 24/56] Add composer install to plugin asset and readme update workflow --- .github/workflows/wordpress-plugin-asset-update.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/wordpress-plugin-asset-update.yml b/.github/workflows/wordpress-plugin-asset-update.yml index 12a9bfb..499dc33 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 From 957ae1c541835fc6550a6bf627cf513c6f6aaa96 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 15:43:40 -0500 Subject: [PATCH 25/56] Update distignore and gitattributes --- .distignore | 1 - .gitattributes | 1 - 2 files changed, 2 deletions(-) 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 From 05fc1a1dcb343749c9f54357764c393cfdfe0747 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 16:07:37 -0500 Subject: [PATCH 26/56] Update translators comment to match WP Core examples. Fix lint errors --- mailchimp.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index b0fd890..45a2d1f 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -40,15 +40,14 @@ } else { add_action( 'admin_notices', - function() { + 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/' From 301086e20d3cc02392d3c63f5f6df9cabf188ab8 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 2 Jan 2025 14:59:14 -0700 Subject: [PATCH 27/56] Update branch name for testing --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 65c8ffa..3331b5f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -11,7 +11,7 @@ on: jobs: build: - uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@develop + uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@enhancement/add-composer-autoload cypress: needs: build From 6a238a22fa82e70c35e3002ef327ee16a07aa930 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Thu, 2 Jan 2025 15:05:11 -0700 Subject: [PATCH 28/56] Revert branch change now that E2E tests were tested --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3331b5f..65c8ffa 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -11,7 +11,7 @@ on: jobs: build: - uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@enhancement/add-composer-autoload + uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@develop cypress: needs: build From 64411117d7d79b854d2e8b62457c8c815a6f41d3 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 17:29:39 -0500 Subject: [PATCH 29/56] Skip pre release triggers. Remove test workflow file. --- ...eploy-test-softprops-gh-release-action.yml | 74 ------------------- .github/workflows/wordpress-plugin-deploy.yml | 1 + 2 files changed, 1 insertion(+), 74 deletions(-) delete mode 100644 .github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml diff --git a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml deleted file mode 100644 index 1b9428e..0000000 --- a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml +++ /dev/null @@ -1,74 +0,0 @@ -# TODO: THIS WORKFLOW FILE IS TO TEST ISSUE #60 "Resolve release deploy action warnings" -# DELETE AFTER TESTING IS COMPLETE. THIS WORKFLOW FILE IS UNNECESSARY. - -name: (delete after testing is done) - Test "Deploy to WordPress.org" - -on: -# TESTING: Commented out to avoid running on the published event by mistake -# release: -# types: [published] - -# TESTING: Draft a release and then run the workflow file manually - workflow_dispatch: - inputs: - tag: - description: 'The tag for the release (e.g., v1.0.0)' - required: true - -jobs: - tag: - name: New release - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup node version and npm cache - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - name: Build - run: | - npm ci --no-optional - npm run build - - - name: Install SVN - run: | - sudo apt-get update - sudo apt-get install subversion - - # TESTING: COMMENTED OUT TO AVOID DEPLOY TO WORDPRESS.ORG DURING TESTING - - # - name: WordPress Plugin Deploy - # id: deploy - # uses: 10up/action-wordpress-plugin-deploy@stable - # with: - # generate-zip: true - # env: - # SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - # SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - # SLUG: mailchimp - - # TESTING: Generate the WordPress Plugin zip file without deploying - - name: Generate Plugin Zip File For Testing (skip deploy to WordPress.org) - id: deploy - run: | - # Create a zip file for the plugin - mkdir -p build - zip -r build/mailchimp.zip . -x "*.git*" "node_modules/*" "tests/*" - env: - SLUG: mailchimp - - - name: Update GitHub release with built plugin files - uses: softprops/action-gh-release@v2 - with: - # files: ${{ steps.deploy.outputs.zip-path }} # TESTING: Original zip file source - files: build/mailchimp.zip # TESTING: Get zip file from generate plugin step - tag_name: ${{ github.event.inputs.tag }} # Pass the tag from workflow_dispatch input - body: | - This release contains the latest updates for the WordPress plugin. - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index e16c0b3..bc71c73 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 From 1474fbe477f96072274f85c3f14addf0966ea878 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 17:33:44 -0500 Subject: [PATCH 30/56] Add back test workflow file for QA --- ...eploy-test-softprops-gh-release-action.yml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml diff --git a/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml new file mode 100644 index 0000000..1b9428e --- /dev/null +++ b/.github/workflows/wordpress-plugin-deploy-test-softprops-gh-release-action.yml @@ -0,0 +1,74 @@ +# TODO: THIS WORKFLOW FILE IS TO TEST ISSUE #60 "Resolve release deploy action warnings" +# DELETE AFTER TESTING IS COMPLETE. THIS WORKFLOW FILE IS UNNECESSARY. + +name: (delete after testing is done) - Test "Deploy to WordPress.org" + +on: +# TESTING: Commented out to avoid running on the published event by mistake +# release: +# types: [published] + +# TESTING: Draft a release and then run the workflow file manually + workflow_dispatch: + inputs: + tag: + description: 'The tag for the release (e.g., v1.0.0)' + required: true + +jobs: + tag: + name: New release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup node version and npm cache + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Build + run: | + npm ci --no-optional + npm run build + + - name: Install SVN + run: | + sudo apt-get update + sudo apt-get install subversion + + # TESTING: COMMENTED OUT TO AVOID DEPLOY TO WORDPRESS.ORG DURING TESTING + + # - name: WordPress Plugin Deploy + # id: deploy + # uses: 10up/action-wordpress-plugin-deploy@stable + # with: + # generate-zip: true + # env: + # SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + # SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + # SLUG: mailchimp + + # TESTING: Generate the WordPress Plugin zip file without deploying + - name: Generate Plugin Zip File For Testing (skip deploy to WordPress.org) + id: deploy + run: | + # Create a zip file for the plugin + mkdir -p build + zip -r build/mailchimp.zip . -x "*.git*" "node_modules/*" "tests/*" + env: + SLUG: mailchimp + + - name: Update GitHub release with built plugin files + uses: softprops/action-gh-release@v2 + with: + # files: ${{ steps.deploy.outputs.zip-path }} # TESTING: Original zip file source + files: build/mailchimp.zip # TESTING: Get zip file from generate plugin step + tag_name: ${{ github.event.inputs.tag }} # Pass the tag from workflow_dispatch input + body: | + This release contains the latest updates for the WordPress plugin. + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 7ac413e1bffb07bbde7f9d8322bb02d2f48763cf Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 18:33:08 -0500 Subject: [PATCH 31/56] Fix fatal error by checking that phone option is enabled --- mailchimp.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mailchimp.php b/mailchimp.php index f9870e5..f094615 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -1004,7 +1004,12 @@ 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'] ) { + if ( + 'phone' === $mv_var['type'] && // Merge field is phone + 'on' === get_option( $opt ) && // Merge field is "included" in the Mailchimp admin options + isset( $mv_var['options']['phone_format'] ) && // Phone format is set in Mailchimp account + 'US' === $mv_var['options']['phone_format'] // Phone format is US in Mailchimp account + ) { $opt_val = mailchimp_sf_merge_validate_phone( $opt_val, $mv_var ); if ( is_wp_error( $opt_val ) ) { return $opt_val; From 23fb25b372a42a30afd49bd441c47489068c5c19 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 18:56:42 -0500 Subject: [PATCH 32/56] Add address validation check for included merge field Add validation comments --- mailchimp.php | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index f094615..12d2190 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -1003,18 +1003,29 @@ 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 ( - 'phone' === $mv_var['type'] && // Merge field is phone - 'on' === get_option( $opt ) && // Merge field is "included" in the Mailchimp admin options - isset( $mv_var['options']['phone_format'] ) && // Phone format is set in Mailchimp account - 'US' === $mv_var['options']['phone_format'] // Phone format is US in Mailchimp account - ) { + /** + * 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 + */ + if ( 'phone' === $mv_var['type'] && '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; } - } elseif ( is_array( $opt_val ) && 'address' === $mv_var['type'] ) { // Handle address logic + } + + /** + * Address validation + * + * - Merge field is address + * - Merge field is "included" in the Mailchimp admin options + * - Merge field is an array (address contains multiple elements) + */ + elseif ( 'address' === $mv_var['type'] && 'on' === get_option( $opt ) && is_array( $opt_val ) ) { // Handle address logic $validate = mailchimp_sf_merge_validate_address( $opt_val, $mv_var ); if ( is_wp_error( $validate ) ) { return $validate; @@ -1024,8 +1035,12 @@ function mailchimp_sf_merge_submit( $mv ) { $merge->$tag = $validate; } continue; + } - } elseif ( is_array( $opt_val ) ) { + /** + * Not sure what this is for + */ + elseif ( is_array( $opt_val ) ) { $keys = array_keys( $opt_val ); $val = new stdClass(); foreach ( $keys as $key ) { @@ -1034,6 +1049,10 @@ function mailchimp_sf_merge_submit( $mv ) { $opt_val = $val; } + /** + * 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'] ) ); From 271f3aa2b020d3ff4ba6d633e9e69035980cb945 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 19:08:58 -0500 Subject: [PATCH 33/56] Refactor if else statement to switch for readability --- mailchimp.php | 98 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index 12d2190..cbfb595 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -1003,54 +1003,70 @@ function mailchimp_sf_merge_submit( $mv ) { $opt_val = isset( $_POST[ $opt ] ) ? map_deep( stripslashes_deep( $_POST[ $opt ] ), 'sanitize_text_field' ) : ''; - /** - * 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 - */ - if ( 'phone' === $mv_var['type'] && '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; - } - } + 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; - /** - * Address validation - * - * - Merge field is address - * - Merge field is "included" in the Mailchimp admin options - * - Merge field is an array (address contains multiple elements) - */ - elseif ( 'address' === $mv_var['type'] && 'on' === get_option( $opt ) && is_array( $opt_val ) ) { // Handle address logic - $validate = mailchimp_sf_merge_validate_address( $opt_val, $mv_var ); - if ( is_wp_error( $validate ) ) { - return $validate; - } + /** + * 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; + } - if ( $validate ) { - $merge->$tag = $validate; - } - continue; - } + if ( $validate ) { + $merge->$tag = $validate; + } + } + break; - /** - * Not sure what this is for - */ - 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; + /** + * 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 ) === '' ) { From 428c4dc84b604cfa3e7199d43e2b898348058b7c Mon Sep 17 00:00:00 2001 From: max Date: Sat, 21 Dec 2024 12:37:19 -0500 Subject: [PATCH 34/56] Dismiss cookie modal if exists --- tests/cypress/e2e/connect.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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() From 0e26284cf74758304823a2aed92af4da8c4882d4 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 19:58:33 -0500 Subject: [PATCH 35/56] Add intval to required field to force same type comparison --- views/setup_page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/setup_page.php b/views/setup_page.php index d1f1fcd..bfb88dd 100644 --- a/views/setup_page.php +++ b/views/setup_page.php @@ -300,7 +300,7 @@ function ( $ele ) { - + Date: Thu, 2 Jan 2025 20:25:20 -0500 Subject: [PATCH 36/56] Add public as requirement to show include box on merge field --- views/setup_page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/setup_page.php b/views/setup_page.php index d1f1fcd..3b4a8b9 100644 --- a/views/setup_page.php +++ b/views/setup_page.php @@ -303,7 +303,7 @@ function ( $ele ) {