Skip to content

Commit

Permalink
Check for Composer dependency before loading Composer (#61)
Browse files Browse the repository at this point in the history
* Check for a dependent class before loading, prepare for mantle 1.0

* Adjust logic to prevent loading composer (aims to aid when plugin is loaded with Composer)

* 0.1.3 release
  • Loading branch information
srtfisher authored Mar 11, 2024
1 parent 5b17b9e commit 5dadf78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `WP Page Cache Control` will be documented in this file.

## v0.1.3 - 2024-03-08

- Check for already-loaded Composer dependencies before loading them again.

## v0.1.2 - 2024-02-29

- Fixing bug with Pantheon Provider not properly detecting the user's IP address.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": "^8.0",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"mantle-framework/support": "^0.11|^0.12"
"mantle-framework/support": "^0.11|^0.12|^1.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^2.0",
Expand Down
19 changes: 8 additions & 11 deletions wp-page-cache-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Page Cache Control
* Plugin URI: https://github.com/alleyinteractive/wp-page-cache-control
* Description: Control and modify the page cache for multiple hosting providers.
* Version: 0.1.2
* Version: 0.1.3
* Author: Sean Fisher
* Author URI: https://github.com/alleyinteractive/wp-page-cache-control
* Requires at least: 5.9
Expand All @@ -29,13 +29,10 @@
*/
define( 'WP_PAGE_CACHE_CONTROL_DIR', __DIR__ );

// Check if Composer is installed (remove if Composer is not required for your plugin).
if ( ! file_exists( __DIR__ . '/vendor/wordpress-autoload.php' ) ) {
// Will also check for the presence of an already loaded Composer autoloader
// to see if the Composer dependencies have been installed in a parent
// folder. This is useful for when the plugin is loaded as a Composer
// dependency in a larger project.
if ( ! class_exists( \Composer\InstalledVersions::class ) ) {
// Check if Composer is installed by checking for the existence of the Str class.
if ( ! class_exists( \Mantle\Support\Str::class ) ) {
// Check if the autoloader exists. Otherwise, display an admin notice and bail.
if ( ! file_exists( __DIR__ . '/vendor/wordpress-autoload.php' ) ) {
\add_action(
'admin_notices',
function () {
Expand All @@ -48,10 +45,10 @@ function () {
);

return;
} else {
// Load Composer dependencies.
require_once __DIR__ . '/vendor/wordpress-autoload.php';
}
} else {
// Load Composer dependencies.
require_once __DIR__ . '/vendor/wordpress-autoload.php';
}

// Load the plugin's main files.
Expand Down

0 comments on commit 5dadf78

Please sign in to comment.