Skip to main content

Core Helpers — functions

100 public functions. 5 are 🔌 pluggable (function_exists()-guarded, so a theme/child can override them).

FunctionSummary
fw_add_comment_metaAdd meta data field to a comment.
fw_add_metadataAdd metadata for the specified object.
fw_add_post_metaAdd meta data field to a post.
fw_add_term_metaAdd meta data field to a term.
fw_add_user_metaAdd meta data field to a user.
fw_addslashes_deep_keysAdd slashes to values, and to keys if magic_quotes_gpc = On
fw_akgRecursively find a key's value in array
fw_aksSet (or create if not exists) value for specified key in some array level
fw_akuUnset specified key in some array level
fw_attr_to_htmlGenerate attributes string for html tag
fw_callIn the value is instance of FW_Callback class then it is executed and returns the callback value In other case function returns the provided value
fw_callbackRecommend when the function call may require many resources or time (database requests) , or the value is small Not recommended using on very large values
fw_collect_first_level_optionsCollect correct options from the first level of the array and group them
fw_collect_optionsRecursively walks an options array and collects every option and container into the referenced result array.
fw_current_screen_matchCheck if current screen pass/match give rules
fw_current_urlReturns the full URL of the current request, resolved against the site home and cached statically.
fw_current_user_canCheck if current user has one capability from the given list
fw_db_option_storage_loadLoads an option value through its configured fw-storage backend, or returns the value unchanged when none is set.
fw_db_option_storage_saveSaves an option value through its configured fw-storage backend, or returns the value unchanged when none is set.
fw_db_option_storage_typeReturns the registered option storage type instance for the given type, all types when none is given, or null.
fw_delete_comment_metaRemove metadata matching criteria from a comment.
fw_delete_metadataDeletes object metadata rows matching the given meta type, object, key and optional value.
fw_delete_post_metaRemove metadata matching criteria from a post.
fw_delete_term_metaRemove metadata matching criteria from a term.
fw_delete_user_metaRemove metadata matching criteria from a user.
fw_dirname_to_classnameConverts a hyphenated directory name into an underscore-separated class name (e.g. 'foo-bar' to 'Foo_Bar').
fw_extReturns the given URL with its scheme stripped down to a protocol-relative '//' prefix.
fw_extract_only_optionsExtract only input options (without containers)
fw_fix_pathConvert to Unix style directory separators
fw_get_db_customizer_optionGet a customizer framework option value from the database
fw_get_db_ext_settings_optionGet extension's settings option value from the database
fw_get_db_extension_dataGet extension's data from the database
fw_get_db_extension_user_dataGet user meta set by specific extension
fw_get_db_post_optionGet post option value from the database
fw_get_db_settings_optionGet a theme settings option value from the database
fw_get_db_term_optionGet term option value from the database
fw_get_framework_asset_uriURI to a framework asset, preferring its minified (.min) build when present.
fw_get_framework_customizations_dir_rel_pathRelative path of the framework customizations directory
fw_get_framework_directoryFull path to the parent-theme/framework directory
fw_get_framework_directory_uriURI to the parent-theme/framework directory
fw_get_google_fontsReturns the cached list of Google fonts keyed by family, with position metadata.
fw_get_google_fonts_v2Returns the Google fonts catalog as a JSON string, preferring the bundled static file.
fw_get_image_sizesReturn all images sizes register by add_image_size() merged with WordPress default image sizes.
fw_get_json_last_error_messageReturns a human-readable message for the last json_decode error, or null when there was none.
fw_get_mime_type_by_extReturn mime_types by file extension ex : input : array( 'png', 'jpg', 'jpeg' ) => output : array( 'image/jpeg' ).
fw_get_options_errors_from_inputValidates option input and returns a map of option ids to their validation error messages.
fw_get_options_values_from_inputGet correct values from input (POST) for given options This values can be saved in db then replaced with $option['value'] for each option
fw_get_path_urlfw_get_path_url( dirname(FILE) .'/test.css' ) --> http://site.url/path/to/test.css
fw_get_stylesheet_customizations_directoryFull path to the child-theme framework customizations directory
fw_get_stylesheet_customizations_directory_uriURI to the child-theme framework customizations directory
fw_get_template_customizations_directoryFull path to the parent-theme framework customizations directory
fw_get_template_customizations_directory_uriURI to the parent-theme framework customizations directory
fw_get_term_metaRetrieve term meta field for a term.
fw_get_url_without_schemeReturns the given URL with its scheme stripped down to a protocol-relative '//' prefix.
fw_get_variables_from_fileSafe load variables from an file Use this function to not include files directly and to not give access to current context variables (like $this)
fw_html_attr_name_to_array_multi_keyConverts an HTML array-attribute name like 'hello[world]' into a slash-separated multikey path.
fw_html_tagGenerate html tag
fw_htmlspecialcharsUse this id do not want to enter every time same last two parameters Info: Cannot use default parameters because in php 5.2 encoding is not UTF-8 by default
fw_human_bytesConvert bytes to human readable format
fw_human_timeConvert number of seconds to 'X {units}'
fw_id_to_titleTry to make user friendly title from an id
fw_image_tagBuilds a responsive img tag for an attachment ID or image URL with sizing, srcset and loading hints.
fw_include_file_isolatedUse this function to not include files directly and to not give access to current context variables (like $this)
fw_is_built_assetWas this framework-relative source path minified by our build pipeline?
fw_is_callbackCheck is the current value is instance of FW_Callback class
fw_is_cliCheck for command line interface
fw_is_editor_contextReturns whether the current request is rendering for an editor (admin, AJAX, or block-renderer REST).
fw_is_post_editIf currently is a Post Edit page display/submit
fw_is_real_post_saveReturns whether the current save_post is a genuine Save rather than a revision or autosave (deprecated).
fw_is_valid_domain_nameReturns whether the given string is a syntactically valid domain name.
fw_locate_theme_pathSearch relative path in child then in parent theme directory and return full path
fw_locate_theme_path_uriSearch relative path in child then in parent theme directory and return URI
fw_make_stylesheet_portableMake stylesheet contents (portable) independent of directory location For e.g. replace relative paths 'url(img/bg.png)' with full paths 'url(http://site.com/assets/img/bg.png)'
fw_min_uriRewrites a framework CSS/JS asset URI to its .min variant when a built minified file exists.
fw_multi_ext2typeReturn types from file extensions ex : input array( 'png', 'jpg', 'zip' ) => output : array( 'image', 'archive' ).
fw_oembed_getThis function is a wrapper function that set correct width and height for iframes from wp_oembed_get() function
fw_prepare_option_valueUsed when getting some option value from serialized array saved in a custom place and that option is unreachable for standard WordPress filters by other plugins For e.g. that option cannot be translated by plugins, so we pass its value through this function and do the fixes
fw_printprint_r() alternative
fw_rand_md5Generate a random unique 32-char hex token.
fw_read_file_by_uriTry to find file path by its uri and read the file contents
fw_render_viewSafe render a view and return html In view will be accessible only passed variables Use this function to not include files directly and to not give access to current context variables (like $this)
fw_resizeResizes an image URL to the given dimensions via FW_Resize, returning the original URL on failure.
fw_secure_randReference
fw_set_db_customizer_optionSet a theme customizer option value in database
fw_set_db_ext_settings_optionSet extension's setting option value in database
fw_set_db_extension_dataSet some extension's data in database
fw_set_db_extension_user_dataIn case the extension doesn't exist or is disabled, or the value is equal to previous, returns false
fw_set_db_post_optionSet post option value in database
fw_set_db_settings_optionSet a theme settings option value in database
fw_set_db_term_optionSet term option value in database
fw_string_to_icon_html@param array Additional attributes
fw_stripslashes_deep_keysStrip slashes from values, and from keys if magic_quotes_gpc = On
fw_strlenReturns the UTF-8 length of a string, using mb_strlen() when available.
fw_typography_size_cssResolve a typography size value to a CSS length string, tolerating every shape the value can take across the size_format migration: - a unit-input array array( 'value' => '1.5', 'unit' => 'rem' ) -> "1.5rem" - a JSON string of that '{"value":"24","unit":"px"}' -> "24px" - a legacy plain number 16 / "16" -> "16px" - an already-typed CSS length string "1.25em" -> passthrough - blank / false -> '' So a size that predates the unit-input control (a bare integer) resolves exactly as before (+px), and a new unit-input value keeps its chosen unit.
fw_unique_incrementReturns a per-request incrementing counter, unique within the current page load.
fw_update_comment_metaUpdate comment meta field based on comment ID.
fw_update_metadataUpdate metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.
fw_update_post_metaUpdates a post meta value via fw_update_metadata(), adding it if the key does not exist.
fw_update_term_metaUpdate term meta field based on term ID.
fw_update_user_metaUpdate user meta field based on user ID.

