Skip to content

Commit

Permalink
Merge pull request #179 from wp-graphql/fix/#176-fatal-error-for-comp…
Browse files Browse the repository at this point in the history
…oser-installs

fix: prevent error when users install the plugin from Composer
  • Loading branch information
jasonbahl authored Nov 11, 2022
2 parents c5a6dbb + e532b7c commit e86416d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Cache/Invalidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function __construct( Collection $collection ) {
* Initialize the actions to listen for
*/
public function init() {

// @phpcs:ignore
do_action( 'graphql_cache_invalidation_init', $this );

Expand Down
12 changes: 11 additions & 1 deletion wp-graphql-smart-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
const WPGRAPHQL_REQUIRED_MIN_VERSION = '1.2.0';
const WPGRAPHQL_SMART_CACHE_VERSION = '0.3.1';

require __DIR__ . '/vendor/autoload.php';
// If the autoload file exists, require it.
// If the plugin was installed from composer, the autoload
// would be required elsewhere in the project
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}

if ( ! defined( 'WPGRAPHQL_SMART_CACHE_PLUGIN_DIR' ) ) {
define( 'WPGRAPHQL_SMART_CACHE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand All @@ -58,6 +63,11 @@ function can_load_plugin() {
return false;
}

// If the Document class doesn't exist, then the autoloader failed to load
if ( ! class_exists( Document::class ) ) {
return false;
}

// Do we have a WPGraphQL version to check against?
if ( empty( defined( 'WPGRAPHQL_VERSION' ) ) ) {
return false;
Expand Down

0 comments on commit e86416d

Please sign in to comment.