Last active
July 26, 2016 18:23
-
-
Save tripflex/d566c5ae51dcb23fd7916f0e87ff2b5b to your computer and use it in GitHub Desktop.
Get custom field configuration data (to get label, description, or other field configuration)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is for backwards compatibility with Field Editor 1.4.6 or older, any version 1.4.7 and newer | |
* will already have this function built-in, probably with some type of caching as well. | |
* | |
* If you decide to add this to your site, make sure to remove it later on if you upgrade to 1.4.7 or | |
* newer. | |
*/ | |
if( ! function_exists( 'get_custom_field_config' ) ){ | |
/** | |
* Get Custom Field Configuration | |
* | |
* | |
* @since @@version | |
* | |
* @param string $meta_key Meta key of the field to obtain configuration for | |
* @param string $config_key (Optional) Return a specific configuration value (eg label, description, etc) | |
* | |
* @return array|bool $value Returns FALSE if error, or field config not found, otherwise returns an | |
* array of configuration data for the field. | |
*/ | |
function get_custom_field_config( $meta_key = false, $config_key = false ){ | |
if( ! $meta_key || ! class_exists( 'WP_Job_Manager_Field_Editor_Fields' ) ) return false; | |
$jmfe = WP_Job_Manager_Field_Editor_Fields::get_instance(); | |
$all_fields = $jmfe->get_fields(); | |
if( empty( $all_fields ) ) return FALSE; | |
/** | |
* Loop through each field group (job, company, resume_fields), | |
* checking for meta key which will be the array key. | |
*/ | |
foreach( $all_fields as $field_group => $fields ) { | |
if( array_key_exists( $meta_key, $fields ) ) { | |
if( ! empty( $config_key ) && array_key_exists( $config_key, $fields[ $meta_key ] ) ){ | |
return $fields[ $meta_key ][ $config_key ]; | |
} | |
return $fields[$meta_key]; | |
} | |
} | |
/** | |
* Return FALSE when all else fails | |
*/ | |
return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment