Version Description
- *
Download this release
Release Info
Developer | hidaka.bizplugin |
Plugin | What's New Generator |
Version | 1.7.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.0 to 1.7.0
- admin-ui.php +112 -0
- image/list.png +0 -0
- readme.txt +5 -1
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- whats-new-generator.php +76 -181
- whats-new.css +30 -5
- whatsnew-view.php +11 -5
admin-ui.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WNGAdminUi {
|
4 |
+
var $file_path;
|
5 |
+
|
6 |
+
public function __construct( $path){
|
7 |
+
$this->file_path = $path;
|
8 |
+
$this->setUi();
|
9 |
+
}
|
10 |
+
|
11 |
+
public function setUi(){
|
12 |
+
register_setting(WNG::OPTIONS, WNG::OPTIONS, array( &$this, 'validate' ));
|
13 |
+
add_settings_section('main_section', '表示設定', array(&$this,'section_text_fn'), $this->file_path);
|
14 |
+
add_settings_field('wng_title', 'タイトル', array(&$this,'setting_title'), $this->file_path, 'main_section');
|
15 |
+
add_settings_field('wng_background_color', 'タイトル背景色', array(&$this,'setting_background_color'), $this->file_path, 'main_section');
|
16 |
+
add_settings_field('wng_content_type', '表示するコンテンツ', array(&$this,'setting_content_type'), $this->file_path, 'main_section');
|
17 |
+
add_settings_field('wng_category_name', 'カテゴリーのスラッグ', array(&$this,'setting_category_name'), $this->file_path, 'main_section');
|
18 |
+
add_settings_field('wng_orderby', '表示順序', array(&$this,'setting_orderby'), $this->file_path, 'main_section');
|
19 |
+
add_settings_field('wng_number', '表示件数', array(&$this,'setting_number'), $this->file_path, 'main_section');
|
20 |
+
add_settings_field('wng_newmark', 'NEW!マーク表示期間', array(&$this,'setting_newmark'), $this->file_path, 'main_section');
|
21 |
+
add_settings_field('wng_postlist_url', '一覧ページのurl', array(&$this,'setting_postlist_url'), $this->file_path, 'main_section');
|
22 |
+
}
|
23 |
+
|
24 |
+
public function show_admin_page() {
|
25 |
+
$file = $this->file_path;
|
26 |
+
$option_name = WNG::OPTIONS;
|
27 |
+
$shortcode = "[" . WNG::SHORTCODE . "]";
|
28 |
+
include_once('admin-view.php');
|
29 |
+
$info = new WhatsNewInfo();
|
30 |
+
include_once('whatsnew-view.php');
|
31 |
+
}
|
32 |
+
|
33 |
+
function validate($input) {
|
34 |
+
if(!preg_match('/^#[a-f0-9]{6}$/i', $input['wng_background_color'])){
|
35 |
+
$input['wng_background_color'] = "#f5f5f5";
|
36 |
+
}
|
37 |
+
if ( !is_numeric( $input['wng_newmark']) || $input['wng_newmark'] < 0){
|
38 |
+
$input['wng_newmark'] = 0;
|
39 |
+
}
|
40 |
+
if ($input['wng_newmark'] > 30 ){
|
41 |
+
$input['wng_newmark'] = 30;
|
42 |
+
}
|
43 |
+
$input['wng_title'] = esc_html( $input['wng_title'] );
|
44 |
+
$input['wng_category_name'] = trim(esc_html( $input['wng_category_name'] ));
|
45 |
+
$input['wng_postlist_url'] = esc_url( $input['wng_postlist_url'] );
|
46 |
+
return $input;
|
47 |
+
}
|
48 |
+
|
49 |
+
function section_text_fn() {
|
50 |
+
}
|
51 |
+
|
52 |
+
function setting_title() {
|
53 |
+
$options = WNG::get_option();
|
54 |
+
$value = $options["wng_title"];
|
55 |
+
echo "<input id='wng_title' name='whats_new_options[wng_title]' size='40' type='text' value='{$value}' />";
|
56 |
+
}
|
57 |
+
|
58 |
+
function setting_postlist_url() {
|
59 |
+
$options = WNG::get_option();
|
60 |
+
$value = $options["wng_postlist_url"];
|
61 |
+
echo "<input id='wng_postlist_url' name='whats_new_options[wng_postlist_url]' size='40' type='text' value='{$value}' />";
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
function setting_background_color() {
|
66 |
+
$options = WNG::get_option();
|
67 |
+
$value = $options["wng_background_color"];
|
68 |
+
echo "<input id='wng_background_color' name='whats_new_options[wng_background_color]' size='10' type='text' value='{$value}' />";
|
69 |
+
}
|
70 |
+
|
71 |
+
function setting_newmark() {
|
72 |
+
$options = WNG::get_option();
|
73 |
+
$value = $options["wng_newmark"];
|
74 |
+
echo "<input id='wng_newmark' name='whats_new_options[wng_newmark]' size='2' type='text' value='{$value}' />日間";
|
75 |
+
}
|
76 |
+
|
77 |
+
function setting_category_name() {
|
78 |
+
$options = WNG::get_option();
|
79 |
+
$value = $options["wng_category_name"];
|
80 |
+
echo "<input id='wng_category_name' name='whats_new_options[wng_category_name]' size='40' type='text' value='{$value}' />";
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
function setting_number() {
|
85 |
+
$options = WNG::get_option();
|
86 |
+
$items = array("3", "5", "7","10", "15", "20");
|
87 |
+
echo "<select id='wng_number' name='whats_new_options[wng_number]'>";
|
88 |
+
foreach($items as $item) {
|
89 |
+
$selected = ($options['wng_number']==$item) ? 'selected="selected"' : '';
|
90 |
+
echo "<option value='$item' $selected>$item</option>";
|
91 |
+
}
|
92 |
+
echo "</select>";
|
93 |
+
}
|
94 |
+
|
95 |
+
function setting_content_type() {
|
96 |
+
$options = WNG::get_option();
|
97 |
+
$items = array("投稿", "固定ページ", "投稿+固定ページ");
|
98 |
+
foreach($items as $item) {
|
99 |
+
$checked = ($options['wng_content_type']==$item) ? ' checked="checked" ' : '';
|
100 |
+
echo "<label><input {$checked} value='{$item}' name='whats_new_options[wng_content_type]' type='radio' /> $item</label><br />";
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
function setting_orderby() {
|
105 |
+
$options = WNG::get_option();
|
106 |
+
$items = array("公開日順", "更新日順");
|
107 |
+
foreach($items as $item) {
|
108 |
+
$checked = ($options['wng_orderby']==$item) ? ' checked="checked" ' : '';
|
109 |
+
echo "<label><input {$checked} value='{$item}' name='whats_new_options[wng_orderby]' type='radio' /> $item</label><br />";
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}
|
image/list.png
ADDED
Binary file
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link:
|
|
4 |
Tags: what's new, update Post page
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -39,6 +39,10 @@ What’s New Generatorは、投稿、固定ページ、ウィジェットに新
|
|
39 |
|
40 |
== Changelog ==
|
41 |
|
|
|
|
|
|
|
|
|
42 |
= 1.6.0 =
|
43 |
* 新着一覧の表示コンテンツに投稿+固定ページを追加
|
44 |
|
4 |
Tags: what's new, update Post page
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 1.7.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
39 |
|
40 |
== Changelog ==
|
41 |
|
42 |
+
= 1.7.0 =
|
43 |
+
* 新着一覧のタイトルに記事一覧へのリンクを表示する機能を追加
|
44 |
+
* カテゴリを指定するチェックボックスを削除
|
45 |
+
|
46 |
= 1.6.0 =
|
47 |
* 新着一覧の表示コンテンツに投稿+固定ページを追加
|
48 |
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|
whats-new-generator.php
CHANGED
@@ -1,117 +1,96 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
-
Plugin Name: What's New Generator
|
4 |
Plugin URI: http://residentbird.main.jp/bizplugin/
|
5 |
Description: What's New(新着情報)を指定した固定ページや投稿に自動的に表示するプラグインです。
|
6 |
-
Version: 1.
|
7 |
Author:WordPress Biz Plugin
|
8 |
Author URI: http://residentbird.main.jp/bizplugin/
|
9 |
*/
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
public function __construct(){
|
22 |
-
register_activation_hook(__FILE__, array(&$this,'on_activation')); //プラグイン有効時の処理を設定
|
23 |
-
register_deactivation_hook(__FILE__, array(&$this,'on_deactivation'));
|
24 |
-
add_action( 'admin_init', array(&$this,'on_admin_init') ); //管理画面の初期化
|
25 |
-
add_action( 'admin_menu', array(&$this, 'on_admin_menu')); //管理画面にメニューを追加
|
26 |
-
add_action('wp_print_styles', array(&$this,'on_print_styles')); //cssの設定(管理画面以外)
|
27 |
-
add_shortcode($this->shortcode, array(&$this,'show_shortcode')); //ショートコードの設定
|
28 |
-
add_filter('widget_text', 'do_shortcode');
|
29 |
}
|
30 |
|
31 |
-
function
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
}
|
35 |
|
36 |
-
function
|
37 |
-
|
38 |
-
|
39 |
-
/* CSSファイルが存在すれば、関数呼び出しでCSSを追加する */
|
40 |
-
if(file_exists($cssPath)){
|
41 |
-
/* CSSの格納URL */
|
42 |
-
$cssUrl = plugins_url('whats-new.css', __FILE__);
|
43 |
-
/* CSS登録 */
|
44 |
-
wp_register_style('whats-new-style', $cssUrl);
|
45 |
-
/* CSS追加 */
|
46 |
-
wp_enqueue_style('whats-new-style');
|
47 |
-
}
|
48 |
}
|
49 |
|
50 |
-
function
|
51 |
-
wp_enqueue_style( 'whats-new-style' );
|
52 |
wp_enqueue_style( 'wp-color-picker' );
|
|
|
53 |
wp_enqueue_script( 'whats-new-admin-js', plugins_url('whats-new-admin.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
|
54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
function on_activation() {
|
57 |
-
$
|
58 |
-
if(
|
59 |
-
|
60 |
-
"wng_title" => "新着情報",
|
61 |
-
"wng_content_type" => "投稿",
|
62 |
-
"wng_orderby" => "公開日順",
|
63 |
-
"wng_category_chk" => "",
|
64 |
-
"wng_category_name" => "",
|
65 |
-
"wng_background_color" => "#f5f5f5",
|
66 |
-
"wng_newmark" => "7",
|
67 |
-
"wng_number" => "10"
|
68 |
-
);
|
69 |
-
update_option($this->option_name, $arr);
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
|
73 |
function on_admin_init() {
|
74 |
-
|
75 |
-
|
76 |
-
add_settings_field('wng_title', 'タイトル', array(&$this,'setting_title'), __FILE__, 'main_section');
|
77 |
-
add_settings_field('wng_background_color', 'タイトル背景色', array(&$this,'setting_background_color'), __FILE__, 'main_section');
|
78 |
-
add_settings_field('wng_content_type', '表示するコンテンツ', array(&$this,'setting_content_type'), __FILE__, 'main_section');
|
79 |
-
add_settings_field('wng_category', ' カテゴリーを指定する', array(&$this,'setting_category_chk'), __FILE__, 'main_section');
|
80 |
-
add_settings_field('wng_category_name', ' カテゴリーのスラッグ', array(&$this,'setting_category_name'), __FILE__, 'main_section');
|
81 |
-
add_settings_field('wng_orderby', '表示順序', array(&$this,'setting_orderby'), __FILE__, 'main_section');
|
82 |
-
add_settings_field('wng_number', '表示件数', array(&$this,'setting_number'), __FILE__, 'main_section');
|
83 |
-
add_settings_field('wng_newmark', 'NEW!マーク表示期間', array(&$this,'setting_newmark'), __FILE__, 'main_section');
|
84 |
-
wp_register_style( 'whats-new-style', plugins_url('whats-new.css', __FILE__) );
|
85 |
-
}
|
86 |
-
|
87 |
-
function validate($input) {
|
88 |
-
if(!preg_match('/^#[a-f0-9]{6}$/i', $input['wng_background_color'])){
|
89 |
-
$input['wng_background_color'] = "#f5f5f5";
|
90 |
-
}
|
91 |
-
if ( !is_numeric( $input['wng_newmark']) || $input['wng_newmark'] < 0){
|
92 |
-
$input['wng_newmark'] = 0;
|
93 |
-
}
|
94 |
-
if ($input['wng_newmark'] > 30 ){
|
95 |
-
$input['wng_newmark'] = 30;
|
96 |
-
}
|
97 |
-
return $input; // return validated input
|
98 |
}
|
99 |
|
100 |
public function on_admin_menu() {
|
101 |
-
|
102 |
-
add_action( 'admin_print_styles-' . $page, array(&$this,'myplugin_admin_styles') );
|
103 |
}
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
$this->show_whatsnew();
|
111 |
}
|
112 |
|
113 |
function show_whatsnew(){
|
114 |
-
$info = new WhatsNewInfo(
|
115 |
include('whatsnew-view.php');
|
116 |
}
|
117 |
|
@@ -122,79 +101,6 @@ class WhatsNewPlugin{
|
|
122 |
ob_end_clean();
|
123 |
return $contents;
|
124 |
}
|
125 |
-
|
126 |
-
// Section HTML, displayed before the first option
|
127 |
-
function section_text_fn() {
|
128 |
-
//echo '<p>Below are some examples of different option controls.</p>';
|
129 |
-
}
|
130 |
-
|
131 |
-
// TEXTBOX - Name: whats_new_options[text_string]
|
132 |
-
function setting_title() {
|
133 |
-
$options = get_option($this->option_name);
|
134 |
-
$value = esc_html( $options["wng_title"] );
|
135 |
-
echo "<input id='wng_title' name='whats_new_options[wng_title]' size='40' type='text' value='{$value}' />";
|
136 |
-
}
|
137 |
-
|
138 |
-
function setting_background_color() {
|
139 |
-
$options = get_option($this->option_name);
|
140 |
-
$value = esc_html( $options["wng_background_color"] );
|
141 |
-
echo "<input id='wng_background_color' name='whats_new_options[wng_background_color]' size='10' type='text' value='{$value}' />";
|
142 |
-
}
|
143 |
-
|
144 |
-
function setting_newmark() {
|
145 |
-
$options = get_option($this->option_name);
|
146 |
-
$value = esc_html( $options["wng_newmark"] );
|
147 |
-
echo "<input id='wng_newmark' name='whats_new_options[wng_newmark]' size='2' type='text' value='{$value}' />日間";
|
148 |
-
}
|
149 |
-
|
150 |
-
|
151 |
-
function setting_category_chk() {
|
152 |
-
$id = "wng_category_chk";
|
153 |
-
$options = get_option($this->option_name);
|
154 |
-
$checked = (isset($options[$id]) && $options[$id]) ? $checked = ' checked="checked" ': "";
|
155 |
-
$name = $this->option_name. "[$id]";
|
156 |
-
|
157 |
-
echo "<input ".$checked." id='id_".$id."' name='".$name."' type='checkbox' />";
|
158 |
-
}
|
159 |
-
|
160 |
-
// TEXTBOX - Name: whats_new_options[text_string]
|
161 |
-
function setting_category_name() {
|
162 |
-
$options = get_option($this->option_name);
|
163 |
-
$value = esc_html( $options["wng_category_name"] );
|
164 |
-
echo "<input id='wng_category_name' name='whats_new_options[wng_category_name]' size='40' type='text' value='{$value}' />";
|
165 |
-
}
|
166 |
-
|
167 |
-
|
168 |
-
// DROP-DOWN-BOX - Name: whats_new_options[dropdown1]
|
169 |
-
function setting_number() {
|
170 |
-
$options = get_option($this->option_name);
|
171 |
-
$items = array("3", "5", "7","10", "15", "20");
|
172 |
-
echo "<select id='wng_number' name='whats_new_options[wng_number]'>";
|
173 |
-
foreach($items as $item) {
|
174 |
-
$selected = ($options['wng_number']==$item) ? 'selected="selected"' : '';
|
175 |
-
echo "<option value='$item' $selected>$item</option>";
|
176 |
-
}
|
177 |
-
echo "</select>";
|
178 |
-
}
|
179 |
-
|
180 |
-
// RADIO-BUTTON - Name: whats_new_options[option_set1]
|
181 |
-
function setting_content_type() {
|
182 |
-
$options = get_option($this->option_name);
|
183 |
-
$items = array("投稿", "固定ページ", "投稿+固定ページ");
|
184 |
-
foreach($items as $item) {
|
185 |
-
$checked = ($options['wng_content_type']==$item) ? ' checked="checked" ' : '';
|
186 |
-
echo "<label><input ".$checked." value='$item' name='whats_new_options[wng_content_type]' type='radio' /> $item</label><br />";
|
187 |
-
}
|
188 |
-
}
|
189 |
-
|
190 |
-
function setting_orderby() {
|
191 |
-
$options = get_option($this->option_name);
|
192 |
-
$items = array("公開日順", "更新日順");
|
193 |
-
foreach($items as $item) {
|
194 |
-
$checked = ($options['wng_orderby']==$item) ? ' checked="checked" ' : '';
|
195 |
-
echo "<label><input ".$checked." value='$item' name='whats_new_options[wng_orderby]' type='radio' /> $item</label><br />";
|
196 |
-
}
|
197 |
-
}
|
198 |
}
|
199 |
|
200 |
/**
|
@@ -203,48 +109,35 @@ class WhatsNewPlugin{
|
|
203 |
*/
|
204 |
class WhatsNewInfo{
|
205 |
var $title;
|
206 |
-
var $num;
|
207 |
-
var $content_type;
|
208 |
-
var $orderby;
|
209 |
-
var $category_chk;
|
210 |
-
var $category_name;
|
211 |
var $background_color;
|
|
|
212 |
var $items = array();
|
213 |
|
214 |
-
public function __construct(
|
215 |
-
$options = get_option(
|
216 |
-
$this->num = $options['wng_number'];
|
217 |
-
$this->content_type = $options['wng_content_type'];
|
218 |
-
$this->orderby = $options['wng_orderby'];
|
219 |
$this->title = esc_html( $options['wng_title'] );
|
220 |
-
$this->category_chk = isset($options['wng_category_chk']) ? $options['wng_category_chk'] : "";
|
221 |
-
$this->category_name = $options['wng_category_name'];
|
222 |
$this->background_color = $options['wng_background_color'];
|
223 |
-
$this->
|
224 |
-
}
|
225 |
|
226 |
-
private function createWhatsNewItems($option_name){
|
227 |
$condition = array();
|
228 |
-
if ( $
|
229 |
$condition['post_type'] = 'post';
|
230 |
-
}else if ( $
|
231 |
$condition['post_type'] = 'page';
|
232 |
}else{
|
233 |
$condition['post_type'] = array('page', 'post');
|
234 |
}
|
235 |
-
$condition['numberposts'] = $
|
236 |
$condition['order'] = 'desc';
|
237 |
-
$condition['orderby'] = $
|
238 |
-
|
239 |
-
$condition['category_name'] = $this->category_name;
|
240 |
-
}
|
241 |
|
242 |
$posts = get_posts( $condition );
|
243 |
if ( !is_array($posts) ){
|
244 |
return;
|
245 |
}
|
246 |
foreach($posts as $post){
|
247 |
-
$this->items[] = new WhatsNewItem($post
|
248 |
}
|
249 |
}
|
250 |
}
|
@@ -260,16 +153,18 @@ class WhatsNewItem{
|
|
260 |
var $url;
|
261 |
var $newmark;
|
262 |
|
263 |
-
public function __construct( $post
|
|
|
|
|
264 |
$this->raw_date = $orderby == '公開日順' ? $post->post_date : $post->post_modified;
|
265 |
$this->date = date("Y年n月j日", strtotime($this->raw_date));
|
266 |
$this->title = esc_html( $post->post_title );
|
267 |
$this->url = get_permalink($post->ID);
|
268 |
-
$this->newmark = $this->is_new(
|
269 |
}
|
270 |
|
271 |
-
public function is_new(
|
272 |
-
$options = get_option(
|
273 |
$term = $options['wng_newmark'];
|
274 |
if ( !isset($term) || $term == 0){
|
275 |
return false;
|
1 |
<?php
|
2 |
/*
|
3 |
+
Plugin Name: What's New Generator
|
4 |
Plugin URI: http://residentbird.main.jp/bizplugin/
|
5 |
Description: What's New(新着情報)を指定した固定ページや投稿に自動的に表示するプラグインです。
|
6 |
+
Version: 1.7.0
|
7 |
Author:WordPress Biz Plugin
|
8 |
Author URI: http://residentbird.main.jp/bizplugin/
|
9 |
*/
|
10 |
|
11 |
+
include_once "admin-ui.php";
|
12 |
+
new WhatsNewPlugin();
|
13 |
|
14 |
+
class WNG
|
15 |
+
{
|
16 |
+
const SHORTCODE = "showwhatsnew";
|
17 |
+
const OPTIONS = "whats_new_options";
|
18 |
|
19 |
+
public static function get_option(){
|
20 |
+
return get_option(self::OPTIONS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
+
public static function update_option( $options ){
|
24 |
+
if ( empty($options)){
|
25 |
+
return;
|
26 |
+
}
|
27 |
+
update_option(self::OPTIONS, $options);
|
28 |
}
|
29 |
|
30 |
+
public static function enqueue_css_js(){
|
31 |
+
wp_enqueue_style( 'whats-new-style', plugins_url('whats-new.css', __FILE__ ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
+
public static function enqueue_admin_css_js(){
|
|
|
35 |
wp_enqueue_style( 'wp-color-picker' );
|
36 |
+
wp_enqueue_style( 'whats-new-style', plugins_url('whats-new.css', __FILE__ ) );
|
37 |
wp_enqueue_script( 'whats-new-admin-js', plugins_url('whats-new-admin.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
|
38 |
}
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
/**
|
43 |
+
* プラグイン本体
|
44 |
+
*/
|
45 |
+
class WhatsNewPlugin{
|
46 |
+
|
47 |
+
var $adminUi;
|
48 |
+
|
49 |
+
public function __construct(){
|
50 |
+
register_activation_hook(__FILE__, array(&$this,'on_activation'));
|
51 |
+
add_action( 'admin_init', array(&$this,'on_admin_init') );
|
52 |
+
add_action( 'admin_menu', array(&$this, 'on_admin_menu'));
|
53 |
+
add_action( 'wp_enqueue_scripts', array(&$this,'on_enqueue_scripts'));
|
54 |
+
add_shortcode( WNG::SHORTCODE, array(&$this,'show_shortcode'));
|
55 |
+
add_filter( 'widget_text', 'do_shortcode');
|
56 |
+
}
|
57 |
|
58 |
function on_activation() {
|
59 |
+
$option = WNG::get_option();
|
60 |
+
if($option) {
|
61 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
+
$arr = array(
|
64 |
+
"wng_title" => "新着情報",
|
65 |
+
"wng_content_type" => "投稿",
|
66 |
+
"wng_orderby" => "公開日順",
|
67 |
+
"wng_category_name" => "",
|
68 |
+
"wng_background_color" => "#f5f5f5",
|
69 |
+
"wng_newmark" => "7",
|
70 |
+
"wng_postlist_url" => "",
|
71 |
+
"wng_number" => "10"
|
72 |
+
);
|
73 |
+
WNG::update_option( $arr );
|
74 |
}
|
75 |
|
76 |
function on_admin_init() {
|
77 |
+
WNG::enqueue_admin_css_js();
|
78 |
+
$this->adminUi = new WNGAdminUi(__FILE__);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
|
81 |
public function on_admin_menu() {
|
82 |
+
add_options_page("What's New 設定", "What's New 設定", 'administrator', __FILE__, array(&$this->adminUi, 'show_admin_page'));
|
|
|
83 |
}
|
84 |
|
85 |
+
function on_enqueue_scripts() {
|
86 |
+
if ( is_admin() ){
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
WNG::enqueue_css_js();
|
|
|
90 |
}
|
91 |
|
92 |
function show_whatsnew(){
|
93 |
+
$info = new WhatsNewInfo();
|
94 |
include('whatsnew-view.php');
|
95 |
}
|
96 |
|
101 |
ob_end_clean();
|
102 |
return $contents;
|
103 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
/**
|
109 |
*/
|
110 |
class WhatsNewInfo{
|
111 |
var $title;
|
|
|
|
|
|
|
|
|
|
|
112 |
var $background_color;
|
113 |
+
var $postlist_url;
|
114 |
var $items = array();
|
115 |
|
116 |
+
public function __construct(){
|
117 |
+
$options = WNG::get_option();
|
|
|
|
|
|
|
118 |
$this->title = esc_html( $options['wng_title'] );
|
|
|
|
|
119 |
$this->background_color = $options['wng_background_color'];
|
120 |
+
$this->postlist_url = $options['wng_postlist_url'];
|
|
|
121 |
|
|
|
122 |
$condition = array();
|
123 |
+
if ( $options['wng_content_type'] == '投稿'){
|
124 |
$condition['post_type'] = 'post';
|
125 |
+
}else if ( $options['wng_content_type'] == '固定ページ' ){
|
126 |
$condition['post_type'] = 'page';
|
127 |
}else{
|
128 |
$condition['post_type'] = array('page', 'post');
|
129 |
}
|
130 |
+
$condition['numberposts'] = $options['wng_number'];
|
131 |
$condition['order'] = 'desc';
|
132 |
+
$condition['orderby'] = $options['wng_orderby'] == '公開日順' ? 'post_date' : 'modified';
|
133 |
+
$condition['category_name'] = $options['wng_category_name'];
|
|
|
|
|
134 |
|
135 |
$posts = get_posts( $condition );
|
136 |
if ( !is_array($posts) ){
|
137 |
return;
|
138 |
}
|
139 |
foreach($posts as $post){
|
140 |
+
$this->items[] = new WhatsNewItem($post);
|
141 |
}
|
142 |
}
|
143 |
}
|
153 |
var $url;
|
154 |
var $newmark;
|
155 |
|
156 |
+
public function __construct( $post ){
|
157 |
+
$options = WNG::get_option();
|
158 |
+
$orderby = $options['wng_orderby'];
|
159 |
$this->raw_date = $orderby == '公開日順' ? $post->post_date : $post->post_modified;
|
160 |
$this->date = date("Y年n月j日", strtotime($this->raw_date));
|
161 |
$this->title = esc_html( $post->post_title );
|
162 |
$this->url = get_permalink($post->ID);
|
163 |
+
$this->newmark = $this->is_new();
|
164 |
}
|
165 |
|
166 |
+
public function is_new(){
|
167 |
+
$options = WNG::get_option();
|
168 |
$term = $options['wng_newmark'];
|
169 |
if ( !isset($term) || $term == 0){
|
170 |
return false;
|
whats-new.css
CHANGED
@@ -10,9 +10,7 @@ div.whatsnew {
|
|
10 |
font-size: 100%;
|
11 |
}
|
12 |
|
13 |
-
|
14 |
-
font-weight: bold;
|
15 |
-
font-size: 110%;
|
16 |
margin: 0;
|
17 |
padding: 5px 10px;
|
18 |
background-color: WhiteSmoke;
|
@@ -29,6 +27,33 @@ p.whatsnewtitle {
|
|
29 |
-moz-border-radius-topright: 5px; /* 右上 */
|
30 |
}
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
div.whatsnew dl {
|
33 |
margin: 5px 0;
|
34 |
padding: 0;
|
@@ -36,11 +61,11 @@ div.whatsnew dl {
|
|
36 |
}
|
37 |
|
38 |
div.whatsnew dt {
|
39 |
-
margin: 0
|
40 |
padding: 0;
|
41 |
border: 0;
|
42 |
float: left;
|
43 |
-
width:
|
44 |
font-weight: normal;
|
45 |
}
|
46 |
|
10 |
font-size: 100%;
|
11 |
}
|
12 |
|
13 |
+
div.whatsnewtitle {
|
|
|
|
|
14 |
margin: 0;
|
15 |
padding: 5px 10px;
|
16 |
background-color: WhiteSmoke;
|
27 |
-moz-border-radius-topright: 5px; /* 右上 */
|
28 |
}
|
29 |
|
30 |
+
div.wntitle {
|
31 |
+
font-weight: bold;
|
32 |
+
font-size: 100%;
|
33 |
+
text-align: left;
|
34 |
+
float:left;
|
35 |
+
}
|
36 |
+
|
37 |
+
div.all-post {
|
38 |
+
background: transparent url('./image/list.png') left center no-repeat;
|
39 |
+
padding-left:1.3em;
|
40 |
+
font-weight: normal;
|
41 |
+
font-size: 90%;
|
42 |
+
text-align: right;
|
43 |
+
cursor: pointer;
|
44 |
+
float:right;
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
div.whatsnew dd:after, div.whatsnewtitle:after {
|
49 |
+
content: "";
|
50 |
+
clear: both;
|
51 |
+
height: 0;
|
52 |
+
display: block;
|
53 |
+
visibility: hidden;
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
div.whatsnew dl {
|
58 |
margin: 5px 0;
|
59 |
padding: 0;
|
61 |
}
|
62 |
|
63 |
div.whatsnew dt {
|
64 |
+
margin: 0 0 0 0.5em;
|
65 |
padding: 0;
|
66 |
border: 0;
|
67 |
float: left;
|
68 |
+
width: 8.5em;
|
69 |
font-weight: normal;
|
70 |
}
|
71 |
|
whatsnew-view.php
CHANGED
@@ -1,10 +1,16 @@
|
|
1 |
<div class='whatsnew'>
|
2 |
-
<
|
3 |
-
<?php if (!empty($info->background_color)){
|
4 |
echo "style='background-color: {$info->background_color};'";
|
5 |
}?>>
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
<dl>
|
10 |
<?php foreach($info->items as $item): ?>
|
@@ -13,7 +19,7 @@
|
|
13 |
</dt>
|
14 |
<dd>
|
15 |
<?php if ( $item->newmark ): ?>
|
16 |
-
<span class='newmark'
|
17 |
<?php endif; ?>
|
18 |
<a href="<?php echo $item->url; ?>"><?php echo $item->title; ?> </a>
|
19 |
</dd>
|
1 |
<div class='whatsnew'>
|
2 |
+
<div class='whatsnewtitle' <?php if (!empty($info->background_color)){
|
|
|
3 |
echo "style='background-color: {$info->background_color};'";
|
4 |
}?>>
|
5 |
+
<div class='wntitle'>
|
6 |
+
<?php echo $info->title; ?>
|
7 |
+
</div>
|
8 |
+
<?php if (!empty($info->postlist_url)): ?>
|
9 |
+
<div class='all-post'>
|
10 |
+
<a href="<?php echo $info->postlist_url; ?>">一覧へ</a>
|
11 |
+
</div>
|
12 |
+
<?php endif; ?>
|
13 |
+
</div>
|
14 |
|
15 |
<dl>
|
16 |
<?php foreach($info->items as $item): ?>
|
19 |
</dt>
|
20 |
<dd>
|
21 |
<?php if ( $item->newmark ): ?>
|
22 |
+
<span class='newmark'>NEW!</span>
|
23 |
<?php endif; ?>
|
24 |
<a href="<?php echo $item->url; ?>"><?php echo $item->title; ?> </a>
|
25 |
</dd>
|