This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
/
wp-graphql-acf.php
116 lines (96 loc) · 2.4 KB
/
wp-graphql-acf.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
112
113
114
<?php
/**
* Plugin Name: WPGraphQL for Advanced Custom Fields
* Plugin URI: https://wpgraphql.com/acf
* Description: Adds Advanced Custom Fields to the WPGraphQL Schema
* Author: WPGraphQL, Jason Bahl
* Author URI: https://www.wpgraphql.com
* Text Domain: wp-graphql-acf
* Domain Path: /languages
* Version: 0.6.2
* Requires PHP: 7.0
* GitHub Plugin URI: https://github.com/wp-graphql/wp-graphql-acf
*
* @package WPGraphQL_ACF
*/
namespace WPGraphQL\ACF;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once( __DIR__ . '/vendor/autoload.php' );
/**
* Define constants
*/
const WPGRAPHQL_REQUIRED_MIN_VERSION = '0.4.0';
const WPGRAPHQL_ACF_VERSION = '0.6.2';
/**
* Initialize the plugin
*
* @return ACF|void
*/
function init() {
/**
* If either ACF 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\ACF
*/
return ACF::instance();
}
add_action( 'init', '\WPGraphQL\ACF\init' );
/**
* Show admin notice to admins if this plugin is active but either ACF 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() {
?>
<div class="error notice">
<p><?php esc_html_e( sprintf( 'Both WPGraphQL (v%s+) and Advanced Custom Fields (v5.7+) must be active for "wp-graphql-acf" to work', WPGRAPHQL_REQUIRED_MIN_VERSION ), 'wp-graphiql-acf' ); ?></p>
</div>
<?php
}
);
}
/**
* Check whether ACF and WPGraphQL are active, and whether the minimum version requirement has been
* met
*
* @return bool
* @since 0.3
*/
function can_load_plugin() {
// Is ACF active?
if ( ! class_exists( 'ACF' ) ) {
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;
}