VK All in One Expansion Unit - Version 5.9.3

Version Description

Download this release

Release Info

Developer kurudrive
Plugin Icon 128x128 VK All in One Expansion Unit
Version 5.9.3
Comparing to
See all releases

Code changes from version 5.9.2 to 5.9.3

plugins/call-to-action/class-vk-call-to-action.php CHANGED
@@ -8,253 +8,270 @@ https://github.com/vektor-inc/vektor-wp-libraries
8
 
9
  // namespace Vektor\ExUnit\Package\Cta;
10
 
11
- if ( ! class_exists( 'Vk_Call_To_Action' ) )
12
- {
13
-
14
- class Vk_Call_To_Action
15
- {
16
- const POST_TYPE = 'cta';
17
-
18
- const CONTENT_NUMBER = 100;
19
-
20
- public static function init()
21
- {
22
- add_action( 'init', array( __CLASS__, 'set_posttype' ) );
23
- add_action( 'vkExUnit_package_init', array( __CLASS__, 'option_init' ) );
24
- add_action( 'admin_menu', array( __CLASS__, 'add_custom_field' ) );
25
- add_action( 'save_post', array( __CLASS__, 'save_custom_field' ) );
26
- add_action( 'widgets_init', array( __CLASS__, 'widget_init' ) );
27
- if( veu_content_filter_state() == 'content' )
28
- add_filter( 'the_content', array( __CLASS__, 'content_filter' ), self::CONTENT_NUMBER, 1 );
29
- else
30
- add_action( 'loop_end', array( __CLASS__, 'set_content_loopend' ), self::CONTENT_NUMBER, 1 );
31
- require_once dirname( __FILE__ ) . '/widget-call-to-action.php';
32
- }
33
 
34
- public static function widget_init() {
35
- return register_widget( 'Widget_CTA' );
36
- }
37
 
38
- public static function set_content_loopend($query )
39
- {
40
- if( ! $query->is_main_query() ) return;
41
- if( ! is_single() ) return;
42
- echo self::content_filter('');
43
- }
44
 
 
45
 
46
- public static function option_init()
47
- {
48
- vkExUnit_register_setting(
49
- 'Call To Action', // tab label.
50
- 'vkExUnit_cta_settings', // name attr
51
- array( __CLASS__, 'sanitize_config' ), // sanitaise function name
52
- array( __CLASS__, 'render_configPage' ) // setting_page function name
53
- );
54
- }
 
 
 
 
55
 
 
 
 
56
 
57
- public static function set_posttype()
58
- {
59
- global $vk_call_to_action_textdomain;
60
- $labels = array(
61
- 'name' => 'CTA',
62
- 'singular_name' => 'CTA',
63
- 'edit_item' => __( 'Edit CTA', $vk_call_to_action_textdomain ),
64
- 'add_new_item' => __( 'Add new CTA', $vk_call_to_action_textdomain ),
65
- 'new_item' => __( 'New CTA', $vk_call_to_action_textdomain ),
66
- );
67
-
68
- $args = array(
69
- 'labels' => $labels,
70
- 'public' => false,
71
- 'publicly_queryable' => false,
72
- 'has_archive' => true,
73
- 'show_ui' => true,
74
- 'show_in_menu' => true,
75
- 'menu_position' => 5,
76
- 'query_var' => true,
77
- 'rewrite' => true,
78
- 'capability_type' => 'post',
79
- 'has_archive' => false,
80
- 'hierarchical' => false,
81
- 'taxonomies' => array(),
82
- 'supports' => array( 'title' ),
83
- );
84
- register_post_type( self::POST_TYPE , $args );
85
- }
86
 
87
 
88
- public static function add_custom_field()
89
- {
90
- global $vk_call_to_action_textdomain;
91
- $post_types = get_post_types( array( '_builtin' => false, 'public' => true ) );
92
- while ( list($key, $post ) = each( $post_types ) ) {
93
- add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), $post, 'normal', 'high' );
 
94
  }
95
- add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), 'page', 'normal', 'high' );
96
- add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), 'post', 'normal', 'high' );
97
 
