PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
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 / admin / installation-success-integration.php

installation-success-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at src/integrations/admin/installation-success-integration.php

150 lines 4.0 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\Admin;
4
5 use WPSEO_Admin_Asset_Manager;
6 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7 use Yoast\WP\SEO\Helpers\Options_Helper;
8 use Yoast\WP\SEO\Helpers\Product_Helper;
9 use Yoast\WP\SEO\Integrations\Integration_Interface;
10
11 /**
12 * Installation_Success_Integration class
13 */
14 class Installation_Success_Integration implements Integration_Interface {
15
16 /**
17 * The options helper.
18 *
19 * @var Options_Helper
20 */
21 protected $options_helper;
22
23 /**
24 * The product helper.
25 *
26 * @var Product_Helper
27 */
28 protected $product_helper;
29
30 /**
31 * {@inheritDoc}
32 */
33 public static function get_conditionals() {
34 return [ Admin_Conditional::class ];
35 }
36
37 /**
38 * Installation_Success_Integration constructor.
39 *
40 * @param Options_Helper $options_helper The options helper.
41 * @param Product_Helper $product_helper The product helper.
42 */
43 public function __construct( Options_Helper $options_helper, Product_Helper $product_helper ) {
44 $this->options_helper = $options_helper;
45 $this->product_helper = $product_helper;
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public function register_hooks() {
52 \add_filter( 'admin_menu', [ $this, 'add_submenu_page' ], 9 );
53 \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
54 \add_action( 'admin_init', [ $this, 'maybe_redirect' ] );
55 }
56
57 /**
58 * Redirects to the installation success page if an installation has just occurred.
59 *
60 * @return void
61 */
62 public function maybe_redirect() {
63 if ( ! $this->options_helper->get( 'should_redirect_after_install_free', false ) ) {
64 return;
65 }
66 $this->options_helper->set( 'should_redirect_after_install_free', false );
67
68 if ( ! empty( $this->options_helper->get( 'activation_redirect_timestamp_free', 0 ) ) ) {
69 return;
70 }
71 $this->options_helper->set( 'activation_redirect_timestamp_free', \time() );
72
73 // phpcs:ignore WordPress.Security.NonceVerification -- This is not a form.
74 if ( isset( $_REQUEST['activate-multi'] ) && $_REQUEST['activate-multi'] === 'true' ) {
75 return;
76 }
77
78 if ( $this->product_helper->is_premium() ) {
79 return;
80 }
81
82 if ( \is_network_admin() || \is_plugin_active_for_network( \WPSEO_BASENAME ) ) {
83 return;
84 }
85
86 \wp_safe_redirect( \admin_url( 'admin.php?page=wpseo_installation_successful_free' ), 302, 'Yoast SEO' );
87 $this->terminate_execution();
88 }
89
90 /**
91 * Adds the installation success submenu page.
92 *
93 * @param array $submenu_pages The Yoast SEO submenu pages.
94 *
95 * @return array the filtered submenu pages.
96 */
97 public function add_submenu_page( $submenu_pages ) {
98 \add_submenu_page(
99 null,
100 \__( 'Installation Successful', 'wordpress-seo' ),
101 null,
102 'manage_options',
103 'wpseo_installation_successful_free',
104 [ $this, 'render_page' ]
105 );
106
107 return $submenu_pages;
108 }
109
110 /**
111 * Enqueue assets on the Installation success page.
112 */
113 public function enqueue_assets() {
114 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
115 if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_installation_successful_free' ) {
116 return;
117 }
118
119 $asset_manager = new WPSEO_Admin_Asset_Manager();
120 $asset_manager->enqueue_script( 'installation-success' );
121 $asset_manager->enqueue_style( 'tailwind' );
122 $asset_manager->enqueue_style( 'monorepo' );
123
124 $asset_manager->localize_script(
125 'installation-success',
126 'wpseoInstallationSuccess',
127 [
128 'pluginUrl' => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
129 'configurationWorkoutUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ),
130 'canDoConfigurationWorkout' => \current_user_can( 'wpseo_manage_options' ),
131 'canEditWordPressOptions' => \current_user_can( 'manage_options' ),
132 ]
133 );
134 }
135
136 /**
137 * Renders the installation success page.
138 */
139 public function render_page() {
140 echo '<div id="wpseo-installation-successful-free" class="yoast"></div>';
141 }
142
143 /**
144 * Wrap the `exit` function to make unit testing easier.
145 */
146 public function terminate_execution() {
147 exit;
148 }
149 }
150