PageRenderTime 501ms CodeModel.GetById 162ms app.highlight 236ms RepoModel.GetById 85ms app.codeStats 1ms

/classes/fields/pick.php

https://github.com/ElmsPark/pods
PHP | 1209 lines | 828 code | 211 blank | 170 comment | 229 complexity | 57feaa4e7f0ac699db1beca35190b5da MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * @package Pods\Fields
   4 */
   5class PodsField_Pick extends PodsField {
   6
   7    /**
   8     * Field Type Group
   9     *
  10     * @var string
  11     * @since 2.0.0
  12     */
  13    public static $group = 'Relationships / Media';
  14
  15    /**
  16     * Field Type Identifier
  17     *
  18     * @var string
  19     * @since 2.0.0
  20     */
  21    public static $type = 'pick';
  22
  23    /**
  24     * Field Type Label
  25     *
  26     * @var string
  27     * @since 2.0.0
  28     */
  29    public static $label = 'Relationship';
  30
  31    /**
  32     * Available Related Objects
  33     *
  34     * @var array
  35     * @since 2.3.0
  36     */
  37    private static $related_objects = array();
  38
  39    /**
  40     * Setup related objects list
  41     *
  42     * @since 2.0.0
  43     */
  44    public function __construct () {
  45        if ( empty( self::$related_objects ) ) {
  46            $related_objects = get_transient( 'pods_related_objects' );
  47
  48            if ( !empty( $related_objects ) )
  49                self::$related_objects = $related_objects;
  50            else {
  51                // Custom
  52                self::$related_objects[ 'custom-simple' ] = array(
  53                    'label' => __( 'Simple (custom defined list)', 'pods' ),
  54                    'group' => __( 'Custom', 'pods' ),
  55                    'simple' => true
  56                );
  57
  58                // Pods
  59                // @todo Upgrade should convert to proper type selections (pods-pod_name >> post_type-pod_name
  60                $_pods = pods_api()->load_pods( array( 'type' => 'pod' ) );
  61
  62                foreach ( $_pods as $k => $pod ) {
  63                    self::$related_objects[ 'pod-' . $pod[ 'name' ] ] = array(
  64                        'label' => $pod[ 'label' ] . ' (' . $pod[ 'name' ] . ')',
  65                        'group' => __( 'Pods', 'pods' )
  66                    );
  67                }
  68
  69                // Post Types
  70                $post_types = get_post_types();
  71                asort( $post_types );
  72
  73                $ignore = array( 'attachment', 'revision', 'nav_menu_item' );
  74
  75                foreach ( $post_types as $post_type => $label ) {
  76                    if ( in_array( $post_type, $ignore ) || empty( $post_type ) || 0 === strpos( $post_type, '_pods_' ) ) {
  77                        unset( $post_types[ $post_type ] );
  78
  79                        continue;
  80                    }
  81
  82                    $post_type = get_post_type_object( $post_type );
  83
  84                    self::$related_objects[ 'post_type-' . $post_type->name ] = array(
  85                        'label' => $post_type->label,
  86                        'group' => __( 'Post Types', 'pods' )
  87                    );
  88                }
  89
  90                // Taxonomies
  91                $taxonomies = get_taxonomies();
  92                asort( $taxonomies );
  93
  94                $ignore = array( 'nav_menu', 'post_format' );
  95
  96                foreach ( $taxonomies as $taxonomy => $label ) {
  97                    if ( in_array( $taxonomy, $ignore ) || empty( $taxonomy ) )
  98                        continue;
  99
 100                    $taxonomy = get_taxonomy( $taxonomy );
 101
 102                    self::$related_objects[ 'taxonomy-' . $taxonomy->name ] = array(
 103                        'label' => $taxonomy->label,
 104                        'group' => __( 'Taxonomies', 'pods' )
 105                    );
 106                }
 107
 108                // Other WP Objects
 109                self::$related_objects[ 'user' ] = array(
 110                    'label' => __( 'Users', 'pods' ),
 111                    'group' => __( 'Other WP Objects', 'pods' )
 112                );
 113
 114                self::$related_objects[ 'role' ] = array(
 115                    'label' => __( 'User Roles', 'pods' ),
 116                    'group' => __( 'Other WP Objects', 'pods' ),
 117                    'simple' => true
 118                );
 119
 120                self::$related_objects[ 'comment' ] = array(
 121                    'label' => __( 'Comments', 'pods' ),
 122                    'group' => __( 'Other WP Objects', 'pods' )
 123                );
 124
 125                self::$related_objects[ 'image-size' ] = array(
 126                    'label' => __( 'Image Sizes', 'pods' ),
 127                    'group' => __( 'Other WP Objects', 'pods' ),
 128                    'simple' => true
 129                );
 130
 131                self::$related_objects[ 'nav_menu' ] = array(
 132                    'label' => __( 'Navigation Menus', 'pods' ),
 133                    'group' => __( 'Other WP Objects', 'pods' )
 134                );
 135
 136                self::$related_objects[ 'post_format' ] = array(
 137                    'label' => __( 'Post Formats', 'pods' ),
 138                    'group' => __( 'Other WP Objects', 'pods' )
 139                );
 140
 141                self::$related_objects[ 'post-status' ] = array(
 142                    'label' => __( 'Post Status', 'pods' ),
 143                    'group' => __( 'Other WP Objects', 'pods' ),
 144                    'simple' => true
 145                );
 146
 147                self::$related_objects[ 'sidebar' ] = array(
 148                    'label' => __( 'Sidebars', 'pods' ),
 149                    'group' => __( 'Other WP Objects', 'pods' ),
 150                    'simple' => true
 151                );
 152
 153                // Advanced Objects
 154                self::$related_objects[ 'table' ] = array(
 155                    'label' => __( 'Database Table', 'pods' ),
 156                    'group' => __( 'Advanced Objects', 'pods' )
 157                );
 158
 159                self::$related_objects[ 'site' ] = array(
 160                    'label' => __( 'Multisite Sites', 'pods' ),
 161                    'group' => __( 'Advanced Objects', 'pods' )
 162                );
 163
 164                self::$related_objects[ 'network' ] = array(
 165                    'label' => __( 'Multisite Networks', 'pods' ),
 166                    'group' => __( 'Advanced Objects', 'pods' )
 167                );
 168
 169                self::$related_objects[ 'post-types' ] = array(
 170                    'label' => __( 'Post Types', 'pods' ),
 171                    'group' => __( 'Advanced Objects', 'pods' ),
 172                    'simple' => true
 173                );
 174
 175                self::$related_objects[ 'taxonomies' ] = array(
 176                    'label' => __( 'Taxonomies', 'pods' ),
 177                    'group' => __( 'Advanced Objects', 'pods' ),
 178                    'simple' => true
 179                );
 180
 181                set_transient( 'pods_related_objects', self::$related_objects );
 182            }
 183        }
 184    }
 185
 186    /**
 187     * Add options and set defaults to
 188     *
 189     * @return array
 190     *
 191     * @since 2.0.0
 192     */
 193    public function options () {
 194        $options = array(
 195            'pick_format_type' => array(
 196                'label' => __( 'Selection Type', 'pods' ),
 197                'help' => __( 'help', 'pods' ),
 198                'default' => 'single',
 199                'type' => 'pick',
 200                'data' => array(
 201                    'single' => __( 'Single Select', 'pods' ),
 202                    'multi' => __( 'Multiple Select', 'pods' )
 203                ),
 204                'dependency' => true
 205            ),
 206            'pick_format_single' => array(
 207                'label' => __( 'Format', 'pods' ),
 208                'help' => __( 'help', 'pods' ),
 209                'depends-on' => array( 'pick_format_type' => 'single' ),
 210                'default' => 'dropdown',
 211                'type' => 'pick',
 212                'data' => apply_filters(
 213                    'pods_form_ui_field_pick_format_single_options',
 214                    array(
 215                        'dropdown' => __( 'Drop Down', 'pods' ),
 216                        'radio' => __( 'Radio Buttons', 'pods' ),
 217                        'autocomplete' => __( 'Autocomplete', 'pods' )
 218                    ) + ( ( pods_developer() ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() )
 219                ),
 220                'dependency' => true
 221            ),
 222            'pick_format_multi' => array(
 223                'label' => __( 'Format', 'pods' ),
 224                'help' => __( 'help', 'pods' ),
 225                'depends-on' => array( 'pick_format_type' => 'multi' ),
 226                'default' => 'checkbox',
 227                'type' => 'pick',
 228                'data' => apply_filters(
 229                    'pods_form_ui_field_pick_format_multi_options',
 230                    array(
 231                        'checkbox' => __( 'Checkboxes', 'pods' ),
 232                        'multiselect' => __( 'Multi Select', 'pods' ),
 233                        'autocomplete' => __( 'Autocomplete', 'pods' )
 234                    ) + ( ( pods_developer() ) ? array( 'flexible' => __( 'Flexible', 'pods' ) ) : array() )
 235                ),
 236                'dependency' => true
 237            ),
 238            'pick_limit' => array(
 239                'label' => __( 'Selection Limit', 'pods' ),
 240                'help' => __( 'help', 'pods' ),
 241                'depends-on' => array( 'pick_format_type' => 'multi' ),
 242                'default' => 0,
 243                'type' => 'number'
 244            ),
 245            'pick_table_id' => array(
 246                'label' => __( 'Table ID Column', 'pods' ),
 247                'help' => __( 'You must provide the ID column name for the table, this will be used to keep track of the relationship', 'pods' ),
 248                'depends-on' => array( 'pick_object' => 'table' ),
 249                'required' => 1,
 250                'default' => '',
 251                'type' => 'text'
 252            ),
 253            'pick_table_index' => array(
 254                'label' => __( 'Table Index Column', 'pods' ),
 255                'help' => __( 'You must provide the index column name for the table, this may optionally also be the ID column name', 'pods' ),
 256                'depends-on' => array( 'pick_object' => 'table' ),
 257                'required' => 1,
 258                'default' => '',
 259                'type' => 'text'
 260            ),
 261            'pick_display' => array(
 262                'label' => __( 'Display Field in Selection List', 'pods' ),
 263                'help' => __( 'Provide the name of a field on the related object to reference, example: {@post_title}', 'pods' ),
 264                'excludes-on' => array(
 265                    'pick_object' => array_merge(
 266                        array( 'site', 'network' ),
 267                        self::simple_objects()
 268                    )
 269                ),
 270                'default' => '',
 271                'type' => 'text'
 272            ),
 273            'pick_where' => array(
 274                'label' => __( 'Customized <em>WHERE</em>', 'pods' ),
 275                'help' => __( 'help', 'pods' ),
 276                'excludes-on' => array(
 277                    'pick_object' => array_merge(
 278                        array( 'site', 'network' ),
 279                        self::simple_objects()
 280                    )
 281                ),
 282                'default' => '',
 283                'type' => 'text'
 284            ),
 285            'pick_orderby' => array(
 286                'label' => __( 'Customized <em>ORDER BY</em>', 'pods' ),
 287                'help' => __( 'help', 'pods' ),
 288                'excludes-on' => array(
 289                    'pick_object' => array_merge(
 290                        array( 'site', 'network' ),
 291                        self::simple_objects()
 292                    )
 293                ),
 294                'default' => '',
 295                'type' => 'text'
 296            ),
 297            'pick_groupby' => array(
 298                'label' => __( 'Customized <em>GROUP BY</em>', 'pods' ),
 299                'help' => __( 'help', 'pods' ),
 300                'excludes-on' => array(
 301                    'pick_object' => array_merge(
 302                        array( 'site', 'network' ),
 303                        self::simple_objects()
 304                    )
 305                ),
 306                'default' => '',
 307                'type' => 'text'
 308            )
 309            /*,
 310            'pick_size' => array(
 311                'label' => __( 'Field Size', 'pods' ),
 312                'default' => 'medium',
 313                'type' => 'pick',
 314                'data' => array(
 315                    'small' => __( 'Small', 'pods' ),
 316                    'medium' => __( 'Medium', 'pods' ),
 317                    'large' => __( 'Large', 'pods' )
 318                )
 319            )*/
 320        );
 321        return $options;
 322    }
 323
 324    /**
 325     * Register a related object
 326     *
 327     * @param string $name Object name
 328     * @param string $label Object label
 329     * @param array $options Object options
 330     *
 331     * @return array|boolean Object array or false if unsuccessful
 332     * @since 2.3.0
 333     */
 334    public function register_related_object ( $name, $label, $options = null ) {
 335        if ( empty( $name ) || empty( $label ) )
 336            return false;
 337
 338        $related_object = array(
 339            'label' => $label,
 340            'group' => $label,
 341            'simple' => false,
 342            'data' => array()
 343            //'data_callback' => false,
 344            //'value_to_label_callback' => false,
 345            //'simple_value_callback' => false
 346        );
 347
 348        $related_object = array_merge( $related_object, $options );
 349
 350        self::$related_objects[ $name ] = $related_object;
 351
 352        return true;
 353    }
 354
 355    /**
 356     * Return available related objects
 357     *
 358     * @return array Field selection array
 359     * @since 2.3.0
 360     */
 361    public function related_objects () {
 362        $related_objects = array();
 363
 364        foreach ( self::$related_objects as $related_object ) {
 365            if ( !isset( $related_objects[ $related_object[ 'group' ] ] ) )
 366                $related_objects[ $related_object[ 'group' ] ] = array();
 367
 368            $related_objects[ $related_object[ 'group' ] ][] = $related_object[ 'label' ];
 369        }
 370
 371        return (array) apply_filters( 'pods_form_ui_field_pick_related_objects', $related_objects );
 372    }
 373
 374    /**
 375     * Return available simple object names
 376     *
 377     * @return array Simple object names
 378     * @since 2.3.0
 379     */
 380    public function simple_objects () {
 381        $simple_objects = array();
 382
 383        foreach ( self::$related_objects as $object => $related_object ) {
 384            if ( !isset( $related_object[ 'simple' ] ) || !$related_object[ 'simple' ] )
 385                continue;
 386
 387            $simple_objects[] = $object;
 388        }
 389
 390        return (array) apply_filters( 'pods_form_ui_field_pick_simple_objects', $simple_objects );
 391    }
 392
 393    /**
 394     * Define the current field's schema for DB table storage
 395     *
 396     * @param array $options
 397     *
 398     * @return array
 399     * @since 2.0.0
 400     */
 401    public function schema ( $options = null ) {
 402        $schema = false;
 403
 404        if ( in_array( pods_var( 'pick_object', $options ), array( 'custom-simple', 'role', 'post-types', 'taxonomies' ) ) )
 405            $schema = 'LONGTEXT';
 406
 407        return $schema;
 408    }
 409
 410    /**
 411     * Change the way the value of the field is displayed with Pods::get
 412     *
 413     * @param mixed $value
 414     * @param string $name
 415     * @param array $options
 416     * @param array $fields
 417     * @param array $pod
 418     * @param int $id
 419     *
 420     * @since 2.0.0
 421     */
 422    public function display ( $value = null, $name = null, $options = null, $pod = null, $id = null ) {
 423        $fields = null;
 424
 425        if ( is_object( $pod ) && isset( $pod->fields ) )
 426            $fields = $pod->fields;
 427        elseif ( is_array( $pod ) && isset( $pod[ 'fields' ] ) )
 428            $fields = $pod[ 'fields' ];
 429
 430        return pods_serial_comma( $value, $name, $fields );
 431    }
 432
 433    /**
 434     * Customize output of the form field
 435     *
 436     * @param string $name
 437     * @param mixed $value
 438     * @param array $options
 439     * @param array $pod
 440     * @param int $id
 441     *
 442     * @since 2.0.0
 443     */
 444    public function input ( $name, $value = null, $options = null, $pod = null, $id = null ) {
 445        global $wpdb;
 446
 447        $options = (array) $options;
 448        $form_field_type = PodsForm::$field_type;
 449
 450        $options[ 'grouped' ] = 1;
 451
 452        $options[ 'table_info' ] = array();
 453
 454        $custom = pods_var_raw( 'pick_custom', $options, false );
 455
 456        $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id );
 457
 458        $ajax = false;
 459
 460        if ( ( 'custom-simple' != pods_var( 'pick_object', $options ) || empty( $custom ) ) && '' != pods_var( 'pick_object', $options, '', null, true ) ) {
 461            $autocomplete = false;
 462
 463            if ( 'single' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_single', $options ) )
 464                $autocomplete = true;
 465            elseif ( 'multi' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_multi', $options ) )
 466                $autocomplete = true;
 467
 468            $params[ 'limit' ] = -1;
 469
 470            if ( $autocomplete )
 471                $params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', 30, $name, $value, $options, $pod, $id );
 472
 473            $ajax = true;
 474        }
 475
 476        if ( 'single' == pods_var( 'pick_format_type', $options ) ) {
 477            if ( 'dropdown' == pods_var( 'pick_format_single', $options ) )
 478                $field_type = 'select';
 479            elseif ( 'radio' == pods_var( 'pick_format_single', $options ) )
 480                $field_type = 'radio';
 481            elseif ( 'autocomplete' == pods_var( 'pick_format_single', $options ) )
 482                $field_type = 'select2';
 483            else {
 484                // Support custom integration
 485                do_action( 'pods_form_ui_field_pick_input_' . pods_var( 'pick_format_type', $options ) . '_' . pods_var( 'pick_format_single', $options ), $name, $value, $options, $pod, $id );
 486                do_action( 'pods_form_ui_field_pick_input', pods_var( 'pick_format_type', $options ), $name, $value, $options, $pod, $id );
 487                return;
 488            }
 489        }
 490        elseif ( 'multi' == pods_var( 'pick_format_type', $options ) ) {
 491            if ( 'checkbox' == pods_var( 'pick_format_multi', $options ) )
 492                $field_type = 'checkbox';
 493            elseif ( 'multiselect' == pods_var( 'pick_format_multi', $options ) )
 494                $field_type = 'select';
 495            elseif ( 'autocomplete' == pods_var( 'pick_format_multi', $options ) )
 496                $field_type = 'select2';
 497            else {
 498                // Support custom integration
 499                do_action( 'pods_form_ui_field_pick_input_' . pods_var( 'pick_format_type', $options ) . '_' . pods_var( 'pick_format_multi', $options ), $name, $value, $options, $pod, $id );
 500                do_action( 'pods_form_ui_field_pick_input', pods_var( 'pick_format_type', $options ), $name, $value, $options, $pod, $id );
 501                return;
 502            }
 503        }
 504
 505        pods_view( PODS_DIR . 'ui/fields/' . $field_type . '.php', compact( array_keys( get_defined_vars() ) ) );
 506    }
 507
 508    /**
 509     * Get the data from the field
 510     *
 511     * @param string $name The name of the field
 512     * @param string|array $value The value of the field
 513     * @param array $options
 514     * @param array $pod
 515     * @param int $id
 516     *
 517     * @return array Array of possible field data
 518     *
 519     * @since 2.0.0
 520     */
 521    public function data ( $name, $value = null, $options = null, $pod = null, $id = null ) {
 522        $data = array( '' => pods_var_raw( 'pick_select_text', $options, __( '-- Select One --', 'pods' ), null, true ) );
 523
 524        if ( 'single' != pods_var( 'pick_format_type', $options ) || 'dropdown' != pods_var( 'pick_format_single', $options ) )
 525            $data = array();
 526
 527        if ( isset( $options[ 'data' ] ) && !empty( $options[ 'data' ] ) )
 528            $data = (array) $options[ 'data' ];
 529
 530        $custom = trim( pods_var_raw( 'pick_custom', $options, '' ) );
 531
 532        $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id );
 533
 534        if ( 'custom-simple' == pods_var( 'pick_object', $options ) && !empty( $custom ) ) {
 535            if ( !is_array( $custom ) ) {
 536                $custom = explode( "\n", $custom );
 537
 538                foreach ( $custom as $custom_value ) {
 539                    $custom_label = explode( '|', $custom_value );
 540
 541                    if ( empty( $custom_label ) )
 542                        continue;
 543
 544                    if ( 1 == count( $custom_label ) )
 545                        $custom_label = $custom_value;
 546                    else {
 547                        $custom_value = $custom_label[ 0 ];
 548                        $custom_label = $custom_label[ 1 ];
 549                    }
 550
 551                    $data[ $custom_value ] = $custom_label;
 552                }
 553            }
 554            else {
 555                foreach ( $custom as $custom_value => $custom_label ) {
 556                    $data[ $custom_value ] = $custom_label;
 557                }
 558            }
 559        }
 560        elseif ( '' != pods_var( 'pick_object', $options, '' ) && array() == pods_var_raw( 'data', $options, array(), null, true ) ) {
 561            if ( 'post-status' == $options[ 'pick_object' ] ) {
 562                $post_stati = get_post_stati( array(), 'objects' );
 563
 564                foreach ( $post_stati as $post_status ) {
 565                    $data[ $post_status->name ] = $post_status->label;
 566                }
 567            }
 568            elseif ( 'role' == $options[ 'pick_object' ] ) {
 569                global $wp_roles;
 570
 571                foreach ( $wp_roles->role_objects as $key => $role ) {
 572                    $data[ $key ] = $wp_roles->role_names[ $key ];
 573                }
 574            }
 575            elseif ( 'sidebar' == $options[ 'pick_object' ] ) {
 576                global $wp_registered_sidebars;
 577
 578                if ( !empty( $wp_registered_sidebars ) ) {
 579                    foreach ( $wp_registered_sidebars as $sidebar ) {
 580                        $data[ $sidebar[ 'id' ] ] = $sidebar[ 'name' ];
 581                    }
 582                }
 583            }
 584            elseif ( 'image-size' == $options[ 'pick_object' ] ) {
 585                $image_sizes = get_intermediate_image_sizes();
 586
 587                foreach ( $image_sizes as $image_size ) {
 588                    $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) );
 589                }
 590            }
 591            elseif ( 'post-types' == $options[ 'pick_object' ] ) {
 592                $post_types = get_post_types( array(), 'objects' );
 593
 594                $ignore = array( 'revision', 'nav_menu_item' );
 595
 596                foreach ( $post_types as $post_type ) {
 597                    if ( in_array( $post_type->name, $ignore ) || 0 === strpos( $post_type->name, '_pods_' ) )
 598                        continue;
 599
 600                    $data[ $post_type->name ] = $post_type->label;
 601                }
 602            }
 603            elseif ( 'taxonomies' == $options[ 'pick_object' ] ) {
 604                $taxonomies = get_taxonomies( array(), 'objects' );
 605
 606                $ignore = array( 'nav_menu', 'post_format' );
 607
 608                foreach ( $taxonomies as $taxonomy ) {
 609                    if ( in_array( $taxonomy->name, $ignore ) )
 610                        continue;
 611
 612                    $data[ $taxonomy->name ] = $taxonomy->label;
 613                }
 614            }
 615            elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ] ) ) {
 616                if ( !empty( self::$related_objects[ $options[ 'pick_object' ][ 'data' ] ] ) )
 617                    $data = self::$related_objects[ $options[ 'pick_object' ] ][ 'data' ];
 618                elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ][ 'data_callback' ] ) && is_callable( self::$related_objects[ $options[ 'pick_object' ] ][ 'data_callback' ] ) ) {
 619                    $data = call_user_func_array(
 620                        self::$related_objects[ $options[ 'pick_object' ] ][ 'data_callback' ],
 621                        array( compact( array( 'name', 'value', 'options', 'pod', 'id' ) ) )
 622                    );
 623                }
 624            }
 625            else {
 626                $pick_val = pods_var( 'pick_val', $options );
 627
 628                if ( 'table' == pods_var( 'pick_object', $options ) )
 629                    $pick_val = pods_var( 'pick_table', $options, $pick_val, null, true );
 630
 631                $options[ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $options ), $pick_val, null, null, $options );
 632
 633                $search_data = pods_data();
 634                $search_data->table = $options[ 'table_info' ][ 'table' ];
 635                $search_data->join = $options[ 'table_info' ][ 'join' ];
 636                $search_data->field_id = $options[ 'table_info' ][ 'field_id' ];
 637                $search_data->field_index = $options[ 'table_info' ][ 'field_index' ];
 638                $search_data->where = $options[ 'table_info' ][ 'where' ];
 639                $search_data->orderby = $options[ 'table_info' ][ 'orderby' ];
 640
 641                if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
 642                    $search_data->pod = $options[ 'table_info' ][ 'pod' ][ 'name' ];
 643                    $search_data->fields = $options[ 'table_info' ][ 'pod' ][ 'fields' ];
 644                }
 645
 646                $params = array(
 647                    'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`",
 648                    'table' => $search_data->table,
 649                    'where' => pods_var_raw( 'pick_where', $options, (array) $options[ 'table_info' ][ 'where_default' ], null, true ),
 650                    'orderby' => pods_var_raw( 'pick_orderby', $options, null, null, true ),
 651                    'groupby' => pods_var_raw( 'pick_groupby', $options, null, null, true )
 652                );
 653
 654                if ( in_array( $options[ 'pick_object' ], array( 'site', 'network' ) ) )
 655                    $params[ 'select' ] .= ', `t`.`path`';
 656
 657                if ( !empty( $params[ 'where' ] ) && (array) $options[ 'table_info' ][ 'where_default' ] != $params[ 'where' ]  )
 658                    $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ], true );
 659
 660                /* not needed yet
 661                if ( !empty( $params[ 'orderby' ] ) )
 662                    $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true );
 663
 664                if ( !empty( $params[ 'groupby' ] ) )
 665                    $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/
 666
 667                $display = trim( pods_var( 'pick_display', $options ), ' {@}' );
 668
 669                if ( 0 < strlen( $display ) ) {
 670                    if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) ) {
 671                        if ( isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ][ $display ] ) ) {
 672                            $search_data->field_index = $display;
 673
 674                            $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
 675                        }
 676                        elseif ( isset( $options[ 'table_info' ][ 'pod' ][ 'fields' ][ $display ] ) ) {
 677                            $search_data->field_index = $display;
 678
 679                            if ( 'table' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] && !in_array( $options[ 'table_info' ][ 'pod' ][ 'type' ], array( 'pod', 'table' ) ) )
 680                                $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`";
 681                            else
 682                                $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
 683                        }
 684                    }
 685                    elseif ( isset( $options[ 'table_info' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'object_fields' ][ $display ] ) ) {
 686                        $search_data->field_index = $display;
 687
 688                        $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
 689                    }
 690                }
 691
 692                $autocomplete = false;
 693
 694                if ( 'single' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_single', $options ) )
 695                    $autocomplete = true;
 696                elseif ( 'multi' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_multi', $options ) )
 697                    $autocomplete = true;
 698
 699                if ( $autocomplete )
 700                    $params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', 30, $name, $value, $options, $pod, $id );
 701
 702                $results = $search_data->select( $params );
 703
 704                if ( !empty( $results ) && ( !$autocomplete || $search_data->total_found() <= $params[ 'limit' ] ) ) {
 705                    foreach ( $results as $result ) {
 706                        $result = get_object_vars( $result );
 707
 708                        $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] );
 709
 710                        if ( in_array( $options[ 'pick_object' ], array( 'site', 'network' ) ) )
 711                            $result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result[ 'path' ];
 712                        elseif ( strlen( $result[ $search_data->field_index ] ) < 1 )
 713                            $result[ $search_data->field_index ] = '(No Title)';
 714
 715                        $data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ];
 716                    }
 717                }
 718                elseif ( !empty( $value ) && $autocomplete && $params[ 'limit' ] < $search_data->total_found() ) {
 719                    $ids = $value;
 720
 721                    if ( is_array( $ids ) )
 722                        $ids = implode( ', ', $ids );
 723
 724                    if ( is_array( $params[ 'where' ] ) )
 725                        $params[ 'where' ] = implode( ' AND ', $params[ 'where' ] );
 726                    if ( !empty( $params[ 'where' ] ) )
 727                        $params[ 'where' ] .= ' AND ';
 728
 729                    $params[ 'where' ] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )";
 730
 731                    $results = $search_data->select( $params );
 732
 733                    if ( !empty( $results ) ) {
 734                        foreach ( $results as $result ) {
 735                            $result = get_object_vars( $result );
 736
 737                            $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] );
 738
 739                            if ( strlen( $result[ $search_data->field_index ] ) < 1 )
 740                                $result[ $search_data->field_index ] = '(No Title)';
 741
 742                            $data[ $result[ $search_data->field_id ] ] = $result[ $search_data->field_index ];
 743                        }
 744                    }
 745                }
 746            }
 747        }
 748
 749        $data = apply_filters( 'pods_field_pick_data', $data, $name, $value, $options, $pod, $id );
 750
 751        return $data;
 752    }
 753
 754    /**
 755     * Customize the Pods UI manage table column output
 756     *
 757     * @param int $id
 758     * @param mixed $value
 759     * @param string $name
 760     * @param array $options
 761     * @param array $fields
 762     * @param array $pod
 763     *
 764     * @since 2.0.0
 765     */
 766    public function ui ( $id, $value, $name = null, $options = null, $fields = null, $pod = null ) {
 767        $value = $this->simple_value( $value, $options );
 768
 769        return $this->display( $value, $name, $options, $pod, $id );
 770    }
 771
 772    /**
 773     * Convert a simple value to the correct value
 774     *
 775     * @param mixed $value Value of the field
 776     * @param array $options Field options
 777     * @param boolean $raw Whether to return the raw list of keys (true) or convert to key=>value (false)
 778     */
 779    public function simple_value ( $value, $options, $raw = false ) {
 780        if ( isset( $options[ 'options' ] ) ) {
 781            $options = array_merge( $options[ 'options' ], $options );
 782
 783            unset( $options[ 'options' ] );
 784        }
 785
 786        if ( in_array( pods_var( 'pick_object', $options ), self::simple_objects() ) ) {
 787            $data = array();
 788
 789            if ( 'custom-simple' == $options[ 'pick_object' ] ) {
 790                $custom = trim( pods_var_raw( 'pick_custom', $options, '' ) );
 791
 792                $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, pods_var( 'name', $options ), $value, $options, null, null );
 793
 794                if ( !empty( $custom ) ) {
 795                    if ( !is_array( $custom ) ) {
 796                        $custom = explode( "\n", $custom );
 797
 798                        foreach ( $custom as $custom_value ) {
 799                            $custom_label = explode( '|', $custom_value );
 800
 801                            if ( empty( $custom_label ) )
 802                                continue;
 803
 804                            if ( 1 == count( $custom_label ) )
 805                                $custom_label = $custom_value;
 806                            else {
 807                                $custom_value = $custom_label[ 0 ];
 808                                $custom_label = $custom_label[ 1 ];
 809                            }
 810
 811                            $data[ $custom_value ] = $custom_label;
 812                        }
 813                    }
 814                    else
 815                        $data = $custom;
 816                }
 817            }
 818            elseif ( 'post-status' == $options[ 'pick_object' ] ) {
 819                $post_stati = get_post_stati( array(), 'objects' );
 820
 821                foreach ( $post_stati as $post_status ) {
 822                    $data[ $post_status->name ] = $post_status->label;
 823                }
 824            }
 825            elseif ( 'role' == $options[ 'pick_object' ] ) {
 826                global $wp_roles;
 827
 828                foreach ( $wp_roles->role_objects as $key => $role ) {
 829                    $data[ $key ] = $wp_roles->role_names[ $key ];
 830                }
 831            }
 832            elseif ( 'sidebar' == $options[ 'pick_object' ] ) {
 833                global $wp_registered_sidebars;
 834
 835                if ( !empty( $wp_registered_sidebars ) ) {
 836                    foreach ( $wp_registered_sidebars as $sidebar ) {
 837                        $data[ $sidebar[ 'id' ] ] = $sidebar[ 'name' ];
 838                    }
 839                }
 840            }
 841            elseif ( 'image-size' == $options[ 'pick_object' ] ) {
 842                $image_sizes = get_intermediate_image_sizes();
 843
 844                foreach ( $image_sizes as $image_size ) {
 845                    $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) );
 846                }
 847            }
 848            elseif ( 'post-types' == $options[ 'pick_object' ] ) {
 849                $post_types = get_post_types( array(), 'objects' );
 850
 851                $ignore = array( 'revision', 'nav_menu_item' );
 852
 853                foreach ( $post_types as $post_type ) {
 854                    if ( in_array( $post_type->name, $ignore ) || 0 === strpos( $post_type->name, '_pods_' ) )
 855                        continue;
 856
 857                    $data[ $post_type->name ] = $post_type->label;
 858                }
 859            }
 860            elseif ( 'taxonomies' == $options[ 'pick_object' ] ) {
 861                $taxonomies = get_taxonomies( array(), 'objects' );
 862
 863                $ignore = array( 'nav_menu', 'post_format' );
 864
 865                foreach ( $taxonomies as $taxonomy ) {
 866                    if ( in_array( $taxonomy->name, $ignore ) )
 867                        continue;
 868
 869                    $data[ $taxonomy->name ] = $taxonomy->label;
 870                }
 871            }
 872            elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ] ) ) {
 873                if ( !empty( self::$related_objects[ $options[ 'pick_object' ][ 'data' ] ] ) )
 874                    $data = self::$related_objects[ $options[ 'pick_object' ] ][ 'data' ];
 875                elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ][ 'simple_value_callback' ] ) && is_callable( self::$related_objects[ $options[ 'pick_object' ] ][ 'simple_value_callback' ] ) ) {
 876                    $data = call_user_func_array(
 877                        self::$related_objects[ $options[ 'pick_object' ] ][ 'simple_value_callback' ],
 878                        array( compact( array( 'value', 'options', 'raw' ) ) )
 879                    );
 880                }
 881            }
 882
 883            $simple = false;
 884            $key = 0;
 885
 886            if ( !is_array( $value ) && !empty( $value ) )
 887                $simple = @json_decode( $value, true );
 888
 889            if ( is_array( $simple ) )
 890                $value = $simple;
 891
 892            if ( is_array( $value ) ) {
 893                if ( !empty( $data ) ) {
 894                    $val = array();
 895
 896                    foreach ( $value as $k => $v ) {
 897                        if ( isset( $data[ $v ] ) ) {
 898                            if ( false === $raw ) {
 899                                $k = $v;
 900                                $v = $data[ $v ];
 901                            }
 902
 903                            $val[ $k ] = $v;
 904                        }
 905                    }
 906
 907                    $value = $val;
 908                }
 909            }
 910            elseif ( isset( $data[ $value ] ) && false === $raw ) {
 911                $key = $value;
 912                $value = $data[ $value ];
 913            }
 914
 915            $single_multi = pods_var( 'pick_format_type', $options, 'single' );
 916
 917            if ( 'multi' == $single_multi )
 918                $limit = (int) pods_var( 'pick_limit', $options, 0 );
 919            else
 920                $limit = 1;
 921
 922            if ( is_array( $value ) && 0 < $limit ) {
 923                if ( 1 == $limit )
 924                    $value = current( $value );
 925                else
 926                    $value = array_slice( $value, 0, $limit, true );
 927            }
 928            elseif ( !is_array( $value ) && null !== $value && 0 < strlen( $value ) ) {
 929                if ( 1 != $limit || ( true === $raw && 'multi' == $single_multi ) ) {
 930                    $value = array(
 931                        $key => $value
 932                    );
 933                }
 934            }
 935        }
 936
 937        return $value;
 938    }
 939
 940    /**
 941     * Get the label from a pick value
 942     *
 943     * @param string|array $pod An array of Pod data or Pod name
 944     * @param string|array $field An array of field data or field name
 945     * @param string|array $value The value to return label(s) for
 946     *
 947     * @return string
 948     *
 949     * @since 2.2
 950     */
 951    public function value_to_label ( $pod, $field, $value ) {
 952        if ( !is_array( $pod ) && !empty( $pod ) )
 953            $pod = pods_api()->load_pod( array( 'name' => $pod ) );
 954
 955        if ( empty( $pod ) )
 956            return false;
 957
 958        if ( !is_array( $field ) && !empty( $field ) )
 959            $field = pods_api()->load_field( array( 'name' => $field, 'pod' => $pod[ 'name' ] ) );
 960
 961        if ( empty( $field ) )
 962            return false;
 963
 964        $options = array_merge( $field[ 'options' ], $field );
 965
 966        $custom = trim( pods_var_raw( 'pick_custom', $options, '' ) );
 967
 968        $custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field[ 'name' ], $value, $options, $pod, 0 );
 969
 970        $data = pods_var_raw( 'data', $options, array(), null, true );
 971
 972        if ( 'custom-simple' == pods_var( 'pick_object', $options ) && !empty( $custom ) ) {
 973            if ( !is_array( $custom ) ) {
 974                $custom = explode( "\n", $custom );
 975
 976                foreach ( $custom as $custom_value ) {
 977                    $custom_label = explode( '|', $custom_value );
 978
 979                    if ( empty( $custom_label ) )
 980                        continue;
 981
 982                    if ( 1 == count( $custom_label ) )
 983                        $custom_label = $custom_value;
 984                    else {
 985                        $custom_value = $custom_label[ 0 ];
 986                        $custom_label = $custom_label[ 1 ];
 987                    }
 988
 989                    if ( $value == $custom_value ) {
 990                        $data = $custom_label;
 991
 992                        break;
 993                    }
 994                }
 995            }
 996            else {
 997                foreach ( $custom as $custom_value => $custom_label ) {
 998                    if ( $value == $custom_value ) {
 999                        $data = $custom_label;
1000
1001                        break;
1002                    }
1003                }
1004            }
1005        }
1006        elseif ( '' != pods_var( 'pick_object', $options, '' ) && empty( $data ) ) {
1007            if ( 'post-status' == $options[ 'pick_object' ] ) {
1008                $post_stati = get_post_stati( array(), 'objects' );
1009
1010                foreach ( $post_stati as $post_status ) {
1011                    $data[ $post_status->name ] = $post_status->label;
1012                }
1013            }
1014            elseif ( 'role' == $options[ 'pick_object' ] ) {
1015                global $wp_roles;
1016
1017                foreach ( $wp_roles->role_objects as $key => $role ) {
1018                    $data[ $key ] = $wp_roles->role_names[ $key ];
1019                }
1020            }
1021            elseif ( 'sidebar' == $options[ 'pick_object' ] ) {
1022                global $wp_registered_sidebars;
1023
1024                if ( !empty( $wp_registered_sidebars ) ) {
1025                    foreach ( $wp_registered_sidebars as $sidebar ) {
1026                        $data[ $sidebar[ 'id' ] ] = $sidebar[ 'name' ];
1027                    }
1028                }
1029            }
1030            elseif ( 'image-size' == $options[ 'pick_object' ] ) {
1031                $image_sizes = get_intermediate_image_sizes();
1032
1033                foreach ( $image_sizes as $image_size ) {
1034                    $data[ $image_size ] = ucwords( str_replace( '-', ' ', $image_size ) );
1035                }
1036            }
1037            elseif ( 'post-types' == $options[ 'pick_object' ] ) {
1038                $post_types = get_post_types( array(), 'objects' );
1039
1040                $ignore = array( 'revision', 'nav_menu_item' );
1041
1042                foreach ( $post_types as $post_type ) {
1043                    if ( in_array( $post_type->name, $ignore ) || 0 === strpos( $post_type->name, '_pods_' ) )
1044                        continue;
1045
1046                    $data[ $post_type->name ] = $post_type->label;
1047                }
1048            }
1049            elseif ( 'taxonomies' == $options[ 'pick_object' ] ) {
1050                $taxonomies = get_taxonomies( array(), 'objects' );
1051
1052                $ignore = array( 'nav_menu', 'post_format' );
1053
1054                foreach ( $taxonomies as $taxonomy ) {
1055                    if ( in_array( $taxonomy->name, $ignore ) )
1056                        continue;
1057
1058                    $data[ $taxonomy->name ] = $taxonomy->label;
1059                }
1060            }
1061            elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ] ) ) {
1062                if ( !empty( self::$related_objects[ $options[ 'pick_object' ][ 'data' ] ] ) )
1063                    $data = self::$related_objects[ $options[ 'pick_object' ] ][ 'data' ];
1064                elseif ( isset( self::$related_objects[ $options[ 'pick_object' ] ][ 'value_to_label_callback' ] ) && is_callable( self::$related_objects[ $options[ 'pick_object' ] ][ 'value_to_label_callback' ] ) ) {
1065                    $data = call_user_func_array(
1066                        self::$related_objects[ $options[ 'pick_object' ] ][ 'value_to_label_callback' ],
1067                        array( compact( array( 'pod', 'field', 'value' ) ) )
1068                    );
1069                }
1070            }
1071            else {
1072                $pick_val = pods_var( 'pick_val', $options );
1073
1074                if ( 'table' == pods_var( 'pick_object', $options ) )
1075                    $pick_val = pods_var( 'pick_table', $options, $pick_val, null, true );
1076
1077                $options[ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $options ), $pick_val, null, null, $options );
1078
1079                $search_data = pods_data();
1080                $search_data->table = $options[ 'table_info' ][ 'table' ];
1081                $search_data->join = $options[ 'table_info' ][ 'join' ];
1082                $search_data->field_id = $options[ 'table_info' ][ 'field_id' ];
1083                $search_data->field_index = $options[ 'table_info' ][ 'field_index' ];
1084                $search_data->where = $options[ 'table_info' ][ 'where' ];
1085                $search_data->orderby = $options[ 'table_info' ][ 'orderby' ];
1086
1087                if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
1088                    $search_data->pod = $options[ 'table_info' ][ 'pod' ][ 'name' ];
1089                    $search_data->fields = $options[ 'table_info' ][ 'pod' ][ 'fields' ];
1090                }
1091
1092                $params = array(
1093                    'select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`",
1094                    'table' => $search_data->table,
1095                    'where' => pods_var_raw( 'pick_where', $options, (array) $options[ 'table_info' ][ 'where_default' ], null, true ),
1096                    'orderby' => pods_var_raw( 'pick_orderby', $options, null, null, true ),
1097                    'groupby' => pods_var_raw( 'pick_groupby', $options, null, null, true )
1098                );
1099
1100                if ( in_array( $options[ 'pick_object' ], array( 'site', 'network' ) ) )
1101                    $params[ 'select' ] .= ', `t`.`path`';
1102
1103                if ( !empty( $params[ 'where' ] ) && (array) $options[ 'table_info' ][ 'where_default' ] != $params[ 'where' ] )
1104                    $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ], true );
1105
1106                if ( empty( $params[ 'where' ] ) )
1107                    $params[ 'where' ] = array();
1108
1109                if ( !is_array( $params[ 'where' ] ) )
1110                    $params[ 'where' ] = (array) $params[ 'where' ];
1111
1112                $params[ 'where' ][] = "`t`.`{$search_data->field_id}` = " . number_format( $value, 0, '', '' );
1113
1114                /* not needed yet
1115                if ( !empty( $params[ 'orderby' ] ) )
1116                    $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true );
1117
1118                if ( !empty( $params[ 'groupby' ] ) )
1119                    $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/
1120
1121                $display = trim( pods_var( 'pick_display', $options ), ' {@}' );
1122
1123                if ( 0 < strlen( $display ) ) {
1124                    if ( isset( $options[ 'table_info' ][ 'pod' ] ) && !empty( $options[ 'table_info' ][ 'pod' ] ) ) {
1125                        if ( isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'pod' ][ 'object_fields' ][ $display ] ) ) {
1126                            $search_data->field_index = $display;
1127
1128                            $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1129                        }
1130                        elseif ( isset( $options[ 'table_info' ][ 'pod' ][ 'fields' ][ $display ] ) ) {
1131                            $search_data->field_index = $display;
1132
1133                            if ( 'table' == $options[ 'table_info' ][ 'pod' ][ 'storage' ] && !in_array( $options[ 'table_info' ][ 'pod' ][ 'type' ], array( 'pod', 'table' ) ) )
1134                                $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`";
1135                            else
1136                                $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1137                        }
1138                    }
1139                    elseif ( isset( $options[ 'table_info' ][ 'object_fields' ] ) && isset( $options[ 'table_info' ][ 'object_fields' ][ $display ] ) ) {
1140                        $search_data->field_index = $display;
1141
1142                        $params[ 'select' ] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
1143                    }
1144                }
1145
1146                $autocomplete = false;
1147
1148                if ( 'single' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_single', $options ) )
1149                    $autocomplete = true;
1150                elseif ( 'multi' == pods_var( 'pick_format_type', $options ) && 'autocomplete' == pods_var( 'pick_format_multi', $options ) )
1151                    $autocomplete = true;
1152
1153                if ( $autocomplete )
1154                    $params[ 'limit' ] = apply_filters( 'pods_form_ui_field_pick_autocomplete_limit', 30, $field[ 'name' ], $value, $options, $pod, 0 );
1155
1156                $results = $search_data->select( $params );
1157
1158                if ( !empty( $results ) && ( !$autocomplete || $search_data->total_found() <= $params[ 'limit' ] ) ) {
1159                    foreach ( $results as $result ) {
1160                        $result = get_object_vars( $result );
1161
1162                        $result[ $search_data->field_index ] = trim( $result[ $search_data->field_index ] );
1163
1164                        if ( in_array( $options[ 'pick_object' ], array( 'site', 'network' ) ) )
1165                            $result[ $search_data->field_index ] = $result[ $search_data->field_index ] . $result[ 'path' ];
1166                        elseif ( strlen( $result[ $search_data->field_index ] ) < 1 )
1167                            $result[ $search_data->field_index ] = '(No Title)';
1168
1169                        $data = $result[ $search_data->field_index ];
1170                    }
1171                }
1172                elseif ( !empty( $value ) && $autocomplete && $params[ 'limit' ] < $search_data->total_found() ) {
1173                    $ids = $value;
1174
1175                    if ( is_array( $ids ) )
1176                        $ids = implode( ', ', $ids );
1177
1178                    if ( is_array( $params[ 'where' ] ) )
1179                        $params[ 'where' ] = implode( ' AND ', $params[ 'where' ] );
1180                    if ( !empty( $params[ 'where' ] ) )
1181                        $params[ 'where' ] .= ' AND ';
1182
1183                    $params[ 'where' ] .= "`t`.`{$search_data->field_id}

Large files files are truncated, but you can click here to view the full file