adminUi = new WNGAdminUi(__FILE__); } public function on_admin_menu() { add_options_page("What's New 設定", "What's New 設定", 'administrator', __FILE__, array(&$this->adminUi, 'show_admin_page')); } function on_enqueue_css_js() { if ( is_admin() ){ return; } WNG::enqueue_css_js(); } function show_whatsnew(){ $info = new WhatsNewInfo(); include( dirname(__FILE__) . '/whatsnew-view.php'); } function show_shortcode(){ ob_start(); $this->show_whatsnew(); $contents = ob_get_contents(); ob_end_clean(); return $contents; } } class WhatsNewInfo{ var $title; var $items = array(); public function __construct(){ $options = WNG::get_option(); $this->title = esc_html( $options['wng_title'] ); $this->title_tag = $options['wng_title_tag']; $condition = array(); if ( $options['wng_content_type'] == '投稿'){ $condition['post_type'] = array('post', 'service'); }else if ( $options['wng_content_type'] == '固定ページ' ){ $condition['post_type'] = 'page'; }else{ $condition['post_type'] = array('page', 'post'); } $condition['numberposts'] = $options['wng_number']; $condition['order'] = 'desc'; $condition['orderby'] = $options['wng_orderby'] == '公開日順' ? 'post_date' : 'modified'; $condition['category_name'] = $options['wng_category_name']; $posts = get_posts( $condition ); if ( !is_array($posts) ){ return; } foreach($posts as $post){ $this->items[] = new WhatsNewItem($post); } } } class WhatsNewItem{ var $date; var $raw_date; var $title; var $url; var $newmark; private static $number = 0; public function __construct( $post ){ $options = WNG::get_option(); $orderby = $options['wng_orderby']; $this->raw_date = $orderby == '公開日順' ? $post->post_date : $post->post_modified; $this->date = date(get_option('date_format'), strtotime($this->raw_date)); $this->title = esc_html( $post->post_title ); $this->url = get_permalink($post->ID); $this->newmark = $this->is_new(); self::$number++; } public function is_new(){ $options = WNG::get_option(); if ( isset($options['wng_latest_new']) && self::$number == 0){ return true; } $term = $options['wng_newmark']; if ( !isset($term) || $term == 0){ return false; } $today = date_i18n('U'); $post_date = date('U', strtotime($this->raw_date)); $diff = ( $today - $post_date ) / ( 24 * 60 * 60 ); if ($term > $diff){ return true; } return false; } }