PodsAdmin::admin_setup PHP Method

admin_setup() public method

Handle main Pods Setup area for managing Pods and Fields
public admin_setup ( )
    public function admin_setup()
    {
        $pods = pods_api()->load_pods(array('fields' => false));
        $view = pods_var('view', 'get', 'all', null, true);
        if (empty($pods) && !isset($_GET['action'])) {
            $_GET['action'] = 'add';
        }
        if ('pods-add-new' == $_GET['page']) {
            if (isset($_GET['action']) && 'add' != $_GET['action']) {
                pods_redirect(pods_query_arg(array('page' => 'pods', 'action' => $_GET['action'])));
            } else {
                $_GET['action'] = 'add';
            }
        } elseif (isset($_GET['action']) && 'add' == $_GET['action']) {
            pods_redirect(pods_query_arg(array('page' => 'pods-add-new', 'action' => '')));
        }
        $types = array('post_type' => __('Post Type (extended)', 'pods'), 'taxonomy' => __('Taxonomy (extended)', 'pods'), 'cpt' => __('Custom Post Type', 'pods'), 'ct' => __('Custom Taxonomy', 'pods'), 'user' => __('User (extended)', 'pods'), 'media' => __('Media (extended)', 'pods'), 'comment' => __('Comments (extended)', 'pods'), 'pod' => __('Advanced Content Type', 'pods'), 'settings' => __('Custom Settings Page', 'pods'));
        $row = false;
        $pod_types_found = array();
        $fields = array('label' => array('label' => __('Label', 'pods')), 'name' => array('label' => __('Name', 'pods')), 'type' => array('label' => __('Type', 'pods')), 'storage' => array('label' => __('Storage Type', 'pods'), 'width' => '10%'), 'field_count' => array('label' => __('Number of Fields', 'pods'), 'width' => '8%'));
        $total_fields = 0;
        foreach ($pods as $k => $pod) {
            if (isset($types[$pod['type']])) {
                if (in_array($pod['type'], array('post_type', 'taxonomy'))) {
                    if (empty($pod['object'])) {
                        if ('post_type' == $pod['type']) {
                            $pod['type'] = 'cpt';
                        } else {
                            $pod['type'] = 'ct';
                        }
                    }
                }
                if (!isset($pod_types_found[$pod['type']])) {
                    $pod_types_found[$pod['type']] = 1;
                } else {
                    $pod_types_found[$pod['type']]++;
                }
                if ('all' != $view && $view != $pod['type']) {
                    unset($pods[$k]);
                    continue;
                }
                $pod['real_type'] = $pod['type'];
                $pod['type'] = $types[$pod['type']];
            } elseif ('all' != $view) {
                continue;
            }
            $pod['storage'] = ucwords($pod['storage']);
            if ($pod['id'] == pods_var('id') && 'delete' != pods_var('action')) {
                $row = $pod;
            }
            $pod = array('id' => $pod['id'], 'label' => pods_var_raw('label', $pod), 'name' => pods_var_raw('name', $pod), 'object' => pods_var_raw('object', $pod), 'type' => pods_var_raw('type', $pod), 'real_type' => pods_var_raw('real_type', $pod), 'storage' => pods_var_raw('storage', $pod), 'field_count' => count($pod['fields']));
            $total_fields += $pod['field_count'];
            $pods[$k] = $pod;
        }
        if (false === $row && 0 < pods_var('id') && 'delete' != pods_var('action')) {
            pods_message('Pod not found', 'error');
            unset($_GET['id']);
            unset($_GET['action']);
        }
        $ui = array('data' => $pods, 'row' => $row, 'total' => count($pods), 'total_found' => count($pods), 'items' => 'Pods', 'item' => 'Pod', 'fields' => array('manage' => $fields), 'actions_disabled' => array('view', 'export'), 'actions_custom' => array('add' => array($this, 'admin_setup_add'), 'edit' => array($this, 'admin_setup_edit'), 'duplicate' => array('callback' => array($this, 'admin_setup_duplicate'), 'restrict_callback' => array($this, 'admin_setup_duplicate_restrict')), 'reset' => array('label' => __('Delete All Items', 'pods'), 'confirm' => __('Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods'), 'callback' => array($this, 'admin_setup_reset'), 'restrict_callback' => array($this, 'admin_setup_reset_restrict'), 'nonce' => true), 'delete' => array($this, 'admin_setup_delete')), 'action_links' => array('add' => pods_query_arg(array('page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => ''))), 'search' => false, 'searchable' => false, 'sortable' => true, 'pagination' => false, 'extra' => array('total' => ', ' . number_format_i18n($total_fields) . ' ' . _n('field', 'fields', $total_fields, 'pods')));
        if (1 < count($pod_types_found)) {
            $ui['views'] = array('all' => __('All', 'pods'));
            $ui['view'] = $view;
            $ui['heading'] = array('views' => __('Type', 'pods'));
            $ui['filters_enhanced'] = true;
            foreach ($pod_types_found as $pod_type => $number_found) {
                $ui['views'][$pod_type] = $types[$pod_type];
            }
        }
        pods_ui($ui);
    }