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.
Built from https://develop.svn.wordpress.org/trunk@57648


git-svn-id: http://core.svn.wordpress.org/trunk@57149 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-02-17 15:24:08 +00:00
parent 0ab7276020
commit f97698702d
21 changed files with 31 additions and 31 deletions

View File

@ -561,8 +561,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
'postId' => $comment ? $comment->comment_post_ID : '', 'postId' => $comment ? $comment->comment_post_ID : '',
/* translators: %s: Number of comments. */ /* translators: %s: Number of comments. */
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
'total_pages' => ceil( $total / $per_page ), 'total_pages' => (int) ceil( $total / $per_page ),
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), 'total_pages_i18n' => number_format_i18n( (int) ceil( $total / $per_page ) ),
'total' => $total, 'total' => $total,
'time' => $time, 'time' => $time,
'in_moderation' => $counts->moderated, 'in_moderation' => $counts->moderated,
@ -3089,10 +3089,10 @@ function wp_ajax_query_attachments() {
$posts_per_page = (int) $attachments_query->get( 'posts_per_page' ); $posts_per_page = (int) $attachments_query->get( 'posts_per_page' );
$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0; $max_pages = $posts_per_page ? (int) ceil( $total_posts / $posts_per_page ) : 0;
header( 'X-WP-Total: ' . (int) $total_posts ); header( 'X-WP-Total: ' . (int) $total_posts );
header( 'X-WP-TotalPages: ' . (int) $max_pages ); header( 'X-WP-TotalPages: ' . $max_pages );
wp_send_json_success( $posts ); wp_send_json_success( $posts );
} }

View File

@ -319,7 +319,7 @@ class WP_List_Table {
); );
if ( ! $args['total_pages'] && $args['per_page'] > 0 ) { if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); $args['total_pages'] = (int) ceil( $args['total_items'] / $args['per_page'] );
} }
// Redirect if page number is invalid and headers are not already sent. // Redirect if page number is invalid and headers are not already sent.

View File

@ -2832,7 +2832,7 @@ function media_upload_library_form( $errors ) {
'format' => '', 'format' => '',
'prev_text' => __( '«' ), 'prev_text' => __( '«' ),
'next_text' => __( '»' ), 'next_text' => __( '»' ),
'total' => ceil( $wp_query->found_posts / 10 ), 'total' => (int) ceil( $wp_query->found_posts / 10 ),
'current' => $q['paged'], 'current' => $q['paged'],
) )
); );

View File

@ -874,7 +874,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) {
return; return;
} }
$num_pages = ceil( $num_pages = (int) ceil(
wp_count_terms( wp_count_terms(
array_merge( array_merge(
$args, $args,

View File

@ -470,7 +470,7 @@ class WP_Comment_Query {
} }
if ( $this->found_comments && $this->query_vars['number'] ) { if ( $this->found_comments && $this->query_vars['number'] ) {
$this->max_num_pages = ceil( $this->found_comments / $this->query_vars['number'] ); $this->max_num_pages = (int) ceil( $this->found_comments / $this->query_vars['number'] );
} }
// If querying for a count only, there's nothing more to do. // If querying for a count only, there's nothing more to do.

View File

@ -269,7 +269,7 @@ class WP_Network_Query {
} }
if ( $this->found_networks && $this->query_vars['number'] ) { if ( $this->found_networks && $this->query_vars['number'] ) {
$this->max_num_pages = ceil( $this->found_networks / $this->query_vars['number'] ); $this->max_num_pages = (int) ceil( $this->found_networks / $this->query_vars['number'] );
} }
// If querying for a count only, there's nothing more to do. // If querying for a count only, there's nothing more to do.

View File

@ -3624,7 +3624,7 @@ class WP_Query {
$this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); $this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
if ( ! empty( $limits ) ) { if ( ! empty( $limits ) ) {
$this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); $this->max_num_pages = (int) ceil( $this->found_posts / $q['posts_per_page'] );
} }
} }

View File

@ -377,7 +377,7 @@ class WP_Site_Query {
} }
if ( $this->found_sites && $this->query_vars['number'] ) { if ( $this->found_sites && $this->query_vars['number'] ) {
$this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); $this->max_num_pages = (int) ceil( $this->found_sites / $this->query_vars['number'] );
} }
// If querying for a count only, there's nothing more to do. // If querying for a count only, there's nothing more to do.

View File

@ -310,7 +310,7 @@ class Walker {
$start = ( (int) $page_num - 1 ) * (int) $per_page; $start = ( (int) $page_num - 1 ) * (int) $per_page;
$end = $start + $per_page; $end = $start + $per_page;
if ( -1 == $max_depth ) { if ( -1 == $max_depth ) {
$this->max_pages = ceil( $total_top / $per_page ); $this->max_pages = (int) ceil( $total_top / $per_page );
} }
} }
@ -354,7 +354,7 @@ class Walker {
$total_top = count( $top_level_elements ); $total_top = count( $top_level_elements );
if ( $paging ) { if ( $paging ) {
$this->max_pages = ceil( $total_top / $per_page ); $this->max_pages = (int) ceil( $total_top / $per_page );
} else { } else {
$end = $total_top; $end = $total_top;
} }

View File

@ -1515,7 +1515,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$top_level_count = $top_level_query->query( $top_level_args ); $top_level_count = $top_level_query->query( $top_level_args );
$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; $comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
} }
} }

View File

