Skip to content

Commit

Permalink
Merge pull request #1 from sharazghouri/dev
Browse files Browse the repository at this point in the history
New Filters & Actions added
  • Loading branch information
sharazghouri authored Mar 24, 2023
2 parents 6efd0a0 + 1371850 commit 796e3b7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 `<form>`)
* `sbsa_do_settings_sections_[option_group]` - Settings form fields HTMLoutput (inside the `<form>`)
* `sbsa_do_settings_sections_[option_group]` - Settings form fields HTMLoutput (inside the `<form>`)
* `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**
<img width="1190" alt="image" src="https://user-images.githubusercontent.com/17900945/227388614-e0bb62c4-f09a-49f9-875f-b37e2d0e9fce.png">
Expand Down
59 changes: 53 additions & 6 deletions src/SettingsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_before_settings_page_' . $this->option_group );
?>
<div class="sbsa-settings sbsa-settings--<?php echo esc_attr( $this->option_group ); ?>">
<?php
/**
* Hook: execute a callback before the settings page header.
*
* @hook sbsa_before_settings_page_header_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_before_settings_page_header_' . $this->option_group );
?>
<?php $this->settings_header(); ?>
<?php
/**
* Hook: execute a callback after the settings page header.
*
* @hook sbsa_after_settings_page_header_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_before_settings_page_header_' . $this->option_group );
?>
<div class="sbsa-settings__content">
<?php $this->settings(); ?>
</div>
</div>
<?php
/**
* Hook: execute a callback after the settings page.
*
* @hook sbsa_after_settings_page_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_after_settings_page_' . $this->option_group );
}

/**
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 '<span>dss</span>';
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 ) {
Expand Down Expand Up @@ -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_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_before_tabless_settings_' . $this->option_group );

?>
<div class="sbsa-section sbsa-tabless">
<?php do_settings_sections( $this->option_group ); ?>
</div>
<?php
/**
* Hook: execute a callback after the tabless settings section.
*
* @hook sbsa_after_settings_<option_group>
* @since 0.2.0
*/
do_action( 'sbsa_after_tabless_settings_' . $this->option_group );
}

/**
Expand Down

0 comments on commit 796e3b7

Please sign in to comment.