Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.
Note: See TracChangeset for help on using the changeset viewer.