PHP Class TitanFramework

Since: 1.0
Mostrar archivo Open project: gambitph/titan-framework Class Usage Examples

Public Properties

Property Type Description
$cssInstance TitanFrameworkCSS The CSS class instance used
$optionNamespace string Options will be prefixed with this in the database
$optionsUsed array We store the options (with IDs) here, used for ensuring our serialized option value doesn't get cluttered with unused options
$settings array The current list of settings

Public Methods

Method Description
__construct ( string $optionNamespace ) Creates a new TitanFramework object
addCustomizerSaveFilter ( mixed $value, string $optionName, mixed $oldValue ) : mixed Adds a 'tf_save_option_{namespace}_{optionID}' filter to all Customizer options which are just about to be saved
createAdminPage ( array $settings ) : TitanFrameworkAdminPage Create a admin page
createAdminPanel ( array $settings ) : TitanFrameworkAdminPage Create a admin page
createCSS ( string $CSSString ) : void Generates style rules which can use options as their values
createContainer ( array $settings ) : TitanFrameworkCustomizer | TitanFrameworkAdminPage | TitanFrameworkMetaBox Creates a container (e.g. admin page, meta box, customizer section) depending on the type parameter given in $settings
createCustomizer ( array $settings ) : TitanFrameworkCustomizer Create a customizer section
createMetaBox ( array $settings ) : TitanFrameworkMetaBox Create a meta box
createSampleContentPage ( array $settings ) : TitanFrameworkAdminPage Create a sample content only.
createThemeCustomizerSection ( array $settings ) : TitanFrameworkCustomizer Create a customizer section
deleteAllOptions ( ) : void Deletes ALL the options for the namespace. Even deletes all meta found in all posts.
displayFrameworkError ( string $message, array | object $errorObject = null ) : void Displays an error notice
generateCSS ( ) : string Gets the CSS generated
getAllInstances ( ) : array Gets all active instances of Titan Framework
getInstance ( string $optionNamespace ) : TitanFramework Gets an instance of the framework for the namespace
getInternalAdminPageOption ( string $optionName, mixed $defaultValue = false ) : mixed Gets the admin page option that's loaded into the instance, used by the option class
getOption ( string $optionName, integer $postID = null ) : mixed Get an option
getOptions ( array $optionArray, integer $postID = null ) : array Gets a set of options. Pass an associative array containing the option names as keys and the values you want to be retained if the option names are not implemented.
getURL ( string $script, string $file ) : string Acts the same way as plugins_url( 'script', __FILE__ ) but returns then correct url when called from inside a theme.
loadAdminScripts ( string $hook ) : void Loads all the admin scripts used by Titan Framework
rememberAllOptions ( TitanFrameworkOption $option ) : void Action hook on tf_create_option to remember all the options, used to ensure that our serialized option does not get cluttered with unused options
removeChildThemeOptions ( boolean $continueCreating, array $optionSettings ) : boolean Hook to the tf_create_option_continue filter, to check whether or not to continue adding an option (if the option id was used in $titan->removeOption).
removeOption ( string $optionName ) : void A function available ONLY to CHILD themes to stop the creation of options created by the PARENT theme.
saveInternalAdminPageOptions ( ) : array Saves all the admin (not meta & customizer) options which are currently loaded into this instance
set ( string $setting, string $value ) : void Sets a value in the $setting class variable
setInternalAdminPageOption ( string $optionName, mixed $value ) : boolean Sets the admin page option that's loaded into the instance, used by the option class.
setOption ( string $optionName, mixed $value, integer $postID = null ) : boolean Sets an option

Protected Methods

Method Description
getInternalAdminOptions ( ) : array Gets all the admin page options (not meta & customizer) and loads them from the database into a class variable. This is needed because all our admin page options are contained in a single entry.

Method Details

__construct() public method

Creates a new TitanFramework object
Since: 1.0
public __construct ( string $optionNamespace )
$optionNamespace string The namespace to get options from.

