GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Functions
helper-functions.php File Reference

Go to the source code of this file.

Functions

 _gravityview_process_posted_fields ()
 Maybe convert jQuery-serialized fields into array, otherwise return $_POST['fields'] array. More...
 
 _gravityview_strip_subdomain ( $string_maybe_has_subdomain)
 Do a very basic match for second-level TLD domains, like .co.uk More...
 
 gravityview_css_url ( $css_file='', $dir_path='')
 Functions that don't require GravityView or Gravity Forms API access but are used in the plugin to extend PHP and WP functions. More...
 
 gravityview_format_link ( $value=null)
 Convert a whole link into a shorter link for display. More...
 
 gravityview_get_floaty ( $height=87, $css_class=null)
 Get an image of our intrepid explorer friend. More...
 
 gravityview_get_input_id_from_id ( $field_id='')
 Very commonly needed: get the # of the input based on a full field ID. More...
 
 gravityview_get_permalink_query_args ( $id=0)
 Get get_permalink() without the home_url() prepended to it. More...
 
 gravityview_get_terms_choices ( $args=array())
 Get categories formatted in a way used by GravityView and Gravity Forms input choices. More...
 
 gravityview_is_not_empty_string ( $mixed='')
 Check whether a variable is not an empty string. More...
 
 gravityview_maybe_convert_date_string_to_timestamp ( $value='')
 Convert a string to a timestamp if it's a valid date or a relative date prefixed with "relative:". More...
 
 gravityview_number_format ( $number, $decimals='', $separator=true)
 Intelligently format a number. More...
 
 gravityview_ob_include ( $file_path, $object=NULL)
 Get the contents of a file using include() and ob_start() More...
 
if(! function_exists( 'gravityview_sanitize_html_class')) gravityview_strip_whitespace ( $string)
 Replace multiple newlines, tabs, and spaces with a single space. More...
 
 gv_empty ( $value, $zero_is_empty=true, $allow_string_booleans=true)
 Is the value empty? More...
 
 gv_map_deep ( $value, $callback)
 Maps a function to all non-iterable elements of an array or an object. More...
 
 gv_maybe_json_decode ( $value, $assoc=false, $depth=512, $options=0)
 If content is JSON, decode it. More...
 
 gv_not_empty ( $value, $zero_is_empty=false, $allow_string_booleans=false)
 The inverse of gv_empty() More...
 
 gv_selected ( $value, $current, $echo=true, $type='selected')
 Similar to the WordPress selected(), checked(), and disabled() functions, except it allows arrays to be passed as current value. More...
 

Function Documentation

◆ _gravityview_process_posted_fields()

_gravityview_process_posted_fields ( )

Maybe convert jQuery-serialized fields into array, otherwise return $_POST['fields'] array.

Fields are passed as a jQuery-serialized array, created in admin-views.js in the serializeForm method.

Since
1.16.5

GVCommon::gv_parse_str

Returns
array Array of fields

Definition at line 627 of file helper-functions.php.

References gravityview(), and GVCommon\gv_parse_str().

Referenced by GravityView_Plugin_Hooks_ACF\fix_posted_fields(), and GravityView_Admin_Views\save_postdata().

◆ _gravityview_strip_subdomain()

_gravityview_strip_subdomain (   $string_maybe_has_subdomain)

Do a very basic match for second-level TLD domains, like .co.uk

Ideally, we'd use https://github.com/jeremykendall/php-domain-parser to check for this, but it's too much work for such a basic functionality. Maybe if it's needed more in the future. So instead, we use Basic matching regex.

Parameters
string$domainDomain to check if it's a TLD or subdomain
Returns
string Extracted domain if it has a subdomain

Definition at line 375 of file helper-functions.php.

Referenced by gravityview_format_link().

◆ gravityview_css_url()

gravityview_css_url (   $css_file = '',
  $dir_path = '' 
)

Functions that don't require GravityView or Gravity Forms API access but are used in the plugin to extend PHP and WP functions.

Since
1.12 Get the URL for a CSS file

If there's a CSS file with the same name as a GravityView CSS file in the current theme directory, it will be used. Place the CSS file in a /gravityview/css/ sub-directory.

Example: /twentysixteen/gravityview/css/gv-default-styles.css

Will use, in order: 1) [theme directory]/gravityview/css/ 2) [gravityview plugin]/css/ (no check performed)

