forked from anacoelhovicente/wp-graphql-autodescription
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-graphql-autodescription.php
executable file
·111 lines (95 loc) · 2.6 KB
/
wp-graphql-autodescription.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Plugin Name: WPGraphQL for The Seo Framework
* Plugin URI: https://github.com/nogueiram-27/wp-graphql-autodescription
* Description: Adds support for The Seo Framework to the WPGraphQL Schema.
* Author: Ana Vicente
* Author URI: https://anavicente.me
* Version: 1.1.0
* Text Domain: wp-graphql-autodescription
* Requires at least: 4.7.0
* Tested up to: 5.8.1
*
* @package WP_Graphql_Auto_Description
*/
namespace WPGraphQL\AutoDescription;
if (!defined('ABSPATH')) {
exit;
}
/**
* Define constants
*/
const WPGRAPHQL_REQUIRED_MIN_VERSION = '1.8.0';
const WPGRAPHQL_THESEOFRAMEWORK_VERSION = '3.0.3';
/**
* Initialize the plugin
*
* @return AutoDescription|void
*/
function init()
{
/**
* If either The Seo Framework or WPGraphQL are not active, show the admin notice and bail
*/
if (false === can_load_plugin()) {
// Show the admin notice
add_action('admin_init', __NAMESPACE__ . '\show_admin_notice');
// Bail
return;
}
/**
* Return the instance of WPGraphQL\AutoDescription
*/
return AutoDescription::instance();
}
add_action('init', '\WPGraphQL\AutoDescription\init');
/**
* Show admin notice to admins if this plugin is active but either The Seo Framework and/or WPGraphQL
* are not active
*
* @return bool
*/
function show_admin_notice()
{
/**
* For users with lower capabilities, don't show the notice
*/
if (!current_user_can('manage_options')) {
return false;
}
add_action(
'admin_notices',
function () {
echo '<div class="error notice">';
echo '<p>' . esc_html__(sprintf('Both WPGraphQL (v%s+) and The Seo Framework (v%s+) must be active for "wp-graphql-autodescription" to work', WPGRAPHQL_REQUIRED_MIN_VERSION, WPGRAPHQL_THESEOFRAMEWORK_VERSION), 'wp-graphql-autodescription') . '</p>';
echo '</div>';
}
);
}
/**
* Check whether The Seo Framework and WPGraphQL are active, and whether the minimum version requirement has been
* met
*
* @return bool
* @since 0.3
*/
function can_load_plugin()
{
// Is The Seo Framework active?
if (!function_exists('the_seo_framework')) {
return false;
}
// 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;
}