addCustomizerSaveFilter() public method

This uses the pre_update_option filter to check all the options being saved if it's a theme_mod option. It further checks whether these are Titan customizer options, then attaches the new hook into those.
See also: pre_update_option filter
Since: 1.8
public addCustomizerSaveFilter ( mixed $value, string $optionName, mixed $oldValue ) : mixed
$value mixed The value to be saved in the options.
$optionName string The option name.
$oldValue mixed The previously stored value.
return mixed The modified value to save

createAdminPage() public method

Create a admin page
Since: 1.0
public createAdminPage ( array $settings ) : TitanFrameworkAdminPage
$settings array The arguments for creating the admin page.
return TitanFrameworkAdminPage The created admin page

createAdminPanel() public method

Create a admin page
Deprecation: 1.9 Use createContainer() with 'type' => 'admin-page' or createAdminPanel() instead.
Since: 1.0
public createAdminPanel ( array $settings ) : TitanFrameworkAdminPage
$settings array The arguments for creating the admin page.
return TitanFrameworkAdminPage The created admin page

createCSS() public method

Generates style rules which can use options as their values
Since: 1.0
public createCSS ( string $CSSString ) : void
$CSSString string The styles to render.
return void

createContainer() public method

Creates a container (e.g. admin page, meta box, customizer section) depending on the type parameter given in $settings
Since: 1.9
public createContainer ( array $settings ) : TitanFrameworkCustomizer | TitanFrameworkAdminPage | TitanFrameworkMetaBox
$settings array The arguments for creating the container.
return TitanFrameworkCustomizer | TitanFrameworkAdminPage | TitanFrameworkMetaBox The created container

createCustomizer() public method

Create a customizer section
Since: 1.9
public createCustomizer ( array $settings ) : TitanFrameworkCustomizer
$settings array The arguments for creating a customizer section.
return TitanFrameworkCustomizer The created section

createMetaBox() public method

Create a meta box
Since: 1.0
public createMetaBox ( array $settings ) : TitanFrameworkMetaBox
$settings array The arguments for creating the meta box.
return TitanFrameworkMetaBox The created meta box

createSampleContentPage() public method

Use createSampleContent() with 'type' => 'sample-panel' or createSamplePanel() instead.
Since: 1.11
public createSampleContentPage ( array $settings ) : TitanFrameworkAdminPage
$settings array The arguments for creating the sample conent page.
return TitanFrameworkAdminPage The created sample coennt page.

createThemeCustomizerSection() public method

Create a customizer section
Deprecation: 1.9 Use createContainer() with 'type' => 'customizer' or createCustomizer instead.
Since: 1.0
public createThemeCustomizerSection ( array $settings ) : TitanFrameworkCustomizer
$settings array The arguments for creating a customizer section.
return TitanFrameworkCustomizer The created section

deleteAllOptions() public method

Mainly used for unit tests
Since: 1.9
public deleteAllOptions ( ) : void
return void

displayFrameworkError() public static method

Displays an error notice
Since: 1.0
public static displayFrameworkError ( string $message, array | object $errorObject = null ) : void
$message string The error message to display.
$errorObject array | object The object to dump inside the error message.
return void

generateCSS() public method

Gets the CSS generated
Since: 1.6
public generateCSS ( ) : string
return string The generated CSS

getAllInstances() public static method

Gets all active instances of Titan Framework
Since: 1.9.2
public static getAllInstances ( ) : array
return array An array of TitanFramework objects

getInstance() public static method

Gets an instance of the framework for the namespace
Since: 1.0
public static getInstance ( string $optionNamespace ) : TitanFramework
$optionNamespace string The namespace to get options from.
return TitanFramework

getInternalAdminOptions() protected method

Gets all the admin page options (not meta & customizer) and loads them from the database into a class variable. This is needed because all our admin page options are contained in a single entry.
Since: 1.9
protected getInternalAdminOptions ( ) : array
return array All admin options currently in the instance

