PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.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 18.0, at src/integrations/admin/installation-success-integration.php

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