Skip to content

65183 misc set screen options - #11739

Open
pbearne wants to merge 6 commits into
WordPress:trunkfrom
pbearne:65183-misc-set_screen_options
Open

pbearne wants to merge 6 commits into
WordPress:trunkfrom
pbearne:65183-misc-set_screen_options

Conversation

@pbearne

@pbearne pbearne commented May 6, 2026

Copy link
Copy Markdown

Description:
This PR adds unit tests for the set_screen_options() function in wp-admin/includes/misc.php. These tests ensure that the function correctly saves screen options (like items per page) for the current user, handles non-standard options via filters, and correctly validates input ranges.

The tests cover:

  • Saving standard _per_page options.
  • Saving custom options using the set-screen-option filter.
  • Handling layout_columns options.
  • Validating that values are within the allowed range (1-999).
  • Correct handling of missing or invalid $_POST data.
  • Ensuring the function correctly performs nonce and referer checks.

Trac ticket: https://core.trac.wordpress.org/ticket/65183

AI Disclosure:

  • AI assistance: Yes
  • Tool(s): Junie (JetBrains)
  • Model(s): gemini-3-flash-preview
  • Used for: Code analysis, test implementation, and workflow management.

@github-actions

github-actions Bot commented May 6, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests override inherited die handling in a way that can let execution continue unexpectedly and lack assertions for nonce rejection and redirect destinations.

2 open issues
What changed in this PR

Adds PHPUnit coverage for WordPress’s set_screen_options() function under Trac ticket #65183, without changing production code.

Changes:

  • Tests saving standard per-page options and filter-enabled custom and layout options.
  • Covers absent POST data and rejection of values above 999.
  • Adds request setup and redirect interception for save-path tests.
File Description
tests/​phpunit/​tests/​admin/​includes/​misc/​setScreenOptions.php Adds screen-option persistence tests, input datasets, and filter callbacks.

Review effort: Balanced

Comment on lines +42 to +45
$_SERVER['HTTP_REFERER'] = admin_url( 'edit.php?pagenum=2' );
$_POST['screenoptionnonce'] = wp_create_nonce( 'screen-options-nonce' );
$_REQUEST['screenoptionnonce'] = $_POST['screenoptionnonce'];
$_REQUEST['_wp_http_referer'] = $_SERVER['HTTP_REFERER'];
Comment on lines +74 to +75
public function wp_die_handler( $message = '', $title = '', $args = array() ) {
return array( $this, 'die_handler' );

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the existing Copilot finding about wp_die_handler(): the parent test class already registers get_wp_die_handler(), which selects $this->wp_die_handler as the terminal handler. This override returns another callback instead of throwing, so it changes that inherited contract. Remove the custom die-handler override/registration and use the inherited WPDieException behavior.

The check_admin_referer hook also cannot bypass nonce validation; its return value is ignored. These requests already supply valid nonces, so those callbacks can be removed. Keep the assertions on saved/rejected user metadata.

Randomized local single-site and multisite checks pass, as do lint and coding standards. The old CI log has expired and GitHub rejects its rerun, so please also refresh against trunk for a current run.

AI review · gpt-6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants