From 8a5ce09500b38b5469643a28eef8fc045c56589f Mon Sep 17 00:00:00 2001 From: Dimitrios Vasileiou-Kalfas Date: Fri, 26 Aug 2022 09:49:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20ORN-1259=20check=20w?= =?UTF-8?q?pgraphql=20is=20activated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: ORN-1259 --- wp-graphql-filter-query.php | 77 ++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/wp-graphql-filter-query.php b/wp-graphql-filter-query.php index bfa264d..a26a33b 100644 --- a/wp-graphql-filter-query.php +++ b/wp-graphql-filter-query.php @@ -21,6 +21,13 @@ * Domain Path: /languages */ +namespace WPGraphQL\FILTER_QUERY; + +/** + * Define constants + */ +const WPGRAPHQL_REQUIRED_MIN_VERSION = '0.4.0'; + /** * Load files */ @@ -37,6 +44,19 @@ die; } +/** + * If either WPGraphQL is not active, show the admin notice and return. + */ +if ( false === can_load_plugin() ) { + // Show the admin notice. + add_action( 'admin_init', __NAMESPACE__ . '\show_admin_notice' ); + + return; +} + +( new FilterQuery() )->add_hooks(); +( new AggregateQuery() )->add_hooks(); + /** * Get the supported post types. * @@ -68,6 +88,59 @@ function filter_query_get_supported_post_types(): array { return $type_objects; } +/** + * Show admin notice to admins if this plugin is active but WPGraphQL not. + * + * @return bool + */ +function show_admin_notice() { -( new FilterQuery() )->add_hooks(); -( new AggregateQuery() )->add_hooks(); + /** + * For users with lower capabilities, don't show the notice. + */ + if ( ! current_user_can( 'manage_options' ) ) { + return false; + } + + add_action( + 'admin_notices', + function() { + ?> +
+

+ +

+
+ Date: Fri, 26 Aug 2022 12:00:43 +0100 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Added=20new=20na?= =?UTF-8?q?mespace=20ref=20to=20fn=20calls,=20Disabled=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Disabled broken fn check code as WP_GraphQL etc isn't available when searched for in tests --- src/aggregate-query.php | 1 + src/filter-query.php | 1 + tests/wp-graphql-filter-query.test.php | 2 ++ wp-graphql-filter-query.php | 28 +++++++++++++------------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/aggregate-query.php b/src/aggregate-query.php index 5225a20..12588c9 100644 --- a/src/aggregate-query.php +++ b/src/aggregate-query.php @@ -6,6 +6,7 @@ */ namespace WPGraphQLFilterQuery; +use function WPGraphQL\FILTER_QUERY\filter_query_get_supported_post_types; /** * Main class. diff --git a/src/filter-query.php b/src/filter-query.php index 2ba86e4..5ba76ba 100644 --- a/src/filter-query.php +++ b/src/filter-query.php @@ -8,6 +8,7 @@ namespace WPGraphQLFilterQuery; use WPGraphQL\Data\Connection\AbstractConnectionResolver; +use function WPGraphQL\FILTER_QUERY\filter_query_get_supported_post_types; /** * Main class. diff --git a/tests/wp-graphql-filter-query.test.php b/tests/wp-graphql-filter-query.test.php index 1f99ca3..c8b1e91 100644 --- a/tests/wp-graphql-filter-query.test.php +++ b/tests/wp-graphql-filter-query.test.php @@ -1,5 +1,7 @@