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 +47 -13 18.8 → trunk View file →
@@ -3,11 +3,11 @@
3 3 namespace Yoast\WP\SEO\Integrations\Admin;
4 4
5 5 use WPSEO_Admin_Asset_Manager;
6 6 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7 -use Yoast\WP\SEO\Conditionals\Installation_Success_Conditional;
8 7 use Yoast\WP\SEO\Helpers\Options_Helper;
9 8 use Yoast\WP\SEO\Helpers\Product_Helper;
9 +use Yoast\WP\SEO\Helpers\Short_Link_Helper;
10 10 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 11
12 12 /**
13 13 * Installation_Success_Integration class
@@ -28,23 +28,32 @@
28 28 */
29 29 protected $product_helper;
30 30
31 31 /**
32 + * The shortlinker.
33 + *
34 + * @var Short_Link_Helper
35 + */
36 + private $shortlinker;
37 +
38 + /**
32 39 * {@inheritDoc}
33 40 */
34 41 public static function get_conditionals() {
35 - return [ Admin_Conditional::class, Installation_Success_Conditional::class ];
42 + return [ Admin_Conditional::class ];
36 43 }
37 44
38 45 /**
39 46 * Installation_Success_Integration constructor.
40 47 *
41 - * @param Options_Helper $options_helper The options helper.
42 - * @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.
43 51 */
44 - 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 ) {
45 53 $this->options_helper = $options_helper;
46 54 $this->product_helper = $product_helper;
55 + $this->shortlinker = $shortlinker;
47 56 }
48 57
49 58 /**
50 59 * {@inheritDoc}
@@ -60,8 +69,16 @@
60 69 *
61 70 * @return void
62 71 */
63 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 +
64 81 if ( ! $this->options_helper->get( 'should_redirect_after_install_free', false ) ) {
65 82 return;
66 83 }
67 84 $this->options_helper->set( 'should_redirect_after_install_free', false );
@@ -83,8 +100,17 @@
83 100 if ( \is_network_admin() || \is_plugin_active_for_network( \WPSEO_BASENAME ) ) {
84 101 return;
85 102 }
86 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 +
87 113 \wp_safe_redirect( \admin_url( 'admin.php?page=wpseo_installation_successful_free' ), 302, 'Yoast SEO' );
88 114 $this->terminate_execution();
89 115 }
90 116
@@ -96,14 +122,14 @@
96 122 * @return array the filtered submenu pages.
97 123 */
98 124 public function add_submenu_page( $submenu_pages ) {
99 125 \add_submenu_page(
100 - null,
126 + 'options.php',
101 127 \__( 'Installation Successful', 'wordpress-seo' ),
102 - null,
128 + '',
103 129 'manage_options',
104 130 'wpseo_installation_successful_free',
105 - [ $this, 'render_page' ]
131 + [ $this, 'render_page' ],
106 132 );
107 133
108 134 return $submenu_pages;
109 135 }
@@ -109,8 +135,10 @@
109 135 }
110 136
111 137 /**
112 138 * Enqueue assets on the Installation success page.
139 + *
140 + * @return void
113 141 */
114 142 public function enqueue_assets() {
115 143 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
116 144 if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_installation_successful_free' ) {
@@ -121,22 +149,26 @@
121 149 $asset_manager->enqueue_script( 'installation-success' );
122 150 $asset_manager->enqueue_style( 'installation-success' );
123 151 $asset_manager->enqueue_style( 'monorepo' );
124 152
153 + $ftc_url = \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#/first-time-configuration' ) );
154 +
125 155 $asset_manager->localize_script(
126 156 'installation-success',
127 157 'wpseoInstallationSuccess',
128 158 [
129 159 'pluginUrl' => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
130 - 'configurationWorkoutUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_workouts#configuration' ) ),
131 - 'canDoConfigurationWorkout' => \current_user_can( 'wpseo_manage_options' ),
132 - 'canEditWordPressOptions' => \current_user_can( 'manage_options' ),
133 - ]
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 + ],
134 164 );
135 165 }
136 166
137 167 /**
138 168 * Renders the installation success page.
169 + *
170 + * @return void
139 171 */
140 172 public function render_page() {
141 173 echo '<div id="wpseo-installation-successful-free" class="yoast"></div>';
142 174 }
@@ -142,9 +174,11 @@
142 174 }
143 175
144 176 /**
145 177 * Wrap the `exit` function to make unit testing easier.
178 + *
179 + * @return void
146 180 */
147 181 public function terminate_execution() {
148 - exit;
182 + exit();
149 183 }
150 184 }