Skip to content

Commit 584b7c5

Browse files
authored
Merge pull request #95 from mailchimp/enhancement/add-composer-autoload
Add composer autoload
2 parents 8d10e68 + 34d9065 commit 584b7c5

File tree

7 files changed

+55
-4
lines changed

7 files changed

+55
-4
lines changed

.distignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/.wordpress-org
55
/node_modules
66
/tests
7-
/vendor
87

98
# Files to ignore
109
/.*

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/.wordpress-org export-ignore
33
/node_modules export-ignore
44
/tests export-ignore
5-
/vendor export-ignore
65

76
/.* export-ignore
87
/CHANGELOG.md export-ignore

.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-asset-update.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
node-version-file: .nvmrc
2121
cache: npm
2222

23+
- name: Install Composer dependencies and dump autoload
24+
run: |
25+
composer install --no-dev --optimize-autoloader
26+
composer dump-autoload
27+
2328
- name: Build
2429
run: |
2530
npm ci --no-optional

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
node-version-file: '.nvmrc'
2121
cache: 'npm'
2222

23+
- name: Install Composer dependencies and dump autoload
24+
run: |
25+
composer install --no-dev --optimize-autoloader
26+
composer dump-autoload
27+
2328
- name: Build
2429
run: |
2530
npm ci --no-optional

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
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+
},
2129
"config": {
2230
"allow-plugins": {
2331
"dealerdirect/phpcodesniffer-composer-installer": true
@@ -26,4 +34,4 @@
2634
"scripts": {
2735
"lint": "phpcs --standard=./phpcs.xml -p -s ."
2836
}
29-
}
37+
}

mailchimp.php

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

37+
// Check if the autoload file exists
38+
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
39+
require_once __DIR__ . '/vendor/autoload.php';
40+
} else {
41+
add_action(
42+
'admin_notices',
43+
function () {
44+
?>
45+
<div class="notice notice-error">
46+
<p>
47+
<?php
48+
echo wp_kses_post(
49+
sprintf(
50+
/* translators: 1: Command to run, e.g., <code>composer install</code>, 2: Support URL, e.g., https://wordpress.org/support/plugin/mailchimp/. */
51+
__( 'The composer autoload file is not found or not readable. Please contact <a href="%2$s" target="_blank">support</a> if you\'re a user. Please run %1$s if you\'re a developer in a development environment.', 'mailchimp' ),
52+
'<code>composer install</code>',
53+
'https://wordpress.org/support/plugin/mailchimp/'
54+
)
55+
);
56+
?>
57+
</p>
58+
</div>
59+
<?php
60+
}
61+
);
62+
63+
// Exit early.
64+
return;
65+
}
66+
3767
// Version constant for easy CSS refreshes
3868
define( 'MCSF_VER', '1.6.2' );
3969

0 commit comments

Comments
 (0)