Skip to content

Commit 3b8f473

Browse files
author
hsehszroc
committed
REMOVED: translation text support
- ON VALIDATE METHOD: -- Info was only for developers. -- Also, removed escaping. - ON GET METHOD: -- Added escaping on wp_die(). REVIEW: other codes and comments.
1 parent b7e4f5d commit 3b8f473

File tree

1 file changed

+20
-68
lines changed

1 file changed

+20
-68
lines changed

Config.php

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,13 @@ public function start_onboarding() {
224224
/**
225225
* Starts onboarding.
226226
*
227-
* Voila!!! We are now at onboarding intro page.
228-
*
229227
* @see {@method `Config::start_onboarding()`}
230228
* @since 1.0
231229
*/
232230
public function init() {
233-
// phpcs:disable WordPress.Security.NonceVerification
234-
$get = wp_unslash( $_GET );
231+
$get = wp_unslash( $_GET ); // phpcs:disable WordPress.Security.NonceVerification.Recommended
235232
$current_page = isset( $get['page'] ) ? $get['page'] : false;
236233
$multi_activated = isset( $get['activate-multi'] );
237-
// phpcs:enable WordPress.Security.NonceVerification
238234

239235
// Bail early on these events.
240236
if ( wp_doing_ajax() || is_network_admin() ) {
@@ -249,6 +245,8 @@ public function init() {
249245

250246
// Once redirected, that's enough. Don't do it ever again.
251247
delete_transient( $this->get_prefix() . '_onboarding_redirect' );
248+
249+
// Voila!!! We are now at onboarding intro page.
252250
wp_safe_redirect( admin_url( 'admin.php?page=' . $this->get_page() ) );
253251
exit;
254252
}
@@ -347,8 +345,10 @@ public static function get( string $prefix, string $capability = 'manage_options
347345
$namespace = self::validate( $capability, $prefix );
348346

349347
if ( is_wp_error( $namespace ) ) {
350-
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
351-
wp_die( $namespace->get_error_message(), $namespace->get_error_data() );
348+
wp_die(
349+
wp_kses_post( $namespace->get_error_message() ),
350+
wp_kses_post( $namespace->get_error_data() )
351+
);
352352
}
353353

354354
if ( ! is_a( $config, get_class() ) ) {
@@ -388,6 +388,7 @@ public static function get( string $prefix, string $capability = 'manage_options
388388
* @return string|WP_Error Namespace if valid, `WP_Error` otherwise.
389389
*
390390
* @since 1.0
391+
* @since 1.1 Removed translation support (info was only for developers).
391392
* @static
392393
*/
393394
private static function validate( string $cap, string $prefix ) {
@@ -405,81 +406,32 @@ private static function validate( string $cap, string $prefix ) {
405406

406407
// Only show directory information if user has given capability.
407408
if ( isset( $user_caps[ $cap ] ) && $user_caps[ $cap ] ) {
408-
$located = sprintf( '%1$s <code><b><em>%2$s</em></b></code>', __( 'Files are located inside directory:', 'tws-onboarding' ), $dir );
409+
$located = sprintf( 'Files are located inside directory: <code><b><em>%1$s</em></b></code>', $dir );
409410
}
410411

411-
$allowed_html = array(
412-
'b' => array(),
413-
'em' => array(),
414-
'code' => array(),
415-
);
416-
417412
if ( 'thewebsolver' === $prefix || '' === $prefix ) {
418413
// Prefix errors.
419-
$prefix_title = __( 'Onboarding class prefix error', 'tws-onboarding' );
420-
$prefix_msg = sprintf(
421-
'<h1>%1$s</h1><p>%2$s.</p><p>%3$s.</p><p>%4$s</p>',
422-
$prefix_title,
423-
__( 'Use your plugin\'s unique prefix for <code><b><em>Config::get()</em></b></code> to get the config instance', 'tws-onboarding' ),
424-
__( 'Default prefix <b><em>"thewebsolver"</em></b> is being used', 'tws-onboarding' ),
425-
wp_kses( $located, $allowed_html )
426-
);
414+
$prefix_title = 'Onboarding class prefix error';
415+
$prefix_msg = sprintf( '<h1>%1$s</h1><p>Use your plugin\'s unique prefix for <code><b><em>Config::get()</em></b></code> to get the config instance.</p><p>Default prefix <b><em>"thewebsolver"</em></b> is being used.</p><p>%2$s</p>', $prefix_title, $located );
427416

428-
return new WP_Error(
429-
'prefix_mismatch',
430-
wp_kses(
431-
$prefix_msg,
432-
array(
433-
'h1' => array(),
434-
'p' => array(),
435-
'b' => array(),
436-
'em' => array(),
437-
'code' => array(),
438-
)
439-
),
440-
esc_html( $prefix_title )
441-
);
417+
return new WP_Error( 'prefix_mismatch', $prefix_msg, $prefix_title );
442418
}
443419

444-
$note = __( 'Set unique namespace to instantiate <code><b><em>Config::get()</em></b></code> and declare the same namespace at the top of the <code><b><em>Config.php</em></b></code> and <code><b><em>Includes/Wizard.php</em></b></code> files.', 'tws-onboarding' );
420+
$note = 'Set unique namespace to instantiate <code><b><em>Config::get()</em></b></code> and declare the same namespace at the top of the <code><b><em>Config.php</em></b></code> and <code><b><em>Includes/Wizard.php</em></b></code> files.';
445421

446422
// Case where namespace not declared.
447423
if ( 0 === strlen( __NAMESPACE__ ) ) {
448-
$notitle = __( 'Namespace not declared', 'tws-onboarding' );
449-
$nons = __( 'Onboarding Config was instantiated without namespace.', 'tws-onboarding' );
450-
451-
return new WP_Error(
452-
'namespace_not_declared',
453-
sprintf(
454-
'<h1>%1$s</h1><p>%2$s</p><p>%3$s</p><p>%4$s</p>',
455-
esc_html( $notitle ),
456-
esc_html( $nons ),
457-
wp_kses( $note, $allowed_html ),
458-
wp_kses( $located, $allowed_html )
459-
),
460-
esc_html( $notitle )
461-
);
424+
$notitle = 'Namespace not declared';
425+
$nons = 'Onboarding Config was instantiated without namespace.';
426+
427+
return new WP_Error( 'namespace_not_declared', sprintf( '<h1>%1$s</h1><p>%2$s</p><p>%3$s</p><p>%4$s</p>', $notitle, $nons, $note, $located ), $notitle );
462428
}
463429

464430
// Case where default namespace is being used.
465431
if ( __NAMESPACE__ === $default ) {
466-
$title = __( 'Namespace Not Unique', 'tws-onboarding' );
467-
$message = __( 'Onboarding Config was instantiated with default namespace.', 'tws-onboarding' );
468-
$passed = __( 'Change this default namespace:', 'tws-onboarding' );
469-
470-
return new WP_Error(
471-
'namespace_no_match',
472-
sprintf(
473-
'<h1>%1$s</h1><p>%2$s</p><p>%3$s</p><p>%4$s</p><hr><p>%5$s <code><b><em>%6$s</em></b></code></p>',
474-
esc_html( $title ),
475-
esc_html( $message ),
476-
wp_kses( $note, $allowed_html ),
477-
wp_kses( $located, $allowed_html ),
478-
esc_html( $passed ),
479-
esc_html( $default )
480-
),
481-
esc_html( $title )
482-
);
432+
$title = 'Namespace Not Unique';
433+
434+
return new WP_Error( 'namespace_no_match', sprintf( '<h1>%1$s</h1><p>Onboarding Config was instantiated with default namespace.</p><p>%2$s</p><p>%3$s</p><hr><p>Change this default namespace: <code><b><em>%4$s</em></b></code></p>', $title, $note, $located, $default ), $title );
483435
}
484436

485437
return $ns;

0 commit comments

Comments
 (0)