Since
1.17

get_stylesheet_directory() get_stylesheet_directory_uri()

Parameters
string$css_fileFilename of the CSS file (like gv-default-styles.css)
string$dir_pathAbsolute path to the directory where the CSS file is stored. If empty, uses default GravityView templates CSS folder.
Returns
string URL path to the file.

Definition at line 30 of file helper-functions.php.

References gravityview(), and GRAVITYVIEW_DIR.

Referenced by GravityView_Default_Template_List\__construct(), GravityView_frontend\enqueue_default_style(), and GravityView_Field_Notes\register_scripts().

◆ gravityview_format_link()

gravityview_format_link (   $value = null)

Convert a whole link into a shorter link for display.

Since
1.1
Parameters
string$valueExisting URL
Returns
string If parse_url doesn't find a 'host', returns original value. Otherwise, returns formatted link.
Runs Filter:
gravityview_anchor_text_striphttp Strip scheme from the displayed URL?
Since
1.5.1
Parameters
boolean$enableWhether to strip the scheme. Return false to show scheme. (default: true)
If true: http://example.com => example.com
Runs Filter:
gravityview_anchor_text_stripwww Strip www from the domain?
Since
1.5.1
Parameters
boolean$enableWhether to strip www. Return false to show www. (default: true)
If true: www.example.com => example.com
Runs Filter:
gravityview_anchor_text_nosubdomain Strip subdomains from the domain?
Since
1.5.1
Parameters
boolean$enableWhether to strip subdomains. Return false to show subdomains. (default: true)
If true: http://demo.example.com => example.com
If false: http://demo.example.com => demo.example.com
Runs Filter:
gravityview_anchor_text_rootonly Display link path going only to the base directory, not a sub-directory or file?
Since
1.5.1
Parameters
boolean$enableWhether to enable "root only". Return false to show full path. (default: true)
If true: http://example.com/sub/directory/page.html => example.com
If false: http://example.com/sub/directory/page.html => example.com/sub/directory/page.html
Runs Filter:
gravityview_anchor_text_noquerystring Strip the query string from the end of the URL?
Since
1.5.1
Parameters
boolean$enableWhether to enable "root only". Return false to show full path. (default: true)
If true: http://example.com/?query=example => example.com

Definition at line 273 of file helper-functions.php.

References $value, and _gravityview_strip_subdomain().

◆ gravityview_get_floaty()

gravityview_get_floaty (   $height = 87,
  $css_class = null 
)

Get an image of our intrepid explorer friend.

Since
1.12
2.1 Added $class parameter
Parameters
int$heightHeight of the cutie in pixels
null | string$css_classIf defined, use the passed CSS class (can be empty string). Otherwise, use default alignleft (or alignright, based on RTL).
Returns
string HTML image tag with floaty's cute mug on it

Definition at line 208 of file helper-functions.php.

References GRAVITYVIEW_FILE.

Referenced by GravityView_Admin_Notices\admin_notice(), GravityView_Admin\connected_form_warning(), GravityView_Admin\get_floaty(), and GravityView_Welcome\tabs().

◆ gravityview_get_input_id_from_id()

gravityview_get_input_id_from_id (   $field_id = '')

Very commonly needed: get the # of the input based on a full field ID.

Example: 12.3 => field #12, input #3. Returns: 3 Example: 7 => field #7, no input. Returns: 0

Since
1.16.4
Parameters
string$field_idFull ID of field, with or without input ID, like "12.3" or "7".
Returns
int If field ID has an input, returns that input number. Otherwise, returns false.

Definition at line 550 of file helper-functions.php.

References $field_id, and gravityview().

Referenced by GravityView_Field_List\_filter_field_label(), GravityView_Field_Date\date_display(), GravityView_Field_Time\date_format(), GravityView_Field_Survey\field_options(), GravityView_Widget_Search\prepare_field_filter(), GravityView_Field_Address\search_bar_input_type(), and GravityView_Field_Address\search_field_filter().

◆ gravityview_get_permalink_query_args()

gravityview_get_permalink_query_args (   $id = 0)

Get get_permalink() without the home_url() prepended to it.

