GFCommon
Class GFCommon
Includes common methods accessed throughout Gravity Forms and add-ons.
Source: common.php:18
Details
- Kind:
class - Namespace:
(global)
Properties
| Property | Type | Description |
|---|---|---|
$dismissible_messages | array | An array of dismissible messages to display on the page. |
Methods
| Method | Description |
|---|---|
get_number_separators() | Returns the decimal and thousands separators for the specified number format. |
is_block_editor_page() | Determines if the current page is the block editor. |
is_block_renderer_request() | Determines if the current request is a block renderer request. These are REST API requests that render a block in the block editor. |
remove_currency_symbol() | Removes the currency symbol from the supplied value. |
format_number() | Formats the given value using currency or number formatting. |
maybe_decode_json() | Decode JSON string to array. |
is_json() | Determines if provided string is a JSON object. |
strip_all_tags_from_json_string() | Strips HTML tags using wp_strip_all_tags from a string that may contain unicode. |
get_base_path() | Returns the physical path of the plugin's root folder, without trailing slash. |
get_image_url() | Returns the URL to an image within the plugin's image directory. |
get_image_path() | Returns the path to an image within the plugin's image directory. |
get_font_url() | Returns the URL to an font file within the plugin's fonts directory. |
get_font_path() | Returns the path to an font file within the plugin's fonts directory. |
get_absolute_path() | Converts a relative path and any path symbols to the full resolved path. |
is_file_in_uploads() | Checks if the given file path is within the canonical uploads folder. |
glob() | Returns an array of files/directories which match the supplied pattern. |
glob_require_once() | Requires and returns an array of files which match the supplied pattern. |
is_valid_url() | Validates URLs. |
validate_file_url() | Validates a file URL for security concerns including scheme, traversal, null bytes, and file extension. |
get_merge_tags() | This function is used by the gfMergeTags JS object to get the localized label for non-field merge tags as well as |
get_field_merge_tags() |
Method Reference
get_number_separators()
public static function get_number_separators( $number_format )
Returns the decimal and thousands separators for the specified number format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$number_format | string | The number format to get the separators for. |
Returns
array— Returns an array containing the decimal and thousands separators.
Since: 2.9.3
Source: common.php:90
is_block_editor_page()
public static function is_block_editor_page()
Determines if the current page is the block editor.
Returns
bool— Returns true if the current page is the block editor. Returns false otherwise.
Since: 2.7
Source: common.php:109
is_block_renderer_request()
public static function is_block_renderer_request(): bool
Determines if the current request is a block renderer request. These are REST API requests that render a block in the block editor.
Returns
bool— Returns true if the current request is a block renderer request. Returns false otherwise.
Since: 2.9.7
Source: common.php:139
remove_currency_symbol()
public static function remove_currency_symbol( $value, $currency=null )
Removes the currency symbol from the supplied value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | string | The value to be cleaned. | |
$currency | null | array | string | null | Null to use the default currency, an array of currency properties, or the currency code. |
Returns
string
Since:
unknown2.4.18(Updated to support the currency code being passed for the $currency param.)
Source: common.php:154
format_number()
public static function format_number( $number, $number_format, $currency_code_or_entry='', $include_thousands_sep=false )
Formats the given value using currency or number formatting.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$number | int | float | string | The number to format. | |
$number_format | string | The field number format: decimal_comma, decimal_dot, or currency. | |
$currency_code_or_entry | string | array | '' | The currency code or entry object. Optional. |
$include_thousands_sep | bool | false | Indicates if the thousands separator should be included. Optional. |
Returns
string
Since:
unknown2.9.29(Updated the third parameter to accept the currency code or entry object.)
Source: common.php:222
maybe_decode_json()
public static function maybe_decode_json( $value )
Decode JSON string to array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | string | JSON string. |
Returns
array|string
Since: 2.5
Source: common.php:444
is_json()
public static function is_json( $string )
Determines if provided string is a JSON object.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$string | string | JSON string. |
Returns
bool
Since: 2.5
Source: common.php:462
strip_all_tags_from_json_string()
public static function strip_all_tags_from_json_string( $string )
Strips HTML tags using wp_strip_all_tags from a string that may contain unicode.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$string | string | JSON string. |
Returns
string
Since: 2.8.5
Source: common.php:480
get_base_path()
public static function get_base_path()
Returns the physical path of the plugin's root folder, without trailing slash.
Returns
string
Since:
unknown2.6.2(Updated to use GF_PLUGIN_DIR_PATH.)
Source: common.php:500
get_image_url()
public static function get_image_url( $image_path )
Returns the URL to an image within the plugin's image directory.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$image_path | string | The image path, including subdirectories if needed. |
Returns
string
Since: 2.5
Source: common.php:513
get_image_path()
public static function get_image_path( $image_path )
Returns the path to an image within the plugin's image directory.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$image_path | string | The image path, including subdirectories if needed. |
Returns
string
Since: 2.5
Source: common.php:528
get_font_url()
public static function get_font_url( $font_path )
Returns the URL to an font file within the plugin's fonts directory.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$font_path | string | The font path, including subdirectories if needed. |
Returns
string
Since: 2.5
Source: common.php:543
get_font_path()
public static function get_font_path( $font_path )
Returns the path to an font file within the plugin's fonts directory.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$font_path | string | The font path, including subdirectories if needed. |
Returns
string
Since: 2.5
Source: common.php:558
get_absolute_path()
public static function get_absolute_path( $path )
Converts a relative path and any path symbols to the full resolved path.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$path | string | The path to process. |
Returns
string
Since: 2.10.1
Source: common.php:573
is_file_in_uploads()
public static function is_file_in_uploads( $file )
Checks if the given file path is within the canonical uploads folder.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$file | string | The file to check. |
Returns
bool
Since: 2.10.1
Source: common.php:605
glob()
public static function glob( $pattern, $base_path='' )
Returns an array of files/directories which match the supplied pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$pattern | string | The pattern to be appended to the base path when performing the search. | |
$base_path | string | '' | The base path. Defaults to the plugin's root folder. |
Returns
array|false
Since: 2.4.15
Source: common.php:631
glob_require_once()
public static function glob_require_once( $pattern, $base_path='' )
Requires and returns an array of files which match the supplied pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$pattern | string | The pattern to be appended to the base path when performing the search. | |
$base_path | string | '' | The base path. Defaults to the plugin's root folder. |
Returns
array|false
Since: 2.4.15
Source: common.php:653
is_valid_url()
public static function is_valid_url( $url )
Validates URLs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$url | string | The URL to validate. |
Returns
bool— True if valid. False otherwise.
Since: 2.0.7.12 (Filters added to allow for using custom validation.)
Source: common.php:705
validate_file_url()
public static function validate_file_url( $url, $args=[] )
Validates a file URL for security concerns including scheme, traversal, null bytes, and file extension.
Returns a WP_Error on failure with a specific error code, or true on success.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$url | string | The URL to validate. | |
$args | array | [] | { Optional. Validation arguments. |
Returns
true| WP_Error — True if the URL passes all checks, WP_Error otherwise.
Since: 2.10.2
Source: common.php:759
get_merge_tags()
public static function get_merge_tags( $fields, $element_id, $hide_all_fields=false, $exclude_field_types=[], $option='' )
This function is used by the gfMergeTags JS object to get the localized label for non-field merge tags as well as
for backwards compatibility with the gform_custom_merge_tags hook. Lastly, this plugin is used by the soon-to-be deprecated insert_variables() function as the new gfMergeTags object has not yet been applied to the Post Content Template setting.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$fields | GF_Field[] | ||
$element_id | |||
$hide_all_fields | bool | false | |
$exclude_field_types | array | [] | |
$option | string | '' |
Returns
array
Source: common.php:905
get_field_merge_tags()
public static function get_field_merge_tags( $field, $option='' )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field | GF_Field | ||
$option | string | '' |
Returns
string
Source: common.php:1084