-
Notifications
You must be signed in to change notification settings - Fork 44
/
html-forms.php
1844 lines (1639 loc) · 62.3 KB
/
html-forms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php //HTMLフォーム生成関数
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
//著者セレクトボックスをの取得
if ( !function_exists( 'get_author_list_selectbox_tag' ) ):
function get_author_list_selectbox_tag($name, $value){
$users = get_users( array('orderby'=>'ID','order'=>'ASC') );
$html = '<select id="'.$name.'" name="'.$name.'">'.PHP_EOL;
foreach($users as $user) {
$uid = $user->ID;
if ($uid == intval($value)) {
$selected = " selected";
} else {
$selected = null;
}
$html .= ' <option value="'.$uid.'"'.$selected.'>'.$user->display_name.'</option>'.PHP_EOL;
} //foreach
$html .= '</select>'.PHP_EOL;
return $html;
}
endif;
//著者セレクトボックスをの取得
if ( !function_exists( 'generate_author_list_selectbox_tag' ) ):
function generate_author_list_selectbox_tag($name, $value){
echo get_author_list_selectbox_tag($name, $value);
}
endif;
//チェックボックスのチェックを付けるか
if ( !function_exists( 'the_checkbox_checked' ) ):
function the_checkbox_checked($val1, $val2 = 1){
if ( (is_array($val1) && in_array($val2, $val1)) || ($val1 == $val2) ) {
echo ' checked="checked"';
}
}
endif;
//セレクトボックスのチェックを付けるか
if ( !function_exists( 'the_option_selected' ) ):
function the_option_selected($val1, $val2){
if ($val1 == $val2) {
echo ' selected="selected"';
}
}
endif;
//brタグの出力
if ( !function_exists( 'generate_br_tag' ) ):
function generate_br_tag(){
echo '<br>';
}
endif;
//セレクトボックスの生成
if ( !function_exists( 'generate_selectbox_tag' ) ):
function generate_selectbox_tag($name, $options, $now_value, $label = null, $icon_font_visible = false){
$style = null;
if ($icon_font_visible) {
$style = ' style="font-family: FontAwesome;font-size: 20px;text-align: center;"';
}
ob_start();
if ($label) {
generate_label_tag($name, $label);
generate_br_tag();
}
?>
<select name="<?php echo $name; ?>"<?php echo $style; ?>>
<?php
foreach ($options as $value => $caption) {
//アイコンフォントを利用する場合
$add_option_class = null;
?>
<option value="<?php echo $value; ?>"<?php the_option_selected($value, $now_value) ?><?php echo $add_option_class; ?>><?php echo $caption; ?></option>
<?php } ?>
</select>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//レンジボックスの生成
if ( !function_exists( 'generate_range_tag' ) ):
function generate_range_tag($name, $value, $min, $max, $step){
ob_start();?>
<div class="range-wrap">
<output id="<?php echo $name; ?>"><?php echo $value; ?></output>
<span class="range-min"><?php echo $min; ?></span><input type="range" name="<?php echo $name; ?>" value="<?php echo $value; ?>" min="<?php echo $min; ?>" max="<?php echo $max; ?>" step="<?php echo $step; ?>"
oninput="document.getElementById('<?php echo $name; ?>').value=this.value"><span class="range-min"><?php echo $max; ?></span>
</div>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//スキン制御タグで囲む
if ( !function_exists( 'get_skin_control_tag' ) ):
function get_skin_control_tag($tag){
return '<div class="skin-control">'.$tag.'</div>';
}
endif;
//入力フォームをスキン制御タグで囲む
add_filter( 'admin_input_form_tag', 'wrap_skin_control_tag', 10, 3 );
if ( !function_exists( 'wrap_skin_control_tag' ) ):
function wrap_skin_control_tag($tag, $name, $value = 1){
if (is_form_skin_option($name, $value)) {
global $_FORM_SKIN_OPTIONS;
$name = str_replace('[]', '', $name);
// _v($_FORM_SKIN_OPTIONS);
// _v($name);
// _v($value);
if (isset($_FORM_SKIN_OPTIONS[$name])) {
//値が配列だった場合配列だけをスキン制御タグで囲む
if (is_array($_FORM_SKIN_OPTIONS[$name]) && in_array(trim($value), $_FORM_SKIN_OPTIONS[$name])) {
$tag = get_skin_control_tag($tag);
}
//値が文字列・数字だった場合スキン制御タグで囲む
elseif (is_string($_FORM_SKIN_OPTIONS[$name]) || is_numeric($_FORM_SKIN_OPTIONS[$name])){
$tag = get_skin_control_tag($tag);
}
}
}
return $tag;
}
endif;
//チェックボックスの生成
if ( !function_exists( 'generate_checkbox_tag' ) ):
function generate_checkbox_tag($name, $now_value, $label, $default_value = 1){
ob_start();
$id = $name.'_'.$default_value;
?>
<input type="checkbox" name="<?php echo $name; ?>" id="<?php echo $id; ?>" value="<?php echo $default_value; ?>"<?php the_checkbox_checked($now_value, $default_value); ?>><?php generate_label_tag($id, $label); ?>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name, $default_value);
}
endif;
//ラジオボックスの生成
if ( !function_exists( 'generate_radiobox_tag' ) ):
function generate_radiobox_tag($name, $options, $now_value, $label = null){
ob_start();
$i = 0;
if ($label) {
generate_label_tag($name, $label);
generate_br_tag();
}?>
<ul>
<?php foreach ($options as $value => $caption) {
$id = $name.'_'.$i;
// _v($value.' == '.$now_value);
// _v($value == $now_value);
?>
<li><input type="radio" name="<?php echo $name; ?>" id="<?php echo $id; ?>" value="<?php echo $value; ?>"<?php the_checkbox_checked($value, $now_value) ?>><label for="<?php echo $id; ?>"><?php echo $caption; ?></label></li>
<?php
$i++;
} ?>
</ul>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//ラベルの取得
if ( !function_exists( 'get_label_tag' ) ):
function get_label_tag($id, $caption){
return '<label for="'. $id.'">'.$caption.'</label>';
}
endif;
//ラベルの生成
if ( !function_exists( 'generate_label_tag' ) ):
function generate_label_tag($id, $caption){
echo get_label_tag($id, $caption);
}
endif;
//必須入力項目案内
if ( !function_exists( 'generate_necessity_input_tag' ) ):
function generate_necessity_input_tag($message = '*'){?>
<span class="necessity-input"><?php echo $message; ?></span>
<?php
}
endif;
//入力できないフォームクラスコードの生成
if ( !function_exists( 'get_not_allowed_form_class' ) ):
function get_not_allowed_form_class($is_allowed, $in = false){
if (!$is_allowed) {
if ($in) {
return ' not-allowed-form';
} else {
return ' class="not-allowed-form"';
}
}
}
endif;
//入力できないフォームクラスコードの生成
if ( !function_exists( 'generate_not_allowed_form_class' ) ):
function generate_not_allowed_form_class($is_not_allowed, $in = false){
echo get_not_allowed_form_class($is_not_allowed);
}
endif;
//説明文の生成
if ( !function_exists( 'generate_tips_tag' ) ):
function generate_tips_tag($caption){
ob_start();?>
<p class="tips"><span class="fa fa-info-circle" aria-hidden="true"></span> <?php echo $caption; ?></p>
<?php
$tag = ob_get_clean();
$tag = change_fa($tag);
echo $tag;
}
endif;
//アラート文の生成
if ( !function_exists( 'generate_alert_tag' ) ):
function generate_alert_tag($caption){
ob_start();?>
<p class="alert"><span class="fa fa-exclamation-triangle" aria-hidden="true"></span> <?php echo $caption; ?></p>
<?php
$tag = ob_get_clean();
$tag = change_fa($tag);
echo $tag;
}
endif;
//ハウツー説明文の取得
if ( !function_exists( 'get_howto_tag' ) ):
function get_howto_tag($caption, $id = ''){
$caption = apply_filters('howto_tag_caption', $caption, $id);
return '<p class="howto">'.$caption.'</p>';
}
endif;
//ハウツー説明文の生成
if ( !function_exists( 'generate_howto_tag' ) ):
function generate_howto_tag($caption, $id = ''){
echo get_howto_tag($caption, $id);
}
endif;
//解説ページへのリンク取得
if ( !function_exists( 'get_help_page_tag' ) ):
function get_help_page_tag($url, $text = null){
$link_text = $text ? $text : __( '解説ページ', THEME_NAME );
$tag = ' <a href="'.$url.'" target="_blank" rel="noopener" class="help-page"><span class="fa fa-question-circle" aria-hidden="true"></span> '.$link_text.'</a>';
$tag = change_fa($tag);
return $tag;
}
endif;
if ( !function_exists( 'generate_help_page_tag' ) ):
function generate_help_page_tag($url, $text = null){
echo get_help_page_tag($url, $text);
}
endif;
//通知メッセージの生成
if ( !function_exists( 'generate_notice_message_tag' ) ):
function generate_notice_message_tag($caption){?>
<div class="updated">
<p>
<strong>
<?php echo $caption; ?>
</strong>
</p>
</div>
<?php
}
endif;
//エラーメッセージの生成
if ( !function_exists( 'generate_error_message_tag' ) ):
function generate_error_message_tag($caption){?>
<div class="error">
<p>
<strong>
<?php echo $caption; ?>
</strong>
</p>
</div>
<?php
}
endif;
//テキストボックスの生成
if ( !function_exists( 'generate_textbox_tag' ) ):
function generate_textbox_tag($name, $value, $placeholder, $cols = DEFAULT_INPUT_COLS){
ob_start();?>
<input type="text" id="<?php echo $name; ?>" name="<?php echo $name; ?>" size="<?php echo $cols; ?>" value="<?php echo esc_attr(stripslashes_deep(strip_tags($value))); ?>" placeholder="<?php echo esc_attr($placeholder); ?>">
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//テキストエリアの生成
if ( !function_exists( 'generate_textarea_tag' ) ):
function generate_textarea_tag($name, $value, $placeholder, $rows = DEFAULT_INPUT_ROWS, $cols = DEFAULT_INPUT_COLS, $style = null){
$style_tag = null;
if ($style) {
$style_tag = ' style="'.$style.'"';
}
ob_start();?>
<textarea id="<?php echo $name; ?>" name="<?php echo $name; ?>" placeholder="<?php echo $placeholder; ?>" rows="<?php echo $rows; ?>" cols="<?php echo $cols; ?>"<?php echo $style_tag; ?>><?php echo $value; ?></textarea>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//ナンバーボックスの生成
if ( !function_exists( 'generate_number_tag' ) ):
function generate_number_tag($name, $value, $placeholder = '', $min = 1, $max = 100, $step = 1, $width = 100){
$width_attr = null;
if ($width) {
$width_attr = ' style="width: '.$width.'px;"';
}
ob_start();?>
<input type="number" name="<?php echo $name; ?>" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" min="<?php echo $min; ?>" max="<?php echo $max; ?>" step="<?php echo $step; ?>"<?php echo $width_attr; ?>>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//チェックボックスの生成
if ( !function_exists( 'generate_sort_options_tag' ) ):
function generate_sort_options_tag($keyword = null, $order_by = null){?>
<!-- 抽出フォーム -->
<div class="sort-options">
<form method="post" action="">
<input type="text" name="s" value="<?php echo $keyword; ?>" placeholder="<?php _e( 'タイトル検索', THEME_NAME ) ?>">
<?php
$options = array(
'title' => __( 'タイトル昇順', THEME_NAME ),
'title DESC' => __( 'タイトル降順', THEME_NAME ),
'date' => __( '作成日昇順', THEME_NAME ),
'date DESC, id DESC' => __( '作成日降順', THEME_NAME ),
'modified' => __( '編集日昇順', THEME_NAME ),
'modified DESC, id DESC' => __( '編集日降順', THEME_NAME ),
);
generate_selectbox_tag('order', $options, $order_by);
?>
<input type="submit" name="" value="<?php _e( '抽出', THEME_NAME ) ?>">
</form>
</div>
<?php
}
endif;
//サイトロゴの生成
if ( !function_exists( 'generate_the_site_logo_tag' ) ):
function generate_the_site_logo_tag($is_header = true){
$tag = 'div';
if (!is_singular() && !is_archive() && !is_search() && $is_header) {
$tag = 'h1';
}
if ($is_header) {
$class = ' logo-header';
} else {
$class = ' logo-footer';
}
$logo_url = get_the_site_logo_url();
$footer_logo_ur = get_footer_logo_url();
if (!$is_header && $footer_logo_ur) {
$logo_url = $footer_logo_ur;
}
if ( $logo_url ) {
$class .= ' logo-image';
} else {
$class .= ' logo-text';
}
if ($is_header) {
$img_class = 'header-site-logo-image';
} else {
$img_class = 'footer-site-logo-image';
}
//ロゴの幅設定
$site_logo_width = get_the_site_logo_width();
$width_attr = null;
if ($site_logo_width && $is_header) {
$width_attr = ' width="'.$site_logo_width.'"';
}
//ロゴの高さ設定
$site_logo_height = get_the_site_logo_height();
$height_attr = null;
if ($site_logo_height && $is_header) {
$height_attr = ' height="'.$site_logo_height.'"';
}
//パーマリンク設定とホームURLの出力を合わせる
$home_url = user_trailingslashit(get_home_url());
$home_url = apply_filters('site_logo_url', $home_url);
//サイトロゴテキスト(Alt属性)
$site_logo_text = apply_filters('site_logo_text', get_bloginfo('name'));
if ($is_header) {
$home_url = apply_filters('header_site_logo_url', $home_url);
$site_logo_text = apply_filters('header_site_logo_text', $site_logo_text);
} else {
$home_url = apply_filters('footer_site_logo_url', $home_url);
$site_logo_text = apply_filters('footer_site_logo_text', $site_logo_text);
}
$itemprop = null;
if (!$logo_url) {
$itemprop = ' itemprop="name about"';
}
$logo_before_tag = '<'.$tag.' class="logo'.$class.'"><a href="'.esc_url($home_url).'" class="site-name site-name-text-link" itemprop="url"><span class="site-name-text"'.$itemprop.'>';
$logo_after_tag = '</span></a></'.$tag.'>';
if ($logo_url) {
$site_logo_tag = '<img class="site-logo-image '.$img_class.'" src="'.$logo_url.'" alt="'.esc_attr($site_logo_text).'"'.$width_attr.$height_attr.'><meta itemprop="name about" content="' . esc_attr($site_logo_text) . '">';
} else {
$site_logo_tag = esc_html($site_logo_text);
}
$all_tag = $logo_before_tag.$site_logo_tag.$logo_after_tag;
echo apply_filters( 'the_site_logo_tag', $all_tag, $is_header, $home_url, $site_logo_text, $site_logo_width, $site_logo_height );
}
endif;
//カラーピッカーの生成
if ( !function_exists( 'generate_color_picker_tag' ) ):
function generate_color_picker_tag($name, $value, $label){
ob_start();?>
<p><label for="<?php echo $name; ?>"><?php echo $label; ?></label></p>
<p><input type="text" name="<?php echo $name; ?>" value="<?php echo esc_html($value); ?>" ></p>
<?php wp_enqueue_script( 'wp-color-picker' );
$data = minify_js('(function( $ ) {
var options = {
defaultColor: false,
change: function(event, ui){},
clear: function() {},
hide: true,
palettes: true
};
$("input:text[name=\''.$name.'\']").wpColorPicker(options);
})( jQuery );');
wp_add_inline_script( 'wp-color-picker', $data, 'after' ) ;
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//ビジュアルエディターの生成
if ( !function_exists( 'generate_visuel_editor_tag' ) ):
function generate_visuel_editor_tag($name, $content, $editor_id = 'wp_editor', $textarea_rows = 16){
ob_start();
$settings = array(
'textarea_name' => $name,
'textarea_rows' => $textarea_rows,
); //配列としてデータを渡すためname属性を指定する
wp_editor( $content, $editor_id, $settings );
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//メインカラム広告の詳細設定フォーム
if ( !function_exists( 'generate_main_column_ad_detail_setting_forms' ) ):
function generate_main_column_ad_detail_setting_forms($name, $value, $label_name = null, $label_value = null, $body_ad_name = null, $body_ad_value = null){ ?>
<span class="toggle">
<span class="toggle-link"><?php _e( '詳細設定', THEME_NAME ) ?></span>
<div class="toggle-content">
<div class="detail-area">
<?php
global $_MAIN_DATA_AD_FORMATS;
$options = $_MAIN_DATA_AD_FORMATS;
generate_selectbox_tag($name, $options, $value, __( 'フォーマット(広告ユニット)', THEME_NAME ));
//ラベル表示の設定
if ($label_name) {
echo '<p>';
generate_checkbox_tag( $label_name, $label_value, __( '広告ラベルを表示', THEME_NAME ));
echo '</p>';
}
//本文中広告用の設定
if (isset($body_ad_name)){
echo '<div>';
generate_checkbox_tag( $body_ad_name, $body_ad_value, __( '広告の表示数を制御する', THEME_NAME ));
echo '<div class="indent">';
generate_label_tag(OP_AD_POS_CONTENT_MIDDLE_COUNT, __( '先頭から', THEME_NAME ));
generate_number_tag(OP_AD_POS_CONTENT_MIDDLE_COUNT, get_ad_pos_content_middle_count(), -1, -1, 100, 1, 70);
echo '<span>'.__( '個まで', THEME_NAME ).'</span>';
echo '<br>';
echo '<span>'.__( '※-1で全てのH2見出し手前に広告を挿入', THEME_NAME ).'</span>';
echo '</div>';
echo '</div>';
}
?>
</div>
</div>
</span>
<?php
}
endif;
//トグルフォーム
if ( !function_exists( 'generate_toggle_area' ) ):
function generate_toggle_area($caption, $content){ ?>
<span class="toggle">
<span class="toggle-link"><?php echo $caption; ?></span>
<div class="toggle-content">
<?php echo $content; ?>
</div>
</span>
<?php
}
endif;
//トグルが入力されているか
if ( !function_exists( 'generate_toggle_entered' ) ):
function generate_toggle_entered($is_entered){ ?>
<span class="toggle-entered">[<?php
if ($is_entered) {
_e( '入力済', THEME_NAME );
} else {
_e( '未入力', THEME_NAME );
}
?>]</span>
<?php
}
endif;
//サイドバー広告の詳細設定フォーム
if ( !function_exists( 'generate_sidebar_ad_detail_setting_forms' ) ):
function generate_sidebar_ad_detail_setting_forms($name, $value, $label_name, $label_value){ ?>
<span class="toggle">
<span class="toggle-link"><?php _e( '詳細設定', THEME_NAME ) ?></span>
<div class="toggle-content">
<div class="detail-area">
<?php
global $_SIDEBAR_DATA_AD_FORMATS;
$options = $_SIDEBAR_DATA_AD_FORMATS;
generate_selectbox_tag($name, $options, $value, __( 'フォーマット(広告ユニット)', THEME_NAME ));
//ラベル表示の設定
echo '<p>';
generate_checkbox_tag( $label_name, $label_value, __( '広告ラベルを表示', THEME_NAME ));
echo '</p>';
?>
</div>
</div>
</span>
<?php
}
endif;
//画像をアップロードボックス生成
if ( !function_exists( 'generate_upload_image_tag' ) ):
function generate_upload_image_tag($name, $value, $id = null){
$thumb_id = isset($id) ? $id : $name;
ob_start();
?>
<input name="<?php echo $name; ?>" type="text" value="<?php echo $value; ?>" />
<input type="button" name="<?php echo $name; ?>_select" value="<?php _e( '選択', THEME_NAME ) ?>" />
<input type="button" name="<?php echo $name; ?>_clear" value="<?php _e( 'クリア', THEME_NAME ) ?>" />
<div id="<?php echo $thumb_id; ?>_thumbnail" class="uploded-thumbnail">
<?php if ($value): ?>
<img src="<?php echo $value; ?>" alt="選択中の画像">
<?php endif ?>
</div>
<?php if (0/*$value*/): ?>
<?php generate_tips_tag(__( '大きな画像は縮小して表示されます。', THEME_NAME )) ?>
<?php endif ?>
<script type="text/javascript">
(function ($) {
var custom_uploader;
$("input:button[name='<?php echo $name; ?>_select']").click(function(e) {
e.preventDefault();
if (custom_uploader) {
custom_uploader.open();
return;
}
custom_uploader = wp.media({
title: "<?php _e( '画像を選択してください。', THEME_NAME ) ?>",
/* ライブラリの一覧は画像のみにする */
library: {
type: "image"
},
button: {
text: "<?php _e( '画像の選択', THEME_NAME ) ?>"
},
/* 選択できる画像は 1 つだけにする */
multiple: false
});
custom_uploader.on("select", function() {
var images = custom_uploader.state().get("selection");
/* file の中に選択された画像の各種情報が入っている */
images.each(function(file){
/* テキストフォームと表示されたサムネイル画像があればクリア */
$("input:text[name='<?php echo $name; ?>']").val("");
$("#<?php echo $thumb_id; ?>_thumbnail").empty();
/* テキストフォームに画像の URL を表示 */
$("input:text[name='<?php echo $name; ?>']").val(file.attributes.sizes.full.url);
/* プレビュー用に選択されたサムネイル画像を表示 */
$("#<?php echo $thumb_id; ?>_thumbnail").append('<img src="'+file.attributes.sizes.full.url+'" />');
});
});
custom_uploader.open();
});
/* クリアボタンを押した時の処理 */
$("input:button[name='<?php echo $name; ?>_clear']").click(function() {
$("input:text[name='<?php echo $name; ?>']").val("");
$("#<?php echo $thumb_id; ?>_thumbnail").empty();
});
})(jQuery);
</script>
<?php
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//カテゴリチェックリストの作成
if ( !function_exists( 'generate_category_checklist' ) ):
function generate_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false,
$popular_cats = false, $walker = null, $checked_ontop = true) {
//wp_category_checklist()定義ファイルの呼び出し
require_once( ABSPATH . '/wp-admin/includes/template.php' ); ?>
<div class="category-checklist-wrap">
<ul id="category-checklist" data-wp-lists="list:category" class="category-checklist form-no-clear">
<?php wp_category_checklist(
$post_id,
$descendants_and_self,
$selected_cats,
$popular_cats,
$walker,
$checked_ontop
); ?>
</ul>
</div>
<?php
}
endif;
//階層化カテゴリチェックリストの出力
if ( !function_exists( 'generate_hierarchical_category_check_list' ) ):
function generate_hierarchical_category_check_list( $cat, $name, $checks, $width = 0 ) {
ob_start();
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
echo '<div class="tab-content category-check-list '.$name.'-list" style="width: '.$width.';">';
echo '<ul class="category-check-list-root"><li>'; echo "\n";
hierarchical_category_check_list( $cat, $name, $checks );
echo '</div>';
$res = ob_get_clean();
echo apply_filters('admin_input_form_tag', $res, $name);
}
endif;
//階層化カテゴリチェックリストの出力の再帰関数
if ( !function_exists( 'hierarchical_category_check_list' ) ):
function hierarchical_category_check_list( $cat, $name, $checks ) {
if (is_string($checks)) {
$checks = array();
}
// wpse-41548 // alchymyth // a hierarchical list of all categories //
$next = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cat);
if( $next ) {
foreach( $next as $cat ) :
$checked = '';
if (in_array($cat->term_id, $checks)) {
$checked = ' checked="checked"';
}
$id = $name.'_'.$cat->term_id;
echo '<ul><li><input type="checkbox" name="'.$name.'[]" id="'.$id.'" value="'.$cat->term_id.'"'.$checked.'><label for="'.$id.'">' . $cat->name . '</label>';
hierarchical_category_check_list( $cat->term_id, $name, $checks );
endforeach;
};
echo '</li></ul>'; echo "\n";
}
endif;
//タグチェックリスト
if ( !function_exists( 'generate_tagcloud_check_list' ) ):
function generate_tagcloud_check_list($name, $checks = array()){
if (is_string($checks)) {
$checks = array();
}
$html = '<div class="tagcloud tagcloud-list '.$name.'-list" style="width: 100%;">';
$tags = get_tags();
//_v($tags);
if ($tags) {
foreach($tags as $tag) {
$checked = null;
if (in_array($tag->term_id, $checks)) {
$checked = ' checked="checked"';
}
$id = $tag->term_id;
$input_id = $name.'-'.$id;
$html .= '<span class="tag-cloud-link admin-tag tag-link-"'.$id.'"><label for="'.$input_id.'"><input type="checkbox" id="'.$input_id.'" name="'.$name.'[]" value="'.$id.'"'.$checked.'>' . $tag->name . '<span class="tag-link-count">('.$tag->count.')</span></label></span>';
}
}
$html .= '</div>';
echo apply_filters('admin_input_form_tag', $html, $name);
}
endif;
//ページ表示チェックリスト
if ( !function_exists( 'generate_page_display_check_list' ) ):
function generate_page_display_check_list( $name, $checks, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
if (empty($checks)) {
$checks = array();
}
echo '<div class="tab-content page-display-check-list '.$name.'-list" style="width: '.$width.';"><ul>';
$id = $name.'_'.'is_front_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_front_page" id="'.$id.'" ';
checked(in_array('is_front_page', $checks));
echo '><label for="'.$id.'">' . __( 'トップページのみ', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_single';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_single" id="'.$id.'" ';
checked(in_array('is_single', $checks));
echo '><label for="'.$id.'">' . __( '投稿', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_page" id="'.$id.'" ';
checked(in_array('is_page', $checks));
echo '><label for="'.$id.'">' . __( '固定ページ', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_category';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_category" id="'.$id.'" ';
checked(in_array('is_category', $checks));
echo '><label for="'.$id.'">' . __( 'カテゴリー一覧', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_tag';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_tag" id="'.$id.'" ';
checked(in_array('is_tag', $checks));
echo '><label for="'.$id.'">' . __( 'タグ一覧', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_author';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_author" id="'.$id.'" ';
checked(in_array('is_author', $checks));
echo '><label for="'.$id.'">' . __( '著者一覧', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_archive';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_archive" id="'.$id.'" ';
checked(in_array('is_archive', $checks));
echo '><label for="'.$id.'">' . __( 'アーカイブ一覧', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_search';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_search" id="'.$id.'" ';
checked(in_array('is_search', $checks));
echo '><label for="'.$id.'">' . __( '検索結果一覧', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_404';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_404" id="'.$id.'" ';
checked(in_array('is_404', $checks));
echo '><label for="'.$id.'">' . __( '404ページ', THEME_NAME ) . '</label></li>';
$id = $name.'_'.'is_amp';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_amp" id="'.$id.'" ';
checked(in_array('is_amp', $checks));
echo '><label for="'.$id.'">' . __( 'AMPページ', THEME_NAME ) . '</label></li>';
if (is_wpforo_exist()) {
$id = $name.'_'.'is_wpforo_plugin_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_wpforo_plugin_page" id="'.$id.'" ';
checked(in_array('is_wpforo_plugin_page', $checks));
echo '><label for="'.$id.'">' . __( 'wpForoページ', THEME_NAME ) . '</label></li>';
}
if (is_bbpress_exist()) {
$id = $name.'_'.'is_bbpress_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_bbpress_page" id="'.$id.'" ';
checked(in_array('is_bbpress_page', $checks));
echo '><label for="'.$id.'">' . __( 'bbPressページ', THEME_NAME ) . '</label></li>';
}
if (is_buddypress_exist()) {
$id = $name.'_'.'is_buddypress_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_buddypress_page" id="'.$id.'" ';
checked(in_array('is_buddypress_page', $checks));
echo '><label for="'.$id.'">' . __( 'BuddyPressページ', THEME_NAME ) . '</label></li>';
}
if (is_plugin_fourm_exist()) {
$id = $name.'_'.'is_plugin_fourm_page';
echo '<li><input type="checkbox" name="'.$name.'[]" value="is_plugin_fourm_page" id="'.$id.'" ';
checked(in_array('is_plugin_fourm_page', $checks));
echo '><label for="'.$id.'">' . __( 'プラグインフォーラムページ(bbPress、BuddyPress、wpForo)', THEME_NAME ) . '</label></li>';
}
echo '</ul></div>';
}
endif;
//投稿者チェックリスト
if ( !function_exists( 'generate_author_check_list' ) ):
function generate_author_check_list( $name, $checks, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
if (empty($checks)) {
$checks = array();
}
echo '<div class="tab-content author-check-list '.$name.'-list" style="width: '.$width.';"><ul>';
$users = get_users( array('orderby'=>'ID','order'=>'ASC') );
foreach($users as $user) {
$uid = $user->ID;
$id = $name.'_'.$uid;
echo '<li><input type="checkbox" name="'.$name.'[]" value="'.$uid.'" id="'.$id.'"';
checked(in_array($uid, $checks));
echo '><label for="'.$id.'">' . $user->display_name . '</label></li>';
} //foreach
echo '</ul></div>';
}
endif;
//投稿ページリスト
if ( !function_exists( 'generate_post_check_list' ) ):
function generate_post_check_list( $name, $value, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
echo '<div class="tab-content post-check-list '.$name.'-list" style="width: '.$width.';">';
echo '<p>'.__( '投稿ID入力', THEME_NAME ).'</p>';
generate_textbox_tag($name, $value, __( '例:111,222,333', THEME_NAME ));
echo '<p>'.__( '投稿IDをカンマ区切りで入力してください。', THEME_NAME ).'</p>';
echo '</div>';
}
endif;
//固定ページリスト
if ( !function_exists( 'generate_fixed_page_check_list' ) ):
function generate_fixed_page_check_list( $name, $value, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
echo '<div class="tab-content fixed-page-check-list '.$name.'-list" style="width: '.$width.';">';
echo '<p>'.__( '固定ページID入力', THEME_NAME ).'</p>';
generate_textbox_tag($name, $value, __( '例:111,222,333', THEME_NAME ));
echo '<p>'.__( '固定ページIDをカンマ区切りで入力してください。', THEME_NAME ).'</p>';
echo '</div>';
}
endif;
//タグエディット
if ( !function_exists( 'generate_tag_check_list' ) ):
function generate_tag_check_list( $name, $value, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
echo '<div class="tab-content tag-check-list '.$name.'-list" style="width: '.$width.';">';
echo '<p>'.__( 'タグID入力', THEME_NAME ).'</p>';
generate_textbox_tag($name, $value, __( '例:111,222,333', THEME_NAME ));
echo '<p>'.__( 'タグIDをカンマ区切りで入力してください。', THEME_NAME ).'</p>';
echo '</div>';
}
endif;
//カスタム投稿タイプエディット
if ( !function_exists( 'generate_custom_post_type_check_list' ) ):
function generate_custom_post_type_check_list( $name, $checks, $width = 0 ) {
if ($width == 0) {
$width = 'auto';
} else {
$width = $width.'px';
}
if (empty($checks)) {
$checks = array();
}
echo '<div class="tab-content custom-post-type-check-list '.$name.'-list cocoon-donation-privilege" style="width: '.$width.';"><ul>';
$custom_post_types = get_custum_post_types();
foreach($custom_post_types as $custom_post_type) {
$post_type_object = get_post_type_object($custom_post_type);
$label = ($post_type_object->label) ? $post_type_object->label : $custom_post_type;
$id = $id = $name.'_'.$custom_post_type;
echo '<li><input type="checkbox" name="'.esc_attr($name).'[]" value="'.esc_attr($custom_post_type).'" id="'.esc_attr($id).'"';
checked(in_array($custom_post_type, $checks));
echo '><label for="'.$id.'">' . esc_html($label) . '</label></li>';
} //foreach
echo '</ul></div>';
// echo '<div class="tab-content tag-check-list '.$name.'-list" style="width: '.$width.';">';
// echo '<p>'.__( 'タグID入力', THEME_NAME ).'</p>';
// generate_textbox_tag($name, $value, __( '例:111,222,333', THEME_NAME ));
// echo '<p>'.__( 'タグIDをカンマ区切りで入力してください。', THEME_NAME ).'</p>';
// echo '</div>';
}
endif;
//Windows Live Writerで編集するためのリンクを作成する
if ( !function_exists( 'wlw_edit_post_link' ) ):
function wlw_edit_post_link($link, $before = '', $after = ''){
$query = ( is_single() ? 'postid' : 'pageid' );