PluginProbe
Parse.ly / 3.12.0
Parse.ly v3.12.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.12.0, at wp-parsely.php

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