98
- add_meta_box( 'vkExUnit_cta_url', __( 'CTA Contents', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box_cta' ), self::POST_TYPE, 'normal', 'high' );
99
- }
100
 
101
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  * CTAメイン設定画面のurl
103
  * ExUnitと単体プラグインなどによって変動する
104
  * @return [type] [description]
105
  */
106
- public static function setting_page_url()
107
- {
108
- if ( veu_is_cta_active() ){
109
- $setting_page_url = admin_url( 'admin.php?page=vkExUnit_main_setting#vkExUnit_cta_settings' );
110
- } else {
111
- $setting_page_url = admin_url( 'options-general.php?page=vk_cta_options' );
 
112
  }
113
- return $setting_page_url;
114
- }
115
 
116
- public static function render_meta_box()
117
- {
118
- global $vk_call_to_action_textdomain;
119
- echo '<input type="hidden" name="_nonce_vkExUnit_custom_cta" id="_nonce_vkExUnit__custom_field_metaKeyword" value="'.wp_create_nonce( plugin_basename( __FILE__ ) ).'" />';
120
-
121
- $ctas = self::get_ctas( true, ' - ' );
122
- // ランダムを先頭に追加
123
- array_unshift( $ctas, array( 'key' => 'random', 'label' => __( 'Random', $vk_call_to_action_textdomain ) ) );
124
- array_unshift( $ctas, array( 'key' => 'disable', 'label' => __( 'Disable display', $vk_call_to_action_textdomain ) ) );
125
- array_unshift( $ctas, array( 'key' => 0, 'label' => __( 'Follow common setting', $vk_call_to_action_textdomain ) ) );
126
- $now = get_post_meta( get_the_id(),'vkexunit_cta_each_option', true );
127
- ?>
128
- <input type="hidden" name="_vkExUnit_cta_switch" value="cta_number" />
129
-
130
- <select name="vkexunit_cta_each_option" id="vkexunit_cta_each_option">
131
- <?php foreach ( $ctas as $cta ) : ?>
132
- <option value="<?php echo $cta['key'] ?>" <?php echo($cta['key'] == $now)? 'selected':''; ?> ><?php echo $cta['label'] ?></option>
133
- <?php endforeach; ?>
134
- </select>
135
- <p>
136
- <a href="<?php echo self::setting_page_url(); ?>" class="button button-default" target="_blank"><?php _e( 'CTA common setting', $vk_call_to_action_textdomain ); ?></a>
137
- <a href="<?php echo admin_url( 'edit.php?post_type=cta' ) ?>" class="button button-default" target="_blank"><?php _e( 'Show CTA index page', $vk_call_to_action_textdomain ); ?></a>
138
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  <?php
140
- }
141
 
142
 
143
- public static function render_meta_box_cta() {
144
-
145
- global $vk_call_to_action_textdomain;
146
-
147
- echo '<input type="hidden" name="_nonce_vkExUnit_custom_cta" id="_nonce_vkExUnit__custom_field_metaKeyword" value="'.wp_create_nonce( plugin_basename( __FILE__ ) ).'" />';
148
- $imgid = get_post_meta( get_the_id(), 'vkExUnit_cta_img', true );
149
- $cta_image = wp_get_attachment_image_src( $imgid, 'large' );
150
- $image_position = get_post_meta( get_the_id(), 'vkExUnit_cta_img_position', true );
151
- ?>
152
- <style>
153
- #message.updated a {display:none;}
154
- #thumbnail_box { max-width:300px; max-height:300px; }
155
- #cta-thumbnail_image { max-width:300px; max-height:300px; }
156
- #cta-thumbnail_image.noimage { display:none; }
157
- #cta-thumbnail_control.add #media_thumb_url_add { display:inline; }
158
- #cta-thumbnail_control.add #media_thumb_url_change,
159
- #cta-thumbnail_control.add #media_thumb_url_remove { display:none; }
160
- #cta-thumbnail_control.change #media_thumb_url_add { display:none; }
161
- #cta-thumbnail_control.change #media_thumb_url_change,
162
- #cta-thumbnail_control.change #media_thumb_url_remove { display:inline; }
163
- .form-table input[type=text],
164
- .form-table input[type=url],
165
- .form-table textarea { width:80%; }
166
- </style>
167
- <script type="text/javascript">
168
- jQuery(document).ready(function($){
169
- var custom_uploader;
170
- jQuery('.cta-media_btn').click(function(e) {
171
- e.preventDefault();
172
-
173
- if (custom_uploader) {
174
- custom_uploader.open();
175
- return;
176
- }
177
- custom_uploader = wp.media({
178
- title: 'Choose Image',
179
- library: {type: 'image'},
180
- button: {text: 'Choose Image'},
181
- multiple: false,
182
- });
183
-
184
- custom_uploader.on('select', function() {
185
- var images = custom_uploader.state().get('selection');
186
- images.each(function(file){
187
- jQuery('#cta-thumbnail_image').attr('src', file.toJSON().url).removeClass("noimage");
188
- jQuery('.vkExUnit_cta_img').val(file.toJSON().id);
189
- jQuery('#cta-thumbnail_control').removeClass("add").addClass("change");
190
- });
191
- });
192
- custom_uploader.open();
193
- });
194
- jQuery('#cta-thumbnail_control #media_thumb_url_remove').on('click', function(){
195
- jQuery('#cta-thumbnail_image').attr('src', '').addClass("noimage");
196
- jQuery('.vkExUnit_cta_img').val('');
197
- jQuery('#cta-thumbnail_control').removeClass("change").addClass("add");
198
- return false;
199
- });
200
- });
201
- </script>
202
- <input type="hidden" name="_vkExUnit_cta_switch" value="cta_content" />
203
- <table class="form-table">
204
- <tr>
205
- <th><?php _e( 'CTA image', $vk_call_to_action_textdomain ); ?></th>
206
- <td>
207
- <div id="cta-thumbnail_box" >
208
- <img id="cta-thumbnail_image" src="<?php echo ($cta_image)? $cta_image[0] : ''; ?>" class="<?php echo ($cta_image)? '' : 'noimage'; ?>" />
209
- </div>
210
- <div id="cta-thumbnail_control" class="<?php echo ($cta_image)? 'change' : 'add'; ?>">
211
  <button id="media_thumb_url_add" class="cta-media_btn button button-default"><?php _e( 'Add image', $vk_call_to_action_textdomain ); ?></button>
212
  <button id="media_thumb_url_change" class="cta-media_btn button button-default"><?php _e( 'Change image', $vk_call_to_action_textdomain ); ?></button>
213
  <button id="media_thumb_url_remove" class="button button-default"><?php _e( 'Remove image', $vk_call_to_action_textdomain ); ?></button>
214
- </div>
215
- <input type="hidden" name="vkExUnit_cta_img" class="vkExUnit_cta_img" value="<?php echo $imgid; ?>" />
216
- </td>
217
- </tr>
218
- <tr><th><label for="vkExUnit_cta_img_position"><?php _e( 'CTA image position', $vk_call_to_action_textdomain ); ?></label></th>
219
- <td>
220
- <select name="vkExUnit_cta_img_position" id="vkExUnit_cta_img_position">
221
- <option value="right" <?php echo ($image_position == 'right')? 'selected' : ''; ?> ><?php _e( 'right', $vk_call_to_action_textdomain ); ?></option>
222
- <option value="center" <?php echo ($image_position == 'center')? 'selected' : ''; ?> ><?php _e( 'center', $vk_call_to_action_textdomain ); ?></option>
223
- <option value="left" <?php echo ($image_position == 'left')? 'selected' : ''; ?> ><?php _e( 'left', $vk_call_to_action_textdomain ); ?></option>
224
- </select>
225
- </td></tr>
226
- <tr><th>
227
- <label for="vkExUnit_cta_button_text"><?php _e( 'Button text', $vk_call_to_action_textdomain ); ?></label></th><td>
228
- <input type="text" name="vkExUnit_cta_button_text" id="vkExUnit_cta_button_text" value="<?php echo esc_html( get_post_meta( get_the_id(), 'vkExUnit_cta_button_text', true ) ); ?>" />
229
- </td></tr>
230
- <tr><th>
231
- <label for="vkExUnit_cta_button_icon"><?php _e( 'Button icon', $vk_call_to_action_textdomain ); ?></label></th><td>
232
- <p><?php _e( 'To choose your favorite icon, and enter the class.', $vk_call_to_action_textdomain )?><br>
233
- <label for="icon_before"><?php _e('Before :',$vk_call_to_action_textdomain );?>
234
- <input type="text" name="vkExUnit_cta_button_icon_before" id="vkExUnit_cta_button_icon_before" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_button_icon_before', true ); ?>" /><br>
235
- <label for="icon_after"><?php _e('After :',$vk_call_to_action_textdomain );?>
236
- <input type="text" name="vkExUnit_cta_button_icon_after" id="vkExUnit_cta_button_icon_after" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_button_icon_after', true ); ?>" /><br>
237
- <?php _e( ' ex:fa-arrow-circle-o-right', $vk_call_to_action_textdomain )?><br>
238
- <a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank">[Font Awesome Icons]</a><br>
239
- </p>
240
- </td></tr>
241
- <tr><th>
242
- <label for="vkExUnit_cta_url"><?php _e( 'Button link url', $vk_call_to_action_textdomain ); ?></label></th><td>
243
- <input type="url" name="vkExUnit_cta_url" id="vkExUnit_cta_url" placeholder="http://" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_url', true ); ?>" />
244
- </td></tr>
245
- <tr><th>
246
-
247
- <?php
248
- $target_blank = get_post_meta( get_the_id(), 'vkExUnit_cta_url_blank', true );
249
- if ( $target_blank == "window_self") {
250
- $checked = ' checked';
251
- } else {
252
- $checked = '';
253
- }
254
- ?>
255
- <label for="vkExUnit_cta_url_blank"><?php _e( 'Target window', $vk_call_to_action_textdomain ); ?></label></th><td>
256
- <input type="checkbox" id="vkExUnit_cta_url_blank" name="vkExUnit_cta_url_blank" value="window_self"<?php echo $checked; ?> />
257
- <label for="vkExUnit_cta_url_blank"><?php _e('Open in a self window', 'vkExUnit'); ?></label>
258
  </td></tr>
259
  <tr><th><label for="vkExUnit_cta_text"><?php _e( 'Text message', $vk_call_to_action_textdomain ); ?>
260
  </th>
@@ -264,296 +281,334 @@ if ( $target_blank == "window_self") {
264
  </table>
265
  <a href="<?php echo admin_url( 'admin.php?page=vkExUnit_main_setting#vkExUnit_cta_settings' ); ?>" class="button button-default" target="_blank"><?php _e( 'CTA setting', $vk_call_to_action_textdomain ); ?></a>
266
  <?php
267
- }
268
 
269
 
270
- public static function save_custom_field( $post_id )
271
- {
272
- if ( ! isset( $_POST['_vkExUnit_cta_switch'] ) ) { return $post_id; }
273
- $noonce = isset( $_POST['_nonce_vkExUnit_custom_cta'] ) ? htmlspecialchars( $_POST['_nonce_vkExUnit_custom_cta'] ) : null;
274
 
275
- // if autosave is to deny
276
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
277
- return $post_id; }
278
 
279
- if ( ! wp_verify_nonce( $noonce, plugin_basename( __FILE__ ) ) ) {
280
- return $post_id;
281
- }
282
 
283
- if ( $_POST['_vkExUnit_cta_switch'] == 'cta_number' ) {
284
- $data = $_POST['vkexunit_cta_each_option'];
285
 
286
- if ( get_post_meta( $post_id, 'vkexunit_cta_each_option' ) == '' ) {
287
- add_post_meta( $post_id, 'vkexunit_cta_each_option', $data, true );
288
- } elseif ( $data != get_post_meta( $post_id, 'vkexunit_cta_each_option', true ) ) {
289
- update_post_meta( $post_id, 'vkexunit_cta_each_option', $data );
290
- } elseif ( ! $data ) {
291
- delete_post_meta( $post_id, 'vkexunit_cta_each_option', get_post_meta( $post_id, 'vkexunit_cta_each_option', true ) );
292
- }
293
- return $post_id;
294
- } elseif ( $_POST['_vkExUnit_cta_switch'] == 'cta_content' ) {
295
-
296
- // カスタムフィールドの設定
297
- $custom_fields = array(
298
- 'vkExUnit_cta_img' => array(
299
- 'escape_type' => '',
300
- ),
301
- 'vkExUnit_cta_img_position' => array(
302
  'escape_type' => '',
303
- ),
304
- 'vkExUnit_cta_button_text' => array(
305
- 'escape_type' => 'stripslashes',
306
- ),
307
- 'vkExUnit_cta_button_icon' => array(
308
- 'escape_type' => 'stripslashes',
309
- ),
310
- 'vkExUnit_cta_button_icon_before' => array(
311
- 'escape_type' => 'stripslashes',
312
- ),
313
- 'vkExUnit_cta_button_icon_after' => array(
314
- 'escape_type' => 'stripslashes',
315
- ),
316
- 'vkExUnit_cta_url' => array(
317
- 'escape_type' => '',
318
- ),
319
- 'vkExUnit_cta_url_blank' => array(
320
- 'escape_type' => '',
321
- ),
322
- 'vkExUnit_cta_text' => array(
323
  'escape_type' => 'stripslashes',
324
- ),
325
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
- // カスタムフィールドの保存
328
- foreach ( $custom_fields as $custom_field_name => $custom_field_options ) {
329
 
330
- if ( isset( $_POST[$custom_field_name] ) ) {
331
- if ( isset( $custom_field_name['escape_type'] ) && $custom_field_name['escape_type'] == 'stripslashes' ){
332
- $data = stripslashes( $_POST[$custom_field_name] );
333
- } else {
334
- $data = $_POST[$custom_field_name];
 
335
  }
336
- }
337
-
338
- if ( get_post_meta( $post_id, $custom_field_name ) == '' ) {
339
- // データが今までなかったらカスタムフィールドに新規保存
340
- add_post_meta( $post_id, $custom_field_name, $data, true );
341
- } elseif ( $data != get_post_meta( $post_id, $custom_field_name, true ) ) {
342
- // 保存されてたデータと送信されてきたデータが違ったら更新
343
- update_post_meta( $post_id, $custom_field_name, $data );
344
- } elseif ( ! $data ) {
345
- // データが送信されてこなかった(空のデータが送られてきた)らフィールドの値を削除
346
- delete_post_meta( $post_id, $custom_field_name, get_post_meta( $post_id, $custom_field_name, true ) );
347
- }
348
 
349
- } // foreach ( $custom_fields as $key => $custom_field_name ) {
 
 
 
 
 
 
 
 
 
 
350
 
351
- return $post_id;
 
352
  }
353
- }
354
 
355
 
356
- public static function get_cta_post( $id )
357
- {
358
- $args = array(
359
- 'post_type' => self::POST_TYPE,
360
- 'p' => $id,
361
- 'post_count' => 1,
362
- );
363
- $query = new \WP_Query( $args );
364
- if ( ! $query->post_count ) { return null; }
365
 
366
- return $query->posts[0];
367
- }
368
 
369
 
370
- public static function render_cta_content( $id )
371
- {
372
- if ( ! $id ) { return ''; }
373
- $post = self::get_cta_post( $id );
374
 
375
- // たぶん何か必ず $post にはデータが返ってくるので事実上不要
376
- if ( ! $post ) { return ''; }
 
377
 
378
- include dirname( __FILE__ ) . '/view-actionbox.php';
379
- return $content;
380
- }
381
 
382
- public static function cta_id_random()
383
- {
384
- // ランダムに抽出したCTAの投稿IDを返す
385
- // CTAの投稿をランダムで1件取得
386
- $args = array(
387
- 'post_type' => self::POST_TYPE, //投稿タイプを指定
388
- 'posts_per_page' => 1, // 1ページでの表示件数を指定
389
- 'orderby' => 'rand', // 表示順をランダムで取得
390
- );
391
- $cta_post = get_posts( $args );
392
- if ( $cta_post && isset ( $cta_post[0] ) ) {
393
- return $cta_post[0]->ID;
394
  }
395
- }
396
 
397
- public static function is_cta_id( $id = null )
398
- {
399
 
400
- // 表示する投稿のIDを取得
401
- if ( ! $id ) { $id = get_the_id(); }
402
- // ?
403
- if ( ! $id ) { return null; }
 
 
404
 
405
- // 各投稿編集画面で プルダウンで指定されている 表示するCTAの投稿ID(もしくは共通設定や非表示)
406
- $post_config = get_post_meta( $id, 'vkexunit_cta_each_option', true );
407
 
408
- // 「共通設定を使用」じゃなかった場合
409
- if ( $post_config ) {
410
 
411
- // 「表示しない」が選択されていたら $id には nullを返す( CTAは表示されない )
412
- if ( $post_config == 'disable' ) { return null; }
 
413
 
414
- // 「表示しない」が選択されていたら $id には nullを返す( CTAは表示されない )
415
- if ( $post_config == 'random' ) {
416
- return self::cta_id_random();
 
 
417
  }
418
- return $post_config;
419
- }
420
 
421
- ////////////////////////////////////////
422
- // 共通設定を使用の場合
423
- ////////////////////////////////////////
424
- // 今表示している記事の投稿タイプを取得
425
- $post_type = get_post_type( $id );
426
- // 投稿タイプ別にどのCTAを共通設定として表示するかの情報を取得
427
- $option = self::get_option();
428
-
429
- // 今表示している記事の投稿タイプのとき どのCTAを表示するかの設定が
430
- // 定義されており なおかつ 数字で入っている場合
431
- if (
432
  isset( $option[ $post_type ] ) &&
433
  is_numeric( $option[ $post_type ] )
434
  // $option[ $post_type ] > 0
435
  ) {
436
- // その数字(表示するCTAの投稿ID)を返す
437
- return $option[ $post_type ] ;
438
- } else {
439
- return self::cta_id_random();
 
 
440
  }
441
- return null;
442
- }
443
 
444
- public static function content_filter( $content )
445
- {
446
- // 固定ページウィジェットの場合
447
- if ( self::is_pagewidget() ) { return $content; }
448
- // Ligthning Advanced Unit のウィジェットだと...思う...
449
- if ( self::is_contentsarea_posts_widget() ) { return $content; }
450
- // 抜粋の場合
451
- if ( vkExUnit_is_excerpt() ) {
 
 
 
 
 
452
  return $content;
453
  }
454
- // 上記以外の場合に出力
455
- $content .= self::render_cta_content( self::is_cta_id() );
456
- return $content;
457
- }
458
 
459
 
460
- public static function is_pagewidget()
461
- {
462
- global $is_pagewidget;
463
- return ( $is_pagewidget )? true : false;
464
- }
465
-
466
 
467
- public static function is_contentsarea_posts_widget()
468
- {
469
- global $is_contentsarea_posts_widget;
470
- return ( $is_contentsarea_posts_widget ) ? true : false;
471
- }
472
 
 
 
 
 
473
 
474
- public static function sanitize_config( $input ) {
475
- $posttypes = array_merge( array( 'post' => 'post', 'page' => 'page' ), get_post_types( array( 'public' => true, '_builtin' => false ), 'names' ) );
476
- $option = get_option( 'vkExUnit_cta_settings' );
477
- if ( ! $option ) { $current_option = self::get_default_option(); }
478
 
479
- while ( list( $key, $value ) = each( $input ) ) {
480
- if ( $value == 'random' ){
481
- $option[ $key ] = 'random';
482
- } else {
483
- $option[ $key ] = ( is_numeric( $value ) )? $value : 0 ;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  }
 
485
  }
486
- return $option;
487
- }
488
 
489
 
490
- public static function get_default_option()
491
- {
492
- $option = array();
493
- $posttypes = array_merge( array( 'post' => 'post', 'page' => 'page' ), get_post_types( array( 'public' => true, '_builtin' => false ), 'names' ) );
494
- while ( list($key, $posttype) = each( $posttypes ) ) {
495
- $option[ $posttype ] = false;
 
 
 
 
 
 
 
 
 
 
 
496
  }
497
- return $option;
498
- }
499
 
500
 
501
- public static function get_option( $show_label = false )
502
- {
503
- $default = self::get_default_option();
504
- $option = get_option( 'vkExUnit_cta_settings' );
505
 
506
- if ( ! $option || ! is_array( $option ) ) { return $default; }
 
507
 
508
- $posttypes = array_merge( array( 'post' => 'post', 'page' => 'page' ), get_post_types( array( 'public' => true, '_builtin' => false ), 'names' ) );
 
 
 
 
 
 
 
 
 
 
509
 
510
- $output_option = array();
511
- while ( list($key, $value) = each( $posttypes ) ) {
512
- $output_option[ $value ] = ( isset( $option[ $value ] ) )? $option[ $value ] : $default[ $value ];
513
- }
514
 
515
- return $output_option;
516
- }
517
 
518
 
519
- public static function get_ctas( $show_label = false, $head = '' )
520
- {
521
- $args = array(
522
- 'post_type' => self::POST_TYPE,
523
- 'nopaging' => true,
524
- 'post_count' => -1,
525
- );
526
- $query = new \WP_Query( $args );
527
- $ctas = array();
528
- while ( list( $key, $post ) = each( $query->posts ) ) {
529
- if ( $show_label ) {
530
- $ctas[] = array(
531
- 'key' => $post->ID,
532
- 'label' => $head . $post->post_title,
533
- );
534
- } else {
535
- $ctas[] = $post->ID;
536
  }
 
537
  }
538
- return $ctas;
539
- }
540
 
541
 
542
- public static function render_configPage()
543
- {
544
- global $vk_call_to_action_textdomain;
545
- $options = self::get_option();
546
- $ctas = self::get_ctas( true, ' - ' );
547
 
548
- // ランダムを先頭に追加
549
- array_unshift( $ctas, array( 'key' => 'random', 'label' => __( 'Random', $vk_call_to_action_textdomain ) ) );
550
- // 表示しないを先頭に追加
551
- array_unshift( $ctas, array( 'key' => 0, 'label' => __( 'Disable display', $vk_call_to_action_textdomain ) ) );
 
 
 
 
 
 
 
 
 
 
552
 
553
- include dirname( __FILE__ ) . '/view-adminsetting.php';
 
554
  }
555
- }
556
 
557
- Vk_Call_To_Action::init();
558
 
559
  } // if ( ! class_exists( 'Vk_Call_To_Action' ) )
