PluginProbe
Parse.ly / 3.9.0
Parse.ly v3.9.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.9.0, at wp-parsely.php

298 lines 10.4 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.9.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.9.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 require_once __DIR__ . '/src/RemoteAPI/interface-cache.php';
150 require_once __DIR__ . '/src/RemoteAPI/interface-remote-api.php';
151 require_once __DIR__ . '/src/RemoteAPI/class-remote-api-base.php';
152 require_once __DIR__ . '/src/RemoteAPI/class-remote-api-cache.php';
153 require_once __DIR__ . '/src/RemoteAPI/class-related-api.php';
154 require_once __DIR__ . '/src/RemoteAPI/class-analytics-posts-api.php';
155 require_once __DIR__ . '/src/RemoteAPI/class-analytics-post-detail-api.php';
156 require_once __DIR__ . '/src/RemoteAPI/class-referrers-post-detail-api.php';
157 require_once __DIR__ . '/src/RemoteAPI/class-wordpress-cache.php';
158
159 require_once __DIR__ . '/src/Endpoints/class-base-api-proxy.php';
160 require_once __DIR__ . '/src/Endpoints/class-related-api-proxy.php';
161 require_once __DIR__ . '/src/Endpoints/class-analytics-posts-api-proxy.php';
162 require_once __DIR__ . '/src/Endpoints/class-analytics-post-detail-api-proxy.php';
163 require_once __DIR__ . '/src/Endpoints/class-referrers-post-detail-api-proxy.php';
164 require_once __DIR__ . '/src/Endpoints/class-rest-metadata.php';
165
166 add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' );
167 /**
168 * Registers REST Endpoints that act as a proxy to the Parse.ly API.
169 * This is needed to get around CORS issues with Firefox.
170 *
171 * @since 3.2.0
172 */
173 function parsely_rest_api_init(): void {
174 $wp_cache = new WordPress_Cache();
175 $rest = new Rest_Metadata( $GLOBALS['parsely'] );
176 $rest->run();
177
178 parsely_run_rest_api_endpoint(
179 Related_API::class,
180 Related_API_Proxy::class,
181 $wp_cache
182 );
183
184 parsely_run_rest_api_endpoint(
185 Analytics_Posts_API::class,
186 Analytics_Posts_API_Proxy::class,
187 $wp_cache
188 );
189
190 parsely_run_rest_api_endpoint(
191 Analytics_Post_Detail_API::class,
192 Analytics_Post_Detail_API_Proxy::class,
193 $wp_cache
194 );
195
196 parsely_run_rest_api_endpoint(
197 Referrers_Post_Detail_API::class,
198 Referrers_Post_Detail_API_Proxy::class,
199 $wp_cache
200 );
201 }
202
203 require_once __DIR__ . '/src/blocks/recommendations/class-recommendations-block.php';
204
205 add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' );
206 /**
207 * Registers the Recommendations Block.
208 */
209 function init_recommendations_block(): void {
210 $recommendations_block = new Recommendations_Block();
211 $recommendations_block->run();
212 }
213
214 require_once __DIR__ . '/src/content-helper/editor-sidebar/class-editor-sidebar.php';
215
216 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' );
217 /**
218 * Inserts the PCH Editor Sidebar.
219 *
220 * @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets().
221 * @since 3.9.0 Renamed from init_content_helper().
222 */
223 function init_content_helper_editor_sidebar(): void {
224 ( new Editor_Sidebar( $GLOBALS['parsely'] ) )->run();
225 }
226
227 require_once __DIR__ . '/src/UI/class-recommended-widget.php';
228
229 add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' );
230 /**
231 * Registers the Parse.ly Recommended widget.
232 */
233 function parsely_recommended_widget_register(): void {
234 register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) );
235 }
236
237 require_once __DIR__ . '/src/Integrations/class-integration.php';
238 require_once __DIR__ . '/src/Integrations/class-integrations.php';
239 require_once __DIR__ . '/src/Integrations/class-amp.php';
240 require_once __DIR__ . '/src/Integrations/class-google-web-stories.php';
241
242 add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line
243 /**
244 * Instantiates Integrations collection and registers built-in integrations.
245 *
246 * @since 2.6.0
247 *
248 * @param Parsely|string|null $parsely The Parsely object to pass to the integrations.
249 * @return Integrations
250 */
251 function parsely_integrations( $parsely = null ): Integrations {
252 // If $parsely value is "", then this function is being called by the init
253 // hook and we can get the value from $GLOBALS. If $parsely is an instance
254 // of the Parsely object, then this function is being called by a test.
255 if ( ! is_object( $parsely ) || get_class( $parsely ) !== Parsely::class ) {
256 $parsely = $GLOBALS['parsely'];
257 }
258
259 $parsely_integrations = new Integrations( $parsely );
260 $parsely_integrations->register( 'amp', Amp::class );
261 $parsely_integrations->register( 'webstories', Google_Web_Stories::class );
262 $parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations );
263 $parsely_integrations->integrate();
264
265 return $parsely_integrations;
266 }
267
268 /**
269 * Instantiates and runs the specified API endpoint.
270 *
271 * @since 3.6.0
272 *
273 * @param string $api_class_name The proxy class to instantiate.
274 * @param string $proxy_api_class_name The API proxy class to instantiate and run.
275 * @param WordPress_Cache $wp_cache The WordPress cache instance to be used.
276 */
277 function parsely_run_rest_api_endpoint(
278 string $api_class_name,
279 string $proxy_api_class_name,
280 WordPress_Cache &$wp_cache
281 ): void {
282 /**
283 * Internal Variable.
284 *
285 * @var RemoteAPI\Remote_API_Base
286 */
287 $remote_api = new $api_class_name( $GLOBALS['parsely'] );
288 $remote_api_cache = new Remote_API_Cache( $remote_api, $wp_cache );
289
290 /**
291 * Internal Variable.
292 *
293 * @var Endpoints\Base_API_Proxy
294 */
295 $remote_api_proxy = new $proxy_api_class_name( $GLOBALS['parsely'], $remote_api_cache );
296 $remote_api_proxy->run();
297 }
298