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