8
 
9
  // namespace Vektor\ExUnit\Package\Cta;
10
 
11
+ if ( ! class_exists( 'Vk_Call_To_Action' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ class Vk_Call_To_Action {
 
 
14
 
15
+ const POST_TYPE = 'cta';
 
 
 
 
 
16
 
17
+ const CONTENT_NUMBER = 100;
18
 
19
+ public static function init() {
20
+ add_action( 'init', array( __CLASS__, 'set_posttype' ) );
21
+ add_action( 'vkExUnit_package_init', array( __CLASS__, 'option_init' ) );
22
+ add_action( 'admin_menu', array( __CLASS__, 'add_custom_field' ) );
23
+ add_action( 'save_post', array( __CLASS__, 'save_custom_field' ) );
24
+ add_action( 'widgets_init', array( __CLASS__, 'widget_init' ) );
25
+ if ( veu_content_filter_state() == 'content' ) {
26
+ add_filter( 'the_content', array( __CLASS__, 'content_filter' ), self::CONTENT_NUMBER, 1 );
27
+ } else {
28
+ add_action( 'loop_end', array( __CLASS__, 'set_content_loopend' ), self::CONTENT_NUMBER, 1 );
29
+ }
30
+ require_once dirname( __FILE__ ) . '/widget-call-to-action.php';
31
+ }
32
 
33
+ public static function widget_init() {
34
+ return register_widget( 'Widget_CTA' );
35
+ }
36
 
37
+ public static function set_content_loopend( $query ) {
38
+ if ( ! $query->is_main_query() ) {
39
+ return;
40
+ }
41
+ if ( ! is_single() ) {
42
+ return;
43
+ }
44
+ echo self::content_filter( '' );
45
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
 
48
+ public static function option_init() {
49
+ vkExUnit_register_setting(
50
+ 'Call To Action', // tab label.
51
+ 'vkExUnit_cta_settings', // name attr
52
+ array( __CLASS__, 'sanitize_config' ), // sanitaise function name
53
+ array( __CLASS__, 'render_configPage' ) // setting_page function name
54
+ );
55
  }
 
 
56
 
 
 
57
 
58
+ public static function set_posttype() {
59
+ global $vk_call_to_action_textdomain;
60
+ $labels = array(
61
+ 'name' => 'CTA',
62
+ 'singular_name' => 'CTA',
63
+ 'edit_item' => __( 'Edit CTA', $vk_call_to_action_textdomain ),
64
+ 'add_new_item' => __( 'Add new CTA', $vk_call_to_action_textdomain ),
65
+ 'new_item' => __( 'New CTA', $vk_call_to_action_textdomain ),
66
+ );
67
+
68
+ $args = array(
69
+ 'labels' => $labels,
70
+ 'public' => false,
71
+ 'publicly_queryable' => false,
72
+ 'has_archive' => true,
73
+ 'show_ui' => true,
74
+ 'show_in_menu' => true,
75
+ 'menu_position' => 5,
76
+ 'query_var' => true,
77
+ 'rewrite' => true,
78
+ 'capability_type' => 'post',
79
+ 'has_archive' => false,
80
+ 'hierarchical' => false,
81
+ 'taxonomies' => array(),
82
+ 'supports' => array( 'title' ),
83
+ );
84
+ register_post_type( self::POST_TYPE, $args );
85
+ }
86
+
87
+
88
+ public static function add_custom_field() {
89
+ global $vk_call_to_action_textdomain;
90
+ $post_types = get_post_types(
91
+ array(
92
+ '_builtin' => false,
93
+ 'public' => true,
94
+ )
95
+ );
96
+ foreach ( $post_types as $key => $post ) {
97
+ add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), $post, 'normal', 'high' );
98
+ }
99
+ add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), 'page', 'normal', 'high' );
100
+ add_meta_box( 'vkExUnit_cta', __( 'Call to Action setting', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box' ), 'post', 'normal', 'high' );
101
+
102
+ add_meta_box( 'vkExUnit_cta_url', __( 'CTA Contents', $vk_call_to_action_textdomain ), array( __CLASS__, 'render_meta_box_cta' ), self::POST_TYPE, 'normal', 'high' );
103
+ }
104
+
105
+ /**
106
  * CTAメイン設定画面のurl
107
  * ExUnitと単体プラグインなどによって変動する
108
  * @return [type] [description]
109
  */
110
+ public static function setting_page_url() {
111
+ if ( veu_is_cta_active() ) {
112
+ $setting_page_url = admin_url( 'admin.php?page=vkExUnit_main_setting#vkExUnit_cta_settings' );
113
+ } else {
114
+ $setting_page_url = admin_url( 'options-general.php?page=vk_cta_options' );
115
+ }
116
+ return $setting_page_url;
117
  }
 
 
118
 
119
+ public static function render_meta_box() {
120
+ global $vk_call_to_action_textdomain;
121
+ echo '<input type="hidden" name="_nonce_vkExUnit_custom_cta" id="_nonce_vkExUnit__custom_field_metaKeyword" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
122
+
123
+ $ctas = self::get_ctas( true, ' - ' );
124
+ // ランダムを先頭に追加
125
+ array_unshift(
126
+ $ctas, array(
127
+ 'key' => 'random',
128
+ 'label' => __( 'Random', $vk_call_to_action_textdomain ),
129
+ )
130
+ );
131
+ array_unshift(
132
+ $ctas, array(
133
+ 'key' => 'disable',
134
+ 'label' => __( 'Disable display', $vk_call_to_action_textdomain ),
135
+ )
136
+ );
137
+ array_unshift(
138
+ $ctas, array(
139
+ 'key' => 0,
140
+ 'label' => __( 'Follow common setting', $vk_call_to_action_textdomain ),
141
+ )
142
+ );
143
+ $now = get_post_meta( get_the_id(), 'vkexunit_cta_each_option', true );
144
+ ?>
145
+ <input type="hidden" name="_vkExUnit_cta_switch" value="cta_number" />
146
+
147
+ <select name="vkexunit_cta_each_option" id="vkexunit_cta_each_option">
148
+ <?php foreach ( $ctas as $cta ) : ?>
149
+ <option value="<?php echo $cta['key']; ?>" <?php echo( $cta['key'] == $now ) ? 'selected' : ''; ?> ><?php echo $cta['label']; ?></option>
150
+ <?php endforeach; ?>
151
+ </select>
152
+ <p>
153
+ <a href="<?php echo self::setting_page_url(); ?>" class="button button-default" target="_blank"><?php _e( 'CTA common setting', $vk_call_to_action_textdomain ); ?></a>
154
+ <a href="<?php echo admin_url( 'edit.php?post_type=cta' ); ?>" class="button button-default" target="_blank"><?php _e( 'Show CTA index page', $vk_call_to_action_textdomain ); ?></a>
155
+ </p>
156
  <?php
157
+ }
158
 
159
 
160
+ public static function render_meta_box_cta() {
161
+
162
+ global $vk_call_to_action_textdomain;
163
+
164
+ echo '<input type="hidden" name="_nonce_vkExUnit_custom_cta" id="_nonce_vkExUnit__custom_field_metaKeyword" value="' . wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
165
+ $imgid = get_post_meta( get_the_id(), 'vkExUnit_cta_img', true );
166
+ $cta_image = wp_get_attachment_image_src( $imgid, 'large' );
167
+ $image_position = get_post_meta( get_the_id(), 'vkExUnit_cta_img_position', true );
168
+ ?>
169
+ <style>
170
+ #message.updated a {display:none;}
171
+ #thumbnail_box { max-width:300px; max-height:300px; }
172
+ #cta-thumbnail_image { max-width:300px; max-height:300px; }
173
+ #cta-thumbnail_image.noimage { display:none; }
174
+ #cta-thumbnail_control.add #media_thumb_url_add { display:inline; }
175
+ #cta-thumbnail_control.add #media_thumb_url_change,
176
+ #cta-thumbnail_control.add #media_thumb_url_remove { display:none; }
177
+ #cta-thumbnail_control.change #media_thumb_url_add { display:none; }
178
+ #cta-thumbnail_control.change #media_thumb_url_change,
179
+ #cta-thumbnail_control.change #media_thumb_url_remove { display:inline; }
180
+ .form-table input[type=text],
181
+ .form-table input[type=url],
182
+ .form-table textarea { width:80%; }
183
+ </style>
184
+ <script type="text/javascript">
185
+ jQuery(document).ready(function($){
186
+ var custom_uploader;
187
+ jQuery('.cta-media_btn').click(function(e) {
188
+ e.preventDefault();
189
+
190
+ if (custom_uploader) {
191
+ custom_uploader.open();
192
+ return;
193
+ }
194
+ custom_uploader = wp.media({
195
+ title: 'Choose Image',
196
+ library: {type: 'image'},
197
+ button: {text: 'Choose Image'},
198
+ multiple: false,
199
+ });
200
+
201
+ custom_uploader.on('select', function() {
202
+ var images = custom_uploader.state().get('selection');
203
+ images.each(function(file){
204
+ jQuery('#cta-thumbnail_image').attr('src', file.toJSON().url).removeClass("noimage");
205
+ jQuery('.vkExUnit_cta_img').val(file.toJSON().id);
206
+ jQuery('#cta-thumbnail_control').removeClass("add").addClass("change");
207
+ });
208
+ });
209
+ custom_uploader.open();
210
+ });
211
+ jQuery('#cta-thumbnail_control #media_thumb_url_remove').on('click', function(){
212
+ jQuery('#cta-thumbnail_image').attr('src', '').addClass("noimage");
213
+ jQuery('.vkExUnit_cta_img').val('');
214
+ jQuery('#cta-thumbnail_control').removeClass("change").addClass("add");
215
+ return false;
216
+ });
217
+ });
218
+ </script>
219
+ <input type="hidden" name="_vkExUnit_cta_switch" value="cta_content" />
220
+ <table class="form-table">
221
+ <tr>
222
+ <th><?php _e( 'CTA image', $vk_call_to_action_textdomain ); ?></th>
223
+ <td>
224
+ <div id="cta-thumbnail_box" >
225
+ <img id="cta-thumbnail_image" src="<?php echo ( $cta_image ) ? $cta_image[0] : ''; ?>" class="<?php echo ( $cta_image ) ? '' : 'noimage'; ?>" />
226
+ </div>
227
+ <div id="cta-thumbnail_control" class="<?php echo ( $cta_image ) ? 'change' : 'add'; ?>">
228
  <button id="media_thumb_url_add" class="cta-media_btn button button-default"><?php _e( 'Add image', $vk_call_to_action_textdomain ); ?></button>
229
  <button id="media_thumb_url_change" class="cta-media_btn button button-default"><?php _e( 'Change image', $vk_call_to_action_textdomain ); ?></button>
230
  <button id="media_thumb_url_remove" class="button button-default"><?php _e( 'Remove image', $vk_call_to_action_textdomain ); ?></button>
231
+ </div>
232
+ <input type="hidden" name="vkExUnit_cta_img" class="vkExUnit_cta_img" value="<?php echo $imgid; ?>" />
233
+ </td>
234
+ </tr>
235
+ <tr><th><label for="vkExUnit_cta_img_position"><?php _e( 'CTA image position', $vk_call_to_action_textdomain ); ?></label></th>
236
+ <td>
237
+ <select name="vkExUnit_cta_img_position" id="vkExUnit_cta_img_position">
238
+ <option value="right" <?php echo ( $image_position == 'right' ) ? 'selected' : ''; ?> ><?php _e( 'right', $vk_call_to_action_textdomain ); ?></option>
239
+ <option value="center" <?php echo ( $image_position == 'center' ) ? 'selected' : ''; ?> ><?php _e( 'center', $vk_call_to_action_textdomain ); ?></option>
240
+ <option value="left" <?php echo ( $image_position == 'left' ) ? 'selected' : ''; ?> ><?php _e( 'left', $vk_call_to_action_textdomain ); ?></option>
241
+ </select>
242
+ </td></tr>
243
+ <tr><th>
244
+ <label for="vkExUnit_cta_button_text"><?php _e( 'Button text', $vk_call_to_action_textdomain ); ?></label></th><td>
245
+ <input type="text" name="vkExUnit_cta_button_text" id="vkExUnit_cta_button_text" value="<?php echo esc_html( get_post_meta( get_the_id(), 'vkExUnit_cta_button_text', true ) ); ?>" />
246
+ </td></tr>
247
+ <tr><th>
248
+ <label for="vkExUnit_cta_button_icon"><?php _e( 'Button icon', $vk_call_to_action_textdomain ); ?></label></th><td>
249
+ <p><?php _e( 'To choose your favorite icon, and enter the class.', $vk_call_to_action_textdomain ); ?><br>
250
+ <label for="icon_before"><?php _e( 'Before :', $vk_call_to_action_textdomain ); ?>
251
+ <input type="text" name="vkExUnit_cta_button_icon_before" id="vkExUnit_cta_button_icon_before" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_button_icon_before', true ); ?>" /><br>
252
+ <label for="icon_after"><?php _e( 'After :', $vk_call_to_action_textdomain ); ?>
253
+ <input type="text" name="vkExUnit_cta_button_icon_after" id="vkExUnit_cta_button_icon_after" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_button_icon_after', true ); ?>" /><br>
254
+ <?php _e( ' ex:fa-arrow-circle-o-right', $vk_call_to_action_textdomain ); ?><br>
255
+ <a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank">[Font Awesome Icons]</a><br>
256
+ </p>
257
+ </td></tr>
258
+ <tr><th>
259
+ <label for="vkExUnit_cta_url"><?php _e( 'Button link url', $vk_call_to_action_textdomain ); ?></label></th><td>
260
+ <input type="url" name="vkExUnit_cta_url" id="vkExUnit_cta_url" placeholder="http://" value="<?php echo get_post_meta( get_the_id(), 'vkExUnit_cta_url', true ); ?>" />
261
+ </td></tr>
262
+ <tr><th>
263
+
264
+ <?php
265
+ $target_blank = get_post_meta( get_the_id(), 'vkExUnit_cta_url_blank', true );
266
+ if ( $target_blank == 'window_self' ) {
267
+ $checked = ' checked';
268
+ } else {
269
+ $checked = '';
270
+ }
271
+ ?>
272
+ <label for="vkExUnit_cta_url_blank"><?php _e( 'Target window', $vk_call_to_action_textdomain ); ?></label></th><td>
273
+ <input type="checkbox" id="vkExUnit_cta_url_blank" name="vkExUnit_cta_url_blank" value="window_self"<?php echo $checked; ?> />
274
+ <label for="vkExUnit_cta_url_blank"><?php _e( 'Open in a self window', 'vkExUnit' ); ?></label>
275
  </td></tr>
276
  <tr><th><label for="vkExUnit_cta_text"><?php _e( 'Text message', $vk_call_to_action_textdomain ); ?>
277
  </th>
281
  </table>
282
  <a href="<?php echo admin_url( 'admin.php?page=vkExUnit_main_setting#vkExUnit_cta_settings' ); ?>" class="button button-default" target="_blank"><?php _e( 'CTA setting', $vk_call_to_action_textdomain ); ?></a>
283
  <?php
284
+ }
285
 
286
 
287
+ public static function save_custom_field( $post_id ) {
288
+ if ( ! isset( $_POST['_vkExUnit_cta_switch'] ) ) {
289
+ return $post_id; }
290
+ $noonce = isset( $_POST['_nonce_vkExUnit_custom_cta'] ) ? htmlspecialchars( $_POST['_nonce_vkExUnit_custom_cta'] ) : null;
291
 
292
+ // if autosave is to deny
293
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
294
+ return $post_id; }
295
 
296
+ if ( ! wp_verify_nonce( $noonce, plugin_basename( __FILE__ ) ) ) {
297
+ return $post_id;
298
+ }
299
 
300
+ if ( $_POST['_vkExUnit_cta_switch'] == 'cta_number' ) {
301
+ $data = $_POST['vkexunit_cta_each_option'];
302
 
303
+ if ( get_post_meta( $post_id, 'vkexunit_cta_each_option' ) == '' ) {
304
+ add_post_meta( $post_id, 'vkexunit_cta_each_option', $data, true );
305
+ } elseif ( $data != get_post_meta( $post_id, 'vkexunit_cta_each_option', true ) ) {
306
+ update_post_meta( $post_id, 'vkexunit_cta_each_option', $data );
307
+ } elseif ( ! $data ) {
308
+ delete_post_meta( $post_id, 'vkexunit_cta_each_option', get_post_meta( $post_id, 'vkexunit_cta_each_option', true ) );
309
+ }
310
+ return $post_id;
311
+ } elseif ( $_POST['_vkExUnit_cta_switch'] == 'cta_content' ) {
312
+
313
+ // カスタムフィールドの設定
314
+ $custom_fields = array(
315
+ 'vkExUnit_cta_img' => array(
316
+ 'escape_type' => '',
317
+ ),
318
+ 'vkExUnit_cta_img_position' => array(
319
  'escape_type' => '',
320
+ ),
321
+ 'vkExUnit_cta_button_text' => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  'escape_type' => 'stripslashes',
323
+ ),
324
+ 'vkExUnit_cta_button_icon' => array(
325
+ 'escape_type' => 'stripslashes',
326
+ ),
327
+ 'vkExUnit_cta_button_icon_before' => array(
328
+ 'escape_type' => 'stripslashes',
329
+ ),
330
+ 'vkExUnit_cta_button_icon_after' => array(
331
+ 'escape_type' => 'stripslashes',
332
+ ),
333
+ 'vkExUnit_cta_url' => array(
334
+ 'escape_type' => '',
335
+ ),
336
+ 'vkExUnit_cta_url_blank' => array(
337
+ 'escape_type' => '',
338
+ ),
339
+ 'vkExUnit_cta_text' => array(
340
+ 'escape_type' => 'stripslashes',
341
+ ),
342
+ );
343
 
344
+ // カスタムフィールドの保存
345
+ foreach ( $custom_fields as $custom_field_name => $custom_field_options ) {
346
 
347
+ if ( isset( $_POST[ $custom_field_name ] ) ) {
348
+ if ( isset( $custom_field_name['escape_type'] ) && $custom_field_name['escape_type'] == 'stripslashes' ) {
349
+ $data = stripslashes( $_POST[ $custom_field_name ] );
350
+ } else {
351
+ $data = $_POST[ $custom_field_name ];
352
+ }
353
  }
 
 
 
 
 
 
 
 
 
 
 
 
354
 
355
+ if ( get_post_meta( $post_id, $custom_field_name ) == '' ) {
356
+ // データが今までなかったらカスタムフィールドに新規保存
357
+ add_post_meta( $post_id, $custom_field_name, $data, true );
358
+ } elseif ( $data != get_post_meta( $post_id, $custom_field_name, true ) ) {
359
+ // 保存されてたデータと送信されてきたデータが違ったら更新
360
+ update_post_meta( $post_id, $custom_field_name, $data );
361
+ } elseif ( ! $data ) {
362
+ // データが送信されてこなかった(空のデータが送られてきた)らフィールドの値を削除
363
+ delete_post_meta( $post_id, $custom_field_name, get_post_meta( $post_id, $custom_field_name, true ) );
364
+ }
365
+ } // foreach ( $custom_fields as $key => $custom_field_name ) {
366
 
367
+ return $post_id;
368
+ }
369
  }
 
