PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.7.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.7.4
3.4.6 3.4.5 3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 All 199 releases
← All changes | admin/class-convertkit-admin-setup-wizard.php +65 -34 2.2.1 → 2.7.4 View file →
@@ -64,8 +64,18 @@
64 64 */
65 65 public $page_name = false;
66 66
67 67 /**
68 + * Whether the wizard is being served within a modal or
69 + * new window.
70 + *
71 + * @since 2.2.6
72 + *
73 + * @var bool
74 + */
75 + public $is_modal = false;
76 +
77 + /**
68 78 * The URL to take the user to when they click the Exit link.
69 79 *
70 80 * @since 1.9.8.4
71 81 *
@@ -113,38 +123,27 @@
113 123 }
114 124
115 125 // Define actions to register the setup screen.
116 126 add_action( 'admin_menu', array( $this, 'register_screen' ) );
117 - add_action( 'admin_head', array( $this, 'hide_screen_from_menu' ) );
118 127 add_action( 'admin_init', array( $this, 'maybe_load_setup_screen' ) );
119 128
120 129 }
121 130
122 131 /**
123 - * Register the setup screen in WordPress' Dashboard, so that index.php?page={$this->page_name}
132 + * Register the wizard screen in WordPress' Dashboard, so that options.php?page={$this->page_name}
124 133 * does not 404 when in the WordPress Admin interface.
125 134 *
135 + * Ensures the WordPress user has the given required_capability to access this screen.
136 + *
126 137 * @since 1.9.8.4
127 138 */
128 139 public function register_screen() {
129 140
130 - add_dashboard_page( '', '', 'edit_posts', $this->page_name, '__return_false' );
141 + add_submenu_page( '', '', '', $this->required_capability, $this->page_name, '__return_false' );
131 142
132 143 }
133 144
134 145 /**
135 - * Hides the menu registered when register_screen() above is called, otherwise
136 - * we would have a blank submenu entry below the Dashboard menu.
137 - *
138 - * @since 1.9.8.4
139 - */
140 - public function hide_screen_from_menu() {
141 -
142 - remove_submenu_page( 'index.php', $this->page_name );
143 -
144 - }
145 -
146 - /**
147 146 * Loads the setup screen if the request URL is for this class
148 147 *
149 148 * @since 1.9.8.4
150 149 */
@@ -163,8 +162,14 @@
163 162
164 163 // Define current screen, so that calls to get_current_screen() tell Plugins which screen is loaded.
165 164 set_current_screen( $this->page_name );
166 165
166 + // If the convertkit-modal parameter exists and is 1, set the flag to denote
167 + // this wizard is served in a modal.
168 + if ( array_key_exists( 'convertkit-modal', $_REQUEST ) && $_REQUEST['convertkit-modal'] === '1' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
169 + $this->is_modal = true;
170 + }
171 +
167 172 // Define the step the user is on in the setup process.
168 173 $this->step = ( isset( $_REQUEST['step'] ) ? absint( $_REQUEST['step'] ) : 1 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
169 174
170 175 // Process any posted form data.
@@ -194,17 +199,8 @@
194 199 * @since 1.9.8.4
195 200 */
196 201 private function process_form() {
197 202
198 - // Run security checks.
199 - if ( ! isset( $_POST['_wpnonce'] ) ) {
200 - return;
201 - }
202 - if ( ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), $this->page_name ) ) {
203 - $this->error = __( 'Invalid nonce specified.', 'convertkit' );
204 - return;
205 - }
206 -
207 203 /**
208 204 * Process submitted form data for the given setup wizard name and current step.
209 205 *
210 206 * @since 1.9.8.4
@@ -226,12 +222,13 @@
226 222
227 223 // Define the current step URL.
228 224 $this->current_step_url = add_query_arg(
229 225 array(
230 - 'page' => $this->page_name,
231 - 'step' => $this->step,
226 + 'page' => $this->page_name,
227 + 'convertkit-modal' => $this->is_modal(),
228 + 'step' => $this->step,
232 229 ),
233 - admin_url( 'index.php' )
230 + admin_url( 'options.php' )
234 231 );
235 232
236 233 // Define the previous step URL if we're not on the first or last step.
237 234 if ( $this->step > 1 && $this->step < count( $this->steps ) ) {
@@ -236,12 +233,13 @@
236 233 // Define the previous step URL if we're not on the first or last step.
237 234 if ( $this->step > 1 && $this->step < count( $this->steps ) ) {
238 235 $this->previous_step_url = add_query_arg(
239 236 array(
240 - 'page' => $this->page_name,
241 - 'step' => ( $this->step - 1 ),
237 + 'page' => $this->page_name,
238 + 'convertkit-modal' => $this->is_modal(),
239 + 'step' => ( $this->step - 1 ),
242 240 ),
243 - admin_url( 'index.php' )
241 + admin_url( 'options.php' )
244 242 );
245 243 }
246 244
247 245 // Define the next step URL if we're not on the last page.
@@ -247,12 +245,13 @@
247 245 // Define the next step URL if we're not on the last page.
248 246 if ( $this->step < count( $this->steps ) ) {
249 247 $this->next_step_url = add_query_arg(
250 248 array(
251 - 'page' => $this->page_name,
252 - 'step' => ( $this->step + 1 ),
249 + 'page' => $this->page_name,
250 + 'convertkit-modal' => $this->is_modal(),
251 + 'step' => ( $this->step + 1 ),
253 252 ),
254 - admin_url( 'index.php' )
253 + admin_url( 'options.php' )
255 254 );
256 255 }
257 256
258 257 }
@@ -286,9 +285,9 @@
286 285 convertkit_select2_enqueue_scripts();
287 286
288 287 // Enqueue JS.
289 288 wp_enqueue_script( 'convertkit-admin-preview-output', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/preview-output.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
290 - wp_enqueue_script( 'convertkit-admin-setup-wizard', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/setup-wizard.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
289 + wp_enqueue_script( 'convertkit-admin-setup-wizard', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/setup-wizard.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
291 290
292 291 }
293 292
294 293 /**
@@ -353,8 +352,40 @@
353 352 do_action( 'admin_print_footer_scripts' );
354 353
355 354 // Load footer view.
356 355 include_once CONVERTKIT_PLUGIN_PATH . '/views/backend/setup-wizard/footer.php';
356 +
357 + }
358 +
359 + /**
360 + * Whether this wizard is served in a modal window.
361 + *
362 + * @since 2.2.6
363 + *
364 + * @return bool
365 + */
366 + public function is_modal() {
367 +
368 + return $this->is_modal;
369 +
370 + }
371 +
372 + /**
373 + * Outputs HTML to close the current window, due to it being opened
374 + * by window.open().
375 + *
376 + * @since 2.2.6
377 + */
378 + public function maybe_close_modal() {
379 +
380 + // Sanity check we requested a modal.
381 + if ( ! $this->is_modal() ) {
382 + return;
383 + }
384 +
385 + // Load HTML to close the modal.
386 + include_once CONVERTKIT_PLUGIN_PATH . '/views/backend/setup-wizard/close-modal.php';
387 + exit;
357 388
358 389 }
359 390
360 391 /**