Make WordPress Core

Changeset 43819


Ignore:
Timestamp:
10/24/2018 04:32:29 PM (8 years ago)
Author:
jorbin
Message:

php7.3 compatibility: Fix compact throwing notices

In PHP 7.3, the compact() function has been changed to issue an E_NOTICE level error if a passed string refers to an unset variable. In previous versions of PHP, this notice was silently skipped. The full RFC can be viewed here: https://wiki.php.net/rfc/compact

This fixes all unit tested code that uses compact.

Props desrosj.
Fixes #44416.

Location:
branches/5.0
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/class-wp-comment-query.php

    r41686 r43819  
    634634                $offset = absint( $this->query_vars['offset'] );
    635635                $paged = absint( $this->query_vars['paged'] );
     636                $limits = '';
    636637
    637638                if ( ! empty( $number ) ) {
     
    818819                }
    819820
    820                 $join = '';
     821                $join    = '';
     822                $groupby = '';
    821823
    822824                if ( $join_posts_table ) {
  • branches/5.0/src/wp-includes/class-wp-xmlrpc-server.php

    r42811 r43819  
    35183518                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    35193519                do_action( 'xmlrpc_call', 'wp.editComment' );
     3520                $comment = array(
     3521                        'comment_ID' => $comment_ID,
     3522                );
     3523
    35203524
    35213525                if ( isset($content_struct['status']) ) {
     
    35253529                        if ( ! in_array($content_struct['status'], $statuses) )
    35263530                                return new IXR_Error( 401, __( 'Invalid comment status.' ) );
    3527                         $comment_approved = $content_struct['status'];
     3531                        $comment['comment_approved'] = $content_struct['status'];
    35283532                }
    35293533
     
    35313535                if ( !empty( $content_struct['date_created_gmt'] ) ) {
    35323536                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    3533                         $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    3534                         $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    3535                         $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
    3536                 }
    3537 
    3538                 if ( isset($content_struct['content']) )
    3539                         $comment_content = $content_struct['content'];
    3540 
    3541                 if ( isset($content_struct['author']) )
    3542                         $comment_author = $content_struct['author'];
    3543 
    3544                 if ( isset($content_struct['author_url']) )
    3545                         $comment_author_url = $content_struct['author_url'];
    3546 
    3547                 if ( isset($content_struct['author_email']) )
    3548                         $comment_author_email = $content_struct['author_email'];
    3549 
    3550                 // We've got all the data -- post it:
    3551                 $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
     3537
     3538                        $dateCreated                 = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
     3539                        $comment['comment_date']     = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
     3540                        $comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
     3541                }
     3542
     3543                if ( isset($content_struct['content']) ) {
     3544                        $comment['comment_content'] = $content_struct['content'];
     3545                }
     3546
     3547                if ( isset($content_struct['author']) ) {
     3548                        $comment['comment_author'] = $content_struct['author'];
     3549                }
     3550
     3551                if ( isset($content_struct['author_url']) ) {
     3552                        $comment['comment_author_url'] = $content_struct['author_url'];
     3553                }
     3554
     3555                if ( isset($content_struct['author_email']) ) {
     3556                        $comment['comment_author_email'] = $content_struct['author_email'];
     3557                }
    35523558
    35533559                $result = wp_update_comment($comment);
     
    49904996
    49914997                // Only use a password if one was given.
    4992                 if ( isset($content_struct['wp_password']) )
     4998                if ( isset($content_struct['wp_password']) ) {
    49934999                        $post_password = $content_struct['wp_password'];
     5000                } else {
     5001                        $post_password = '';
     5002                }
    49945003
    49955004                // Only set a post parent if one was provided.
    4996                 if ( isset($content_struct['wp_page_parent_id']) )
     5005                if ( isset($content_struct['wp_page_parent_id']) ) {
    49975006                        $post_parent = $content_struct['wp_page_parent_id'];
     5007                } else {
     5008                        $post_parent = 0;
     5009                }
    49985010
    49995011                // Only set the menu_order if it was provided.
    5000                 if ( isset($content_struct['wp_page_order']) )
     5012                if ( isset($content_struct['wp_page_order']) ) {
    50015013                        $menu_order = $content_struct['wp_page_order'];
     5014                } else {
     5015                        $menu_order = 0;
     5016                }
    50025017
    50035018                $post_author = $user->ID;
     
    53095324                $this->escape($postdata);
    53105325
    5311                 $ID = $postdata['ID'];
    5312                 $post_content = $postdata['post_content'];
    5313                 $post_title = $postdata['post_title'];
    5314                 $post_excerpt = $postdata['post_excerpt'];
    5315                 $post_password = $postdata['post_password'];
    5316                 $post_parent = $postdata['post_parent'];
    5317                 $post_type = $postdata['post_type'];
    5318                 $menu_order = $postdata['menu_order'];
     5326                $ID             = $postdata['ID'];
     5327                $post_content   = $postdata['post_content'];
     5328                $post_title     = $postdata['post_title'];
     5329                $post_excerpt   = $postdata['post_excerpt'];
     5330                $post_password  = $postdata['post_password'];
     5331                $post_parent    = $postdata['post_parent'];
     5332                $post_type      = $postdata['post_type'];
     5333                $menu_order     = $postdata['menu_order'];
     5334                $ping_status    = $postdata['ping_status'];
     5335                $comment_status = $postdata['comment_status'];
    53195336
    53205337                // Let WordPress manage slug if none was provided.
  • branches/5.0/src/wp-includes/comment.php

    r43729 r43819  
    29662966function wp_handle_comment_submission( $comment_data ) {
    29672967
    2968         $comment_post_ID = $comment_parent = 0;
     2968        $comment_post_ID = $comment_parent = $user_ID = 0;
    29692969        $comment_author = $comment_author_email = $comment_author_url = $comment_content = null;
    29702970
  • branches/5.0/src/wp-includes/post.php

    r43806 r43819  
    34163416        }
    34173417
     3418        $new_postarr = array_merge(
     3419                array(
     3420                        'ID' => $post_ID,
     3421                ),
     3422                compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
     3423        );
     3424
    34183425        /**
    34193426         * Filters the post parent -- used to check for and prevent hierarchy loops.
     
    34263433         * @param array $postarr     Array of sanitized, but otherwise unmodified post data.
    34273434         */
    3428         $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
     3435        $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, $new_postarr, $postarr );
    34293436
    34303437        /*
  • branches/5.0/tests/phpunit/tests/dependencies/scripts.php

    r43788 r43819  
    862862         */
    863863        public function test_wp_enqueue_code_editor_when_generated_array_by_compact_will_be_passed() {
     864                $file                   = '';
    864865                $wp_enqueue_code_editor = wp_enqueue_code_editor( compact( 'file' ) );
    865866                $this->assertNonEmptyMultidimensionalArray( $wp_enqueue_code_editor );
Note: See TracChangeset for help on using the changeset viewer.