Plugin Directory

Changeset 489080


Ignore:
Timestamp:
01/12/2012 11:17:24 PM (14 years ago)
Author:
logikal16
Message:

CFS 1.3.0

Location:
custom-field-suite/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • custom-field-suite/trunk/cfs.php

    r485124 r489080  
    44Plugin URI: http://uproot.us/custom-field-suite/
    55Description: Visually create custom field groups.
    6 Version: 1.2.6
     6Version: 1.3.0
    77Author: Matt Gibbs
    88Author URI: http://uproot.us/
     
    1212
    1313$cfs = new Cfs();
    14 $cfs->version = '1.2.6';
     14$cfs->version = '1.3.0';
    1515
    1616class Cfs
     
    4949        add_action('save_post', array($this, 'save_post'));
    5050        add_action('delete_post', array($this, 'delete_post'));
     51
     52        // 3rd party hooks
     53        add_action('gform_post_submission', array($this, 'gform_handler'), 10, 2);
    5154
    5255        // add translations
     
    390393        include($this->dir . '/core/admin/field_html.php');
    391394    }
     395
     396
     397    /*--------------------------------------------------------------------------------------
     398    *
     399    *    gform_handler (gravity forms)
     400    *
     401    *    @author Matt Gibbs
     402    *    @since 1.3.0
     403    *
     404    *-------------------------------------------------------------------------------------*/
     405
     406    function gform_handler($entry, $form)
     407    {
     408        global $wpdb;
     409
     410        // get the form id
     411        $form_id = $entry['form_id'];
     412        $form_data = array();
     413
     414        // get submitted fields
     415        foreach ($form['fields'] as $field)
     416        {
     417            $field_id = $field['id'];
     418
     419            // handle fields with children
     420            if (null !== $field['inputs'])
     421            {
     422                $values = array();
     423
     424                foreach ($field['inputs'] as $sub_field)
     425                {
     426                    $sub_field_value = $entry[$sub_field['id']];
     427
     428                    if (!empty($sub_field_value))
     429                    {
     430                        $values[] = $sub_field_value;
     431                    }
     432                }
     433                $value = implode("\n", $values);
     434            }
     435            else
     436            {
     437                $value = $entry[$field_id];
     438            }
     439
     440            $form_data[$field['label']] = $value;
     441        }
     442
     443        // see if any field groups use this form id
     444        $field_groups = array();
     445        $results = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'cfs_extras'");
     446        foreach ($results as $result)
     447        {
     448            $meta_value = unserialize($result->meta_value);
     449            $meta_value = $meta_value['gforms'];
     450
     451            if ($form_id == $meta_value['form_id'])
     452            {
     453                $fields = array();
     454                $all_fields = $wpdb->get_results("SELECT name, label FROM {$wpdb->prefix}cfs_fields WHERE post_id = '{$result->post_id}'");
     455                foreach ($all_fields as $field)
     456                {
     457                    $fields[$field->label] = $field->name;
     458                }
     459
     460                $field_groups[$result->post_id] = array(
     461                    'post_type' => $meta_value['post_type'],
     462                    'fields' => $fields,
     463                );
     464            }
     465        }
     466
     467        foreach ($field_groups as $post_id => $data)
     468        {
     469            $field_data = array();
     470            $intersect = array_intersect_key($form_data, $data['fields']);
     471            foreach ($intersect as $key => $field_value)
     472            {
     473                $field_name = $data['fields'][$key];
     474                $field_data[$field_name] = $field_value;
     475            }
     476
     477            $post_data = array(
     478                'post_type' => $meta_value['post_type'],
     479            );
     480            if (isset($entry['post_id']))
     481            {
     482                $post_data['ID'] = $entry['post_id'];
     483            }
     484
     485            // save data
     486            $this->save($field_data, $post_data);
     487        }
     488    }
    392489}
  • custom-field-suite/trunk/core/actions/admin_head.php

    r481990 r489080  
    3636    add_meta_box('cfs_fields', 'Fields', array($this, 'meta_box'), 'cfs', 'normal', 'high', array('box' => 'fields'));
    3737    add_meta_box('cfs_rules', 'Placement Rules', array($this, 'meta_box'), 'cfs', 'normal', 'high', array('box' => 'rules'));
     38    add_meta_box('cfs_extras', 'Extras', array($this, 'meta_box'), 'cfs', 'normal', 'high', array('box' => 'extras'));
    3839}
    3940
  • custom-field-suite/trunk/core/actions/save_fields.php

    r474942 r489080  
    8383
    8484update_post_meta($post_id, 'cfs_rules', $data);
     85
     86/*---------------------------------------------------------------------------------------------
     87    Save extras
     88---------------------------------------------------------------------------------------------*/
     89
     90$cfs_extras = $_POST['cfs']['extras'];
     91update_post_meta($post_id, 'cfs_extras', $cfs_extras);
  • custom-field-suite/trunk/core/api.php

    r475093 r489080  
    102102                {
    103103                    $sql = "
    104                     SELECT v.value, v.weight
     104                    SELECT m.meta_value AS value, v.weight
    105105                    FROM {$wpdb->prefix}cfs_values v
    106                     WHERE v.post_id = '$post_id' AND v.field_id = '$field->id'
     106                    INNER JOIN {$wpdb->postmeta} m ON m.meta_id = v.meta_id
     107                    WHERE m.post_id = '$post_id' AND v.field_id = '$field->id'
    107108                    ORDER BY v.weight, v.sub_weight";
    108109
     
    270271        $options = (object) array_merge($defaults, $options);
    271272
    272         // Create the post if $post_data['ID'] is missing
    273         $post_id = empty($post_data['ID']) ? wp_insert_post($post_data) : $post_data['ID'];
     273        // create post if the ID is missing
     274        if (empty($post_data['ID']))
     275        {
     276            $post_defaults = array(
     277                'post_title' => 'Untitled',
     278                'post_content' => '',
     279                'post_content_filtered' => '',
     280                'post_excerpt' => '',
     281                'to_ping' => '',
     282                'pinged' => '',
     283            );
     284            $post_data = array_merge($post_defaults, $post_data);
     285            $post_id = wp_insert_post($post_data);
     286        }
     287        else
     288        {
     289            $post_id = $post_data['ID'];
     290
     291            if (1 < count($post_data))
     292            {
     293                $wpdb->update($wpdb->posts, $post_data, array('ID' => $post_id));
     294            }
     295        }
    274296
    275297        // If NOT "raw_input", then flatten the data!
     
    336358
    337359            // If saving raw input, delete existing postdata
    338             $sql = "DELETE v, m
     360            $sql = "
     361            DELETE v, m
    339362            FROM {$wpdb->prefix}cfs_values v
    340363            LEFT JOIN {$wpdb->postmeta} m ON m.meta_id = v.meta_id
     
    347370
    348371        // Delete from cfs_values and postmeta
    349         $sql = "DELETE v, m
     372        $sql = "
     373        DELETE v, m
    350374        FROM {$wpdb->prefix}cfs_values v
    351375        LEFT JOIN {$wpdb->postmeta} m ON m.meta_id = v.meta_id
     
    387411                        'meta_id' => $meta_id,
    388412                        'post_id' => $post_id,
    389                         'value' => $v,
    390413                        'weight' => $weight,
    391414                        'sub_weight' => $sub_weight,
     
    419442                            'meta_id' => $meta_id,
    420443                            'post_id' => $post_id,
    421                             'value' => $v,
    422444                            'weight' => $weight,
    423445                            'sub_weight' => $sub_weight,
  • custom-field-suite/trunk/core/upgrade.php

    r474942 r489080  
    1010    if (version_compare($last_version, '1.0.0', '<'))
    1111    {
    12         $sql = "CREATE TABLE {$wpdb->prefix}cfs_fields (
    13             id INT unsigned not null auto_increment primary key,
     12        $sql = "
     13        CREATE TABLE {$wpdb->prefix}cfs_fields (
     14            id INT unsigned not null auto_increment,
    1415            name TEXT,
    1516            label TEXT,
     
    1920            parent_id INT unsigned default 0,
    2021            weight INT unsigned,
    21             options TEXT
     22            options TEXT,
     23            PRIMARY KEY (id),
     24            INDEX post_id_idx (post_id)
    2225        ) DEFAULT CHARSET=utf8";
    2326        dbDelta($sql);
    2427
    25         $sql = "CREATE TABLE {$wpdb->prefix}cfs_values (
    26             id INT unsigned not null auto_increment primary key,
     28        $sql = "
     29        CREATE TABLE {$wpdb->prefix}cfs_values (
     30            id INT unsigned not null auto_increment,
    2731            field_id INT unsigned,
    2832            meta_id INT unsigned,
    2933            post_id INT unsigned,
    30             value TEXT,
    3134            weight INT unsigned,
    32             sub_weight INT unsigned
     35            sub_weight INT unsigned,
     36            PRIMARY KEY (id),
     37            INDEX field_id_idx (field_id),
     38            INDEX post_id_idx (post_id)
    3339        ) DEFAULT CHARSET=utf8";
    3440        dbDelta($sql);
  • custom-field-suite/trunk/css/fields.css

    r474942 r489080  
    152152---------------------------------------------------------------------------------------------*/
    153153
    154 #cfs_rules .inside {
     154#cfs_rules .inside,
     155#cfs_extras .inside {
    155156    margin: 0;
    156157    padding: 0;
    157158}
    158159
    159 #cfs_rules table td {
     160#cfs_rules table td,
     161#cfs_extras table td {
    160162    padding: 10px;
    161163}
    162164
    163 #cfs_rules table td.label {
     165#cfs_rules table td.label,
     166#cfs_extras table td.label {
    164167    width: 24%;
    165168    vertical-align: top;
    166169}
    167170
    168 #cfs_rules table td.label label {
     171#cfs_rules table td.label label,
     172#cfs_extras table td.label label {
    169173    font-weight: bold;
    170174    color: #333;
    171175}
    172176
    173 #cfs_rules table td.label p.description {
     177#cfs_rules table td.label p.description,
     178#cfs_extras table td.label p.description {
    174179    color: #666;
    175180    font-style: normal;
     
    178183
    179184#cfs_rules table select,
     185#cfs_extras table select,
    180186#cfs_rules table textarea,
    181 #cfs_rules table input[type="text"] {
     187#cfs_extras table textarea,
     188#cfs_rules table input[type="text"],
     189#cfs_extras table input[type="text"] {
    182190    width: 99.95%;
    183191    height: auto;
     
    186194}
    187195
    188 #wpcontent #cfs_rules table select.multiple {
     196#wpcontent #cfs_rules table select.multiple,
     197#wpcontent #cfs_extras table select.multiple {
    189198    height: 100px;
    190199}
  • custom-field-suite/trunk/readme.txt

    r485124 r489080  
    22Contributors: logikal16
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JMVGK3L35X6BU
    4 Tags: fields, custom fields, pods, cck, more fields, extra fields
     4Tags: fields, custom fields, pods, cck, more fields, extra fields, gravity forms
    55Requires at least: 3.2
    6 Tested up to: 3.3
     6Tested up to: 3.3.1
    77Stable tag: trunk
    88
     
    1212
    1313Visually create custom fields that can be used on any edit page.
     14
     15Now with Gravity Forms integration!
    1416
    1517= Field Types =
     
    4143
    4244== Changelog ==
     45
     46= 1.3.0 =
     47* Gravity Forms integration!
     48* Better error handling for the API save() method
    4349
    4450= 1.2.6 =
Note: See TracChangeset for help on using the changeset viewer.