What's New Generator - Version 1.3.0

Version Description

  • Added filter fook for widget
Download this release

Release Info

Developer hidaka.bizplugin
Plugin Icon wp plugin What's New Generator
Version 1.3.0
Comparing to
See all releases

Version 1.3.0

Files changed (5) hide show
  1. admin-view.php +20 -0
  2. readme.txt +44 -0
  3. whats-new-generator.php +241 -0
  4. whats-new.css +49 -0
  5. whatsnew-view.php +19 -0
admin-view.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <div class="icon32" id="icon-options-general">
3
+ <br>
4
+ </div>
5
+ <h2>What's New Generator 設定</h2>
6
+ <h3>ショートコード</h3>
7
+ <p>以下のコードをコピーして、What's Newを表示する固定ページや投稿の本文内に貼り付けてください。</p>
8
+ <p>
9
+ <input type="text" value=<?php echo $shortcode;?> readonly></input>
10
+ </p>
11
+ <form action="options.php" method="post">
12
+ <?php settings_fields( $option_name ); ?>
13
+ <?php do_settings_sections( $file ); ?>
14
+ <p class="submit">
15
+ <input name="Submit" type="submit" class="button-primary"
16
+ value="<?php esc_attr_e('Save Changes'); ?>" />
17
+ </p>
18
+ </form>
19
+ <h3>プレビュー</h3>
20
+ </div>
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === What's New Generator ===
2
+ Contributors: WordPress BizPlugin
3
+ Donate link:
4
+ Tags: what's new, update
5
+ Requires at least: 3.4
6
+ Tested up to: 3.4.2
7
+ Stable tag: 1.3.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ This plug-in creates the latest information of your site in the page by shortcode.
12
+
13
+ == Description ==
14
+
15
+ This plug-in creates the latest information of your site in the page by shortcode.
16
+
17
+ = Features =
18
+
19
+ * Select what's new from posts or pages
20
+ * Select the number of what's new items
21
+ * Preview what's new on admin page
22
+
23
+ == Installation ==
24
+
25
+ 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
26
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
27
+
28
+ == Changelog ==
29
+
30
+ = 1.3.0 =
31
+ * Added filter fook for widget
32
+
33
+ = 1.2.0 =
34
+ * Added feature to change a background color
35
+
36
+ = 1.1.0 =
37
+ * Added categories option
38
+ * Changed styles of what's new
39
+
40
+ = 1.0.0 =
41
+ * First release.
42
+
43
+ == Usage ==
44
+ Full Usage instructions and documentation can be found here: http://residentbird.main.jp/bizplugin/plugins/whats-new-generator/
whats-new-generator.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.0
7
+ Author:WordPress Biz Plugin
8
+ Author URI: http://residentbird.main.jp/bizplugin/
9
+ */
10
+
11
+ $whatsNewPlugin = new WhatsNewPlugin();
12
+
13
+ /**
14
+ * プラグイン本体
15
+ */
16
+ class WhatsNewPlugin{
17
+
18
+ var $shortcode = "showwhatsnew";
19
+ var $option_name = 'whats_new_options';
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 on_deactivation(){
32
+ unregister_setting($this->option_name, $this->option_name );
33
+ //delete_option($this->option_name);
34
+ wp_deregister_style('whats-new-style');
35
+ }
36
+
37
+ function on_print_styles() {
38
+ $cssPath = WP_PLUGIN_DIR . '/whats-new-genarator/whats-new.css';
39
+
40
+ /* CSSファイルが存在すれば、関数呼び出しでCSSを追加する */
41
+ if(file_exists($cssPath)){
42
+ /* CSSの格納URL */
43
+ $cssUrl = plugins_url('whats-new.css', __FILE__);
44
+ /* CSS登録 */
45
+ wp_register_style('whats-new-style', $cssUrl);
46
+ /* CSS追加 */
47
+ wp_enqueue_style('whats-new-style');
48
+ }
49
+ }
50
+
51
+ function myplugin_admin_styles() {
52
+ wp_enqueue_style( 'whats-new-style' );
53
+ }
54
+
55
+ function on_activation() {
56
+ $tmp = get_option($this->option_name);
57
+ if(!is_array($tmp)) {
58
+ $arr = array(
59
+ "wng_title" => "新着情報",
60
+ "wng_content_type" => "投稿",
61
+ "wng_orderby" => "公開日順",
62
+ "wng_category_chk" => "",
63
+ "wng_category_name" => "",
64
+ "wng_background_color" => "#f5f5f5",
65
+ "wng_number" => "10"
66
+ );
67
+ update_option($this->option_name, $arr);
68
+ }
69
+ }
70
+
71
+ function on_admin_init() {
72
+ register_setting($this->option_name, $this->option_name);
73
+ add_settings_section('main_section', '表示設定', array(&$this,'section_text_fn'), __FILE__);
74
+ add_settings_field('wng_title', 'タイトル', array(&$this,'setting_title'), __FILE__, 'main_section');
75
+ add_settings_field('wng_background_color', 'タイトル背景色', array(&$this,'setting_background_color'), __FILE__, 'main_section');
76
+ add_settings_field('wng_content_type', '表示するコンテンツ', array(&$this,'setting_content_type'), __FILE__, 'main_section');
77
+ add_settings_field('wng_category', ' カテゴリーを指定する', array(&$this,'setting_category_chk'), __FILE__, 'main_section');
78
+ add_settings_field('wng_category_name', ' カテゴリーのスラッグ', array(&$this,'setting_category_name'), __FILE__, 'main_section');
79
+ add_settings_field('wng_orderby', '表示順序', array(&$this,'setting_orderby'), __FILE__, 'main_section');
80
+ add_settings_field('wng_number', '表示件数', array(&$this,'setting_number'), __FILE__, 'main_section');
81
+ wp_register_style( 'whats-new-style', plugins_url('whats-new.css', __FILE__) );
82
+ }
83
+
84
+
85
+ public function on_admin_menu() {
86
+ $page = add_options_page("What's New 設定", "What's New 設定", 'administrator', __FILE__, array(&$this, 'show_admin_page'));
87
+ add_action( 'admin_print_styles-' . $page, array(&$this,'myplugin_admin_styles') );
88
+ }
89
+
90
+ public function show_admin_page() {
91
+ $file = __FILE__;
92
+ $option_name = $this->option_name;
93
+ $shortcode = "[" . $this->shortcode . "]";
94
+ include_once('admin-view.php');
95
+ $this->show_whatsnew();
96
+ }
97
+
98
+ function show_whatsnew(){
99
+ $info = new WhatsNewInfo($this->option_name);
100
+ include('whatsnew-view.php');
101
+ }
102
+
103
+ function show_shortcode(){
104
+ ob_start();
105
+ $this->show_whatsnew();
106
+ $contents = ob_get_contents();
107
+ ob_end_clean();
108
+ return $contents;
109
+ }
110
+
111
+ // Section HTML, displayed before the first option
112
+ function section_text_fn() {
113
+ //echo '<p>Below are some examples of different option controls.</p>';
114
+ }
115
+
116
+ // TEXTBOX - Name: whats_new_options[text_string]
117
+ function setting_title() {
118
+ $options = get_option($this->option_name);
119
+ $value = esc_html( $options["wng_title"] );
120
+ echo "<input id='wng_title' name='whats_new_options[wng_title]' size='40' type='text' value='{$value}' />";
121
+ }
122
+
123
+ function setting_background_color() {
124
+ $options = get_option($this->option_name);
125
+ $value = esc_html( $options["wng_background_color"] );
126
+ echo "<input id='wng_background_color' name='whats_new_options[wng_background_color]' size='10' type='text' value='{$value}' />";
127
+ }
128
+
129
+
130
+ function setting_category_chk() {
131
+ $id = "wng_category_chk";
132
+ $options = get_option($this->option_name);
133
+ $checked = (isset($options[$id]) && $options[$id]) ? $checked = ' checked="checked" ': "";
134
+ $name = $this->option_name. "[$id]";
135
+
136
+ echo "<input ".$checked." id='id_".$id."' name='".$name."' type='checkbox' />";
137
+ }
138
+
139
+ // TEXTBOX - Name: whats_new_options[text_string]
140
+ function setting_category_name() {
141
+ $options = get_option($this->option_name);
142
+ $value = esc_html( $options["wng_category_name"] );
143
+ echo "<input id='wng_category_name' name='whats_new_options[wng_category_name]' size='40' type='text' value='{$value}' />";
144
+ }
145
+
146
+
147
+ // DROP-DOWN-BOX - Name: whats_new_options[dropdown1]
148
+ function setting_number() {
149
+ $options = get_option($this->option_name);
150
+ $items = array("5", "10", "15", "20");
151
+ echo "<select id='wng_number' name='whats_new_options[wng_number]'>";
152
+ foreach($items as $item) {
153
+ $selected = ($options['wng_number']==$item) ? 'selected="selected"' : '';
154
+ echo "<option value='$item' $selected>$item</option>";
155
+ }
156
+ echo "</select>";
157
+ }
158
+
159
+ // RADIO-BUTTON - Name: whats_new_options[option_set1]
160
+ function setting_content_type() {
161
+ $options = get_option($this->option_name);
162
+ $items = array("投稿", "固定ページ");
163
+ foreach($items as $item) {
164
+ $checked = ($options['wng_content_type']==$item) ? ' checked="checked" ' : '';
165
+ echo "<label><input ".$checked." value='$item' name='whats_new_options[wng_content_type]' type='radio' /> $item</label><br />";
166
+ }
167
+ }
168
+
169
+ function setting_orderby() {
170
+ $options = get_option($this->option_name);
171
+ $items = array("公開日順", "更新日順");
172
+ foreach($items as $item) {
173
+ $checked = ($options['wng_orderby']==$item) ? ' checked="checked" ' : '';
174
+ echo "<label><input ".$checked." value='$item' name='whats_new_options[wng_orderby]' type='radio' /> $item</label><br />";
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * What's New に表示する内容
181
+ *
182
+ */
183
+ class WhatsNewInfo{
184
+ var $title;
185
+ var $num;
186
+ var $content_type;
187
+ var $orderby;
188
+ var $category_chk;
189
+ var $category_name;
190
+ var $background_color;
191
+ var $items = array();
192
+
193
+ public function __construct($option_name){
194
+ $options = get_option($option_name);
195
+ $this->num = $options['wng_number'];
196
+ $this->content_type = $options['wng_content_type'];
197
+ $this->orderby = $options['wng_orderby'];
198
+ $this->title = esc_html( $options['wng_title'] );
199
+ $this->category_chk = isset($options['wng_category_chk']) ? $options['wng_category_chk'] : "";
200
+ $this->category_name = $options['wng_category_name'];
201
+ $this->background_color = $options['wng_background_color'];
202
+ $this->createWhatsNewItems();
203
+ }
204
+
205
+ private function createWhatsNewItems(){
206
+ $condition = array();
207
+ $condition['post_type'] = $this->content_type == '投稿' ? 'post' : 'page';
208
+ $condition['numberposts'] = $this->num;
209
+ $condition['order'] = 'desc';
210
+ $condition['orderby'] = $this->orderby == '公開日順' ? 'post_date' : 'modified';
211
+ if ( $this->content_type == '投稿' && $this->category_chk == 'on' && $this->category_name != ""){
212
+ $condition['category_name'] = $this->category_name;
213
+ }
214
+
215
+ $posts = get_posts( $condition );
216
+ if ( !is_array($posts) ){
217
+ return;
218
+ }
219
+ foreach($posts as $post){
220
+ $this->items[] = new WhatsNewItem($post, $this->orderby);
221
+ }
222
+ }
223
+ }
224
+
225
+ /**
226
+ * 個々のWhat's New項目の内容
227
+ *
228
+ */
229
+ class WhatsNewItem{
230
+ var $date;
231
+ var $title;
232
+ var $url;
233
+
234
+ public function __construct( $post, $orderby ){
235
+ $this->date = $orderby == '公開日順' ? $post->post_date : $post->post_modified;
236
+ $this->date = date("Y年n月j日", strtotime($this->date));
237
+ $this->title = esc_html( $post->post_title );
238
+ $this->url = get_permalink($post->ID);
239
+ }
240
+ }
241
+ ?>
whats-new.css ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @CHARSET "UTF-8";
2
+
3
+ div.whatsnew {
4
+ margin:10px 0;
5
+ background-color: White;
6
+ border-radius: 5px; /* CSS3 */
7
+ -webkit-border-radius: 5px; /* Safari,Google Chrome */
8
+ -moz-border-radius: 5px; /* Firefox */
9
+ border: 1px Silver solid;
10
+ font-size: 100%;
11
+ }
12
+
13
+ div.whatsnew h2 {
14
+ margin: 0;
15
+ padding: 5px 10px;
16
+ background-color: WhiteSmoke;
17
+ box-shadow: 1px 1px 4px #ccc;
18
+ -webkit-box-shadow: 1px 1px 4px #ccc;
19
+ -moz-box-shadow: 1px 1px 4px #ccc;
20
+ border: 0;
21
+ border-bottom: 1px Silver solid;
22
+ border-top-left-radius: 5px; /* 左上 */
23
+ border-top-right-radius: 5px; /* 右上 */
24
+ -webkit-border-top-left-radius: 5px; /* 左上 */
25
+ -webkit-border-top-right-radius: 5px; /* 右上 */
26
+ -moz-border-radius-topleft: 5px; /* 左上 */
27
+ -moz-border-radius-topright: 5px; /* 右上 */
28
+ font-size: 100%;
29
+ }
30
+
31
+ div.whatsnew dl {
32
+ margin: 5px 0;
33
+ padding: 0;
34
+ border: 0;
35
+ }
36
+
37
+ div.whatsnew dt {
38
+ margin: 0 7px;
39
+ padding: 0;
40
+ border: 0;
41
+ float: left;
42
+ width: 8em;
43
+ font-weight: normal;
44
+ }
45
+
46
+ div.whatsnew dd {
47
+ margin: 0;
48
+ padding: 0 0 0 9em;
49
+ }
whatsnew-view.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class='whatsnew'>
2
+ <h2
3
+ <?php if (!empty($info->background_color)){
4
+ echo "style='background-color: {$info->background_color};'";
5
+ }?>>
6
+ <?php echo $info->title; ?>
7
+ </h2>
8
+
9
+ <dl>
10
+ <?php foreach($info->items as $item): ?>
11
+ <dt>
12
+ <?php echo $item->date; ?>
13
+ </dt>
14
+ <dd>
15
+ <a href="<?php echo $item->url; ?>"><?php echo $item->title; ?> </a>
16
+ </dd>
17
+ <?php endforeach; ?>
18
+ </dl>
19
+ </div>