Skip to content

Commit 3ae92ef

Browse files
authored
Merge pull request #9 from cfg/escape-translations
Use escaped variants of _e() and __()
2 parents cf52f2a + e243c4d commit 3ae92ef

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

options-importer.php

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: WP Options Importer
55
Plugin URI: https://github.com/alleyinteractive/options-importer
66
Description: Export and import WordPress Options
7-
Version: 6
7+
Version: 7
88
Author: Matthew Boynes
99
Author URI: http://www.alleyinteractive.com/
1010
*/
@@ -58,7 +58,7 @@ class WP_Options_Importer {
5858
/**
5959
* The plugin version.
6060
*/
61-
const VERSION = 6;
61+
const VERSION = 7;
6262

6363
/**
6464
* The minimum file version the importer will allow.
@@ -116,7 +116,7 @@ public function setup() {
116116
*/
117117
public function register_importer() {
118118
if ( function_exists( 'register_importer' ) ) {
119-
register_importer( 'wp-options-import', __( 'Options', 'wp-options-importer' ), __( 'Import wp_options from a JSON file', 'wp-options-importer' ), array( $this, 'dispatch' ) );
119+
register_importer( 'wp-options-import', esc_html__( 'Options', 'wp-options-importer' ), esc_html__( 'Import wp_options from a JSON file', 'wp-options-importer' ), array( $this, 'dispatch' ) );
120120
}
121121
}
122122

@@ -128,7 +128,7 @@ public function register_importer() {
128128
*/
129129
public function export_filters() {
130130
?>
131-
<p><label><input type="radio" name="content" value="options" /> <?php _e( 'Options', 'wp-options-importer' ); ?></label></p>
131+
<p><label><input type="radio" name="content" value="options" /> <?php esc_html_e( 'Options', 'wp-options-importer' ); ?></label></p>
132132
<?php
133133
}
134134

@@ -235,7 +235,7 @@ public function dispatch() {
235235
if ( $this->handle_upload() ) {
236236
$this->pre_import();
237237
} else {
238-
echo '<p><a href="' . esc_url( admin_url( 'admin.php?import=wp-options-import' ) ) . '">' . __( 'Return to File Upload', 'wp-options-importer' ) . '</a></p>';
238+
echo '<p><a href="' . esc_url( admin_url( 'admin.php?import=wp-options-import' ) ) . '">' . esc_html__( 'Return to File Upload', 'wp-options-importer' ) . '</a></p>';
239239
}
240240
break;
241241
case 2:
@@ -258,7 +258,7 @@ public function dispatch() {
258258
*/
259259
private function header() {
260260
echo '<div class="wrap">';
261-
echo '<h2>' . __( 'Import WordPress Options', 'wp-options-importer' ) . '</h2>';
261+
echo '<h2>' . esc_html__( 'Import WordPress Options', 'wp-options-importer' ) . '</h2>';
262262
}
263263

264264

@@ -279,8 +279,8 @@ private function footer() {
279279
*/
280280
private function greet() {
281281
echo '<div class="narrow">';
282-
echo '<p>'.__( 'Howdy! Upload your WordPress options JSON file and we&#8217;ll import the desired data. You&#8217;ll have a chance to review the data prior to import.', 'wp-options-importer' ).'</p>';
283-
echo '<p>'.__( 'Choose a JSON (.json) file to upload, then click Upload file and import.', 'wp-options-importer' ).'</p>';
282+
echo '<p>'.esc_html__( 'Howdy! Upload your WordPress options JSON file and we&#8217;ll import the desired data. You&#8217;ll have a chance to review the data prior to import.', 'wp-options-importer' ).'</p>';
283+
echo '<p>'.esc_html__( 'Choose a JSON (.json) file to upload, then click Upload file and import.', 'wp-options-importer' ).'</p>';
284284
wp_import_upload_form( 'admin.php?import=wp-options-import&amp;step=1' );
285285
echo '</div>';
286286
}
@@ -297,15 +297,15 @@ private function handle_upload() {
297297

298298
if ( isset( $file['error'] ) ) {
299299
return $this->error_message(
300-
__( 'Sorry, there has been an error.', 'wp-options-importer' ),
300+
esc_html__( 'Sorry, there has been an error.', 'wp-options-importer' ),
301301
esc_html( $file['error'] )
302302
);
303303
}
304304

305305
if ( ! isset( $file['file'], $file['id'] ) ) {
306306
return $this->error_message(
307-
__( 'Sorry, there has been an error.', 'wp-options-importer' ),
308-
__( 'The file did not upload properly. Please try again.', 'wp-options-importer' )
307+
esc_html__( 'Sorry, there has been an error.', 'wp-options-importer' ),
308+
esc_html__( 'The file did not upload properly. Please try again.', 'wp-options-importer' )
309309
);
310310
}
311311

@@ -314,16 +314,16 @@ private function handle_upload() {
314314
if ( ! file_exists( $file['file'] ) ) {
315315
wp_import_cleanup( $this->file_id );
316316
return $this->error_message(
317-
__( 'Sorry, there has been an error.', 'wp-options-importer' ),
318-
sprintf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wp-options-importer' ), esc_html( $file['file'] ) )
317+
esc_html__( 'Sorry, there has been an error.', 'wp-options-importer' ),
318+
sprintf( esc_html__( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wp-options-importer' ), esc_html( $file['file'] ) )
319319
);
320320
}
321321

322322
if ( ! is_file( $file['file'] ) ) {
323323
wp_import_cleanup( $this->file_id );
324324
return $this->error_message(
325-
__( 'Sorry, there has been an error.', 'wordpress-importer' ),
326-
__( 'The path is not a file, please try again.', 'wordpress-importer' )
325+
esc_html__( 'Sorry, there has been an error.', 'wordpress-importer' ),
326+
esc_html__( 'The path is not a file, please try again.', 'wordpress-importer' )
327327
);
328328
}
329329

@@ -531,26 +531,26 @@ private function pre_import() {
531531
<?php wp_nonce_field( 'import-wordpress-options' ); ?>
532532
<input type="hidden" name="import_id" value="<?php echo absint( $this->file_id ); ?>" />
533533

534-
<h3><?php _e( 'What would you like to import?', 'wp-options-importer' ) ?></h3>
534+
<h3><?php esc_html_e( 'What would you like to import?', 'wp-options-importer' ) ?></h3>
535535
<p>
536-
<label><input type="radio" class="which-options" name="settings[which_options]" value="default" checked="checked" /> <?php _e( 'Default Options' ); ?></label>
537-
<br /><label><input type="radio" class="which-options" name="settings[which_options]" value="all" /> <?php _e( 'All Options' ); ?></label>
538-
<br /><label><input type="radio" class="which-options" name="settings[which_options]" value="specific" /> <?php _e( 'Specific Options' ); ?></label>
536+
<label><input type="radio" class="which-options" name="settings[which_options]" value="default" checked="checked" /> <?php esc_html_e( 'Default Options' ); ?></label>
537+
<br /><label><input type="radio" class="which-options" name="settings[which_options]" value="all" /> <?php esc_html_e( 'All Options' ); ?></label>
538+
<br /><label><input type="radio" class="which-options" name="settings[which_options]" value="specific" /> <?php esc_html_e( 'Specific Options' ); ?></label>
539539
</p>
540540

541541
<div id="option_importer_details">
542-
<h3><?php _e( 'Select the options to import', 'wp-options-importer' ); ?></h3>
542+
<h3><?php esc_html_e( 'Select the options to import', 'wp-options-importer' ); ?></h3>
543543
<p>
544-
<a href="#" class="options-bulk-select" data-select="all"><?php _e( 'Select All', 'wp-options-importer' ); ?></a>
545-
| <a href="#" class="options-bulk-select" data-select="none"><?php _e( 'Select None', 'wp-options-importer' ); ?></a>
546-
| <a href="#" class="options-bulk-select" data-select="defaults"><?php _e( 'Select Defaults', 'wp-options-importer' ); ?></a>
544+
<a href="#" class="options-bulk-select" data-select="all"><?php esc_html_e( 'Select All', 'wp-options-importer' ); ?></a>
545+
| <a href="#" class="options-bulk-select" data-select="none"><?php esc_html_e( 'Select None', 'wp-options-importer' ); ?></a>
546+
| <a href="#" class="options-bulk-select" data-select="defaults"><?php esc_html_e( 'Select Defaults', 'wp-options-importer' ); ?></a>
547547
</p>
548548
<table id="importing_options">
549549
<thead>
550550
<tr>
551551
<th>&nbsp;</th>
552-
<th><?php _e( 'Option Name', 'wp-options-importer' ); ?></th>
553-
<th><?php _e( 'New Value', 'wp-options-importer' ) ?></th>
552+
<th><?php esc_html_e( 'Option Name', 'wp-options-importer' ); ?></th>
553+
<th><?php esc_html_e( 'New Value', 'wp-options-importer' ) ?></th>
554554
</tr>
555555
</thead>
556556
<tbody>
@@ -579,18 +579,18 @@ private function pre_import() {
579579
</table>
580580
</div>
581581

582-
<h3><?php _e( 'Additional Settings', 'wp-options-importer' ); ?></h3>
582+
<h3><?php esc_html_e( 'Additional Settings', 'wp-options-importer' ); ?></h3>
583583
<p>
584584
<input type="checkbox" value="1" name="settings[override]" id="override_current" checked="checked" />
585-
<label for="override_current"><?php _e( 'Override existing options', 'wp-options-importer' ); ?></label>
585+
<label for="override_current"><?php esc_html_e( 'Override existing options', 'wp-options-importer' ); ?></label>
586586
</p>
587-
<p class="description"><?php _e( 'If you uncheck this box, options will be skipped if they currently exist.', 'wp-options-importer' ); ?></p>
587+
<p class="description"><?php esc_html_e( 'If you uncheck this box, options will be skipped if they currently exist.', 'wp-options-importer' ); ?></p>
588588

589589
<div class="error inline" id="import_all_warning">
590-
<p class="description"><?php _e( 'Caution! Importing all options with the override option set could break this site. For instance, it may change the site URL, the active theme, and active plugins. Only proceed if you know exactly what you&#8217;re doing.', 'wp-options-importer' ); ?></p>
590+
<p class="description"><?php esc_html_e( 'Caution! Importing all options with the override option set could break this site. For instance, it may change the site URL, the active theme, and active plugins. Only proceed if you know exactly what you&#8217;re doing.', 'wp-options-importer' ); ?></p>
591591
</div>
592592

593-
<?php submit_button( __( 'Import Selected Options', 'wp-options-importer' ) ); ?>
593+
<?php submit_button( esc_html__( 'Import Selected Options', 'wp-options-importer' ) ); ?>
594594
</form>
595595
<?php
596596
}
@@ -604,7 +604,7 @@ private function pre_import() {
604604
private function import() {
605605
if ( $this->run_data_check() ) {
606606
if ( empty( $_POST['settings']['which_options'] ) ) {
607-
$this->error_message( __( 'The posted data does not appear intact. Please try again.', 'wp-options-importer' ) );
607+
$this->error_message( esc_html__( 'The posted data does not appear intact. Please try again.', 'wp-options-importer' ) );
608608
$this->pre_import();
609609
return;
610610
}
@@ -616,7 +616,7 @@ private function import() {
616616
$options_to_import = $this->get_whitelist_options();
617617
} elseif ( 'specific' == $_POST['settings']['which_options'] ) {
618618
if ( empty( $_POST['options'] ) ) {
619-
$this->error_message( __( 'There do not appear to be any options to import. Did you select any?', 'wp-options-importer' ) );
619+
$this->error_message( esc_html__( 'There do not appear to be any options to import. Did you select any?', 'wp-options-importer' ) );
620620
$this->pre_import();
621621
return;
622622
}
@@ -634,7 +634,7 @@ private function import() {
634634
foreach ( (array) $options_to_import as $option_name ) {
635635
if ( isset( $this->import_data['options'][ $option_name ] ) ) {
636636
if ( in_array( $option_name, $blacklist ) ) {
637-
echo "\n<p>" . sprintf( __( 'Skipped option `%s` because a plugin or theme does not allow it to be imported.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
637+
echo "\n<p>" . sprintf( esc_html__( 'Skipped option `%s` because a plugin or theme does not allow it to be imported.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
638638
continue;
639639
}
640640

@@ -643,7 +643,7 @@ private function import() {
643643
// define( 'WP_OPTION_IMPORT_BLACKLIST_REGEX', '/^(home|siteurl)$/' );
644644
// to ensure that none of your sites could change their own url using this tool.
645645
if ( defined( 'WP_OPTION_IMPORT_BLACKLIST_REGEX' ) && preg_match( WP_OPTION_IMPORT_BLACKLIST_REGEX, $option_name ) ) {
646-
echo "\n<p>" . sprintf( __( 'Skipped option `%s` because this WordPress installation does not allow it.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
646+
echo "\n<p>" . sprintf( esc_html__( 'Skipped option `%s` because this WordPress installation does not allow it.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
647647
continue;
648648
}
649649

@@ -653,7 +653,7 @@ private function import() {
653653

654654
// only import the setting if it's not present
655655
if ( $old_value !== $hash ) {
656-
echo "\n<p>" . sprintf( __( 'Skipped option `%s` because it currently exists.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
656+
echo "\n<p>" . sprintf( esc_html__( 'Skipped option `%s` because it currently exists.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
657657
continue;
658658
}
659659
}
@@ -666,12 +666,12 @@ private function import() {
666666
update_option( $option_name, $option_value );
667667
}
668668
} elseif ( 'specific' == $_POST['settings']['which_options'] ) {
669-
echo "\n<p>" . sprintf( __( 'Failed to import option `%s`; it does not appear to be in the import file.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
669+
echo "\n<p>" . sprintf( esc_html__( 'Failed to import option `%s`; it does not appear to be in the import file.', 'wp-options-importer' ), esc_html( $option_name ) ) . '</p>';
670670
}
671671
}
672672

673673
$this->clean_up();
674-
echo '<p>' . __( 'All done. That was easy.', 'wp-options-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'wp-options-importer' ) . '</a>' . '</p>';
674+
echo '<p>' . esc_html__( 'All done. That was easy.', 'wp-options-importer' ) . ' <a href="' . admin_url() . '">' . esc_html__( 'Have fun!', 'wp-options-importer' ) . '</a>' . '</p>';
675675
}
676676
}
677677

@@ -684,22 +684,22 @@ private function import() {
684684
private function run_data_check() {
685685
if ( empty( $this->import_data['version'] ) ) {
686686
$this->clean_up();
687-
return $this->error_message( __( 'Sorry, there has been an error. This file may not contain data or is corrupt.', 'wp-options-importer' ) );
687+
return $this->error_message( esc_html__( 'Sorry, there has been an error. This file may not contain data or is corrupt.', 'wp-options-importer' ) );
688688
}
689689

690690
if ( $this->import_data['version'] < $this->min_version ) {
691691
$this->clean_up();
692-
return $this->error_message( sprintf( __( 'This JSON file (version %s) is not supported by this version of the importer. Please update the plugin on the source, or download an older version of the plugin to this installation.', 'wp-options-importer' ), intval( $this->import_data['version'] ) ) );
692+
return $this->error_message( sprintf( esc_html__( 'This JSON file (version %s) is not supported by this version of the importer. Please update the plugin on the source, or download an older version of the plugin to this installation.', 'wp-options-importer' ), intval( $this->import_data['version'] ) ) );
693693
}
694694

695695
if ( $this->import_data['version'] > self::VERSION ) {
696696
$this->clean_up();
697-
return $this->error_message( sprintf( __( 'This JSON file (version %s) is from a newer version of this plugin and may not be compatible. Please update this plugin.', 'wp-options-importer' ), intval( $this->import_data['version'] ) ) );
697+
return $this->error_message( sprintf( esc_html__( 'This JSON file (version %s) is from a newer version of this plugin and may not be compatible. Please update this plugin.', 'wp-options-importer' ), intval( $this->import_data['version'] ) ) );
698698
}
699699

700700
if ( empty( $this->import_data['options'] ) ) {
701701
$this->clean_up();
702-
return $this->error_message( __( 'Sorry, there has been an error. This file appears valid, but does not seem to have any options.', 'wp-options-importer' ) );
702+
return $this->error_message( esc_html__( 'Sorry, there has been an error. This file appears valid, but does not seem to have any options.', 'wp-options-importer' ) );
703703
}
704704

705705
return true;

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: mboynes,alleyinteractive
33
Tags: options, importer, exporter, export, import, migrate, settings, wp_options
44
Requires at least: 3.8
55
Tested up to: 3.9
6-
Stable tag: 6
6+
Stable tag: 7
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -98,6 +98,12 @@ uncheck those which you don't want to include.
9898

9999
== Changelog ==
100100

101+
= 7 =
102+
* Use escaped variants of `_e()` and `__()`
103+
104+
= 6 =
105+
* Remove multisite site-specific exclusions
106+
101107
= 5 =
102108
* Added WP_OPTION_EXPORT_BLACKLIST_REGEX
103109
* Breaking: Changed the `options_export_exclude` filter to `options_export_blacklist` to be consistent with imports.

0 commit comments

Comments
 (0)