Skip to content

Commit 1af5301

Browse files
authored
dev: enforce plugin dep versions (#35)
* chore: cleanup phpstan.neon * dev: check plugin dependency versions.
1 parent 971c1e5 commit 1af5301

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Changelog
22

33
## Unreleased
4+
- dev: check plugin dependency versions.
45
- dev: namespace Composer dependencies with Strauss.
5-
- chore: update WPGraphQL Plugin Boilerplate dependency to v0.0.8.
66
- dev: wrap global functions in `function_exists()` checks.
7+
- chore: update WPGraphQL Plugin Boilerplate dependency to v0.0.8.
8+
79
## v0.0.9
810
- chore: update WPGraphQL Plugin Boilerplate dependency to v0.0.7.
911

phpstan.neon.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ parameters:
1616
- vendor/axepress/wp-graphql-plugin-boilerplate/phpstan/Model.stub
1717
bootstrapFiles:
1818
- phpstan/constants.php
19-
- wp-graphql-rank-math.php
20-
- access-functions.php
21-
- activation.php
22-
- deactivation.php
2319
paths:
2420
- wp-graphql-rank-math.php
2521
- access-functions.php
2622
- activation.php
2723
- deactivation.php
2824
- src/
25+
excludePaths:
26+
analyse:
27+
- vendor-prefixed
2928
scanDirectories:
30-
- src/
3129
- ../seo-by-rank-math
3230
- vendor-prefixed/axepress/wp-graphql-plugin-boilerplate/src/
3331
scanFiles:

wp-graphql-rank-math.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,22 @@ function graphql_seo_constants() : void {
8181
if ( ! function_exists( 'graphql_seo_dependencies_not_ready' ) ) {
8282
/**
8383
* Checks if all the the required plugins are installed and activated.
84+
*
85+
* @return array<string, string> List of dependencies that are not ready.
8486
*/
8587
function graphql_seo_dependencies_not_ready() : array {
88+
$wpgraphql_version = '1.8.1';
89+
$rankmath_version = '1.0.90';
90+
8691
$deps = [];
8792

88-
if ( ! class_exists( '\WPGraphQL' ) ) {
89-
$deps[] = 'WPGraphQL';
93+
// WPGraphQL Check.
94+
if ( ! class_exists( '\WPGraphQL' ) || ( defined( 'WPGRAPHQL_VERSION' ) && version_compare( WPGRAPHQL_VERSION, $wpgraphql_version, '<' ) ) ) { // @phpstan-ignore-line
95+
$deps['WPGraphQL'] = $wpgraphql_version;
9096
}
91-
if ( ! class_exists( '\RankMath' ) ) {
92-
$deps[] = 'RankMath SEO';
97+
98+
if ( ! class_exists( '\RankMath' ) || defined( 'RANK_MATH_VERSION' ) && version_compare( RANK_MATH_VERSION, $rankmath_version, '<' ) ) {
99+
$deps['RankMath SEO'] = $rankmath_version;
93100
}
94101

95102
return $deps;
@@ -112,18 +119,19 @@ function graphql_seo_init() : void {
112119
return;
113120
}
114121

115-
foreach ( $not_ready as $dep ) {
122+
foreach ( $not_ready as $dep => $version ) {
116123
add_action(
117124
'admin_notices',
118-
function() use ( $dep ) {
125+
function() use ( $dep, $version ) {
119126
?>
120127
<div class="error notice">
121128
<p>
122129
<?php
123130
printf(
124131
/* translators: dependency not ready error message */
125-
esc_html__( '%1$s must be active for WPGraphQL for Rank Math to work.', 'wp-graphql-rank-math' ),
126-
esc_html( $dep )
132+
esc_html__( '%1$s (v%2$s+) must be active for WPGraphQL for Rank Math to work.', 'wp-graphql-rank-math' ),
133+
esc_attr( $dep ),
134+
esc_attr( $version ),
127135
);
128136
?>
129137
</p>

0 commit comments

Comments
 (0)