PluginProbe
WPGraphQL for ACF / 2.7.1
WPGraphQL for ACF v2.7.1
3.0.0 2.8.0 2.7.1 2.7.0 2.6.4 2.6.5 2.6.3 2.6.2 2.6.1 trunk 2.0.0 2.0.0-beta.7.0.0 2.1.0 2.1.1 2.1.2 2.2.0 2.3.0 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.6.0
wpgraphql-acf / wpgraphql-acf.php

wpgraphql-acf.php in WPGraphQL for ACF 2.7.1, at wpgraphql-acf.php

145 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WPGraphQL for ACF
4 * Description: WPGraphQL for ACF seamlessly integrates Advanced Custom Fields with WPGraphQL.
5 * Author: WPGraphQL
6 * Author URI: https://www.wpgraphql.com
7 * Version: 2.7.1
8 * Text Domain: wpgraphql-acf
9 * Requires PHP: 7.3
10 * Requires at least: 5.9
11 * Tested up to: 7.0
12 * License: GPL-3
13 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
14 * Requires Plugins: wp-graphql
15 * Requires WPGraphQL: 1.29
16 * WPGraphQL tested up to: 2.0.0
17 *
18 * @package WPGraphQL\ACF
19 */
20
21 // Exit if accessed directly.
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 if ( ! class_exists( 'WPGraphQLAcf' ) ) {
27 require_once __DIR__ . '/src/WPGraphQLAcf.php';
28 }
29
30 // If this file doesn't exist, the plugin was likely installed from Composer
31 // and the autoloader is included in the parent project
32 if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
33 require_once __DIR__ . '/vendor/autoload.php';
34 }
35
36 if ( ! defined( 'WPGRAPHQL_FOR_ACF_VERSION' ) ) {
37 define( 'WPGRAPHQL_FOR_ACF_VERSION', '2.7.1' );
38 }
39
40 if ( ! defined( 'WPGRAPHQL_FOR_ACF_VERSION_WPGRAPHQL_REQUIRED_MIN_VERSION' ) ) {
41 define( 'WPGRAPHQL_FOR_ACF_VERSION_WPGRAPHQL_REQUIRED_MIN_VERSION', '1.14.4' );
42 }
43
44 if ( ! defined( 'WPGRAPHQL_FOR_ACF_VERSION_PLUGIN_DIR' ) ) {
45 define( 'WPGRAPHQL_FOR_ACF_VERSION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
46 }
47
48 if ( ! function_exists( 'graphql_acf_init' ) ) {
49 /**
50 * Function that instantiates the plugins main class
51 *
52 * @return void
53 */
54 function graphql_acf_init() {
55 $wp_graphql_acf = new \WPGraphQLAcf();
56 add_action( 'plugins_loaded', [ $wp_graphql_acf, 'init' ], 50 );
57 }
58
59 /**
60 * Load plugin text domain at init so translations are loaded at the correct time (WordPress 6.7+).
61 * Prevents _load_textdomain_just_in_time "triggered too early" notice.
62 *
63 * @return void
64 */
65 function graphql_acf_load_textdomain() {
66 load_plugin_textdomain(
67 'wpgraphql-acf',
68 false,
69 dirname( plugin_basename( __FILE__ ) ) . '/languages'
70 );
71 }
72 add_action( 'init', 'graphql_acf_load_textdomain', 0 );
73 }
74 graphql_acf_init();
75
76 /**
77 * Initialize the plugin tracker
78 *
79 * @return void
80 */
81 function graphql_acf_init_appsero_telemetry() {
82 // If the class doesn't exist, or code is being scanned by PHPSTAN, move on.
83 if ( ! class_exists( 'Appsero\Client' ) || defined( 'PHPSTAN' ) ) {
84 return;
85 }
86
87 $client = new Appsero\Client( '4988d797-77ee-4201-84ce-1d610379f843', 'WPGraphQL for Advanced Custom Fields', __FILE__ );
88 $insights = $client->insights();
89
90 // If the Appsero client has the add_plugin_data method, use it
91 if ( method_exists( $insights, 'add_plugin_data' ) ) {
92 // @phpstan-ignore-next-line
93 $insights->add_plugin_data();
94 }
95
96 // @phpstan-ignore-next-line
97 $insights->init();
98 }
99
100 graphql_acf_init_appsero_telemetry();
101
102 /**
103 * Mirror the Appsero API requests to our own telemetry server.
104 *
105 * @param bool|\WP_Error $preempt Whether to preempt the request.
106 * @param array $args The arguments for the request.
107 * @param string $url The URL for the request.
108 * @return bool|\WP_Error Whether to preempt the request.
109 */
110 add_filter(
111 'pre_http_request',
112 static function ( $preempt, $args, $url ) {
113 if ( strpos( $url, 'api.appsero.com' ) === false ) {
114 return $preempt;
115 }
116
117 // Scope: only mirror this plugin's payloads, not other Appsero plugins on the site.
118 $body = is_array( $args['body'] ?? null ) ? $args['body'] : [];
119 if ( ( $body['hash'] ?? null ) !== '4988d797-77ee-4201-84ce-1d610379f843' ) {
120 return $preempt;
121 }
122
123 $mirror = str_replace(
124 'https://api.appsero.com/',
125 'https://telemetry.wpgraphql.com/api/appsero/',
126 $url
127 );
128
129 wp_remote_post(
130 $mirror,
131 array_merge(
132 $args,
133 [
134 'blocking' => false,
135 'timeout' => 3,
136 ]
137 )
138 );
139
140 return $preempt; // let the real Appsero request proceed
141 },
142 10,
143 3
144 );
145