function pl_custom_bulk_action() { $wp_list_table = _get_list_table('WP_Posts_List_Table'); $action = $wp_list_table->current_action(); switch ($action) { case 'pl-template': $done = 0; $post_ids = $_REQUEST['post']; $post_type = $_REQUEST['pl-post-type']; $template = $_REQUEST['selected-template']; if (!$post_ids || !$template) { return false; } foreach ($post_ids as $post_id) { $set = pl_meta($post_id, PL_SETTINGS); $set['live']['custom-map']['template']['ctemplate'] = $template; $set['draft']['custom-map']['template']['ctemplate'] = $template; update_post_meta($post_id, PL_SETTINGS, $set); if ('post' == $post_type) { update_post_meta($post_id, 'pl_template_mode', 'local'); } $done++; } $sendback = add_query_arg(array('pl-template' => $done, 'selected-template-name' => $_REQUEST['selected-template-name'], 'ids' => join(',', $post_ids)), admin_url('edit.php?post_type=' . $post_type)); break; default: return; } wp_redirect($sendback); exit; }
function template_mode() { $key = 'pl_template_mode'; $meta = pl_meta($this->id, $key); if (($this->type == 'page' || $meta == 'local') && $meta != 'type') { return 'local'; } else { return 'type'; } }
function show_template() { if (is_admin()) { return false; } global $wp_admin_bar, $pldraft, $plpg, $pl_custom_template, $post; if (version_compare(CORE_VERSION, '2.1', '<')) { if (!is_object($pldraft) || 'live' == $pldraft->mode || is_admin()) { return; } if (class_exists('PLDeveloperTools')) { $template = isset($pl_custom_template['name']) ? $pl_custom_template['name'] : 'None'; } else { $template = false != $plpg->template && '' != $plpg->template ? $plpg->template : 'None'; } $wp_admin_bar->add_menu(array('parent' => false, 'id' => 'page_template', 'title' => sprintf('Template: %s', $template), 'href' => sprintf('%s?tablink=page-setup', site_url()), 'meta' => false)); } else { if (!class_exists('PageLinesPage')) { return false; } $page_handler = new PageLinesPage(); if ($page_handler->is_special()) { $id = $page_handler->special_index_lookup(); } else { $id = $post->ID; } $mode = get_post_meta($id, 'pl_template_mode', true); if (!$mode) { $mode = 'type'; } if ('local' != $mode) { $id = $page_handler->special_index_lookup(); } $type_name = $page_handler->type_name; $set = pl_meta($id, PL_SETTINGS); $template = is_array($set) && isset($set['live']['custom-map']['template']['ctemplate']) ? $set['live']['custom-map']['template']['ctemplate'] : 'Default'; $template = strlen($template) > 15 ? substr($template, 0, 15) . '...' : $template; $meta = sprintf('Mode: %s | Current Type: %s | Template: %s', ucwords($mode), $type_name, ucwords($template)); $wp_admin_bar->add_menu(array('parent' => false, 'id' => 'page_template', 'title' => $meta, 'href' => false, 'meta' => false)); } }
function get_state($pageID, $typeID, $map) { $state = array(); $settings = array(); $default = array('live' => array(), 'draft' => array()); // Local $settings['local'] = pl_meta($pageID, PL_SETTINGS); if ($typeID != $pageID) { $settings['type'] = pl_meta($typeID, PL_SETTINGS); } $settings['global'] = pl_get_global_settings(); foreach ($settings as $scope => $set) { $set = wp_parse_args($set, $default); $scope = str_replace('map-', '', $scope); if ($set['draft'] != $set['live']) { $state[$scope] = $scope; } } if (count($state) > 1) { $state[] = 'multi'; } return $state; }
function pl_manage_page_columns($column_name, $id) { switch ($column_name) { case 'template': $set = pl_meta($id, PL_SETTINGS); echo is_array($set) && isset($set['live']['custom-map']['template']['ctemplate']) ? $set['live']['custom-map']['template']['ctemplate'] : 'None Set'; break; } // end switch }
function page_attributes_meta_box($post) { global $pl_custom_template; $post_type_object = get_post_type_object($post->post_type); ///// CUSTOM PAGE TEMPLATE STUFF ///// $options = '<option value="">Select Template</option>'; $set = pl_meta($post->ID, PL_SETTINGS); $current = is_array($set) && isset($set['live']['custom-map']['template']['ctemplate']) ? $set['live']['custom-map']['template']['ctemplate'] : ''; $custom_template_handler = new PLCustomTemplates(); foreach ($custom_template_handler->get_all() as $index => $t) { $sel = ''; $sel = $current === $index ? 'selected' : ''; $options .= sprintf('<option value="%s" %s>%s</option>', $index, $sel, $t['name']); } printf('<p><strong>%1$s</strong></p>', __('Load PageLines Template', 'pagelines')); printf('<select name="pagelines_template" id="pagelines_template">%s</select>', $options); ///// END TEMPLATE STUFF ///// if ($post_type_object->hierarchical) { $dropdown_args = array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)', 'pagelines'), 'sort_column' => 'menu_order, post_title', 'echo' => 0); $dropdown_args = apply_filters('page_attributes_dropdown_pages_args', $dropdown_args, $post); $pages = wp_dropdown_pages($dropdown_args); if (!empty($pages)) { printf('<p><strong>%1$s</strong></p>', __('Parent Page', 'pagelines')); echo $pages; } } printf('<p><strong>%1$s</strong></p>', __('Page Order', 'pagelines')); printf('<input name="menu_order" type="text" size="4" id="menu_order" value="%s" /></p>', esc_attr($post->menu_order)); }
function publish($response, $data) { global $sections_data_handler, $dms_cache; $pageID = $data['pageID']; $typeID = $data['typeID']; $response['result'] = $sections_data_handler->publish_items($data['store']); $section_handler = new PLCustomSections(); $section_handler->update_objects('publish'); $tpl_handler = new PLCustomTemplates(); $tpl_handler->update_objects('publish'); $settings = array(); $settings['local'] = pl_meta($pageID, PL_SETTINGS); $settings['type'] = pl_meta($typeID, PL_SETTINGS); $settings['global'] = pl_get_global_settings(); foreach ($settings as $scope => $set) { $set = wp_parse_args($set, array('live' => array(), 'draft' => array())); $set['live'] = $set['draft']; $settings[$scope] = $set; } pl_meta_update($pageID, PL_SETTINGS, $settings['local']); pl_meta_update($typeID, PL_SETTINGS, $settings['type']); pl_update_global_settings($settings['global']); // Flush less $dms_cache->purge('live_css'); // run clean post action to trigger caches to clear. Varnish, WPE etc. do_action('clean_post_cache'); return $response; }
function pl_revert_settings($metaID = false) { if ($metaID) { $settings = pl_meta($metaID, PL_SETTINGS, pl_settings_default()); } else { $settings = pl_get_global_settings(); } $settings['draft'] = $settings['live']; if ($metaID) { pl_meta_update($metaID, PL_SETTINGS, $settings); } else { pl_update_global_settings($settings); } }