fw_add_comment_meta

fw_add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false )

Add meta data field to a comment.

ParameterTypeDescription
$comment_idintComment ID.
$meta_keystringMetadata name.
$meta_valuemixedMetadata value.
$uniqueboolOptional, default is false. Whether the same key should not be added.

Returns int\|bool Meta ID on success, false on failure.

Source: framework/helpers/meta.php:600

fw_add_metadata

fw_add_metadata( $meta_type, $object_id, $meta_key, $meta_value, $unique = false )

Add metadata for the specified object.

@uses $wpdb WordPress database object for queries.

unique for the object. If true, and the object already has a value for the specified
metadata key, no change will be made
ParameterTypeDescription
$meta_typestringType of object metadata is for (e.g., comment, post, or user)
$object_idintID of the object metadata is for
$meta_keystringMetadata key
$meta_valuemixedMetadata value. Must be serializable if non-scalar.
$uniqueboolOptional, default is false. Whether the specified metadata key should be

Returns int\|bool The meta ID on success, false on failure.

Source: framework/helpers/meta.php:64

fw_add_post_meta

fw_add_post_meta( $post_id, $meta_key, $meta_value, $unique = false )

Add meta data field to a post.

Post meta data is called "Custom Fields" on the Administration Screen.

Default false.
ParameterTypeDescription
$post_idintPost ID.
$meta_keystringMetadata name.
$meta_valuemixedMetadata value. Must be serializable if non-scalar.
$uniqueboolOptional. Whether the same key should not be added.

Returns int\|bool Meta ID on success, false on failure.

Source: framework/helpers/meta.php:526

fw_add_term_meta

fw_add_term_meta( $term_id, $meta_key, $meta_value, $unique = false )

Add meta data field to a term.

ParameterTypeDescription
$term_idintPost ID.
$keystringMetadata name.
$valuemixedMetadata value.
$uniqueboolOptional, default is false. Whether the same key should not be added.

Returns bool False for failure. True for success.

Source: framework/helpers/meta.php:653

fw_add_user_meta

fw_add_user_meta( $user_id, $meta_key, $meta_value, $unique = false )

Add meta data field to a user.

Post meta data is called "Custom Fields" on the Administration Screens.

ParameterTypeDescription
$user_idintUser ID.
$meta_keystringMetadata name.
$meta_valuemixedMetadata value.
$uniqueboolOptional, default is false. Whether the same key should not be added.

Returns int\|bool Meta ID on success, false on failure.

Source: framework/helpers/meta.php:473

