PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / academy-integration.php

academy-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at src/integrations/academy-integration.php

184 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations;
4
5 use WPSEO_Addon_Manager;
6 use WPSEO_Admin_Asset_Manager;
7 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
8 use Yoast\WP\SEO\Conditionals\User_Can_Manage_Wpseo_Options_Conditional;
9 use Yoast\WP\SEO\Helpers\Current_Page_Helper;
10 use Yoast\WP\SEO\Helpers\Product_Helper;
11 use Yoast\WP\SEO\Helpers\Short_Link_Helper;
12
13 /**
14 * Class Academy_Integration.
15 */
16 class Academy_Integration implements Integration_Interface {
17
18 public const PAGE = 'wpseo_page_academy';
19
20 /**
21 * Holds the WPSEO_Admin_Asset_Manager.
22 *
23 * @var WPSEO_Admin_Asset_Manager
24 */
25 private $asset_manager;
26
27 /**
28 * Holds the Current_Page_Helper.
29 *
30 * @var Current_Page_Helper
31 */
32 private $current_page_helper;
33
34 /**
35 * Holds the Product_Helper.
36 *
37 * @var Product_Helper
38 */
39 private $product_helper;
40
41 /**
42 * Holds the Short_Link_Helper.
43 *
44 * @var Short_Link_Helper
45 */
46 private $shortlink_helper;
47
48 /**
49 * Constructs Academy_Integration.
50 *
51 * @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager.
52 * @param Current_Page_Helper $current_page_helper The Current_Page_Helper.
53 * @param Product_Helper $product_helper The Product_Helper.
54 * @param Short_Link_Helper $shortlink_helper The Short_Link_Helper.
55 */
56 public function __construct(
57 WPSEO_Admin_Asset_Manager $asset_manager,
58 Current_Page_Helper $current_page_helper,
59 Product_Helper $product_helper,
60 Short_Link_Helper $shortlink_helper
61 ) {
62 $this->asset_manager = $asset_manager;
63 $this->current_page_helper = $current_page_helper;
64 $this->product_helper = $product_helper;
65 $this->shortlink_helper = $shortlink_helper;
66 }
67
68 /**
69 * Returns the conditionals based on which this loadable should be active.
70 *
71 * @return array
72 */
73 public static function get_conditionals() {
74 return [ Admin_Conditional::class, User_Can_Manage_Wpseo_Options_Conditional::class ];
75 }
76
77 /**
78 * Initializes the integration.
79 *
80 * This is the place to register hooks and filters.
81 *
82 * @return void
83 */
84 public function register_hooks() {
85 // Add page.
86 \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
87
88 // Are we on the settings page?
89 if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
90 \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
91 \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
92 }
93 }
94
95 /**
96 * Adds the page.
97 *
98 * @param array $pages The pages.
99 *
100 * @return array The pages.
101 */
102 public function add_page( $pages ) {
103 \array_splice(
104 $pages,
105 3,
106 0,
107 [
108 [
109 'wpseo_dashboard',
110 '',
111 \__( 'Academy', 'wordpress-seo' ),
112 'wpseo_manage_options',
113 self::PAGE,
114 [ $this, 'display_page' ],
115 ],
116 ],
117 );
118
119 return $pages;
120 }
121
122 /**
123 * Displays the page.
124 *
125 * @return void
126 */
127 public function display_page() {
128 echo '<div id="yoast-seo-academy"></div>';
129 }
130
131 /**
132 * Enqueues the assets.
133 *
134 * @return void
135 */
136 public function enqueue_assets() {
137 // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
138 \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
139 \wp_enqueue_media();
140 $this->asset_manager->enqueue_script( 'academy' );
141 $this->asset_manager->enqueue_style( 'academy' );
142 $this->asset_manager->localize_script( 'academy', 'wpseoScriptData', $this->get_script_data() );
143 }
144
145 /**
146 * Removes all current WP notices.
147 *
148 * @return void
149 */
150 public function remove_notices() {
151 \remove_all_actions( 'admin_notices' );
152 \remove_all_actions( 'user_admin_notices' );
153 \remove_all_actions( 'network_admin_notices' );
154 \remove_all_actions( 'all_admin_notices' );
155 }
156
157 /**
158 * Creates the script data.
159 *
160 * @return array The script data.
161 */
162 public function get_script_data() {
163 $addon_manager = new WPSEO_Addon_Manager();
164
165 $woocommerce_seo_active = $addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG );
166 $local_seo_active = $addon_manager->is_installed( WPSEO_Addon_Manager::LOCAL_SLUG );
167
168 return [
169 'preferences' => [
170 'isPremium' => $this->product_helper->is_premium(),
171 'isWooActive' => $woocommerce_seo_active,
172 'isLocalActive' => $local_seo_active,
173 'isRtl' => \is_rtl(),
174 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
175 'upsellSettings' => [
176 'actionId' => 'load-nfd-ctb',
177 'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
178 ],
179 ],
180 'linkParams' => $this->shortlink_helper->get_query_params(),
181 ];
182 }
183 }
184