@ -1031,7 +1031,7 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded
$count = ceil( count( $comments ) / $per_page ); $count = ceil( count( $comments ) / $per_page );
} }
return $count; return (int) $count;
} }
/** /**
@ -1170,7 +1170,7 @@ function get_page_of_comment( $comment_id, $args = array() ) {
// Divide comments older than this one by comments per page to get this comment's page number. // Divide comments older than this one by comments per page to get this comment's page number.
} else { } else {
$page = ceil( ( $older_comment_count + 1 ) / $args['per_page'] ); $page = (int) ceil( ( $older_comment_count + 1 ) / $args['per_page'] );
} }
} }

View File

@ -73,7 +73,7 @@ function wp_embed_defaults( $url = '' ) {
$width = 500; $width = 500;
} }
$height = min( ceil( $width * 1.5 ), 1000 ); $height = min( (int) ceil( $width * 1.5 ), 1000 );
/** /**
* Filters the default array of embed dimensions. * Filters the default array of embed dimensions.
@ -577,7 +577,7 @@ function get_oembed_response_data( $post, $width ) {
); );
$width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] );
$height = max( ceil( $width / 16 * 9 ), 200 ); $height = max( (int) ceil( $width / 16 * 9 ), 200 );
$data = array( $data = array(
'version' => '1.0', 'version' => '1.0',

View File

@ -300,7 +300,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
$prepared_args['orderby'] = 'none'; $prepared_args['orderby'] = 'none';
$total_comments = $query->query( $prepared_args ); $total_comments = $query->query( $prepared_args );
$max_pages = ceil( $total_comments / $request['per_page'] ); $max_pages = (int) ceil( $total_comments / $request['per_page'] );
} }
$response = rest_ensure_response( $comments ); $response = rest_ensure_response( $comments );

View File

@ -77,7 +77,7 @@ class WP_REST_Font_Collections_Controller extends WP_REST_Controller {
$page = $request['page']; $page = $request['page'];
$per_page = $request['per_page']; $per_page = $request['per_page'];
$total_items = count( $collections_all ); $total_items = count( $collections_all );
$max_pages = ceil( $total_items / $per_page ); $max_pages = (int) ceil( $total_items / $per_page );
if ( $page > $max_pages && $total_items > 0 ) { if ( $page > $max_pages && $total_items > 0 ) {
return new WP_Error( return new WP_Error(

View File

@ -206,7 +206,7 @@ class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Controller {
} }
if ( $revisions_query->query_vars['posts_per_page'] > 0 ) { if ( $revisions_query->query_vars['posts_per_page'] > 0 ) {
$max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
} else { } else {
$max_pages = $total_revisions > 0 ? 1 : 0; $max_pages = $total_revisions > 0 ? 1 : 0;
} }

View File

@ -403,7 +403,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
$total_posts = $count_query->found_posts; $total_posts = $count_query->found_posts;
} }
$max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] ); $max_pages = (int) ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
if ( $page > $max_pages && $total_posts > 0 ) { if ( $page > $max_pages && $total_posts > 0 ) {
return new WP_Error( return new WP_Error(

View File

@ -308,7 +308,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
} }
if ( $revisions_query->query_vars['posts_per_page'] > 0 ) { if ( $revisions_query->query_vars['posts_per_page'] > 0 ) {
$max_pages = ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] );
} else { } else {
$max_pages = $total_revisions > 0 ? 1 : 0; $max_pages = $total_revisions > 0 ? 1 : 0;
} }

View File

@ -152,7 +152,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
$total = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ]; $total = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ];
$page = (int) $request['page']; $page = (int) $request['page'];
$per_page = (int) $request['per_page']; $per_page = (int) $request['per_page'];
$max_pages = ceil( $total / $per_page ); $max_pages = (int) ceil( $total / $per_page );
if ( $page > $max_pages && $total > 0 ) { if ( $page > $max_pages && $total > 0 ) {
return new WP_Error( return new WP_Error(

View File

@ -348,13 +348,13 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
// Store pagination values for headers. // Store pagination values for headers.
$per_page = (int) $prepared_args['number']; $per_page = (int) $prepared_args['number'];
$page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); $page = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
$response->header( 'X-WP-Total', (int) $total_terms ); $response->header( 'X-WP-Total', (int) $total_terms );
$max_pages = ceil( $total_terms / $per_page ); $max_pages = (int) ceil( $total_terms / $per_page );
$response->header( 'X-WP-TotalPages', (int) $max_pages ); $response->header( 'X-WP-TotalPages', $max_pages );
$request_params = $request->get_query_params(); $request_params = $request->get_query_params();
$collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) ); $collection_url = rest_url( rest_get_route_for_taxonomy_items( $this->taxonomy ) );

View File

@ -348,7 +348,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
// Store pagination values for headers then unset for count query. // Store pagination values for headers then unset for count query.
$per_page = (int) $prepared_args['number']; $per_page = (int) $prepared_args['number'];
$page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); $page = (int) ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
$prepared_args['fields'] = 'ID'; $prepared_args['fields'] = 'ID';
@ -363,9 +363,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
$response->header( 'X-WP-Total', (int) $total_users ); $response->header( 'X-WP-Total', (int) $total_users );
$max_pages = ceil( $total_users / $per_page ); $max_pages = (int) ceil( $total_users / $per_page );
$response->header( 'X-WP-TotalPages', (int) $max_pages ); $response->header( 'X-WP-TotalPages', $max_pages );
$base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
if ( $page > 1 ) { if ( $page > 1 ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-beta1-57647'; $wp_version = '6.5-beta1-57648';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.