fw_addslashes_deep_keys

fw_addslashes_deep_keys( $value )

Add slashes to values, and to keys if magic_quotes_gpc = On

Source: framework/helpers/general.php:633

fw_akg

fw_akg( $keys, $array_or_object, $default_value = null, $keys_delimiter = '/' )

Recursively find a key's value in array

ParameterTypeDescription
$keysstring'a/b/c'
$array_or_objectarray|object
$default_valuenull|mixed
$keys_delimiterstring

Returns null\|mixed

Source: framework/helpers/general.php:287

fw_aks

fw_aks( $keys, $value, &$array_or_object, $keys_delimiter = '/' )

Set (or create if not exists) value for specified key in some array level

ParameterTypeDescription
$keysstring'a/b/c', or 'a/b/c/' equivalent to: $arr['a']['b']['c'][] = $val;
$valuemixed
$array_or_objectarray|object
$keys_delimiterstring

Returns array\|object

Source: framework/helpers/general.php:336

fw_aku

fw_aku( $keys, &$array_or_object, $keys_delimiter = '/' )

Unset specified key in some array level

ParameterTypeDescription
$keysstring'a/b/c' -> unset($arr['a']['b']['c']);
$array_or_objectarray|object
$keys_delimiterstring

Returns array\|object

Source: framework/helpers/general.php:406

fw_attr_to_html

fw_attr_to_html( array $attr_array )

Generate attributes string for html tag

ParameterTypeDescription
$attr_arrayarrayarray('href' => '/', 'title' => 'Test')

Returns string 'href="/" title="Test"'

Source: framework/helpers/general.php:584

fw_call

since 2.6.14

fw_call( $value )

In the value is instance of FW_Callback class then it is executed and returns the callback value In other case function returns the provided value

ParameterTypeDescription
$valuemixed|FW_Callback

Returns mixed

Source: framework/helpers/general.php:2357

fw_callback

since 2.6.14

fw_callback( $callback, array $args = array(), $cache = true )

Recommend when the function call may require many resources or time (database requests) , or the value is small Not recommended using on very large values

ParameterTypeDescription
$callbackstring|arrayCallback function
$argsarrayCallback arguments
$cacheboolWhenever you want to cache the function value after it's first call or not

Returns FW_Callback

Source: framework/helpers/general.php:2343

fw_collect_first_level_options

⚠️ deprecated

fw_collect_first_level_options( &$collected, &$options )

Collect correct options from the first level of the array and group them

It is deprecated since 2.4 because container types were added and there can be any type of containers but this function is hardcoded only for tab,box,group. Use fw_collect_options()

ParameterTypeDescription
$collectedarrayWill be filled with found correct options
$optionsarray

Source: framework/helpers/general.php:963

fw_collect_options

fw_collect_options( &$result, &$options, $settings = array(), $_recursion_data = array() )

Recursively walks an options array and collects every option and container into the referenced result array.

ParameterTypeDescription
$resultarray
$optionsarray
$settingsarray
$_recursion_dataarray(private) for internal use

Source: framework/helpers/general.php:1063

fw_current_screen_match

fw_current_screen_match( array $rules )

Check if current screen pass/match give rules

ParameterTypeDescription
$rulesarrayRules for current screen

Returns bool

Source: framework/helpers/general.php:669

fw_current_url

fw_current_url()

Returns the full URL of the current request, resolved against the site home and cached statically.

Returns string Current url

Source: framework/helpers/general.php:1608

fw_current_user_can

fw_current_user_can( $capabilities, $default_value = null )

Check if current user has one capability from the given list

Return first capability that user can. Else, return default value if it is not null, else return first capability from list. Use default value false to check if user can some of the capabilities

ParameterTypeDescription
$capabilitiesarraylist of capabilities to check
$default_valuemixed

Returns string\|bool\|mixed

Source: framework/helpers/general.php:1665

fw_db_option_storage_load

since 2.5.0

fw_db_option_storage_load($id, array $option, $value, array $params = array())

Loads an option value through its configured fw-storage backend, or returns the value unchanged when none is set.

ParameterTypeDescription
$idstring
$optionarray
$valuemixed
$paramsarray

Returns mixed

Source: framework/helpers/fw-storage.php:56

fw_db_option_storage_save

since 2.5.0

fw_db_option_storage_save($id, array $option, $value, array $params = array())

Saves an option value through its configured fw-storage backend, or returns the value unchanged when none is set.

ParameterTypeDescription
$idstring
$optionarray
$valuemixed
$paramsarray

Returns mixed

Source: framework/helpers/fw-storage.php:21

fw_db_option_storage_type

since 2.5.0

fw_db_option_storage_type($type = null)

Returns the registered option storage type instance for the given type, all types when none is given, or null.

ParameterTypeDescription
$typenull|string

Returns FW_Option_Storage_Type\|FW_Option_Storage_Type[]\|null

Source: framework/helpers/fw-storage.php:101

fw_delete_comment_meta

fw_delete_comment_meta( $comment_id, $meta_key, $meta_value = '' )

Remove metadata matching criteria from a comment.

You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.

ParameterTypeDescription
$comment_idintcomment ID
$meta_keystringMetadata name.
$meta_valuemixedOptional. Metadata value.

Returns bool True on success, false on failure.

Source: framework/helpers/meta.php:636

fw_delete_metadata

fw_delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false )

Deletes object metadata rows matching the given meta type, object, key and optional value.

Delete metadata for the specified object.

@uses $wpdb WordPress database object for queries.

