diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index a04de73bd64e4..3cda30f0d523f 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -128,7 +128,7 @@ function wp_ajax_ajax_tag_search() { if ( str_contains( $search, ',' ) ) { $search = explode( ',', $search ); - $search = $search[ count( $search ) - 1 ]; + $search = array_last( $search ); } $search = trim( $search ); diff --git a/src/wp-includes/class-wp-block-parser.php b/src/wp-includes/class-wp-block-parser.php index 8c619a7b47f2c..ea66e3b51d38d 100644 --- a/src/wp-includes/class-wp-block-parser.php +++ b/src/wp-includes/class-wp-block-parser.php @@ -342,7 +342,7 @@ public function add_freeform( $length = null ) { * @param int|null $last_offset Last byte offset into document if continuing form earlier output. */ public function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { - $parent = $this->stack[ count( $this->stack ) - 1 ]; + $parent = $this->stack[ array_key_last( $this->stack ) ]; $parent->block->innerBlocks[] = (array) $block; $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 244cf84e9b810..fc698b343e138 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -2430,11 +2430,12 @@ public function get_posts() { if ( '' !== $query_vars['author_name'] ) { if ( str_contains( $query_vars['author_name'], '/' ) ) { - $query_vars['author_name'] = explode( '/', $query_vars['author_name'] ); - if ( $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ] ) { - $query_vars['author_name'] = $query_vars['author_name'][ count( $query_vars['author_name'] ) - 1 ]; // No trailing slash. + $author_name_parts = explode( '/', $query_vars['author_name'] ); + $last_part = array_last( $author_name_parts ); + if ( $last_part ) { + $query_vars['author_name'] = $last_part; // No trailing slash. } else { - $query_vars['author_name'] = $query_vars['author_name'][ count( $query_vars['author_name'] ) - 2 ]; // There was a trailing slash. + $query_vars['author_name'] = $author_name_parts[ count( $author_name_parts ) - 2 ]; // There was a trailing slash. } } $query_vars['author_name'] = sanitize_title_for_query( $query_vars['author_name'] ); diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 82b8e89de509c..7e2cb54731b1f 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3994,7 +3994,7 @@ public function get_styles_for_block( $block_metadata ) { */ $is_processing_element = in_array( 'elements', $block_metadata['path'], true ); - $current_element = $is_processing_element ? $block_metadata['path'][ count( $block_metadata['path'] ) - 1 ] : null; + $current_element = $is_processing_element ? array_last( $block_metadata['path'] ) : null; $element_pseudo_allowed = array(); @@ -4688,7 +4688,7 @@ public static function remove_insecure_properties( $theme_json, $origin = 'theme * Get a reference to element name from path. * $metadata['path'] = array( 'styles', 'elements', 'link' ); */ - $current_element = $metadata['path'][ count( $metadata['path'] ) - 1 ]; + $current_element = array_last( $metadata['path'] ); /* * $output is stripped of pseudo selectors. Re-add and process them diff --git a/src/wp-includes/pomo/plural-forms.php b/src/wp-includes/pomo/plural-forms.php index a604334e88c20..cc31471a0b88d 100644 --- a/src/wp-includes/pomo/plural-forms.php +++ b/src/wp-includes/pomo/plural-forms.php @@ -128,7 +128,7 @@ protected function parse( $str ) { case ')': $found = false; while ( ! empty( $stack ) ) { - $o2 = $stack[ count( $stack ) - 1 ]; + $o2 = array_last( $stack ); if ( '(' !== $o2 ) { $output[] = array( 'op', array_pop( $stack ) ); continue; @@ -163,7 +163,7 @@ protected function parse( $str ) { } while ( ! empty( $stack ) ) { - $o2 = $stack[ count( $stack ) - 1 ]; + $o2 = array_last( $stack ); // Ternary is right-associative in C. if ( '?:' === $operator || '?' === $operator ) { diff --git a/src/wp-trackback.php b/src/wp-trackback.php index 76c2a1d4a7285..c666c13e8b823 100644 --- a/src/wp-trackback.php +++ b/src/wp-trackback.php @@ -50,7 +50,7 @@ function trackback_response( $error = 0, $error_message = '' ) { if ( ! isset( $_GET['tb_id'] ) || ! $_GET['tb_id'] ) { $post_id = explode( '/', $_SERVER['REQUEST_URI'] ); - $post_id = (int) $post_id[ count( $post_id ) - 1 ]; + $post_id = (int) array_last( $post_id ); } $trackback_url = isset( $_POST['url'] ) ? sanitize_url( $_POST['url'] ) : '';