Skip to content

Settings: Make all tabs filterable #1806

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

Merged
merged 2 commits into from
Jun 16, 2025
Merged

Conversation

obenland
Copy link
Member

Updates the activitypub_admin_settings_tabs filter to not only add tabs, but control the tabs that get displayed in general.

Proposed changes:

  • Passes all settings tabs to the filter.
  • Adds doing it wrong notice if somehow we end up with 0 tabs and falls back to settings.
  • Determines default tab based on the order in the settings_tabs array.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to Settings > Activitypub and navigate through the settings tabs.
  • Activate/deactivate Welcome and Advanced settings tab, make sure they still work.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Plugins now have full control over which Settings tabs are shown in Settings > Activitypub.

@obenland obenland requested review from pfefferle and Copilot June 12, 2025 15:02
@obenland obenland self-assigned this Jun 12, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the settings tabs logic to let plugins fully control which tabs appear, adds a fallback when no tabs are provided, and chooses the default tab from the filtered list.

  • Passes the complete $settings_tabs array into the activitypub_admin_settings_tabs filter
  • Introduces a _doing_it_wrong fallback and default‐"Settings" tab if no tabs are returned
  • Computes the default selected tab based on the first key in the filtered tabs
Comments suppressed due to low confidence (3)

includes/wp-admin/class-settings.php:307

  • [nitpick] The variable name $settings_tab is easily confused with $settings_tabs. Consider renaming it to something like $default_settings_tab or $settings_tab_item to improve clarity.
$settings_tab      = array(

includes/wp-admin/class-settings.php:347

  • Add a unit or integration test that simulates the activitypub_admin_settings_tabs filter returning an empty array to ensure the fallback logic and _doing_it_wrong notice are exercised correctly.
if ( empty( $settings_tabs ) ) {

includes/wp-admin/class-settings.php:344

  • Expand the docblock above the apply_filters call to include a @return array annotation that describes the expected shape of the returned tabs (e.g., an associative array mapping tab slugs to arrays with 'label' and 'template' keys).
* @param array $settings_tabs The tabs to display.

@obenland obenland merged commit 3a61827 into trunk Jun 16, 2025
11 checks passed
@obenland obenland deleted the update/settings-tab-registration branch June 16, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants