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

Merged
merged 11 commits into from
Jan 29, 2025
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
7 changes: 6 additions & 1 deletion .github/workflows/wordpress-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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 ."
}
}
}
11 changes: 11 additions & 0 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
* 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.' );
MaxwellGarceau marked this conversation as resolved.
Show resolved Hide resolved
}

// Include the autoload file
require_once $autoload_file;

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

Expand Down
Loading