PluginProbe
Parse.ly / 3.11.0
Parse.ly v3.11.0
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / wp-parsely.php

wp-parsely.php in Parse.ly 3.11.0, at wp-parsely.php

306 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Parse.ly
4 *
5 * @package Parsely
6 * @author Parse.ly
7 * @copyright 2012 Parse.ly
8 * @license GPL-2.0-or-later
9 *
10 * @wordpress-plugin
11 * Plugin Name: Parse.ly
12 * Plugin URI: https://docs.parse.ly/wordpress
13 * Description: This plugin makes it a snap to add Parse.ly tracking code and metadata to your WordPress blog.
14 * Version: 3.11.0
15 * Author: Parse.ly
16 * Author URI: https://www.parse.ly
17 * Text Domain: wp-parsely
18 * License: GPL-2.0-or-later
19 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
20 * GitHub Plugin URI: https://github.com/Parsely/wp-parsely
21 * Requires PHP: 7.2
22 * Requires WP: 5.0.0
23 */
24
25 declare(strict_types=1);
26
27 namespace Parsely;
28
29 use Parsely\Content_Helper\Dashboard_Widget;
30 use Parsely\Content_Helper\Editor_Sidebar;
31 use Parsely\Content_Helper\Post_List_Stats;
32 use Parsely\Endpoints\Analytics_Post_Detail_API_Proxy;
33 use Parsely\Endpoints\Analytics_Posts_API_Proxy;
34 use Parsely\Endpoints\GraphQL_Metadata;
35 use Parsely\Endpoints\Referrers_Post_Detail_API_Proxy;
36 use Parsely\Endpoints\Related_API_Proxy;
37 use Parsely\Endpoints\Rest_Metadata;
38 use Parsely\Integrations\Amp;
39 use Parsely\Integrations\Google_Web_Stories;
40 use Parsely\Integrations\Integrations;
41 use Parsely\RemoteAPI\Analytics_Post_Detail_API;
42 use Parsely\RemoteAPI\Analytics_Posts_API;
43 use Parsely\RemoteAPI\Referrers_Post_Detail_API;
44 use Parsely\RemoteAPI\Related_API;
45 use Parsely\RemoteAPI\Remote_API_Cache;
46 use Parsely\RemoteAPI\WordPress_Cache;
47 use Parsely\UI\Admin_Bar;
48 use Parsely\UI\Admin_Warning;
49 use Parsely\UI\Metadata_Renderer;
50 use Parsely\UI\Network_Admin_Sites_List;
51 use Parsely\UI\Plugins_Actions;
52 use Parsely\UI\Recommended_Widget;
53 use Parsely\UI\Row_Actions;
54 use Parsely\UI\Settings_Page;
55 use Parsely\UI\Site_Health;
56
57 require_once __DIR__ . '/src/Utils/utils.php';
58
59 if ( class_exists( Parsely::class ) ) {
60 return;
61 }
62
63 const PARSELY_VERSION = '3.11.0';
64 const PARSELY_FILE = __FILE__;
65
66 require_once __DIR__ . '/src/class-parsely.php';
67 require_once __DIR__ . '/src/class-scripts.php';
68 require_once __DIR__ . '/src/class-dashboard-link.php';
69 require_once __DIR__ . '/src/class-validator.php';
70 require_once __DIR__ . '/src/UI/class-admin-bar.php';
71 require_once __DIR__ . '/src/UI/class-metadata-renderer.php';
72 require_once __DIR__ . '/src/Endpoints/class-metadata-endpoint.php';
73 require_once __DIR__ . '/src/Endpoints/class-graphql-metadata.php';
74
75 require_once __DIR__ . '/src/class-metadata.php';
76 require_once __DIR__ . '/src/Metadata/class-metadata-builder.php';
77 require_once __DIR__ . '/src/Metadata/class-author-archive-builder.php';
78 require_once __DIR__ . '/src/Metadata/class-category-builder.php';
79 require_once __DIR__ . '/src/Metadata/class-date-builder.php';
80 require_once __DIR__ . '/src/Metadata/class-front-page-builder.php';
81 require_once __DIR__ . '/src/Metadata/class-page-builder.php';
82 require_once __DIR__ . '/src/Metadata/class-page-for-posts-builder.php';
83 require_once __DIR__ . '/src/Metadata/class-paginated-front-page-builder.php';
84 require_once __DIR__ . '/src/Metadata/class-post-builder.php';
85 require_once __DIR__ . '/src/Metadata/class-tag-builder.php';
86
87 add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' );
88 /**
89 * Registers the basic classes to initialize the plugin.
90 */
91 function parsely_initialize_plugin(): void {
92 $GLOBALS['parsely'] = new Parsely();
93 $GLOBALS['parsely']->run();
94
95 if ( class_exists( 'WPGraphQL' ) ) {
96 $graphql = new GraphQL_Metadata( $GLOBALS['parsely'] );
97 $graphql->run();
98 }
99
100 $scripts = new Scripts( $GLOBALS['parsely'] );
101 $scripts->run();
102
103 $admin_bar = new Admin_Bar( $GLOBALS['parsely'] );
104 $admin_bar->run();
105
106 $metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] );
107 $metadata_renderer->run();
108 }
109
110 require_once __DIR__ . '/src/content-helper/common/class-content-helper-feature.php';
111 require_once __DIR__ . '/src/content-helper/post-list-stats/class-post-list-stats.php';
112 require_once __DIR__ . '/src/UI/class-admin-warning.php';
113 require_once __DIR__ . '/src/UI/class-plugins-actions.php';
114 require_once __DIR__ . '/src/UI/class-row-actions.php';
115 require_once __DIR__ . '/src/UI/class-site-health.php';
116 require_once __DIR__ . '/src/content-helper/dashboard-widget/class-dashboard-widget.php';
117
118 add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' );
119 /**
120 * Registers the Parse.ly wp-admin warnings, plugin actions and row actions.
121 */
122 function parsely_admin_init_register(): void {
123 $parsely = $GLOBALS['parsely'];
124
125 ( new Admin_Warning( $parsely ) )->run();
126 ( new Plugins_Actions() )->run();
127 ( new Row_Actions( $parsely ) )->run();
128 ( new Post_List_Stats( $parsely ) )->run();
129 ( new Site_Health( $parsely ) )->run();
130 ( new Dashboard_Widget( $parsely ) )->run();
131 }
132
133 require_once __DIR__ . '/src/UI/class-settings-page.php';
134 require_once __DIR__ . '/src/UI/class-network-admin-sites-list.php';
135
136 add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' );
137 /**
138 * Registers the additions the Parse.ly wp-admin settings page and Multisite
139 * Network Admin Sites List table.
140 */
141 function parsely_wp_admin_early_register(): void {
142 $GLOBALS['parsely_settings_page'] = new Settings_Page( $GLOBALS['parsely'] );
143 $GLOBALS['parsely_settings_page']->run();
144
145 $network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
146 $network_admin_sites_list->run();
147 }
148
149 // Endpoint base classes.
150 require_once __DIR__ . '/src/Endpoints/class-base-endpoint.php';
151 require_once __DIR__ . '/src/Endpoints/class-base-api-proxy.php';
152
153 // Endpoint classes.
154 require_once __DIR__ . '/src/Endpoints/class-analytics-post-detail-api-proxy.php';
155 require_once __DIR__ . '/src/Endpoints/class-analytics-posts-api-proxy.php';
156 require_once __DIR__ . '/src/Endpoints/class-referrers-post-detail-api-proxy.php';
157 require_once __DIR__ . '/src/Endpoints/class-related-api-proxy.php';
158 require_once __DIR__ . '/src/Endpoints/class-rest-metadata.php';
159
160 // RemoteAPI base classes.
161 require_once __DIR__ . '/src/RemoteAPI/interface-cache.php';
162 require_once __DIR__ . '/src/RemoteAPI/interface-remote-api.php';
163 require_once __DIR__ . '/src/RemoteAPI/class-remote-api-cache.php';
164 require_once __DIR__ . '/src/RemoteAPI/class-wordpress-cache.php';
165 require_once __DIR__ . '/src/RemoteAPI/class-base-endpoint-remote.php';
166
167 // RemoteAPI classes.
168 require_once __DIR__ . '/src/RemoteAPI/class-analytics-post-detail-api.php';
169 require_once __DIR__ . '/src/RemoteAPI/class-analytics-posts-api.php';
170 require_once __DIR__ . '/src/RemoteAPI/class-referrers-post-detail-api.php';
171 require_once __DIR__ . '/src/RemoteAPI/class-related-api.php';
172 require_once __DIR__ . '/src/RemoteAPI/class-validate-api.php';
173
174 add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' );
175 /**
176 * Registers REST Endpoints that act as a proxy to the Parse.ly API.
177 * This is needed to get around CORS issues with Firefox.
178 *
179 * @since 3.2.0
180 */
181 function parsely_rest_api_init(): void {
182 $wp_cache = new WordPress_Cache();
183 $rest = new Rest_Metadata( $GLOBALS['parsely'] );
184 $rest->run();
185
186 parsely_run_rest_api_endpoint(
187 Related_API::class,
188 Related_API_Proxy::class,
189 $wp_cache
190 );
191
192 parsely_run_rest_api_endpoint(
193 Analytics_Posts_API::class,
194 Analytics_Posts_API_Proxy::class,
195 $wp_cache
196 );
197
198 parsely_run_rest_api_endpoint(
199 Analytics_Post_Detail_API::class,
200 Analytics_Post_Detail_API_Proxy::class,
201 $wp_cache
202 );
203
204 parsely_run_rest_api_endpoint(
205 Referrers_Post_Detail_API::class,
206 Referrers_Post_Detail_API_Proxy::class,
207 $wp_cache
208 );
209 }
210
211 require_once __DIR__ . '/src/blocks/recommendations/class-recommendations-block.php';
212
213 add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' );
214 /**
215 * Registers the Recommendations Block.
216 */
217 function init_recommendations_block(): void {
218 $recommendations_block = new Recommendations_Block();
219 $recommendations_block->run();
220 }
221
222 require_once __DIR__ . '/src/content-helper/editor-sidebar/class-editor-sidebar.php';
223
224 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' );
225 /**
226 * Inserts the PCH Editor Sidebar.
227 *
228 * @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets().
229 * @since 3.9.0 Renamed from init_content_helper().
230 */
231 function init_content_helper_editor_sidebar(): void {
232 ( new Editor_Sidebar( $GLOBALS['parsely'] ) )->run();
233 }
234
235 require_once __DIR__ . '/src/UI/class-recommended-widget.php';
236
237 add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' );
238 /**
239 * Registers the Parse.ly Recommended widget.
240 */
241 function parsely_recommended_widget_register(): void {
242 register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) );
243 }
244
245 require_once __DIR__ . '/src/Integrations/class-integration.php';
246 require_once __DIR__ . '/src/Integrations/class-integrations.php';
247 require_once __DIR__ . '/src/Integrations/class-amp.php';
248 require_once __DIR__ . '/src/Integrations/class-google-web-stories.php';
249
250 add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line
251 /**
252 * Instantiates Integrations collection and registers built-in integrations.
253 *
254 * @since 2.6.0
255 *
256 * @param Parsely|string|null $parsely The Parsely object to pass to the integrations.
257 * @return Integrations
258 */
259 function parsely_integrations( $parsely = null ): Integrations {
260 // If $parsely value is "", then this function is being called by the init
261 // hook and we can get the value from $GLOBALS. If $parsely is an instance
262 // of the Parsely object, then this function is being called by a test.
263 if ( ! is_object( $parsely ) || get_class( $parsely ) !== Parsely::class ) {
264 $parsely = $GLOBALS['parsely'];
265 }
266
267 $parsely_integrations = new Integrations( $parsely );
268 $parsely_integrations->register( 'amp', Amp::class );
269 $parsely_integrations->register( 'webstories', Google_Web_Stories::class );
270 $parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations );
271 $parsely_integrations->integrate();
272
273 return $parsely_integrations;
274 }
275
276 /**
277 * Instantiates and runs the specified API endpoint.
278 *
279 * @since 3.6.0
280 *
281 * @param string $api_class_name The proxy class to instantiate.
282 * @param string $proxy_api_class_name The API proxy class to instantiate and run.
283 * @param WordPress_Cache $wp_cache The WordPress cache instance to be used.
284 */
285 function parsely_run_rest_api_endpoint(
286 string $api_class_name,
287 string $proxy_api_class_name,
288 WordPress_Cache &$wp_cache
289 ): void {
290 /**
291 * Internal Variable.
292 *
293 * @var RemoteAPI\Base_Endpoint_Remote
294 */
295 $remote_api = new $api_class_name( $GLOBALS['parsely'] );
296 $remote_api_cache = new Remote_API_Cache( $remote_api, $wp_cache );
297
298 /**
299 * Internal Variable.
300 *
301 * @var Endpoints\Base_API_Proxy
302 */
303 $remote_api_proxy = new $proxy_api_class_name( $GLOBALS['parsely'], $remote_api_cache );
304 $remote_api_proxy->run();
305 }
306