370
 
371
 
372
+ public static function get_cta_post( $id ) {
373
+ $args = array(
374
+ 'post_type' => self::POST_TYPE,
375
+ 'p' => $id,
376
+ 'post_count' => 1,
377
+ );
378
+ $query = new \WP_Query( $args );
379
+ if ( ! $query->post_count ) {
380
+ return null; }
381
 
382
+ return $query->posts[0];
383
+ }
384
 
385
 
386
+ public static function render_cta_content( $id ) {
387
+ if ( ! $id ) {
388
+ return ''; }
389
+ $post = self::get_cta_post( $id );
390
 
391
+ // たぶん何か必ず $post にはデータが返ってくるので事実上不要
392
+ if ( ! $post ) {
393
+ return ''; }
394
 
395
+ include dirname( __FILE__ ) . '/view-actionbox.php';
396
+ return $content;
397
+ }
398
 
399
+ public static function cta_id_random() {
400
+ // ランダムに抽出したCTAの投稿IDを返す
401
+ // CTAの投稿をランダムで1件取得
402
+ $args = array(
403
+ 'post_type' => self::POST_TYPE, //投稿タイプを指定
404
+ 'posts_per_page' => 1, // 1ページでの表示件数を指定
405
+ 'orderby' => 'rand', // 表示順をランダムで取得
406
+ );
407
+ $cta_post = get_posts( $args );
408
+ if ( $cta_post && isset( $cta_post[0] ) ) {
409
+ return $cta_post[0]->ID;
410
+ }
411
  }
 
