The WPSmartPay Admin Settings system provides a comprehensive framework for managing plugin configuration through WordPress admin interface. This system offers extensive hooks and filters that allow developers to customize, extend, and integrate with the settings interface.

Action Hooks

smartpay_settings_saved

Fires: After WPSmartPay settings are saved on a tab/section.

Parameters:

  • $output (array) — Final sanitized options saved.

  • $input (array) — Raw submitted input.

  • $tab (string) — Current tab slug.

  • $section (string) — Current section slug.

add_action('smartpay_settings_saved', function( $output, $input, $tab, $section ) {
// React to settings changes.
}, 10, 4);

smartpay_admin_add_menu_items

Fires: After WPSmartPay registers default admin menus; add custom submenu pages.

Parameters: none

add_action('smartpay_admin_add_menu_items', function() {
add_submenu_page('smartpay', 'Reports', 'Reports', 'manage_options', 'smartpay-reports', function() {
echo '<div class="wrap"><h1>Reports</h1></div>';
});
}, 20);

Filter Hooks

The WPSmartPay settings system provides a comprehensive set of filters for customizing the admin settings interface. These filters allow you to add new settings tabs, sections, fields, and control how data is sanitized and displayed.

smartpay_settings_tabs

  • Purpose: Add or modify the main settings tabs

  • Parameters: $tabs (array) - Array of tab slugs => tab labels

add_filter('smartpay_settings_tabs', function( $tabs ) {
$tabs['my_custom_tab'] = __('My Custom Tab', 'smartpay');
return $tabs;
});

smartpay_settings_sections_{tab}

  • Purpose: Define sections within a specific tab

  • Parameters: $sections (array) - Array of section slugs => section labels

add_filter('smartpay_settings_sections_general', function( $sections ) {
$sections['advanced'] = __('Advanced Options', 'smartpay');
return $sections;
});

smartpay_settings_sections

  • Purpose: Filter all sections across all tabs

  • Parameters: $sections (array) - Complete sections array

smartpay_settings_{tab}

  • Purpose: Register settings fields for specific tabs

  • Parameters: $settings (array) - Settings array for the tab

  • Available tabs: general, gateways, emails, licenses, extensions, debug_log

add_filter('smartpay_settings_general', function( $settings ) {
$settings['main']['my_custom_setting'] = array(
'id' => 'my_custom_setting',
'name' => __('My Custom Setting', 'smartpay'),
'desc' => __('Description of my setting', 'smartpay'),
'type' => 'text',
);
return $settings;
});

smartpay_settings

  • Purpose: Filter the complete assembled settings structure

  • Parameters: $smartpay_settings (array) - Complete settings array

add_filter('smartpay_settings', function( $settings ) {
// Modify the entire settings structure
return $settings;
});

smartpay_settings_{tab}-{section}_sanitize

  • Purpose: Sanitize raw input for a specific tab-section combination

  • Parameters: $input (array) - Raw submitted input

add_filter('smartpay_settings_general-main_sanitize', function( $input ) {
// Custom sanitization for general tab, main section
if (isset($input['my_field'])) {
$input['my_field'] = sanitize_text_field($input['my_field']);
}
return $input;
});

smartpay_settings_sanitize_{type}

  • Purpose: Sanitize values by field type

  • Parameters: $value (mixed), $key (string) - Field value and key

add_filter('smartpay_settings_sanitize_text', function( $value, $key ) {
// Custom sanitization for text fields
return sanitize_text_field($value);
}, 10, 2);

smartpay_settings_sanitize

  • Purpose: General sanitization filter for all settings

  • Parameters: $value (mixed), $key (string) - Field value and key

add_filter('smartpay_settings_sanitize', function( $value, $key ) {
// Apply custom sanitization to all settings
if ($key === 'special_field') {
return wp_kses_post($value);
}
return $value;
}, 10, 2);

smartpay_non_setting_types

  • Purpose: Declare field types that are not persistent settings

  • Parameters: $types (array) - Array of non-setting field types

add_filter('smartpay_non_setting_types', function( $types ) {
$types[] = 'custom_display_only';
return $types;
});

smartpay_after_setting_output

  • Purpose: Modify generated field HTML before output

  • Parameters: $html (string), $args (array) - Generated HTML and field arguments

add_filter('smartpay_after_setting_output', function( $html, $args ) {
if ($args['id'] === 'special_field') {
$html .= '<div class="custom-help">Additional help text</div>';
}
return $html;
}, 10, 2);

smartpay_get_settings

  • Fires: When WPSmartPay loads the combined settings array.

Parameters:

  • $settings (array)

add_filter('smartpay_get_settings', function( $settings ) {
$settings['feature_flag'] = true;
return $settings;
});

Complete Example: Adding a Custom Tab

// 1. Add the tab
add_filter('smartpay_settings_tabs', function( $tabs ) {
$tabs['my_plugin'] = __('My Plugin', 'smartpay');
return $tabs;
});

// 2. Add sections to the tab
add_filter('smartpay_settings_sections_my_plugin', function( $sections ) {
$sections['main'] = __('Main Settings', 'smartpay');
$sections['advanced'] = __('Advanced Settings', 'smartpay');
return $sections;
});

// 3. Add settings to the tab
add_filter('smartpay_settings_my_plugin', function( $settings ) {
$settings['main'] = array(
'my_text_field' => array(
'id' => 'my_text_field',
'name' => __('Text Field', 'smartpay'),
'desc' => __('Enter some text', 'smartpay'),
'type' => 'text',
),
'my_checkbox' => array(
'id' => 'my_checkbox',
'name' => __('Enable Feature', 'smartpay'),
'desc' => __('Check to enable this feature', 'smartpay'),
'type' => 'checkbox',
),
);

$settings['advanced'] = array(
'my_select' => array(
'id' => 'my_select',
'name' => __('Select Option', 'smartpay'),
'desc' => __('Choose an option', 'smartpay'),
'type' => 'select',
'options' => array(
'option1' => __('Option 1', 'smartpay'),
'option2' => __('Option 2', 'smartpay'),
),
),
);

return $settings;
});

// 4. Add custom sanitization
add_filter('smartpay_settings_my_plugin-main_sanitize', function( $input ) {
if (isset($input['my_text_field'])) {
$input['my_text_field'] = sanitize_text_field($input['my_text_field']);
}
return $input;
});

Common Use Cases

  • Add custom plugin settings

  • Integrate with external services

  • Custom admin pages

  • Settings validation