From 137185042f080cd452502d91840863b7c4178b2a Mon Sep 17 00:00:00 2001 From: Sharaz Shahid Date: Fri, 24 Mar 2023 10:56:58 +0000 Subject: [PATCH] New Filters & Actions added --- README.md | 12 ++++++--- src/SettingsAPI.php | 59 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4c3c2c4..474e3bf 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ API Details new SolutionBoxSettings\SettingsAPI( string $settings_file [, string $option_group = ''] ) -Creates a new settings [option_group](http://codex.wordpress.org/Function_Reference/register_setting) based on a setttings file. +Creates a new settings [option_group](http://codex.wordpress.org/Function_Reference/register_setting) based on a settings file. * `$settings_file` - path to the settings file * `$option_group` - optional "option_group" override (by default this will be set to the basename of the settings file) @@ -193,19 +193,25 @@ Actions & Filters **Actions** +* `sbsa_before_settings_page_[option_group]` - Before setting page HTML is output +* `sbsa_after_settings_page_[option_group]` - After setting page HTML is output +* `sbsa_before_settings_page_header_[option_group]` - Before setting page header HTML is output +* `sbsa_after_settings_page_header_[option_group]` - After setting page header HTML is output +* `sbsa_settings_sections_args_[option_group]` - Section extra args for to wrap the section with HTML and extra class [More](https://developer.wordpress.org/reference/functions/add_settings_section/#parameters) * `sbsa_before_field_[option_group]` - Before a field HTML is output * `sbsa_before_field_[option_group]_[field_id]` - Before a field HTML is output * `sbsa_after_field_[option_group]` - After a field HTML is output * `sbsa_after_field_[option_group]_[field_id]` - After a field HTML is output * `sbsa_before_settings_[option_group]` - Before settings form HTML is output * `sbsa_after_settings_[option_group]` - After settings form HTML is output +* `sbsa_before_tabless_settings_[option_group]` - Before settings section HTML is output +* `sbsa_after_tabless_settings_[option_group]` - After settings section HTML is output * `sbsa_before_settings_fields_[option_group]` - Before settings form fields HTML is output (inside the `
`) * `sbsa_do_settings_sections_[option_group]` - Settings form fields HTMLoutput (inside the ``) -* `sbsa_do_settings_sections_[option_group]` - Settings form fields HTMLoutput (inside the ``) * `sbsa_before_tab_links_[option_group]` - Before tabs HTML is output * `sbsa_after_tab_links_[option_group]` - After tabs HTML is output -API Details +Examples ----------- **Example 1 Tabless settings** image diff --git a/src/SettingsAPI.php b/src/SettingsAPI.php index 55be5e3..1d602e2 100644 --- a/src/SettingsAPI.php +++ b/src/SettingsAPI.php @@ -243,14 +243,46 @@ public function settings_page_content() { if ( ! current_user_can( $this->settings_page['capability'] ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'sbsa' ) ); } + /** + * Hook: execute a callback before the settings page. + * + * @hook sbsa_before_settings_page_ + * @since 0.2.0 + */ + do_action( 'sbsa_before_settings_page_' . $this->option_group ); ?>
+ + * @since 0.2.0 + */ + do_action( 'sbsa_before_settings_page_header_' . $this->option_group ); + ?> settings_header(); ?> + + * @since 0.2.0 + */ + do_action( 'sbsa_before_settings_page_header_' . $this->option_group ); + ?>
settings(); ?>
+ * @since 0.2.0 + */ + do_action( 'sbsa_after_settings_page_' . $this->option_group ); } /** @@ -355,10 +387,10 @@ public function admin_enqueue_scripts() { filemtime( $this->options_path . $sbsa_css_path ) ); // wp_enqueue_style( - // 'sbsa-1', - // 'https://getuikit.com/css/theme.css?lfds8h76', - // array(), - // filemtime( $this->options_path . $sbsa_css_path ) + // 'sbsa-1', + // 'https://getuikit.com/css/theme.css?lfds8h76', + // array(), + // filemtime( $this->options_path . $sbsa_css_path ) // ); $jqui_css_path = 'assets/vendor/jquery-ui/jquery-ui.css'; @@ -429,8 +461,8 @@ private function process_settings() { foreach ( $this->settings as $section ) { if ( isset( $section['section_id'] ) && $section['section_id'] && isset( $section['section_title'] ) ) { $page_name = ( $this->has_tabs() ) ? sprintf( '%s_%s', $this->option_group, $section['tab_id'] ) : $this->option_group; - - add_settings_section( $section['section_id'], $section['section_title'], array( $this, 'section_intro' ), $page_name ); + echo 'dss'; + add_settings_section( $section['section_id'], $section['section_title'], array( $this, 'section_intro' ), $page_name, apply_filters( 'sbsa_settings_sections_args_' . $this->option_group, array(), $section ) ); if ( isset( $section['fields'] ) && is_array( $section['fields'] ) && ! empty( $section['fields'] ) ) { foreach ( $section['fields'] as $field ) { @@ -1337,11 +1369,26 @@ public function get_settings() { * Tabless Settings sections */ public function do_tabless_settings_sections() { + /** + * Hook: execute a callback before the tables settings section. + * + * @hook sbsa_before_settings_ + * @since 0.2.0 + */ + do_action( 'sbsa_before_tabless_settings_' . $this->option_group ); + ?>
option_group ); ?>
+ * @since 0.2.0 + */ + do_action( 'sbsa_after_tabless_settings_' . $this->option_group ); } /**