This repository has been archived by the owner on May 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphql-api-extension-demo.php
executable file
·79 lines (72 loc) · 2.32 KB
/
graphql-api-extension-demo.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
<?php
/*
Plugin Name: GraphQL API - Extension Demo
Plugin URI: https://github.com/GraphQLAPI/extension-demo
Description: Demonstration of extending the GraphQL schema, for the GraphQL API for WordPress
Version: 0.8.1
Requires at least: 5.4
Requires PHP: 7.1
Author: Leonardo Losoviz
Author URI: https://leoloso.com
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Text Domain: graphql-api-extension-demo
Domain Path: /languages
*/
use GraphQLAPI\ExtensionDemo\GraphQLAPIExtension;
use GraphQLAPI\GraphQLAPI\Plugin;
use GraphQLAPI\GraphQLAPI\PluginManagement\ExtensionManager;
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* Load translations
*/
\add_action('init', function (): void {
load_plugin_textdomain('graphql-api-extension-demo', false, plugin_basename(__FILE__) . '/languages');
});
/**
* Create and set-up the extension
*/
add_action('plugins_loaded', function (): void {
/**
* Extension's name and version
*/
$extensionVersion = '0.8.1';
$extensionName = \__('GraphQL API - Extension Demo', 'graphql-api-extension-demo');
$mainPluginVersionConstraint = '^0.8';
/**
* Validate the GraphQL API plugin is active
*/
if (!class_exists(Plugin::class)) {
\add_action('admin_notices', function () use ($extensionName) {
_e(sprintf(
'<div class="notice notice-error">' .
'<p>%s</p>' .
'</div>',
sprintf(
__('Plugin <strong>%s</strong> is not installed or activated. Without it, plugin <strong>%s</strong> will not be loaded.', 'graphql-api-extension-demo'),
__('GraphQL API for WordPress', 'graphql-api-extension-demo'),
$extensionName
)
));
});
return;
}
if (ExtensionManager::assertIsValid(
GraphQLAPIExtension::class,
$extensionVersion,
$extensionName,
$mainPluginVersionConstraint
)) {
// Load Composer’s autoloader
require_once(__DIR__ . '/vendor/autoload.php');
// Create and set-up the extension instance
ExtensionManager::register(new GraphQLAPIExtension(
__FILE__,
$extensionVersion,
$extensionName
))->setup();
}
});