412
 
413
+ public static function is_cta_id( $id = null ) {
 
414
 
415
+ // 表示する投稿のIDを取得
416
+ if ( ! $id ) {
417
+ $id = get_the_id(); }
418
+ // ?
419
+ if ( ! $id ) {
420
+ return null; }
421
 
422
+ // 各投稿編集画面で プルダウンで指定されている 表示するCTAの投稿ID(もしくは共通設定や非表示)
423
+ $post_config = get_post_meta( $id, 'vkexunit_cta_each_option', true );
424
 
425
+ // 「共通設定を使用」じゃなかった場合
426
+ if ( $post_config ) {
427
 
428
+ // 「表示しない」が選択されていたら $id には nullを返す( CTAは表示されない )
429
+ if ( $post_config == 'disable' ) {
430
+ return null; }
431
 
432
+ // 「表示しない」が選択されていたら $id には nullを返す( CTAは表示されない )
433
+ if ( $post_config == 'random' ) {
434
+ return self::cta_id_random();
435
+ }
436
+ return $post_config;
437
  }
 
 
438
 
439
+ ////////////////////////////////////////
440
+ // 共通設定を使用の場合
441
+ ////////////////////////////////////////
442
+ // 今表示している記事の投稿タイプを取得
443
+ $post_type = get_post_type( $id );
444
+ // 投稿タイプ別にどのCTAを共通設定として表示するかの情報を取得
445
+ $option = self::get_option();
446
+
447
+ // 今表示している記事の投稿タイプのとき どのCTAを表示するかの設定が
448
+ // 定義されており なおかつ 数字で入っている場合
449
+ if (
450
  isset( $option[ $post_type ] ) &&
451
  is_numeric( $option[ $post_type ] )
452
  // $option[ $post_type ] > 0
453
  ) {
454
+ // その数字(表示するCTAの投稿ID)を返す
455
+ return $option[ $post_type ];
456
+ } else {
457
+ return self::cta_id_random();
458
+ }
459
+ return null;
460
  }
 
 
