Skip to main content

GFCommon

Class GFCommon

Includes common methods accessed throughout Gravity Forms and add-ons.

Source: common.php:18

Details

  • Kind: class
  • Namespace: (global)

Properties

PropertyTypeDescription
$dismissible_messagesarrayAn array of dismissible messages to display on the page.

Methods

MethodDescription
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

NameTypeDefaultDescription
$number_formatstringThe 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

NameTypeDefaultDescription
$valuestringThe value to be cleaned.
$currencynull | array | stringnullNull to use the default currency, an array of currency properties, or the currency code.

Returns

  • string

Since:

  • unknown
  • 2.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

NameTypeDefaultDescription
$numberint | float | stringThe number to format.
$number_formatstringThe field number format: decimal_comma, decimal_dot, or currency.
$currency_code_or_entrystring | array''The currency code or entry object. Optional.
$include_thousands_sepboolfalseIndicates if the thousands separator should be included. Optional.

Returns

  • string

Since:

  • unknown
  • 2.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

NameTypeDefaultDescription
$valuestringJSON 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

NameTypeDefaultDescription
$stringstringJSON 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

NameTypeDefaultDescription
$stringstringJSON 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:

  • unknown
  • 2.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

NameTypeDefaultDescription
$image_pathstringThe 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

NameTypeDefaultDescription
$image_pathstringThe 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

NameTypeDefaultDescription
$font_pathstringThe 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

NameTypeDefaultDescription
$font_pathstringThe 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

NameTypeDefaultDescription
$pathstringThe 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

NameTypeDefaultDescription
$filestringThe 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

NameTypeDefaultDescription
$patternstringThe pattern to be appended to the base path when performing the search.
$base_pathstring''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

NameTypeDefaultDescription
$patternstringThe pattern to be appended to the base path when performing the search.
$base_pathstring''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

NameTypeDefaultDescription
$urlstringThe 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

NameTypeDefaultDescription
$urlstringThe URL to validate.
$argsarray[]{ 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

NameTypeDefaultDescription
$fieldsGF_Field[]
$element_id
$hide_all_fieldsboolfalse
$exclude_field_typesarray[]
$optionstring''

Returns

  • array

Source: common.php:905

get_field_merge_tags()

public static function get_field_merge_tags( $field, $option='' )

Parameters

NameTypeDefaultDescription
$fieldGF_Field
$optionstring''

Returns

  • string

Source: common.php:1084