From a702bee591d381cc308c672c89e6485dae39ce19 Mon Sep 17 00:00:00 2001 From: Geoffrey K Taylor Date: Tue, 6 Jul 2021 20:20:47 -0400 Subject: [PATCH] Bugfix/global autoloader support (#524) * version numbers updated. * "WP_GraphQL_WooCommerce::includes()" refactored. * External non-vendor includes deprecated. --- README.md | 2 +- README.txt | 2 +- access-functions.php | 3 ++ class-woographql-inflect.php | 3 ++ composer.lock | 2 +- includes/class-wp-graphql-woocommerce.php | 48 +++++++++++++++++++++-- includes/functions.php | 3 ++ tests/_data/config.php | 2 +- wp-graphql-woocommerce.php | 4 +- 9 files changed, 60 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ada78d00..009e9448 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Feel free to test out the extension using this [GraphiQL Playground](https://woo (*) I have a tendency to forget to update the playground between releases :sweat_smile:, so if you believe this to be the case look me up somewhere on this page and lemme know :man_shrugging: -## Wanna help support WooGraphQL's future. +## Wanna help support WooGraphQL's future - Sponsor **@kidunot89** *(WooGraphQL Creator/Developer)* on **[Github](https://github.com/sponsors/kidunot89)** - Sponsor **WooGraphQL** on **[OpenCollective](https://opencollective.com/woographql)** diff --git a/README.txt b/README.txt index 53d10abd..fea05d3a 100644 --- a/README.txt +++ b/README.txt @@ -7,7 +7,7 @@ Requires PHP: 7.1 Requires WooCommerce: 4.8.0 Requires WPGraphQL: 1.3.9+ Works with WPGraphQL-JWT-Authentication: 0.4.0+ -Stable tag: 0.10.0 +Stable tag: 0.10.1 License: GPL-3 License URI: https://www.gnu.org/licenses/gpl-3.0.html Maintained at: https://github.com/wp-graphql/wp-graphql-woocommerce diff --git a/access-functions.php b/access-functions.php index c31a716a..200864e9 100644 --- a/access-functions.php +++ b/access-functions.php @@ -4,6 +4,9 @@ * * @package WPGraphQL\WooCommerce * @since 0.0.1 + * @deprecated v0.10.2 + * + * Will be removed in v0.11.0. Some functions will be relocated. */ /** diff --git a/class-woographql-inflect.php b/class-woographql-inflect.php index 8bafbf43..20ced6f4 100644 --- a/class-woographql-inflect.php +++ b/class-woographql-inflect.php @@ -9,6 +9,9 @@ * @link https://gist.github.com/tbrianjones/ba0460cc1d55f357e00b * @package WPGraphQL\WooCommerce * @since 0.0.4 + * @deprecated v0.10.2 + * + * Will be removed in v0.11.0. Functionality will be no longer in use. */ if ( ! class_exists( 'WooGraphQL_Inflect' ) ) : diff --git a/composer.lock b/composer.lock index c8430930..afd28272 100644 --- a/composer.lock +++ b/composer.lock @@ -182,5 +182,5 @@ "php": ">=7.1.0" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.0.0" } diff --git a/includes/class-wp-graphql-woocommerce.php b/includes/class-wp-graphql-woocommerce.php index ea428f94..0590875d 100644 --- a/includes/class-wp-graphql-woocommerce.php +++ b/includes/class-wp-graphql-woocommerce.php @@ -137,14 +137,56 @@ if ( ! class_exists( 'WP_GraphQL_WooCommerce' ) ) : */ private function includes() { - // Autoload Required Classes. - if ( defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && false !== WPGRAPHQL_WOOCOMMERCE_AUTOLOAD ) { - require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php'; + /** + * WPGRAPHQL_AUTOLOAD can be set to "false" to prevent the autoloader from running. + * In most cases, this is not something that should be disabled, but some environments + * may bootstrap their dependencies in a global autoloader that will autoload files + * before we get to this point, and requiring the autoloader again can trigger fatal errors. + * + * The codeception tests are an example of an environment where adding the autoloader again causes issues + * so this is set to false for tests. + */ + if ( defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && true === WPGRAPHQL_WOOCOMMERCE_AUTOLOAD ) { + if ( file_exists( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php' ) ) { + // Autoload Required Classes. + require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php'; + } + + /** + * If GraphQL class doesn't exist, then dependencies cannot be + * detected. This likely means the user cloned the repo from Github + * but did not run `composer install` + */ + if ( ! class_exists( 'Firebase\JWT\JWT' ) ) { + add_action( + 'admin_notices', + function () { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + echo sprintf( + '
' . + '

%s

' . + '
', + esc_html__( + 'WooGraphQL appears to have been installed without it\'s dependencies. It will not work properly until dependencies are installed. This likely means you have cloned WPGraphQL from Github and need to run the command `composer install`.', + 'wp-graphql-woocommerce' + ) + ); + } + ); + + return false; + } } // Required non-autoloaded classes. require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'access-functions.php'; require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'class-woographql-inflect.php'; + require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'includes/functions.php'; + + return true; } /** diff --git a/includes/functions.php b/includes/functions.php index 98140e57..69528f46 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -4,6 +4,9 @@ * * @package WPGraphQL\WooCommerce * @since 0.3.1 + * @deprecated v0.10.2 + * + * Will be removed in v0.11.0 */ namespace WPGraphQL\WooCommerce\Functions; diff --git a/tests/_data/config.php b/tests/_data/config.php index eadd3dbf..e43a5972 100644 --- a/tests/_data/config.php +++ b/tests/_data/config.php @@ -9,7 +9,7 @@ if ( ! defined( 'GRAPHQL_DEBUG' ) ) { } if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && false !== getenv( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) ) { - define( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD', getenv( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) ); + define( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD', true ); } if ( ! defined( 'GRAPHQL_JWT_AUTH_SECRET_KEY' ) ) { diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php index 50e95c15..ebf1a06f 100644 --- a/wp-graphql-woocommerce.php +++ b/wp-graphql-woocommerce.php @@ -3,7 +3,7 @@ * Plugin Name: WPGraphQL WooCommerce (WooGraphQL) * Plugin URI: https://github.com/wp-graphql/wp-graphql-woocommerce * Description: Adds Woocommerce Functionality to WPGraphQL schema. - * Version: 0.10.0 + * Version: 0.10.1 * Author: kidunot89 * Author URI: https://axistaylor.com * Text Domain: wp-graphql-woocommerce @@ -29,7 +29,7 @@ defined( 'ABSPATH' ) || exit; function woographql_constants() { // Plugin version. if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) ) { - define( 'WPGRAPHQL_WOOCOMMERCE_VERSION', '0.10.0' ); + define( 'WPGRAPHQL_WOOCOMMERCE_VERSION', '0.10.1' ); } // Plugin Folder Path. if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR' ) ) {