461
 
462
+ public static function content_filter( $content ) {
463
+ // 固定ページウィジェットの場合
464
+ if ( self::is_pagewidget() ) {
465
+ return $content; }
466
+ // Ligthning Advanced Unit のウィジェットだと...思う...
467
+ if ( self::is_contentsarea_posts_widget() ) {
468
+ return $content; }
469
+ // 抜粋の場合
470
+ if ( vkExUnit_is_excerpt() ) {
471
+ return $content;
472
+ }
473
+ // 上記以外の場合に出力
474
+ $content .= self::render_cta_content( self::is_cta_id() );
475
  return $content;
476
  }
 
 
 
 
477
 
478
 
479
+ public static function is_pagewidget() {
480
+ global $is_pagewidget;
481
+ return ( $is_pagewidget ) ? true : false;
482
+ }
 
 
483
 
 
 
 
 
 
484
 
485
+ public static function is_contentsarea_posts_widget() {
486
+ global $is_contentsarea_posts_widget;
487
+ return ( $is_contentsarea_posts_widget ) ? true : false;
488
+ }
489
 
 
 
 
 
490
 
491
+ public static function sanitize_config( $input ) {
492
+ $posttypes = array_merge(
493
+ array(
494
+ 'post' => 'post',
495
+ 'page' => 'page',
496
+ ), get_post_types(
497
+ array(
498
+ 'public' => true,
499
+ '_builtin' => false,
500
+ ), 'names'
501
+ )
502
+ );
503
+ $option = get_option( 'vkExUnit_cta_settings' );
504
+ if ( ! $option ) {
505
+ $current_option = self::get_default_option(); }
506
+
507
+ while ( list( $key, $value ) = each( $input ) ) {
508
+ if ( $value == 'random' ) {
509
+ $option[ $key ] = 'random';
510
+ } else {
511
+ $option[ $key ] = ( is_numeric( $value ) ) ? $value : 0;
512
+ }
513
  }
514
+ return $option;
515
  }
 
 
