Skip to content

Commit

Permalink
Fix add_filter type hints in Settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 26, 2023
1 parent 4350dc3 commit 3ed2fa2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/php/Settings/Abstracts/SettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,22 @@ protected function is_tab(): bool {
/**
* Add link to plugin setting page on plugins page.
*
* @param array $actions An array of plugin action links.
* By default, this can include 'activate', 'deactivate', and 'delete'.
* With Multisite active this can also include 'network_active' and 'network_only' items.
* @param array|mixed $actions An array of plugin action links.
* By default, this can include 'activate', 'deactivate', and 'delete'.
* With Multisite active this can also include 'network_active' and 'network_only'
* items.
*
* @return array|string[] Plugin links
*/
public function add_settings_link( array $actions ): array {
public function add_settings_link( $actions ): array {
$new_actions = [
'settings' =>
'<a href="' . admin_url( $this->parent_slug() . '?page=' . $this->option_page() ) .
'" aria-label="' . esc_attr( $this->settings_link_label() ) . '">' .
esc_html( $this->settings_link_text() ) . '</a>',
];

return array_merge( $new_actions, $actions );
return array_merge( $new_actions, (array) $actions );
}

/**
Expand All @@ -306,7 +307,7 @@ protected function init_settings() {
$settings_exist = is_array( $this->settings );
$this->settings = (array) $this->settings;
$form_fields = $this->form_fields();
$network_wide_setting = array_key_exists( self::NETWORK_WIDE, (array) $this->settings ) ?
$network_wide_setting = array_key_exists( self::NETWORK_WIDE, $this->settings ) ?
$this->settings[ self::NETWORK_WIDE ] :
$network_wide;
$this->settings[ self::NETWORK_WIDE ] = $network_wide_setting;
Expand Down
22 changes: 20 additions & 2 deletions src/php/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class Settings implements SettingsInterface {
*/
protected $tabs = [];

/**
* Screen ids of pages and tabs.
*
* @var array
*/
private $screen_ids = [];

/**
* Settings constructor.
*
Expand Down Expand Up @@ -61,8 +68,9 @@ protected function init() {
*
* @var PluginSettingsBase $tab
*/
$tab = new $tab_class( null );
$tabs[] = $tab;
$tab = new $tab_class( null );
$tabs[] = $tab;
$this->screen_ids[] = $tab->screen_id();
}

/**
Expand Down Expand Up @@ -227,4 +235,14 @@ public function set_field( string $key, string $field_key, $value ) {
}
}
}

/**
* Get screen ids of all settings pages and tabs.
*
* @return array
* @noinspection PhpUnused
*/
public function screen_ids(): array {
return $this->screen_ids;
}
}

0 comments on commit 3ed2fa2

Please sign in to comment.