Skip to content

Commit

Permalink
Merge pull request #95 from mailchimp/enhancement/add-composer-autoload
Browse files Browse the repository at this point in the history
Add composer autoload
  • Loading branch information
dkotter authored Jan 29, 2025
2 parents 8d10e68 + 34d9065 commit 584b7c5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 4 deletions.
1 change: 0 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/.wordpress-org
/node_modules
/tests
/vendor

# Files to ignore
/.*
Expand Down
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/.wordpress-org export-ignore
/node_modules export-ignore
/tests export-ignore
/vendor export-ignore

/.* export-ignore
/CHANGELOG.md export-ignore
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/build-release-zip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,4 +52,4 @@ jobs:
- name: Generate ZIP file
uses: 10up/action-wordpress-plugin-build-zip@stable
env:
SLUG: mailchimp
SLUG: mailchimp
5 changes: 5 additions & 0 deletions .github/workflows/wordpress-plugin-asset-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/wordpress-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,4 +34,4 @@
"scripts": {
"lint": "phpcs --standard=./phpcs.xml -p -s ."
}
}
}
30 changes: 30 additions & 0 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
* 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 () {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: 1: Command to run, e.g., <code>composer install</code>, 2: Support URL, e.g., https://wordpress.org/support/plugin/mailchimp/. */
__( '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' ),
'<code>composer install</code>',
'https://wordpress.org/support/plugin/mailchimp/'
)
);
?>
</p>
</div>
<?php
}
);

// Exit early.
return;
}

// Version constant for easy CSS refreshes
define( 'MCSF_VER', '1.6.2' );

Expand Down

0 comments on commit 584b7c5

Please sign in to comment.