getInternalAdminPageOption() public method

Gets the admin page option that's loaded into the instance, used by the option class
Since: 1.9
public getInternalAdminPageOption ( string $optionName, mixed $defaultValue = false ) : mixed
$optionName string The ID of the option (not namespaced).
$defaultValue mixed The default value to return if the option isn't available yet.
return mixed The option value

getOption() public method

Get an option
Since: 1.0
public getOption ( string $optionName, integer $postID = null ) : mixed
$optionName string The name of the option.
$postID integer The post ID if this is a meta option.
return mixed The option value

getOptions() public method

Gets a set of options. Pass an associative array containing the option names as keys and the values you want to be retained if the option names are not implemented.
Since: 1.9
public getOptions ( array $optionArray, integer $postID = null ) : array
$optionArray array An associative array containing option names as keys.
$postID integer The post ID if this is a meta option.
return array An array containing the values saved.

getURL() public static method

Acts the same way as plugins_url( 'script', __FILE__ ) but returns then correct url when called from inside a theme.
Since: 1.1.2
public static getURL ( string $script, string $file ) : string
$script string the script to get the url to, relative to $file.
$file string the current file, should be __FILE__.
return string the url to $script

loadAdminScripts() public method

Loads all the admin scripts used by Titan Framework
Since: 1.0
public loadAdminScripts ( string $hook ) : void
$hook string The slug of admin page that called the enqueue.
return void

rememberAllOptions() public method

Action hook on tf_create_option to remember all the options, used to ensure that our serialized option does not get cluttered with unused options
Since: 1.2.1
public rememberAllOptions ( TitanFrameworkOption $option ) : void
$option TitanFrameworkOption The option that was just created.
return void

removeChildThemeOptions() public method

Hook to the tf_create_option_continue filter, to check whether or not to continue adding an option (if the option id was used in $titan->removeOption).
Since: 1.2.1
public removeChildThemeOptions ( boolean $continueCreating, array $optionSettings ) : boolean
$continueCreating boolean If true, the option will be created.
$optionSettings array The settings for the option to be created.
return boolean If true, continue with creating the option. False to stop it..

removeOption() public method

A function available ONLY to CHILD themes to stop the creation of options created by the PARENT theme.
Since: 1.2.1
public removeOption ( string $optionName ) : void
$optionName string The id of the option to remove / stop from being created.
return void

saveInternalAdminPageOptions() public method

Saves all the admin (not meta & customizer) options which are currently loaded into this instance
Since: 1.0
public saveInternalAdminPageOptions ( ) : array
return array All admin options currently in the instance

set() public method

Sets a value in the $setting class variable
Since: 1.6
public set ( string $setting, string $value ) : void
$setting string The name of the setting.
$value string The value to set.
return void

setInternalAdminPageOption() public method

Doesn't perform a save, only sets the value in the class variable.
Since: 1.9
public setInternalAdminPageOption ( string $optionName, mixed $value ) : boolean
$optionName string The ID of the option (not namespaced).
$value mixed The value to set.
return boolean Always returns true

setOption() public method

Sets an option
Since: 1.0
public setOption ( string $optionName, mixed $value, integer $postID = null ) : boolean
$optionName string The name of the option to save.
$value mixed The value of the option.
$postID integer The ID of the parent post if this is a meta box option.
return boolean Always returns true

Property Details

$cssInstance public_oe property

The CSS class instance used
public TitanFrameworkCSS $cssInstance
return TitanFrameworkCSS

$optionNamespace public_oe property

Options will be prefixed with this in the database
public string $optionNamespace
return string

$optionsUsed public_oe property

We store the options (with IDs) here, used for ensuring our serialized option value doesn't get cluttered with unused options
public array $optionsUsed
return array

$settings public_oe property

The current list of settings
public array $settings
return array