public static function register_notices_callback($arguments) { $screen = get_current_screen(); extract($arguments); $file = $path . '/parts/' . $folder . '/' . $part; $data = get_file_data($file, apply_filters('piklist_get_file_data', array('notice_id' => 'Notice ID', 'notice_type' => 'Notice Type', 'capability' => 'Capability', 'role' => 'Role', 'page' => 'Page'), 'notice')); $data = apply_filters('piklist_add_part', $data, 'notice'); $dismissed = explode(',', (string) get_user_meta(get_current_user_id(), 'dismissed_piklist_notices', true)); if (!empty($dismissed[0]) && in_array($data['notice_id'], $dismissed)) { return; } $page = str_replace(' ', '', $data['page']); $pages = $page ? explode(',', $page) : false; if ($screen->id == $page || empty($page) || in_array($screen->id, $pages)) { if ($data['capability'] && !current_user_can($data['capability']) || $data['role'] && !piklist_user::current_user_role($data['role'])) { return false; } else { $content = array('content' => trim(piklist::render($file, null, true))); if (isset($data)) { $data = array_merge($data, $content); self::$notices[] = $data; } } } }
public static function register_workflows_callback($arguments) { global $pagenow; extract($arguments); $data = get_file_data($path . '/parts/' . $folder . '/' . $part, apply_filters('piklist_get_file_data', array('name' => 'Title', 'description' => 'Description', 'capability' => 'Capability', 'order' => 'Order', 'flow' => 'Flow', 'page' => 'Page', 'post_type' => 'Post Type', 'taxonomy' => 'Taxonomy', 'role' => 'Role', 'redirect' => 'Redirect', 'header' => 'Header', 'disable' => 'Disable', 'position' => 'Position', 'default' => 'Default'), 'workflows')); $data = apply_filters('piklist_add_part', $data, 'workflows'); if (!isset($data['flow'])) { return null; } if ((!isset($data['capability']) || empty($data['capability']) || $data['capability'] && current_user_can(strtolower($data['capability']))) && (!isset($data['role']) || empty($data['role']) || piklist_user::current_user_role($data['role']))) { if (!empty($data['page'])) { $data['page'] = strstr($data['page'], ',') ? piklist::explode(',', $data['page']) : array($data['page']); } $data['page_slug'] = piklist::slug($data['name']); $data['flow_slug'] = piklist::slug($data['flow']); if (!$data['header']) { $data = self::is_active($data); } if (in_array($pagenow, array('admin.php', 'users.php', 'plugins.php', 'options-general.php')) && $data['position'] == 'title') { $data['position'] = 'header'; } $workflow = array('config' => $data, 'part' => $path . '/parts/' . $folder . '/' . $part); if (!isset(self::$workflows[$data['flow']])) { self::$workflows[$data['flow']] = array(); } if ($data['header'] == 'true') { array_unshift(self::$workflows[$data['flow']], $workflow); } elseif (!empty($data['order'])) { self::$workflows[$data['flow']][$data['order']] = $workflow; } else { array_push(self::$workflows[$data['flow']], $workflow); } } }
public static function register_meta_boxes_callback($arguments) { extract($arguments); $current_user = wp_get_current_user(); $data = get_file_data($path . '/parts/' . $folder . '/' . $part, apply_filters('piklist_get_file_data', array('name' => 'Title', 'description' => 'Description', 'capability' => 'Capability', 'order' => 'Order', 'role' => 'Role', 'new' => 'New'), 'users')); $data = apply_filters('piklist_add_part', $data, 'users'); $data = array_filter($data); $meta_box = array('id' => piklist::slug($data['name']), 'config' => $data, 'part' => $path . '/parts/' . $folder . '/' . $part); if ((!isset($data['capability']) || $data['capability'] && current_user_can(strtolower($data['capability']))) && (!isset($data['role']) || piklist_user::current_user_role($data['role'])) && (!isset($data['new']) || $data['new'] && (isset($pagenow) && $pagenow != 'user-new.php'))) { if (isset($order)) { self::$meta_boxes[$order] = $meta_box; } else { array_push(self::$meta_boxes, $meta_box); } } }
public static function register_help_tabs_callback($arguments) { $screen = get_current_screen(); extract($arguments); $file = $path . '/parts/' . $folder . '/' . $part; $data = get_file_data($file, apply_filters('piklist_get_file_data', array('title' => 'Title', 'capability' => 'Capability', 'role' => 'Role', 'page' => 'Page', 'sidebar' => 'Sidebar'), 'help')); $data = apply_filters('piklist_add_part', $data, 'help'); $pages = isset($data['page']) ? explode(',', $data['page']) : false; if (($screen->id == $data['page'] || empty($data['page']) || in_array($screen->id, $pages)) && (isset($data['capability']) && current_user_can($data['capability']) || isset($data['role']) && piklist_user::current_user_role($data['role']))) { if ($data['sidebar'] == 'true') { get_current_screen()->set_help_sidebar(piklist::render($file, null, true)); } else { get_current_screen()->add_help_tab(array('id' => piklist::dashes($add_on . '-' . $part), 'title' => $data['title'], 'content' => piklist::render($file, null, true))); } } }
public static function register_dashboard_widgets_callback($arguments) { global $current_screen; extract($arguments); $file = $path . '/parts/' . $folder . '/' . $part; $data = get_file_data($file, apply_filters('piklist_get_file_data', array('title' => 'Title', 'capability' => 'Capability', 'role' => 'Role', 'id' => 'ID', 'network' => 'Network'), 'dashboard')); $data = apply_filters('piklist_add_part', $data, 'dashboard'); if ($data['network'] == 'only' && $current_screen->id != 'dashboard-network') { return; } if ((empty($data['network']) || $data['network'] == 'false') && (isset($current_screen) && $current_screen->id == 'dashboard-network')) { return; } if (isset($data['capability']) && current_user_can($data['capability']) || isset($data['role']) && piklist_user::current_user_role($data['role'])) { $id = empty($data['id']) ? piklist::dashes($add_on . '-' . $part) : $data['id']; self::$widgets[$id] = array('id' => $id, 'file' => $file, 'data' => $data); wp_add_dashboard_widget($id, self::$widgets[$id]['data']['title'], array('piklist_dashboard', 'render_widget')); } }
public static function register_pointers_callback($arguments) { $screen = get_current_screen(); extract($arguments); $file = $path . '/parts/' . $folder . '/' . $part; $data = get_file_data($file, apply_filters('piklist_get_file_data', array('title' => 'Title', 'pointer_id' => 'Pointer ID', 'capability' => 'Capability', 'role' => 'Role', 'page' => 'Page', 'anchor' => 'Anchor ID', 'edge' => 'Edge', 'align' => 'Align'), 'pointer')); $data = apply_filters('piklist_add_part', $data, 'pointer'); $dismissed = explode(',', (string) get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true)); if (in_array($data['pointer_id'], $dismissed)) { return; } $pages = isset($data['page']) ? explode(',', $data['page']) : false; if ($screen->id == $data['page'] || empty($data['page']) || in_array($screen->id, $pages)) { if ($data['capability'] && !current_user_can($data['capability']) || $data['role'] && !piklist_user::current_user_role($data['role'])) { return false; } else { $content = array('content' => trim(piklist::render($file, null, true))); $data = array_merge($data, $content); self::$pointers[] = $data; } } }
public static function register_meta_boxes_callback($arguments) { extract($arguments); $data = get_file_data($path . '/parts/' . $folder . '/' . $part, apply_filters('piklist_get_file_data', array('name' => 'Title', 'description' => 'Description', 'capability' => 'Capability', 'role' => 'Role', 'order' => 'Order', 'taxonomy' => 'Taxonomy', 'new' => 'New'), 'terms')); $data = apply_filters('piklist_add_part', $data, 'terms'); $taxonomies = empty($data['taxonomy']) ? get_taxonomies() : explode(',', $data['taxonomy']); foreach ($taxonomies as $taxonomy) { $data['taxonomy'] = trim($taxonomy); if ((!isset($data['capability']) || empty($data['capability']) || $data['capability'] && current_user_can(strtolower($data['capability']))) && (!isset($data['role']) || empty($data['role']) || piklist_user::current_user_role($data['role']))) { if (!isset(self::$meta_boxes[$data['taxonomy']])) { self::$meta_boxes[$data['taxonomy']] = array(); add_action($data['taxonomy'] . '_edit_form_fields', array('piklist_taxonomy', 'meta_box'), 10, 2); add_action('edited_' . $data['taxonomy'], array('piklist_taxonomy', 'process_form'), 10, 2); } $meta_box = array('config' => $data, 'part' => $path . '/parts/' . $folder . '/' . $part); if (isset($order)) { self::$meta_boxes[$data['taxonomy']][$order] = $meta_box; } else { array_push(self::$meta_boxes[$data['taxonomy']], $meta_box); } } } }
function piklist($option, $arguments = array()) { if (!is_array($arguments) && strstr($arguments, '=')) { parse_str($arguments, $arguments); } if (is_array($option) || is_object($option)) { $list = array(); $arguments = is_array($arguments) ? $arguments : array($arguments); foreach ($option as $key => $value) { if (count($arguments) > 1) { if (in_array('_key', $arguments)) { $_value = $arguments[1]; $list[$key] = is_object($value) ? $value->{$_value} : $value[$_value]; } else { $__key = $arguments[0]; $_key = is_object($value) ? $value->{$__key} : (isset($value[$__key]) ? $value[$__key] : null); $_value = $arguments[1]; $list[$_key] = is_object($value) ? $value->{$_value} : (isset($value[$_value]) ? $value[$_value] : null); } } else { $_value = $arguments[0]; array_push($list, is_object($value) && isset($value->{$_value}) ? $value->{$_value} : (isset($value[$_value]) ? $value[$_value] : null)); } } return $list; } else { switch ($option) { case 'field': if (piklist_setting::get('active_section')) { piklist_setting::register_setting($arguments); } else { piklist_form::render_field($arguments, isset($arguments['return']) ? $arguments['return'] : false); } break; case 'list_table': piklist_list_table::render($arguments); break; case 'post_type_labels': return piklist::post_type_labels($arguments); break; case 'taxonomy_labels': return piklist::taxonomy_labels($arguments); break; case 'option': case 'post_custom': case 'post_meta': case 'get_post_custom': case 'user_custom': case 'user_meta': case 'get_user_custom': case 'term_custom': case 'term_meta': case 'get_term_custom': switch ($option) { case 'user_custom': case 'user_meta': case 'get_user_custom': $type = 'user'; break; case 'term_custom': case 'term_meta': case 'get_term_custom': $type = 'term'; break; case 'post_custom': case 'post_meta': case 'get_post_custom': $type = 'post'; break; default: $type = 'option'; break; } return piklist::object($type, $arguments); break; case 'dashes': return piklist::dashes($arguments); break; case 'slug': return piklist::slug($arguments); break; case 'performance': piklist::performance(); break; case 'include_meta_boxes': // TODO: Improve if (isset($arguments['post_type'])) { $post_type = $arguments['post_type']; unset($arguments['post_type']); } else { $post_type = null; } piklist::include_meta_boxes($arguments, $post_type); break; case 'include_actions': // TODO: Improve if (isset($arguments['action'])) { $post_type = $arguments['action']; unset($arguments['action']); } piklist::include_actions($action, $arguments); break; case 'include_user_profile_fields': piklist_user::include_user_profile_fields($arguments); break; case 'comments_template': $file = isset($arguments[0]) ? $arguments[0] : '/comments.php'; $seperate_comments = isset($arguments[1]) ? $arguments[1] : false; piklist_comments::comments_template($file, $seperate_comments); break; default: $return = isset($arguments['return']) ? $arguments['return'] : false; $loop = isset($arguments['loop']) ? $arguments['loop'] : null; unset($arguments['return']); unset($arguments['loop']); return piklist::render($option, $arguments, $return, $loop); break; } } }
/** * validate_part_parameter * Check to see if the paramter passes validation. * * @param string $parts The parameter name. * @param mixes $parts The parameter value. * * @access public * @static * @since 1.0 */ public static function validate_part_parameter($parameter, $value) { global $post, $pagenow, $current_screen; switch ($parameter) { case 'capability': return piklist_user::current_user_can($value); break; case 'role': return piklist_user::current_user_role($value); break; case 'logged_in': return $value == 'true' ? is_user_logged_in() : true; break; case 'post_type': return $post && in_array($post->post_type, $value) || !$post; break; case 'status': case 'post_status': return $post && in_array($post->post_status, $value) || !$post; break; case 'new': return $value == 'true' ? $pagenow == 'post-new.php' : true; break; case 'page': $current = array($pagenow); if (!empty($current_screen->id)) { array_push($current, $current_screen->id); } if (!empty($_REQUEST['page'])) { array_push($current, $_REQUEST['page']); } return array_intersect($value, $current); break; case 'id': return $post && in_array($post->ID, $value); break; case 'template': $page_template = $post->post_status == 'auto-draft' ? 'default' : strtolower(str_replace('.php', '', get_post_meta($post->ID, '_wp_page_template', true))); return in_array($page_template, $value); break; case 'post_format': $format = get_post_format($post->ID); $format = empty($format) ? 'standard' : $format; return in_array($format, $value); break; case 'network': if (isset($current_screen) && $current_screen->id == 'dashboard-network') { return $value || $value == 'only'; } elseif (isset($current_screen) && $current_screen->id == 'dashboard') { return $value === true; } break; default: /** * piklist_validate_part_parameter * Add custom part parameters to check. * * @param $parameter Parameter to check. * @param $value Value to compare. * * @since 1.0 */ return apply_filters('piklist_validate_part_parameter', true, $parameter, $value); break; } }
<?php /* Title: Add More Fields: Three Levels Order: 1 Tab: Add-More's Sub Tab: Three Levels Flow: Demo Workflow */ piklist('field', array('type' => 'group', 'field' => 'menu_section', 'label' => __('Menu', 'piklist-demo'), 'add_more' => true, 'fields' => array(array('type' => 'text', 'field' => 'menu_title', 'label' => __('Menu Title', 'piklist-demo'), 'columns' => 12), array('type' => 'group', 'field' => 'recipe', 'add_more' => true, 'fields' => array(array('type' => 'text', 'field' => 'recipe_name', 'label' => __('Recipe', 'piklist-demo'), 'columns' => 12), array('type' => 'checkbox', 'field' => 'dietary_restrictions', 'label' => __('Restrictions', 'piklist-demo'), 'columns' => 12, 'list' => false, 'choices' => array('dairy_free' => 'Dairy Free', 'gluten_free' => 'Gluten Free', 'nut_free' => 'Nut Free')), array('type' => 'group', 'field' => 'ingredient', 'add_more' => true, 'fields' => array(array('type' => 'number', 'field' => 'ingredient_qty', 'label' => __('Qty', 'piklist-demo'), 'columns' => 2), array('type' => 'text', 'field' => 'name', 'label' => __('Description', 'piklist-demo'), 'columns' => 10, 'attributes' => array('rows' => 5))))))))); piklist('field', array('type' => 'group', 'field' => 'project_section', 'label' => __('Project', 'piklist-demo'), 'add_more' => true, 'fields' => array(array('type' => 'text', 'field' => 'Project_title', 'label' => __('Project', 'piklist-demo'), 'columns' => 12), array('type' => 'group', 'field' => 'task', 'add_more' => true, 'fields' => array(array('type' => 'text', 'field' => 'task_name', 'label' => __('Task', 'piklist-demo'), 'columns' => 8), array('type' => 'datepicker', 'field' => 'task_due', 'label' => __('Due', 'piklist-demo'), 'columns' => 4), array('type' => 'textarea', 'field' => 'task_description', 'label' => __('Description', 'piklist-demo'), 'columns' => 12), array('type' => 'checkbox', 'field' => 'authorized_roles', 'label' => __('Authorized Roles', 'piklist-demo'), 'list' => false, 'columns' => 12, 'choices' => piklist_user::available_roles()), array('type' => 'group', 'field' => 'sub_task', 'label' => 'Sub Tasks', 'add_more' => true, 'fields' => array(array('type' => 'text', 'field' => 'sub_task_name', 'label' => __('Sub Task', 'piklist-demo'), 'columns' => 8), array('type' => 'datepicker', 'field' => 'sub_task_due', 'label' => __('Due', 'piklist-demo'), 'columns' => 4)))))))); piklist('shared/code-locater', array('location' => __FILE__, 'type' => 'Media Section'));
public static function save_object($type, $data, $belongs_to = false) { $object = array(); foreach (self::$core_scopes[$type] as $allowed) { if (isset($data[$allowed]) && !empty($data[$allowed])) { $object[$allowed] = is_array($data[$allowed]) && count($data[$allowed]) == 1 ? current($data[$allowed]) : $data[$allowed]; } } switch ($type) { case 'post': $id = isset($object['ID']) ? wp_update_post($object) : wp_insert_post($object); break; case 'comment': if (!empty($object['comment_content'])) { $id = isset($object['ID']) ? wp_update_comment($object) : wp_insert_comment($object); } break; case 'user': if (isset($object['user_pass']) && empty($object['user_pass'])) { unset($object['user_pass']); } $id = isset($object['ID']) ? wp_update_user($object) : wp_insert_user($object); if ($object['user_role'] && $id) { piklist_user::multiple_roles($id, $object['user_role']); } break; } if ($belongs_to && $id) { self::relate($belongs_to, $id); } return isset($id) ? $id : false; }
/** * save_object * Save a core WordPress object (post, user, comment) * * @param string $type The type of object * @param array $data The object * * @return int The object id. * * @access public * @static * @since 1.0 */ public static function save_object($type, $data) { global $wpdb; $object = array(); foreach (self::$scopes[$type] as $allowed) { if (isset($data[$allowed]) && !empty($data[$allowed])) { $object[$allowed] = is_array($data[$allowed]) && count($data[$allowed]) == 1 ? current($data[$allowed]) : $data[$allowed]; } } switch ($type) { case 'post': $id = isset($object['ID']) ? wp_update_post($object) : wp_insert_post($object); break; case 'comment': if (!empty($object['comment_content'])) { $id = isset($object['comment_ID']) ? wp_update_comment($object) : wp_insert_comment($object); } break; case 'user': $re_auth_cookie = false; if (isset($object['user_pass']) && empty($object['user_pass'])) { unset($object['user_pass']); } if (isset($object['ID']) && isset($object['user_login']) && !empty($object['user_login'])) { $user_login = $object['user_login']; $increment = 0; $user_login_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_login = %s LIMIT 1", $user_login, $user_login)); if ($user_login_check != $object['ID']) { while ($user_login_check) { $user_login = $object['user_login'] . '-' . ++$increment; $user_login_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_login = %s LIMIT 1", $user_login, $user_login)); } $result = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_login = %s WHERE ID = %d ", $user_login, $object['ID'])); unset($object['user_login']); if (!isset($object['user_nicename'])) { $object['user_nicename'] = $user_login; } $re_auth_cookie = true; } } if (isset($object['ID'])) { $id = wp_update_user($object); } elseif (isset($object['user_pass']) && isset($object['user_login'])) { $id = wp_insert_user($object); } if (isset($id) && !is_wp_error($id)) { if ($re_auth_cookie) { wp_set_auth_cookie($id); } if (isset($object['user_role'])) { piklist_user::multiple_roles($id, $object['user_role']); } } break; } return isset($id) ? $id : false; }
public static function register_meta_boxes_callback($arguments) { global $post, $pagenow; extract($arguments); $current_user = wp_get_current_user(); $data = get_file_data($path . '/parts/' . $folder . '/' . $part, apply_filters('piklist_get_file_data', array('name' => 'Title', 'context' => 'Context', 'description' => 'Description', 'capability' => 'Capability', 'role' => 'Role', 'priority' => 'Priority', 'order' => 'Order', 'type' => 'Post Type', 'lock' => 'Lock', 'collapse' => 'Collapse', 'status' => 'Status', 'new' => 'New', 'id' => 'ID', 'div' => 'DIV', 'template' => 'Template', 'box' => 'Meta Box'), 'meta-boxes')); $data = apply_filters('piklist_add_part', $data, 'meta-boxes'); $types = empty($data['type']) ? get_post_types() : explode(',', $data['type']); foreach ($types as $type) { $type = trim($type); $statuses = !empty($data['status']) ? explode(',', $data['status']) : false; $ids = !empty($data['id']) ? explode(',', $data['id']) : false; $name = !empty($data['name']) ? $data['name'] : 'piklist_meta_' . piklist::slug($part); if (post_type_exists($type) && (!$data['capability'] || $data['capability'] && current_user_can(strtolower($data['capability']))) && (!$data['role'] || $data['role'] && piklist_user::current_user_role($data['role'])) && (!$data['status'] || $data['status'] && in_array($post->post_status, $statuses)) && (!$data['new'] || $data['new'] && $pagenow != 'post-new.php') && (!$data['id'] || $data['id'] && in_array($post->ID, $ids)) && (!$data['template'] || $data['template'] && $data['template'] == pathinfo(get_page_template_slug($post->ID), PATHINFO_FILENAME))) { $id = !empty($data['div']) ? $data['div'] : 'piklist_meta_' . piklist::slug($part); $textdomain = isset(piklist_add_on::$available_add_ons[$add_on]) && isset(piklist_add_on::$available_add_ons[$add_on]['TextDomain']) ? piklist_add_on::$available_add_ons[$add_on]['TextDomain'] : null; add_meta_box($id, !empty($textdomain) ? __($name, $textdomain) : $name, array('piklist_cpt', 'meta_box'), $type, !empty($data['context']) ? $data['context'] : 'normal', !empty($data['priority']) ? $data['priority'] : 'low', array('part' => $part, 'add_on' => $add_on, 'order' => $data['order'] ? $data['order'] : null, 'config' => $data)); if (isset($data['box']) && strtolower($data['box']) == 'false') { add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'lock_meta_boxes')); add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'no_meta_boxes')); if ($name == 'piklist_meta_' . piklist::slug($part)) { add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'no_title_meta_boxes')); } } else { if (isset($data['lock']) && strtolower($data['lock']) == 'true') { add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'lock_meta_boxes')); } if (isset($data['collapse']) && strtolower($data['collapse']) == 'true') { add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'collapse_meta_boxes')); } } add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'default_classes')); } } }