Skip to content

ORN-1259 : check wpgraphql is activated before activating wpgraphql-filter-query #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aggregate-query.php
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
*/

namespace WPGraphQLFilterQuery;
use function WPGraphQL\FILTER_QUERY\filter_query_get_supported_post_types;

/**
* Main class.
1 change: 1 addition & 0 deletions src/filter-query.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
namespace WPGraphQLFilterQuery;

use WPGraphQL\Data\Connection\AbstractConnectionResolver;
use function WPGraphQL\FILTER_QUERY\filter_query_get_supported_post_types;

/**
* Main class.
2 changes: 2 additions & 0 deletions tests/wp-graphql-filter-query.test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function WPGraphQL\FILTER_QUERY\filter_query_get_supported_post_types;

class Wp_GraphqlFilterQueryTest extends WP_UnitTestCase {

protected function setUp(): void {
77 changes: 75 additions & 2 deletions wp-graphql-filter-query.php
Original file line number Diff line number Diff line change
@@ -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() {
?>
<div class="error notice">
<p>
<?php
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
esc_html_e( 'WPGraphQL (v' . WPGRAPHQL_REQUIRED_MIN_VERSION . '+) must be active for "wp-graphql-filter-query" to work' );
?>
</p>
</div>
<?php
}
);
}


/**
* Check whether WPGraphQL is active, and whether the minimum version requirement has been met.
*
* @return bool
*/
function can_load_plugin() {

// // Is WPGraphQL active?
// if ( ! class_exists( 'WPGraphQL' ) ) {
// return false;
// }

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

// // Have we met the minimum version requirement?
// if ( true === version_compare( WPGRAPHQL_VERSION, WPGRAPHQL_REQUIRED_MIN_VERSION, 'lt' ) ) {
// return false;
// }

return true;
}