Plugin Directory

Changeset 738526


Ignore:
Timestamp:
07/10/2013 02:44:14 AM (13 years ago)
Author:
matthewordie
Message:

Updated for ACF 4.0

Location:
buckets/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • buckets/trunk/buckets.php

    r677270 r738526  
    55Description: A Widget Alternative. Add reusable content inside of content. On a per page basis.
    66Author: Matthew Restorff
    7 Version: 0.1.9.3
     7Version: 0.2
    88Author URI: http://www.matthewrestorff.com
    99*/ 
     
    1717*
    1818*-------------------------------------------------------------------------------------*/
    19 $bucket_version = '0.1.9.3';
     19$bucket_version = '0.2';
    2020add_action('init', 'buckets_init');
    2121add_action( 'admin_head', 'buckets_admin_head' );
    2222add_shortcode( 'bucket', 'buckets_shortcode' );
     23include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     24// Make Sure ACF is loaded
     25if (is_plugin_active('advanced-custom-fields/acf.php')) {
     26    add_action('acf/register_fields', 'register_bucket_fields');
     27}
     28
    2329
    2430
     
    6672    create_tinymce_button();
    6773
    68 
    69    
    70     // Make Sure ACF is loaded
    71     include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    72     if (is_plugin_active('advanced-custom-fields/acf.php'))
    73     {
    74         remove_post_type_support( 'buckets', 'editor' );
    75         load_first();
    76         register_field('Buckets_field', WP_PLUGIN_DIR . '/buckets/fields/buckets.php');
    77         create_bucket_field_groups();
    78     }
    79 
     74    //Load Before ACF
     75    load_first();
     76
     77}
     78
     79
     80
     81
     82/*--------------------------------------------------------------------------------------
     83*
     84*   register_bucket_fields
     85*   Registers the Buckets fields and adds the default field groups.
     86*
     87*   @author Matthew Restorff
     88*
     89*-------------------------------------------------------------------------------------*/
     90
     91function register_bucket_fields()
     92{
     93    remove_post_type_support( 'buckets', 'editor' );
     94    include_once(WP_PLUGIN_DIR . '/buckets/fields/buckets.php');
     95    create_bucket_field_groups();
    8096}
    8197
     
    162178
    163179        add_post_meta($post_id, '_edit_last', '1');
    164         add_post_meta($post_id, 'field_bucketskey778', 'a:8:{s:5:"label";s:7:"Sidebar";s:4:"name";s:7:"sidebar";s:4:"type";s:13:"buckets_field";s:12:"instructions";s:0:"";s:8:"required";s:1:"0";s:3:"max";s:0:"";s:3:"key";s:19:"field_bucketskey778";s:8:"order_no";s:1:"0";}');
     180        add_post_meta($post_id, 'field_bucketskey778', 'a:9:{s:3:"key";s:19:"field_bucketskey778";s:5:"label";s:7:"Sidebar";s:4:"name";s:7:"sidebar";s:4:"type";s:7:"buckets";s:12:"instructions";s:0:"";s:8:"required";s:1:"0";s:3:"max";s:0:"";s:17:"conditional_logic";a:3:{s:6:"status";s:1:"0";s:5:"rules";a:1:{i:0;a:2:{s:5:"field";s:4:"null";s:8:"operator";s:2:"==";}}s:8:"allorany";s:3:"all";}s:8:"order_no";i:0;}');
    165181        add_post_meta($post_id, 'allorany', 'all');
    166182        add_post_meta($post_id, 'rule', 'a:4:{s:5:"param";s:9:"post_type";s:8:"operator";s:2:"==";s:5:"value";s:4:"page";s:8:"order_no";s:1:"0";}');
  • buckets/trunk/fields/buckets.php

    r675373 r738526  
    11<?php
    22
    3 class Buckets_field extends acf_Field
     3class acf_field_buckets extends acf_field
    44{
    5    
    6     /*--------------------------------------------------------------------------------------
    7     *
    8     *   Constructor
    9     *
    10     *   @author Elliot Condon
    11     *   @since 1.0.0
    12     *   @updated 2.2.0
    13     *
    14     *-------------------------------------------------------------------------------------*/
    15    
    16     function __construct($parent)
     5    // vars
     6    var $defaults;
     7   
     8   
     9    /*
     10    *  __construct
     11    *
     12    *  Set name / label needed for actions / filters
     13    *
     14    *  @since   3.6
     15    *  @date    23/01/13
     16    */
     17   
     18    function __construct()
    1719    {
    18         parent::__construct($parent);
     20        // vars
     21        $this->name = 'buckets';
     22        $this->label = __("Buckets Sidebar",'acf');
     23        $this->category = __("Relational",'acf');
     24        $this->defaults = array(
     25            'post_type' =>  array('buckets'),
     26            'max'       =>  '',
     27            'taxonomy'  =>  array('all'),
     28            'filters'   =>  array('search'),
     29            'result_elements' => array('post_title', 'post_type')
     30        );
     31       
     32       
     33        // do not delete!
     34        parent::__construct();
    1935       
    20         $this->name = 'buckets_field';
    21         $this->title = __("Buckets Sidebar",'acf');
    22        
    23         add_action('wp_ajax_acf_get_bucket_results', array($this, 'acf_get_bucket_results'));
    24     }
     36       
     37        // extra
     38        add_action('wp_ajax_acf/fields/relationship/query_posts', array($this, 'query_posts'));
     39        add_action('wp_ajax_nopriv_acf/fields/relationship/query_posts', array($this, 'query_posts'));
     40    }
     41   
     42   
     43    /*
     44    *  load_field()
     45    * 
     46    *  This filter is appied to the $field after it is loaded from the database
     47    * 
     48    *  @type filter
     49    *  @since 3.6
     50    *  @date 23/01/13
     51    * 
     52    *  @param $field - the field array holding all the field options
     53    * 
     54    *  @return $field - the field array holding all the field options
     55    */
     56   
     57    function load_field( $field )
     58    {
     59        // defaults
     60        $field = array_merge($this->defaults, $field);
     61       
     62       
     63        // validate post_type
     64        if( !$field['post_type'] || !is_array($field['post_type']) || in_array('', $field['post_type']) )
     65        {
     66            $field['post_type'] = array( 'all' );
     67        }
     68
     69       
     70        // validate taxonomy
     71        if( !$field['taxonomy'] || !is_array($field['taxonomy']) || in_array('', $field['taxonomy']) )
     72        {
     73            $field['taxonomy'] = array( 'all' );
     74        }
     75       
     76       
     77        // validate result_elements
     78        if( !is_array( $field['result_elements'] ) )
     79        {
     80            $field['result_elements'] = array();
     81        }
     82       
     83        if( !in_array('post_title', $field['result_elements']) )
     84        {
     85            $field['result_elements'][] = 'post_title';
     86        }
     87       
     88       
     89        // filters
     90        if( !is_array( $field['filters'] ) )
     91        {
     92            $field['filters'] = array();
     93        }
     94       
     95       
     96        // return
     97        return $field;
     98    }
     99       
     100
     101    /*
     102    *  posts_where
     103    *
     104    *  @description:
     105    *  @created: 3/09/12
     106    */
    25107   
    26    
    27     /*--------------------------------------------------------------------------------------
    28     *
    29     *   acf_get_relationship_results
    30     *
    31     *   @author Elliot Condon
    32     *   @description: Generates HTML for Left column relationship results
    33     *   @created: 5/07/12
    34     *
    35     *-------------------------------------------------------------------------------------*/
    36    
    37     function acf_get_bucket_results()
     108    function posts_where( $where, &$wp_query )
     109    {
     110        global $wpdb;
     111       
     112        if ( $title = $wp_query->get('like_title') )
     113        {
     114            $where .= " AND " . $wpdb->posts . ".post_title LIKE '%" . esc_sql( like_escape(  $title ) ) . "%'";
     115        }
     116       
     117        return $where;
     118    }
     119   
     120   
     121    /*
     122    *  query_posts
     123    *
     124    *  @description:
     125    *  @since: 3.6
     126    *  @created: 27/01/13
     127    */
     128   
     129    function query_posts()
    38130    {
    39131        // vars
    40132        $options = array(
    41             'post_type' =>  'buckets',
     133            'post_type' => 'all',
     134            'taxonomy' => 'all',
    42135            'posts_per_page' => 10,
    43136            'paged' => 0,
     
    47140            'suppress_filters' => false,
    48141            's' => '',
     142            'lang' => false,
     143            'update_post_meta_cache' => false,
     144            'field_key' => '',
     145            'nonce' => '',
     146            'ancestor' => false,
    49147        );
    50         $ajax = isset( $_POST['action'] ) ? true : false;
    51 
    52        
    53         // override options with posted values
    54         if( $ajax )
    55         {
    56             $options = array_merge($options, $_POST);
    57         }
     148       
     149        $options = array_merge( $options, $_POST );
     150       
     151       
     152        // validate
     153        if( !wp_verify_nonce($options['nonce'], 'acf_nonce') )
     154        {
     155            die(0);
     156        }
     157       
     158       
     159        // WPML
     160        if( $options['lang'] )
     161        {
     162            global $sitepress;
     163           
     164            $sitepress->switch_lang( $options['lang'] );
     165        }
     166       
     167       
     168        // convert types
     169        $options['post_type'] = explode(',', $options['post_type']);
     170        $options['taxonomy'] = explode(',', $options['taxonomy']);
     171       
     172       
     173        // load all post types by default
     174        if( in_array('all', $options['post_type']) )
     175        {
     176            $options['post_type'] = apply_filters('acf/get_post_types', array());
     177        }
     178       
     179       
     180        // attachment doesn't work if it is the only item in an array???
     181        if( is_array($options['post_type']) && count($options['post_type']) == 1 )
     182        {
     183            $options['post_type'] = $options['post_type'][0];
     184        }
     185       
     186       
     187        // create tax queries
     188        if( ! in_array('all', $options['taxonomy']) )
     189        {
     190            // vars
     191            $taxonomies = array();
     192            $options['tax_query'] = array();
     193           
     194            foreach( $options['taxonomy'] as $v )
     195            {
     196               
     197                // find term (find taxonomy!)
     198                // $term = array( 0 => $taxonomy, 1 => $term_id )
     199                $term = explode(':', $v);
     200               
     201               
     202                // validate
     203                if( !is_array($term) || !isset($term[1]) )
     204                {
     205                    continue;
     206                }
     207               
     208               
     209                // add to tax array
     210                $taxonomies[ $term[0] ][] = $term[1];
     211               
     212            }
     213           
     214           
     215            // now create the tax queries
     216            foreach( $taxonomies as $k => $v )
     217            {
     218                $options['tax_query'][] = array(
     219                    'taxonomy' => $k,
     220                    'field' => 'id',
     221                    'terms' => $v,
     222                );
     223            }
     224        }
     225       
     226        unset( $options['taxonomy'] );
    58227       
    59228       
     
    69238       
    70239       
     240        // load field
     241        $field = array();
     242        if( $options['ancestor'] )
     243        {
     244            $ancestor = apply_filters('acf/load_field', array(), $options['ancestor'] );
     245            $field = acf_get_child_field_from_parent_field( $options['field_key'], $ancestor );
     246        }
     247        else
     248        {
     249            $field = apply_filters('acf/load_field', array(), $options['field_key'] );
     250        }
     251       
     252       
     253        // get the post from which this field is rendered on
     254        $the_post = get_post( $options['post_id'] );
     255       
     256       
     257        // filters
     258        $options = apply_filters('acf/fields/relationship/query', $options, $field, $the_post);
     259        $options = apply_filters('acf/fields/relationship/query/name=' . $field['name'], $options, $field, $the_post );
     260        $options = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $options, $field, $the_post );
     261       
     262       
     263        $results = '';
     264       
     265       
    71266        // load the posts
    72267        $posts = get_posts( $options );
     268       
    73269        if( $posts )
    74270        {
    75             foreach( $posts  as $post )
     271            foreach( $posts  as $p )
    76272            {
    77273                // right aligned info
    78                 $layout = false;
    79274                $title = '<span class="relationship-item-info">';
    80                     while(has_sub_field('buckets', $post->ID)){
    81                         $layout = str_replace('_', ' ', get_row_layout());
     275                   
     276                    if( in_array('post_type', $field['result_elements']) )
     277                    {
     278                        $title .= $p->post_type;
    82279                    }
    83                     $title .= $layout;
     280                   
     281                    // WPML
     282                    if( $options['lang'] )
     283                    {
     284                        $title .= ' (' . $options['lang'] . ')';
     285                    }
    84286                   
    85287                $title .= '</span>';
    86288               
     289               
     290                // featured_image
     291                if( in_array('featured_image', $field['result_elements']) )
     292                {
     293                    $image = get_the_post_thumbnail( $p->ID, array(21, 21) );
     294                   
     295                    $title .= '<div class="result-thumbnail">' . $image . '</div>';
     296                }
     297               
     298               
    87299                // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
    88                 $title .= apply_filters( 'the_title', $post->post_title, $post->ID );
     300                $title .= apply_filters( 'the_title', $p->post_title, $p->ID );
    89301
    90302                // status
    91                 if($post->post_status != "publish")
     303                if($p->post_status != "publish")
    92304                {
    93                     $title .= " ($post->post_status)";
     305                    $title .= " ($p->post_status)";
    94306                }
    95307               
    96                 echo '<li><span class="edit" data-url="' . get_admin_url() . 'post.php?post=' . $post->ID . '&action=edit&popup=true&KeepThis=true&TB_iframe=true&height=200&width=200">Edit</span><a href="' . get_permalink($post->ID) . '" data-post_id="' . $post->ID . '">' . $title .  '<span class="add"></span></a></li>';
     308                // filters
     309                $title = apply_filters('acf/fields/relationship/result', $title, $p, $field, $the_post);
     310                $title = apply_filters('acf/fields/relationship/result/name=' . $field['name'] , $title, $p, $field, $the_post);
     311                $title = apply_filters('acf/fields/relationship/result/key=' . $field['key'], $title, $p, $field, $the_post);
     312               
     313               
     314                $results .= '<li><a href="' . get_permalink($p->ID) . '" data-post_id="' . $p->ID . '">' . $title .  '<span class="acf-button-add"></span></a></li>';
    97315            }
    98316        }
    99317       
    100318       
    101         // die?
    102         if( $ajax )
    103         {
    104             die();
    105         }
    106        
    107     }
    108    
    109    
    110     /*--------------------------------------------------------------------------------------
    111     *
    112     *   admin_print_scripts / admin_print_styles
    113     *
    114     *   @author Elliot Condon
    115     *   @since 3.0.0
    116     *
    117     *-------------------------------------------------------------------------------------*/
    118    
    119     function admin_print_scripts()
     319        echo $results;
     320        die();
     321           
     322    }
     323   
     324   
     325    /*
     326    *  create_field()
     327    *
     328    *  Create the HTML interface for your field
     329    *
     330    *  @param   $field - an array holding all the field's data
     331    *
     332    *  @type    action
     333    *  @since   3.6
     334    *  @date    23/01/13
     335    */
     336   
     337    function create_field( $field )
    120338    {
    121         wp_enqueue_script(array(
    122             'jquery-ui-sortable',
    123         ));
    124     }
    125    
    126     function admin_print_styles()
    127     {
    128  
    129     }
    130        
    131    
    132     /*--------------------------------------------------------------------------------------
    133     *
    134     *   create_field
    135     *
    136     *   @author Elliot Condon
    137     *   @since 2.0.5
    138     *   @updated 2.2.0
    139     *
    140     *-------------------------------------------------------------------------------------*/
    141    
    142     function create_field($field)
    143     {
    144         // vars
    145         $defaults = array(
    146             'post_type' =>  'buckets',
    147             'max'       =>  -1,
     339        // global
     340        global $post;
     341
     342       
     343        // no row limit?
     344        if( !$field['max'] || $field['max'] < 1 )
     345        {
     346            $field['max'] = 9999;
     347        }
     348       
     349       
     350        // class
     351        $class = '';
     352        if( $field['filters'] )
     353        {
     354            foreach( $field['filters'] as $filter )
     355            {
     356                $class .= ' has-' . $filter;
     357            }
     358        }
     359       
     360        $attributes = array(
     361            'max' => $field['max'],
     362            's' => '',
     363            'paged' => 1,
     364            'post_type' => implode(',', $field['post_type']),
     365            'taxonomy' => implode(',', $field['taxonomy']),
     366            'field_key' => $field['key']
    148367        );
    149368       
    150         $field = array_merge($defaults, $field);
    151        
    152        
    153         // validate types
    154         $field['max'] = (int) $field['max'];
    155        
    156        
    157         // row limit <= 0?
    158         if( $field['max'] <= 0 )
    159         {
    160             $field['max'] = 9999;
    161         }
    162        
    163         $field['type'] = 'relationship';
     369       
     370        // Lang
     371        if( defined('ICL_LANGUAGE_CODE') )
     372        {
     373            $attributes['lang'] = ICL_LANGUAGE_CODE;
     374        }
     375       
     376       
     377        // parent
     378        preg_match('/\[(field_.*?)\]/', $field['name'], $ancestor);
     379        if( isset($ancestor[1]) && $ancestor[1] != $field['key'])
     380        {
     381            $attributes['ancestor'] = $ancestor[1];
     382        }
     383               
    164384        ?>
    165 <div class="acf_buckets" data-max="<?php echo $field['max']; ?>" data-s="" data-paged="1" data-post_type="buckets">
     385<div class="acf_relationship<?php echo $class; ?>"<?php foreach( $attributes as $k => $v ): ?> data-<?php echo $k; ?>="<?php echo $v; ?>"<?php endforeach; ?>>
    166386   
    167387    <!-- Hidden Blank default value -->
     
    171391    <script type="text/html" class="tmpl-li">
    172392    <li>
    173         <span class="edit" data-url="<?php echo get_admin_url() ?>post.php?post={post_id}&action=edit&popup=true&TB_iframe=1">Edit</span>
    174         <a href="#" data-post_id="{post_id}">{title}<span class="remove"></span></a>
     393        <a href="#" data-post_id="{post_id}">{title}<span class="acf-button-remove"></span></a>
    175394        <input type="hidden" name="<?php echo $field['name']; ?>[]" value="{post_id}" />
    176395    </li>
     
    179398   
    180399    <!-- Left List -->
    181 
    182400    <div class="relationship_left">
    183401        <table class="widefat">
    184402            <thead>
     403                <?php if(in_array( 'search', $field['filters']) ): ?>
    185404                <tr>
    186405                    <th>
    187406                        <label class="relationship_label" for="relationship_<?php echo $field['name']; ?>"><?php _e("Search",'acf'); ?>...</label>
    188407                        <input class="relationship_search" type="text" id="relationship_<?php echo $field['name']; ?>" />
    189                         <div class="clear_relationship_search"></div>
     408                        <!-- <div class="clear_relationship_search"></div> -->
    190409                    </th>
    191410                </tr>
     411                <?php endif; ?>
     412                <?php if(in_array( 'post_type', $field['filters']) ): ?>
     413                <tr>
     414                    <th>
     415                        <?php
     416                       
     417                        // vars
     418                        $choices = array(
     419                            'all' => 'Filter by post type'
     420                        );
     421                       
     422                       
     423                        if( in_array('all', $field['post_type']) )
     424                        {
     425                            $post_types = apply_filters( 'acf/get_post_types', array() );
     426                            $choices = array_merge( $choices, $post_types);
     427                        }
     428                        else
     429                        {
     430                            foreach( $field['post_type'] as $post_type )
     431                            {
     432                                $choices[ $post_type ] = $post_type;
     433                            }
     434                        }
     435                       
     436                       
     437                        // create field
     438                        do_action('acf/create_field', array(
     439                            'type'  =>  'select',
     440                            'name'  =>  '',
     441                            'class' =>  'select-post_type',
     442                            'value' =>  '',
     443                            'choices' => $choices,
     444                        ));
     445                       
     446                        ?>
     447                    </th>
     448                </tr>
     449                <?php endif; ?>
    192450            </thead>
    193451        </table>
     
    197455            </li>
    198456        </ul>
    199         <a href="<?php echo bloginfo('url'); ?>/wp-admin/post-new.php?post_type=buckets&popup=true&TB_iframe=1" title="New Bucket" class="button-primary new-bucket thickbox">Add New</a>
    200457    </div>
    201458    <!-- /Left List -->
     
    205462        <ul class="bl relationship_list">
    206463        <?php
    207 
    208464        if( $field['value'] )
    209465        {
    210             foreach( $field['value'] as $post )
     466            foreach( $field['value'] as $p )
    211467            {
     468                // right aligned info
     469                $title = '<span class="relationship-item-info">';
     470                   
     471                    if( in_array('post_type', $field['result_elements']) )
     472                    {
     473                        $title .= $p->post_type;
     474                    }
     475                   
     476                    // WPML
     477                    if( defined('ICL_LANGUAGE_CODE') )
     478                    {
     479                        $title .= ' (' . ICL_LANGUAGE_CODE . ')';
     480                    }
     481                   
     482                $title .= '</span>';
     483               
     484               
     485                // featured_image
     486                if( in_array('featured_image', $field['result_elements']) )
     487                {
     488                    $image = get_the_post_thumbnail( $p->ID, array(21, 21) );
     489                   
     490                    $title .= '<div class="result-thumbnail">' . $image . '</div>';
     491                }
     492               
    212493               
    213494                // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory
    214                 $title = apply_filters( 'the_title', $post->post_title, $post->ID );
    215 
     495                $title .= apply_filters( 'the_title', $p->post_title, $p->ID );
    216496
    217497                // status
    218                 if($post->post_status == "private" || $post->post_status == "draft")
     498                if($p->post_status != "publish")
    219499                {
    220                     $title .= " ($post->post_status)";
     500                    $title .= " ($p->post_status)";
    221501                }
     502
     503               
     504                // filters
     505                $title = apply_filters('acf/fields/relationship/result', $title, $p, $field, $post);
     506                $title = apply_filters('acf/fields/relationship/result/name=' . $field['name'] , $title, $p, $field, $post);
     507                $title = apply_filters('acf/fields/relationship/result/key=' . $field['key'], $title, $p, $field, $post);
     508               
    222509               
    223510                echo '<li>
    224                     <span class="edit" data-url="' . get_admin_url() . 'post.php?post=' . $post->ID . '&action=edit&popup=true&TB_iframe=1">Edit</span>
    225                     <a href="javascript:;" class="" data-post_id="' . $post->ID . '">' . $title . '<span class="remove"></span></a>
    226                     <input type="hidden" name="' . $field['name'] . '[]" value="' . $post->ID . '" />
     511                    <a href="' . get_permalink($p->ID) . '" class="" data-post_id="' . $p->ID . '">' . $title . '<span class="acf-button-remove"></span></a>
     512                    <input type="hidden" name="' . $field['name'] . '[]" value="' . $p->ID . '" />
    227513                </li>';
     514               
     515                   
    228516            }
    229517        }
     
    231519        ?>
    232520        </ul>
    233        
    234521    </div>
    235522    <!-- / Right List -->
    236     <div style="clear: both;"></div>
     523   
    237524</div>
    238 
    239 
    240525        <?php
    241 
    242    
    243     }
    244    
    245    
    246     /*--------------------------------------------------------------------------------------
    247     *
    248     *   create_options
    249     *
    250     *   @author Elliot Condon
    251     *   @since 2.0.6
    252     *   @updated 2.2.0
    253     *
    254     *-------------------------------------------------------------------------------------*/
    255    
    256     function create_options($key, $field)
     526    }
     527   
     528   
     529   
     530    /*
     531    *  create_options()
     532    *
     533    *  Create extra options for your field. This is rendered when editing a field.
     534    *  The value of $field['name'] can be used (like bellow) to save extra data to the $field
     535    *
     536    *  @type    action
     537    *  @since   3.6
     538    *  @date    23/01/13
     539    *
     540    *  @param   $field  - an array holding all the field's data
     541    */
     542   
     543    function create_options( $field )
    257544    {
    258545        // vars
    259         $defaults = array(
    260             'post_type' =>  'buckets',
    261             'max'       =>  '',
    262             'taxonomy'  =>  array('all'),
    263         );
    264        
    265         $field = array_merge($defaults, $field);
     546        $field = array_merge($this->defaults, $field);
     547        $key = $field['name'];
    266548       
    267549        ?>
    268        
    269         <tr class="field_option field_option_<?php echo $this->name; ?>">
    270             <td class="label">
    271                 <label><?php _e("Maximum posts",'acf'); ?></label>
    272             </td>
    273             <td>
    274                 <?php
    275                 $this->parent->create_field(array(
    276                     'type'  =>  'text',
    277                     'name'  =>  'fields['.$key.'][max]',
    278                     'value' =>  $field['max'],
    279                 ));
    280                 ?>
    281             </td>
    282         </tr>
     550
     551
     552<tr class="field_option field_option_<?php echo $this->name; ?>">
     553    <td class="label">
     554        <label><?php _e("Maximum posts",'acf'); ?></label>
     555    </td>
     556    <td>
     557        <?php
     558        do_action('acf/create_field', array(
     559            'type'  =>  'text',
     560            'name'  =>  'fields['.$key.'][max]',
     561            'value' =>  $field['max'],
     562        ));
     563        ?>
     564    </td>
     565</tr>
    283566        <?php
    284     }
    285    
    286 
    287     /*--------------------------------------------------------------------------------------
    288     *
    289     *   get_value
    290     *
    291     *   @author Elliot Condon
    292     *   @since 3.3.3
    293     *
    294     *-------------------------------------------------------------------------------------*/
    295    
    296     function get_value($post_id, $field)
     567       
     568    }
     569   
     570   
     571    /*
     572    *  format_value()
     573    *
     574    *  This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
     575    *
     576    *  @type    filter
     577    *  @since   3.6
     578    *  @date    23/01/13
     579    *
     580    *  @param   $value  - the value which was loaded from the database
     581    *  @param   $post_id - the $post_id from which the value was loaded
     582    *  @param   $field  - the field array holding all the field options
     583    *
     584    *  @return  $value  - the modified value
     585    */
     586   
     587    function format_value( $value, $post_id, $field, $output = false )
    297588    {
    298         // get value
    299         $value = parent::get_value($post_id, $field);
    300                
    301589        // empty?
    302590        if( !$value )
     
    319607        }
    320608       
    321 
    322609       
    323610        // find posts (DISTINCT POSTS)
     
    325612            'numberposts' => -1,
    326613            'post__in' => $value,
    327             'post_type' =>  get_post_types( array('public' => true) ),
     614            'post_type' =>  apply_filters('acf/get_post_types', array()),
    328615            'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
    329616        ));
     
    331618       
    332619        $ordered_posts = array();
    333         foreach( $posts as $post )
    334         {   
     620        foreach( $posts as $p )
     621        {
    335622            // create array to hold value data
    336             $ordered_posts[ $post->ID ] = $post;
    337         }
    338        
    339        
     623            $ordered_posts[ $p->ID ] = $p;
     624        }
     625       
     626        $buckets = false;
    340627        // override value array with attachments
    341628        foreach( $value as $k => $v)
    342629        {
    343             $value[ $k ] = $ordered_posts[ $v ];
    344 
    345         }
    346                        
     630            // check that post exists (my have been trashed)
     631            if( !isset($ordered_posts[ $v ]) )
     632            {
     633                unset( $value[ $k ] );
     634            }
     635            else
     636            {
     637                $buckets .= get_bucket($v);
     638                $value[ $k ] = $ordered_posts[ $v ];
     639            }
     640        }
     641       
     642       
    347643        // return value
     644        if ($output == true){
     645            return $buckets;
     646        }
    348647        return $value; 
    349648    }
    350649   
    351 
    352 
    353     function get_value_for_api($post_id, $field)
     650   
     651    /*
     652    *  format_value_for_api()
     653    *
     654    *  This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
     655    *
     656    *  @type    filter
     657    *  @since   3.6
     658    *  @date    23/01/13
     659    *
     660    *  @param   $value  - the value which was loaded from the database
     661    *  @param   $post_id - the $post_id from which the value was loaded
     662    *  @param   $field  - the field array holding all the field options
     663    *
     664    *  @return  $value  - the modified value
     665    */
     666   
     667    function format_value_for_api( $value, $post_id, $field )
    354668    {
    355         // get value
    356         $value = parent::get_value($post_id, $field);
    357                
    358         // empty?
    359         if( !$value )
    360         {
    361             return $value;
    362         }
    363        
    364        
    365         // Pre 3.3.3, the value is a string coma seperated
    366         if( !is_array($value) )
    367         {
    368             $value = explode(',', $value);
    369         }
    370        
    371        
    372         // empty?
    373         if( empty($value) )
    374         {
    375             return $value;
    376         }
    377        
    378 
    379        
    380         // find posts (DISTINCT POSTS)
    381         $posts = get_posts(array(
    382             'numberposts' => -1,
    383             'post__in' => $value,
    384             'post_type' =>  get_post_types( array('public' => true) ),
    385             'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
    386         ));
    387 
    388        
    389         $ordered_posts = array();
    390         foreach( $posts as $post )
    391         {   
    392             // create array to hold value data
    393             $ordered_posts[ $post->ID ] = $post;
    394         }
    395        
    396         $buckets = false;
    397         // override value array with attachments
    398         foreach( $value as $k => $v)
    399         {
    400             $buckets .= get_bucket($v);
    401             $value[ $k ] = $ordered_posts[ $v ];
    402 
    403         }
    404        
    405 
    406         return $buckets;
    407 
    408     }
    409 
     669        return $this->format_value( $value, $post_id, $field, true );
     670    }
     671   
     672   
     673    /*
     674    *  update_value()
     675    *
     676    *  This filter is appied to the $value before it is updated in the db
     677    *
     678    *  @type    filter
     679    *  @since   3.6
     680    *  @date    23/01/13
     681    *
     682    *  @param   $value - the value which will be saved in the database
     683    *  @param   $post_id - the $post_id of which the value will be saved
     684    *  @param   $field - the field array holding all the field options
     685    *
     686    *  @return  $value - the modified value
     687    */
     688   
     689    function update_value( $value, $post_id, $field )
     690    {
     691        // array?
     692        if( is_array($value) ){ foreach( $value as $k => $v ){
     693           
     694            // object?
     695            if( is_object($v) && isset($v->ID) )
     696            {
     697                $value[ $k ] = $v->ID;
     698            }
     699           
     700        }}
     701               
     702       
     703        return $value;
     704    }
    410705   
    411706}
    412707
     708new acf_field_buckets();
     709
    413710?>
  • buckets/trunk/readme.txt

    r677270 r738526  
    4242
    4343== Changelog ==
     44= 0.2 =
     45[Fixed] - Updated Buckets plugin to work with ACF 4.0.
     46
    4447= 0.1.9.3 =
    4548[Fixed] - Removed ZeroClipboard function because of security exploit found.
Note: See TracChangeset for help on using the changeset viewer.