/** * Build admin area * * @param $options * @param $component * * @return void * @since 2.0 */ public function admin($options, $component) { global $wp_roles; // Hook into Gravity Forms roles (since it only adds filter if Members plugin itself is activated if (class_exists('RGForms') && !has_filter('members_get_capabilities', array('RGForms', 'members_get_capabilities'))) { add_filter('members_get_capabilities', array('RGForms', 'members_get_capabilities')); } $default_role = get_option('default_role'); $roles = array(); foreach ($wp_roles->role_objects as $key => $role) { $count = $this->count_users($key); $roles[$key] = array('id' => $key, 'label' => $wp_roles->role_names[$key], 'name' => $key, 'capabilities' => count((array) $role->capabilities), 'users' => sprintf(_n('%s User', '%s Users', $count, 'pods'), $count)); if ($default_role == $key) { $roles[$key]['label'] .= ' (site default)'; } if (0 < $count && pods_is_admin(array('list_users'))) { $roles[$key]['users'] .= '<br /><a href="' . admin_url(esc_url('users.php?role=' . $key)) . '">' . __('View Users', 'pods') . '</a>'; } } $ui = array('component' => $component, 'data' => $roles, 'total' => count($roles), 'total_found' => count($roles), 'icon' => PODS_URL . 'ui/images/icon32.png', 'items' => 'Roles', 'item' => 'Role', 'fields' => array('manage' => array('label' => array('label' => __('Label', 'pods')), 'name' => array('label' => __('Name', 'pods')), 'capabilities' => array('label' => __('Capabilities', 'pods')), 'users' => array('label' => __('Users', 'pods'), 'type' => 'text', 'options' => array('text_allow_html' => 1, 'text_allowed_html_tags' => '')))), 'actions_disabled' => array('duplicate', 'view', 'export'), 'actions_custom' => array('add' => array($this, 'admin_add'), 'edit' => array($this, 'admin_edit'), 'delete' => array($this, 'admin_delete')), 'search' => false, 'searchable' => false, 'sortable' => false, 'pagination' => false); if (isset($roles[pods_var('id', 'get', -1)])) { $ui['row'] = $roles[pods_var('id', 'get', -1)]; } if (!pods_is_admin(array('pods_roles_add'))) { $ui['actions_disabled'][] = 'add'; } if (!pods_is_admin(array('pods_roles_edit'))) { $ui['actions_disabled'][] = 'edit'; } if (count($roles) < 2 || !pods_is_admin(array('pods_roles_delete'))) { $ui['actions_disabled'][] = 'delete'; } pods_ui($ui); }
/** * Output admin page */ public static function admin_page() { include_once 'Pods_Jobs_Queue_API.php'; /** * @var $wpdb wpdb */ global $wpdb; $table = Pods_Jobs_Queue_API::table(); Pods_Jobs_Queue_API::install(); $ui = array('item' => __('Job', 'pods-jobs-queue'), 'items' => __('Jobs', 'pods-jobs-queue'), 'header' => array('view' => __('View Job Info', 'pods-jobs-queue')), 'sql' => array('table' => $table, 'field_id' => 'id', 'field_index' => 'callback'), 'orderby' => '( `t`.`status` = "queued" ) DESC, ( `t`.`status` = "completed" ) DESC, `t`.`date_queued` DESC, `t`.`date_completed` DESC', 'fields' => array('manage' => array('callback' => array('name' => 'callback', 'label' => 'Callback', 'type' => 'text'), 'group' => array('name' => 'group', 'label' => 'Group', 'type' => 'text'), 'memo' => array('name' => 'memo', 'label' => 'Memo', 'type' => 'text'), 'status' => array('name' => 'status', 'label' => 'Status', 'type' => 'pick', 'pick_object' => 'custom-simple', 'data' => array('queued' => __('Queued', 'pods-jobs-queue'), 'processing' => __('Processing', 'pods-jobs-queue'), 'completed' => __('Completed', 'pods-jobs-queue'), 'failed' => __('Failed', 'pods-jobs-queue'))), 'date_queued' => array('name' => 'date_queued', 'label' => 'Time Queued', 'type' => 'datetime', 'options' => array('datetime_allow_empty' => 1)), 'date_started' => array('name' => 'date_started', 'label' => 'Time Started', 'type' => 'datetime', 'options' => array('datetime_allow_empty' => 1)), 'date_completed' => array('name' => 'date_completed', 'label' => 'Time Completed', 'type' => 'datetime', 'options' => array('datetime_allow_empty' => 1))), 'search' => array()), 'filters' => array('callback', 'memo', 'group', 'status', 'date_queued', 'date_started', 'date_completed'), 'filters_enhanced' => true, 'actions_disabled' => array('add', 'edit', 'duplicate', 'export'), 'actions_custom' => array('process_job' => array('callback' => array(__CLASS__, 'admin_page_process_job')), 'view' => array('callback' => array(__CLASS__, 'admin_page_view_job')), 'delete' => array('callback' => array(__CLASS__, 'admin_page_delete_job'))), 'actions_bulk' => array('delete' => array('label' => __('Delete', 'pods')), 'process_jobs' => array('callback' => array(__CLASS__, 'admin_page_process_jobs')))); $ui['fields']['search']['callback'] = $ui['fields']['manage']['callback']; $ui['fields']['search']['memo'] = $ui['fields']['manage']['memo']; $ui['fields']['search']['group'] = $ui['fields']['manage']['group']; $ui['fields']['search']['status'] = $ui['fields']['manage']['status']; $ui['fields']['search']['date_queued'] = $ui['fields']['manage']['date_queued']; $ui['fields']['search']['date_started'] = $ui['fields']['manage']['date_started']; $ui['fields']['search']['date_completed'] = $ui['fields']['manage']['date_completed']; $ui['fields']['view'] = $ui['fields']['manage']; unset($ui['fields']['view']['callback']); $ui['fields']['view']['arguments'] = array('name' => 'arguments', 'label' => 'Callback Arguments', 'type' => 'paragraph'); $ui['fields']['view']['log'] = array('name' => 'log', 'label' => 'Callback Log', 'type' => 'text'); $ui['fields']['view']['blog_id'] = array('name' => 'blog_id', 'label' => 'Blog ID', 'type' => 'number', 'options' => array('number_format_type' => '9999.99', 'number_decimals' => 0), 'width' => '5%'); if (!defined('PODS_JOBS_QUEUE_GROUPS') || !PODS_JOBS_QUEUE_GROUPS) { unset($ui['fields']['manage']['group']); unset($ui['fields']['manage']['search']); unset($ui['fields']['manage']['view']); unset($ui['filters'][array_search('group', $ui['filters'])]); } if (1 == pods_v('deleted_bulk')) { unset($ui['actions_custom']['delete']); } pods_ui($ui); }
/** * Get components administration UI */ public function admin_components() { $components = PodsInit::$components->components; $view = pods_var('view', 'get', 'all', null, true); $recommended = array('advanced-relationships', 'advanced-content-types', 'migrate-packages', 'roles-and-capabilities', 'pages', 'table-storage', 'templates'); foreach ($components as $component => &$component_data) { if (!in_array($view, array('all', 'recommended', 'dev')) && (!isset($component_data['Category']) || $view != sanitize_title($component_data['Category']))) { unset($components[$component]); continue; } elseif ('recommended' == $view && !in_array($component_data['ID'], $recommended)) { unset($components[$component]); continue; } elseif ('dev' == $view && pods_developer() && !pods_var_raw('DeveloperMode', $component_data, false)) { unset($components[$component]); continue; } elseif (pods_var_raw('DeveloperMode', $component_data, false) && !pods_developer()) { unset($components[$component]); continue; } elseif (!pods_var_raw('TablelessMode', $component_data, false) && pods_tableless()) { unset($components[$component]); continue; } $component_data['Name'] = strip_tags($component_data['Name']); if (pods_var_raw('DeveloperMode', $component_data, false)) { $component_data['Name'] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>'; } $meta = array(); if (!empty($component_data['Version'])) { $meta[] = 'Version ' . $component_data['Version']; } if (empty($component_data['Author'])) { $component_data['Author'] = 'Pods Framework Team'; $component_data['AuthorURI'] = 'http://pods.io/'; } if (!empty($component_data['AuthorURI'])) { $component_data['Author'] = '<a href="' . $component_data['AuthorURI'] . '">' . $component_data['Author'] . '</a>'; } $meta[] = sprintf(__('by %s', 'pods'), $component_data['Author']); if (!empty($component_data['URI'])) { $meta[] = '<a href="' . $component_data['URI'] . '">' . __('Visit component site', 'pods') . '</a>'; } $component_data['Description'] = wpautop(trim(make_clickable(strip_tags($component_data['Description'], 'em,strong')))); if (!empty($meta)) { $component_data['Description'] .= '<div class="pods-component-meta" ' . (!empty($component_data['Description']) ? ' style="padding:8px 0 4px;"' : '') . '>' . implode(' | ', $meta) . '</div>'; } $component_data = array('id' => $component_data['ID'], 'name' => $component_data['Name'], 'category' => $component_data['Category'], 'version' => '', 'description' => $component_data['Description'], 'mustuse' => pods_var_raw('MustUse', $component_data, false), 'toggle' => 0); if (!empty($component_data['category'])) { $category_url = pods_var_update(array('view' => sanitize_title($component_data['category']), 'pg' => '', 'page' => $_GET['page'])); $component_data['category'] = '<a href="' . $category_url . '">' . $component_data['category'] . '</a>'; } if (isset(PodsInit::$components->settings['components'][$component_data['id']]) && 0 != PodsInit::$components->settings['components'][$component_data['id']]) { $component_data['toggle'] = 1; } elseif ($component_data['mustuse']) { $component_data['toggle'] = 1; } } $ui = array('data' => $components, 'total' => count($components), 'total_found' => count($components), 'icon' => PODS_URL . 'ui/images/icon32.png', 'items' => 'Components', 'item' => 'Component', 'fields' => array('manage' => array('name' => array('label' => __('Name', 'pods'), 'width' => '30%', 'type' => 'text', 'options' => array('text_allow_html' => true)), 'category' => array('label' => __('Category', 'pods'), 'width' => '10%', 'type' => 'text', 'options' => array('text_allow_html' => true)), 'description' => array('label' => __('Description', 'pods'), 'width' => '60%', 'type' => 'text', 'options' => array('text_allow_html' => true, 'text_allowed_html_tags' => 'strong em a ul ol li b i br div')))), 'actions_disabled' => array('duplicate', 'view', 'export', 'add', 'edit', 'delete'), 'actions_custom' => array('toggle' => array('callback' => array($this, 'admin_components_toggle'))), 'filters_enhanced' => true, 'views' => array('all' => __('All', 'pods'), 'field-types' => __('Field Types', 'pods'), 'tools' => __('Tools', 'pods'), 'integration' => __('Integration', 'pods'), 'migration' => __('Migration', 'pods'), 'advanced' => __('Advanced', 'pods')), 'view' => $view, 'heading' => array('views' => __('Category', 'pods')), 'search' => false, 'searchable' => false, 'sortable' => false, 'pagination' => false); if (pods_developer()) { $ui['views']['dev'] = __('Developer Preview', 'pods'); } pods_ui($ui); }
/** * Include and Init the PodsUI class * * @since 2.0 * @deprecated deprecated since version 2.0 */ function pods_ui_manage($obj) { pods_deprecated('pods_ui_manage', '2.0', 'pods_ui'); return pods_ui($obj, true); }
<?php /** * Pass an array to pods_ui() with the name of the Pod in the 'pod' key */ $ui = array('pod' => 'yourpod', 'title' => 'My Pod', 'add_fields' => array('name', 'body'), 'edit_fields' => array('name', 'body', 'approved')); pods_ui($ui); /** * Pass an array to pods_ui() with a Pods object as the 'pod' key */ $object = pods('yourpod'); $ui = array('pod' => $object, 'title' => 'My Pod', 'add_fields' => array('name', 'body'), 'edit_fields' => array('name', 'body', 'approved')); pods_ui($ui); /** * Pass a Pods object to pods_ui(); you can set the Pods->ui array directly on the Pods object */ $object = pods('yourpod'); $object->ui = array('title' => 'My Pod', 'add_fields' => array('name', 'body'), 'edit_fields' => array('name', 'body', 'approved')); pods_ui($object); /** * Pass a Pods object to pods_ui(); you can set the Pods->ui array directly on the Pods object */ pods_ui('pod=yourpod&title=My%20Pod&add_fields=name,body&edit_fields=name,body,approved'); /** * All args in one line */ pods_ui('pod=yourpod&title=My%20Pod');
/** * * Generate UI for Data Management * * @param mixed $options Array or String containing Pod or Options to be used * @param bool $amend Whether to amend the default UI options or replace entirely * * @return PodsUI|void UI object or void if custom UI used * * @since 2.3.10 */ public function ui($options = null, $amend = false) { $num = ''; if (empty($options)) { $options = array(); } else { $num = pods_var('num', $options, ''); if (empty($num)) { $num = ''; } } if ($this->id() != pods_var('id' . $num, 'get', null, null, true)) { $this->fetch(pods_var('id' . $num, 'get', null, null, true)); } if (!empty($options) && !$amend) { $this->ui = $options; return pods_ui($this); } elseif (!empty($options) || 'custom' != pods_var('ui_style', $this->pod_data['options'], 'post_type', null, true)) { $actions_enabled = pods_var_raw('ui_actions_enabled', $this->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $this->pod_data['options'], 0)) { unset($actions_disabled['export']); } } if (empty($options)) { $author_restrict = false; if (isset($this->fields['author']) && 'pick' == $this->fields['author']['type'] && 'user' == $this->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $this->pod)) { $actions_disabled['add'] = 'add'; if ('add' == pods_var('action' . $num, 'get')) { $_GET['action' . $num] = 'manage'; } } if (!$author_restrict && !current_user_can('pods_edit_' . $this->pod) && !current_user_can('pods_edit_others_' . $this->pod)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $this->pod) && !current_user_can('pods_delete_others_' . $this->pod)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $this->pod)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $this->pod)) { $actions_disabled['export'] = 'export'; } } } $_GET['action' . $num] = pods_var('action' . $num, 'get', pods_var('action', $options, 'manage')); $index = $this->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($this->pod_data['fields'][$this->pod_data['field_index']])) { $index = $this->pod_data['field_index']; $label = $this->pod_data['fields'][$this->pod_data['field_index']]; } $manage = array($index => $label); if (isset($this->pod_data['fields']['modified'])) { $manage['modified'] = $this->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $this->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($this->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['fields'][$manage_field]; } elseif (isset($this->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $this->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $this->pod, apply_filters('pods_admin_ui_fields', $manage, $this->pod, $this), $this->pod, $this); $icon = pods_var_raw('ui_icon', $this->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $this->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($this->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['fields'][$filter_field]; } elseif (isset($this->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('fields' => array('manage' => $manage, 'add' => $this->pod_data['fields'], 'edit' => $this->pod_data['fields'], 'duplicate' => $this->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $this->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($this->pod_data['object_fields']) && isset($this->pod_data['object_fields'][$reorder_field]) || isset($this->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } $detail_url = pods_var('detail_url', $this->pod_data['options']); if (0 < strlen($detail_url)) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . $detail_url)); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $this->pod, apply_filters('pods_admin_ui', $ui, $this->pod, $this), $this->pod, $this); // Override UI options foreach ($options as $option => $value) { $ui[$option] = $value; } $this->ui = $ui; return pods_ui($this); } do_action('pods_admin_ui_custom', $this); do_action('pods_admin_ui_custom_' . $this->pod, $this); }
<?php /* * Customizing the fields on various content management screens Programmatically exclude or customize the fields listed on the add, edit, and manage ui screens * * See: http://lowgravity.pl/blog/introduction-to-podscms-2-0-part-2-pods_ui-parameters/ */ $object = pods('name_of_pod'); $fields = array(); // iterate through the fields in this pod foreach ($object->fields as $field => $data) { $fields[$field] = array('label' => $data['label']); } // exclude a specific field by field name unset($fields['field_name']); // customize the label for a particular field $fields['field_name'] = array('label' => 'some_different_label'); // hide some fields on edit screen but still have them on the add screen $edit_fields = $fields; unset($edit_fields['field_name']); // fields visible on manage screens $manage_fields = array('few', 'manage', 'fields'); $object->ui = array('fields' => array('add' => $fields, 'edit' => $edit_fields, 'manage' => $manage_fields)); pods_ui($object);