SLP_Text
extends SLP_Object_With_Objects
in package
Class SLP_Text
This class manages text strings and provides functionality for retrieving text based on keys or slugs, handles optional translation, and manages interactions with related objects such as links.
Table of Contents
Properties
- $addon : object
- $class_prefix : string
- $dir : string
- $myslp : MySLP
- $objects : array<string|int, mixed>
- $slplus : SLPlus
- $text_strings : mixed
- $translate : mixed
- $uses_myslp : bool
- $slug : mixed
- $uses_slplus : mixed
Methods
- __construct() : mixed
- __get() : mixed
- Get the value, running it through a filter.
- __isset() : bool
- Allow isset to be called on private properties.
- add_object() : mixed
- get_instance() : static
- Return an instance of the object which is also registered to the slplus global less the SLP_ part.
- get_text() : mixed
- Get a text value based on a key, with optional translation and fallback logic.
- get_text_group() : array<string|int, mixed>
- Return an entire array of slugs for a specific group.
- get_text_string() : string
- Retrieves a text string based on a provided slug.
- get_text_with_variables_replaced() : string
- Send a set of parameters to a printf on one of the Text Manager's registered printf strings.
- get_url() : string
- Get an entry from our URLs list.
- get_web_link() : SLP_Web_Link
- Get the specified web page HTML with embedded hyperlinks.
- instantiate() : null|object
- Instantiate an object of the noted class.
- set_properties() : mixed
- Set our properties.
- at_startup() : mixed
- Things to do at startup after this baby is initialized. Override in your class.
- initialize() : mixed
- Set the dir property.
- set_default_object_options() : mixed
- Set default options for objects. Override in your class.
- init_strings() : mixed
- Initialize strings in subsets as needed.
Properties
$addon
public
object
$addon
$class_prefix
public
string
$class_prefix
the prefix that goes before all our classes
$dir
public
string
$dir
the root directory for this theme
$myslp
public
MySLP
$myslp
$objects
public
array<string|int, mixed>
$objects
key = class name, array of attributes() auto_instantiate = true , instantiate the object when this object initializes object = the instantiated object options = default startup options subdir = the subdirectory (from theme root) that contains the class definition
$slplus
public
SLPlus
$slplus
$text_strings
public
mixed
$text_strings
$translate
public
mixed
$translate
= \false
$uses_myslp
public
bool
$uses_myslp
Set to true to add a $myslp property pointing to global $myslp
$slug
protected
mixed
$slug
$uses_slplus
protected
mixed
$uses_slplus
= \false
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
__get()
Get the value, running it through a filter.
public
__get(string $property) : mixed
Parameters
- $property : string
Return values
mixed —null if not set or the value
__isset()
Allow isset to be called on private properties.
public
__isset(mixed $property) : bool
Parameters
- $property : mixed
Return values
booladd_object()
public
add_object(mixed $object) : mixed
Parameters
- $object : mixed
get_instance()
Return an instance of the object which is also registered to the slplus global less the SLP_ part.
public
static get_instance([bool $no_global = false ][, mixed $params = array() ]) : static
Parameters
- $no_global : bool = false
-
set to true to skip assigning object to SLP global as a property.
- $params : mixed = array()
-
object init params
Return values
staticget_text()
Get a text value based on a key, with optional translation and fallback logic.
public
get_text(string $key[, mixed|null $value = null ][, bool $allow_empty = true ]) : mixed
This method retrieves a value associated with the specified key. If the value is not provided directly, it looks it up in the global SLPlus options or options_nojs arrays. If the key exists in SmartOptions and empty values are not allowed, it will default to the key's default value. Optionally, the value can be translated through a filter.
Parameters
- $key : string
-
The key used to identify the value to retrieve.
- $value : mixed|null = null
-
Optional. The value to use, bypassing the lookup process. Default is null.
- $allow_empty : bool = true
-
Optional. Whether empty values are allowed. If false, defaults to the key's default value if available. Default is true.
Return values
mixed —The resolved text value associated with the specified key.
get_text_group()
Return an entire array of slugs for a specific group.
public
get_text_group(string $slug) : array<string|int, mixed>
Parameters
- $slug : string
Return values
array<string|int, mixed>get_text_string()
Retrieves a text string based on a provided slug.
public
get_text_string(array<string|int, mixed>|string $slug[, bool $log_no_default = true ]) : string
If the slug does not exist in the current text strings, it initializes the necessary text strings or sets a default value. This method filters and modifies the resulting text via the 'slp_get_text_string' filter.
Parameters
- $slug : array<string|int, mixed>|string
-
A string or an array representing the slug used to retrieve the text. If a string is passed, it is converted into an array with the first element as 'general'.
- $log_no_default : bool = true
-
Indicates whether to log an error if the requested slug is not found and has no default.
Return values
string —The text string associated with the slug, possibly modified by filters.
get_text_with_variables_replaced()
Send a set of parameters to a printf on one of the Text Manager's registered printf strings.
public
get_text_with_variables_replaced(string $slug, mixed $params) : string
Parameters
- $slug : string
-
The printf text slug
- $params : mixed
-
The parameters for the sprintf replacements
Return values
string —the i18n text
get_url()
Get an entry from our URLs list.
public
get_url(string $slug) : string
Parameters
- $slug : string
Return values
stringget_web_link()
Get the specified web page HTML with embedded hyperlinks.
public
get_web_link(string $slug[, string $option = '' ]) : SLP_Web_Link
Parameters
- $slug : string
-
Which web page link to fetch.
- $option : string = ''
-
Option (such as a product slug) for further processing.
Return values
SLP_Web_Link —A web link object.
instantiate()
Instantiate an object of the noted class.
public
instantiate(string $class[, array<string|int, mixed> $options = array() ]) : null|object
Parameters
- $class : string
- $options : array<string|int, mixed> = array()
Return values
null|objectset_properties()
Set our properties.
public
set_properties([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
at_startup()
Things to do at startup after this baby is initialized. Override in your class.
protected
at_startup() : mixed
NOTE: this will not run at initialization if $this->objects is empty.
initialize()
Set the dir property.
protected
initialize() : mixed
Fires from \SLPlus_BaseClass_Object::__construct
set_default_object_options()
Set default options for objects. Override in your class.
protected
set_default_object_options() : mixed
init_strings()
Initialize strings in subsets as needed.
private
init_strings(array<string|int, mixed> $slug) : mixed
Parameters
- $slug : array<string|int, mixed>