PodsUI::setup PHP Method

setup() public method

public setup ( $options ) : array | boolean | mixed | null | PodsArray
$options
return array | boolean | mixed | null | PodsArray
    public function setup($options)
    {
        $options = pods_array($options);
        $options->validate('num', '', 'absint');
        if (empty($options->num)) {
            $options->num = '';
        }
        $options->validate('id', pods_var('id' . $options->num, 'get', $this->id));
        $options->validate('do', pods_var('do' . $options->num, 'get', $this->do), 'in_array', array('save', 'create'));
        $options->validate('excluded', self::$excluded, 'array_merge');
        $options->validate('action', pods_var('action' . $options->num, 'get', $this->action, null, true), 'in_array', $this->actions);
        $options->validate('actions_bulk', $this->actions_bulk, 'array_merge');
        $options->validate('action_bulk', pods_var('action_bulk' . $options->num, 'get', $this->action_bulk, null, true), 'isset', $this->actions_bulk);
        $bulk = pods_var('action_bulk_ids' . $options->num, 'get', array(), null, true);
        if (!empty($bulk)) {
            $bulk = (array) pods_var('action_bulk_ids' . $options->num, 'get', array(), null, true);
        } else {
            $bulk = array();
        }
        $options->validate('bulk', $bulk, 'array_merge', $this->bulk);
        $options->validate('views', $this->views, 'array');
        $options->validate('view', pods_var('view' . $options->num, 'get', $this->view, null, true), 'isset', $this->views);
        $options->validate('searchable', $this->searchable, 'boolean');
        $options->validate('search', pods_var('search' . $options->num, 'get'));
        $options->validate('search_across', $this->search_across, 'boolean');
        $options->validate('search_across_picks', $this->search_across_picks, 'boolean');
        $options->validate('filters', $this->filters, 'array');
        $options->validate('filters_enhanced', $this->filters_enhanced, 'boolean');
        $options->validate('where', $this->where, 'array_merge');
        $options->validate('pagination', $this->pagination, 'boolean');
        $options->validate('page', pods_var('pg' . $options->num, 'get', $this->page), 'absint');
        $options->validate('limit', pods_var('limit' . $options->num, 'get', $this->limit), 'int');
        if (isset($this->pods_data) && is_object($this->pods_data)) {
            $this->sql = array('table' => $this->pods_data->table, 'field_id' => $this->pods_data->field_id, 'field_index' => $this->pods_data->field_index);
        }
        $options->validate('sql', $this->sql, 'array_merge');
        $options->validate('orderby_dir', strtoupper(pods_v('orderby_dir' . $options['num'], 'get', $this->orderby_dir, true)), 'in_array', array('ASC', 'DESC'));
        $orderby = $this->orderby;
        // Enforce strict DB column name usage
        if (!empty($_GET['orderby' . $options->num])) {
            $orderby = pods_clean_name($_GET['orderby' . $options->num], true, false);
        }
        if (!empty($orderby)) {
            $orderby = array('default' => $orderby);
        } else {
            $orderby = array();
        }
        $options->validate('orderby', $orderby, 'array_merge');
        $options->validate('sortable', $this->sortable, 'boolean');
        $options->validate('params', $this->params, 'array');
        $options->validate('restrict', $this->restrict, 'array_merge');
        // handle author restrictions
        if (!empty($options['restrict']['author_restrict'])) {
            $restrict = $options['restrict'];
            if (!is_array($restrict['author_restrict'])) {
                $restrict['author_restrict'] = array($restrict['author_restrict'] => get_current_user_id());
            }
            if (null === $restrict['edit']) {
                $restrict['edit'] = $restrict['author_restrict'];
            }
            $options->restrict = $restrict;
        }
        if (null !== $options['restrict']['edit']) {
            $restrict = $options['restrict'];
            if (null === $restrict['duplicate']) {
                $restrict['duplicate'] = $restrict['edit'];
            }
            if (null === $restrict['delete']) {
                $restrict['delete'] = $restrict['edit'];
            }
            if (null === $restrict['manage']) {
                $restrict['manage'] = $restrict['edit'];
            }
            if (null === $restrict['reorder']) {
                $restrict['reorder'] = $restrict['edit'];
            }
            $options->restrict = $restrict;
        }
        $item = __('Item', 'pods');
        $items = __('Items', 'pods');
        if (is_object($this->pod)) {
            $item = pods_var_raw('label_singular', $this->pod->pod_data['options'], pods_var_raw('label', $this->pod->pod_data, $item, null, true), null, true);
            $items = pods_var_raw('label', $this->pod->pod_data, $items, null, true);
        }
        $options->validate('item', $item);
        $options->validate('items', $items);
        $options->validate('heading', array('manage' => __('Manage', 'pods'), 'add' => __('Add New', 'pods'), 'edit' => __('Edit', 'pods'), 'duplicate' => __('Duplicate', 'pods'), 'view' => __('View', 'pods'), 'reorder' => __('Reorder', 'pods'), 'search' => __('Search', 'pods'), 'views' => __('View', 'pods')), 'array_merge');
        $options->validate('header', array('manage' => sprintf(__('Manage %s', 'pods'), $options->items), 'add' => sprintf(__('Add New %s', 'pods'), $options->item), 'edit' => sprintf(__('Edit %s', 'pods'), $options->item), 'duplicate' => sprintf(__('Duplicate %s', 'pods'), $options->item), 'view' => sprintf(__('View %s', 'pods'), $options->item), 'reorder' => sprintf(__('Reorder %s', 'pods'), $options->items), 'search' => sprintf(__('Search %s', 'pods'), $options->items)), 'array_merge');
        $options->validate('label', array('add' => sprintf(__('Save New %s', 'pods'), $options->item), 'add_new' => __('Add New', 'pods'), 'edit' => sprintf(__('Save %s', 'pods'), $options->item), 'duplicate' => sprintf(__('Save New %s', 'pods'), $options->item), 'delete' => sprintf(__('Delete this %s', 'pods'), $options->item), 'view' => sprintf(__('View %s', 'pods'), $options->item), 'reorder' => sprintf(__('Reorder %s', 'pods'), $options->items)), 'array_merge');
        $options->validate('fields', array('manage' => array($options->sql['field_index'] => array('label' => __('Name', 'pods')))), 'array');
        $options->validate('export', $this->export, 'array_merge');
        $options->validate('reorder', $this->reorder, 'array_merge');
        $options->validate('screen_options', $this->screen_options, 'array_merge');
        $options->validate('session', $this->session, 'in_array', array('search', 'filters', 'show_per_page', 'orderby'));
        $options->validate('user', $this->user, 'in_array', array('search', 'filters', 'show_per_page', 'orderby'));
        $options->validate('action_after', $this->action_after, 'array_merge');
        $options->validate('action_links', $this->action_links, 'array_merge');
        $options->validate('actions_disabled', $this->actions_disabled, 'array');
        $options->validate('actions_hidden', $this->actions_hidden, 'array_merge');
        $options->validate('actions_custom', $this->actions_custom, 'array_merge');
        if (!empty($options->actions_disabled)) {
            if (!empty($options->actions_bulk)) {
                $actions_bulk = $options->actions_bulk;
                foreach ($actions_bulk as $action => $action_opt) {
                    if (in_array($action, $options->actions_disabled)) {
                        unset($actions_bulk[$action]);
                    }
                }
                $options->actions_bulk = $actions_bulk;
            }
            if (!empty($options->actions_custom)) {
                $actions_custom = $options->actions_custom;
                foreach ($actions_custom as $action => $action_opt) {
                    if (in_array($action, $options->actions_disabled)) {
                        unset($actions_custom[$action]);
                    }
                }
                $options->actions_custom = $actions_custom;
            }
        }
        $options->validate('extra', $this->extra, 'array_merge');
        $options->validate('style', $this->style);
        $options->validate('icon', $this->icon);
        $options->validate('css', $this->css);
        $options->validate('wpcss', $this->wpcss, 'boolean');
        if (true === $options['wpcss']) {
            global $user_ID;
            wp_get_current_user();
            $color = get_user_meta($user_ID, 'admin_color', true);
            if (strlen($color) < 1) {
                $color = 'fresh';
            }
            $this->wpcss = "colors-{$color}";
        }
        $options = $options->dump();
        if (is_object($this->pod)) {
            $options = $this->do_hook($this->pod->pod . '_setup_options', $options);
        }
        $options = $this->do_hook('setup_options', $options);
        if (false !== $options && !empty($options)) {
            foreach ($options as $option => $value) {
                if (isset($this->{$option})) {
                    $this->{$option} = $value;
                } else {
                    $this->x[$option] = $value;
                }
            }
        }
        $unique_identifier = pods_var('page', 'get');
        // wp-admin page
        if (is_object($this->pod) && isset($this->pod->pod)) {
            $unique_identifier = '_' . $this->pod->pod;
        } elseif (0 < strlen($this->sql['table'])) {
            $unique_identifier = '_' . $this->sql['table'];
        }
        $unique_identifier .= '_' . $this->page;
        if (0 < strlen($this->num)) {
            $unique_identifier .= '_' . $this->num;
        }
        $this->unique_identifier = 'pods_ui_' . md5($unique_identifier);
        $this->setup_fields();
        return $options;
    }