Helper Functions
#
OverviewMethod contains a number of helper functions, which are detailed below. If using a custom build of the Method theme, the method prefix will instead be whatever prefix you defined in Method Builder's globals file.
Jump to:
- method_get_class()
- method_filter_content()
- method_check_key()
- method_get_post_array()
- method_get_term_array()
#
method_get_class( $class )This function retrieves a string containing one of multiple CSS classes, if one is found matching the $class string passed to the function. You can add new switch cases to this function to make it better work with your theme. This can be particularly useful for classes that need to be uniform across all site layouts, as it allows you to quickly make any needed changes without needing to do repetitive updates.
#
Arguments- $class
(string) (required) The short name for the string containing of class(es) that you'd like to retrieve.
#
ExampleThe following code:
Would produce:
#
method_filter_content( $content )This function applys WordPress' the_content filter to a passed string (if the passed string is not empty).
#
Arguments- $content
(string) (required) A string of unfiltered content, such as content entered through the visual editor.
#
ExampleThe following code:
Would produce:
#
NotesThis function is identical to the filter_content() method included in the Method_Layout class. It is included as a function for use outside of the class as needed (such as functions for AJAX responses).
#
method_check_key( $key )This function checks to see if a passed value is set and is not empty. If both conditions are met, the function returns true. Otherwise, the function returns false.
#
Arguments- $key
(string) (required) The variable to evaluate.
#
ExampleTake the following code:
In the example above:
- $check1 would equal true
- $check2 would equal false
- $check3 would equal false
#
NotesThis function is identical to the check_key() method included in the Method_Layout class. It is included as a function for use outside of the class as needed (such as functions for AJAX responses).
#
method_get_post_array( $type, $none = '' )This function returns an array of post IDs ($key) and post titles ($value) belonging to the passed post type, if any exist and are public, and an optional none value. This function is primarily used to populate options using the CMB2 select field.
#
Arguments- $type
(string) (required) The post type that you would like to retrieve post IDs and titles for. - $none
(string) (optional) If you would like to include a default None value as the first item in the array (with an empty $key), provide a string to use.
#
ExampleTake the follow code:
This would produce:
#
NotesThe ability to provide a custom value for None was added in v1.2.0.
#
method_get_term_array( $tax, $none = '' )This function returns an array of term IDs ($key) and term names ($value) belonging to the passed taxonomy, if any exist and are public, and an optional none value. Empty taxonomies are included. As with method_get_post_array(), this function is primarily used to populate options using the CMB2 select field.
#
Arguments- $tax
(string) (required) The taxonomy that you would like to retrieve term IDs and term names for. - $none
(string) (optional) If you would like to include a default None value as the first item in the array (with an empty $key), provide a string to use.
#
ExampleTake the follow code:
This would produce:
#
NotesThe ability to provide a custom value for None was added in v1.2.0.