Skip to content

Commit 2c0eb23

Browse files
authored
Escaping and function usage updates (#3094)
* Plugin check suggested updates * Escaping * Function changes * Switching to output butter, and avoid stripping the confirmation prompt * Removal of content if there's a script or style tag. * Avoid warning in deprecated function. * Translator comments. * Using wp_parse_url instead for consistency on php versions. * Updating helper to 3.5.8 with escaping. * Validation of order param.
1 parent 79ce8b2 commit 2c0eb23

36 files changed

+111
-80
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
significance: patch
2+
type: security
3+
entry: Validation of the order param for the quiz Students Without Attempts table.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
significance: patch
2+
type: changed
3+
entry: Various escaping and consistency changes.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"deliciousbrains/wp-background-processing": "1.0.2",
3232
"lifterlms/lifterlms-blocks": "2.7.0",
3333
"lifterlms/lifterlms-cli": "0.0.5",
34-
"lifterlms/lifterlms-helper": "3.5.7",
34+
"lifterlms/lifterlms-helper": "3.5.8",
3535
"lifterlms/lifterlms-rest": "1.0.3",
3636
"woocommerce/action-scheduler": "3.5.4",
3737
"gocodebox/banner-notifications": "1.1.1"

includes/abstracts/abstract.llms.admin.table.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ public function get_empty_message() {
372372
public function get_filter_placeholder( $column_id, $column_data ) {
373373
$placeholder = __( 'Any', 'lifterlms' );
374374
if ( is_array( $column_data ) && isset( $column_data['title'] ) ) {
375+
/* translators: %s: Column title. */
375376
$placeholder = sprintf( __( 'Any %s', 'lifterlms' ), $column_data['title'] );
376377
} elseif ( is_string( $column_data ) ) {
378+
/* translators: %s: Column title. */
377379
$placeholder = sprintf( __( 'Any %s', 'lifterlms' ), $column_data );
378380
}
379381
/**
@@ -793,7 +795,7 @@ public function output_tfoot_html() {
793795
<form action="" method="POST">
794796
<button class="llms-button-primary small" name="llms_quiz_resumable_attempt_action" type="submit" value="llms_clear_resumable_attempts">
795797
<i class="fa fa-trash-o" aria-hidden="true"></i>
796-
<?php _e( 'Clear resumable attempts', 'lifterlms' ); ?>
798+
<?php echo esc_html( __( 'Clear resumable attempts', 'lifterlms' ) ); ?>
797799
</button>
798800
<input type="hidden" name="llms_quiz_id" value="<?php echo esc_attr( $this->quiz_id ); ?>">
799801
<?php wp_nonce_field( 'llms_quiz_attempt_actions', '_llms_quiz_attempt_nonce' ); ?>
@@ -814,7 +816,12 @@ public function output_tfoot_html() {
814816
<?php if ( $this->is_paginated ) : ?>
815817
<div class="llms-table-pagination">
816818
<?php if ( $this->max_pages ) : ?>
817-
<span class="llms-table-page-count"><?php echo esc_html( sprintf( esc_html_x( '%1$d of %2$d', 'pagination', 'lifterlms' ), $this->current_page, $this->max_pages ) ); ?></span>
819+
<span class="llms-table-page-count">
820+
<?php
821+
/* translators: %1$d: Current page, %2$d: Total page count. */
822+
echo esc_html( sprintf( esc_html_x( '%1$d of %2$d', 'pagination', 'lifterlms' ), $this->current_page, $this->max_pages ) );
823+
?>
824+
</span>
818825
<?php endif; ?>
819826
<?php if ( 1 !== $this->get_current_page() ) : ?>
820827
<?php if ( $this->max_pages ) : ?>

includes/abstracts/abstract.llms.database.query.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ protected function prepare_query() {
397397
} else {
398398
_doing_it_wrong(
399399
__METHOD__,
400+
/* translators: %s: Method name. */
400401
esc_html( sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'lifterlms' ), __METHOD__ ) ),
401402
'6.0.0'
402403
);

includes/abstracts/abstract.llms.payment.gateway.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ public function get_admin_settings_fields() {
362362
$fields[] = array(
363363
'autoload' => true,
364364
'id' => $this->get_option_name( 'enabled' ),
365+
/* translators: %s: Payment gateway title. */
365366
'desc' => sprintf( _x( 'Enable %s', 'Payment gateway title', 'lifterlms' ), $this->get_admin_title() ),
366367
'desc_tooltip' => __( 'Checking this box will allow users to use this payment gateway.', 'lifterlms' ),
367368
'default' => $this->get_enabled(),
@@ -389,6 +390,7 @@ public function get_admin_settings_fields() {
389390

390391
$fields[] = array(
391392
'id' => $this->get_option_name( 'test_mode_enabled' ),
393+
/* translators: %s: Payment gateway test mode title. */
392394
'desc' => sprintf( _x( 'Enable %s', 'Payment gateway test mode title', 'lifterlms' ), $this->get_test_mode_title() ),
393395
'desc_tooltip' => $this->get_test_mode_description(),
394396
'default' => $this->get_test_mode_enabled(),
@@ -401,6 +403,7 @@ public function get_admin_settings_fields() {
401403
$fields[] = array(
402404
'id' => $this->get_option_name( 'logging_enabled' ),
403405
'desc' => __( 'Enable debug logging', 'lifterlms' ),
406+
/* Translators: %s: Debug log location. */
404407
'desc_tooltip' => sprintf( __( 'When enabled, debugging information will be logged to "%s"', 'lifterlms' ), llms_get_log_path( $this->get_id() ) ),
405408
'title' => __( 'Debug Log', 'lifterlms' ),
406409
'type' => 'checkbox',
@@ -803,7 +806,7 @@ public function get_transaction_url( $transaction_id, $api_mode = 'live' ) {
803806
public function handle_payment_source_switch( $order, $form_data = array() ) {
804807
return llms_add_notice(
805808
sprintf(
806-
// Translatos: %s = the title of the payment gateway.
809+
/* translators: %s: the title of the payment gateway. */
807810
esc_html__( 'The selected payment gateway "%s" does not support payment method switching.', 'lifterlms' ),
808811
$this->get_title()
809812
),

includes/abstracts/abstract.llms.post.model.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ public function get_price( $key, $price_args = array(), $format = 'html' ) {
724724
if ( 'html' === $format || 'raw' === $format ) {
725725
$price = llms_price( $price, $price_args );
726726
if ( 'raw' === $format ) {
727-
$price = strip_tags( $price );
727+
$price = wp_strip_all_tags( $price );
728728
}
729729
} elseif ( 'float' === $format ) {
730730
$price = floatval( number_format( $price, get_lifterlms_decimals(), '.', '' ) );
@@ -855,7 +855,7 @@ protected function get_embed( $type = 'video', $prop = '' ) {
855855

856856
$prop = $prop ? $prop : $type . '_embed';
857857
$url = $this->get( $prop );
858-
if ( trim( $url ) && parse_url( $url ) ) {
858+
if ( trim( $url ) && wp_parse_url( $url ) ) {
859859
$this->get_provider_support( $url );
860860

861861
$ret = wp_oembed_get( sanitize_url( $url ) );
@@ -1516,6 +1516,7 @@ private function update_meta_properties( $post_meta_properties, $allow_same_meta
15161516
$u = update_post_meta( $this->id, $this->meta_prefix . $key, wp_slash( $val ) );
15171517

15181518
if ( ! ( is_numeric( $u ) || true === $u ) ) {
1519+
/* translators: %s: Meta key. */
15191520
$error->add( 'invalid_meta', sprintf( __( 'Cannot insert/update the %s meta', 'lifterlms' ), $key ) );
15201521
}
15211522
}

includes/abstracts/abstract.llms.update.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function __construct() {
7373
break;
7474

7575
}
76-
7776
}
7877

7978
/**
@@ -90,7 +89,6 @@ private function add_actions() {
9089
add_action( $this->get_hook( $func ), array( $this, $func ), 10, 1 );
9190

9291
}
93-
9492
}
9593

9694
/**
@@ -116,7 +114,6 @@ private function check_progress( $progress ) {
116114
$this->log( sprintf( 'Progress: %d completed, %d remaining', $completed, $remaining ) );
117115

118116
}
119-
120117
}
121118

122119
/**
@@ -132,7 +129,6 @@ public function complete() {
132129
$this->log( sprintf( 'LLMS update tasks completed for version %s', $this->version ) );
133130
LLMS_Install::update_db_version( $this->version );
134131
delete_option( 'llms_update_' . $this->version );
135-
136132
}
137133

138134
/**
@@ -150,7 +146,6 @@ private function enqueue() {
150146
}
151147

152148
$this->log( sprintf( 'LLMS update tasks enqueued for version %s', $this->version ) );
153-
154149
}
155150

156151
/**
@@ -168,7 +163,6 @@ protected function function_complete( $function ) {
168163
$progress['functions'][ $function ] = 'done';
169164
update_option( 'llms_update_' . $this->version, $progress );
170165
$this->log( sprintf( '%s::%s() is complete', get_class( $this ), $function ) );
171-
172166
}
173167

174168
/**
@@ -198,7 +192,6 @@ private function get_progress() {
198192
);
199193

200194
return get_option( 'llms_update_' . $this->version, $default );
201-
202195
}
203196

204197
/**
@@ -242,7 +235,6 @@ private function update_status( $status ) {
242235
$p = $this->get_progress();
243236
$p['status'] = $status;
244237
update_option( 'llms_update_' . $this->version, $p );
245-
246238
}
247239

248240
/**
@@ -258,7 +250,6 @@ protected function log( $msg ) {
258250
if ( defined( 'LLMS_BG_UPDATE_LOG' ) && LLMS_BG_UPDATE_LOG ) {
259251
llms_log( $msg, 'updater' );
260252
}
261-
262253
}
263254

264255

@@ -283,9 +274,13 @@ private function output_progress_notice( $progress ) {
283274
$max = count( $progress['functions'] );
284275
$width = $val ? ( $val / $max ) * 100 : 0;
285276
$html = '
286-
<p>' . sprintf( __( 'LifterLMS Database Upgrade %s Progress Report', 'lifterlms' ), $this->version ) . '</p>
277+
';
278+
/* translators: %s: Database version. */
279+
$html .= '<p>' . sprintf( __( 'LifterLMS Database Upgrade %s Progress Report', 'lifterlms' ), $this->version ) . '</p>
287280
<div style="background:#efefef;height:18px;margin:0.5em 0;"><div style="background:#ef476f;display:block;height:18px;width:' . $width . '%;"><span style="padding:0 0.5em;color:#fff;">' . $width . '%</span></div></div>
288-
<p><em>' . sprintf( __( 'This completion percentage is an estimate, please be patient and %1$sclick here%2$s for more information.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-database-updates/#upgrade-progress-report" target="_blank">', '</a>' ) . '</em></p>
281+
';
282+
/* translators: %1$s: Opening link tag, %2$s: closing link tag. */
283+
$html .= '<p><em>' . sprintf( __( 'This completion percentage is an estimate, please be patient and %1$sclick here%2$s for more information.', 'lifterlms' ), '<a href="https://lifterlms.com/docs/lifterlms-database-updates/#upgrade-progress-report" target="_blank">', '</a>' ) . '</em></p>
289284
';
290285

291286
LLMS_Admin_Notices::add_notice(
@@ -297,7 +292,5 @@ private function output_progress_notice( $progress ) {
297292
'type' => 'info',
298293
)
299294
);
300-
301295
}
302-
303296
}

includes/abstracts/llms-abstract-email-provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ protected function do_remote_install_verify() {
326326
}
327327

328328
if ( ! $this->is_installed() ) {
329-
// Translators: %s = title of the email delivery plugin.
330329
return array(
331330
'code' => 'llms_' . $this->id . '_not_found',
331+
/* translators: %s: title of the email delivery plugin. */
332332
'message' => sprintf( __( '%s plugin not found. Please try again.', 'lifterlms' ), $this->get_title() ),
333333
'status' => 400,
334334
);

includes/abstracts/llms-abstract-generator-posts.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ protected function create_post( $type, $raw = array(), $author_id = null ) {
171171

172172
$class_name = sprintf( 'LLMS_%s', implode( '_', array_map( 'ucfirst', explode( '_', $type ) ) ) );
173173
if ( ! class_exists( $class_name ) ) {
174+
/* translators: %s: Name of class. */
174175
throw new Exception( esc_html( sprintf( __( 'The class "%s" does not exist.', 'lifterlms' ), $class_name ) ), intval( self::ERROR_INVALID_POST ) );
175176
}
176177

@@ -514,6 +515,7 @@ protected function get_term_id( $term_name, $tax ) {
514515
$term = wp_insert_term( $term_name, $tax );
515516

516517
if ( is_wp_error( $term ) ) {
518+
/* translators: %s: name of term. */
517519
throw new Exception( esc_html( sprintf( __( 'Error creating new term "%s".', 'lifterlms' ), $term_name ) ), intval( self::ERROR_CREATE_TERM ) );
518520
}
519521

@@ -811,7 +813,7 @@ protected function sideload_images( $post, $raw ) {
811813
$blocked_hosts = apply_filters(
812814
'llms_generator_sideload_hosts_blocklist',
813815
array(
814-
parse_url( get_site_url(), PHP_URL_HOST ),
816+
wp_parse_url( get_site_url(), PHP_URL_HOST ),
815817
)
816818
);
817819

@@ -821,7 +823,7 @@ protected function sideload_images( $post, $raw ) {
821823
foreach ( $raw['_extras']['images'] as $src ) {
822824

823825
// Don't sideload images from blocked hosts.
824-
if ( in_array( parse_url( $src, PHP_URL_HOST ), $blocked_hosts, true ) ) {
826+
if ( in_array( wp_parse_url( $src, PHP_URL_HOST ), $blocked_hosts, true ) ) {
825827
continue;
826828
}
827829

0 commit comments

Comments
 (0)