WordPress.org

Make WordPress Core

Ticket #50343: 50343-required-parameters-before-optional.patch

File 50343-required-parameters-before-optional.patch, 4.5 KB (added by jrf, 16 months ago)
  • src/wp-includes/blocks.php

    From 9e46e1db2e8cce6bcb4618ac1497833cf84dfa13 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Tue, 11 Aug 2020 05:47:55 +0200
    Subject: [PATCH] PHP 8.0: required parameters are no longer allowed after
     optional parameters
    
    As it already wasn't possible to pass the required parameters without also passing the optional one anyway, I'm removing the default value for the (not so) optional parameters and documenting the expected value to "skip" the parameter in the docblock instead.
    ---
     src/wp-includes/blocks.php                                | 8 ++++----
     src/wp-includes/functions.php                             | 6 ++++--
     src/wp-includes/nav-menu.php                              | 5 +++--
     .../tests/rest-api/rest-attachments-controller.php        | 2 +-
     4 files changed, 12 insertions(+), 9 deletions(-)
    
    diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php
    index dfe642ab82..91d0bd4421 100644
    a b function strip_core_block_namespace( $block_name = null ) { 
    397397 *
    398398 * @since 5.3.1
    399399 *
    400  * @param string $block_name       Block name.
    401  * @param array  $block_attributes Block attributes.
    402  * @param string $block_content    Block save content.
     400 * @param string|null $block_name       Block name.
     401 * @param array       $block_attributes Block attributes.
     402 * @param string      $block_content    Block save content.
    403403 * @return string Comment-delimited block content.
    404404 */
    405 function get_comment_delimited_block_content( $block_name = null, $block_attributes, $block_content ) {
     405function get_comment_delimited_block_content( $block_name, $block_attributes, $block_content ) {
    406406        if ( is_null( $block_name ) ) {
    407407                return $block_content;
    408408        }
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 863268c7bd..cf1d8462ab 100644
    a b function wp_extract_urls( $content ) { 
    830830 * @since 1.5.0
    831831 * @since 5.3.0 The `$content` parameter was made optional, and the `$post` parameter was
    832832 *              updated to accept a post ID or a WP_Post object.
     833 * @since 5.6.0 The `$content` parameter is no longer optional, but passing `null` to skip
     834 *              it is still supported.
    833835 *
    834836 * @global wpdb $wpdb WordPress database abstraction object.
    835837 *
    836  * @param string      $content Post content. If `null`, the `post_content` field from `$post` is used.
     838 * @param string|null $content Post content. If `null`, the `post_content` field from `$post` is used.
    837839 * @param int|WP_Post $post    Post ID or post object.
    838840 * @return null|bool Returns false if post is not found.
    839841 */
    840 function do_enclose( $content = null, $post ) {
     842function do_enclose( $content, $post ) {
    841843        global $wpdb;
    842844
    843845        // @todo Tidy this code and make the debug code optional.
  • src/wp-includes/nav-menu.php

    diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php
    index 1881b54247..d8ef881077 100644
    a b function _wp_delete_post_menu_item( $object_id = 0 ) { 
    10531053 * @since 3.0.0
    10541054 * @access private
    10551055 *
    1056  * @param int    $object_id Optional. The ID of the original object being trashed. Default 0.
     1056 * @param int    $object_id The ID of the original object being trashed.
     1057 *                          Pass the integer 0 if the object id is unknown.
    10571058 * @param int    $tt_id     Term taxonomy ID. Unused.
    10581059 * @param string $taxonomy  Taxonomy slug.
    10591060 */
    1060 function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
     1061function _wp_delete_tax_menu_item( $object_id, $tt_id, $taxonomy ) {
    10611062        $object_id = (int) $object_id;
    10621063
    10631064        $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );
  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
    index bd4ebbf6d0..09297129f4 100644
    a b class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 
    15691569                $this->assertArrayNotHasKey( 'https://api.w.org/action-publish', $links );
    15701570        }
    15711571
    1572         protected function check_post_data( $attachment, $data, $context = 'view', $links ) {
     1572        protected function check_post_data( $attachment, $data, $context = 'view', $links = array() ) {
    15731573                parent::check_post_data( $attachment, $data, $context, $links );
    15741574
    15751575                $this->assertArrayNotHasKey( 'content', $data );