516
 
517
 
518
+ public static function get_default_option() {
519
+ $option = array();
520
+ $posttypes = array_merge(
521
+ array(
522
+ 'post' => 'post',
523
+ 'page' => 'page',
524
+ ), get_post_types(
525
+ array(
526
+ 'public' => true,
527
+ '_builtin' => false,
528
+ ), 'names'
529
+ )
530
+ );
531
+ while ( list($key, $posttype) = each( $posttypes ) ) {
532
+ $option[ $posttype ] = false;
533
+ }
534
+ return $option;
535
  }
 
 
536
 
537
 
538
+ public static function get_option( $show_label = false ) {
539
+ $default = self::get_default_option();
540
+ $option = get_option( 'vkExUnit_cta_settings' );
 
541
 
542
+ if ( ! $option || ! is_array( $option ) ) {
543
+ return $default; }
544
 
545
+ $posttypes = array_merge(
546
+ array(
547
+ 'post' => 'post',
548
+ 'page' => 'page',
549
+ ), get_post_types(
550
+ array(
551
+ 'public' => true,
552
+ '_builtin' => false,
553
+ ), 'names'
554
+ )
555
+ );
556
 
557
+ $output_option = array();
558
+ while ( list($key, $value) = each( $posttypes ) ) {
559
+ $output_option[ $value ] = ( isset( $option[ $value ] ) ) ? $option[ $value ] : $default[ $value ];
560
+ }
561
 
562
+ return $output_option;
563
+ }
564
 
