diff --git a/.distignore b/.distignore index 7dacb1d..f242837 100644 --- a/.distignore +++ b/.distignore @@ -4,7 +4,6 @@ /.wordpress-org /node_modules /tests -/vendor # Files to ignore /.* diff --git a/.gitattributes b/.gitattributes index 541a824..0324b53 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,6 @@ /.wordpress-org export-ignore /node_modules export-ignore /tests export-ignore -/vendor export-ignore /.* export-ignore /CHANGELOG.md export-ignore diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index d389693..597a51b 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/wordpress-plugin-asset-update.yml b/.github/workflows/wordpress-plugin-asset-update.yml index 12a9bfb..499dc33 100644 --- a/.github/workflows/wordpress-plugin-asset-update.yml +++ b/.github/workflows/wordpress-plugin-asset-update.yml @@ -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 diff --git a/.github/workflows/wordpress-plugin-deploy.yml b/.github/workflows/wordpress-plugin-deploy.yml index f2a9dff..3e8db49 100644 --- a/.github/workflows/wordpress-plugin-deploy.yml +++ b/.github/workflows/wordpress-plugin-deploy.yml @@ -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 \ No newline at end of file diff --git a/composer.json b/composer.json index 2f2b77a..9965490 100644 --- a/composer.json +++ b/composer.json @@ -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 ." } -} +} \ No newline at end of file diff --git a/mailchimp.php b/mailchimp.php index f9870e5..45a2d1f 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -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 () { + ?> +
+

+ composer install, 2: Support URL, e.g., https://wordpress.org/support/plugin/mailchimp/. */ + __( 'The composer autoload file is not found or not readable. Please contact support if you\'re a user. Please run %1$s if you\'re a developer in a development environment.', 'mailchimp' ), + 'composer install', + 'https://wordpress.org/support/plugin/mailchimp/' + ) + ); + ?> +

+
+