PluginProbe
Parse.ly / 3.6.0
Parse.ly v3.6.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.6.0, at wp-parsely.php

230 lines 6.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.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.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.0';
60 const PARSELY_FILE = __FILE__;
61
62 if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
63 require_once __DIR__ . '/vendor/autoload.php';
64 }
65
66 add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' );
67 /**
68 * Registers the basic classes to initialize the plugin.
69 */
70 function parsely_initialize_plugin(): void {
71 $GLOBALS['parsely'] = new Parsely();
72 $GLOBALS['parsely']->run();
73
74 if ( class_exists( 'WPGraphQL' ) ) {
75 $graphql = new GraphQL_Metadata( $GLOBALS['parsely'] );
76 $graphql->run();
77 }
78
79 $scripts = new Scripts( $GLOBALS['parsely'] );
80 $scripts->run();
81
82 $admin_bar = new Admin_Bar( $GLOBALS['parsely'] );
83 $admin_bar->run();
84
85 $metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] );
86 $metadata_renderer->run();
87 }
88
89 add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' );
90 /**
91 * Registers the Parse.ly wp-admin warnings, plugin actions and row actions.
92 */
93 function parsely_admin_init_register(): void {
94 $admin_warning = new Admin_Warning( $GLOBALS['parsely'] );
95 $admin_warning->run();
96
97 $plugins_actions = new Plugins_Actions();
98 $plugins_actions->run();
99
100 $row_actions = new Row_Actions( $GLOBALS['parsely'] );
101 $row_actions->run();
102
103 $site_health = new Site_Health( $GLOBALS['parsely'] );
104 $site_health->run();
105 }
106
107 add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' );
108 /**
109 * Registers the additions the Parse.ly wp-admin settings page and Multisite
110 * Network Admin Sites List table.
111 */
112 function parsely_wp_admin_early_register(): void {
113 $settings_page = new Settings_Page( $GLOBALS['parsely'] );
114 $settings_page->run();
115
116 $network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
117 $network_admin_sites_list->run();
118 }
119
120 add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' );
121 /**
122 * Registers REST Endpoints that act as a proxy to the Parse.ly API.
123 * This is needed to get around CORS issues with Firefox.
124 *
125 * @since 3.2.0
126 */
127 function parsely_rest_api_init(): void {
128 $wp_cache = new WordPress_Cache();
129 $rest = new Rest_Metadata( $GLOBALS['parsely'] );
130 $rest->run();
131
132 parsely_run_rest_api_endpoint(
133 Related_Proxy::class,
134 Related_API_Proxy::class,
135 $wp_cache
136 );
137
138 parsely_run_rest_api_endpoint(
139 Analytics_Posts_Proxy::class,
140 Analytics_Posts_API_Proxy::class,
141 $wp_cache
142 );
143
144 parsely_run_rest_api_endpoint(
145 Analytics_Post_Detail_Proxy::class,
146 Analytics_Post_Detail_API_Proxy::class,
147 $wp_cache
148 );
149
150 parsely_run_rest_api_endpoint(
151 Referrers_Post_Detail_Proxy::class,
152 Referrers_Post_Detail_API_Proxy::class,
153 $wp_cache
154 );
155 }
156
157 add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' );
158 /**
159 * Registers the Recommendations Block.
160 */
161 function init_recommendations_block(): void {
162 $recommendations_block = new Recommendations_Block();
163 $recommendations_block->run();
164 }
165
166 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\init_content_helper' );
167 /**
168 * Inserts the Content Helper into the WordPress Post Editor.
169 *
170 * @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets()
171 */
172 function init_content_helper(): void {
173 ( new Content_Helper() )->run();
174 }
175
176 add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' );
177 /**
178 * Registers the Parse.ly Recommended widget.
179 */
180 function parsely_recommended_widget_register(): void {
181 register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) );
182 }
183
184 add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' );
185 /**
186 * Instantiates Integrations collection and registers built-in integrations.
187 *
188 * @since 2.6.0
189 *
190 * @param Parsely|string|null $parsely The Parsely object to pass to the integrations.
191 * @return Integrations
192 */
193 function parsely_integrations( $parsely = null ): Integrations {
194 // If $parsely value is "", then this function is being called by the init
195 // hook and we can get the value from $GLOBALS. If $parsely is an instance
196 // of the Parsely object, then this function is being called by a test.
197 if ( empty( $parsely ) || get_class( $parsely ) !== Parsely::class ) {
198 $parsely = $GLOBALS['parsely'];
199 }
200
201 $parsely_integrations = new Integrations( $parsely );
202 $parsely_integrations->register( 'amp', Amp::class );
203 $parsely_integrations->register( 'fbia', Facebook_Instant_Articles::class );
204 $parsely_integrations->register( 'webstories', Google_Web_Stories::class );
205 $parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations );
206 $parsely_integrations->integrate();
207
208 return $parsely_integrations;
209 }
210
211 /**
212 * Instantiates and runs the specified API endpoint.
213 *
214 * @since 3.6.0
215 *
216 * @param string $proxy_class_name The proxy class to instantiate.
217 * @param string $api_proxy_class_name The API proxy class to instantiate and run.
218 * @param WordPress_Cache $wp_cache The WordPress cache instance to be used.
219 */
220 function parsely_run_rest_api_endpoint(
221 string $proxy_class_name,
222 string $api_proxy_class_name,
223 WordPress_Cache &$wp_cache
224 ): void {
225 $proxy_instance = new $proxy_class_name( $GLOBALS['parsely'] );
226 $cached_proxy_instance = new Cached_Proxy( $proxy_instance, $wp_cache );
227 $api_proxy_instance = new $api_proxy_class_name( $GLOBALS['parsely'], $cached_proxy_instance );
228 $api_proxy_instance->run();
229 }
230