public static function get_timestamp() { if (!self::$timestamp) { self::$timestamp = theme_options::get_options(self::$iden); } if (!self::$timestamp) { self::$timestamp = theme_features::get_theme_mtime(); } return self::$timestamp; }
public static function get_options($key = null) { static $caches = null; if ($caches === null) { $caches = (array) theme_options::get_options(self::get_iden()); } if ($key) { return isset($caches[$key]) ? $caches[$key] : false; } return $caches; }
public static function get_options($key = null) { static $caches = null; if ($caches === null) { $caches = theme_options::get_options(__CLASS__); } if ($key) { return isset($caches[$key]) ? $caches[$key] : false; } return $caches; }
public static function get_options($key = null) { static $caches = []; if (!$caches) { $caches = (array) theme_options::get_options(__CLASS__); } if ($key) { return isset($caches[$key]) ? $caches[$key] : null; } return $caches; }
public static function get_options($key = null) { static $caches = []; if (!isset($caches[self::$iden])) { $caches[self::$iden] = theme_options::get_options(self::$iden); } if ($key) { return isset($caches[self::$iden][$key]) ? $caches[self::$iden][$key] : null; } else { return $caches[self::$iden]; } }
public static function get_options($key = null) { static $cache = null; if ($cache === null) { $cache = theme_options::get_options(self::$iden); } if ($key) { return isset($cache[$key]) ? $cache[$key] : false; } else { return $cache; } }
public static function get_options($key = null) { static $cache = null; if ($cache === null) { $cache = array_filter((array) theme_options::get_options(__CLASS__)); } if ($key) { if (isset($cache[$key])) { return $cache[$key]; } return isset(self::options_default()[__CLASS__][$key]) ? self::options_default()[__CLASS__][$key] : false; } return $cache ? $cache : self::options_default()[__CLASS__]; }
public static function get_options($key = null) { static $caches = null; if ($caches === null) { $caches = (array) theme_options::get_options(__CLASS__); } if ($key) { if (isset($caches[$key])) { return $caches[$key]; } else { $caches[$key] = isset(self::options_default()[__CLASS__][$key]) ? self::options_default()[__CLASS__][$key] : false; return $caches[$key]; } } return $caches; }
/** * Display page list on select tag * * @param string $group_id * @param string $page_slug * @return * @version 1.2.0 */ public static function page_option_list($group_id, $iden) { static $pages = null; if ($pages === null) { $pages = get_pages(); } $opt = theme_options::get_options($group_id); $page_id = isset($opt[$iden]) ? (int) $opt[$iden] : null; ob_start(); ?> <select name="<?php echo $group_id; ?> [<?php echo $iden; ?> ]" id="<?php echo $group_id; ?> -<?php echo $iden; ?> "> <option value="-1"><?php echo ___('Select page'); ?> </option> <?php foreach ($pages as $page) { if ($page_id == $page->ID) { $selected = ' selected '; } else { $selected = null; } ?> <option value="<?php echo $page->ID; ?> " <?php echo $selected; ?> ><?php echo theme_cache::get_the_title($page->ID); ?> </option> <?php } ?> </select> <?php }
/** * Process * * * @return * @version 1.0.0 * */ public static function process() { theme_features::check_referer(); if (!theme_cache::current_user_can('manage_options')) { die; } $output = []; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; switch ($type) { case 'import': $file = isset($_FILES['file']) ? $_FILES['file'] : false; if (!$file || $file['error'] != 0) { die(theme_features::json_format(['status' => 'error', 'msg' => ___('Invalid file.')])); } $contents = json_decode(base64_decode(file_get_contents($file['tmp_name'])), true); if (is_array($contents) && !empty($contents)) { set_theme_mod('theme_options', $contents); die(theme_features::json_format(['status' => 'success', 'msg' => ___('Settings has been restored, refreshing page, please wait...')])); /** * invalid contents */ } else { die(theme_features::json_format(['status' => 'error', 'msg' => ___('Invalid file content.')])); } break; /** * export */ /** * export */ case 'export': $contents = base64_encode(json_encode(theme_options::get_options())); /** * write content to a tmp file */ $tmp = tmpfile(); $filepath = stream_get_meta_data($tmp)['uri']; file_put_contents($filepath, $contents); /** * output file download */ header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filepath)); $download_fn = ___('Backup'); $download_fn .= '-' . theme_cache::get_bloginfo('name'); $download_fn .= '-' . theme_functions::$iden; $download_fn .= '-' . date('Ymd-His') . '.bk'; header('Content-Disposition: attachment; filename=" ' . $download_fn . '"'); readfile($filepath); die; } die(theme_features::json_format($output)); }
public static function admin() { $options = theme_options::get_options(); $theme_data = wp_get_theme(); $theme_meta_origin = theme_functions::theme_meta_translate(); $is_oem = isset($theme_meta_origin['oem']) ? true : false; $theme_meta = isset($theme_meta_origin['oem']) ? $theme_meta_origin['oem'] : $theme_meta_origin; ?> <fieldset> <legend><?php echo ___('Theme Information'); ?> </legend> <table class="form-table"> <tbody> <tr> <th scope="row"><?php echo ___('Theme name'); ?> </th> <td><?php echo $theme_meta['name']; ?> </td> </tr> <tr> <th scope="row"><?php echo ___('Theme version'); ?> </th> <td><?php echo $theme_data->display('Version'); ?> </td> </tr> <tr> <th scope="row"><?php echo ___('Theme edition'); ?> </th> <td><?php echo $theme_meta_origin['edition']; ?> </td> </tr> <tr> <th scope="row"><?php echo ___('Theme description'); ?> </th> <td><p><?php echo $theme_meta['des']; ?> </p></td> </tr> <tr> <th scope="row"><?php echo ___('Theme URI'); ?> </th> <td><a href="<?php echo esc_url($theme_meta['theme_url']); ?> " target="_blank"><?php echo esc_url($theme_meta['theme_url']); ?> </a></td> </tr> <tr> <th scope="row"><?php echo ___('Theme author'); ?> </th> <td><?php echo $theme_meta['author']; ?> </td> </tr> <tr> <th scope="row"><?php echo ___('Author site'); ?> </th> <td><a href="<?php echo esc_url($theme_meta['author_url']); ?> " target="_blank"><?php echo esc_url($theme_meta['author_url']); ?> </a></td> </tr> <tr> <th scope="row"><?php echo ___('Feedback and technical support'); ?> </th> <td> <?php if (isset($theme_meta['email'])) { ?> <p><?php echo ___('E-Mail'); ?> <a href="mailto:<?php echo $theme_meta['email']; ?> "><?php echo $theme_meta['email']; ?> </a></p> <?php } ?> <?php if (isset($theme_meta['qq'])) { ?> <p><?php echo ___('QQ'); ?> <?php if (isset($theme_meta['qq']['link'])) { ?> <a target="_blank" href="<?php echo esc_url($theme_meta['qq']['link']); ?> "><?php echo $theme_meta['qq']['number']; ?> </a> <?php } else { ?> <?php echo $theme_meta['qq']['number']; ?> <?php } ?> </p> <?php } ?> <?php if (isset($theme_meta['qq_group'])) { ?> <p><?php echo ___('QQ group'); ?> <?php if (isset($theme_meta['qq_group']['link'])) { ?> <a target="_blank" href="<?php echo esc_url($theme_meta['qq_group']['link']); ?> "><?php echo $theme_meta['qq_group']['number']; ?> </a> <?php } else { ?> <?php echo $theme_meta['qq_group']['number']; ?> <?php } ?> </p> <?php } ?> </td> </tr> <?php if (!$is_oem) { ?> <tr> <th scope="row"><?php echo ___('Donate'); ?> </th> <td> <p> <a id="paypal_donate" href="javascript:;" title="<?php echo ___('Donation by Paypal'); ?> "> <img src="http://ww2.sinaimg.cn/large/686ee05djw1ella1kv74cj202o011wea.jpg" alt="<?php echo ___('Donation by Paypal'); ?> " width="96" height="37"/> </a> <a id="alipay_donate" target="_blank" href="http://ww3.sinaimg.cn/large/686ee05djw1eihtkzlg6mj216y16ydll.jpg" title="<?php echo ___('Donation by Alipay'); ?> "> <img width="96" height="37" src="http://ww1.sinaimg.cn/large/686ee05djw1ellabpq9euj202o011dfm.jpg" alt="<?php echo ___('Donation by Alipay'); ?> "/> </a> </p> </td> </tr> <?php } else { ?> <tr> <th scope="row"><?php echo ___('Theme core'); ?> </th> <td><a href="<?php echo esc_url($theme_meta['core']['url']); ?> " target="_blank"><?php echo $theme_meta['core']['name']; ?> </a></td> </tr> <?php } ?> </tbody> </table> </fieldset> <?php }
public static function get_options($key = null) { static $caches = []; if (!isset($caches)) { $caches = theme_options::get_options(__CLASS__); } if ($key) { if (isset($caches[$key]) && !empty($caches[$key])) { return $caches[$key]; } else { return self::options_default()[__CLASS__][$key]; } } return $caches; }
public static function display_backend_options_list() { ?> <fieldset> <legend><?php echo ___('Theme options debug'); ?> </legend> <textarea class="code widefat" cols="50" rows="50" readonly ><?php esc_textarea(print_r(theme_options::get_options())); ?> </textarea> </fieldset> <?php }
public static function get_posts($args = null) { global $post; $current_post = $post; $options = theme_options::get_options(); $defaults = array('posts_per_page' => isset($options['related_post_num']) ? (int) $options['related_post_num'] : 6); $r = array_merge($defaults, $args); extract($r); /** * get the cache */ $posts = (array) wp_cache_get($current_post->ID, 'theme_related_post'); if (!is_null_array($posts)) { return $posts; } $tags = wp_get_post_tags($current_post->ID); $tags_len = count($tags); $surprise_num = $posts_per_page; $found_posts = 0; /* 存在tags */ if ($tags_len) { for ($i = 0; $i < $tags_len; $i++) { $tags_array[] = $tags[$i]->term_id; } $query_args = array('tag__in' => $tags_array, 'post__not_in' => array($current_post->ID), 'posts_per_page' => $surprise_num); $query = new WP_Query($query_args); if ($query->have_posts()) { foreach ($query->posts as $post) { $posts[] = $post; } } $found_posts = $query->found_posts; /* 发现到的文章数量 */ } $surprise_num = $surprise_num - $found_posts; /* 计算剩余文章数量 */ /* 当剩余文章大于0时候,调用分类目录中的文章来补充 */ if ($surprise_num > 0) { $args = array('category__in' => array(theme_features::get_current_cat_id()), 'post__not_in' => array($current_post->ID), 'posts_per_page' => $surprise_num); $query = new WP_Query($args); if ($query->have_posts()) { foreach ($query->posts as $post) { $posts[] = $post; } } $found_posts = $query->found_posts; /* 发现到的文章数量 */ $surprise_num = $surprise_num - $found_posts; /* 计算剩余文章数量 */ } $posts = array_filter($posts); wp_cache_set($current_post->ID, $posts, 'theme_related_post'); //wp_reset_query(); wp_reset_postdata(); return $posts; }
/** * Display page list on select tag * * @param string $group_id * @param string $page_slug * @return * @version 1.1.1 */ public static function page_option_list($group_id, $page_slug) { static $caches = []; $cache_id = md5(json_encode(func_get_args())); if (isset($caches[$cache_id])) { echo $caches[$cache_id]; return; } $opt = theme_options::get_options($group_id); $page_id = isset($opt[$page_slug]) ? (int) $opt[$page_slug] : null; ob_start(); ?> <select name="<?php echo $group_id, '[', $page_slug, ']'; ?> " id="<?php echo $group_id, '-', $page_slug; ?> "> <option value="0"><?php echo esc_attr(___('Select page')); ?> </option> <?php foreach (get_pages() as $page) { if ($page_id == $page->ID) { $selected = ' selected '; } else { $selected = null; } ?> <option value="<?php echo esc_attr($page->ID); ?> " <?php echo $selected; ?> ><?php echo esc_attr($page->post_title); ?> </option> <?php } ?> </select> <?php $caches[$cache_id] = ob_get_contents(); ob_end_clean(); echo $caches[$cache_id]; }
/** * action_add_history_core_transition_post_status_post_publish * * @param int Post id * @param object Post * @version 1.0.1 */ public static function action_add_history_core_post_publish($post_id, $post) { /** if published, do not add point and history */ if (class_exists('theme_custom_contribution') && theme_custom_contribution::is_once_published($edit_post_id)) { return false; } $meta = array('type' => 'post-publish', 'post-id' => $post_id, 'timestamp' => current_time('timestamp')); /** * add to history */ self::add_history($post->post_author, $meta); /** * update point */ /** * if is not post type, return false */ if ($post->post_type !== 'post') { return false; } $old_point = self::get_point($post->post_author); update_user_meta($post->post_author, self::$user_meta_key['point'], $old_point + (int) theme_options::get_options(__CLASS__)['points']['post-publish']); }