PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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
← All changes | src/integrations/admin/installation-success-integration.php +48 -18 18.0 → trunk View file →
@@ -2,13 +2,12 @@
2 2
3 3 namespace Yoast\WP\SEO\Integrations\Admin;
4 4
5 5 use WPSEO_Admin_Asset_Manager;
6 -use WPSEO_Admin_Asset_Yoast_Components_L10n;
7 6 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
8 -use Yoast\WP\SEO\Conditionals\Installation_Success_Conditional;
9 7 use Yoast\WP\SEO\Helpers\Options_Helper;
10 8 use Yoast\WP\SEO\Helpers\Product_Helper;
9 +use Yoast\WP\SEO\Helpers\Short_Link_Helper;
11 10 use Yoast\WP\SEO\Integrations\Integration_Interface;
12 11
13 12 /**
14 13 * Installation_Success_Integration class
@@ -29,23 +28,32 @@
29 28 */
30 29 protected $product_helper;
31 30
32 31 /**
32 + * The shortlinker.
33 + *
34 + * @var Short_Link_Helper
35 + */
36 + private $shortlinker;
37 +
38 + /**
33 39 * {@inheritDoc}
34 40 */
35 41 public static function get_conditionals() {
36 - return [ Admin_Conditional::class, Installation_Success_Conditional::class ];
42 + return [ Admin_Conditional::class ];
37 43 }
38 44
39 45 /**
40 46 * Installation_Success_Integration constructor.
41 47 *
42 - * @param Options_Helper $options_helper The options helper.
43 - * @param Product_Helper $product_helper The product helper.
48 + * @param Options_Helper $options_helper The options helper.
49 + * @param Product_Helper $product_helper The product helper.
50 + * @param Short_Link_Helper $shortlinker The shortlinker.
44 51 */
45 - public function __construct( Options_Helper $options_helper, Product_Helper $product_helper ) {
52 + public function __construct( Options_Helper $options_helper, Product_Helper $product_helper, Short_Link_Helper $shortlinker ) {
46 53 $this->options_helper = $options_helper;
47 54 $this->product_helper = $product_helper;
55 + $this->shortlinker = $shortlinker;
48 56 }
49 57
50 58 /**
51 59 * {@inheritDoc}
@@ -61,8 +69,16 @@
61 69 *
62 70 * @return void
63 71 */
64 72 public function maybe_redirect() {
73 + if ( \wp_doing_ajax() || \wp_doing_cron() || \wp_is_serving_rest_request() || \wp_is_json_request() ) {
74 + return;
75 + }
76 +
77 + if ( ! \current_user_can( 'manage_options' ) ) {
78 + return;
79 + }
80 +
65 81 if ( ! $this->options_helper->get( 'should_redirect_after_install_free', false ) ) {
66 82 return;
67 83 }
68 84 $this->options_helper->set( 'should_redirect_after_install_free', false );
@@ -80,12 +96,21 @@
80 96 if ( $this->product_helper->is_premium() ) {
81 97 return;
82 98 }
83 99
84 - if ( \is_network_admin() || \is_plugin_active_for_network( WPSEO_BASENAME ) ) {
100 + if ( \is_network_admin() || \is_plugin_active_for_network( \WPSEO_BASENAME ) ) {
85 101 return;
86 102 }
87 103
104 + /**
105 + * Filter: 'wpseo_should_redirect_after_install' - Allows skipping the redirect to the installation success page.
106 + *
107 + * @param bool $should_redirect Whether to redirect. Default true.
108 + */
109 + if ( ! \apply_filters( 'wpseo_should_redirect_after_install', true ) ) {
110 + return;
111 + }
112 +
88 113 \wp_safe_redirect( \admin_url( 'admin.php?page=wpseo_installation_successful_free' ), 302, 'Yoast SEO' );
89 114 $this->terminate_execution();
90 115 }
91 116
@@ -97,14 +122,14 @@
97 122 * @return array the filtered submenu pages.
98 123 */
99 124 public function add_submenu_page( $submenu_pages ) {
100 125 \add_submenu_page(
101 - null,
126 + 'options.php',
102 127 \__( 'Installation Successful', 'wordpress-seo' ),
103 - null,
128 + '',
104 129 'manage_options',
105 130 'wpseo_installation_successful_free',
106 - [ $this, 'render_page' ]
131 + [ $this, 'render_page' ],
107 132 );
108 133
109 134 return $submenu_pages;
110 135 }
@@ -110,8 +135,10 @@
110 135 }
111 136
112 137 /**
113 138 * Enqueue assets on the Installation success page.
139 + *
140 + * @return void
114 141 */
115 142 public function enqueue_assets() {
116 143 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
117 144 if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_installation_successful_free' ) {
@@ -122,25 +149,26 @@
122 149 $asset_manager->enqueue_script( 'installation-success' );
123 150 $asset_manager->enqueue_style( 'installation-success' );
124 151 $asset_manager->enqueue_style( 'monorepo' );
125 152
126 - $yoast_components_l10n = new WPSEO_Admin_Asset_Yoast_Components_L10n();
127 - $yoast_components_l10n->localize_script( 'installation-success' );
153 + $ftc_url = \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#/first-time-configuration' ) );
128 154
129 155 $asset_manager->localize_script(
130 156 'installation-success',
131 157 'wpseoInstallationSuccess',
132 158 [
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 - ]
159 + 'pluginUrl' => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
160 + 'firstTimeConfigurationUrl' => $ftc_url,
161 + 'dashboardUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard' ) ),
162 + 'explorePremiumUrl' => $this->shortlinker->build( 'https://yoa.st/ftc-premium-link' ),
163 + ],
138 164 );
139 165 }
140 166
141 167 /**
142 168 * Renders the installation success page.
169 + *
170 + * @return void
143 171 */
144 172 public function render_page() {
145 173 echo '<div id="wpseo-installation-successful-free" class="yoast"></div>';
146 174 }
@@ -146,9 +174,11 @@
146 174 }
147 175
148 176 /**
149 177 * Wrap the `exit` function to make unit testing easier.
178 + *
179 + * @return void
150 180 */
151 181 public function terminate_execution() {
152 - exit;
182 + exit();
153 183 }
154 184 }