Skip to content

Commit

Permalink
Merge pull request #50 from dwnload/develop
Browse files Browse the repository at this point in the history
Release 3.6.1
  • Loading branch information
thefrosty authored Aug 9, 2022
2 parents 9a6d89d + 731c53b commit 0f03b20
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

# UNRELEASED

## 3.6.1 - 2022-08-09
- Add mew `WpSettingsApi::HOOK_INIT_SLUG__S` action hook, which would allow hooks only on current
`getPluginInfo()->getMenuSlug()`.
- Change passed param in `do_action` for `ActionHookName::SETTINGS_SETTINGS_SIDEBARS` from an array to a
`WpSettingsApi` instance. [#48](https://github.com/dwnload/WpSettingsApi/pull/48)
- Add `isCurrentMenuSlug($slug)` to allow for easy boolean condition checks.

## 3.6.0 - 2022-08-08
- Lock WP Utilities to version `^2.8`.
- Fix: Allow multiple settings instances by not removing current action hook. (Fixes
[#13](https://github.com/dwnload/WpSettingsApi/issues/13))

## 3.5.0 - 2022-03-28
- Add new Alpha Color Picker field type.
- Update `SettingField` and `SettingSection` to extend the `BaseModel` class.
Expand Down
34 changes: 33 additions & 1 deletion src/WpSettingsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class WpSettingsApi extends AbstractHookProvider
public const FILTER_PREFIX = 'dwnload/wp_settings_api/';
public const ACTION_PREFIX = self::FILTER_PREFIX;
public const HOOK_INIT = self::ACTION_PREFIX . 'init';
public const HOOK_INIT_SLUG__S = self::HOOK_INIT . '-%s';
public const HOOK_PRIORITY = 999;
public const VERSION = '3.6.0';
public const VERSION = '3.6.1';

/**
* The current plugin instance.
Expand Down Expand Up @@ -58,6 +59,7 @@ public function addHooks(): void
*/
\do_action(self::HOOK_INIT, (new SectionManager($this)), (new FieldManager()), $this);
}, self::HOOK_PRIORITY);
$this->addAction(self::HOOK_INIT, [$this, 'initMenuSlug'], 10, 3);
$this->addAction('admin_menu', [$this, 'addAdminMenu']);
$this->addAction('admin_init', [$this, 'adminInit']);
}
Expand All @@ -71,6 +73,36 @@ public function getPluginInfo(): PluginSettings
return $this->plugin_info;
}

/**
* Is the current instance's menu slug equal to the passed slug.
* @param string $menu_slug
* @return bool
* @since 3.6.1
*/
public function isCurrentMenuSlug(string $menu_slug): bool
{
return $this->getPluginInfo()->getMenuSlug() === $menu_slug;
}

/**
* Add a custom action for the current WpSettingsApi based on the instance menu slug.
* @param SectionManager $section_manager Instance of the SectionManager object.
* @param FieldManager $field_manager Instance of the FieldManager object.
* @param WpSettingsApi $wp_settings_api
*/
protected function initMenuSlug(
SectionManager $section_manager,
FieldManager $field_manager,
WpSettingsApi $wp_settings_api
): void {
\do_action(
\sprintf(self::HOOK_INIT_SLUG__S, $this->getPluginInfo()->getMenuSlug()),
$section_manager,
$field_manager,
$wp_settings_api
);
}

/**
* Create admin menu and sub-menu items.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/views/setting/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class="Dwnload_WP_Settings_Api__group">
* Action hook before settings section loads.
* @param SettingSection $section
*/
do_action(ActionHookName::FORM_TOP, $section);
do_action(ActionHookName::FORM_TOP, $section, $this);

settings_fields($section->getId());
do_settings_sections($section->getId());
Expand All @@ -28,7 +28,7 @@ class="Dwnload_WP_Settings_Api__group">
* Action hook after settings section loads (before submit button).
* @param SettingSection $section
*/
do_action(ActionHookName::FORM_BOTTOM, $section);
do_action(ActionHookName::FORM_BOTTOM, $section, $this);

submit_button(
sprintf(esc_attr__('Save “%s”', 'dwnload-wp-settings-api'), $section->getTitle()),
Expand All @@ -41,4 +41,4 @@ class="Dwnload_WP_Settings_Api__group">
}

/** Action hook after all settings sections load. */
do_action(ActionHookName::AFTER_SETTINGS_SECTIONS_FORM);
do_action(ActionHookName::AFTER_SETTINGS_SECTIONS_FORM, $this);
6 changes: 3 additions & 3 deletions src/views/settings-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
<div class="Dwnload_WP_Settings_Api__sticky">
<div class="wrap">
<div class="Dwnload_WP_Settings_Api__sticky_notice">
<?php do_action(ActionHookName::SETTINGS_STICKY_ADMIN_NOTICE); ?>
<?php do_action(ActionHookName::SETTINGS_STICKY_ADMIN_NOTICE, $this); ?>
</div>
<div class="alignright">
<?php do_action(ActionHookName::SETTINGS_BEFORE_SUBMIT_BUTTON); ?>
<?php do_action(ActionHookName::SETTINGS_BEFORE_SUBMIT_BUTTON, $this); ?>
<?php submit_button(
__('Save All Changes', 'wp-settings-api'),
'primary',
Expand All @@ -53,7 +53,7 @@

<div class="Dwnload_WP_Settings_Api__sidebar">
<?php include __DIR__ . '/setting/nav.php'; ?>
<?php do_action(ActionHookName::SETTINGS_SETTINGS_SIDEBARS, []); ?>
<?php do_action(ActionHookName::SETTINGS_SETTINGS_SIDEBARS, $this); ?>
</div><!-- .Dwnload_WP_Settings_Api__sidebar -->

<div class="Dwnload_WP_Settings_Api__body">
Expand Down

0 comments on commit 0f03b20

Please sign in to comment.