MySLP_Settings_History
extends MySLP_Base
in package
The MySLP_Settings_History class is responsible for managing the settings history functionality within the application, including custom post type creation, REST API integration, admin menu additions, and tracking changes in settings.
Table of Contents
Constants
- customFieldFromSuffix = '__from'
- menuSlug = 'settings-history'
- optionNames = ['myslp-dashboard-options' => 'SaaS Dashboard', \SLPLUS_PREFIX . '-options' => 'Public', \SLPLUS_PREFIX . '-options_nojs' => 'Private', 'slp-experience' => 'Advanced', 'slp-power' => 'Professional', 'slp-premier-options' => 'Enteprise']
- RESTRoute = 'wp/v2/settings-history'
- slpOptionsPostType = 'settings-history'
Properties
- $page_slug : mixed
Methods
- __construct() : mixed
- Geo_Base constructor.
- addRestResponseData() : void
- Registers a custom REST API field for the specified post type to include processed post content.
- addToMenu() : void
- Adds the History page to the WordPress admin menu.
- fetchCustomFields() : array<string|int, mixed>
- Fetches all custom fields (post meta) for a given post.
- fetchPost() : string
- Fetches the content of a specified post.
- filter_AddOurAdminSlug() : array<string|int, mixed>
- Adds the 'settings-history' slug to the provided array of slugs.
- get_instance() : mixed
- Return an instance of the object.
- getNiceNameForOption() : string
- Retrieves a user-friendly name for the specified option.
- initialize() : mixed
- Do these things when this object is invoked.
- recordSettingsChange() : int|WP_Error
- Records a change in settings by creating a new post with the provided settings name and value.
- renderHistoryDashboard() : void
- Renders the history dashboard.
- createSettingHistoryPostTypes() : void
- Registers custom post types for various settings history categories with specific attributes and features.
- findSettingsChanges() : array<string|int, mixed>
- Compares two associative arrays to identify changes in their values and constructs an array of the differences.
- setHistoryPostTitle() : string
- Generates a title describing the history of changes based on provided settings changes.
Constants
customFieldFromSuffix
public
mixed
customFieldFromSuffix
= '__from'
menuSlug
public
mixed
menuSlug
= 'settings-history'
optionNames
public
mixed
optionNames
= ['myslp-dashboard-options' => 'SaaS Dashboard', \SLPLUS_PREFIX . '-options' => 'Public', \SLPLUS_PREFIX . '-options_nojs' => 'Private', 'slp-experience' => 'Advanced', 'slp-power' => 'Professional', 'slp-premier-options' => 'Enteprise']
RESTRoute
public
mixed
RESTRoute
= 'wp/v2/settings-history'
slpOptionsPostType
public
mixed
slpOptionsPostType
= 'settings-history'
Properties
$page_slug
public
mixed
$page_slug
Tags
Methods
__construct()
Geo_Base constructor.
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
addRestResponseData()
Registers a custom REST API field for the specified post type to include processed post content.
public
addRestResponseData() : void
addToMenu()
Adds the History page to the WordPress admin menu.
public
addToMenu() : void
fetchCustomFields()
Fetches all custom fields (post meta) for a given post.
public
fetchCustomFields(array<string|int, mixed> $post) : array<string|int, mixed>
Parameters
- $post : array<string|int, mixed>
-
Array containing the post data, including an 'id' key referencing the post ID.
Return values
array<string|int, mixed> —An associative array of custom fields in the format [key => value].
fetchPost()
Fetches the content of a specified post.
public
fetchPost(array<string|int, mixed> $restObj, string $field_name) : string
Parameters
- $restObj : array<string|int, mixed>
-
Array containing the REST response data, including an 'id' key referencing the post ID.
- $field_name : string
-
the REST field name to get
Return values
string —The content of the specified post.
filter_AddOurAdminSlug()
Adds the 'settings-history' slug to the provided array of slugs.
public
filter_AddOurAdminSlug(array<string|int, mixed> $slugs) : array<string|int, mixed>
Parameters
- $slugs : array<string|int, mixed>
-
The existing array of admin slugs.
Return values
array<string|int, mixed> —The modified array of slugs including 'settings-history'.
get_instance()
Return an instance of the object.
public
static get_instance([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
getNiceNameForOption()
Retrieves a user-friendly name for the specified option.
public
getNiceNameForOption(string $option) : string
Parameters
- $option : string
-
The key for which the corresponding user-friendly name is to be fetched.
Return values
string —The user-friendly name associated with the given option.
initialize()
Do these things when this object is invoked.
public
final initialize() : mixed
recordSettingsChange()
Records a change in settings by creating a new post with the provided settings name and value.
public
recordSettingsChange(string $option, mixed $new_value) : int|WP_Error
Parameters
- $option : string
-
The name of the setting that has been changed.
- $new_value : mixed
-
The CURRENT value of the setting that has been changed.
Return values
int|WP_Error —The ID of the newly created post on success, or a WP_Error object on failure.
renderHistoryDashboard()
Renders the history dashboard.
public
renderHistoryDashboard() : void
createSettingHistoryPostTypes()
Registers custom post types for various settings history categories with specific attributes and features.
private
createSettingHistoryPostTypes() : void
findSettingsChanges()
Compares two associative arrays to identify changes in their values and constructs an array of the differences.
private
findSettingsChanges(array<string|int, mixed> $previous_value, array<string|int, mixed> $new_value) : array<string|int, mixed>
Parameters
- $previous_value : array<string|int, mixed>
-
The initial set of settings.
- $new_value : array<string|int, mixed>
-
The updated set of settings.
Return values
array<string|int, mixed> —An associative array containing the changed settings, where each key is the setting name, and its value is an array with 'from' and 'to' keys indicating the previous and new values.
setHistoryPostTitle()
Generates a title describing the history of changes based on provided settings changes.
private
setHistoryPostTitle(array<string|int, mixed> $changedSettings) : string
Parameters
- $changedSettings : array<string|int, mixed>
-
An associative array of changed settings where the keys are the setting names and the values represent the changes.
Return values
string —A localized string summarizing the primary changed setting and the count of other changes. Returns an empty string if no changes are provided.