Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#65341 new defect (bug)

wp_ajax_widgets_order looks for is_array( $_POST['sidebars'] ) but dosn't check for isset( $_POST['sidebars'] )

Reported by: pbearne Owned by:
Priority: normal Milestone: Awaiting Review
Component: Administration Version: 2.8
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: tests

Description

when creating tests

got this error

There was 1 error:

1) Tests_wp_ajax_widgets_order::test_widgets_order_missing_sidebars
Undefined index: sidebars

/var/www/src/wp-admin/includes/ajax-actions.php:2324
/var/www/src/wp-includes/class-wp-hook.php:344
/var/www/src/wp-includes/class-wp-hook.php:368
/var/www/src/wp-includes/plugin.php:523
/var/www/tests/phpunit/includes/testcase-ajax.php:265
/var/www/tests/phpunit/tests/admin/includes/ajax-actions/widgetsOrder.php:125
phpvfscomposer:///var/www/vendor/phpunit/phpunit/phpunit:106

So add a test for $_POSTsidebars for use

Change History (3)

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


6 months ago
#1

  • Keywords has-patch has-unit-tests added

This PR adds unit tests for the wp_ajax_widgets_order() function located in src/wp-admin/includes/ajax-actions.php.
And checks for $_POST[sidebars]? for use

The tests cover:

  • Successful saving of the widgets order for multiple sidebars.
  • Proper handling of invalid nonces (save-sidebar-widgets nonce).
  • Verification of user permissions (edit_theme_options capability).
  • Behavior when the sidebars parameter is missing.

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

AI Disclosure:

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

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


6 months ago
#2

Prevent an undefined index notice by checking isset( $_POSTsidebars ) before is_array(), and add an AJAX unit test for requests missing sidebars.

#3 @jorbin
6 months ago

  • Version → 2.8

Introduced in [10922]

Note: See TracTickets for help on using tickets.