| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\General\User_Interface; |
| 4 |
|
| 5 |
use WPSEO_Addon_Manager; |
| 6 |
use WPSEO_Admin_Asset_Manager; |
| 7 |
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; |
| 8 |
use Yoast\WP\SEO\Conditionals\Admin\Non_Network_Admin_Conditional; |
| 9 |
use Yoast\WP\SEO\Conditionals\Admin_Conditional; |
| 10 |
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; |
| 11 |
use Yoast\WP\SEO\Dashboard\Application\Configuration\Dashboard_Configuration; |
| 12 |
use Yoast\WP\SEO\Helpers\Current_Page_Helper; |
| 13 |
use Yoast\WP\SEO\Helpers\Notification_Helper; |
| 14 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 15 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 16 |
use Yoast\WP\SEO\Helpers\Short_Link_Helper; |
| 17 |
use Yoast\WP\SEO\Helpers\User_Helper; |
| 18 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 19 |
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager; |
| 20 |
use Yoast\WP\SEO\Task_List\Application\Configuration\Task_List_Configuration; |
| 21 |
|
| 22 |
/** |
| 23 |
* Class General_Page_Integration. |
| 24 |
*/ |
| 25 |
class General_Page_Integration implements Integration_Interface { |
| 26 |
|
| 27 |
/** |
| 28 |
* The page name. |
| 29 |
*/ |
| 30 |
public const PAGE = 'wpseo_dashboard'; |
| 31 |
|
| 32 |
/** |
| 33 |
* The notification helper. |
| 34 |
* |
| 35 |
* @var Notification_Helper |
| 36 |
*/ |
| 37 |
protected $notification_helper; |
| 38 |
|
| 39 |
/** |
| 40 |
* The dashboard configuration. |
| 41 |
* |
| 42 |
* @var Dashboard_Configuration |
| 43 |
*/ |
| 44 |
private $dashboard_configuration; |
| 45 |
|
| 46 |
/** |
| 47 |
* The task list configuration. |
| 48 |
* |
| 49 |
* @var Task_List_Configuration |
| 50 |
*/ |
| 51 |
private $task_list_configuration; |
| 52 |
|
| 53 |
/** |
| 54 |
* Holds the WPSEO_Admin_Asset_Manager. |
| 55 |
* |
| 56 |
* @var WPSEO_Admin_Asset_Manager |
| 57 |
*/ |
| 58 |
private $asset_manager; |
| 59 |
|
| 60 |
/** |
| 61 |
* Holds the Current_Page_Helper. |
| 62 |
* |
| 63 |
* @var Current_Page_Helper |
| 64 |
*/ |
| 65 |
private $current_page_helper; |
| 66 |
|
| 67 |
/** |
| 68 |
* Holds the Product_Helper. |
| 69 |
* |
| 70 |
* @var Product_Helper |
| 71 |
*/ |
| 72 |
private $product_helper; |
| 73 |
|
| 74 |
/** |
| 75 |
* Holds the Short_Link_Helper. |
| 76 |
* |
| 77 |
* @var Short_Link_Helper |
| 78 |
*/ |
| 79 |
private $shortlink_helper; |
| 80 |
|
| 81 |
/** |
| 82 |
* The promotion manager. |
| 83 |
* |
| 84 |
* @var Promotion_Manager |
| 85 |
*/ |
| 86 |
private $promotion_manager; |
| 87 |
|
| 88 |
/** |
| 89 |
* The alert dismissal action. |
| 90 |
* |
| 91 |
* @var Alert_Dismissal_Action |
| 92 |
*/ |
| 93 |
private $alert_dismissal_action; |
| 94 |
|
| 95 |
/** |
| 96 |
* Holds the user helper. |
| 97 |
* |
| 98 |
* @var User_Helper |
| 99 |
*/ |
| 100 |
private $user_helper; |
| 101 |
|
| 102 |
/** |
| 103 |
* Holds the options helper. |
| 104 |
* |
| 105 |
* @var Options_Helper |
| 106 |
*/ |
| 107 |
private $options_helper; |
| 108 |
|
| 109 |
/** |
| 110 |
* Holds the WooCommerce conditional. |
| 111 |
* |
| 112 |
* @var WooCommerce_Conditional |
| 113 |
*/ |
| 114 |
private $woocommerce_conditional; |
| 115 |
|
| 116 |
/** |
| 117 |
* Holds the WPSEO_Addon_Manager. |
| 118 |
* |
| 119 |
* @var WPSEO_Addon_Manager |
| 120 |
*/ |
| 121 |
private $addon_manager; |
| 122 |
|
| 123 |
/** |
| 124 |
* Constructs Academy_Integration. |
| 125 |
* |
| 126 |
* @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager. |
| 127 |
* @param Current_Page_Helper $current_page_helper The Current_Page_Helper. |
| 128 |
* @param Product_Helper $product_helper The Product_Helper. |
| 129 |
* @param Short_Link_Helper $shortlink_helper The Short_Link_Helper. |
| 130 |
* @param Notification_Helper $notification_helper The Notification_Helper. |
| 131 |
* @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. |
| 132 |
* @param Promotion_Manager $promotion_manager The promotion manager. |
| 133 |
* @param Dashboard_Configuration $dashboard_configuration The dashboard configuration. |
| 134 |
* @param User_Helper $user_helper The user helper. |
| 135 |
* @param Options_Helper $options_helper The options helper. |
| 136 |
* @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional. |
| 137 |
* @param WPSEO_Addon_Manager $addon_manager The WPSEO_Addon_Manager. |
| 138 |
* @param Task_List_Configuration $task_list_configuration The task list configuration. |
| 139 |
*/ |
| 140 |
public function __construct( |
| 141 |
WPSEO_Admin_Asset_Manager $asset_manager, |
| 142 |
Current_Page_Helper $current_page_helper, |
| 143 |
Product_Helper $product_helper, |
| 144 |
Short_Link_Helper $shortlink_helper, |
| 145 |
Notification_Helper $notification_helper, |
| 146 |
Alert_Dismissal_Action $alert_dismissal_action, |
| 147 |
Promotion_Manager $promotion_manager, |
| 148 |
Dashboard_Configuration $dashboard_configuration, |
| 149 |
User_Helper $user_helper, |
| 150 |
Options_Helper $options_helper, |
| 151 |
WooCommerce_Conditional $woocommerce_conditional, |
| 152 |
WPSEO_Addon_Manager $addon_manager, |
| 153 |
Task_List_Configuration $task_list_configuration |
| 154 |
) { |
| 155 |
$this->asset_manager = $asset_manager; |
| 156 |
$this->current_page_helper = $current_page_helper; |
| 157 |
$this->product_helper = $product_helper; |
| 158 |
$this->shortlink_helper = $shortlink_helper; |
| 159 |
$this->notification_helper = $notification_helper; |
| 160 |
$this->alert_dismissal_action = $alert_dismissal_action; |
| 161 |
$this->promotion_manager = $promotion_manager; |
| 162 |
$this->dashboard_configuration = $dashboard_configuration; |
| 163 |
$this->user_helper = $user_helper; |
| 164 |
$this->options_helper = $options_helper; |
| 165 |
$this->woocommerce_conditional = $woocommerce_conditional; |
| 166 |
$this->addon_manager = $addon_manager; |
| 167 |
$this->task_list_configuration = $task_list_configuration; |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Returns the conditionals based on which this loadable should be active. |
| 172 |
* |
| 173 |
* @return array<string> |
| 174 |
*/ |
| 175 |
public static function get_conditionals() { |
| 176 |
return [ Admin_Conditional::class, Non_Network_Admin_Conditional::class ]; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Initializes the integration. |
| 181 |
* |
| 182 |
* This is the place to register hooks and filters. |
| 183 |
* |
| 184 |
* @return void |
| 185 |
*/ |
| 186 |
public function register_hooks() { |
| 187 |
|
| 188 |
// Add page. |
| 189 |
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] ); |
| 190 |
|
| 191 |
// Are we on the dashboard page? |
| 192 |
if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) { |
| 193 |
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Adds the page. |
| 199 |
* |
| 200 |
* @param array<string, array<string>> $pages The pages. |
| 201 |
* |
| 202 |
* @return array<string, array<string>> The pages. |
| 203 |
*/ |
| 204 |
public function add_page( $pages ) { |
| 205 |
\array_splice( |
| 206 |
$pages, |
| 207 |
0, |
| 208 |
0, |
| 209 |
[ |
| 210 |
[ |
| 211 |
self::PAGE, |
| 212 |
'', |
| 213 |
\__( 'General', 'wordpress-seo' ), |
| 214 |
'wpseo_manage_options', |
| 215 |
self::PAGE, |
| 216 |
[ $this, 'display_page' ], |
| 217 |
], |
| 218 |
], |
| 219 |
); |
| 220 |
|
| 221 |
return $pages; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Displays the page. |
| 226 |
* |
| 227 |
* @return void |
| 228 |
*/ |
| 229 |
public function display_page() { |
| 230 |
echo '<div id="yoast-seo-general"></div>'; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Enqueues the assets. |
| 235 |
* |
| 236 |
* @return void |
| 237 |
*/ |
| 238 |
public function enqueue_assets() { |
| 239 |
// Remove the emoji script as it is incompatible with both React and any contenteditable fields. |
| 240 |
\remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
| 241 |
\wp_enqueue_media(); |
| 242 |
$this->asset_manager->enqueue_script( 'general-page' ); |
| 243 |
$this->asset_manager->enqueue_style( 'general-page' ); |
| 244 |
if ( $this->promotion_manager->is( 'black-friday-promotion' ) ) { |
| 245 |
$this->asset_manager->enqueue_style( 'black-friday-banner' ); |
| 246 |
} |
| 247 |
$this->asset_manager->localize_script( 'general-page', 'wpseoScriptData', $this->get_script_data() ); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Creates the script data. |
| 252 |
* |
| 253 |
* @return array The script data. |
| 254 |
*/ |
| 255 |
private function get_script_data() { |
| 256 |
return [ |
| 257 |
'preferences' => [ |
| 258 |
'isPremium' => $this->product_helper->is_premium(), |
| 259 |
'isRtl' => \is_rtl(), |
| 260 |
'userLocale' => \get_user_locale(), |
| 261 |
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), |
| 262 |
'upsellSettings' => [ |
| 263 |
'actionId' => 'load-nfd-ctb', |
| 264 |
'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2', |
| 265 |
], |
| 266 |
'llmTxtEnabled' => $this->options_helper->get( 'enable_llms_txt', true ), |
| 267 |
'isWooCommerceActive' => $this->woocommerce_conditional->is_met(), |
| 268 |
'addonsStatus' => [ |
| 269 |
'isWooSeoActive' => \is_plugin_active( $this->addon_manager->get_plugin_file( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ), |
| 270 |
'isLocalSEOActive' => \is_plugin_active( $this->addon_manager->get_plugin_file( WPSEO_Addon_Manager::LOCAL_SLUG ) ), |
| 271 |
'isNewsSEOActive' => \is_plugin_active( $this->addon_manager->get_plugin_file( WPSEO_Addon_Manager::NEWS_SLUG ) ), |
| 272 |
'isVideoSEOActive' => \is_plugin_active( $this->addon_manager->get_plugin_file( WPSEO_Addon_Manager::VIDEO_SLUG ) ), |
| 273 |
'isDuplicatePostActive' => \defined( 'DUPLICATE_POST_FILE' ), |
| 274 |
], |
| 275 |
], |
| 276 |
'adminUrl' => \admin_url( 'admin.php' ), |
| 277 |
'linkParams' => $this->shortlink_helper->get_query_params(), |
| 278 |
'userEditUrl' => \add_query_arg( 'user_id', '{user_id}', \admin_url( 'user-edit.php' ) ), |
| 279 |
'alerts' => $this->notification_helper->get_alerts(), |
| 280 |
'currentPromotions' => $this->promotion_manager->get_current_promotions(), |
| 281 |
'dismissedAlerts' => $this->alert_dismissal_action->all_dismissed(), |
| 282 |
'dashboard' => $this->dashboard_configuration->get_configuration(), |
| 283 |
'optInNotificationSeen' => [ |
| 284 |
'task_list' => $this->is_task_list_opt_in_notification_seen(), |
| 285 |
], |
| 286 |
'taskListConfiguration' => $this->task_list_configuration->get_configuration(), |
| 287 |
]; |
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Gets if the llms.txt opt-in notification has been seen. |
| 292 |
* |
| 293 |
* @return bool True if the notification has been seen, false otherwise. |
| 294 |
*/ |
| 295 |
private function is_task_list_opt_in_notification_seen(): bool { |
| 296 |
$current_user_id = $this->user_helper->get_current_user_id(); |
| 297 |
return (bool) $this->user_helper->get_meta( $current_user_id, '_yoast_wpseo_task_list_opt_in_notification_seen', true ); |
| 298 |
} |
| 299 |
} |
| 300 |
|