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