PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 28.3, at src/integrations/academy-integration.php

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