get_permalink() does a lot of good stuff: it gets the correct permalink structure for custom post types, pages, posts, etc. Instead of using ?p={id}, ?page_id={id}, or ?p={id}&post_type={post_type}, by using get_permalink(), we can use ?p=slug or ?gravityview={slug}

We could do this in a cleaner fashion, but this prevents a lot of code duplication, checking for URL structure, etc.

Parameters
int | WP_Post$idOptional. Post ID or post object. Default current post.
Returns
array URL args, if exists. Empty array if not.

Definition at line 81 of file helper-functions.php.

References $args.

Referenced by GravityView_Widget_Search\add_no_permalink_fields().

◆ gravityview_get_terms_choices()

gravityview_get_terms_choices (   $args = array())

Get categories formatted in a way used by GravityView and Gravity Forms input choices.

Since
1.15.3
See also
get_terms()
Parameters
array$argsArguments array as used by the get_terms() function. Filtered using gravityview_get_terms_choices_args filter. Defaults: {
string $taxonomy Used as first argument in get_terms(). Default: "category" string $fields Default: 'id=>name' to only fetch term ID and Name
int $number Limit the total number of terms to fetch. Default: 1000
}
Returns
array Multidimensional array with text (Category Name) and value (Category ID) keys.
Runs Filter:
gravityview_get_terms_choices_args Modify the arguments passed to get_terms()
See also
get_terms()
Since
1.15.3

Definition at line 577 of file helper-functions.php.

References $args.

Referenced by GravityView_Widget_Search\get_search_filter_details().

◆ gravityview_is_not_empty_string()

gravityview_is_not_empty_string (   $mixed = '')

Check whether a variable is not an empty string.

See also
/templates/fields/product.php Used to check whether the product array is empty or not
Since
1.12
Parameters
mixed$mixedVariable to check
Returns
bool true: $mixed is not an empty string; false: $mixed is an empty string

Definition at line 64 of file helper-functions.php.

◆ gravityview_maybe_convert_date_string_to_timestamp()

gravityview_maybe_convert_date_string_to_timestamp (   $value = '')

Convert a string to a timestamp if it's a valid date or a relative date prefixed with "relative:".

For example: "relative:-1 week" or "relative:tomorrow" will be converted to a timestamp.

Note: This assumes the date is using a Gregorian calendar.

Since
2.14.8

GFCommon::parse_date() DateTimeImmutable::createFromFormat()

strtotime()

Parameters
string$valueThe string to convert to a timestamp. Supports relative dates and different date formats. Does its best to figure out the date format.
Returns
false|int Timestamp if valid date, otherwise false.

Definition at line 669 of file helper-functions.php.

References $value.

Referenced by GVCommon\matches_operation().

◆ gravityview_number_format()

gravityview_number_format (   $number,
  $decimals = '',
  $separator = true 
)

Intelligently format a number.

If you don't define the number of decimal places, then it will use the existing number of decimal places. This is done in a way that respects the localization of the site.

If you do define decimals, it uses number_format_i18n()

See also
number_format_i18n()
Since
1.13
Parameters
int | float | string | double$numberA number to format
int | string$decimalsOptional. Precision of the number of decimal places. Default '' (use existing number of decimals)
boolean$separatorSeparate with dots or commas, etc. Default: true.
Returns
string Converted number in string format.

Calculate the position of the decimal point in the number

See also
http://stackoverflow.com/a/2430144/480856

Definition at line 241 of file helper-functions.php.

◆ gravityview_ob_include()

gravityview_ob_include (   $file_path,
  $object = NULL 
)

Get the contents of a file using include() and ob_start()

Since
1.13
1.15 Added $object param
Parameters
string$file_pathFull path to a file
mixed$objectPass pseudo-global to the included file
Returns
string Included file contents

Definition at line 187 of file helper-functions.php.

References gravityview().

Referenced by GravityView_Edit_Entry_Render\edit_entry_form(), and GravityView_Edit_Entry_Render\render_form_buttons().

◆ gravityview_strip_whitespace()

if (! function_exists('gravityview_sanitize_html_class')) gravityview_strip_whitespace (   $string)

Replace multiple newlines, tabs, and spaces with a single space.

First, runs normalize_whitespace() on a string. This replaces multiple lines with a single line, and tabs with spaces. We then strip any tabs or newlines and replace those with a single space.