with this value. Otherwise, delete all entries with the specified meta_key.
for all objects, ignoring the specified object_id. Otherwise, only delete matching
metadata entries for the specified object_id.
ParameterTypeDescription
$meta_typestringType of object metadata is for (e.g., comment, post, or user)
$object_idintID of the object metadata is for
$meta_keystringMetadata key
$meta_valuemixedOptional. Metadata value. Must be serializable if non-scalar. If specified, only delete metadata entries
$delete_allboolOptional, default is false. If true, delete matching metadata entries

Returns bool True on successful delete, false on failure.

Source: framework/helpers/meta.php:328

fw_delete_post_meta

fw_delete_post_meta( $post_id, $meta_key, $meta_value = '' )

Remove metadata matching criteria from a post.

You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.

non-scalar. Default empty.
ParameterTypeDescription
$post_idintPost ID.
$meta_keystringMetadata name.
$meta_valuemixedOptional. Metadata value. Must be serializable if

Returns bool True on success, false on failure.

Source: framework/helpers/meta.php:577

fw_delete_term_meta

fw_delete_term_meta( $term_id, $meta_key, $meta_value = '' )

Remove metadata matching criteria from a term.

You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.

ParameterTypeDescription
$term_idintterm ID
$meta_keystringMetadata name.
$meta_valuemixedOptional. Metadata value.

Returns bool False for failure. True for success.

Source: framework/helpers/meta.php:670

fw_delete_user_meta

fw_delete_user_meta( $user_id, $meta_key, $meta_value = '' )

Remove metadata matching criteria from a user.

You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.

ParameterTypeDescription
$user_idintuser ID
$meta_keystringMetadata name.
$meta_valuemixedOptional. Metadata value.

Returns bool True on success, false on failure.

Source: framework/helpers/meta.php:509

fw_dirname_to_classname

fw_dirname_to_classname( $dirname )

Converts a hyphenated directory name into an underscore-separated class name (e.g. 'foo-bar' to 'Foo_Bar').

ParameterTypeDescription
$dirnamestring'foo-bar'

Returns string 'Foo_Bar'

Source: framework/helpers/general.php:1827

fw_ext

fw_ext( $extension_name )

Returns the given URL with its scheme stripped down to a protocol-relative '//' prefix.

Alias

ParameterTypeDescription
$extension_namestring

Returns FW_Extension\|null

Source: framework/helpers/general.php:1932

fw_extract_only_options

fw_extract_only_options( array $options )

Extract only input options (without containers)

ParameterTypeDescription
$optionsarray

Returns array {option_id => option}

Source: framework/helpers/general.php:944

fw_fix_path

fw_fix_path( $path )

Convert to Unix style directory separators

Source: framework/helpers/general.php:11

fw_get_db_customizer_option

fw_get_db_customizer_option( $option_id = null, $default_value = null )

Get a customizer framework option value from the database

ParameterTypeDescription
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$default_valuenull|mixedIf no option found in the database, this value will be returned

Returns mixed\|null

Source: framework/helpers/database.php:600

fw_get_db_ext_settings_option

fw_get_db_ext_settings_option( $extension_name, $option_id = null, $default_value = null, $get_original_value = null )

Get extension's settings option value from the database

ParameterTypeDescription
$extension_namestring
$option_idstring|null
$default_valuenull|mixedIf no option found in the database, this value will be returned
$get_original_valuenull|boolREMOVED https://github.com/ThemeFuse/Unyson/issues/1676

Returns mixed\|null

Source: framework/helpers/database.php:504

fw_get_db_extension_data

fw_get_db_extension_data( $extension_name, $multi_key = null, $default_value = null, $get_original_value = null )

Get extension's data from the database

ParameterTypeDescription
$extension_namestring
$multi_keystring|nullThe key of the data you want to get. null - all data
$default_valuenull|mixedIf no option found in the database, this value will be returned
$get_original_valuenull|boolREMOVED https://github.com/ThemeFuse/Unyson/issues/1676

Returns mixed\|null

Source: framework/helpers/database.php:697

fw_get_db_extension_user_data

fw_get_db_extension_user_data( $user_id, $extension_name, $keys = null )

Get user meta set by specific extension

If the extension doesn't exist or is disabled, or meta key doesn't exist, returns null, else returns the meta key value

ParameterTypeDescription
$user_idint
$extension_namestring
$keysstring

Returns mixed\|null

Source: framework/helpers/database.php:635

fw_get_db_post_option

fw_get_db_post_option($post_id = null, $option_id = null, $default_value = null, $get_original_value = null)

Get post option value from the database

ParameterTypeDescription
$post_idnull|int
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$default_valuenull|mixedIf no option found in the database, this value will be returned
$get_original_valuenull|boolREMOVED https://github.com/ThemeFuse/Unyson/issues/1676

Returns mixed\|null

Source: framework/helpers/database.php:234

fw_get_db_settings_option

fw_get_db_settings_option( $option_id = null, $default_value = null, $get_original_value = null )

Get a theme settings option value from the database

ParameterTypeDescription
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$default_valuenull|mixedIf no option found in the database, this value will be returned
$get_original_valuenull|boolREMOVED https://github.com/ThemeFuse/Unyson/issues/1676

Returns mixed\|null

Source: framework/helpers/database.php:68

fw_get_db_term_option

fw_get_db_term_option( $term_id, $taxonomy, $option_id = null, $default_value = null, $get_original_value = null )

Get term option value from the database

ParameterTypeDescription
$term_idint
$taxonomystring
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$default_valuenull|mixedIf no option found in the database, this value will be returned
$get_original_valuenull|boolREMOVED https://github.com/ThemeFuse/Unyson/issues/1676

Returns mixed\|null

Source: framework/helpers/database.php:433

fw_get_framework_asset_uri

fw_get_framework_asset_uri( $rel_path = '' )

