Created
January 24, 2012 04:47
-
-
Save sorich87/1667864 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Get a field by its id or slug | |
**/ | |
public static function get_by( $field, $value ) { | |
global $wpdb; | |
switch ( $field ) { | |
case 'id' : | |
$field = 'ID'; | |
$field_id = $value; | |
break; | |
case 'slug' : | |
$field = 'field_slug'; | |
$field_id = wp_cache_get( $value, 'rs_registration_fields_slugs' ); | |
break; | |
default: | |
return false; | |
} | |
$fields = false; | |
if ( false !== $field_id ) | |
$fields = wp_cache_get( $field_id, 'rs_registration_fields' ) ); | |
if ( false === $fields ) { | |
$fields = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->rs_registration_fields} WHERE $field = %s", $value ) ); | |
if ( $fields ) { | |
$fields = self::clean_up( $fields ); | |
self::update_caches( $fields ); | |
} | |
} | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment