Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIP linter fixes #820

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions inc/fields/class-shortcode-ui-field-post-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public function action_wp_ajax_shortcode_ui_post_field() {
$requested_shortcode = isset( $_GET['shortcode'] ) ? sanitize_text_field( $_GET['shortcode'] ) : null;
$requested_attr = isset( $_GET['attr'] ) ? sanitize_text_field( $_GET['attr'] ) : null;

$include = filter_input( INPUT_GET, 'include', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm following what FILTER_SANITIZE_NUMBER_INT is doing here, since you map intval over the array a couple lines below. Is the sanitize_int filter just necessary to pass the lint rule?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this seems like an overzealous linter change really, will revisit this PR and see if it's still relevant.

if ( ! is_array( $include ) ) {
$include = (array) explode( ',', filter_input( INPUT_GET, 'include', FILTER_SANITIZE_STRING ) );
}
$include = array_filter( array_map( 'intval', $include ) );

$response = array(
'items' => array(),
'found_items' => 0,
Expand Down Expand Up @@ -136,9 +142,8 @@ public function action_wp_ajax_shortcode_ui_post_field() {
$query_args['s'] = sanitize_text_field( $_GET['s'] );
}

if ( ! empty( $_GET['include'] ) ) {
$post__in = is_array( $_GET['include'] ) ? $_GET['include'] : explode( ',', $_GET['include'] );
$query_args['post__in'] = array_map( 'intval', $post__in );
if ( ! empty( $include ) ) {
$query_args['post__in'] = $include;
$query_args['orderby'] = 'post__in';
$query_args['ignore_sticky_posts'] = true;
}
Expand Down
14 changes: 10 additions & 4 deletions inc/fields/class-shortcode-ui-field-term-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,19 @@ public function output_templates() {
*/
public function action_wp_ajax_shortcode_ui_term_field() {

$args = array();
$nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : null;
$requested_shortcode = isset( $_GET['shortcode'] ) ? sanitize_text_field( $_GET['shortcode'] ) : null;
$requested_attr = isset( $_GET['attr'] ) ? sanitize_text_field( $_GET['attr'] ) : null;
$page = isset( $_GET['page'] ) ? absint( $_GET['page'] ) : null;
$search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';

$include = filter_input( INPUT_GET, 'include', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
if ( ! is_array( $include ) ) {
$include = (array) explode( ',', filter_input( INPUT_GET, 'include', FILTER_SANITIZE_STRING ) );
}
$include = array_filter( array_map( 'intval', $include ) );

$response = array(
'items' => array(),
'found_items' => 0,
Expand Down Expand Up @@ -142,10 +149,9 @@ public function action_wp_ajax_shortcode_ui_term_field() {
$args['hide_empty'] = false;
$args['number'] = 10;

if ( ! empty( $_GET['include'] ) ) {
$term__in = is_array( $_GET['include'] ) ? $_GET['include'] : explode( ',', $_GET['include'] );
$args['number'] = count( $term__in );
$args['include'] = array_map( 'intval', $term__in );
if ( ! empty( $include ) ) {
$args['number'] = count( $include );
$args['include'] = $include;
$args['orderby'] = 'tag__in';
}

Expand Down