Skip to content

Commit

Permalink
Infinite scroll added checks to validate input (#39618)
Browse files Browse the repository at this point in the history
* Added isset checks to avoid Warnings

* changelog

* Added new isset for last_post_date

* Deprecate infinite_scroll_posts_where  hook
  • Loading branch information
darssen authored Oct 10, 2024
1 parent 827b1ee commit 8537542
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Infinite-scroll: Added isset checks to validate input data
13 changes: 8 additions & 5 deletions projects/plugins/jetpack/modules/infinite-scroll/infinity.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,12 @@ public function query_time_filter( $where, $query ) {

$sort_field = self::get_query_sort_field( $query );

if ( 'post_date' !== $sort_field || 'DESC' !== $_REQUEST['query_args']['order'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- no changes made to the site.
if ( 'post_date' !== $sort_field ||
! isset( $_REQUEST['query_args']['order'] ) || 'DESC' !== $_REQUEST['query_args']['order'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.
return $where;
}

$query_before = sanitize_text_field( wp_unslash( $_REQUEST['query_before'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- no changes made to the site.
$query_before = isset( $_REQUEST['query_before'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['query_before'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes made to the site.

if ( empty( $query_before ) ) {
return $where;
Expand All @@ -771,16 +772,18 @@ public function query_time_filter( $where, $query ) {
* will always return results prior to (descending sort)
* or before (ascending sort) the last post date.
*
* @deprecated $$next-version$$
*
* @module infinite-scroll
*
* @param string $clause SQL Date query.
* @param object $query Query.
* @param string $operator @deprecated Query operator.
* @param string $last_post_date @deprecated Last Post Date timestamp.
*/
$operator = 'ASC' === $_REQUEST['query_args']['order'] ? '>' : '<'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- no changes to the site.
$last_post_date = sanitize_text_field( wp_unslash( $_REQUEST['last_post_date'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- no changes to the site.
$where .= apply_filters( 'infinite_scroll_posts_where', $clause, $query, $operator, $last_post_date );
$operator = '<';
$last_post_date = isset( $_REQUEST['last_post_date'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['last_post_date'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no changes to the site
$where .= apply_filters_deprecated( 'infinite_scroll_posts_where', array( $clause, $query, $operator, $last_post_date ), '$$next-version$$', '' );
}

return $where;
Expand Down

0 comments on commit 8537542

Please sign in to comment.