Make WordPress Core

Ticket #37937: 37937.4.patch

File 37937.4.patch, 8.4 KB (added by birgire, 7 years ago)
  • src/wp-includes/class-wp-site-query.php

    diff --git src/wp-includes/class-wp-site-query.php src/wp-includes/class-wp-site-query.php
    index 5367fc7..09bad2d 100644
    class WP_Site_Query { 
    125125         *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
    126126         *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
    127127         *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
    128          *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
    129          *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
    130          *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
    131          *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
    132          *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
     128         *     @type mixed        $public            Limit results to public sites. Accepts boolean values. Default null.
     129         *     @type mixed        $archived          Limit results to archived sites. Accepts boolean values. Default null.
     130         *     @type mixed        $mature            Limit results to mature sites. Accepts boolean values. Default null.
     131         *     @type mixed        $spam              Limit results to spam sites. Accepts boolean values. Default null.
     132         *     @type mixed        $deleted           Limit results to deleted sites. Accepts boolean values. Default null.
    133133         *     @type int          $lang_id           Limit results to a language ID. Default empty.
    134134         *     @type array        $lang__in          Array of language IDs to include affiliated sites for. Default empty.
    135135         *     @type array        $lang__not_in      Array of language IDs to exclude affiliated sites for. Default empty.
    class WP_Site_Query { 
    445445                        $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )";
    446446                }
    447447
    448                 if ( is_numeric( $this->query_vars['archived'] ) ) {
    449                         $archived = absint( $this->query_vars['archived'] );
     448                if ( ! is_null( $this->query_vars['archived'] ) ) {
     449                        $archived = wp_validate_boolean( $this->query_vars['archived'] ) ? 1 : 0;
    450450                        $this->sql_clauses['where']['archived'] = $wpdb->prepare( "archived = %d ", $archived );
    451451                }
    452452
    453                 if ( is_numeric( $this->query_vars['mature'] ) ) {
    454                         $mature = absint( $this->query_vars['mature'] );
     453                if ( ! is_null( $this->query_vars['mature'] ) ) {
     454                        $mature = wp_validate_boolean( $this->query_vars['mature'] ) ? 1 : 0;
    455455                        $this->sql_clauses['where']['mature'] = $wpdb->prepare( "mature = %d ", $mature );
    456456                }
    457457
    458                 if ( is_numeric( $this->query_vars['spam'] ) ) {
    459                         $spam = absint( $this->query_vars['spam'] );
     458                if ( ! is_null( $this->query_vars['spam'] ) ) {
     459                        $spam = wp_validate_boolean( $this->query_vars['spam'] ) ? 1 : 0;
    460460                        $this->sql_clauses['where']['spam'] = $wpdb->prepare( "spam = %d ", $spam );
    461461                }
    462462
    463                 if ( is_numeric( $this->query_vars['deleted'] ) ) {
    464                         $deleted = absint( $this->query_vars['deleted'] );
     463                if ( ! is_null( $this->query_vars['deleted'] ) ) {
     464                        $deleted = wp_validate_boolean( $this->query_vars['deleted'] ) ? 1 : 0;
    465465                        $this->sql_clauses['where']['deleted'] = $wpdb->prepare( "deleted = %d ", $deleted );
    466466                }
    467467
    468                 if ( is_numeric( $this->query_vars['public'] ) ) {
    469                         $public = absint( $this->query_vars['public'] );
     468                if ( ! is_null( $this->query_vars['public'] ) ) {
     469                        $public = wp_validate_boolean( $this->query_vars['public'] ) ? 1 : 0;
    470470                        $this->sql_clauses['where']['public'] = $wpdb->prepare( "public = %d ", $public );
    471471                }
    472472
  • tests/phpunit/tests/multisite/siteQuery.php

    diff --git tests/phpunit/tests/multisite/siteQuery.php tests/phpunit/tests/multisite/siteQuery.php
    index e6f958d..b8f8350 100644
    class Tests_Multisite_Site_Query extends WP_UnitTestCase { 
    737737                ) );
    738738                $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
    739739        }
     740
     741        /**
     742         * @ticket 37937
     743         */
     744        public function test_wp_site_query_by_public_true_values() {
     745
     746                foreach( array( true, 'true', 1, '1' ) as $value ) {
     747                        $q = new WP_Site_Query();
     748                        $found = $q->query( array(
     749                                'public'  => $value,
     750                        ) );
     751                        $this->assertContains( ' public = 1 ', $q->request );
     752                }
     753        }
     754
     755        /**
     756         * @ticket 37937
     757         */
     758        public function test_wp_site_query_by_public_false_values() {
     759                foreach( array( false, 'false', 0, '0' ) as $value ) {
     760                        $q = new WP_Site_Query();
     761                        $found = $q->query( array(
     762                                'public'  => $value,
     763                        ) );
     764                        $this->assertContains( ' public = 0 ', $q->request );
     765                }
     766        }
     767
     768        /**
     769         * @ticket 37937
     770         */
     771        public function test_wp_site_query_by_archived_true_values() {
     772                foreach( array( true, 'true', 1, '1' ) as $value ) {
     773                        $q = new WP_Site_Query();
     774                        $found = $q->query( array(
     775                                'archived'  => $value,
     776                        ) );
     777                        $this->assertContains( ' archived = 1 ', $q->request );
     778                }
     779        }
     780
     781        /**
     782         * @ticket 37937
     783         */
     784        public function test_wp_site_query_by_archived_false_values() {
     785                foreach( array( false, 'false', 0, '0' ) as $value ) {
     786                        $q = new WP_Site_Query();
     787                        $found = $q->query( array(
     788                                'archived'  => $value,
     789                        ) );
     790                        $this->assertContains( ' archived = 0 ', $q->request );
     791                }
     792        }
     793
     794        /**
     795         * @ticket 37937
     796         */
     797        public function test_wp_site_query_by_mature_true_values() {
     798                foreach( array( true, 'true', 1, '1' ) as $value ) {
     799                        $q = new WP_Site_Query();
     800                        $found = $q->query( array(
     801                                'mature'  => $value,
     802                        ) );
     803                        $this->assertContains( ' mature = 1 ', $q->request );
     804                }
     805        }
     806
     807        /**
     808         * @ticket 37937
     809         */
     810        public function test_wp_site_query_by_mature_false_values() {
     811                foreach( array( false, 'false', 0, '0' ) as $value ) {
     812                        $q = new WP_Site_Query();
     813                        $found = $q->query( array(
     814                                'mature'  => $value,
     815                        ) );
     816                        $this->assertContains( ' mature = 0 ', $q->request );
     817                }
     818        }
     819
     820        /**
     821         * @ticket 37937
     822         */
     823        public function test_wp_site_query_by_spam_true_values() {
     824                foreach( array( true, 'true', 1, '1' ) as $value ) {
     825                        $q = new WP_Site_Query();
     826                        $found = $q->query( array(
     827                                'spam'  => $value,
     828                        ) );
     829                        $this->assertContains( ' spam = 1 ', $q->request );
     830                }
     831        }
     832
     833        /**
     834         * @ticket 37937
     835         */
     836        public function test_wp_site_query_by_spam_false_values() {
     837                foreach( array( false, 'false', 0, '0' ) as $value ) {
     838                        $q = new WP_Site_Query();
     839                        $found = $q->query( array(
     840                                'spam'  => $value,
     841                        ) );
     842                        $this->assertContains( ' spam = 0 ', $q->request );
     843                }
     844        }
     845
     846        /**
     847         * @ticket 37937
     848         */
     849        public function test_wp_site_query_by_deleted_true_values() {
     850                foreach( array( true, 'true', 1, '1' ) as $value ) {
     851                        $q = new WP_Site_Query();
     852                        $found = $q->query( array(
     853                                'deleted'  => $value,
     854                        ) );
     855                        $this->assertContains( ' deleted = 1 ', $q->request );
     856                }
     857        }
     858
     859        /**
     860         * @ticket 37937
     861         */
     862        public function test_wp_site_query_by_deleted_false_values() {
     863                foreach( array( false, 'false', 0, '0' ) as $value ) {
     864                        $q = new WP_Site_Query();
     865                        $found = $q->query( array(
     866                                'deleted'  => $value,
     867                        ) );
     868                        $this->assertContains( ' deleted = 0 ', $q->request );
     869                }
     870        }
    740871}
    741872
    742873endif;