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

283 lines 9.9 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://www.parse.ly/help/integration/wordpress
13 * Description: This plugin makes it a snap to add Parse.ly tracking code and metadata to your WordPress blog.
14 * Version: 3.6.1
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.1
22 * Requires WP: 5.0.0
23 */
24
25 declare(strict_types=1);
26
27 namespace Parsely;
28
29 use Parsely\Endpoints\Analytics_Post_Detail_API_Proxy;
30 use Parsely\Endpoints\Analytics_Posts_API_Proxy;
31 use Parsely\Endpoints\GraphQL_Metadata;
32 use Parsely\Endpoints\Referrers_Post_Detail_API_Proxy;
33 use Parsely\Endpoints\Related_API_Proxy;
34 use Parsely\Endpoints\Rest_Metadata;
35 use Parsely\Integrations\Amp;
36 use Parsely\Integrations\Facebook_Instant_Articles;
37 use Parsely\Integrations\Google_Web_Stories;
38 use Parsely\Integrations\Integrations;
39 use Parsely\RemoteAPI\Analytics_Post_Detail_Proxy;
40 use Parsely\RemoteAPI\Analytics_Posts_Proxy;
41 use Parsely\RemoteAPI\Cached_Proxy;
42 use Parsely\RemoteAPI\Referrers_Post_Detail_Proxy;
43 use Parsely\RemoteAPI\Related_Proxy;
44 use Parsely\RemoteAPI\WordPress_Cache;
45 use Parsely\UI\Admin_Bar;
46 use Parsely\UI\Admin_Warning;
47 use Parsely\UI\Metadata_Renderer;
48 use Parsely\UI\Network_Admin_Sites_List;
49 use Parsely\UI\Plugins_Actions;
50 use Parsely\UI\Recommended_Widget;
51 use Parsely\UI\Row_Actions;
52 use Parsely\UI\Settings_Page;
53 use Parsely\UI\Site_Health;
54
55 if ( class_exists( Parsely::class ) ) {
56 return;
57 }
58
59 const PARSELY_VERSION = '3.6.1';
60 const PARSELY_FILE = __FILE__;
61
62 require_once __DIR__ . '/src/class-parsely.php';
63 require_once __DIR__ . '/src/class-scripts.php';
64 require_once __DIR__ . '/src/class-dashboard-link.php';
65 require_once __DIR__ . '/src/UI/class-admin-bar.php';
66 require_once __DIR__ . '/src/UI/class-metadata-renderer.php';
67 require_once __DIR__ . '/src/Endpoints/class-metadata-endpoint.php';
68 require_once __DIR__ . '/src/Endpoints/class-graphql-metadata.php';
69
70 require_once __DIR__ . '/src/class-metadata.php';
71 require_once __DIR__ . '/src/Metadata/class-metadata-builder.php';
72 require_once __DIR__ . '/src/Metadata/class-author-archive-builder.php';
73 require_once __DIR__ . '/src/Metadata/class-category-builder.php';
74 require_once __DIR__ . '/src/Metadata/class-date-builder.php';
75 require_once __DIR__ . '/src/Metadata/class-front-page-builder.php';
76 require_once __DIR__ . '/src/Metadata/class-page-builder.php';
77 require_once __DIR__ . '/src/Metadata/class-page-for-posts-builder.php';
78 require_once __DIR__ . '/src/Metadata/class-paginated-front-page-builder.php';
79 require_once __DIR__ . '/src/Metadata/class-post-builder.php';
80 require_once __DIR__ . '/src/Metadata/class-tag-builder.php';
81
82 add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' );
83 /**
84 * Registers the basic classes to initialize the plugin.
85 */
86 function parsely_initialize_plugin(): void {
87 $GLOBALS['parsely'] = new Parsely();
88 $GLOBALS['parsely']->run();
89
90 if ( class_exists( 'WPGraphQL' ) ) {
91 $graphql = new GraphQL_Metadata( $GLOBALS['parsely'] );
92 $graphql->run();
93 }
94
95 $scripts = new Scripts( $GLOBALS['parsely'] );
96 $scripts->run();
97
98 $admin_bar = new Admin_Bar( $GLOBALS['parsely'] );
99 $admin_bar->run();
100
101 $metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] );
102 $metadata_renderer->run();
103 }
104
105 require_once __DIR__ . '/src/UI/class-admin-warning.php';
106 require_once __DIR__ . '/src/UI/class-plugins-actions.php';
107 require_once __DIR__ . '/src/UI/class-row-actions.php';
108 require_once __DIR__ . '/src/UI/class-site-health.php';
109
110 add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' );
111 /**
112 * Registers the Parse.ly wp-admin warnings, plugin actions and row actions.
113 */
114 function parsely_admin_init_register(): void {
115 $admin_warning = new Admin_Warning( $GLOBALS['parsely'] );
116 $admin_warning->run();
117
118 $plugins_actions = new Plugins_Actions();
119 $plugins_actions->run();
120
121 $row_actions = new Row_Actions( $GLOBALS['parsely'] );
122 $row_actions->run();
123
124 $site_health = new Site_Health( $GLOBALS['parsely'] );
125 $site_health->run();
126 }
127
128 require_once __DIR__ . '/src/UI/class-settings-page.php';
129 require_once __DIR__ . '/src/UI/class-network-admin-sites-list.php';
130
131 add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' );
132 /**
133 * Registers the additions the Parse.ly wp-admin settings page and Multisite
134 * Network Admin Sites List table.
135 */
136 function parsely_wp_admin_early_register(): void {
137 $settings_page = new Settings_Page( $GLOBALS['parsely'] );
138 $settings_page->run();
139
140 $network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
141 $network_admin_sites_list->run();
142 }
143
144 require_once __DIR__ . '/src/RemoteAPI/interface-cache.php';
145 require_once __DIR__ . '/src/RemoteAPI/interface-proxy.php';
146 require_once __DIR__ . '/src/RemoteAPI/class-base-proxy.php';
147 require_once __DIR__ . '/src/RemoteAPI/class-cached-proxy.php';
148 require_once __DIR__ . '/src/RemoteAPI/class-related-proxy.php';
149 require_once __DIR__ . '/src/RemoteAPI/class-analytics-posts-proxy.php';
150 require_once __DIR__ . '/src/RemoteAPI/class-analytics-post-detail-proxy.php';
151 require_once __DIR__ . '/src/RemoteAPI/class-referrers-post-detail-proxy.php';
152 require_once __DIR__ . '/src/RemoteAPI/class-wordpress-cache.php';
153
154 require_once __DIR__ . '/src/Endpoints/class-base-api-proxy.php';
155 require_once __DIR__ . '/src/Endpoints/class-related-api-proxy.php';
156 require_once __DIR__ . '/src/Endpoints/class-analytics-posts-api-proxy.php';
157 require_once __DIR__ . '/src/Endpoints/class-analytics-post-detail-api-proxy.php';
158 require_once __DIR__ . '/src/Endpoints/class-referrers-post-detail-api-proxy.php';
159 require_once __DIR__ . '/src/Endpoints/class-rest-metadata.php';
160
161 add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' );
162 /**
163 * Registers REST Endpoints that act as a proxy to the Parse.ly API.
164 * This is needed to get around CORS issues with Firefox.
165 *
166 * @since 3.2.0
167 */
168 function parsely_rest_api_init(): void {
169 $wp_cache = new WordPress_Cache();
170 $rest = new Rest_Metadata( $GLOBALS['parsely'] );
171 $rest->run();
172
173 parsely_run_rest_api_endpoint(
174 Related_Proxy::class,
175 Related_API_Proxy::class,
176 $wp_cache
177 );
178
179 parsely_run_rest_api_endpoint(
180 Analytics_Posts_Proxy::class,
181 Analytics_Posts_API_Proxy::class,
182 $wp_cache
183 );
184
185 parsely_run_rest_api_endpoint(
186 Analytics_Post_Detail_Proxy::class,
187 Analytics_Post_Detail_API_Proxy::class,
188 $wp_cache
189 );
190
191 parsely_run_rest_api_endpoint(
192 Referrers_Post_Detail_Proxy::class,
193 Referrers_Post_Detail_API_Proxy::class,
194 $wp_cache
195 );
196 }
197
198 require_once __DIR__ . '/src/blocks/recommendations/class-recommendations-block.php';
199
200 add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' );
201 /**
202 * Registers the Recommendations Block.
203 */
204 function init_recommendations_block(): void {
205 $recommendations_block = new Recommendations_Block();
206 $recommendations_block->run();
207 }
208
209 require_once __DIR__ . '/src/blocks/content-helper/class-content-helper.php';
210
211 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\init_content_helper' );
212 /**
213 * Inserts the Content Helper into the WordPress Post Editor.
214 *
215 * @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets()
216 */
217 function init_content_helper(): void {
218 ( new Content_Helper() )->run();
219 }
220
221 require_once __DIR__ . '/src/UI/class-recommended-widget.php';
222
223 add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' );
224 /**
225 * Registers the Parse.ly Recommended widget.
226 */
227 function parsely_recommended_widget_register(): void {
228 register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) );
229 }
230
231 require_once __DIR__ . '/src/Integrations/class-integration.php';
232 require_once __DIR__ . '/src/Integrations/class-integrations.php';
233 require_once __DIR__ . '/src/Integrations/class-amp.php';
234 require_once __DIR__ . '/src/Integrations/class-facebook-instant-articles.php';
235 require_once __DIR__ . '/src/Integrations/class-google-web-stories.php';
236
237 add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' );
238 /**
239 * Instantiates Integrations collection and registers built-in integrations.
240 *
241 * @since 2.6.0
242 *
243 * @param Parsely|string|null $parsely The Parsely object to pass to the integrations.
244 * @return Integrations
245 */
246 function parsely_integrations( $parsely = null ): Integrations {
247 // If $parsely value is "", then this function is being called by the init
248 // hook and we can get the value from $GLOBALS. If $parsely is an instance
249 // of the Parsely object, then this function is being called by a test.
250 if ( empty( $parsely ) || get_class( $parsely ) !== Parsely::class ) {
251 $parsely = $GLOBALS['parsely'];
252 }
253
254 $parsely_integrations = new Integrations( $parsely );
255 $parsely_integrations->register( 'amp', Amp::class );
256 $parsely_integrations->register( 'fbia', Facebook_Instant_Articles::class );
257 $parsely_integrations->register( 'webstories', Google_Web_Stories::class );
258 $parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations );
259 $parsely_integrations->integrate();
260
261 return $parsely_integrations;
262 }
263
264 /**
265 * Instantiates and runs the specified API endpoint.
266 *
267 * @since 3.6.0
268 *
269 * @param string $proxy_class_name The proxy class to instantiate.
270 * @param string $api_proxy_class_name The API proxy class to instantiate and run.
271 * @param WordPress_Cache $wp_cache The WordPress cache instance to be used.
272 */
273 function parsely_run_rest_api_endpoint(
274 string $proxy_class_name,
275 string $api_proxy_class_name,
276 WordPress_Cache &$wp_cache
277 ): void {
278 $proxy_instance = new $proxy_class_name( $GLOBALS['parsely'] );
279 $cached_proxy_instance = new Cached_Proxy( $proxy_instance, $wp_cache );
280 $api_proxy_instance = new $api_proxy_class_name( $GLOBALS['parsely'], $cached_proxy_instance );
281 $api_proxy_instance->run();
282 }
283