Skip to content

Commit 315867a

Browse files
authored
Merge pull request #233 from rami-elementor/i18n
Improve i18n, a11y, and security
2 parents 6f5ca6d + 8217760 commit 315867a

13 files changed

+73
-45
lines changed

src/js/components/SnippetForm/SnippetEditor/SnippetEditor.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ const SnippetTypeTabs: React.FC<SnippetTypeTabsProps> = ({
109109
? <a
110110
className="button button-large nav-tab-button nav-tab-inactive go-pro-button"
111111
href="https://codesnippets.pro/pricing/"
112-
title="Find more about Pro"
113112
onClick={event => {
114113
event.preventDefault()
115114
openUpgradeDialog()
116115
}}
117116
>
118-
{_x('Upgrade to ', 'Upgrade to Pro', 'code-snippets')}
119-
<span className="badge">{_x('Pro', 'Upgrade to Pro', 'code-snippets')}</span>
117+
{__('Upgrade to <span class="badge">Pro</span>', 'code-snippets')}
120118
</a>
121119
: null}
122120
</h2>

src/js/components/SnippetForm/fields/ScopeInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const ShortcodeInfo: React.FC = () => {
110110
: __('After saving, you can copy a shortcode, or use the Classic Editor button, Block editor (Pro) or Elementor widget (Pro).', 'code-snippets')}
111111
{' '}
112112
<ExternalLink
113-
href={__('https://help.codesnippets.pro/article/50-inserting-snippets', 'code-snippets')}
113+
href="https://help.codesnippets.pro/article/50-inserting-snippets"
114114
>
115115
{__('Learn more', 'code-snippets')}
116116
</ExternalLink>

src/php/admin-menus/class-import-menu.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,22 @@ protected function print_messages() {
137137
esc_html_e( 'No snippets were imported.', 'code-snippets' );
138138

139139
} else {
140-
/* translators: 1: amount of snippets imported, 2: link to Snippets menu */
141-
$text = _n(
142-
'Successfully imported <strong>%1$d</strong> snippet. <a href="%2$s">Have fun!</a>',
143-
'Successfully imported <strong>%1$d</strong> snippets. <a href="%2$s">Have fun!</a>',
144-
$imported,
145-
'code-snippets'
140+
/* translators: %d: amount of snippets imported */
141+
printf(
142+
_n(
143+
'Successfully imported %d snippet.',
144+
'Successfully imported %d snippets.',
145+
$imported,
146+
'code-snippets'
147+
),
148+
'<strong>' . number_format_i18n(( $imported ) . '</strong>',
146149
);
147150

148-
printf( wp_kses_post( $text ), esc_html( $imported ), esc_url( code_snippets()->get_menu_url( 'manage' ) ) );
151+
printf(
152+
' <a href="%s">%s</a>',
153+
esc_url( code_snippets()->get_menu_url( 'manage' ) )
154+
esc_html__( 'Have fun!', 'code-snippets' );
155+
);
149156
}
150157

151158
echo '</p></div>';

src/php/class-admin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public function plugin_action_links( array $actions, string $plugin_file ): arra
110110
sprintf(
111111
$format,
112112
esc_url( code_snippets()->get_menu_url( 'settings' ) ),
113-
esc_html__( 'Change plugin settings', 'code-snippets' ),
113+
esc_attr__( 'Change plugin settings', 'code-snippets' ),
114114
esc_html__( 'Settings', 'code-snippets' )
115115
),
116116
sprintf(
117117
$format,
118118
esc_url( code_snippets()->get_menu_url() ),
119-
esc_html__( 'Manage your existing snippets', 'code-snippets' ),
119+
esc_attr__( 'Manage your existing snippets', 'code-snippets' ),
120120
esc_html__( 'Snippets', 'code-snippets' )
121121
),
122122
],
@@ -128,7 +128,7 @@ public function plugin_action_links( array $actions, string $plugin_file ): arra
128128
'<a href="%1$s" title="%2$s" style="color: #d46f4d; font-weight: bold;" target="_blank">%3$s</a>',
129129
'https://snipco.de/JE2i',
130130
esc_attr__( 'Upgrade to Code Snippets Pro', 'code-snippets' ),
131-
esc_html__( 'Get Pro', 'code-snippets' )
131+
esc_attr__( 'Upgrade to Pro', 'code-snippets' )
132132
);
133133
}
134134
return $actions;
@@ -297,7 +297,7 @@ public function print_notices() {
297297
printf(
298298
'<a href="%s" class="notice-dismiss"><span class="screen-reader-text">%s</span></a>',
299299
esc_url( wp_nonce_url( add_query_arg( $meta_key, $notice ), $meta_key ) ),
300-
esc_attr__( 'Dismiss', 'code-snippets' )
300+
esc_html__( 'Dismiss', 'code-snippets' )
301301
);
302302

303303
echo '</p></div>';

src/php/class-contextual-help.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function load_help_sidebar() {
7272
'https://codesnippets.pro' => __( 'Plugin Website', 'code-snippets' ),
7373
];
7474

75-
$contents = '<p><strong>' . __( 'For more information:', 'code-snippets' ) . "</strong></p>\n";
75+
$contents = sprintf( "<p><strong>%s</strong></p>\n", esc_html__( 'For more information:', 'code-snippets' ) );
7676

7777
foreach ( $sidebar_links as $url => $label ) {
7878
$contents .= "\n" . sprintf( '<p><a href="%s">%s</a></p>', esc_url( $url ), esc_html( $label ) );
@@ -136,7 +136,8 @@ private function load_manage_help() {
136136
[
137137
__( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ),
138138
__( "If something goes wrong with a snippet, and you can't use WordPress, you can cause all snippets to stop executing by turning on <strong>safe mode</strong>.", 'code-snippets' ),
139-
__( 'You can find out how to enable safe mode in the <a href="https://help.codesnippets.pro/article/12-safe-mode">Code Snippets Pro Docs</a>.', 'code-snippets' ),
139+
/* translators: %s: URL to Code Snippets Pro Docs */
140+
sprintf( __( 'You can find out how to enable safe mode in the <a href="%s">Code Snippets Pro Docs</a>.', 'code-snippets' ), 'https://help.codesnippets.pro/article/12-safe-mode' )
140141
]
141142
);
142143
}
@@ -151,7 +152,8 @@ private function load_edit_help() {
151152
[
152153
$this->get_intro_text() .
153154
__( 'Here you can add a new snippet, or edit an existing one.', 'code-snippets' ),
154-
__( "If you're not sure about the types of snippets you can add, take a look at the <a href=\"https://help.codesnippets.pro/collection/2-adding-snippets\">Code Snippets Pro Docs</a> for inspiration.", 'code-snippets' ),
155+
/* translators: %s: URL to Code Snippets Pro Docs */
156+
sprintf( __( "If you're not sure about the types of snippets you can add, take a look at the <a href=\"%s\">Code Snippets Pro Docs</a> for inspiration.", 'code-snippets' ), 'https://help.codesnippets.pro/collection/2-adding-snippets' ),
155157
]
156158
);
157159

@@ -160,7 +162,7 @@ private function load_edit_help() {
160162
__( 'Adding Snippets', 'code-snippets' ),
161163
[
162164
__( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ),
163-
__( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ),
165+
__( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimize the chance of a faulty snippet becoming active on your site.', 'code-snippets' ),
164166
]
165167
);
166168
}

src/php/class-list-table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected function column_activate( Snippet $snippet ): string {
292292
}
293293

294294
return sprintf(
295-
'<a class="%s" href="%s" title="%s">&nbsp;</a> ',
295+
'<a class="%1$s" href="%2$s" title="%3$s" aria-label="%3$s">&nbsp;</a> ',
296296
esc_attr( $class ),
297297
esc_url( $this->get_action_link( $action, $snippet ) ),
298298
esc_attr( $label )

src/php/cloud/class-cloud-search-list-table.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function display_rows() {
117117
*/
118118
foreach ( $this->items as $item ) {
119119
?>
120-
<div class="plugin-card cloud-search-card plugin-card-<?php echo sanitize_html_class( $item->id ); ?>">
120+
<div class="plugin-card cloud-search-card plugin-card-<?php echo esc_attr( $item->id ); ?>">
121121
<?php
122122
cloud_lts_display_column_hidden_input( 'code', $item );
123123
cloud_lts_display_column_hidden_input( 'name', $item );
@@ -163,14 +163,12 @@ public function display_rows() {
163163
<p class="authors">
164164
<cite>
165165
<?php
166-
esc_html_e( 'Codevault: ', 'code-snippets' );
167-
168166
printf(
169-
'<a target="_blank" href="%s">%s</a>',
167+
'%s <a target="_blank" href="%s">%s</a>',
168+
esc_html__( 'Codevault:', 'code-snippets' );
170169
esc_url( sprintf( 'https://codesnippets.cloud/codevault/%s', $item->codevault ) ),
171170
esc_html( $item->codevault )
172171
);
173-
174172
?>
175173
</cite>
176174
</p>
@@ -250,14 +248,22 @@ public function display_rows() {
250248
</div>
251249
</div>
252250
<div class="column-compatibility">
253-
<strong><?php esc_html_e( 'WP Compatability:', 'code-snippets' ); ?></strong>
251+
<strong><?php esc_html_e( 'WP Compatibility:', 'code-snippets' ); ?></strong>
254252
<?php
255253
if ( empty( $wp_tested ) ) {
256-
echo '<span class="compatibility-untested">', esc_html__( 'Not indicated by author', 'code-snippets' ), '</span>';
254+
printf(
255+
'<span class="compatibility-untested">%s</span>',
256+
esc_html__( 'Not indicated by author', 'code-snippets' )
257+
);
257258
} else {
258-
// translators: tested status.
259-
$text = sprintf( __( 'Author states %s', 'code-snippets' ), $wp_tested );
260-
echo '<span class="compatibility-compatible">', esc_html( $text ), '</span>';
259+
printf(
260+
'<span class="compatibility-compatible">%s</span>',
261+
sprintf(
262+
// translators: %s: tested status.
263+
__( 'Author states %s', 'code-snippets' ),
264+
$wp_tested
265+
)
266+
);
261267
}
262268
?>
263269
</div>

src/php/cloud/list-table-shared-ops.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function cloud_lts_build_action_links( Cloud_Snippet $cloud_snippet, string $sou
125125
$thickbox_url = '#TB_inline?&width=700&height=500&inlineId=show-code-preview';
126126

127127
$thickbox_link = sprintf(
128-
'<a href="%s" title="%s" class="cloud-snippet-preview cloud-snippet-preview-style thickbox %s" data-snippet="%s" data-lang="%s">%s</a>',
128+
'<a href="%s" aria-label="%s" class="cloud-snippet-preview cloud-snippet-preview-style thickbox %s" data-snippet="%s" data-lang="%s">%s</a>',
129129
esc_url( $thickbox_url ),
130130
esc_attr( $cloud_snippet->name ),
131131
$additional_classes,
@@ -224,7 +224,7 @@ function cloud_lts_pagination( string $which, string $source, int $total_items,
224224
$page_links[] = sprintf(
225225
'<a class="next-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
226226
esc_url( add_query_arg( $source . '_page', min( $total_pages, $current + 1 ), $current_url ) ),
227-
__( 'Next page' ),
227+
esc_html__( 'Next page', 'code-snippets' ),
228228
'&rsaquo;'
229229
);
230230
}
@@ -235,7 +235,7 @@ function cloud_lts_pagination( string $which, string $source, int $total_items,
235235
$page_links[] = sprintf(
236236
'<a class="last-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
237237
esc_url( add_query_arg( $source . '_page', $total_pages, $current_url ) ),
238-
__( 'Last page', 'code-snippets' ),
238+
esc_html__( 'Last page', 'code-snippets' ),
239239
'&raquo;'
240240
);
241241
}

src/php/front-end/class-front-end.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ public function render_content_shortcode( array $atts ): string {
303303
}
304304

305305
/* translators: 1: snippet name, 2: snippet edit link */
306-
$text = __( '<strong>%1$s</strong> is currently inactive. You can <a href="%2$s">edit this snippet</a> to activate it and make it visible. This message will not appear in the published post.', 'code-snippets' );
307-
306+
$text = __( '%1$s is currently inactive. You can <a href="%2$s">edit this snippet</a> to activate it and make it visible. This message will not appear in the published post.', 'code-snippets' );
307+
$snippet_name = '<strong>' . $snippet->name . '</strong>';
308308
$edit_url = add_query_arg( 'id', $snippet->id, code_snippets()->get_menu_url( 'edit' ) );
309+
309310
return wp_kses(
310-
sprintf( $text, $snippet->name, $edit_url ),
311+
sprintf( $text, $snippet_name, $edit_url ),
311312
[
312313
'strong' => [],
313314
'a' => [

src/php/views/manage.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
[ 'span' => [ 'class' => [ 'highlight-yellow' ] ] ]
2929
);
3030

31-
$feedback_url = __( 'mailto:team@codesnippets.pro?subject=Code Snippet Beta Test Feedback', 'code-snippets' );
32-
printf( ' <a href="%s">%s</a>', esc_url( $feedback_url ), esc_html__( 'Click here to submit your feedback', 'code-snippets' ) );
31+
printf(
32+
' <a href="%s">%s</a>',
33+
esc_url( __( 'mailto:team@codesnippets.pro?subject=Code Snippet Beta Test Feedback', 'code-snippets' ) ),
34+
esc_html__( 'Click here to submit your feedback', 'code-snippets' )
35+
);
3336
echo '</p></div>';
3437
}
3538

@@ -58,7 +61,7 @@
5861
?>
5962
<a class="button button-large nav-tab-button nav-tab-inactive go-pro-button"
6063
href="https://codesnippets.pro/pricing/" target="_blank"
61-
title="<?php esc_html_e( 'Find more about Pro (opens in external tab)', 'code-snippets' ); ?>">
64+
aria-label="<?php esc_attr_e( 'Find more about Pro (opens in external tab)', 'code-snippets' ); ?>">
6265
<?php echo wp_kses( __( 'Upgrade to <span class="badge">Pro</span>', 'code-snippets' ), [ 'span' => [ 'class' => 'badge' ] ] ); ?>
6366
<span class="dashicons dashicons-external"></span>
6467
</a>
@@ -79,7 +82,7 @@
7982
],
8083
'css' => [
8184
__( 'Style snippets are written in CSS and loaded in the admin area or on the site front-end, just like the theme style.css.', 'code-snippets' ),
82-
esc_html__( 'Learn more about style snippets &rarr;', 'code-snippets' ),
85+
__( 'Learn more about style snippets &rarr;', 'code-snippets' ),
8386
'https://codesnippets.pro/learn-css/',
8487
],
8588
'js' => [

src/php/views/partials/cloud-search.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</select>
5454
<input type="text" id="cloud_search" name="cloud_search" class="cloud_search"
5555
value="<?php echo esc_html( $search_query ); ?>"
56-
placeholder="<?php esc_html_e( 'e.g. Remove unused javascript…', 'code-snippets' ); ?>">
56+
placeholder="<?php esc_attr_e( 'e.g. Remove unused javascript…', 'code-snippets' ); ?>">
5757

5858
<button type="submit" id="cloud-search-submit" class="button">
5959
<?php esc_html_e( 'Search Cloud', 'code-snippets' ); ?>

src/php/views/partials/list-table-notices.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@
1818
?>
1919
<div id="message" class="notice notice-error fade is-dismissible">
2020
<p>
21-
<?php echo wp_kses_post( __( '<strong>Warning:</strong> Safe mode is active and snippets will not execute! Remove the <code>CODE_SNIPPETS_SAFE_MODE</code> constant from <code>wp-config.php</code> to turn off safe mode.', 'code-snippets' ) ); ?>
21+
<?php
22+
printf(
23+
'<strong>%s</strong> %s',
24+
esc_html__( 'Warning:', 'code-snippets' ),
25+
sprintf(
26+
// translators: 1: constant name, 2: file name.
27+
esc_html__( 'Safe mode is active and snippets will not execute! Remove the %1$s constant from %2$s file to turn off safe mode.', 'code-snippets' )
28+
'<code>CODE_SNIPPETS_SAFE_MODE</code>',
29+
'<code>wp-config.php</code>',
30+
)
31+
);
32+
?>
2233

2334
<a href="https://help.codesnippets.pro/article/12-safe-mode" target="_blank">
2435
<?php esc_html_e( 'Help', 'code-snippets' ); ?>

src/php/views/welcome.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class="csp-link-<?php echo esc_attr( $link_name ); ?>">
8080
<h1>📰 <?php esc_html_e( 'Latest news', 'code-snippets' ); ?></h1>
8181
<div class="csp-cards">
8282
<a class="csp-card" href="<?php echo esc_url( $hero['follow_url'] ); ?>" target="_blank"
83-
title="<?php esc_html_e( 'Read more', 'code-snippets' ); ?>">
83+
title="<?php esc_attr_e( 'Read more', 'code-snippets' ); ?>">
8484
<header>
8585
<span class="dashicons dashicons-external"></span>
8686
<h2><?php echo esc_html( $hero['name'] ); ?></h2>
@@ -95,7 +95,7 @@ class="csp-link-<?php echo esc_attr( $link_name ); ?>">
9595
</a>
9696

9797
<a class="csp-card" href="https://wordpress.org/plugins/code-snippets/changelog" target="_blank"
98-
title="<?php esc_html_e( 'Read the full changelog', 'code-snippets' ); ?>">
98+
title="<?php esc_attr_e( 'Read the full changelog', 'code-snippets' ); ?>">
9999
<header>
100100
<span class="dashicons dashicons-external"></span>
101101
<h2><?php esc_html_e( 'Latest changes', 'code-snippets' ); ?></h2>
@@ -148,7 +148,7 @@ class="csp-link-<?php echo esc_attr( $link_name ); ?>">
148148
<?php foreach ( $this->api->get_features() as $feature ) { ?>
149149
<a class="csp-card"
150150
href="<?php echo esc_url( $feature['follow_url'] ); ?>" target="_blank"
151-
title="<?php esc_html_e( 'Read more', 'code-snippets' ); ?>">
151+
title="<?php esc_attr_e( 'Read more', 'code-snippets' ); ?>">
152152
<figure>
153153
<img src="<?php echo esc_url( $feature['image_url'] ); ?>"
154154
alt="<?php esc_attr_e( 'Feature image', 'code-snippets' ); ?>">

0 commit comments

Comments
 (0)