Make WordPress Core

Changeset 57648


Ignore:
Timestamp:
02/17/2024 03:22:37 PM (8 months ago)
Author:
swissspidy
Message:

General: Consistently cast return value to int in functions that use ceil().

The return value of ceil() is still of type float as the value range of float is usually bigger than that of int.

Props crstauf, audrasjb.
Fixes #58683.

Location:
trunk/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r57545 r57648  
    562562                /* translators: %s: Number of comments. */
    563563                'total_items_i18n'     => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
    564                 'total_pages'          => ceil( $total / $per_page ),
    565                 'total_pages_i18n'     => number_format_i18n( ceil( $total / $per_page ) ),
     564                'total_pages'          => (int) ceil( $total / $per_page ),
     565                'total_pages_i18n'     => number_format_i18n( (int) ceil( $total / $per_page ) ),
    566566                'total'                => $total,
    567567                'time'                 => $time,
     
    30903090    $posts_per_page = (int) $attachments_query->get( 'posts_per_page' );
    30913091
    3092     $max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0;
     3092    $max_pages = $posts_per_page ? (int) ceil( $total_posts / $posts_per_page ) : 0;
    30933093
    30943094    header( 'X-WP-Total: ' . (int) $total_posts );
    3095     header( 'X-WP-TotalPages: ' . (int) $max_pages );
     3095    header( 'X-WP-TotalPages: ' . $max_pages );
    30963096
    30973097    wp_send_json_success( $posts );
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r57644 r57648  
    320320
    321321        if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
    322             $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
     322            $args['total_pages'] = (int) ceil( $args['total_items'] / $args['per_page'] );
    323323        }
    324324
  • trunk/src/wp-admin/includes/media.php

    r57524 r57648  
    28332833                'prev_text' => __( '«' ),
    28342834                'next_text' => __( '»' ),
    2835                 'total'     => ceil( $wp_query->found_posts / 10 ),
     2835                'total'     => (int) ceil( $wp_query->found_posts / 10 ),
    28362836                'current'   => $q['paged'],
    28372837            )
  • trunk/src/wp-admin/includes/nav-menu.php

    r56599 r57648  
    875875    }
    876876
    877     $num_pages = ceil(
     877    $num_pages = (int) ceil(
    878878        wp_count_terms(
    879879            array_merge(
  • trunk/src/wp-includes/class-wp-comment-query.php

    r57342 r57648  
    471471
    472472        if ( $this->found_comments && $this->query_vars['number'] ) {
    473             $this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] );
     473            $this->max_num_pages = (int) ceil( $this->found_comments / $this->query_vars['number'] );
    474474        }
    475475
  • trunk/src/wp-includes/class-wp-network-query.php

    r55526 r57648  
    270270
    271271        if ( $this->found_networks && $this->query_vars['number'] ) {
    272             $this->max_num_pages = ceil( $this->found_networks / $this->query_vars['number'] );
     272            $this->max_num_pages = (int) ceil( $this->found_networks / $this->query_vars['number'] );
    273273        }
    274274
  • trunk/src/wp-includes/class-wp-query.php

    r57312 r57648  
    36253625
    36263626        if ( ! empty( $limits ) ) {
    3627             $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
     3627            $this->max_num_pages = (int) ceil( $this->found_posts / $q['posts_per_page'] );
    36283628        }
    36293629    }
  • trunk/src/wp-includes/class-wp-site-query.php

    r57644 r57648  
    378378
    379379        if ( $this->found_sites && $this->query_vars['number'] ) {
    380             $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] );
     380            $this->max_num_pages = (int) ceil( $this->found_sites / $this->query_vars['number'] );
    381381        }
    382382
  • trunk/src/wp-includes/class-wp-walker.php

    r56549 r57648  
    311311            $end    = $start + $per_page;
    312312            if ( -1 == $max_depth ) {
    313                 $this->max_pages = ceil( $total_top / $per_page );
     313                $this->max_pages = (int) ceil( $total_top / $per_page );
    314314            }
    315315        }
     
    355355        $total_top = count( $top_level_elements );
    356356        if ( $paging ) {
    357             $this->max_pages = ceil( $total_top / $per_page );
     357            $this->max_pages = (int) ceil( $total_top / $per_page );
    358358        } else {
    359359            $end = $total_top;
  • trunk/src/wp-includes/comment-template.php

    r56687 r57648  
    15161516            $top_level_count = $top_level_query->query( $top_level_args );
    15171517
    1518             $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
     1518            $comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
    15191519        }
    15201520    }
  • trunk/src/wp-includes/comment.php

    r57644 r57648  
    10321032    }
    10331033
    1034     return $count;
     1034    return (int) $count;
    10351035}
    10361036
     
    11711171            // Divide comments older than this one by comments per page to get this comment's page number.
    11721172        } else {
    1173             $page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
     1173            $page = (int) ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
    11741174        }
    11751175    }
  • trunk/src/wp-includes/embed.php

    r56682 r57648  
    7474    }
    7575
    76     $height = min( ceil( $width * 1.5 ), 1000 );
     76    $height = min( (int) ceil( $width * 1.5 ), 1000 );
    7777
    7878    /**
     
    578578
    579579    $width  = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
    580     $height = max( ceil( $width / 16 * 9 ), 200 );
     580    $height = max( (int) ceil( $width / 16 * 9 ), 200 );
    581581
    582582    $data = array(
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r57176 r57648  
    301301
    302302            $total_comments = $query->query( $prepared_args );
    303             $max_pages      = ceil( $total_comments / $request['per_page'] );
     303            $max_pages      = (int) ceil( $total_comments / $request['per_page'] );
    304304        }
    305305
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php

    r57548 r57648  
    7878        $per_page    = $request['per_page'];
    7979        $total_items = count( $collections_all );
    80         $max_pages   = ceil( $total_items / $per_page );
     80        $max_pages   = (int) ceil( $total_items / $per_page );
    8181
    8282        if ( $page > $max_pages && $total_items > 0 ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php

    r57628 r57648  
    207207
    208208            if ( $revisions_query->query_vars['posts_per_page'] > 0 ) {
    209                 $max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
     209                $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
    210210            } else {
    211211                $max_pages = $total_revisions > 0 ? 1 : 0;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r57603 r57648  
    404404        }
    405405
    406         $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
     406        $max_pages = (int) ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
    407407
    408408        if ( $page > $max_pages && $total_posts > 0 ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r57230 r57648  
    309309
    310310            if ( $revisions_query->query_vars['posts_per_page'] > 0 ) {
    311                 $max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
     311                $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
    312312            } else {
    313313                $max_pages = $total_revisions > 0 ? 1 : 0;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php

    r56586 r57648  
    153153        $page      = (int) $request['page'];
    154154        $per_page  = (int) $request['per_page'];
    155         $max_pages = ceil( $total / $per_page );
     155        $max_pages = (int) ceil( $total / $per_page );
    156156
    157157        if ( $page > $max_pages && $total > 0 ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r56415 r57648  
    349349        // Store pagination values for headers.
    350350        $per_page = (int) $prepared_args['number'];
    351         $page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
     351        $page     = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
    352352
    353353        $response->header( 'X-WP-Total', (int) $total_terms );
    354354
    355         $max_pages = ceil( $total_terms / $per_page );
    356 
    357         $response->header( 'X-WP-TotalPages', (int) $max_pages );
     355        $max_pages = (int) ceil( $total_terms / $per_page );
     356
     357        $response->header( 'X-WP-TotalPages', $max_pages );
    358358
    359359        $request_params = $request->get_query_params();
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r56833 r57648  
    349349        // Store pagination values for headers then unset for count query.
    350350        $per_page = (int) $prepared_args['number'];
    351         $page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
     351        $page     = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
    352352
    353353        $prepared_args['fields'] = 'ID';
     
    364364        $response->header( 'X-WP-Total', (int) $total_users );
    365365
    366         $max_pages = ceil( $total_users / $per_page );
    367 
    368         $response->header( 'X-WP-TotalPages', (int) $max_pages );
     366        $max_pages = (int) ceil( $total_users / $per_page );
     367
     368        $response->header( 'X-WP-TotalPages', $max_pages );
    369369
    370370        $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
Note: See TracChangeset for help on using the changeset viewer.