URI to a framework asset, preferring its minified (.min) build when present.

Returns the .min.css / .min.js sibling ONLY when our build pipeline actually produced it (per fw_is_built_asset()) and SCRIPT_DEBUG is off; otherwise falls back to the unminified source. So a missing/skipped build — or a stale pre-shipped vendor .min — never gets served by mistake.

ParameterTypeDescription
$rel_pathstringe.g. '/static/css/fw.css'

Returns string

Source: framework/helpers/general.php:215

fw_get_framework_customizations_dir_rel_path

fw_get_framework_customizations_dir_rel_path( $append = '' )

Relative path of the framework customizations directory

ParameterTypeDescription
$appendstring

Returns string

Source: framework/helpers/general.php:35

fw_get_framework_directory

fw_get_framework_directory( $rel_path = '' )

Full path to the parent-theme/framework directory

ParameterTypeDescription
$rel_pathstring

Returns string

Source: framework/helpers/general.php:136

fw_get_framework_directory_uri

fw_get_framework_directory_uri( $rel_path = '' )

URI to the parent-theme/framework directory

ParameterTypeDescription
$rel_pathstring

Returns string

Source: framework/helpers/general.php:160

fw_get_google_fonts

fw_get_google_fonts()

Returns the cached list of Google fonts keyed by family, with position metadata.

Returns Array with Google fonts

Source: framework/helpers/general.php:1514

fw_get_google_fonts_v2

fw_get_google_fonts_v2()

Returns the Google fonts catalog as a JSON string, preferring the bundled static file.

Returns string JSON encoded array with Google fonts

Source: framework/helpers/general.php:1548

fw_get_image_sizes

fw_get_image_sizes( $size = '' )

Return all images sizes register by add_image_size() merged with WordPress default image sizes.

ParameterTypeDescription
$sizestring

Returns array\|bool

Source: framework/helpers/general.php:2023

fw_get_json_last_error_message

since 2.4.10

fw_get_json_last_error_message()

Returns a human-readable message for the last json_decode error, or null when there was none.

Returns string\|null

Source: framework/helpers/general.php:2106

fw_get_mime_type_by_ext

fw_get_mime_type_by_ext( $type = array() )

Return mime_types by file extension ex : input : array( 'png', 'jpg', 'jpeg' ) => output : array( 'image/jpeg' ).

ParameterTypeDescription
$typearray

Returns array

Source: framework/helpers/general.php:2139

fw_get_options_errors_from_input

fw_get_options_errors_from_input( array $options, $input_array = null )

Validates option input and returns a map of option ids to their validation error messages.

Collect server-side validation errors for option input (Phase 3b).

Returns a map of { option_id => error_message } for every leaf option that fails validation. An empty array means "all valid".

Validation is fully opt-in and backward compatible: an option with no validation rules, whose type doesn't override _get_value_error(), and which nothing hooks via fw_option_value_error, never produces an error — so this returns [] and the normal save proceeds unchanged.

ParameterTypeDescription
$optionsarray
$input_arrayarray|null

Returns array { option_id => message }

Source: framework/helpers/general.php:1338

fw_get_options_values_from_input

fw_get_options_values_from_input( array $options, $input_array = null )

Get correct values from input (POST) for given options This values can be saved in db then replaced with $option['value'] for each option

ParameterTypeDescription
$optionsarray
$input_arrayarray

Returns array Values

Source: framework/helpers/general.php:1287

fw_get_path_url

since 2.6.11

fw_get_path_url( $path )

fw_get_path_url( dirname(FILE) .'/test.css' ) --> http://site.url/path/to/test.css

ParameterTypeDescription
$pathstring

Returns string\|null

Source: framework/helpers/general.php:2302

fw_get_stylesheet_customizations_directory

fw_get_stylesheet_customizations_directory( $rel_path = '' )

Full path to the child-theme framework customizations directory

ParameterTypeDescription
$rel_pathstring

Returns null\|string

Source: framework/helpers/general.php:58

fw_get_stylesheet_customizations_directory_uri

fw_get_stylesheet_customizations_directory_uri( $rel_path = '' )

URI to the child-theme framework customizations directory

ParameterTypeDescription
$rel_pathstring

Returns null\|string

Source: framework/helpers/general.php:74

fw_get_template_customizations_directory

fw_get_template_customizations_directory( $rel_path = '' )

Full path to the parent-theme framework customizations directory

ParameterTypeDescription
$rel_pathstring

Returns string

Source: framework/helpers/general.php:93

fw_get_template_customizations_directory_uri

fw_get_template_customizations_directory_uri( $rel_path = '' )

URI to the parent-theme framework customizations directory

ParameterTypeDescription
$rel_pathstring

Returns string

Source: framework/helpers/general.php:113

fw_get_term_meta

fw_get_term_meta( $term_id, $key, $single = false )

Retrieve term meta field for a term.

is true.

ParameterTypeDescription
$term_idintTerm ID.
$keystringThe meta key to retrieve.
$singleboolWhether to return a single value.

Returns mixed Will be an array if $single is false. Will be value of meta data field if $single

Source: framework/helpers/meta.php:684

fw_get_url_without_scheme

fw_get_url_without_scheme( $url )

Returns the given URL with its scheme stripped down to a protocol-relative '//' prefix.

Source: framework/helpers/general.php:1937

fw_get_variables_from_file

fw_get_variables_from_file( $file_path, array $_extract_variables, array $_set_variables = array() )

Safe load variables from an file Use this function to not include files directly and to not give access to current context variables (like $this)

ParameterTypeDescription
$file_pathstring
$_extract_variablesarrayExtract these from file array('variable_name' => 'default_value')
$_set_variablesarraySet these to be available in file (like variables in view)

