Skip to content
Permalink
Browse files

Port all remaining WP changes for PHP 7.3 compatibility (#359)

Closes #263.
----

* WP-r43975: Build/Test Tools: Use 7.3 for PHP 7.3

Travis now supports PHP7.3 without workarounds, so let's remove the workarounds.

Merges https://core.trac.wordpress.org/changeset/43726 to trunk.

See https://core.trac.wordpress.org/ticket/44771.

Conflicts:
  .travis.yml
----
Merges https://core.trac.wordpress.org/changeset/43975 / WordPress/wordpress-develop@b4d7e7a to ClassicPress.

* WP-r43819: 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.

WP:Props desrosj.
Fixes https://core.trac.wordpress.org/ticket/44416.

----
Merges https://core.trac.wordpress.org/changeset/43819 / WordPress/wordpress-develop@5a3ad21 to ClassicPress.

* WP-r43899: Nav Menus: Fix a PHP 7.3 error when switching themes.

When switching themes, `wp_map_nav_menu_locations()` is used to ensure nav menus are placed in the relevant menu location. Occasionally, menus are registered to locations with numeric slugs, rather than strings. `wp_map_nav_menu_locations()` assumed it would be the latter, and ran `stripos()` on those numeric slugs. This behaviour is deprecated in PHP 7.3.

As this is the last known PHP 7.3 incompatibility, this commit also removes PHP 7.3 from Travis' `allowed_failures` list.

WP:Props desrosj, jorbin.
See https://core.trac.wordpress.org/ticket/45018.

----
Merges https://core.trac.wordpress.org/changeset/43899 / WordPress/wordpress-develop@61ee6d9 to ClassicPress.

* Fix whitespace errors

* WP-r44186: Networks and Sites: Fix incorrect variable location.

This fixes an issue introduced in https://core.trac.wordpress.org/changeset/44166 where the `$groupby` variable was inserted too low in the `get_site_ids()` function while merging https://core.trac.wordpress.org/changeset/43832 into `trunk`. The merged location did not account for a new conditional statement that existed only in `trunk`, and would have resulted in values assigned to `$groupby` being erased in certain scenarios.

WP:Props spacedmonkey.

See https://core.trac.wordpress.org/ticket/44416.
Fixes https://core.trac.wordpress.org/ticket/45582.

----
Merges https://core.trac.wordpress.org/changeset/44186 / WordPress/wordpress-develop@7f23254 to ClassicPress.
  • Loading branch information...
nylen committed Feb 15, 2019
1 parent 28b0fe9 commit dc1ce212eb997e6ce3d2dd70e96c99286b1fad24
@@ -14,6 +14,7 @@ matrix:
include:
- php: 7.1
env: WP_TRAVISCI=travis:precommit-and-js
- php: 7.3
- php: 7.2
- php: 7.1
- php: 7.0
@@ -51,7 +52,7 @@ before_script:
- |
# Install the specified version of PHPUnit depending on the PHP version:
case "$TRAVIS_PHP_VERSION" in
7.2|7.1|7.0|nightly)
7.3|7.2|7.1|7.0|nightly)
echo "Using PHPUnit 6.x"
composer global require "phpunit/phpunit:^6"
;;
@@ -633,6 +633,7 @@ protected function get_comment_ids() {
$number = absint( $this->query_vars['number'] );
$offset = absint( $this->query_vars['offset'] );
$paged = absint( $this->query_vars['paged'] );
$limits = '';
if ( ! empty( $number ) ) {
if ( $offset ) {
@@ -817,7 +818,8 @@ protected function get_comment_ids() {
$this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )';
}
$join = '';
$join = '';
$groupby = '';
if ( $join_posts_table ) {
$join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
@@ -522,12 +522,11 @@ protected function get_site_ids() {
$this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
}
$join = '';
$join = '';
$groupby = '';
$where = implode( ' AND ', $this->sql_clauses['where'] );
$groupby = '';
$pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
/**
@@ -3517,38 +3517,44 @@ public function wp_editComment( $args ) {
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.editComment' );
$comment = array(
'comment_ID' => $comment_ID,
);
if ( isset($content_struct['status']) ) {
$statuses = get_comment_statuses();
$statuses = array_keys($statuses);
if ( ! in_array($content_struct['status'], $statuses) )
return new IXR_Error( 401, __( 'Invalid comment status.' ) );
$comment_approved = $content_struct['status'];
$comment['comment_approved'] = $content_struct['status'];
}
// Do some timestamp voodoo
if ( !empty( $content_struct['date_created_gmt'] ) ) {
// We know this is supposed to be GMT, so we're going to slap that Z on there by force
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
$comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
$comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
}
if ( isset($content_struct['content']) )
$comment_content = $content_struct['content'];
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
$comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
$comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
}
if ( isset($content_struct['author']) )
$comment_author = $content_struct['author'];
if ( isset($content_struct['content']) ) {
$comment['comment_content'] = $content_struct['content'];
}
if ( isset($content_struct['author_url']) )
$comment_author_url = $content_struct['author_url'];
if ( isset($content_struct['author']) ) {
$comment['comment_author'] = $content_struct['author'];
}
if ( isset($content_struct['author_email']) )
$comment_author_email = $content_struct['author_email'];
if ( isset($content_struct['author_url']) ) {
$comment['comment_author_url'] = $content_struct['author_url'];
}
// We've got all the data -- post it:
$comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
if ( isset($content_struct['author_email']) ) {
$comment['comment_author_email'] = $content_struct['author_email'];
}
$result = wp_update_comment($comment);
if ( is_wp_error( $result ) )
@@ -4989,16 +4995,25 @@ public function mw_newPost($args) {
$post_name = $content_struct['wp_slug'];
// Only use a password if one was given.
if ( isset($content_struct['wp_password']) )
if ( isset($content_struct['wp_password']) ) {
$post_password = $content_struct['wp_password'];
} else {
$post_password = '';
}
// Only set a post parent if one was provided.
if ( isset($content_struct['wp_page_parent_id']) )
if ( isset($content_struct['wp_page_parent_id']) ) {
$post_parent = $content_struct['wp_page_parent_id'];
} else {
$post_parent = 0;
}
// Only set the menu_order if it was provided.
if ( isset($content_struct['wp_page_order']) )
if ( isset($content_struct['wp_page_order']) ) {
$menu_order = $content_struct['wp_page_order'];
} else {
$menu_order = 0;
}
$post_author = $user->ID;
@@ -5308,14 +5323,16 @@ public function mw_editPost( $args ) {
$this->escape($postdata);
$ID = $postdata['ID'];
$post_content = $postdata['post_content'];
$post_title = $postdata['post_title'];
$post_excerpt = $postdata['post_excerpt'];
$post_password = $postdata['post_password'];
$post_parent = $postdata['post_parent'];
$post_type = $postdata['post_type'];
$menu_order = $postdata['menu_order'];
$ID = $postdata['ID'];
$post_content = $postdata['post_content'];
$post_title = $postdata['post_title'];
$post_excerpt = $postdata['post_excerpt'];
$post_password = $postdata['post_password'];
$post_parent = $postdata['post_parent'];
$post_type = $postdata['post_type'];
$menu_order = $postdata['menu_order'];
$ping_status = $postdata['ping_status'];
$comment_status = $postdata['comment_status'];
// Let ClassicPress manage slug if none was provided.
$post_name = $postdata['post_name'];
@@ -2977,7 +2977,7 @@ function _close_comments_for_old_post( $open, $post_id ) {
*/
function wp_handle_comment_submission( $comment_data ) {
$comment_post_ID = $comment_parent = 0;
$comment_post_ID = $comment_parent = $user_ID = 0;
$comment_author = $comment_author_email = $comment_author_url = $comment_content = null;
if ( isset( $comment_data['comment_post_ID'] ) ) {
@@ -1139,7 +1139,9 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat
foreach ( $registered_nav_menus as $new_location => $name ) {
// ...actually match!
if ( false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
if ( is_string( $new_location ) && false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
continue;
} elseif ( is_numeric( $new_location ) && $new_location !== $slug ) {
continue;
}
@@ -1150,7 +1152,9 @@ function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locat
foreach ( $slug_group as $slug ) {
// ... have a match as well.
if ( false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
if ( is_string( $location ) && false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
continue;
} elseif ( is_numeric( $location ) && $location !== $slug ) {
continue;
}
@@ -3374,6 +3374,13 @@ function wp_insert_post( $postarr, $wp_error = false ) {
$post_parent = 0;
}
$new_postarr = array_merge(
array(
'ID' => $post_ID,
),
compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
);
/**
* Filters the post parent -- used to check for and prevent hierarchy loops.
*
@@ -3384,7 +3391,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
* @param array $new_postarr Array of parsed post data.
* @param array $postarr Array of sanitized, but otherwise unmodified post data.
*/
$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, $new_postarr, $postarr );
/*
* If the post is being untrashed and it has a desired slug stored in post meta,
@@ -960,6 +960,7 @@ public function test_wp_enqueue_code_editor_when_php_file_will_be_passed() {
* @covers wp_enqueue_code_editor()
*/
public function test_wp_enqueue_code_editor_when_generated_array_by_compact_will_be_passed() {
$file = '';
$wp_enqueue_code_editor = wp_enqueue_code_editor( compact( 'file' ) );
$this->assertNonEmptyMultidimensionalArray( $wp_enqueue_code_editor );
@@ -200,4 +200,29 @@ function test_numerical_locations() {
);
$this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
/**
* Technically possible old nav menu locations were registered numerically.
*
* @covers wp_map_nav_menu_locations()
*/
public function test_numerical_old_locations() {
$this->register_nav_menu_locations( array( 'primary', 1 ) );
$old_nav_menu_locations = array(
'primary' => 1,
'tertiary' => 2,
0 => 3,
);
$next_theme_nav_menu_locations = array();
$new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $next_theme_nav_menu_locations, $old_nav_menu_locations );
$expected_nav_menu_locations = array(
'primary' => 1,
0 => 3,
);
$this->assertEqualSets( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
}

0 comments on commit dc1ce21

Please sign in to comment.
You can’t perform that action at this time.