function run_installation_routine($url = '') { $settings = pl_get_global_settings(); // Only sets defaults if they are null set_default_settings(); if (!$settings) { $this->load_page_templates(); $this->apply_page_templates(); // Publish New Templates $tpl_handler = new PLCustomTemplates(); $tpl_handler->update_objects('publish'); } // Add Templates $id = $this->page_on_activation(); // Redirect $url = add_query_arg('pl-installed-theme', pl_theme_info('template'), get_permalink($id)); return $url; }
function run_installation_routine($url = '') { set_theme_mod('pl_installed', true); $settings = pl_get_global_settings(); // Only sets defaults if they are null set_default_settings(); if (is_file(trailingslashit(get_stylesheet_directory()) . 'pl-config.json')) { $settings_handler = new PageLinesSettings(); $settings_handler->import_from_child(); } $this->apply_page_templates(); // Publish New Templates $tpl_handler = new PLCustomTemplates(); $tpl_handler->update_objects('publish'); // Add Templates $id = $this->page_on_activation(); // Redirect $url = add_query_arg('pl-installed-theme', pl_theme_info('template'), get_permalink($id)); return $url; }
function getopts() { $option = array(); // do globals if (isset($this->data->export_global)) { $option['pl-settings'] = pl_get_global_settings(); } // grab the map // $option['pl-template_map'] = get_option( 'pl-template-map', array() ); // grab user templates if (isset($this->data->templates)) { $templates = get_option('pl-user-templates', array('draft' => array(), 'live' => array())); $draft = array(); $live = array(); foreach ($this->data->templates as $k => $data) { if (isset($templates['draft'][$k])) { $draft[$k] = $templates['draft'][$k]; } if (isset($templates['live'][$k])) { $live[$k] = $templates['live'][$k]; } } $option['pl-user-templates'] = stripslashes_deep(array('draft' => $draft, 'live' => $live)); } if (isset($this->data->export_types)) { $lookup_array = array('blog', 'category', 'search', 'tag', 'author', 'archive', 'page', 'post', '404_page'); $args = array('public' => true, '_builtin' => false); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $post_types = get_post_types($args, $output, $operator); $meta = array(); $master = array_unique(array_merge($post_types, $lookup_array)); foreach ($master as $t => $type) { $key = array_search($type, $lookup_array); if (!$key) { $key = pl_create_int_from_string($type) + 70000000; } else { $key = $key + 70000000; } // $option[$type] = $key; $meta[$key] = get_post_meta($key, 'pl-settings'); if (empty($meta[$key])) { unset($meta[$key]); } } $post_ids = get_posts(array('numberposts' => -1, 'fields' => 'ids', 'post_type' => 'any')); $option['post_ids'] = $post_ids; foreach ($post_ids as $k => $p) { $meta[$p] = get_post_meta($p, 'pl-settings'); if (empty($meta[$p])) { unset($meta[$p]); } } $option['post_meta'] = $meta; } $option['custom'] = get_option('pl-user-sections'); // do section data global $sections_data_handler; $section_data = $sections_data_handler->dump_opts(); foreach ($section_data as $k => $data) { $section_data[$k]->draft = $this->unserialize($data->draft); $section_data[$k]->live = $this->unserialize($data->live); } $option['section_data'] = $section_data; $contents = json_encode($option); $contents .= $this->get_file_headers(); return $contents; }
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 current_page_data($scope = 'local') { $d = array(); if ($scope == 'local') { $d = pl_settings($this->draft->mode, $this->page->id); } elseif ($scope == 'type') { $d = pl_settings($this->draft->mode, $this->page->typeid); } elseif ($scope == 'section') { global $sections_handler; $d = $sections_handler->get_user_section_settings(); } elseif ($scope == 'template') { global $pl_custom_template; $d = !empty($pl_custom_template) ? $pl_custom_template['settings'] : array(); } elseif ($scope == 'global') { $d = pl_get_global_settings(pl_get_mode()); } return $d ? $d : array(); }
function set_default_settings() { $settings = pl_get_global_settings(); if (!$settings) { $settings = pl_settings_default(); } $settings_defaults = apply_filters('pl_theme_default_settings', get_default_settings()); $region_defaults = apply_filters('pl_theme_default_regions', array()); if (empty($settings['draft'])) { $settings['draft'] = array('settings' => $settings_defaults, 'regions' => $region_defaults); } if (empty($settings['live'])) { $settings['live'] = array('settings' => $settings_defaults, 'regions' => $region_defaults); } pl_update_global_settings($settings); return $settings; }
function getopts() { $option = array(); // do globals if (isset($this->data->export_global)) { $option['pl-settings'] = pl_get_global_settings(); } // grab the map // $option['pl-template_map'] = get_option( 'pl-template-map', array() ); // grab user templates if (isset($this->data->templates)) { $templates = get_option('pl-user-templates', array()); foreach ($this->data->templates as $t => $s) { if (isset($templates['live'][$t])) { $option['pl-user-templates'][$t] = $templates['live'][$t]; } } } if (isset($this->data->export_types)) { $lookup_array = array('blog', 'category', 'search', 'tag', 'author', 'archive', 'page', 'post', '404_page'); $args = array('public' => true, '_builtin' => false); $output = 'names'; // names or objects, note names is the default $operator = 'and'; // 'and' or 'or' $post_types = get_post_types($args, $output, $operator); $meta = array(); $master = array_unique(array_merge($post_types, $lookup_array)); foreach ($master as $t => $type) { $key = pl_create_int_from_string($type) + 70000000; $meta[$key] = get_post_meta($key, 'pl-settings'); if (empty($meta[$key])) { unset($meta[$key]); } } $option['post_meta'] = $meta; } // do section data global $sections_data_handler; $option['section_data'] = $sections_data_handler->dump_opts(); $contents = json_encode($option); $contents .= $this->get_file_headers(); return $contents; }
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 update_setting($args = array()) { $defaults = array('key' => '', 'val' => '', 'mode' => 'draft', 'scope' => 'global', 'uid' => 'settings'); $a = wp_parse_args($args, $defaults); $scope = $a['scope']; $mode = $a['mode']; $key = $a['key']; $val = $a['val']; $uid = $a['uid']; $parse_value = array($key => $val); if ($scope == 'global') { $settings = pl_get_global_settings(); $old_settings = isset($settings[$mode][$uid]) ? $settings[$mode][$uid] : array(); $settings[$mode][$uid] = wp_parse_args($parse_value, $old_settings); pl_update_global_settings($settings); } elseif ($scope == 'local' || $scope == 'type') { global $plpg; $theID = $scope == 'local' ? $plpg->id : $plpg->typeid; $settings = $this->meta($theID, PL_SETTINGS, pl_settings_default()); $old_settings = isset($settings[$mode][$uid]) ? $settings[$mode][$uid] : array(); $settings[$mode][$uid] = wp_parse_args($parse_value, $old_settings); pl_meta_update($theID, PL_SETTINGS, $settings); } }