-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Refactor: Extract wp_delete_inactive_widgets() for reuse in widget …
#12099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pbearne
wants to merge
21
commits into
WordPress:trunk
Choose a base branch
from
pbearne:impove-wp_delete_inactive_widgets-routine
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e3f59a1
Refactor: Extract `wp_delete_inactive_widgets()` for reuse in widget …
fb40fd9
Change version number to 7.1.0 in docblock
pbearne a4da520
Add void return type to wp_delete_inactive_widgets()
t-hamano 3fab2e4
Simplify inactive widgets guard clause using null coalescing
t-hamano 6904654
Empty inactive widgets array instead of unsetting each key
t-hamano ab7e373
Update src/wp-admin/includes/widgets.php
pbearne 7ea85a4
Merge branch 'trunk' into impove-wp_delete_inactive_widgets-routine
pbearne 34c7eca
Refactor: Replace inlined widget cleanup logic with `wp_delete_inacti…
dc5a171
Apply suggestions from code review
pbearne 6054978
Update widgets-form.php
pbearne ac8dd6d
Add unit tests for `wp_delete_inactive_widgets()` functionality
5304460
Merge remote-tracking branch 'origin/impove-wp_delete_inactive_widget…
12f1e2b
Merge branch 'trunk' into impove-wp_delete_inactive_widgets-routine
pbearne ea76949
Format widget option updates in unit tests for better readability
8865b8f
Merge remote-tracking branch 'origin/impove-wp_delete_inactive_widget…
bcdbcca
Align indentation in `wp_delete_inactive_widgets` unit tests for cons…
32a4737
Potential fix for pull request finding
t-hamano 4b97587
Tests: Remove the redundant `widgets.php` require in the inactive wid…
t-hamano 1ccf2df
Coding Standards: Add a blank line after `set_up()` in the inactive w…
t-hamano 0728eb6
Tests: Remove a redundant `widget_search` option update in the inacti…
t-hamano 4fa891b
Tests: Assert that a widget without a stored option is not created on…
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Test wp_delete_inactive_widgets(). | ||
| * | ||
| * @group widgets | ||
| * @covers ::wp_delete_inactive_widgets | ||
| */ | ||
| class Tests_Widgets_WpDeleteInactiveWidgets extends WP_UnitTestCase { | ||
| public function set_up() { | ||
| parent::set_up(); | ||
| require_once ABSPATH . 'wp-admin/includes/widgets.php'; | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_delete_inactive_widgets() does nothing when there are no inactive widgets. | ||
| */ | ||
| public function test_wp_delete_inactive_widgets_empty() { | ||
| $sidebars_widgets = wp_get_sidebars_widgets(); | ||
| $sidebars_widgets['wp_inactive_widgets'] = array(); | ||
| wp_set_sidebars_widgets( $sidebars_widgets ); | ||
|
|
||
| wp_delete_inactive_widgets(); | ||
|
|
||
| $this->assertEmpty( wp_get_sidebars_widgets()['wp_inactive_widgets'] ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_delete_inactive_widgets() removes inactive widgets and their settings. | ||
| */ | ||
| public function test_wp_delete_inactive_widgets_removes_widgets() { | ||
| // Set up some inactive widgets. | ||
| $widget_id_1 = 'search-2'; | ||
| $widget_id_2 = 'text-3'; | ||
| $widget_id_3 = 'no-option-4'; | ||
|
|
||
| update_option( | ||
| 'widget_search', | ||
| array( | ||
| 2 => array( | ||
| 'title' => 'Search', | ||
| ), | ||
| 3 => array( | ||
| 'title' => 'Active Search', | ||
| ), | ||
| '_multiwidget' => 1, | ||
| ) | ||
| ); | ||
| update_option( | ||
| 'widget_text', | ||
| array( | ||
| 3 => array( | ||
| 'text' => 'Some text', | ||
| ), | ||
| '_multiwidget' => 1, | ||
| ) | ||
| ); | ||
|
|
||
| $sidebars_widgets = wp_get_sidebars_widgets(); | ||
| $sidebars_widgets['wp_inactive_widgets'] = array( $widget_id_1, $widget_id_2, $widget_id_3 ); | ||
| $sidebars_widgets['sidebar-1'] = array( 'search-3' ); | ||
| wp_set_sidebars_widgets( $sidebars_widgets ); | ||
|
|
||
| // Run the function. | ||
| wp_delete_inactive_widgets(); | ||
|
|
||
| $updated_sidebars = wp_get_sidebars_widgets(); | ||
| $this->assertEmpty( $updated_sidebars['wp_inactive_widgets'], 'Inactive widgets sidebar should be empty.' ); | ||
| $this->assertContains( 'search-3', $updated_sidebars['sidebar-1'], 'Active widgets should remain.' ); | ||
|
|
||
| $search_option = get_option( 'widget_search' ); | ||
| $this->assertArrayNotHasKey( 2, $search_option, 'Inactive search widget setting should be removed.' ); | ||
| $this->assertArrayHasKey( 3, $search_option, 'Active search widget setting should remain.' ); | ||
|
|
||
| $text_option = get_option( 'widget_text' ); | ||
| $this->assertArrayNotHasKey( 3, $text_option, 'Inactive text widget setting should be removed.' ); | ||
|
|
||
| $this->assertFalse( get_option( 'widget_no-option' ), 'A missing widget option should not be created.' ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.