-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-graphql-multisite.php
77 lines (70 loc) · 1.89 KB
/
wp-graphql-multisite.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
<?php
/**
* Plugin Name: WP GraphQL for Multisites
* Description: Adds graphql nodes for multisite or network queries
* Version: 1.0.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Tom Do
*/
register_activation_hook( __FILE__, 'child_plugin_activate' );
function child_plugin_activate(){
// Require parent plugin
if ( ! is_plugin_active( 'wp-graphql/wp-graphql.php' ) && current_user_can( 'activate_plugins' ) ) {
// Stop activation redirect and show error
wp_die('Sorry, but this plugin requires the WP GraphQL base plugin to be installed and active. <br><a href="' . admin_url( 'plugins.php' ) . '">« Return to Plugins</a>');
}
}
add_action( 'graphql_register_types', 'register_site_type' );
function register_site_type() {
register_graphql_object_type( 'Site', [
'fields' => [
'blog_id' => [
'type' => 'String',
],
'domain' => [
'type' => 'String',
],
'path' => [
'type' => 'String',
],
'site_id' => [
'type' => 'String',
],
'registered' => [
'type' => 'String',
],
'last_updated' => [
'type' => 'String',
],
'public' => [
'type' => 'String',
],
'archived' => [
'type' => 'String',
],
'mature' => [
'type' => 'String',
],
'spam' => [
'type' => 'String',
],
'deleted' => [
'type' => 'String',
],
'lang_id' => [
'type' => 'String',
],
],
] );
}
add_action( 'graphql_register_types', function() {
register_graphql_fields( 'RootQuery', [
'Sites' => [
'type' => ["list_of" => "Site"],
'resolve' => function() {
return get_sites();
}
]
] );
} );