PluginProbe
Parse.ly / 3.13.2
Parse.ly v3.13.2
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.13.2, at wp-parsely.php

350 lines 12.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.13.2
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\Excerpt_Generator;
32 use Parsely\Content_Helper\Post_List_Stats;
33 use Parsely\Endpoints\Analytics_Post_Detail_API_Proxy;
34 use Parsely\Endpoints\Analytics_Posts_API_Proxy;
35 use Parsely\Endpoints\ContentSuggestions\Suggest_Meta_Description_API_Proxy;
36 use Parsely\Endpoints\ContentSuggestions\Write_Title_API_Proxy;
37 use Parsely\Endpoints\GraphQL_Metadata;
38 use Parsely\Endpoints\Referrers_Post_Detail_API_Proxy;
39 use Parsely\Endpoints\Related_API_Proxy;
40 use Parsely\Endpoints\Rest_Metadata;
41 use Parsely\Endpoints\User_Meta\Dashboard_Widget_Settings_Endpoint;
42 use Parsely\Endpoints\User_Meta\Editor_Sidebar_Settings_Endpoint;
43 use Parsely\Integrations\Amp;
44 use Parsely\Integrations\Google_Web_Stories;
45 use Parsely\Integrations\Integrations;
46 use Parsely\RemoteAPI\Analytics_Post_Detail_API;
47 use Parsely\RemoteAPI\Analytics_Posts_API;
48 use Parsely\RemoteAPI\ContentSuggestions\Suggest_Meta_Description_API;
49 use Parsely\RemoteAPI\ContentSuggestions\Write_Title_API;
50 use Parsely\RemoteAPI\Referrers_Post_Detail_API;
51 use Parsely\RemoteAPI\Related_API;
52 use Parsely\RemoteAPI\Remote_API_Cache;
53 use Parsely\RemoteAPI\WordPress_Cache;
54 use Parsely\UI\Admin_Bar;
55 use Parsely\UI\Admin_Warning;
56 use Parsely\UI\Metadata_Renderer;
57 use Parsely\UI\Network_Admin_Sites_List;
58 use Parsely\UI\Plugins_Actions;
59 use Parsely\UI\Recommended_Widget;
60 use Parsely\UI\Row_Actions;
61 use Parsely\UI\Settings_Page;
62 use Parsely\UI\Site_Health;
63
64 require_once __DIR__ . '/src/Utils/utils.php';
65
66 if ( class_exists( Parsely::class ) ) {
67 return;
68 }
69
70 const PARSELY_VERSION = '3.13.2';
71 const PARSELY_FILE = __FILE__;
72
73 require_once __DIR__ . '/src/class-parsely.php';
74 require_once __DIR__ . '/src/class-scripts.php';
75 require_once __DIR__ . '/src/class-dashboard-link.php';
76 require_once __DIR__ . '/src/class-validator.php';
77 require_once __DIR__ . '/src/UI/class-admin-bar.php';
78 require_once __DIR__ . '/src/UI/class-metadata-renderer.php';
79 require_once __DIR__ . '/src/Endpoints/class-metadata-endpoint.php';
80 require_once __DIR__ . '/src/Endpoints/class-graphql-metadata.php';
81 require_once __DIR__ . '/src/Telemetry/telemetry-init.php';
82
83 require_once __DIR__ . '/src/class-metadata.php';
84 require_once __DIR__ . '/src/Metadata/class-metadata-builder.php';
85 require_once __DIR__ . '/src/Metadata/class-author-archive-builder.php';
86 require_once __DIR__ . '/src/Metadata/class-category-builder.php';
87 require_once __DIR__ . '/src/Metadata/class-date-builder.php';
88 require_once __DIR__ . '/src/Metadata/class-front-page-builder.php';
89 require_once __DIR__ . '/src/Metadata/class-page-builder.php';
90 require_once __DIR__ . '/src/Metadata/class-page-for-posts-builder.php';
91 require_once __DIR__ . '/src/Metadata/class-paginated-front-page-builder.php';
92 require_once __DIR__ . '/src/Metadata/class-post-builder.php';
93 require_once __DIR__ . '/src/Metadata/class-tag-builder.php';
94
95 add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' );
96 /**
97 * Registers the basic classes to initialize the plugin.
98 */
99 function parsely_initialize_plugin(): void {
100 $GLOBALS['parsely'] = new Parsely();
101 $GLOBALS['parsely']->run();
102
103 if ( class_exists( 'WPGraphQL' ) ) {
104 $graphql = new GraphQL_Metadata( $GLOBALS['parsely'] );
105 $graphql->run();
106 }
107
108 $scripts = new Scripts( $GLOBALS['parsely'] );
109 $scripts->run();
110
111 $admin_bar = new Admin_Bar( $GLOBALS['parsely'] );
112 $admin_bar->run();
113
114 $metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] );
115 $metadata_renderer->run();
116 }
117
118 require_once __DIR__ . '/src/content-helper/common/class-content-helper-feature.php';
119 require_once __DIR__ . '/src/content-helper/post-list-stats/class-post-list-stats.php';
120 require_once __DIR__ . '/src/UI/class-admin-warning.php';
121 require_once __DIR__ . '/src/UI/class-plugins-actions.php';
122 require_once __DIR__ . '/src/UI/class-row-actions.php';
123 require_once __DIR__ . '/src/UI/class-site-health.php';
124 require_once __DIR__ . '/src/content-helper/dashboard-widget/class-dashboard-widget.php';
125
126 add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' );
127 /**
128 * Registers the Parse.ly wp-admin warnings, plugin actions and row actions.
129 */
130 function parsely_admin_init_register(): void {
131 $parsely = $GLOBALS['parsely'];
132
133 ( new Admin_Warning( $parsely ) )->run();
134 ( new Plugins_Actions() )->run();
135 ( new Row_Actions( $parsely ) )->run();
136 ( new Post_List_Stats( $parsely ) )->run();
137 ( new Site_Health( $parsely ) )->run();
138 ( new Dashboard_Widget( $parsely ) )->run();
139 }
140
141 require_once __DIR__ . '/src/UI/class-settings-page.php';
142 require_once __DIR__ . '/src/UI/class-network-admin-sites-list.php';
143
144 add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' );
145 /**
146 * Registers the additions the Parse.ly wp-admin settings page and Multisite
147 * Network Admin Sites List table.
148 */
149 function parsely_wp_admin_early_register(): void {
150 $GLOBALS['parsely_settings_page'] = new Settings_Page( $GLOBALS['parsely'] );
151 $GLOBALS['parsely_settings_page']->run();
152
153 $network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
154 $network_admin_sites_list->run();
155 }
156
157 // Endpoint base classes.
158 require_once __DIR__ . '/src/Endpoints/class-base-endpoint.php';
159 require_once __DIR__ . '/src/Endpoints/class-base-api-proxy.php';
160 require_once __DIR__ . '/src/Endpoints/user-meta/class-base-endpoint-user-meta.php';
161
162 // Endpoint classes.
163 require_once __DIR__ . '/src/Endpoints/class-analytics-post-detail-api-proxy.php';
164 require_once __DIR__ . '/src/Endpoints/class-analytics-posts-api-proxy.php';
165 require_once __DIR__ . '/src/Endpoints/class-referrers-post-detail-api-proxy.php';
166 require_once __DIR__ . '/src/Endpoints/class-related-api-proxy.php';
167 require_once __DIR__ . '/src/Endpoints/class-rest-metadata.php';
168 require_once __DIR__ . '/src/Endpoints/content-suggestions/class-suggest-meta-description-api-proxy.php';
169 require_once __DIR__ . '/src/Endpoints/content-suggestions/class-write-title-api-proxy.php';
170 require_once __DIR__ . '/src/Endpoints/user-meta/class-dashboard-widget-settings-endpoint.php';
171 require_once __DIR__ . '/src/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php';
172
173 // RemoteAPI base classes.
174 require_once __DIR__ . '/src/RemoteAPI/interface-cache.php';
175 require_once __DIR__ . '/src/RemoteAPI/interface-remote-api.php';
176 require_once __DIR__ . '/src/RemoteAPI/class-remote-api-cache.php';
177 require_once __DIR__ . '/src/RemoteAPI/class-wordpress-cache.php';
178 require_once __DIR__ . '/src/RemoteAPI/class-base-endpoint-remote.php';
179 require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-content-suggestions-base-api.php';
180
181 // RemoteAPI classes.
182 require_once __DIR__ . '/src/RemoteAPI/class-analytics-post-detail-api.php';
183 require_once __DIR__ . '/src/RemoteAPI/class-analytics-posts-api.php';
184 require_once __DIR__ . '/src/RemoteAPI/class-referrers-post-detail-api.php';
185 require_once __DIR__ . '/src/RemoteAPI/class-related-api.php';
186 require_once __DIR__ . '/src/RemoteAPI/class-validate-api.php';
187 require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-suggest-meta-description-api.php';
188 require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-write-title-api.php';
189
190 add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' );
191 /**
192 * Registers REST Endpoints that act as a proxy to the Parse.ly API.
193 * This is needed to get around CORS issues with Firefox.
194 *
195 * @since 3.2.0
196 */
197 function parsely_rest_api_init(): void {
198 $wp_cache = new WordPress_Cache();
199 $rest = new Rest_Metadata( $GLOBALS['parsely'] );
200 $rest->run();
201
202 // Content Helper settings endpoints.
203 ( new Dashboard_Widget_Settings_Endpoint( $GLOBALS['parsely'] ) )->run();
204 ( new Editor_Sidebar_Settings_Endpoint( $GLOBALS['parsely'] ) )->run();
205
206 parsely_run_rest_api_endpoint(
207 Related_API::class,
208 Related_API_Proxy::class,
209 $wp_cache
210 );
211
212 parsely_run_rest_api_endpoint(
213 Analytics_Posts_API::class,
214 Analytics_Posts_API_Proxy::class,
215 $wp_cache
216 );
217
218 parsely_run_rest_api_endpoint(
219 Analytics_Post_Detail_API::class,
220 Analytics_Post_Detail_API_Proxy::class,
221 $wp_cache
222 );
223
224 parsely_run_rest_api_endpoint(
225 Referrers_Post_Detail_API::class,
226 Referrers_Post_Detail_API_Proxy::class,
227 $wp_cache
228 );
229
230 parsely_run_rest_api_endpoint(
231 Write_Title_API::class,
232 Write_Title_API_Proxy::class,
233 $wp_cache
234 );
235
236 parsely_run_rest_api_endpoint(
237 Suggest_Meta_Description_API::class,
238 Suggest_Meta_Description_API_Proxy::class,
239 $wp_cache
240 );
241 }
242
243 require_once __DIR__ . '/src/blocks/recommendations/class-recommendations-block.php';
244
245 add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' );
246 /**
247 * Registers the Recommendations Block.
248 */
249 function init_recommendations_block(): void {
250 $recommendations_block = new Recommendations_Block();
251 $recommendations_block->run();
252 }
253
254 require_once __DIR__ . '/src/content-helper/editor-sidebar/class-editor-sidebar.php';
255
256 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' );
257 /**
258 * Inserts the PCH Editor Sidebar.
259 *
260 * @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets().
261 * @since 3.9.0 Renamed from init_content_helper().
262 */
263 function init_content_helper_editor_sidebar(): void {
264 ( new Editor_Sidebar( $GLOBALS['parsely'] ) )->run();
265 }
266
267 require_once __DIR__ . '/src/content-helper/excerpt-generator/class-excerpt-generator.php';
268
269 add_action( 'init', __NAMESPACE__ . '\\init_content_helper_excerpt_generator' );
270 /**
271 * Initializes and inserts the PCH Excerpt Generator.
272 *
273 * @since 3.13.0
274 */
275 function init_content_helper_excerpt_generator(): void {
276 ( new Excerpt_Generator( $GLOBALS['parsely'] ) )->run();
277 }
278
279 require_once __DIR__ . '/src/UI/class-recommended-widget.php';
280
281 add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' );
282 /**
283 * Registers the Parse.ly Recommended widget.
284 */
285 function parsely_recommended_widget_register(): void {
286 register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) );
287 }
288
289 require_once __DIR__ . '/src/Integrations/class-integration.php';
290 require_once __DIR__ . '/src/Integrations/class-integrations.php';
291 require_once __DIR__ . '/src/Integrations/class-amp.php';
292 require_once __DIR__ . '/src/Integrations/class-google-web-stories.php';
293
294 add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line
295 /**
296 * Instantiates Integrations collection and registers built-in integrations.
297 *
298 * @since 2.6.0
299 *
300 * @param Parsely|string|null $parsely The Parsely object to pass to the integrations.
301 * @return Integrations
302 */
303 function parsely_integrations( $parsely = null ): Integrations {
304 // If $parsely value is "", then this function is being called by the init
305 // hook and we can get the value from $GLOBALS. If $parsely is an instance
306 // of the Parsely object, then this function is being called by a test.
307 if ( ! is_object( $parsely ) || get_class( $parsely ) !== Parsely::class ) {
308 $parsely = $GLOBALS['parsely'];
309 }
310
311 $parsely_integrations = new Integrations( $parsely );
312 $parsely_integrations->register( 'amp', Amp::class );
313 $parsely_integrations->register( 'webstories', Google_Web_Stories::class );
314 $parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations );
315 $parsely_integrations->integrate();
316
317 return $parsely_integrations;
318 }
319
320 /**
321 * Instantiates and runs the specified API endpoint.
322 *
323 * @since 3.6.0
324 *
325 * @param string $api_class_name The proxy class to instantiate.
326 * @param string $proxy_api_class_name The API proxy class to instantiate and run.
327 * @param WordPress_Cache $wp_cache The WordPress cache instance to be used.
328 */
329 function parsely_run_rest_api_endpoint(
330 string $api_class_name,
331 string $proxy_api_class_name,
332 WordPress_Cache &$wp_cache
333 ): void {
334 /**
335 * Internal Variable.
336 *
337 * @var RemoteAPI\Base_Endpoint_Remote
338 */
339 $remote_api = new $api_class_name( $GLOBALS['parsely'] );
340 $remote_api_cache = new Remote_API_Cache( $remote_api, $wp_cache );
341
342 /**
343 * Internal Variable.
344 *
345 * @var Endpoints\Base_API_Proxy
346 */
347 $remote_api_proxy = new $proxy_api_class_name( $GLOBALS['parsely'], $remote_api_cache );
348 $remote_api_proxy->run();
349 }
350