| 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.18.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.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_Suggestions; |
| 32 |
use Parsely\Content_Helper\Post_List_Stats; |
| 33 |
use Parsely\Endpoints\GraphQL_Metadata; |
| 34 |
use Parsely\Endpoints\Rest_Metadata; |
| 35 |
use Parsely\Integrations\Amp; |
| 36 |
use Parsely\Integrations\Google_Web_Stories; |
| 37 |
use Parsely\Integrations\Integrations; |
| 38 |
use Parsely\REST_API\REST_API_Controller; |
| 39 |
use Parsely\UI\Admin_Bar; |
| 40 |
use Parsely\UI\Admin_Warning; |
| 41 |
use Parsely\UI\Metadata_Renderer; |
| 42 |
use Parsely\UI\Network_Admin_Sites_List; |
| 43 |
use Parsely\UI\Plugins_Actions; |
| 44 |
use Parsely\UI\Recommended_Widget; |
| 45 |
use Parsely\UI\Row_Actions; |
| 46 |
use Parsely\UI\Settings_Page; |
| 47 |
use Parsely\UI\Site_Health; |
| 48 |
|
| 49 |
if ( class_exists( Parsely::class ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
const PARSELY_VERSION = '3.18.1'; |
| 54 |
const PARSELY_FILE = __FILE__; |
| 55 |
|
| 56 |
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 57 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 58 |
} |
| 59 |
|
| 60 |
// Load Telemetry classes. |
| 61 |
require_once __DIR__ . '/src/Telemetry/telemetry-init.php'; |
| 62 |
|
| 63 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' ); |
| 64 |
/** |
| 65 |
* Registers the basic classes to initialize the plugin. |
| 66 |
*/ |
| 67 |
function parsely_initialize_plugin(): void { |
| 68 |
$GLOBALS['parsely'] = new Parsely(); |
| 69 |
$GLOBALS['parsely']->run(); |
| 70 |
|
| 71 |
if ( class_exists( 'WPGraphQL' ) ) { |
| 72 |
$graphql = new GraphQL_Metadata( $GLOBALS['parsely'] ); |
| 73 |
$graphql->run(); |
| 74 |
} |
| 75 |
|
| 76 |
$scripts = new Scripts( $GLOBALS['parsely'] ); |
| 77 |
$scripts->run(); |
| 78 |
|
| 79 |
$admin_bar = new Admin_Bar( $GLOBALS['parsely'] ); |
| 80 |
$admin_bar->run(); |
| 81 |
|
| 82 |
$metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] ); |
| 83 |
$metadata_renderer->run(); |
| 84 |
} |
| 85 |
|
| 86 |
add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' ); |
| 87 |
/** |
| 88 |
* Registers the Parse.ly wp-admin warnings, plugin actions and row actions. |
| 89 |
*/ |
| 90 |
function parsely_admin_init_register(): void { |
| 91 |
$parsely = $GLOBALS['parsely']; |
| 92 |
|
| 93 |
( new Admin_Warning( $parsely ) )->run(); |
| 94 |
( new Plugins_Actions() )->run(); |
| 95 |
( new Row_Actions( $parsely ) )->run(); |
| 96 |
( new Post_List_Stats( $parsely ) )->run(); |
| 97 |
( new Site_Health( $parsely ) )->run(); |
| 98 |
( new Dashboard_Widget( $parsely ) )->run(); |
| 99 |
} |
| 100 |
|
| 101 |
add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' ); |
| 102 |
/** |
| 103 |
* Registers the additions the Parse.ly wp-admin settings page and Multisite |
| 104 |
* Network Admin Sites List table. |
| 105 |
*/ |
| 106 |
function parsely_wp_admin_early_register(): void { |
| 107 |
$GLOBALS['parsely_settings_page'] = new Settings_Page( $GLOBALS['parsely'] ); |
| 108 |
$GLOBALS['parsely_settings_page']->run(); |
| 109 |
|
| 110 |
$network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] ); |
| 111 |
$network_admin_sites_list->run(); |
| 112 |
|
| 113 |
// Initialize the REST API Controller. |
| 114 |
$rest_api_controller = $GLOBALS['parsely']->get_rest_api_controller(); |
| 115 |
$rest_api_controller->init(); |
| 116 |
} |
| 117 |
|
| 118 |
add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' ); |
| 119 |
/** |
| 120 |
* Registers REST Endpoints that act as a proxy to the Parse.ly API. |
| 121 |
* This is needed to get around CORS issues with Firefox. |
| 122 |
* |
| 123 |
* @since 3.2.0 |
| 124 |
*/ |
| 125 |
function parsely_rest_api_init(): void { |
| 126 |
$rest = new Rest_Metadata( $GLOBALS['parsely'] ); |
| 127 |
$rest->run(); |
| 128 |
} |
| 129 |
|
| 130 |
add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' ); |
| 131 |
/** |
| 132 |
* Registers the Recommendations Block. |
| 133 |
*/ |
| 134 |
function init_recommendations_block(): void { |
| 135 |
$recommendations_block = new Recommendations_Block(); |
| 136 |
$recommendations_block->run(); |
| 137 |
} |
| 138 |
|
| 139 |
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' ); |
| 140 |
/** |
| 141 |
* Inserts the PCH Editor Sidebar. |
| 142 |
* |
| 143 |
* @since 3.5.0 Moved from Parsely\Scripts\enqueue_block_editor_assets(). |
| 144 |
* @since 3.9.0 Renamed from init_content_helper(). |
| 145 |
*/ |
| 146 |
function init_content_helper_editor_sidebar(): void { |
| 147 |
$GLOBALS['parsely_editor_sidebar']->run(); |
| 148 |
} |
| 149 |
|
| 150 |
add_action( 'admin_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); |
| 151 |
add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); |
| 152 |
/** |
| 153 |
* Initializes the PCH Editor Sidebar features. |
| 154 |
* |
| 155 |
* @since 3.16.0 |
| 156 |
*/ |
| 157 |
function parsely_content_helper_editor_sidebar_features(): void { |
| 158 |
if ( ! isset( $GLOBALS['parsely_editor_sidebar'] ) ) { |
| 159 |
/** |
| 160 |
* The Editor Sidebar instance. |
| 161 |
* |
| 162 |
* @since 3.16.0 |
| 163 |
* @var Editor_Sidebar $GLOBALS['parsely_editor_sidebar'] |
| 164 |
*/ |
| 165 |
$GLOBALS['parsely_editor_sidebar'] = new Editor_Sidebar( $GLOBALS['parsely'] ); |
| 166 |
$GLOBALS['parsely_editor_sidebar']->init_features(); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' ); |
| 171 |
/** |
| 172 |
* Registers the Parse.ly Recommended widget. |
| 173 |
*/ |
| 174 |
function parsely_recommended_widget_register(): void { |
| 175 |
register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) ); |
| 176 |
} |
| 177 |
|
| 178 |
add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line |
| 179 |
/** |
| 180 |
* Instantiates Integrations collection and registers built-in integrations. |
| 181 |
* |
| 182 |
* @since 2.6.0 |
| 183 |
* |
| 184 |
* @param Parsely|string|null $parsely The Parsely object to pass to the integrations. |
| 185 |
* @return Integrations |
| 186 |
*/ |
| 187 |
function parsely_integrations( $parsely = null ): Integrations { |
| 188 |
// If $parsely value is "", then this function is being called by the init |
| 189 |
// hook and we can get the value from $GLOBALS. If $parsely is an instance |
| 190 |
// of the Parsely object, then this function is being called by a test. |
| 191 |
if ( ! is_object( $parsely ) || get_class( $parsely ) !== Parsely::class ) { |
| 192 |
$parsely = $GLOBALS['parsely']; |
| 193 |
} |
| 194 |
|
| 195 |
$parsely_integrations = new Integrations( $parsely ); |
| 196 |
$parsely_integrations->register( 'amp', Amp::class ); |
| 197 |
$parsely_integrations->register( 'webstories', Google_Web_Stories::class ); |
| 198 |
$parsely_integrations = apply_filters( 'wp_parsely_add_integration', $parsely_integrations ); |
| 199 |
$parsely_integrations->integrate(); |
| 200 |
|
| 201 |
return $parsely_integrations; |
| 202 |
} |
| 203 |
|