From 6392fbf349fff05aa4cb4654cd6317117b2a0f21 Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 26 Dec 2024 15:44:26 -0500 Subject: [PATCH 1/8] 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 2/8] 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 11f276238509c6e08043d79e18851fec1d9c87fa Mon Sep 17 00:00:00 2001 From: MaxwellGarceau Date: Thu, 2 Jan 2025 15:30:53 -0500 Subject: [PATCH 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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