Returns array

Source: framework/helpers/general.php:900

fw_html_attr_name_to_array_multi_key

fw_html_attr_name_to_array_multi_key( $attr_name, $set_mode = false )

Converts an HTML array-attribute name like 'hello[world]' into a slash-separated multikey path.

ParameterTypeDescription
$attr_name
$set_modebool

Returns mixed

Source: framework/helpers/general.php:1386

fw_html_tag

fw_html_tag( $tag, $attr = array(), $end = false )

Generate html tag

ParameterTypeDescription
$tagstringTag name
$attrarrayTag attributes
$endbool|stringAppend closing tag. Also accepts body content

Returns string The tag's html

Source: framework/helpers/general.php:560

fw_htmlspecialchars

fw_htmlspecialchars( $string )

Use this id do not want to enter every time same last two parameters Info: Cannot use default parameters because in php 5.2 encoding is not UTF-8 by default

ParameterTypeDescription
$stringstring

Returns string

Source: framework/helpers/general.php:1650

fw_human_bytes

since 2.4.17

fw_human_bytes( $bytes, $precision = 2 )

Convert bytes to human readable format

ParameterTypeDescription
$bytesintegerSize in bytes to convert
$precisioninteger

Returns string

Source: framework/helpers/general.php:1744

fw_human_time

fw_human_time( $seconds )

Convert number of seconds to 'X {units}'

E.g. 123 => '2 minutes' then you can use this string how you want, for e.g. append ' ago' => '2 minutes ago'

ParameterTypeDescription
$secondsint

Returns string

Source: framework/helpers/general.php:1687

fw_id_to_title

fw_id_to_title( $id )

Try to make user friendly title from an id

ParameterTypeDescription
$idstring'hello-world'

Returns string 'Hello world'

Source: framework/helpers/general.php:1909

fw_image_tag

🔌 pluggable

fw_image_tag( $source, $args = array() )

Builds a responsive img tag for an attachment ID or image URL with sizing, srcset and loading hints.

Modern <img> builder shared across shortcodes (media-image, reviews-table …).

Improvements over hand-built <img> tags from the Unyson era:

  • Responsive srcset/sizes (via wp_get_attachment_image) when the display size isn't an exact px crop; a 1x/2x density srcset for exact px crops when the source is large enough.

  • width/height attributes (px) to reduce CLS.

  • fetchpriority="high" + eager loading for above-the-fold (LCP) images; lazy + async decoding otherwise.

  • Inline CSS for non-px units (%, vw, rem…); alt resolved from the media library; graceful fallback when GD/Imagick (fw_resize) is unavailable.

    alt, fetchpriority ('high'|''), sizes, fallback_size,
    extra_attr (assoc array merged onto the tag).
ParameterTypeDescription
$sourceint|stringAttachment ID (enables srcset/crop) OR an image URL.
$argsarraywidth, height (unit-input value | px | ''), class,

Returns string

Source: framework/helpers/general.php:2207

fw_include_file_isolated

fw_include_file_isolated( $file_path, $once = false )

Use this function to not include files directly and to not give access to current context variables (like $this)

ParameterTypeDescription
$file_pathstring
$oncebool

Returns bool If was included or not

Source: framework/helpers/general.php:923

fw_is_built_asset

fw_is_built_asset( $rel_path )

Was this framework-relative source path minified by our build pipeline?

Reads the build manifest (framework/build-manifest.php, generated by build/build.mjs) once per request. The asset helpers consult this so they only ever serve a .min WE produced — never a stale, pre-shipped vendor *.min.* that doesn't correspond to its (possibly customized) source.

ParameterTypeDescription
$rel_pathstringframework-relative, e.g. '/static/css/fw.css'

Returns bool

Source: framework/helpers/general.php:191

fw_is_callback

fw_is_callback( $value )

Check is the current value is instance of FW_Callback class

ParameterTypeDescription
$valuemixed

Returns bool

Source: framework/helpers/general.php:2374

fw_is_cli

since 2.6.16

fw_is_cli()

Check for command line interface

Returns bool

Source: framework/helpers/general.php:2384

fw_is_editor_context

since 2.16.23

fw_is_editor_context()

Returns whether the current request is rendering for an editor (admin, AJAX, or block-renderer REST).

Whether the current request is an EDITING surface rather than a visitor page view.

Shortcode views use this to show authoring guidance — "Add a poster image and a video URL", an empty-state hint, a placeholder — that a visitor must never see.

The historic test was is_admin() || DOING_AJAX, and it has a blind spot that only appeared once elements became Gutenberg blocks: ServerSideRender renders through the REST API, which is neither. A view guarded the old way returns nothing in a block preview, so the block shows Gutenberg's bare "Block rendered as empty" instead of the element's own guidance.

REST is deliberately narrowed to the block-renderer route rather than accepting every REST request: a public REST consumer fetching post content is a VISITOR, and must not receive editor-only markup.

Returns bool True when the caller is rendering for an editor.

Source: framework/helpers/general.php:1453

fw_is_post_edit

fw_is_post_edit()

If currently is a Post Edit page display/submit

Returns bool

Source: framework/helpers/general.php:1782

fw_is_real_post_save

⚠️ deprecated

fw_is_real_post_save( $post_id )

Returns whether the current save_post is a genuine Save rather than a revision or autosave (deprecated).

This function is used in 'save_post' action

Used to check if current post save is a regular "Save" button press not a revision, auto-save or something else

save_post action happens also happens on Preview, Revision, Auto-save Restore, ... the verifications in this function simplifies too much the save process, the developers should study and understand better how it works and handle different save cases in their scripts using wp functions

ParameterTypeDescription
$post_id

Returns bool

Source: framework/helpers/general.php:1497

