Make WordPress Core

Opened 9 years ago

Last modified 5 weeks ago

#40863 reopened defect (bug)

WP 4.7.5 XMLRPC new method for parsing arguments omits menu_order

Reported by: bjminihan Owned by:
Priority: normal Milestone: Awaiting Review
Component: XML-RPC Version: 4.7.5
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

In WP 4.7.5, in wp-includes/class-wp-xmlrpc-server.php, on line 1327, this line:

$post_data = wp_parse_args( $content_struct, $defaults );

was changed to:

$post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults );

Unfortunately, the new intersection strips out any arguments from $content_struct that don't exist in $defaults.

So you can no longer edit a post and change the "menu_order" field, because it doesn't exist in the $defaults declared just before this line.

Please provide either an updated list of acceptable defaults (e.g. including menu fields), or allow for additional fields to pass through to wp_parse_args.

Tested with latest version of WP, and confirmed that swapping the changed line above enables/disables the ability to change menu_order in posts.

Attachments (1)

40863.diff​ (507 bytes ) - added by iworks 9 years ago.

Download all attachments as: .zip

Change History (9)

#1 follow-up: @iworks
9 years ago

Added two params:

  • menu_order
  • to_ping

We still have to miss (based on wp_insert_post()) those fields:

  • pinged
  • import_id
  • context
  • post_content_filtered

But I'm not sure we should add it.

#WCPL2017

#2 in reply to: ↑ 1 @bjminihan
9 years ago

Adding menu_order would solve our problem nicely. Not sure my opinion matters, but I agree the other fields aren't necessary. Thanks

Replying to iworks:

Added two params:

  • menu_order
  • to_ping

We still have to miss (based on wp_insert_post()) those fields:

  • pinged
  • import_id
  • context
  • post_content_filtered

But I'm not sure we should add it.

#WCPL2017

#3 @bjminihan
9 years ago

  • Resolution → worksforme
  • Status new → closed

#4 follow-up: @markoheijnen
9 years ago

  • Resolution worksforme
  • Status closed → reopened

I assume closing this ticket wasn't intended. Let's also at least add a basic test for this so this wouldn't happen in the future.

#5 @bjminihan
9 years ago

My apologies, but I'm not aware of the specific process I need to follow. I conducted a test on a site with the above change, and found that it worked perfectly

#6 in reply to: ↑ 4 @bjminihan
9 years ago

Replying to markoheijnen:

I assume closing this ticket wasn't intended. Let's also at least add a basic test for this so this wouldn't happen in the future.

I'm sorry, but I'm not clear on the process for implementing this change (re-inserting menu_order back into the class-wp-xmlrpc-server.file). Do you know how I would initiate that process?

This ticket was mentioned in ​PR #14189 on ​WordPress/wordpress-develop by ​@salvatorecorsi.


5 weeks ago
#7

  • Keywords has-patch has-unit-tests added

wp.newPost and wp.editPost silently discard a supplied menu_order: _insert_post() intersects the content struct with defaults that do not include this field. For example, creating a page with menu_order: 5 stores 0, and editing a page whose order is 10 to menu_order: 0 leaves 10.

Add menu_order with a default of 0 to the existing whitelist and document the parameter. The existing edit merge preserves the stored order when it is omitted. Add integration tests for posts and pages, positive/zero/negative values, and an edit that omits the field.

This follows the whitelist approach in the earlier patch by iworks on the ticket, focusing on the menu_order bug confirmed by the reporter.

Reproduction

  1. Call wp.newPost as an editor with post_title: "Menu order test", post_type: "page", and menu_order: 5. The saved order should be 5.
  2. Start with a page whose menu_order is 10 and call wp.editPost with menu_order: 0. The saved order should be 0.
  3. Edit that page with only post_title and confirm that its saved order is preserved.

Validation

  • Before the implementation change, the new wp.newPost tests had 3 failures in 4 cases, and the wp.editPost tests had 4 failures in 5 cases.
  • Native PHPUnit on PHP 8.3.28 and private MariaDB: the full XML-RPC classes passed 359 tests and 1,355 assertions. The create/edit classes separately passed 58 tests and 167 assertions.
  • WordPress PHPCS scan of the three changed files: no errors; one existing PreparedSQL.NotPrepared warning also reproduced on unchanged trunk. The error-only scan passed.
  • PHP compatibility scan, PHP syntax checks for all changed files, and git diff --check passed.
  • No JavaScript/assets changed; build and E2E checks were not run.

The local serialized PHPUnit runner invokes php vendor/bin/phpunit -c phpunit.xml.dist --filter '^Tests_XMLRPC_'. Coding standards and compatibility used php vendor/bin/phpcs --standard=phpcs.xml.dist --parallel=1 <three changed files> and php vendor/bin/phpcs --standard=phpcompat.xml.dist --parallel=1 <three changed files>.

Use of AI Tools

AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-6
Used for: Ticket investigation, implementation, regression tests, local validation, this description, and an independent automated review. No human review is claimed; this PR is submitted for contributor and maintainer review.

​@salvatorecorsi commented on ​PR #14189:


5 weeks ago
#8

The full PHPUnit workflow passed all 64 PHP/database configurations, including multisite and memcached. E2E, build, PHPStan, compatibility and coding standards also passed.

The five failed upgrade jobs in ​this run failed during tool setup: setup-php reported Could not setup wp-cli, then the initial wp core download exited 127 with wp: command not found, before the modified implementation ran.

Could a maintainer rerun only those failed jobs? The targeted gh run rerun 38125458556 --failed attempt was denied with Must have admin rights to Repository. The logs do not indicate a code correction for this patch.

Note: See TracTickets for help on using tickets.