Sparxstar Access Manager provides a comprehensive API for managing Secure Custom Field (SCF) options and runtime rules in WordPress multi-site environments.
Main plugin orchestrator class.
Location: src/class-plugin.php
Methods:
Get the singleton instance of the plugin.
$plugin = \Starisian\Sparxstar\BosonScaffold\Plugin::get_instance();Initialize the plugin. Called automatically on plugins_loaded hook.
Get the Secure Custom Field Manager instance.
$scf_manager = $plugin->get_scf_manager();Get the Rules Engine instance.
$rules_engine = $plugin->get_rules_engine();Activate plugin for a specific site. Called automatically on activation.
Manages SCF options for the current site.
Location: src/class-secure-custom-field-manager.php
Methods:
Load SCF options from the database. Called automatically on init hook.
Get all SCF options.
$options = $scf_manager->get_options();Returns: Array of all SCF options
Get a specific SCF option.
$value = $scf_manager->get_option('field_name', 'default_value');Parameters:
$key- Option key$default- Default value if option doesn't exist
Returns: Option value or default
Set all SCF options.
$scf_manager->set_options([
'field_1' => 'value_1',
'field_2' => 'value_2'
]);Parameters:
$options- Array of options to set
Returns: True on success, false on failure
Check if plugin is enabled for the current site.
if ( $scf_manager->is_enabled() ) {
// Plugin is enabled
}Returns: True if enabled, false otherwise
Get all plugin options including SCF options and rules.
$all_options = $scf_manager->get_plugin_options();Returns: Array of plugin options
Update plugin options.
$scf_manager->update_plugin_options([
'enabled' => true,
'scf_options' => ['key' => 'value']
]);Parameters:
$options- Options to update
Returns: True on success, false on failure
Enforces runtime rules based on SCF options.
Location: src/class-rules-engine.php
Methods:
Enforce all configured rules. Called automatically on init hook.
$rules_engine->enforce_rules();Get all configured rules.
$rules = $rules_engine->get_rules();Returns: Array of rules
Manages the admin interface for subsite-specific settings.
Location: src/class-admin-manager.php
Methods:
Add admin menu page. Called automatically on admin_menu hook.
Register plugin settings. Called automatically on admin_init hook.
Render the settings page.
Sanitize and validate settings input.
Modify SCF options after they're loaded from the database.
Parameters:
$options(array) - SCF options
Example:
add_filter('spx_boson_scf_options', function($options) {
// Add a custom option
$options['custom_field'] = 'custom_value';
// Modify existing option
if (isset($options['existing_field'])) {
$options['existing_field'] = strtoupper($options['existing_field']);
}
return $options;
});Modify rules before they're enforced.
Parameters:
$rules(array) - Array of rules
Example:
add_filter('spx_boson_rules', function($rules) {
// Add a custom rule
$rules[] = [
'type' => 'custom_type',
'enabled' => true,
'config' => ['key' => 'value']
];
return $rules;
});Handle custom rule types.
Parameters:
$handled(bool) - Whether the rule was handled$rule(array) - The rule configuration
Example:
add_filter('spx_boson_handle_rule', function($handled, $rule) {
if ($rule['type'] === 'my_custom_rule') {
// Handle your custom rule logic
if ($rule['enabled']) {
// Do something
}
return true; // Mark as handled
}
return $handled;
}, 10, 2);Fired after SCF options are loaded.
Parameters:
$options(array) - Loaded SCF options
Example:
add_action('spx_boson_options_loaded', function($options) {
// React to options being loaded
error_log('SCF options loaded: ' . print_r($options, true));
});Fired after rules are enforced.
Parameters:
$rules(array) - Enforced rules
Example:
add_action('spx_boson_rules_enforced', function($rules) {
// React to rules being enforced
$count = count($rules);
error_log("Enforced {$count} rules");
});Fired when an access control rule is applied.
Parameters:
$rule(array) - The rule configuration
Example:
add_action('spx_boson_access_control_rule', function($rule) {
// Custom access control logic
if ($rule['condition'] === 'user_role') {
// Check user role
}
});Fired when a field validation rule is applied.
Parameters:
$rule(array) - The rule configuration
Example:
add_action('spx_boson_field_validation_rule', function($rule) {
// Custom validation logic
});Fired when a content restriction rule is applied.
Parameters:
$rule(array) - The rule configuration
Example:
add_action('spx_boson_content_restriction_rule', function($rule) {
// Custom content restriction logic
});Fired when an unknown rule type is encountered.
Parameters:
$rule_type(string) - The unknown rule type$rule(array) - The rule configuration
Example:
add_action('spx_boson_unknown_rule_type', function($rule_type, $rule) {
error_log("Unknown rule type: {$rule_type}");
}, 10, 2);Controls access based on user roles or capabilities.
Structure:
{
"type": "access_control",
"enabled": true,
"condition": "user_role",
"value": "editor"
}Fields:
type- Must be "access_control"enabled- Boolean, whether rule is activecondition- What to check (e.g., "user_role", "user_capability")value- Expected value
Validates field values against patterns or rules.
Structure:
{
"type": "field_validation",
"enabled": true,
"field": "email",
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
}Fields:
type- Must be "field_validation"enabled- Boolean, whether rule is activefield- Field name to validatepattern- Regex pattern for validation
Restricts content based on rules.
Structure:
{
"type": "content_restriction",
"enabled": true,
"content_type": "post",
"restriction": "role_based"
}Fields:
type- Must be "content_restriction"enabled- Boolean, whether rule is activecontent_type- Type of content to restrictrestriction- Restriction method
Plugin version string.
echo SPX_BOSON_VERSION; // "1.0.0"Full path to main plugin file.
echo SPX_BOSON_PLUGIN_FILE;Plugin directory path with trailing slash.
require_once SPX_BOSON_PLUGIN_DIR . 'includes/file.php';Plugin URL with trailing slash.
echo SPX_BOSON_PLUGIN_URL . 'assets/style.css';Plugin basename (directory/file.php).
echo SPX_BOSON_PLUGIN_BASENAME;<?php
/**
* Custom integration with Sparxstar Access Manager
*/
// Modify SCF options
add_filter('spx_boson_scf_options', function($options) {
$options['custom_integration'] = [
'enabled' => true,
'api_key' => get_option('my_api_key')
];
return $options;
});
// Add custom rules
add_filter('spx_boson_rules', function($rules) {
$rules[] = [
'type' => 'api_access',
'enabled' => true,
'endpoint' => '/api/v1/protected'
];
return $rules;
});
// Handle custom rule type
add_filter('spx_boson_handle_rule', function($handled, $rule) {
if ($rule['type'] === 'api_access' && $rule['enabled']) {
// Implement API access control
add_filter('rest_pre_dispatch', function($result, $server, $request) use ($rule) {
$route = $request->get_route();
if (strpos($route, $rule['endpoint']) === 0) {
// Check API access
if (!current_user_can('manage_options')) {
return new WP_Error(
'rest_forbidden',
__('Access denied'),
['status' => 403]
);
}
}
return $result;
}, 10, 3);
return true;
}
return $handled;
}, 10, 2);
// React to options loaded
add_action('spx_boson_options_loaded', function($options) {
if (isset($options['custom_integration'])) {
// Initialize custom integration
}
});Each subsite has its own independent configuration stored in its own options table:
// On site 1
$site_1_options = get_blog_option(1, 'spx_boson_options');
// On site 2
$site_2_options = get_blog_option(2, 'spx_boson_options');
// These are completely independentWhen working with multiple sites programmatically:
// Save current site
$original_site = get_current_blog_id();
// Switch to site 2
switch_to_blog(2);
// Get site 2's SCF manager options
$plugin = \Starisian\Sparxstar\BosonScaffold\Plugin::get_instance();
$scf_manager = $plugin->get_scf_manager();
$site_2_options = $scf_manager->get_options();
// Restore original site
restore_current_blog();The plugin includes built-in error handling:
// JSON validation errors are added as settings errors
add_action('admin_notices', function() {
settings_errors('spx_boson_options');
});public function test_custom_scf_filter() {
add_filter('spx_boson_scf_options', function($options) {
$options['test'] = 'value';
return $options;
});
$scf_manager = new SecureCustomFieldManager();
$scf_manager->load_options();
$this->assertEquals('value', $scf_manager->get_option('test'));
}