Skip to content

Commit a702bee

Browse files
authored
Bugfix/global autoloader support (#524)
* version numbers updated. * "WP_GraphQL_WooCommerce::includes()" refactored. * External non-vendor includes deprecated.
1 parent 6f4a685 commit a702bee

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Feel free to test out the extension using this [GraphiQL Playground](https://woo
5151

5252
(*) 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:
5353

54-
## Wanna help support WooGraphQL's future.
54+
## Wanna help support WooGraphQL's future
5555

5656
- Sponsor **@kidunot89** *(WooGraphQL Creator/Developer)* on **[Github](https://github.com/sponsors/kidunot89)**
5757
- Sponsor **WooGraphQL** on **[OpenCollective](https://opencollective.com/woographql)**

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Requires PHP: 7.1
77
Requires WooCommerce: 4.8.0
88
Requires WPGraphQL: 1.3.9+
99
Works with WPGraphQL-JWT-Authentication: 0.4.0+
10-
Stable tag: 0.10.0
10+
Stable tag: 0.10.1
1111
License: GPL-3
1212
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1313
Maintained at: https://github.com/wp-graphql/wp-graphql-woocommerce

access-functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*
55
* @package WPGraphQL\WooCommerce
66
* @since 0.0.1
7+
* @deprecated v0.10.2
8+
*
9+
* Will be removed in v0.11.0. Some functions will be relocated.
710
*/
811

912
/**

class-woographql-inflect.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* @link https://gist.github.com/tbrianjones/ba0460cc1d55f357e00b
1010
* @package WPGraphQL\WooCommerce
1111
* @since 0.0.4
12+
* @deprecated v0.10.2
13+
*
14+
* Will be removed in v0.11.0. Functionality will be no longer in use.
1215
*/
1316

1417
if ( ! class_exists( 'WooGraphQL_Inflect' ) ) :

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-wp-graphql-woocommerce.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,56 @@ public function __wakeup() {
137137
*/
138138
private function includes() {
139139

140-
// Autoload Required Classes.
141-
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && false !== WPGRAPHQL_WOOCOMMERCE_AUTOLOAD ) {
142-
require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php';
140+
/**
141+
* WPGRAPHQL_AUTOLOAD can be set to "false" to prevent the autoloader from running.
142+
* In most cases, this is not something that should be disabled, but some environments
143+
* may bootstrap their dependencies in a global autoloader that will autoload files
144+
* before we get to this point, and requiring the autoloader again can trigger fatal errors.
145+
*
146+
* The codeception tests are an example of an environment where adding the autoloader again causes issues
147+
* so this is set to false for tests.
148+
*/
149+
if ( defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && true === WPGRAPHQL_WOOCOMMERCE_AUTOLOAD ) {
150+
if ( file_exists( WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php' ) ) {
151+
// Autoload Required Classes.
152+
require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'vendor/autoload.php';
153+
}
154+
155+
/**
156+
* If GraphQL class doesn't exist, then dependencies cannot be
157+
* detected. This likely means the user cloned the repo from Github
158+
* but did not run `composer install`
159+
*/
160+
if ( ! class_exists( 'Firebase\JWT\JWT' ) ) {
161+
add_action(
162+
'admin_notices',
163+
function () {
164+
if ( ! current_user_can( 'manage_options' ) ) {
165+
return;
166+
}
167+
168+
echo sprintf(
169+
'<div class="notice notice-error">' .
170+
'<p>%s</p>' .
171+
'</div>',
172+
esc_html__(
173+
'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`.',
174+
'wp-graphql-woocommerce'
175+
)
176+
);
177+
}
178+
);
179+
180+
return false;
181+
}
143182
}
144183

145184
// Required non-autoloaded classes.
146185
require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'access-functions.php';
147186
require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'class-woographql-inflect.php';
187+
require_once WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR . 'includes/functions.php';
188+
189+
return true;
148190
}
149191

150192
/**

includes/functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*
55
* @package WPGraphQL\WooCommerce
66
* @since 0.3.1
7+
* @deprecated v0.10.2
8+
*
9+
* Will be removed in v0.11.0
710
*/
811

912
namespace WPGraphQL\WooCommerce\Functions;

tests/_data/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010

1111
if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) && false !== getenv( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) ) {
12-
define( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD', getenv( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD' ) );
12+
define( 'WPGRAPHQL_WOOCOMMERCE_AUTOLOAD', true );
1313
}
1414

1515
if ( ! defined( 'GRAPHQL_JWT_AUTH_SECRET_KEY' ) ) {

wp-graphql-woocommerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WPGraphQL WooCommerce (WooGraphQL)
44
* Plugin URI: https://github.com/wp-graphql/wp-graphql-woocommerce
55
* Description: Adds Woocommerce Functionality to WPGraphQL schema.
6-
* Version: 0.10.0
6+
* Version: 0.10.1
77
* Author: kidunot89
88
* Author URI: https://axistaylor.com
99
* Text Domain: wp-graphql-woocommerce
@@ -29,7 +29,7 @@
2929
function woographql_constants() {
3030
// Plugin version.
3131
if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_VERSION' ) ) {
32-
define( 'WPGRAPHQL_WOOCOMMERCE_VERSION', '0.10.0' );
32+
define( 'WPGRAPHQL_WOOCOMMERCE_VERSION', '0.10.1' );
3333
}
3434
// Plugin Folder Path.
3535
if ( ! defined( 'WPGRAPHQL_WOOCOMMERCE_PLUGIN_DIR' ) ) {

0 commit comments

Comments
 (0)