WordPress.org

Plugin Directory

Changeset 618615


Ignore:
Timestamp:
10/29/12 12:39:25 (18 months ago)
Author:
eskapism
Message:

version 1.0.6

Location:
simple-fields
Files:
2 added
5 edited
14 copied

Legend:

Unmodified
Added
Removed
  • simple-fields/tags/1.0.6/functions.php

    r617428 r618615  
    3939function simple_fields_get_post_value($post_id, $field_name_or_id, $single = true) { 
    4040 
     41    global $sf; 
     42 
    4143    $fetch_by_id = true; 
    4244    if (is_array($field_name_or_id) && sizeof($field_name_or_id) == 2) { 
     
    7577                } 
    7678 
     79                // xxx make sure extended return value works here too 
     80                // check for settings saved for the field (in gui or through register_field_group) 
     81                $parsed_options_for_this_field = array(); 
     82                $field_options_key = "type_".$one_field["type"]."_options"; 
     83                if (isset($one_field[$field_options_key])) { 
     84                    // settings exist for this field 
     85                    if (isset($one_field[$field_options_key]["enable_extended_return_values"]) && $one_field[$field_options_key]["enable_extended_return_values"]) { 
     86                        $parsed_options_for_this_field["extended_return"] = 1; 
     87                    } 
     88 
     89                    if (isset($parsed_options_for_this_field["extended_return"]) && $parsed_options_for_this_field["extended_return"]) { 
     90                        // Yep, use extended return values 
     91                        $num_values = count($saved_values); 
     92                        while ($num_values--) { 
     93                            $saved_values[$num_values] = $sf->get_extended_return_values_for_field($one_field, $saved_values[$num_values]); 
     94                        } 
     95                    } 
     96 
     97                } 
     98                 
    7799                if ($is_found && $single) { 
    78100                    $return_val = $saved_values[0]; 
     
    81103                } 
    82104 
     105                // hm.. can't get here right??! 
    83106                if ($is_found) { 
    84107                    return $return_val; 
     
    184207 */ 
    185208function simple_fields_get_all_fields_and_values_for_post($post_id, $args = "") { 
    186  
    187     $cache_key = 'simple_fields_get_all_fields_and_values_for_post_' . $post_id . json_encode($args); 
    188     $selected_post_connector = wp_cache_get( $cache_key ); 
     209     
     210    global $sf; 
     211    $cache_key = 'simple_fields_'.$sf->ns_key.'_get_all_fields_and_values_for_post_' . $post_id . json_encode($args); 
     212    $selected_post_connector = wp_cache_get( $cache_key , 'simple_fields' ); 
    189213 
    190214    if (FALSE === $selected_post_connector) { 
     
    195219        $args = wp_parse_args($args, $defaults); 
    196220     
    197         global $sf; 
    198221        $post                     = get_post($post_id); 
    199222        $connector_to_use         = $sf->get_selected_connector_for_post($post); 
     
    275298                    $selected_post_connector["field_groups"][$one_field_group["id"]]["fields"][$one_field_id]["saved_values"][$num_in_set] = $saved_value; 
    276299                    $selected_post_connector["field_groups"][$one_field_group["id"]]["fields"][$one_field_id]["meta_keys"][$num_in_set] = $custom_field_key; 
    277  
    278                 } 
    279             } 
    280      
    281         } 
    282         wp_cache_set( $cache_key, $selected_post_connector ); 
     300     
     301                } 
     302            } 
     303     
     304        } 
     305        wp_cache_set( $cache_key, $selected_post_connector, 'simple_fields' ); 
    283306    } 
    284307 
     
    436459    #sf_d($field_groups); 
    437460    $highest_id = 0; 
    438      
     461 
    439462    // First get the id of the field group we are adding. Existing or highest new. 
    440463    // Loop through all existing field groups to see if the field group we are adding already exists 
     
    642665    } // if passed as arg field group has fields 
    643666 
    644     #sf_d($field_groups[$field_group_id]); 
    645     #sf_d($fields); 
    646  
    647     wp_cache_delete( "simple_fields_groups" ); 
     667    $sf->clear_caches(); 
    648668    update_option("simple_fields_groups", $field_groups); 
    649669 
     
    756776 
    757777    } 
    758  
    759     wp_cache_delete("simple_fields_post_connectors"); 
     778     
     779    $sf->clear_caches(); 
    760780    update_option("simple_fields_post_connectors", $post_connectors); 
    761781 
     
    811831        unset($post_type_defaults[0]); 
    812832    } 
    813  
    814     wp_cache_delete("simple_fields_post_type_defaults"); 
     833     
     834    $sf->clear_caches(); 
    815835    update_option("simple_fields_post_type_defaults", $post_type_defaults); 
    816836 
     
    897917                update_post_meta($post_id, "_simple_fields_fieldGroupID_{$field_group_id}_fieldID_added_numInSet_{$num_in_set}", 1); 
    898918                update_post_meta($post_id, "_simple_fields_been_saved", 1); 
    899  
    900                 // value updated. exit function. 
    901                 return; 
     919                 
     920                // value updated. clear cache and exit function. 
     921                $sf->clear_caches(); 
     922                return TRUE; 
    902923 
    903924            } // if 
     
    11921213    } 
    11931214 
    1194     $cache_key = "simple_fields_fieldgroup_" . $field_group_id_or_slug . "_" . $post_id . json_encode($options); 
    1195     $values = wp_cache_get( $cache_key ); 
     1215    global $sf; 
     1216    $cache_key = "simple_fields_".$sf->ns_key."_fieldgroup_" . $field_group_id_or_slug . "_" . $post_id . json_encode($options); 
     1217    $values = wp_cache_get( $cache_key, 'simple_fields'); 
    11961218    if (FALSE === $values) { 
    11971219     
    1198         global $sf; 
    11991220        $field_group = $sf->get_field_group_by_slug($field_group_id_or_slug); 
    12001221     
     
    12111232            $values = simple_fields_value($str_field_slugs, $post_id); 
    12121233        } 
    1213         wp_cache_set( $cache_key, $values ); 
     1234        wp_cache_set( $cache_key, $values, 'simple_fields' ); 
    12141235    } 
    12151236    return $values; 
    12161237} 
    1217  
    12181238 
    12191239/* 
  • simple-fields/tags/1.0.6/readme.txt

    r617428 r618615  
    55Requires at least: 3.3.1 
    66Tested up to: 3.4.2 
    7 Stable tag: 1.0.5 
     7Stable tag: 1.0.6 
    88 
    99Add more advanced custom fields types to your edit post page. Field can be of several types, including textarea, checkbox, radio buttons, files and color picker. 
     
    164164 
    165165== Changelog == 
     166 
     167#### Version 1.0.6 
     168- Added: date_i8n-format for date field when using extended return values 
     169- Added: support for extended return values for function simple_fields_get_post_value() 
     170- Fxed: added group to cache functions + clears the cache when using the register-functions 
     171- Fixed: file dialog javascript now checks that the pagenow variable exists before trying to use it. Hopefully fixes problems with Post Thumbnail Editor 
     172 and other plugins that also use the file dialog. 
     173- Changed: hide "show time" for date field, since we don't use it for anything 
    166174 
    167175#### Version 1.0.5 
  • simple-fields/tags/1.0.6/scripts.js

    r617428 r618615  
    621621        // Media browser: make sure search and filter works by adding hidden inputs 
    622622        // would have been best to do this in PHP, but I can't find any filter for it 
    623         if ( pagenow == "media-upload-popup" && window.location.search.match(/simple_fields_dummy=/) ) { 
     623        if ( window.pagenow && window.pagenow == "media-upload-popup" && window.location.search.match(/simple_fields_dummy=/) ) { 
    624624 
    625625            var frm_filter = $("form#filter"); 
  • simple-fields/tags/1.0.6/simple_fields.php

    r617428 r618615  
    44Plugin URI: http://simple-fields.com 
    55Description: Add groups of textareas, input-fields, dropdowns, radiobuttons, checkboxes and files to your edit post screen. 
    6 Version: 1.0.5 
     6Version: 1.0.6 
    77Author: Pär Thernström 
    88Author URI: http://eskapism.se/ 
     
    3939     
    4040        // array with registered field type objects 
    41         $registered_field_types 
    42      
     41        $registered_field_types, 
     42         
     43        // key to use in cache 
     44        $ns_key 
     45         
    4346    ; 
    4447 
     
    5255        define( "SIMPLE_FIELDS_URL", plugins_url(basename(dirname(__FILE__))). "/"); 
    5356        define( "SIMPLE_FIELDS_NAME", "Simple Fields"); 
    54         define( "SIMPLE_FIELDS_VERSION", "1.0.5"); 
     57        define( "SIMPLE_FIELDS_VERSION", "1.0.6"); 
    5558 
    5659        load_plugin_textdomain( 'simple-fields', null, basename(dirname(__FILE__)).'/languages/'); 
     60         
     61        // setup cache 
     62        // based on stuff found here: 
     63        // http://core.trac.wordpress.org/ticket/4476 
     64        $ns_key = wp_cache_get( 'simple_fields_namespace_key', 'simple_fields' ); 
     65        if ( $ns_key === false ) wp_cache_set( 'simple_fields_namespace_key', 1, 'simple_fields' ); 
     66        $this->ns_key = wp_cache_get( 'simple_fields_namespace_key', 'simple_fields' ); 
    5767         
    5868        require( dirname(__FILE__) . "/functions.php" ); 
     
    6474        // Load field types 
    6575        require( dirname(__FILE__) . "/field_types/field_divider.php" ); 
     76        //require( dirname(__FILE__) . "/field_types/field_date_v2.php" ); 
    6677 
    6778        $this->plugin_foldername_and_filename = basename(dirname(__FILE__)) . "/" . basename(__FILE__); 
     
    7081        // Actions and filters 
    7182        add_action( 'admin_init', array($this, 'admin_init') ); 
     83        add_action( 'admin_init', array($this, 'check_upgrade_stuff') ); 
    7284        add_action( 'admin_menu', array($this, "admin_menu") ); 
    7385        add_action( 'admin_head', array($this, 'admin_head') ); 
     
    95107         
    96108    } 
     109 
     110    // check some things regarding update 
     111    function check_upgrade_stuff() { 
     112 
     113        global $wpdb; 
     114 
     115        $db_version = get_option("simple_fields_db_version"); 
     116 
     117        if ($db_version === FALSE) { 
     118 
     119            // 1 = the first version, nothing done during update 
     120            $db_version = 1; 
     121            update_option("simple_history_db_version", 1); 
     122         
     123        } 
     124 
     125        // Do things depending on current version 
     126        // ...to come... 
     127         
     128    } 
    97129     
    98130         
     
    158190    function admin_init() { 
    159191 
     192        // @todo: only enqueue scripts when we need them = on a page that uses simple fields 
    160193        wp_enqueue_script("jquery"); 
    161194        wp_enqueue_script("jquery-ui-core"); 
     
    10771110 
    10781111        // use wp_cache 
    1079         $connectors = wp_cache_get( 'simple_fields_post_connectors' ); 
     1112        $connectors = wp_cache_get( 'simple_fields_'.$this->ns_key.'_post_connectors', 'simple_fields' ); 
    10801113        if (FALSE === $connectors) { 
    10811114 
     
    11361169            } 
    11371170             
    1138             wp_cache_set( 'simple_fields_post_connectors', $connectors ); 
     1171            wp_cache_set( 'simple_fields_'.$this->ns_key.'_post_connectors', $connectors, 'simple_fields' ); 
    11391172             
    11401173        } 
     
    11451178    function get_post_type_defaults() { 
    11461179 
    1147         $post_type_defaults = wp_cache_get( 'simple_fields_post_type_defaults' ); 
     1180        $post_type_defaults = wp_cache_get( 'simple_fields_'.$this->ns_key.'_post_type_defaults', 'simple_fields' ); 
    11481181        if (FALSE === $post_type_defaults) { 
    11491182            $post_type_defaults = (array) get_option("simple_fields_post_type_defaults"); 
    1150             wp_cache_set( 'simple_fields_post_type_defaults', $post_type_defaults );         
     1183            wp_cache_set( 'simple_fields_'.$this->ns_key.'_post_type_defaults', $post_type_defaults, 'simple_fields' ); 
    11511184        } 
    11521185 
     
    11621195    function get_field_groups() { 
    11631196         
    1164         $field_groups = wp_cache_get( 'simple_fields_groups' ); 
     1197        $field_groups = wp_cache_get( 'simple_fields_'.$this->ns_key.'_groups', 'simple_fields' ); 
    11651198        if (FALSE === $field_groups) { 
    11661199             
     
    12391272            } 
    12401273 
    1241             wp_cache_set( 'simple_fields_groups', $field_groups ); 
     1274            wp_cache_set( 'simple_fields_'.$this->ns_key.'_groups', $field_groups, 'simple_fields' ); 
    12421275             
    12431276        } 
     
    19211954                    $out .= "<div class='simple-fields-field-group-one-field-row-col-first'></div>"; 
    19221955                    $out .= "<div class='simple-fields-field-group-one-field-row-col-second'>"; 
    1923                     $out .= "   <p><input type='checkbox' name='field[{$fieldID}][type_date_options][use_time]' " . (($field_type_date_option_use_time) ? " checked='checked'" : "") . " value='1' /> ".__('Also show time', 'simple-fields') . "</p>"; 
     1956                    $out .= "   <!-- <p><input type='checkbox' name='field[{$fieldID}][type_date_options][use_time]' " . (($field_type_date_option_use_time) ? " checked='checked'" : "") . " value='1' /> ".__('Also show time', 'simple-fields') . "</p> -->"; 
    19241957                    $out .= "</div>"; 
    19251958                $out .= "</div>"; 
     
    31923225    /** 
    31933226     * Retrieve and return extended return values for a field type 
     3227     * @param mixed $field array or string or int or whatever with field info 
     3228     * @param mixed $field_value 
    31943229     */ 
    31953230    function get_extended_return_values_for_field($field, $field_value) { 
     
    33693404                    $return_field_value["timestamp"] = $date; 
    33703405                    $return_field_value["date_format"] = date(get_option('date_format'), $date); 
     3406                    $return_field_value["date_format_i18n"] = date_i18n( get_option('date_format'), $date); 
     3407                    // $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); 
     3408                    //echo get_option("gmt_offset"); // 14 if UTC+14 
    33713409                } 
    33723410            } 
     
    33853423    function get_field_group_by_slug($field_group_slug) { 
    33863424         
    3387         $cache_key = "get_field_group_by_slug_" . $field_group_slug; 
    3388         $return_val = wp_cache_get( $cache_key );        
     3425        $cache_key = 'simple_fields_'.$this->ns_key.'_get_field_group_by_slug_' . $field_group_slug; 
     3426        $return_val = wp_cache_get( $cache_key, 'simple_fields' ); 
    33893427        if (FALSE === $return_val) { 
    33903428         
     
    33973435                    if ($one_field_group["deleted"]) continue; 
    33983436                    if ($one_field_group["slug"] == $field_group_slug) { 
    3399                         wp_cache_set( $cache_key, $one_field_group ); 
     3437                        wp_cache_set( $cache_key, $one_field_group, 'simple_fields' ); 
    34003438                        return $one_field_group; 
    34013439                    } 
    34023440                } 
    34033441                 
    3404                 wp_cache_set( $cache_key, FALSE ); 
     3442                wp_cache_set( $cache_key, FALSE, 'simple_fields' ); 
    34053443                return FALSE; 
    34063444     
     
    34093447                // look for group using id 
    34103448                if (isset($field_groups[$field_group_slug]) && is_array($field_groups[$field_group_slug]) && !$field_groups[$field_group_slug]["deleted"]) { 
    3411                     wp_cache_set( $cache_key, $field_groups[$field_group_slug] ); 
     3449                    wp_cache_set( $cache_key, $field_groups[$field_group_slug], 'simple_fields' ); 
    34123450                    return $field_groups[$field_group_slug]; 
    34133451                } else { 
    3414                     wp_cache_set( $cache_key, FALSE ); 
     3452                    wp_cache_set( $cache_key, FALSE, 'simple_fields' ); 
    34153453                    return FALSE; 
    34163454                } 
     
    34483486    } 
    34493487 
     3488    function clear_caches() { 
     3489        $this->ns_key = wp_cache_incr( 'simple_fields_namespace_key', 1, 'simple_fields' ); 
     3490    } 
    34503491     
    34513492} // end class 
  • simple-fields/tags/1.0.6/tests/SimpleFieldsTests/SimpleFieldsTest.php

    r614081 r618615  
    324324 
    325325        $vals = simple_fields_value("field_date", $post_id, "extended_return=1"); 
    326         $vals_expected = array ( 'saved_value' => '12/10/2012', 'timestamp' => 1350000000, 'date_format' => 'October 12, 2012'); 
     326        $vals_expected = array (  
     327            'saved_value' => '12/10/2012',  
     328            'timestamp' => 1350000000,  
     329            'date_format' => 'October 12, 2012', 
     330            'date_format_i18n' => 'October 12, 2012' 
     331        ); 
    327332        $this->assertEquals($vals_expected, $vals); 
    328333         
  • simple-fields/trunk/functions.php

    r617428 r618615  
    3939function simple_fields_get_post_value($post_id, $field_name_or_id, $single = true) { 
    4040 
     41    global $sf; 
     42 
    4143    $fetch_by_id = true; 
    4244    if (is_array($field_name_or_id) && sizeof($field_name_or_id) == 2) { 
     
    7577                } 
    7678 
     79                // xxx make sure extended return value works here too 
     80                // check for settings saved for the field (in gui or through register_field_group) 
     81                $parsed_options_for_this_field = array(); 
     82                $field_options_key = "type_".$one_field["type"]."_options"; 
     83                if (isset($one_field[$field_options_key])) { 
     84                    // settings exist for this field 
     85                    if (isset($one_field[$field_options_key]["enable_extended_return_values"]) && $one_field[$field_options_key]["enable_extended_return_values"]) { 
     86                        $parsed_options_for_this_field["extended_return"] = 1; 
     87                    } 
     88 
     89                    if (isset($parsed_options_for_this_field["extended_return"]) && $parsed_options_for_this_field["extended_return"]) { 
     90                        // Yep, use extended return values 
     91                        $num_values = count($saved_values); 
     92                        while ($num_values--) { 
     93                            $saved_values[$num_values] = $sf->get_extended_return_values_for_field($one_field, $saved_values[$num_values]); 
     94                        } 
     95                    } 
     96 
     97                } 
     98                 
    7799                if ($is_found && $single) { 
    78100                    $return_val = $saved_values[0]; 
     
    81103                } 
    82104 
     105                // hm.. can't get here right??! 
    83106                if ($is_found) { 
    84107                    return $return_val; 
     
    184207 */ 
    185208function simple_fields_get_all_fields_and_values_for_post($post_id, $args = "") { 
    186  
    187     $cache_key = 'simple_fields_get_all_fields_and_values_for_post_' . $post_id . json_encode($args); 
    188     $selected_post_connector = wp_cache_get( $cache_key ); 
     209     
     210    global $sf; 
     211    $cache_key = 'simple_fields_'.$sf->ns_key.'_get_all_fields_and_values_for_post_' . $post_id . json_encode($args); 
     212    $selected_post_connector = wp_cache_get( $cache_key , 'simple_fields' ); 
    189213 
    190214    if (FALSE === $selected_post_connector) { 
     
    195219        $args = wp_parse_args($args, $defaults); 
    196220     
    197         global $sf; 
    198221        $post                     = get_post($post_id); 
    199222        $connector_to_use         = $sf->get_selected_connector_for_post($post); 
     
    275298                    $selected_post_connector["field_groups"][$one_field_group["id"]]["fields"][$one_field_id]["saved_values"][$num_in_set] = $saved_value; 
    276299                    $selected_post_connector["field_groups"][$one_field_group["id"]]["fields"][$one_field_id]["meta_keys"][$num_in_set] = $custom_field_key; 
    277  
    278                 } 
    279             } 
    280      
    281         } 
    282         wp_cache_set( $cache_key, $selected_post_connector ); 
     300     
     301                } 
     302            } 
     303     
     304        } 
     305        wp_cache_set( $cache_key, $selected_post_connector, 'simple_fields' ); 
    283306    } 
    284307 
     
    436459    #sf_d($field_groups); 
    437460    $highest_id = 0; 
    438      
     461 
    439462    // First get the id of the field group we are adding. Existing or highest new. 
    440463    // Loop through all existing field groups to see if the field group we are adding already exists 
     
    642665    } // if passed as arg field group has fields 
    643666 
    644     #sf_d($field_groups[$field_group_id]); 
    645     #sf_d($fields); 
    646  
    647     wp_cache_delete( "simple_fields_groups" ); 
     667    $sf->clear_caches(); 
    648668    update_option("simple_fields_groups", $field_groups); 
    649669 
     
    756776 
    757777    } 
    758  
    759     wp_cache_delete("simple_fields_post_connectors"); 
     778     
     779    $sf->clear_caches(); 
    760780    update_option("simple_fields_post_connectors", $post_connectors); 
    761781 
     
    811831        unset($post_type_defaults[0]); 
    812832    } 
    813  
    814     wp_cache_delete("simple_fields_post_type_defaults"); 
     833     
     834    $sf->clear_caches(); 
    815835    update_option("simple_fields_post_type_defaults", $post_type_defaults); 
    816836 
     
    897917                update_post_meta($post_id, "_simple_fields_fieldGroupID_{$field_group_id}_fieldID_added_numInSet_{$num_in_set}", 1); 
    898918                update_post_meta($post_id, "_simple_fields_been_saved", 1); 
    899  
    900                 // value updated. exit function. 
    901                 return; 
     919                 
     920                // value updated. clear cache and exit function. 
     921                $sf->clear_caches(); 
     922                return TRUE; 
    902923 
    903924            } // if 
     
    11921213    } 
    11931214 
    1194     $cache_key = "simple_fields_fieldgroup_" . $field_group_id_or_slug . "_" . $post_id . json_encode($options); 
    1195     $values = wp_cache_get( $cache_key ); 
     1215    global $sf; 
     1216    $cache_key = "simple_fields_".$sf->ns_key."_fieldgroup_" . $field_group_id_or_slug . "_" . $post_id . json_encode($options); 
     1217    $values = wp_cache_get( $cache_key, 'simple_fields'); 
    11961218    if (FALSE === $values) { 
    11971219     
    1198         global $sf; 
    11991220        $field_group = $sf->get_field_group_by_slug($field_group_id_or_slug); 
    12001221     
     
    12111232            $values = simple_fields_value($str_field_slugs, $post_id); 
    12121233        } 
    1213         wp_cache_set( $cache_key, $values ); 
     1234        wp_cache_set( $cache_key, $values, 'simple_fields' ); 
    12141235    } 
    12151236    return $values; 
    12161237} 
    1217  
    12181238 
    12191239/* 
  • simple-fields/trunk/readme.txt

    r617428 r618615  
    55Requires at least: 3.3.1 
    66Tested up to: 3.4.2 
    7 Stable tag: 1.0.5 
     7Stable tag: 1.0.6 
    88 
    99Add more advanced custom fields types to your edit post page. Field can be of several types, including textarea, checkbox, radio buttons, files and color picker. 
     
    164164 
    165165== Changelog == 
     166 
     167#### Version 1.0.6 
     168- Added: date_i8n-format for date field when using extended return values 
     169- Added: support for extended return values for function simple_fields_get_post_value() 
     170- Fxed: added group to cache functions + clears the cache when using the register-functions 
     171- Fixed: file dialog javascript now checks that the pagenow variable exists before trying to use it. Hopefully fixes problems with Post Thumbnail Editor 
     172 and other plugins that also use the file dialog. 
     173- Changed: hide "show time" for date field, since we don't use it for anything 
    166174 
    167175#### Version 1.0.5 
  • simple-fields/trunk/scripts.js

    r617428 r618615  
    621621        // Media browser: make sure search and filter works by adding hidden inputs 
    622622        // would have been best to do this in PHP, but I can't find any filter for it 
    623         if ( pagenow == "media-upload-popup" && window.location.search.match(/simple_fields_dummy=/) ) { 
     623        if ( window.pagenow && window.pagenow == "media-upload-popup" && window.location.search.match(/simple_fields_dummy=/) ) { 
    624624 
    625625            var frm_filter = $("form#filter"); 
  • simple-fields/trunk/simple_fields.php

    r617428 r618615  
    44Plugin URI: http://simple-fields.com 
    55Description: Add groups of textareas, input-fields, dropdowns, radiobuttons, checkboxes and files to your edit post screen. 
    6 Version: 1.0.5 
     6Version: 1.0.6 
    77Author: Pär Thernström 
    88Author URI: http://eskapism.se/ 
     
    3939     
    4040        // array with registered field type objects 
    41         $registered_field_types 
    42      
     41        $registered_field_types, 
     42         
     43        // key to use in cache 
     44        $ns_key 
     45         
    4346    ; 
    4447 
     
    5255        define( "SIMPLE_FIELDS_URL", plugins_url(basename(dirname(__FILE__))). "/"); 
    5356        define( "SIMPLE_FIELDS_NAME", "Simple Fields"); 
    54         define( "SIMPLE_FIELDS_VERSION", "1.0.5"); 
     57        define( "SIMPLE_FIELDS_VERSION", "1.0.6"); 
    5558 
    5659        load_plugin_textdomain( 'simple-fields', null, basename(dirname(__FILE__)).'/languages/'); 
     60         
     61        // setup cache 
     62        // based on stuff found here: 
     63        // http://core.trac.wordpress.org/ticket/4476 
     64        $ns_key = wp_cache_get( 'simple_fields_namespace_key', 'simple_fields' ); 
     65        if ( $ns_key === false ) wp_cache_set( 'simple_fields_namespace_key', 1, 'simple_fields' ); 
     66        $this->ns_key = wp_cache_get( 'simple_fields_namespace_key', 'simple_fields' ); 
    5767         
    5868        require( dirname(__FILE__) . "/functions.php" ); 
     
    6474        // Load field types 
    6575        require( dirname(__FILE__) . "/field_types/field_divider.php" ); 
     76        //require( dirname(__FILE__) . "/field_types/field_date_v2.php" ); 
    6677 
    6778        $this->plugin_foldername_and_filename = basename(dirname(__FILE__)) . "/" . basename(__FILE__); 
     
    7081        // Actions and filters 
    7182        add_action( 'admin_init', array($this, 'admin_init') ); 
     83        add_action( 'admin_init', array($this, 'check_upgrade_stuff') ); 
    7284        add_action( 'admin_menu', array($this, "admin_menu") ); 
    7385        add_action( 'admin_head', array($this, 'admin_head') ); 
     
    95107         
    96108    } 
     109 
     110    // check some things regarding update 
     111    function check_upgrade_stuff() { 
     112 
     113        global $wpdb; 
     114 
     115        $db_version = get_option("simple_fields_db_version"); 
     116 
     117        if ($db_version === FALSE) { 
     118 
     119            // 1 = the first version, nothing done during update 
     120            $db_version = 1; 
     121            update_option("simple_history_db_version", 1); 
     122         
     123        } 
     124 
     125        // Do things depending on current version 
     126        // ...to come... 
     127         
     128    } 
    97129     
    98130         
     
    158190    function admin_init() { 
    159191 
     192        // @todo: only enqueue scripts when we need them = on a page that uses simple fields 
    160193        wp_enqueue_script("jquery"); 
    161194        wp_enqueue_script("jquery-ui-core"); 
     
    10771110 
    10781111        // use wp_cache 
    1079         $connectors = wp_cache_get( 'simple_fields_post_connectors' ); 
     1112        $connectors = wp_cache_get( 'simple_fields_'.$this->ns_key.'_post_connectors', 'simple_fields' ); 
    10801113        if (FALSE === $connectors) { 
    10811114 
     
    11361169            } 
    11371170             
    1138             wp_cache_set( 'simple_fields_post_connectors', $connectors ); 
     1171            wp_cache_set( 'simple_fields_'.$this->ns_key.'_post_connectors', $connectors, 'simple_fields' ); 
    11391172             
    11401173        } 
     
    11451178    function get_post_type_defaults() { 
    11461179 
    1147         $post_type_defaults = wp_cache_get( 'simple_fields_post_type_defaults' ); 
     1180        $post_type_defaults = wp_cache_get( 'simple_fields_'.$this->ns_key.'_post_type_defaults', 'simple_fields' ); 
    11481181        if (FALSE === $post_type_defaults) { 
    11491182            $post_type_defaults = (array) get_option("simple_fields_post_type_defaults"); 
    1150             wp_cache_set( 'simple_fields_post_type_defaults', $post_type_defaults );         
     1183            wp_cache_set( 'simple_fields_'.$this->ns_key.'_post_type_defaults', $post_type_defaults, 'simple_fields' ); 
    11511184        } 
    11521185 
     
    11621195    function get_field_groups() { 
    11631196         
    1164         $field_groups = wp_cache_get( 'simple_fields_groups' ); 
     1197        $field_groups = wp_cache_get( 'simple_fields_'.$this->ns_key.'_groups', 'simple_fields' ); 
    11651198        if (FALSE === $field_groups) { 
    11661199             
     
    12391272            } 
    12401273 
    1241             wp_cache_set( 'simple_fields_groups', $field_groups ); 
     1274            wp_cache_set( 'simple_fields_'.$this->ns_key.'_groups', $field_groups, 'simple_fields' ); 
    12421275             
    12431276        } 
     
    19211954                    $out .= "<div class='simple-fields-field-group-one-field-row-col-first'></div>"; 
    19221955                    $out .= "<div class='simple-fields-field-group-one-field-row-col-second'>"; 
    1923                     $out .= "   <p><input type='checkbox' name='field[{$fieldID}][type_date_options][use_time]' " . (($field_type_date_option_use_time) ? " checked='checked'" : "") . " value='1' /> ".__('Also show time', 'simple-fields') . "</p>"; 
     1956                    $out .= "   <!-- <p><input type='checkbox' name='field[{$fieldID}][type_date_options][use_time]' " . (($field_type_date_option_use_time) ? " checked='checked'" : "") . " value='1' /> ".__('Also show time', 'simple-fields') . "</p> -->"; 
    19241957                    $out .= "</div>"; 
    19251958                $out .= "</div>"; 
     
    31923225    /** 
    31933226     * Retrieve and return extended return values for a field type 
     3227     * @param mixed $field array or string or int or whatever with field info 
     3228     * @param mixed $field_value 
    31943229     */ 
    31953230    function get_extended_return_values_for_field($field, $field_value) { 
     
    33693404                    $return_field_value["timestamp"] = $date; 
    33703405                    $return_field_value["date_format"] = date(get_option('date_format'), $date); 
     3406                    $return_field_value["date_format_i18n"] = date_i18n( get_option('date_format'), $date); 
     3407                    // $timezone_format = _x('Y-m-d G:i:s', 'timezone date format'); 
     3408                    //echo get_option("gmt_offset"); // 14 if UTC+14 
    33713409                } 
    33723410            } 
     
    33853423    function get_field_group_by_slug($field_group_slug) { 
    33863424         
    3387         $cache_key = "get_field_group_by_slug_" . $field_group_slug; 
    3388         $return_val = wp_cache_get( $cache_key );        
     3425        $cache_key = 'simple_fields_'.$this->ns_key.'_get_field_group_by_slug_' . $field_group_slug; 
     3426        $return_val = wp_cache_get( $cache_key, 'simple_fields' ); 
    33893427        if (FALSE === $return_val) { 
    33903428         
     
    33973435                    if ($one_field_group["deleted"]) continue; 
    33983436                    if ($one_field_group["slug"] == $field_group_slug) { 
    3399                         wp_cache_set( $cache_key, $one_field_group ); 
     3437                        wp_cache_set( $cache_key, $one_field_group, 'simple_fields' ); 
    34003438                        return $one_field_group; 
    34013439                    } 
    34023440                } 
    34033441                 
    3404                 wp_cache_set( $cache_key, FALSE ); 
     3442                wp_cache_set( $cache_key, FALSE, 'simple_fields' ); 
    34053443                return FALSE; 
    34063444     
     
    34093447                // look for group using id 
    34103448                if (isset($field_groups[$field_group_slug]) && is_array($field_groups[$field_group_slug]) && !$field_groups[$field_group_slug]["deleted"]) { 
    3411                     wp_cache_set( $cache_key, $field_groups[$field_group_slug] ); 
     3449                    wp_cache_set( $cache_key, $field_groups[$field_group_slug], 'simple_fields' ); 
    34123450                    return $field_groups[$field_group_slug]; 
    34133451                } else { 
    3414                     wp_cache_set( $cache_key, FALSE ); 
     3452                    wp_cache_set( $cache_key, FALSE, 'simple_fields' ); 
    34153453                    return FALSE; 
    34163454                } 
     
    34483486    } 
    34493487 
     3488    function clear_caches() { 
     3489        $this->ns_key = wp_cache_incr( 'simple_fields_namespace_key', 1, 'simple_fields' ); 
     3490    } 
    34503491     
    34513492} // end class 
  • simple-fields/trunk/tests/SimpleFieldsTests/SimpleFieldsTest.php

    r614081 r618615  
    324324 
    325325        $vals = simple_fields_value("field_date", $post_id, "extended_return=1"); 
    326         $vals_expected = array ( 'saved_value' => '12/10/2012', 'timestamp' => 1350000000, 'date_format' => 'October 12, 2012'); 
     326        $vals_expected = array (  
     327            'saved_value' => '12/10/2012',  
     328            'timestamp' => 1350000000,  
     329            'date_format' => 'October 12, 2012', 
     330            'date_format_i18n' => 'October 12, 2012' 
     331        ); 
    327332        $this->assertEquals($vals_expected, $vals); 
    328333         
Note: See TracChangeset for help on using the changeset viewer.