See also
normalize_whitespace()
GravityView_Helper_Functions_Test::test_gravityview_strip_whitespace
Since
1.13
Parameters
string$stringString to strip whitespace from
Returns
string Stripped string!

Definition at line 172 of file helper-functions.php.

Referenced by GravityView_Field_Notes\display_note(), GravityView_Edit_Entry_Render\edit_entry_form(), GravityView_Field_Notes\get_add_note_part(), GravityView_Ajax\get_field_options(), and GravityView_Ajax\get_sortable_fields().

◆ gv_empty()

gv_empty (   $value,
  $zero_is_empty = true,
  $allow_string_booleans = true 
)

Is the value empty?

Allows you to pass a function instead of just a variable, like the empty() function insists upon (until PHP 5.5)

Checks whether false, null, empty string, empty array, object with no vars defined

Since
1.15.1
Parameters
mixed$valueCheck whether this is empty
boolean$zero_is_emptyShould the number zero be treated as an empty value?
boolean$allow_string_booleansWhether to check if 'yes', 'true' => true and 'no', 'false' => false
Returns
boolean True: empty; false: not empty

Arrays with empty values are empty.

Consider the a missing product field.

Definition at line 412 of file helper-functions.php.

References $value.

Referenced by GravityView_Widget_Search\filter_entries(), GravityView_Edit_Entry_Render\get_field_value(), gv_not_empty(), GravityView_Shortcode\parse_and_sanitize_atts(), gravityview\parse_and_sanitize_atts(), and Field_Template\render().

◆ gv_map_deep()

gv_map_deep (   $value,
  $callback 
)

Maps a function to all non-iterable elements of an array or an object.

See also
map_deep() This is an alias of the WP core function map_deep(), added in 4.4. Here for legacy purposes.
Since
1.16.3
Parameters
mixed$valueThe array, object, or scalar.
callable$callbackThe function to map onto $value.
Returns
mixed The value with the callback applied to all non-arrays and non-objects inside it.

Definition at line 511 of file helper-functions.php.

References $value.

Referenced by gvfield\callback(), gvlogic\callback(), GravityView_Widget_Search\filter_entries(), GVCommon\get_directory_widgets(), GravityView_Widget_Search\rgget_or_rgpost(), GravityView_Field_Post_Category\set_post_categories(), and GravityView_Field_Notes\strings().

◆ gv_maybe_json_decode()

gv_maybe_json_decode (   $value,
  $assoc = false,
  $depth = 512,
  $options = 0 
)

If content is JSON, decode it.

Otherwise, return the passed value

Since
2.0
See also
json_decode() for more information about the function parameters
Parameters
string$valueThe string that may be decoded
bool$assoc[optional] When true, returned objects will be converted into associative arrays
int$depth[optional] User specified recursion depth.
int$options[optional] Bitmask of JSON decode options. Used only on sites running PHP 5.4+
Returns
array|mixed|object|string If $value is JSON, returns the response from json_decode(). Otherwise, returns original value.

Definition at line 474 of file helper-functions.php.

References $value.

Referenced by View_Collection\merge_deep().

◆ gv_not_empty()

gv_not_empty (   $value,
  $zero_is_empty = false,
  $allow_string_booleans = false 
)

The inverse of gv_empty()

Since
2.0
Parameters
mixed$valueCheck whether this is not empty
bool$zero_is_emptyShould the number zero be treated as an empty value? Default: false
bool$allow_string_booleansWhether to check if 'yes', 'true' => true and 'no', 'false' => false. Default: false
Returns
bool

Definition at line 395 of file helper-functions.php.

References $value, and gv_empty().

◆ gv_selected()

gv_selected (   $value,
  $current,
  $echo = true,
  $type = 'selected' 
)

Similar to the WordPress selected(), checked(), and disabled() functions, except it allows arrays to be passed as current value.

See also
selected() WordPress core function
Parameters
string$valueOne of the values to compare
mixed$current(true) The other value to compare if not just true
bool$echoWhether to echo or just return the string
string$typeThe type of checked|selected|disabled we are doing
Returns
string html attribute or empty string

sanitize_html_class doesn't handle spaces (multiple classes). We remedy that.

sanitize_html_class

Parameters
string | array$classesText or array of classes to sanitize
Returns
string Sanitized CSS string

Definition at line 109 of file helper-functions.php.

References $output, and $value.

Referenced by Page_Size\render_frontend().