PluginProbe ʕ •ᴥ•ʔ
Menu Icons by Themeisle – Add Icons to Navigation Menus / 0.2.2
Menu Icons by Themeisle – Add Icons to Navigation Menus v0.2.2
trunk 0.1.0 0.1.1 0.1.2 0.1.3 0.1.4 0.1.5 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.11.2 0.11.3 0.11.4 0.11.5 0.12.0 0.12.1 0.12.10 0.12.11 0.12.12 0.12.2 0.12.3 0.12.4 0.12.5 0.12.6 0.12.7 0.12.8 0.12.9 0.13.0 0.13.1 0.13.10 0.13.11 0.13.12 0.13.13 0.13.14 0.13.15 0.13.16 0.13.17 0.13.18 0.13.19 0.13.2 0.13.20 0.13.21 0.13.22 0.13.23 0.13.3 0.13.4 0.13.5 0.13.6 0.13.7 0.13.8 0.13.9 0.2.0 0.2.1 0.2.2 0.2.3 0.3.0 0.3.1 0.3.2 0.4.0 0.5.0 0.5.1 0.6.0 0.7.0 0.8.0 0.8.1 0.9.0 0.9.2
menu-icons / includes / type-fonts.php
menu-icons / includes Last commit date
admin.php 12 years ago type-dashicons.php 12 years ago type-fontawesome.php 12 years ago type-fonts.php 12 years ago type-genericons.php 12 years ago type.php 12 years ago walker-nav-menu-edit.php 12 years ago
type-fonts.php
210 lines
1 <?php
2 /**
3 * Icon fonts handler
4 *
5 * @package Menu_Icons
6 * @author Dzikri Aziz <kvcrvt@gmail.com>
7 */
8
9 require_once dirname( __FILE__ ) . '/type.php';
10
11 /**
12 * Generic handler for icon fonts
13 *
14 */
15 abstract class Menu_Icons_Type_Fonts extends Menu_Icons_Type {
16
17 /**
18 * Get icon names
19 *
20 * @since 0.1.0
21 * @return array
22 */
23 abstract function get_names();
24
25
26 /**
27 * Print field for icons selection
28 *
29 * @since 0.1.0
30 * @param int $id Menu item ID
31 * @param array $meta_value Current value of 'menu-icons' metadata
32 */
33 public function the_field( $id, $meta_value ) {
34 $current = isset( $meta_value[ $this->key ] ) ? $meta_value[ $this->key ] : '';
35 $input_id = sprintf( 'menu-icons-%d-%s', $id, $this->key );
36 $input_name = sprintf( 'menu-icons[%d][%s]', $id, $this->key );
37 ?>
38 <?php printf(
39 '<p class="field-icon-child description menu-icon-type-%1$s" data-dep-on="%1$s">',
40 esc_attr( $this->type )
41 ) ?>
42 <label for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_html( $this->label ); ?></label>
43 <?php printf(
44 '<select id="%s" name="%s" data-key="%s">',
45 esc_attr( $input_id ),
46 esc_attr( esc_attr( $input_name ) ),
47 esc_attr( $this->key )
48 ) ?>
49 <?php printf(
50 '<option value=""%s>%s</option>',
51 selected( empty( $current ), true, false ),
52 esc_html__( '&mdash; Select &mdash;', 'menu-icons' )
53 ) ?>
54 <?php foreach ( $this->get_names() as $group ) : ?>
55 <optgroup label="<?php echo esc_attr( $group['label'] ) ?>">
56 <?php foreach ( $group['items'] as $value => $label ) : ?>
57 <?php printf(
58 '<option value="%s"%s>%s</option>',
59 esc_attr( $value ),
60 selected( $meta_value[ $this->key ], $value, false ),
61 esc_html( $label )
62 ) ?>
63 <?php endforeach; ?>
64 </optgroup>
65 <?php endforeach; ?>
66 </select>
67 </p>
68 <?php
69 }
70
71
72 /**
73 * Preview
74 *
75 * @since 0.2.0
76 * @param string $id Menu item ID
77 * @param array $meta_value Menu item metadata value
78 * @return array
79 */
80 public function preview_cb( $id, $meta_value ) {
81 return sprintf(
82 '<i class="_icon %s %s"></i>',
83 esc_attr( $this->type ),
84 esc_attr( $meta_value[ $this->key ] )
85 );
86 }
87
88
89 /**
90 * Media frame data
91 *
92 * @since 0.2.0
93 * @param string $id Icon type ID
94 * @return array
95 */
96 public function frame_cb( $id ) {
97 $data = array(
98 'controller' => 'miFont',
99 );
100
101 foreach ( $this->get_names() as $group ) {
102 $data['groups'][ $group['key'] ] = $group['label'];
103
104 foreach ( $group['items'] as $id => $label ) {
105 $data['items'][] = array(
106 'group' => $group['key'],
107 'id' => $id,
108 'label' => $label,
109 );
110 }
111 }
112
113 return $data;
114 }
115
116
117 /**
118 * Media frame templates
119 *
120 * @since 0.2.0
121 * @return array
122 */
123 public function templates() {
124 $icon = sprintf(
125 '<i class="_icon %s {{ data.icon }}" style="
126 font-size:{{ data.size }}em;
127 vertical-align:{{ data["vertical-align"] }};
128 "></i>',
129 esc_attr( $this->type )
130 );
131
132 $templates = array(
133 'field' => sprintf(
134 '<i class="_icon %1$s {{ data["%1$s-icon"] }}"></i>',
135 esc_attr( $this->type )
136 ),
137 'item' => sprintf(
138 '<div class="attachment-preview">
139 <span class="_icon"><i class="%s {{ data.id }}"></i></span>
140 <div class="filename"><div>{{ data.label }}</div></div>
141 <a class="check" href="#" title="%s"><div class="media-modal-icon"></div></a>
142 </div>',
143 esc_attr( $this->type ),
144 esc_attr__( 'Deselect', 'menu-icons' )
145 ),
146 'preview-before' => sprintf(
147 '<a href="#">%s {{ data.title }}</a>',
148 $icon
149 ),
150 'preview-after' => sprintf(
151 '<a href="#">{{ data.title }} %s</i></a>',
152 $icon
153 ),
154 );
155
156 return $templates;
157 }
158
159
160 /**
161 * Add icon to menu title
162 *
163 * Icon types should override this method if they want to provide different markup.
164 *
165 * @since 0.1.0
166 * @param string $title Menu item title
167 * @param array $values Menu item metadata value
168 *
169 * @return string
170 */
171 protected function add_icon( $title, $values ) {
172 $title = sprintf(
173 '%s<i class="_mi _%s %s %s"%s></i>%s',
174 'before' === $values['position'] ? '' : $title,
175 esc_attr( $values['position'] ),
176 esc_attr( $this->type ),
177 esc_attr( $values[ $this->key ] ),
178 $this->get_style( $values ),
179 'after' === $values['position'] ? '' : $title
180 );
181
182 return $title;
183 }
184
185
186 /**
187 * Inline style for icon size, etc
188 *
189 * @since 0.2.0
190 * @param array $values Menu item metadata value
191 * @return string
192 */
193 protected function get_style( $values ) {
194 $style = '';
195
196 if ( ! empty( $values['size'] ) ) {
197 $style .= sprintf( 'font-size:%sem;', $values['size'] );
198 }
199 if ( ! empty( $values['vertical-align'] ) ) {
200 $style .= sprintf( 'vertical-align:%s;', $values['vertical-align'] );
201 }
202
203 if ( ! empty( $style ) ) {
204 $style = sprintf( ' style="%s"', $style );
205 }
206
207 return $style;
208 }
209 }
210