fw_is_valid_domain_name

fw_is_valid_domain_name( $domain_name )

Returns whether the given string is a syntactically valid domain name.

Source: framework/helpers/general.php:1636

fw_locate_theme_path

fw_locate_theme_path( $rel_path )

Search relative path in child then in parent theme directory and return full path

ParameterTypeDescription
$rel_pathstring'/some/path_to_dir' or '/some/path_to_file.php'

Returns string URI

Source: framework/helpers/general.php:823

fw_locate_theme_path_uri

fw_locate_theme_path_uri( $rel_path )

Search relative path in child then in parent theme directory and return URI

ParameterTypeDescription
$rel_pathstring'/some/path_to_dir' or '/some/path_to_file.php'

Returns string URI

Source: framework/helpers/general.php:806

fw_make_stylesheet_portable

fw_make_stylesheet_portable( $href, $contents = null )

Make stylesheet contents (portable) independent of directory location For e.g. replace relative paths 'url(img/bg.png)' with full paths 'url(http://site.com/assets/img/bg.png)'

ParameterTypeDescription
$hrefstring'http://.../style.css'
$contentsnull|stringIf not specified, will try to read from $href

Returns bool\|string false - on failure; string - stylesheet contents

Source: framework/helpers/general.php:1983

fw_min_uri

🔌 pluggable

fw_min_uri( $uri = '' )

Rewrites a framework CSS/JS asset URI to its .min variant when a built minified file exists.

Receiver-agnostic minified-asset wrapper.

