PluginProbe ʕ •ᴥ•ʔ
VK Blocks / 0.16.2
VK Blocks v0.16.2
1.123.0 1.122.0 1.121.0 1.120.0 1.119.2 1.119.1 1.119.0 1.118.7 1.82.0.0 1.82.0.1 1.83.0.0 1.83.0.1 1.84.0.0 1.84.0.1 1.85.0.2 1.85.0.3 1.85.1.0 1.85.1.1 1.86.0.0 1.86.0.1 1.86.1.0 1.87.0.0 1.87.0.1 1.88.0.1 1.88.0.2 1.89.0.0 1.9.2 1.90.0.0 1.90.0.1 1.90.1.1 1.91.0.0 1.91.1.1 1.92.0.0 1.92.0.1 1.92.1.0 1.92.1.1 1.93.0.0 trunk 1.93.0.1 0.1.1 1.93.1.0 0.10.3 1.93.1.1 0.11.0 1.94.0.0 0.12.6 1.94.0.1 0.15.1 1.94.1.0 0.16.2 1.94.2.1 0.17.6 1.94.2.2 0.2.2 1.95.0.3 0.22.4 1.95.0.4 0.26.7 1.96.2.0 0.3.2 1.96.2.1 0.31.0 1.97.0.1 0.35.5 1.97.0.2 0.37.5 1.99.0.0 0.38.8 1.99.0.1 0.39.4 0.4.7 0.41.0 0.42.0 0.44.13 0.45.2 0.46.1 0.47.0 0.48.0 0.49.8 0.5.2 0.50.3 0.51.0 0.52.2 0.53.2 0.54.0 0.55.0 0.56.2 0.56.3 0.57.6 0.58.10 0.59.0 0.6.0 0.60.1 0.61.2 0.7.1 0.8.2 1.0.16 1.10.0 1.100.0.0 1.100.0.1 1.102.0.0 1.102.0.1 1.103.0.0 1.104.0.0 1.104.0.1 1.105.1.0 1.105.1.1 1.106.0.0 1.106.0.1 1.107.0.0 1.107.0.1 1.107.0.2 1.108.0.0 1.108.0.1 1.109.0.0 1.109.0.1 1.11.4 1.110.0.0 1.110.0.1 1.111.0.0 1.111.0.1 1.111.0.2 1.112.0.0 1.112.0.1 1.113.0.0 1.113.0.1 1.114.0.0 1.114.0.1 1.114.2.0 1.114.2.1 1.115.0.0 1.115.0.1 1.115.1.0 1.115.1.1 1.115.2.0 1.115.2.1 1.116.0.0 1.116.0.1 1.116.1.0 1.116.1.1 1.116.2.0 1.117.0.0 1.117.0.1 1.117.1.0 1.118.2 1.118.5 1.12.0 1.13.2 1.14.1 1.15.1 1.16.11 1.17.0 1.18.6 1.19.0 1.19.1 1.2.3 1.20.7 1.21.0 1.22.4 1.23.0 1.24.5 1.25.1 1.26.2 1.27.7.2 1.28.0.1 1.29.2.0 1.3.9 1.30.0.1 1.31.0.1 1.32.0.2 1.33.2.1 1.36.1.5 1.37.0.0 1.39.2.1 1.4.6 1.40.0.1 1.40.1.0 1.40.1.1 1.41.0.0 1.41.0.1 1.41.2.2 1.41.2.3 1.43.0.0 1.43.0.1 1.43.0.2 1.44.0.0 1.44.0.1 1.45.0.0 1.45.0.1 1.46.0.0 1.46.0.1 1.47.0.0 1.47.0.1 1.47.1.0 1.48.0.0 1.48.0.1 1.48.0.2 1.48.1.0 1.48.1.1 1.5.0 1.50.0.0 1.50.0.1 1.51.0.0 1.51.0.1 1.52.0.0 1.52.0.1 1.53.0.0 1.53.0.1 1.54.0.0 1.54.0.1 1.55.0.0 1.55.0.1 1.56.0.0 1.56.0.1 1.57.0.0 1.57.0.2 1.57.0.3 1.57.0.4 1.57.0.5 1.57.1.0 1.57.1.1 1.57.1.2 1.58.0.0 1.58.0.1 1.59.0.0 1.59.0.1 1.6.0 1.60.0.0 1.60.0.1 1.63.0.0 1.63.0.1 1.64.0.0 1.64.0.1 1.64.1.0 1.64.1.2 1.67.0.0 1.67.0.1 1.68.0.0 1.68.0.1 1.69.0.0 1.69.0.1 1.69.1.1 1.69.1.2 1.7.1 1.70.0.0 1.70.0.1 1.71.0.0 1.71.0.1 1.72.0.0 1.72.1.0 1.72.1.1 1.73.0.0 1.73.0.1 1.74.0.0 1.74.0.1 1.75.0.0 1.75.1.0 1.75.1.1 1.76.0.0 1.76.0.1 1.76.1.0 1.76.1.1 1.76.2.0 1.76.2.1 1.77.0.0 1.77.0.1 1.78.0.0 1.78.0.1 1.79.0.0 1.79.0.1 1.79.0.2 1.79.0.3 1.79.1.0 1.79.1.1 1.8.2 1.80.1.0 1.80.1.1 1.80.1.2 1.81.0.1 1.81.0.2
vk-blocks / inc / term-color / package / class.term-color.php
vk-blocks / inc / term-color / package Last commit date
class.term-color.php 6 years ago
class.term-color.php
252 lines
1 <?php
2
3 /*
4 このファイルの�
5 �ファイルは
6 https://github.com/vektor-inc/vektor-wp-libraries
7 にあります。修正の際は上記リポジトリのデータを修正してください。
8 */
9
10 if ( ! class_exists( 'Vk_term_color' ) ) {
11
12 class Vk_term_color {
13
14 /*-------------------------------------------*/
15 /* REGISTER TERM META
16 /*-------------------------------------------*/
17
18 function term_meta_color() {
19
20 register_meta( 'term', 'term_color', array( $this, 'sanitize_hex' ) );
21 }
22
23 /*-------------------------------------------*/
24 /* SANITIZE DATA
25 /*-------------------------------------------*/
26
27 public static function sanitize_hex( $color ) {
28 // sanitize_hex_color() は undefined function くらう
29 $color = ltrim( $color, '#' );
30 return preg_match( '/([A-Fa-f0-9]{3}){1,2}$/', $color ) ? $color : '';
31 }
32
33 /*-------------------------------------------*/
34 /* タクソノミー新規追加ページでの日本語�
35 �力フォーム
36 /*-------------------------------------------*/
37 function taxonomy_add_new_meta_field_color() {
38
39 // this will add the custom meta field to the add new term page
40 ?>
41 <div class="form-field">
42 <?php wp_nonce_field( basename( __FILE__ ), 'term_color_nonce' ); ?>
43 <label for="term_color"><?php _e( 'Color', 'lightning-pro' ); ?></label>
44 <input type="text" name="term_color" id="term_color" class="term_color" value="">
45 </div>
46 <?php
47 }
48
49 /*-------------------------------------------*/
50 /* タクソノミー編集ページでのフォーム
51 /*-------------------------------------------*/
52 function taxonomy_add_edit_meta_field_color( $term ) {
53
54 // put the term ID into a variable
55 $term_color = Vk_term_color::get_term_color( $term->term_id );
56 ?>
57 <tr class="form-field">
58 <th scope="row" valign="top"><label for="term_color"><?php _e( 'Color', 'lightning-pro' ); ?></label></th>
59 <td>
60 <?php wp_nonce_field( basename( __FILE__ ), 'term_color_nonce' ); ?>
61 <input type="text" name="term_color" id="term_color" class="term_color" value="<?php echo $term_color; ?>">
62 </td>
63 </tr>
64 <?php
65 }
66
67 /*-------------------------------------------*/
68 /* カラーの保存処理
69 /*-------------------------------------------*/
70 // Save extra taxonomy fields callback function.
71 function save_term_meta_color( $term_id ) {
72
73 // verify the nonce --- remove if you don't care
74 if ( ! isset( $_POST['term_color_nonce'] ) || ! wp_verify_nonce( $_POST['term_color_nonce'], basename( __FILE__ ) ) ) {
75 return;
76 }
77
78 if ( isset( $_POST['term_color'] ) ) {
79 $now_value = get_term_meta( $term_id, 'term_color', true );
80 $new_value = $_POST['term_color'];
81 if ( $now_value != $new_value ) {
82 update_term_meta( $term_id, 'term_color', $new_value );
83 } else {
84 add_term_meta( $term_id, 'term_color', $new_value );
85 }
86 }
87 }
88
89 /*-------------------------------------------*/
90 /* 管理画面 _ カラーピッカーのスクリプトの読み込み
91 /*-------------------------------------------*/
92
93 function admin_enqueue_scripts( $hook_suffix ) {
94
95 // if ( 'edit-tags.php' !== $hook_suffix || 'category' !== get_current_screen()->taxonomy )
96 // return;
97
98 wp_enqueue_style( 'wp-color-picker' );
99 wp_enqueue_script( 'wp-color-picker' );
100
101 // add_action( 'admin_head', 'lmu_term_colors_print_styles' );
102 add_action( 'admin_footer', array( $this, 'term_colors_print_scripts' ) );
103 }
104
105 function term_colors_print_styles() {
106 ?>
107
108 <style type="text/css">
109 .column-color { width: 50px; }
110 .column-color .color-block { display: inline-block; width: 28px; height: 28px; border: 1px solid #ddd; }
111 </style>
112 <?php
113 }
114
115 function term_colors_print_scripts() {
116 ?>
117
118 <script type="text/javascript">
119 jQuery( document ).ready( function( $ ) {
120 $( '.term_color' ).wpColorPicker();
121 } );
122 </script>
123 <?php
124 }
125
126 /*-------------------------------------------*/
127 /* 管理画面 _ カテゴリー一覧でカラムの追加
128 /*-------------------------------------------*/
129
130 function edit_term_columns( $columns ) {
131
132 $columns['color'] = __( 'Color', 'lightning-pro' );
133
134 return $columns;
135 }
136
137
138 function manage_term_custom_column( $out, $column, $term_id ) {
139
140 if ( 'color' === $column ) {
141
142 $color = Vk_term_color::get_term_color( $term_id );
143
144 if ( ! $color ) {
145 $color = '#ffffff';
146 }
147
148 $out = sprintf( '<span class="color-block" style="background:%s;">&nbsp;</span>', esc_attr( $color ) );
149 }
150
151 return $out;
152 }
153
154 /*-------------------------------------------*/
155 /* termのカラーを取得
156 /*-------------------------------------------*/
157 public static function get_term_color( $term_id ) {
158 $term_color_default = '#999999';
159 $term_color_default = apply_filters( 'term_color_default_custom', $term_color_default );
160 if ( isset( $term_id ) ) {
161 $term_color = Vk_term_color::sanitize_hex( get_term_meta( $term_id, 'term_color', true ) );
162 $term_color = ( $term_color ) ? '#' . $term_color : $term_color_default;
163 } else {
164 $term_color = $term_color_default;
165 }
166 return $term_color;
167 }
168
169 /*-------------------------------------------*/
170 /* termのカラーを取得
171 /*-------------------------------------------*/
172 public static function get_single_term_with_color( $post = '', $args = array() ) {
173 if ( ! $post ) {
174 global $post;
175 }
176
177 $args_default = array(
178 'class' => '',
179 );
180 $args = wp_parse_args( $args, $args_default );
181
182 $outer_class = '';
183 if ( ! empty( $args['class'] ) ) {
184 $outer_class = ' class="' . esc_attr( $args['class'] ) . '"';
185 }
186
187 $taxonomies = get_the_taxonomies();
188 $single_term_with_color = '';
189 if ( $taxonomies ) :
190 // get $taxonomy name
191 $taxonomy = key( $taxonomies );
192 $terms = get_the_terms( $post->ID, $taxonomy );
193 $term_name = esc_html( $terms[0]->name );
194 $term_color = Vk_term_color::get_term_color( $terms[0]->term_id );
195 $term_color = ( $term_color ) ? ' style="color:#fff;background-color:' . $term_color . '"' : '';
196 $single_term_with_color .= '<span' . $outer_class . $term_color . '>' . $term_name . '</span>';
197 endif;
198 return $single_term_with_color;
199 }
200
201 /*-------------------------------------------*/
202 /* term color を有効化する taxonomy
203 /*-------------------------------------------*/
204 public function get_term_color_taxonomies() {
205 /*
206 最初Global変数指定をしていたが、 Global変数では
207 複数の term color が存在した場合に実行タイミングの都合上任意に指定が効かないため、
208 フックでの指定を行う
209 */
210 global $vk_term_color_taxonomies;
211 if ( $vk_term_color_taxonomies ) {
212 $taxonomies = $vk_term_color_taxonomies;
213 } else {
214 $taxonomies = array( 'category', 'post_tag' );
215 }
216 $taxonomies = apply_filters( 'term_color_taxonomies_custom', $taxonomies );
217 // 重複の値を削除
218 $taxonomies = array_unique( $taxonomies );
219 // 特に影響はないがキーを振り直す
220 $taxonomies = array_values( $taxonomies );
221 return $taxonomies;
222 }
223 /*-------------------------------------------*/
224 /* 実行
225 /*-------------------------------------------*/
226 public function __construct() {
227 add_action( 'init', array( $this, 'term_meta_color' ) );
228 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
229
230 /*-------------------------------------------*/
231 /* 管理画面 _ 各種処理発火
232 /*-------------------------------------------*/
233 // カラーピッカーを追加するタクソノミー
234
235 $taxonomies = Vk_term_color::get_term_color_taxonomies();
236
237 // 該当のタクソノミー分ループ処理する
238 foreach ( $taxonomies as $key => $value ) {
239 add_action( $value . '_add_form_fields', array( $this, 'taxonomy_add_new_meta_field_color' ), 10, 2 );
240 add_action( $value . '_edit_form_fields', array( $this, 'taxonomy_add_edit_meta_field_color' ), 10, 2 );
241 add_action( 'edited_' . $value, array( $this, 'save_term_meta_color' ), 10, 2 );
242 add_action( 'create_' . $value, array( $this, 'save_term_meta_color' ), 10, 2 );
243 add_filter( 'manage_edit-' . $value . '_columns', array( $this, 'edit_term_columns' ) );
244 add_filter( 'manage_' . $value . '_custom_column', array( $this, 'manage_term_custom_column' ), 10, 3 );
245 }
246 }
247 }
248
249 $Vk_term_color = new Vk_term_color();
250
251 }
252