Skip to content

Commit 6392fbf

Browse files
Add composer autoload
1 parent 0b93ec3 commit 6392fbf

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

.github/workflows/build-release-zip.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ jobs:
3535
if: steps.cache-node-modules.outputs.cache-hit != 'true'
3636
run: npm ci --no-optional
3737

38+
- name: Install Composer dependencies and dump autoload
39+
run: |
40+
composer install --no-dev --optimize-autoloader
41+
composer dump-autoload
42+
3843
- name: Build plugin
3944
run: |
4045
npm run build
@@ -47,4 +52,4 @@ jobs:
4752
- name: Generate ZIP file
4853
uses: 10up/action-wordpress-plugin-build-zip@stable
4954
env:
50-
SLUG: mailchimp
55+
SLUG: mailchimp

.github/workflows/wordpress-plugin-deploy.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ jobs:
1919
node-version-file: '.nvmrc'
2020
cache: 'npm'
2121

22+
- name: Install Composer dependencies and dump autoload
23+
run: |
24+
composer install --no-dev --optimize-autoloader
25+
composer dump-autoload
26+
2227
- name: Build
2328
run: |
2429
npm ci --no-optional
@@ -47,4 +52,4 @@ jobs:
4752
upload_url: ${{ github.event.release.upload_url }}
4853
asset_path: ${{ steps.deploy.outputs.zip-path }}
4954
asset_name: mailchimp.zip
50-
asset_content_type: application/zip
55+
asset_content_type: application/zip

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
"10up/phpcs-composer": "^3.0",
1919
"sirbrillig/phpcs-changed": "^2.11"
2020
},
21+
"autoload": {
22+
"psr-4": {
23+
"Mailchimp\\WordPress\\": "src/"
24+
},
25+
"classmap": [
26+
"includes"
27+
],
28+
"files": [
29+
"includes/admin/admin-notices.php"
30+
]
31+
},
2132
"config": {
2233
"allow-plugins": {
2334
"dealerdirect/phpcodesniffer-composer-installer": true
@@ -26,4 +37,4 @@
2637
"scripts": {
2738
"lint": "phpcs --standard=./phpcs.xml -p -s ."
2839
}
29-
}
40+
}

mailchimp.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3535
*/
3636

37+
// Define the path to the Composer autoload file
38+
$autoloadFile = __DIR__ . '/vendor/autoload.php';
39+
40+
// Check if the autoload file exists
41+
if ( ! file_exists( $autoloadFile ) ) {
42+
die( 'Composer autoload file not found. Run `composer install` to generate it.' );
43+
}
44+
45+
// Include the autoload file
46+
require_once $autoloadFile;
47+
3748
// Version constant for easy CSS refreshes
3849
define( 'MCSF_VER', '1.6.2' );
3950

0 commit comments

Comments
 (0)