Wrap any already-built framework/extension asset URL (e.g. the result of an extension's get_uri()/get_declared_URI(), regardless of which class produced it) and get back the .min.css / .min.js sibling when it exists on disk and SCRIPT_DEBUG is off; the original URL otherwise.

Operates purely on the URL string, so — unlike a per-class method — it can never trigger an undefined-method fatal. Only rewrites assets served from within the framework directory (anything else, e.g. a theme customization override, is returned untouched).

ParameterTypeDescription
$uristringe.g. 'https://site/.../extensions/shortcodes/.../styles.css?ver=1'

Returns string

Source: framework/helpers/general.php:248

fw_multi_ext2type

fw_multi_ext2type( $ext_array = array() )

Return types from file extensions ex : input array( 'png', 'jpg', 'zip' ) => output : array( 'image', 'archive' ).

ParameterTypeDescription
$ext_arrayarray

Returns array

Source: framework/helpers/general.php:2163

fw_oembed_get

fw_oembed_get( $url, $args = array() )

This function is a wrapper function that set correct width and height for iframes from wp_oembed_get() function

ParameterTypeDescription
$url
$argsarray

Returns bool\|string

Source: framework/helpers/general.php:1843

fw_prepare_option_value

fw_prepare_option_value( $value )

Used when getting some option value from serialized array saved in a custom place and that option is unreachable for standard WordPress filters by other plugins For e.g. that option cannot be translated by plugins, so we pass its value through this function and do the fixes

ParameterTypeDescription
$value

Returns array

Source: framework/helpers/general.php:1419

fw_print

fw_print( $value )

print_r() alternative

ParameterTypeDescription
$valuemixedValue to debug

Source: framework/helpers/general.php:478

fw_rand_md5

fw_rand_md5()

Generate a random unique 32-char hex token.

Uses random_bytes() (CSPRNG) on PHP 7+, falling back to wp_generate_password() if random_bytes is unavailable. Previously built from rand()/mt_rand()/uniqid() which are not cryptographically secure and would be flagged by security review if this token ever ends up in a security-sensitive context.

Returns string 32-character hexadecimal string.

Source: framework/helpers/general.php:455

fw_read_file_by_uri

fw_read_file_by_uri( $file_uri )

Try to find file path by its uri and read the file contents

ParameterTypeDescription
$file_uristring

Returns bool\|string false or string - the file contents

Source: framework/helpers/general.php:1948

fw_render_view

🔌 pluggable

fw_render_view( $file_path, $view_variables = array(), $return = true )

Safe render a view and return html In view will be accessible only passed variables Use this function to not include files directly and to not give access to current context variables (like $this)

ParameterTypeDescription
$file_pathstring
$view_variablesarray
$returnboolIn some cases, for memory saving reasons, you can disable the use of output buffering

Returns string HTML

Source: framework/helpers/general.php:851

fw_resize

🔌 pluggable

fw_resize( $url, $width = false, $height = false, $crop = false )

Resizes an image URL to the given dimensions via FW_Resize, returning the original URL on failure.

Source: framework/helpers/general.php:2177

fw_secure_rand

fw_secure_rand( $length )

Reference

Strong cryptography in PHP http://www.zimuel.it/en/strong-cryptography-in-php/ > Don't use rand() or mt_rand()

Returns string

Source: framework/helpers/general.php:1871

fw_set_db_customizer_option

fw_set_db_customizer_option( $option_id = null, $value = '' )

Set a theme customizer option value in database

ParameterTypeDescription
$option_idnullSpecific option id (accepts multikey). null - all options
$valuemixed

Source: framework/helpers/database.php:610

fw_set_db_ext_settings_option

fw_set_db_ext_settings_option( $extension_name, $option_id = null, $value = '' )

Set extension's setting option value in database

ParameterTypeDescription
$extension_namestring
$option_idstring|null
$valuemixed

Source: framework/helpers/database.php:520

fw_set_db_extension_data

fw_set_db_extension_data( $extension_name, $multi_key = null, $value = '' )

Set some extension's data in database

ParameterTypeDescription
$extension_namestring
$multi_keystring|nullThe key of the data you want to set. null - all data
$valuemixed

Source: framework/helpers/database.php:720

fw_set_db_extension_user_data

fw_set_db_extension_user_data( $user_id, $extension_name, $value, $keys = null )

In case the extension doesn't exist or is disabled, or the value is equal to previous, returns false

ParameterTypeDescription
$user_idint
$extension_namestring
$valuemixed
$keysstring

Returns bool\|int

Source: framework/helpers/database.php:660

fw_set_db_post_option

fw_set_db_post_option( $post_id = null, $option_id = null, $value = '' )

Set post option value in database

ParameterTypeDescription
$post_idnull|int
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$value

Source: framework/helpers/database.php:245

fw_set_db_settings_option

fw_set_db_settings_option( $option_id = null, $value = '' )

Set a theme settings option value in database

ParameterTypeDescription
$option_idnullSpecific option id (accepts multikey). null - all options
$valuemixed

Source: framework/helpers/database.php:78

fw_set_db_term_option

fw_set_db_term_option( $term_id, $taxonomy, $option_id = null, $value = '' )

Set term option value in database

ParameterTypeDescription
$term_idint
$taxonomystring
$option_idstring|nullSpecific option id (accepts multikey). null - all options
$valuemixed

Returns null

Source: framework/helpers/database.php:453

fw_string_to_icon_html

fw_string_to_icon_html( $icon, array $attributes = array() )

@param array Additional attributes

ParameterTypeDescription
$iconstringA string that is meant to be an icon (an image, a font icon class, or something else)

Returns string

Source: framework/helpers/general.php:2062

fw_stripslashes_deep_keys

fw_stripslashes_deep_keys( $value )

Strip slashes from values, and from keys if magic_quotes_gpc = On

Source: framework/helpers/general.php:601

fw_strlen

fw_strlen( $string )

Returns the UTF-8 length of a string, using mb_strlen() when available.

Source: framework/helpers/general.php:1770

fw_typography_size_css

🔌 pluggable

fw_typography_size_css( $size, $default_unit = 'px' )

Resolve a typography size value to a CSS length string, tolerating every shape the value can take across the size_format migration: - a unit-input array array( 'value' => '1.5', 'unit' => 'rem' ) -> "1.5rem" - a JSON string of that '{"value":"24","unit":"px"}' -> "24px" - a legacy plain number 16 / "16" -> "16px" - an already-typed CSS length string "1.25em" -> passthrough - blank / false -> '' So a size that predates the unit-input control (a bare integer) resolves exactly as before (+px), and a new unit-input value keeps its chosen unit.

ParameterTypeDescription
$sizemixed
$default_unitstringunit appended to a bare number (default 'px').

Returns string CSS length, or '' when there's nothing to emit.

Source: framework/helpers/general.php:2404

fw_unique_increment

fw_unique_increment()

Returns a per-request incrementing counter, unique within the current page load.

Source: framework/helpers/general.php:467

fw_update_comment_meta

fw_update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' )

Update comment meta field based on comment ID.

Use the $prev_value parameter to differentiate between meta fields with the same key and comment ID.

If the meta field for the comment does not exist, it will be added.

ParameterTypeDescription
$comment_idintComment ID.
$meta_keystringMetadata key.
$meta_valuemixedMetadata value.
$prev_valuemixedOptional. Previous value to check before removing.

Returns int\|bool Meta ID if the key didn't exist, true on successful update, false on failure.

Source: framework/helpers/meta.php:619

fw_update_metadata

fw_update_metadata( $meta_type, $object_id, $meta_key, $meta_value, $prev_value = '' )

Update metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.

@uses $wpdb WordPress database object for queries.

the specified value. Otherwise, update all entries.
ParameterTypeDescription
$meta_typestringType of object metadata is for (e.g., comment, post, or user)
$object_idintID of the object metadata is for
$meta_keystringMetadata key
$meta_valuemixedMetadata value. Must be serializable if non-scalar.
$prev_valuemixedOptional. If specified, only update existing metadata entries with

Returns int\|bool Meta ID if the key didn't exist, true on successful update, false on failure.

Source: framework/helpers/meta.php:177

fw_update_post_meta

fw_update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' )

Updates a post meta value via fw_update_metadata(), adding it if the key does not exist.

Update post meta field based on post ID.

Use the $prev_value parameter to differentiate between meta fields with the same key and post ID.

If the meta field for the post does not exist, it will be added.

Default empty.

false on failure.
ParameterTypeDescription
$post_idintPost ID.
$meta_keystringMetadata key.
$meta_valuemixedMetadata value. Must be serializable if non-scalar.
$prev_valuemixedOptional. Previous value to check before removing.

Returns int\|bool Meta ID if the key didn't exist, true on successful update,

Source: framework/helpers/meta.php:554

fw_update_term_meta

fw_update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' )

Update term meta field based on term ID.

Use the $prev_value parameter to differentiate between meta fields with the same key and term ID.

If the meta field for the term does not exist, it will be added.

ParameterTypeDescription
$term_idintTerm ID.
$keystringMetadata key.
$valuemixedMetadata value.
$prev_valuemixedOptional. Previous value to check before removing.

Returns bool False on failure, true if success.

Source: framework/helpers/meta.php:703

fw_update_user_meta

fw_update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' )

Update user meta field based on user ID.

Use the $prev_value parameter to differentiate between meta fields with the same key and user ID.

If the meta field for the user does not exist, it will be added.

ParameterTypeDescription
$user_idintUser ID.
$meta_keystringMetadata key.
$meta_valuemixedMetadata value.
$prev_valuemixedOptional. Previous value to check before removing.

Returns int\|bool Meta ID if the key didn't exist, true on successful update, false on failure.

Source: framework/helpers/meta.php:492

← Back to Functions overview