565
 
566
+ public static function get_ctas( $show_label = false, $head = '' ) {
567
+ $args = array(
568
+ 'post_type' => self::POST_TYPE,
569
+ 'nopaging' => true,
570
+ 'post_count' => -1,
571
+ );
572
+ $query = new \WP_Query( $args );
573
+ $ctas = array();
574
+ while ( list( $key, $post ) = each( $query->posts ) ) {
575
+ if ( $show_label ) {
576
+ $ctas[] = array(
577
+ 'key' => $post->ID,
578
+ 'label' => $head . $post->post_title,
579
+ );
580
+ } else {
581
+ $ctas[] = $post->ID;
582
+ }
583
  }
584
+ return $ctas;
585
  }
 
 
586
 
587
 
588
+ public static function render_configPage() {
589
+ global $vk_call_to_action_textdomain;
590
+ $options = self::get_option();
591
+ $ctas = self::get_ctas( true, ' - ' );
 
592
 
593
+ // ランダムを先頭に追加
594
+ array_unshift(
595
+ $ctas, array(
596
+ 'key' => 'random',
597
+ 'label' => __( 'Random', $vk_call_to_action_textdomain ),
598
+ )
599
+ );
600
+ // 表示しないを先頭に追加
601
+ array_unshift(
602
+ $ctas, array(
603
+ 'key' => 0,
604
+ 'label' => __( 'Disable display', $vk_call_to_action_textdomain ),
605
+ )
606
+ );
607
 
608
+ include dirname( __FILE__ ) . '/view-adminsetting.php';
609
+ }
610
  }
 
611
 
612
+ Vk_Call_To_Action::init();
613
 
614
  } // if ( ! class_exists( 'Vk_Call_To_Action' ) )
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: Google Analytics, New posts, Related Posts, sitemap, sns, twitter card, Facebook Page Plugin, OG tags,
5
  Requires at least: 4.4
6
  Tested up to: 4.9.2
7
- Stable tag: 5.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
4
  Tags: Google Analytics, New posts, Related Posts, sitemap, sns, twitter card, Facebook Page Plugin, OG tags,
5
  Requires at least: 4.4
6
  Tested up to: 4.9.2
7
+ Stable tag: 5.9.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
vkExUnit.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: VK All in One Expansion Unit
4
  * Plugin URI: https://ex-unit.nagoya
5
  * Description: This plug-in is an integrated plug-in with a variety of features that make it powerful your web site. Many features can be stopped individually. Example Facebook Page Plugin,Social Bookmarks,Print OG Tags,Print Twitter Card Tags,Print Google Analytics tag,New post widget,Insert Related Posts and more!
6
- * Version: 5.9.2
7
  * Author: Vektor,Inc.
8
  * Text Domain: vkExUnit
9
  * Domain Path: /languages
3
  * Plugin Name: VK All in One Expansion Unit
4
  * Plugin URI: https://ex-unit.nagoya
5
  * Description: This plug-in is an integrated plug-in with a variety of features that make it powerful your web site. Many features can be stopped individually. Example Facebook Page Plugin,Social Bookmarks,Print OG Tags,Print Twitter Card Tags,Print Google Analytics tag,New post widget,Insert Related Posts and more!
6
+ * Version: 5.9.3
7
  * Author: Vektor,Inc.
8
  * Text Domain: vkExUnit
9
  * Domain Path: /languages