Created
August 4, 2011 17:52
-
-
Save jontas/1125756 to your computer and use it in GitHub Desktop.
Easy Content Types Date change
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
| jtaschermbp:easy-content-types jontas$ git diff . | |
| diff --git a/wp-content/plugins/easy-content-types/includes/register-meta-boxes.php b/wp-content/plugins/easy-content-types/includes/register-meta-boxes.php | |
| index bd54733..de44155 100755 | |
| --- a/wp-content/plugins/easy-content-types/includes/register-meta-boxes.php | |
| +++ b/wp-content/plugins/easy-content-types/includes/register-meta-boxes.php | |
| @@ -71,7 +71,7 @@ function ecpt_show_box($post, $metabox) { | |
| ', $field['desc']; | |
| break; | |
| case 'date': | |
| - echo '<input type="text" class="ecpt_datepicker" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', ' | |
| + echo '<input type="text" class="ecpt_datepicker" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? ecpt_get_date($meta) : $field['std'], '" size="30" style="width:97%" />', ' | |
| ', $field['desc']; | |
| break; | |
| case 'upload': | |
| @@ -155,6 +155,8 @@ function ecpt_save_data($post_id) { | |
| if($field->type == 'textarea') { | |
| // preserve line breaks for textareas | |
| $new = wpautop($data); | |
| + } elseif ('date' == $field->type) { | |
| + $new = strtotime(str_replace('-', '/', $data)); //strtotime can't do m-d-y, only m/d/y | |
| } else { | |
| $new = $data; | |
| } | |
| @@ -169,5 +171,12 @@ function ecpt_save_data($post_id) { | |
| } | |
| } | |
| +function ecpt_get_date($date) { | |
| + //this is to handle legacy data where the date is still a string | |
| + if (!is_numeric($date)) { | |
| + $date = strtotime(str_replace('-', '/', $date)); //strtotime can't do m-d-y, only m/d/y | |
| + } | |
| + return date('m-d-Y', $date); | |
| +} | |
| ?> | |
| \ No newline at end of file | |
| diff --git a/wp-content/plugins/easy-content-types/includes/shortcodes.php b/wp-content/plugins/easy-content-types/includes/shortcodes.php | |
| index 63d32ad..b76dde7 100755 | |
| --- a/wp-content/plugins/easy-content-types/includes/shortcodes.php | |
| +++ b/wp-content/plugins/easy-content-types/includes/shortcodes.php | |
| @@ -18,8 +18,17 @@ function ecpt_field_shortcode( $atts, $content = null ) | |
| if($url) { $field .= '</a>'; } | |
| } else { | |
| + | |
| + global $ecpt_db_meta_fields_name; | |
| + global $wpdb; | |
| + $value = get_post_meta($post->ID, $ecpt_prefix . $id, true); | |
| + $field_type = $wpdb->get_var("SELECT type FROM {$ecpt_db_meta_fields_name} WHERE name = '" . $wpdb->escape($id) . "'"); //not sure if i need this escape but it can't hurt | |
| + if ('date' == $field_type && is_numeric($value)) { | |
| + $value = date('m-d-Y', $value); | |
| + } | |
| + | |
| if($url) { $field .= '<a href="' . $url . '">'; } | |
| - $field .= get_post_meta($post->ID, $ecpt_prefix . $id, true); | |
| + $field .= $value; | |
| if($url) { $field .= '</a>'; } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment