Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add composer autoload #95

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
/.wordpress-org
/node_modules
/tests
/vendor

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

/.* export-ignore
/CHANGELOG.md export-ignore
7 changes: 6 additions & 1 deletion .github/workflows/build-release-zip.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .github/workflows/wordpress-plugin-asset-update.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion .github/workflows/wordpress-plugin-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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' );

Loading