WordPress.org

Plugin Directory

Changeset 611160


Ignore:
Timestamp:
10/11/12 21:59:00 (19 months ago)
Author:
eskapism
Message:

version 1.0.2

Location:
simple-fields/trunk
Files:
7 added
3 edited

Legend:

Unmodified
Added
Removed
  • simple-fields/trunk/functions.php

    r610518 r611160  
    410410 * @param string $slug the slug of this field group. must be unique. 
    411411 * @param array $new_field_group settings/options for the new group 
    412  * @param return array the new field group as an array 
     412 * @return array the new field group as an array 
    413413 */ 
    414414function simple_fields_register_field_group($slug = "", $new_field_group = array()) { 
     
    457457        $new_field_group["name"] = $slug; 
    458458    } 
     459     
     460    // make sure slug is valid 
     461    $slug = sanitize_key($slug); 
    459462 
    460463    if (!isset($field_groups[$field_group_id])) { 
     
    522525            // Find id of possibly existing field using the slug 
    523526            // If existing field is found then merge old values with new 
    524             foreach ($field_groups[$field_group_id]["fields"] as $one_existing_field) { 
    525  
    526                 if ($one_existing_field["slug"] == $one_new_field["slug"]) { 
    527                     // Found existing field with same slug 
    528                     // Merge new field values with the old values, so $field_defaults will have the combines values 
    529                     $field_defaults = simple_fields_merge_arrays($field_defaults, $one_existing_field); 
    530                 } 
    531  
     527            if (isset($field_groups[$field_group_id]["fields"]) && is_array($field_groups[$field_group_id]["fields"])) { 
     528                foreach ($field_groups[$field_group_id]["fields"] as $one_existing_field) { 
     529     
     530                    if ($one_existing_field["slug"] == $one_new_field["slug"]) { 
     531                        // Found existing field with same slug 
     532                        // Merge new field values with the old values, so $field_defaults will have the combines values 
     533                        $field_defaults = simple_fields_merge_arrays($field_defaults, $one_existing_field); 
     534                    } 
     535     
     536                } 
    532537            } 
    533538 
     
    660665        $new_post_connector["name"] = $unique_name; 
    661666    } 
     667 
     668    $slug = sanitize_key($slug); 
    662669 
    663670    $post_connector_defaults = array( 
     
    775782    } 
    776783 
    777     $post_type_defaults = (array) get_option("simple_fields_post_type_defaults"); 
     784    $post_type_defaults = $sf->get_post_type_defaults(); 
    778785 
    779786    $post_type_defaults[$post_type] = $connector_id_or_special_type; 
     
    10431050 
    10441051/** 
    1045  * Return the name of the post connector for the current post in the loop 
    1046  * 
    1047  * @return mixed False if no connector or connector not found. String name of connector if found. 
    1048  */ 
    1049 function simple_fields_connector() { 
     1052 * Return the slug of the post connector for the current post in the loop or for the post specified in $post_id 
     1053 * @param $post_id optional post or post id 
     1054 * @return mixed False if no connector or connector not found. String slug of connector if found. 
     1055 */ 
     1056function simple_fields_connector($post_id = NULL) { 
     1057 
    10501058    global $post, $sf; 
    1051     $connector_id = $sf->get_selected_connector_for_post($post); 
     1059     
     1060    if (is_numeric($post_id)) { 
     1061        $post_this = get_post($post_id); 
     1062    } else { 
     1063        $post_this = $post; 
     1064    } 
     1065 
     1066    $connector_id = $sf->get_selected_connector_for_post($post_this); 
    10521067 
    10531068    if ($connector_id == "__none__") { 
     
    10751090    return ($connector_slug === $slug); 
    10761091} 
     1092 
     1093/* 
     1094@todo: add simple_fields_fieldgroup_values() as smart alias to  
     1095simple_fields_get_post_group_values($post_id, $field_group_name_or_id, $use_name = true, $return_format = 1) { 
     1096use slug and fewer args 
     1097*/ 
  • simple-fields/trunk/readme.txt

    r610518 r611160  
    55Requires at least: 3.3.1 
    66Tested up to: 3.4.2 
    7 Stable tag: 1.0.1 
     7Stable tag: 1.0.2 
    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.2 
     168- Changed: Don't load example field types 
     169- Fixed: jQuery is needed for debug output but was not enqueued 
     170- Added: French translation. Thank you very much, translator! 
     171- Small bugfixes 
     172- Added unit tests. Hopefully this makes it easier for me to spot bugs in the future. Btw: these are the first unit tests I've ever written, so please feel free to comment on the way I've done it! :) 
    166173 
    167174#### Version 1.0.1 
  • simple-fields/trunk/simple_fields.php

    r610518 r611160  
    5252        define( "SIMPLE_FIELDS_URL", plugins_url(basename(dirname(__FILE__))). "/"); 
    5353        define( "SIMPLE_FIELDS_NAME", "Simple Fields"); 
    54         define( "SIMPLE_FIELDS_VERSION", "1.0.1"); 
     54        define( "SIMPLE_FIELDS_VERSION", "1.0.2"); 
    5555 
    5656        load_plugin_textdomain( 'simple-fields', null, basename(dirname(__FILE__)).'/languages/'); 
     
    5858        require( dirname(__FILE__) . "/functions.php" ); 
    5959        require( dirname(__FILE__) . "/class_simple_fields_field.php" ); 
    60         require( dirname(__FILE__) . "/field_types/field_example.php" ); 
    61         require( dirname(__FILE__) . "/field_types/field_minimalistic_example.php" ); 
     60         
     61        // require( dirname(__FILE__) . "/field_types/field_example.php" ); 
     62        // require( dirname(__FILE__) . "/field_types/field_minimalistic_example.php" ); 
    6263 
    6364        $this->plugin_foldername_and_filename = basename(dirname(__FILE__)) . "/" . basename(__FILE__); 
     
    244245     */ 
    245246    function get_default_connector_for_post_type($post_type) { 
    246         $post_type_defaults = (array) get_option("simple_fields_post_type_defaults"); 
     247        $post_type_defaults = $this->get_post_type_defaults(); 
    247248        $selected_post_type_default = (isset($post_type_defaults[$post_type]) ? $post_type_defaults[$post_type] : "__none__"); 
    248249        return $selected_post_type_default; 
    249250    } 
    250  
    251251 
    252252    /** 
     
    994994        return $connectors; 
    995995    } 
     996 
     997    function get_post_type_defaults() { 
     998        return (array) get_option("simple_fields_post_type_defaults"); 
     999    } 
    9961000     
    9971001    /** 
     
    11871191    } // function  
    11881192 
     1193 
    11891194    /** 
    11901195     * get selected post connector for a post 
    1191      * @param object $post 
     1196     * a post has a post connector, or no connector 
     1197     * this function will return the inherited connector if post is set to inherit connector 
     1198     * unless it's the top most post since then nere are no more to inherit 
     1199     * should not return be __none__ then? 
     1200     * 
     1201     * @param object $post or int post id 
    11921202     * @return id or string __none__ 
    11931203     */ 
     
    12011211         
    12021212        global $sf; 
     1213         
     1214        // make sure $post is a post object 
     1215        if (is_numeric($post)) $post = get_post($post); 
    12031216         
    12041217        $post_type = $post->post_type; 
     
    24042417                echo "<h3>simple_fields_post_type_defaults</h3>"; 
    24052418                echo '<p>Called with: get_option("simple_fields_post_type_defaults")'; 
    2406                 sf_d( get_option("simple_fields_post_type_defaults") ); 
     2419                sf_d( $this->get_post_type_defaults() ); 
    24072420                 
    24082421            } 
     
    27022715    } 
    27032716     
    2704     // Some debug functions 
     2717    /** 
     2718     * If debug option is enabled then output debug-box by hooking onto the_content 
     2719     */ 
    27052720    function maybe_add_debug_info() { 
    27062721        global $sf; 
     
    27102725            // 1 = debug for admins only, 2 = debug for all 
    27112726            if ( ($options["debug_type"] === 1 && current_user_can("edit_themes")) ||  $options["debug_type"] === 2) { 
    2712                 add_filter("the_content", array($this, "simple_fields_value_get_functions_test")); 
     2727                 
     2728                // enqueu jquery because that is used to show/hide the debug box 
     2729                wp_enqueue_script("jquery"); 
     2730                 
     2731                // add filter 
     2732                add_filter("the_content", array($this, "simple_fields_content_debug_output")); 
    27132733            }    
    27142734     
     
    27172737     
    27182738    // Outputs the names of the post connectors attached to the post you view + outputs the values 
    2719     function simple_fields_value_get_functions_test($the_content) { 
     2739    function simple_fields_content_debug_output($the_content) { 
    27202740         
    27212741        $output = ""; 
Note: See TracChangeset for help on using the changeset viewer.