PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-icon_picker.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago index.php 1 year ago
class-acf-field-icon_picker.php
799 lines
1 <?php
2 /**
3 * This is a PHP file containing the code for the acf_field_icon_picker class.
4 *
5 * @package Advanced_Custom_Fields_Pro
6 */
7
8 if ( ! class_exists( 'acf_field_icon_picker' ) ) :
9
10 /**
11 * Class acf_field_icon_picker.
12 */
13 class acf_field_icon_picker extends acf_field {
14 /**
15 * Initialize icon picker field
16 *
17 * @since 6.3
18 *
19 * @return void
20 */
21 public function initialize() {
22 $this->name = 'icon_picker';
23 $this->label = __( 'Icon Picker', 'acf' );
24 $this->public = true;
25 $this->category = 'advanced';
26 $this->description = __( 'An interactive UI for selecting an icon. Select from Dashicons, the media library, or a standalone URL input.', 'acf' );
27 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-icon-picker.png';
28 $this->doc_url = 'https://www.advancedcustomfields.com/resources/icon-picker/';
29 $this->defaults = array(
30 'library' => 'all',
31 'tabs' => array_keys( $this->get_tabs() ),
32 'return_format' => 'string',
33 'default_value' => array(
34 'type' => null,
35 'value' => null,
36 ),
37 );
38 }
39
40 /**
41 * Gets the available tabs for the icon picker field.
42 *
43 * @since 6.3
44 *
45 * @return array
46 */
47 public function get_tabs() {
48 $tabs = array(
49 'dashicons' => esc_html__( 'Dashicons', 'acf' ),
50 );
51
52 if ( current_user_can( 'upload_files' ) ) {
53 $tabs['media_library'] = esc_html__( 'Media Library', 'acf' );
54 }
55
56 $tabs['url'] = esc_html__( 'URL', 'acf' );
57
58 /**
59 * Allows filtering the tabs used by the icon picker.
60 *
61 * @since 6.3
62 *
63 * @param array $tabs An associative array of tabs in key => label format.
64 * @return array
65 */
66 return apply_filters( 'acf/fields/icon_picker/tabs', $tabs );
67 }
68
69 /**
70 * Renders icon picker field
71 *
72 * @since 6.3
73 *
74 * @param object $field The ACF Field
75 * @return void
76 */
77 public function render_field( $field ) {
78 $uploader = acf_get_setting( 'uploader' );
79
80 // Enqueue uploader scripts
81 if ( $uploader === 'wp' ) {
82 acf_enqueue_uploader();
83 }
84
85 $div = array(
86 'id' => $field['id'],
87 'class' => $field['class'] . ' acf-icon-picker',
88 );
89
90 echo '<div ' . acf_esc_attrs( $div ) . '>';
91
92 acf_hidden_input(
93 array(
94 'name' => $field['name'] . '[type]',
95 'value' => $field['value']['type'],
96 'data-hidden-type' => 'type',
97 )
98 );
99 acf_hidden_input(
100 array(
101 'name' => $field['name'] . '[value]',
102 'value' => $field['value']['value'],
103 'data-hidden-type' => 'value',
104 )
105 );
106
107 if ( ! is_array( $field['tabs'] ) ) {
108 $field['tabs'] = array();
109 }
110
111 $tabs = $this->get_tabs();
112 $shown = array_filter(
113 $tabs,
114 function ( $tab ) use ( $field ) {
115 return in_array( $tab, $field['tabs'], true );
116 },
117 ARRAY_FILTER_USE_KEY
118 );
119
120 foreach ( $shown as $name => $label ) {
121 if ( count( $shown ) > 1 ) {
122 acf_render_field_wrap(
123 array(
124 'type' => 'tab',
125 'label' => $label,
126 'key' => 'acf_icon_picker_tabs',
127 'selected' => $name === $field['value']['type'],
128 'unique_tab_key' => $name,
129 )
130 );
131 }
132
133 $wrapper_class = str_replace( '_', '-', $name );
134 echo '<div class="acf-icon-picker-tabs acf-icon-picker-' . esc_attr( $wrapper_class ) . '-tabs">';
135
136 switch ( $name ) {
137 case 'dashicons':
138 echo '<div class="acf-dashicons-search-wrap">';
139 acf_text_input(
140 array(
141 'class' => 'acf-dashicons-search-input',
142 'placeholder' => esc_html__( 'Search icons...', 'acf' ),
143 'type' => 'search',
144 )
145 );
146 echo '</div>';
147 echo '<div class="acf-dashicons-list"></div>';
148 ?>
149 <div class="acf-dashicons-list-empty">
150 <img src="<?php echo esc_url( acf_get_url( 'assets/images/face-sad.svg' ) ); ?>" />
151 <p class="acf-no-results-text">
152 <?php
153 printf(
154 /* translators: %s: The invalid search term */
155 esc_html__( "No search results for '%s'", 'acf' ),
156 '<span class="acf-invalid-dashicon-search-term"></span>'
157 );
158 ?>
159 </p>
160 </div>
161
162 <?php
163 break;
164 case 'media_library':
165 ?>
166 <div class="acf-icon-picker-tab" data-category="<?php echo esc_attr( $name ); ?>">
167 <div class="acf-icon-picker-media-library">
168 <?php
169 $button_style = 'display: none;';
170
171 if ( in_array( $field['value']['type'], array( 'media_library', 'dashicons' ), true ) && ! empty( $field['value']['value'] ) ) {
172 $button_style = '';
173 }
174 ?>
175 <button
176 aria-label="<?php esc_attr_e( 'Click to change the icon in the Media Library', 'acf' ); ?>"
177 class="acf-icon-picker-media-library-preview"
178 style="<?php echo esc_attr( $button_style ); ?>"
179 >
180 <div class="acf-icon-picker-media-library-preview-img" style="<?php echo esc_attr( 'media_library' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
181 <?php
182 $img_url = wp_get_attachment_image_url( $field['value']['value'], 'thumbnail' );
183 // If the type is media_library, then we need to show the media library preview.
184 ?>
185 <img src="<?php echo esc_url( $img_url ); ?>" alt="<?php esc_attr_e( 'The currently selected image preview', 'acf' ); ?>" />
186 </div>
187 <div class="acf-icon-picker-media-library-preview-dashicon" style="<?php echo esc_attr( 'dashicons' !== $field['value']['type'] ? 'display: none;' : '' ); ?>">
188 <div class="dashicons <?php echo esc_attr( $field['value']['value'] ); ?>">
189 </div>
190 </div>
191 </button>
192 <button class="acf-icon-picker-media-library-button">
193 <div class="acf-icon-picker-media-library-button-icon dashicons dashicons-admin-media"></div>
194 <span><?php esc_html_e( 'Browse Media Library', 'acf' ); ?></span>
195 </button>
196 </div>
197 </div>
198 <?php
199 break;
200 case 'url':
201 echo '<div class="acf-icon-picker-url">';
202 acf_text_input(
203 array(
204 'class' => 'acf-icon_url',
205 'value' => $field['value']['type'] === 'url' ? $field['value']['value'] : '',
206 )
207 );
208
209 // Helper Text
210 ?>
211 <p class="description"><?php esc_html_e( 'The URL to the icon you\'d like to use, or svg as Data URI', 'acf' ); ?></p>
212 <?php
213 echo '</div>';
214 break;
215 default:
216 do_action( 'acf/fields/icon_picker/tab/' . $name, $field );
217 }
218
219 echo '</div>';
220 }
221
222 echo '</div>';
223 }
224
225 /**
226 * Renders field settings for the icon picker field.
227 *
228 * @since 6.3
229 *
230 * @param array $field The icon picker field object.
231 * @return void
232 */
233 public function render_field_settings( $field ) {
234 acf_render_field_setting(
235 $field,
236 array(
237 'label' => __( 'Tabs', 'acf' ),
238 'instructions' => __( 'Select where content editors can choose the icon from.', 'acf' ),
239 'type' => 'checkbox',
240 'name' => 'tabs',
241 'choices' => $this->get_tabs(),
242 )
243 );
244
245 $return_format_doc = sprintf(
246 '<a href="%s" target="_blank">%s</a>',
247 'https://www.advancedcustomfields.com/resources/icon-picker/',
248 __( 'Learn More', 'acf' )
249 );
250
251 $return_format_instructions = sprintf(
252 /* translators: %s - link to documentation */
253 __( 'Specify the return format for the icon. %s', 'acf' ),
254 $return_format_doc
255 );
256
257 acf_render_field_setting(
258 $field,
259 array(
260 'label' => __( 'Return Format', 'acf' ),
261 'instructions' => $return_format_instructions,
262 'type' => 'radio',
263 'name' => 'return_format',
264 'choices' => array(
265 'string' => __( 'String', 'acf' ),
266 'array' => __( 'Array', 'acf' ),
267 ),
268 'layout' => 'horizontal',
269 )
270 );
271 }
272
273 /**
274 * Localizes text for Icon Picker
275 *
276 * @since 6.3
277 *
278 * @return void
279 */
280 public function input_admin_enqueue_scripts() {
281 acf_localize_data(
282 array(
283 'iconPickerA11yStrings' => array(
284 'noResultsForSearchTerm' => esc_html__( 'No results found for that search term', 'acf' ),
285 'newResultsFoundForSearchTerm' => esc_html__( 'The available icons matching your search query have been updated in the icon picker below.', 'acf' ),
286 ),
287 'iconPickeri10n' => $this->get_dashicons(),
288 )
289 );
290 }
291
292 /**
293 * Validates the field value before it is saved into the database.
294 *
295 * @since 6.3
296 *
297 * @param integer $valid The current validation status.
298 * @param mixed $value The value of the field.
299 * @param array $field The field array holding all the field options.
300 * @param string $input The corresponding input name for $_POST value.
301 * @return boolean true If the value is valid, false if not.
302 */
303 public function validate_value( $valid, $value, $field, $input ) {
304 // If the value is empty, return true. You're allowed to save nothing.
305 if ( empty( $value ) && empty( $field['required'] ) ) {
306 return true;
307 }
308
309 // If the value is not an array, return $valid status.
310 if ( ! is_array( $value ) ) {
311 return $valid;
312 }
313
314 // If the value is an array, but the type is not set, fail validation.
315 if ( ! isset( $value['type'] ) ) {
316 return __( 'Icon picker requires an icon type.', 'acf' );
317 }
318
319 // If the value is an array, but the value is not set, fail validation.
320 if ( ! isset( $value['value'] ) ) {
321 return __( 'Icon picker requires a value.', 'acf' );
322 }
323
324 return true;
325 }
326
327 /**
328 * format_value()
329 *
330 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
331 *
332 * @since 6.3
333 *
334 * @param mixed $value The value which was loaded from the database.
335 * @param integer $post_id The $post_id from which the value was loaded.
336 * @param array $field The field array holding all the field options.
337 * @return mixed $value The modified value.
338 */
339 public function format_value( $value, $post_id, $field ) {
340 // Handle empty values.
341 if ( empty( $value ) ) {
342 // Return the default value if there is one.
343 if ( isset( $field['default_value'] ) ) {
344 return $field['default_value'];
345 } else {
346 // Otherwise return false.
347 return false;
348 }
349 }
350
351 // If media_library, behave the same as an image field.
352 if ( $value['type'] === 'media_library' ) {
353 // convert to int
354 $value['value'] = intval( $value['value'] );
355
356 // format
357 if ( $field['return_format'] === 'string' ) {
358 return wp_get_attachment_url( $value['value'] );
359 } elseif ( $field['return_format'] === 'array' ) {
360 $value['value'] = acf_get_attachment( $value['value'] );
361 return $value;
362 }
363 }
364
365 // If the desired return format is a string
366 if ( $field['return_format'] === 'string' ) {
367 return $value['value'];
368 }
369
370 // If nothing specific matched the return format, just return the value.
371 return $value;
372 }
373
374 /**
375 * get_dashicons()
376 *
377 * This function will return an array of dashicons.
378 *
379 * @since 6.3
380 *
381 * @return array $dashicons an array of dashicons.
382 */
383 public function get_dashicons() {
384 $dashicons = array(
385 'dashicons-admin-appearance' => esc_html__( 'Appearance Icon', 'acf' ),
386 'dashicons-admin-collapse' => esc_html__( 'Collapse Icon', 'acf' ),
387 'dashicons-admin-comments' => esc_html__( 'Comments Icon', 'acf' ),
388 'dashicons-admin-customizer' => esc_html__( 'Customizer Icon', 'acf' ),
389 'dashicons-admin-generic' => esc_html__( 'Generic Icon', 'acf' ),
390 'dashicons-admin-home' => esc_html__( 'Home Icon', 'acf' ),
391 'dashicons-admin-links' => esc_html__( 'Links Icon', 'acf' ),
392 'dashicons-admin-media' => esc_html__( 'Media Icon', 'acf' ),
393 'dashicons-admin-multisite' => esc_html__( 'Multisite Icon', 'acf' ),
394 'dashicons-admin-network' => esc_html__( 'Network Icon', 'acf' ),
395 'dashicons-admin-page' => esc_html__( 'Page Icon', 'acf' ),
396 'dashicons-admin-plugins' => esc_html__( 'Plugins Icon', 'acf' ),
397 'dashicons-admin-post' => esc_html__( 'Post Icon', 'acf' ),
398 'dashicons-admin-settings' => esc_html__( 'Settings Icon', 'acf' ),
399 'dashicons-admin-site' => esc_html__( 'Site Icon', 'acf' ),
400 'dashicons-admin-site-alt' => esc_html__( 'Site (alt) Icon', 'acf' ),
401 'dashicons-admin-site-alt2' => esc_html__( 'Site (alt2) Icon', 'acf' ),
402 'dashicons-admin-site-alt3' => esc_html__( 'Site (alt3) Icon', 'acf' ),
403 'dashicons-admin-tools' => esc_html__( 'Tools Icon', 'acf' ),
404 'dashicons-admin-users' => esc_html__( 'Users Icon', 'acf' ),
405 'dashicons-airplane' => esc_html__( 'Airplane Icon', 'acf' ),
406 'dashicons-album' => esc_html__( 'Album Icon', 'acf' ),
407 'dashicons-align-center' => esc_html__( 'Align Center Icon', 'acf' ),
408 'dashicons-align-full-width' => esc_html__( 'Align Full Width Icon', 'acf' ),
409 'dashicons-align-left' => esc_html__( 'Align Left Icon', 'acf' ),
410 'dashicons-align-none' => esc_html__( 'Align None Icon', 'acf' ),
411 'dashicons-align-pull-left' => esc_html__( 'Align Pull Left Icon', 'acf' ),
412 'dashicons-align-pull-right' => esc_html__( 'Align Pull Right Icon', 'acf' ),
413 'dashicons-align-right' => esc_html__( 'Align Right Icon', 'acf' ),
414 'dashicons-align-wide' => esc_html__( 'Align Wide Icon', 'acf' ),
415 'dashicons-amazon' => esc_html__( 'Amazon Icon', 'acf' ),
416 'dashicons-analytics' => esc_html__( 'Analytics Icon', 'acf' ),
417 'dashicons-archive' => esc_html__( 'Archive Icon', 'acf' ),
418 'dashicons-arrow-down' => esc_html__( 'Arrow Down Icon', 'acf' ),
419 'dashicons-arrow-down-alt' => esc_html__( 'Arrow Down (alt) Icon', 'acf' ),
420 'dashicons-arrow-down-alt2' => esc_html__( 'Arrow Down (alt2) Icon', 'acf' ),
421 'dashicons-arrow-left' => esc_html__( 'Arrow Left Icon', 'acf' ),
422 'dashicons-arrow-left-alt' => esc_html__( 'Arrow Left (alt) Icon', 'acf' ),
423 'dashicons-arrow-left-alt2' => esc_html__( 'Arrow Left (alt2) Icon', 'acf' ),
424 'dashicons-arrow-right' => esc_html__( 'Arrow Right Icon', 'acf' ),
425 'dashicons-arrow-right-alt' => esc_html__( 'Arrow Right (alt) Icon', 'acf' ),
426 'dashicons-arrow-right-alt2' => esc_html__( 'Arrow Right (alt2) Icon', 'acf' ),
427 'dashicons-arrow-up' => esc_html__( 'Arrow Up Icon', 'acf' ),
428 'dashicons-arrow-up-alt' => esc_html__( 'Arrow Up (alt) Icon', 'acf' ),
429 'dashicons-arrow-up-alt2' => esc_html__( 'Arrow Up (alt2) Icon', 'acf' ),
430 'dashicons-art' => esc_html__( 'Art Icon', 'acf' ),
431 'dashicons-awards' => esc_html__( 'Awards Icon', 'acf' ),
432 'dashicons-backup' => esc_html__( 'Backup Icon', 'acf' ),
433 'dashicons-bank' => esc_html__( 'Bank Icon', 'acf' ),
434 'dashicons-beer' => esc_html__( 'Beer Icon', 'acf' ),
435 'dashicons-bell' => esc_html__( 'Bell Icon', 'acf' ),
436 'dashicons-block-default' => esc_html__( 'Block Default Icon', 'acf' ),
437 'dashicons-book' => esc_html__( 'Book Icon', 'acf' ),
438 'dashicons-book-alt' => esc_html__( 'Book (alt) Icon', 'acf' ),
439 'dashicons-buddicons-activity' => esc_html__( 'Activity Icon', 'acf' ),
440 'dashicons-buddicons-bbpress-logo' => esc_html__( 'bbPress Icon', 'acf' ),
441 'dashicons-buddicons-buddypress-logo' => esc_html__( 'BuddyPress Icon', 'acf' ),
442 'dashicons-buddicons-community' => esc_html__( 'Community Icon', 'acf' ),
443 'dashicons-buddicons-forums' => esc_html__( 'Forums Icon', 'acf' ),
444 'dashicons-buddicons-friends' => esc_html__( 'Friends Icon', 'acf' ),
445 'dashicons-buddicons-groups' => esc_html__( 'Groups Icon', 'acf' ),
446 'dashicons-buddicons-pm' => esc_html__( 'PM Icon', 'acf' ),
447 'dashicons-buddicons-replies' => esc_html__( 'Replies Icon', 'acf' ),
448 'dashicons-buddicons-topics' => esc_html__( 'Topics Icon', 'acf' ),
449 'dashicons-buddicons-tracking' => esc_html__( 'Tracking Icon', 'acf' ),
450 'dashicons-building' => esc_html__( 'Building Icon', 'acf' ),
451 'dashicons-businessman' => esc_html__( 'Businessman Icon', 'acf' ),
452 'dashicons-businessperson' => esc_html__( 'Businessperson Icon', 'acf' ),
453 'dashicons-businesswoman' => esc_html__( 'Businesswoman Icon', 'acf' ),
454 'dashicons-button' => esc_html__( 'Button Icon', 'acf' ),
455 'dashicons-calculator' => esc_html__( 'Calculator Icon', 'acf' ),
456 'dashicons-calendar' => esc_html__( 'Calendar Icon', 'acf' ),
457 'dashicons-calendar-alt' => esc_html__( 'Calendar (alt) Icon', 'acf' ),
458 'dashicons-camera' => esc_html__( 'Camera Icon', 'acf' ),
459 'dashicons-camera-alt' => esc_html__( 'Camera (alt) Icon', 'acf' ),
460 'dashicons-car' => esc_html__( 'Car Icon', 'acf' ),
461 'dashicons-carrot' => esc_html__( 'Carrot Icon', 'acf' ),
462 'dashicons-cart' => esc_html__( 'Cart Icon', 'acf' ),
463 'dashicons-category' => esc_html__( 'Category Icon', 'acf' ),
464 'dashicons-chart-area' => esc_html__( 'Chart Area Icon', 'acf' ),
465 'dashicons-chart-bar' => esc_html__( 'Chart Bar Icon', 'acf' ),
466 'dashicons-chart-line' => esc_html__( 'Chart Line Icon', 'acf' ),
467 'dashicons-chart-pie' => esc_html__( 'Chart Pie Icon', 'acf' ),
468 'dashicons-clipboard' => esc_html__( 'Clipboard Icon', 'acf' ),
469 'dashicons-clock' => esc_html__( 'Clock Icon', 'acf' ),
470 'dashicons-cloud' => esc_html__( 'Cloud Icon', 'acf' ),
471 'dashicons-cloud-saved' => esc_html__( 'Cloud Saved Icon', 'acf' ),
472 'dashicons-cloud-upload' => esc_html__( 'Cloud Upload Icon', 'acf' ),
473 'dashicons-code-standards' => esc_html__( 'Code Standards Icon', 'acf' ),
474 'dashicons-coffee' => esc_html__( 'Coffee Icon', 'acf' ),
475 'dashicons-color-picker' => esc_html__( 'Color Picker Icon', 'acf' ),
476 'dashicons-columns' => esc_html__( 'Columns Icon', 'acf' ),
477 'dashicons-controls-back' => esc_html__( 'Back Icon', 'acf' ),
478 'dashicons-controls-forward' => esc_html__( 'Forward Icon', 'acf' ),
479 'dashicons-controls-pause' => esc_html__( 'Pause Icon', 'acf' ),
480 'dashicons-controls-play' => esc_html__( 'Play Icon', 'acf' ),
481 'dashicons-controls-repeat' => esc_html__( 'Repeat Icon', 'acf' ),
482 'dashicons-controls-skipback' => esc_html__( 'Skip Back Icon', 'acf' ),
483 'dashicons-controls-skipforward' => esc_html__( 'Skip Forward Icon', 'acf' ),
484 'dashicons-controls-volumeoff' => esc_html__( 'Volume Off Icon', 'acf' ),
485 'dashicons-controls-volumeon' => esc_html__( 'Volume On Icon', 'acf' ),
486 'dashicons-cover-image' => esc_html__( 'Cover Image Icon', 'acf' ),
487 'dashicons-dashboard' => esc_html__( 'Dashboard Icon', 'acf' ),
488 'dashicons-database' => esc_html__( 'Database Icon', 'acf' ),
489 'dashicons-database-add' => esc_html__( 'Database Add Icon', 'acf' ),
490 'dashicons-database-export' => esc_html__( 'Database Export Icon', 'acf' ),
491 'dashicons-database-import' => esc_html__( 'Database Import Icon', 'acf' ),
492 'dashicons-database-remove' => esc_html__( 'Database Remove Icon', 'acf' ),
493 'dashicons-database-view' => esc_html__( 'Database View Icon', 'acf' ),
494 'dashicons-desktop' => esc_html__( 'Desktop Icon', 'acf' ),
495 'dashicons-dismiss' => esc_html__( 'Dismiss Icon', 'acf' ),
496 'dashicons-download' => esc_html__( 'Download Icon', 'acf' ),
497 'dashicons-drumstick' => esc_html__( 'Drumstick Icon', 'acf' ),
498 'dashicons-edit' => esc_html__( 'Edit Icon', 'acf' ),
499 'dashicons-edit-large' => esc_html__( 'Edit Large Icon', 'acf' ),
500 'dashicons-edit-page' => esc_html__( 'Edit Page Icon', 'acf' ),
501 'dashicons-editor-aligncenter' => esc_html__( 'Align Center Icon', 'acf' ),
502 'dashicons-editor-alignleft' => esc_html__( 'Align Left Icon', 'acf' ),
503 'dashicons-editor-alignright' => esc_html__( 'Align Right Icon', 'acf' ),
504 'dashicons-editor-bold' => esc_html__( 'Bold Icon', 'acf' ),
505 'dashicons-editor-break' => esc_html__( 'Break Icon', 'acf' ),
506 'dashicons-editor-code' => esc_html__( 'Code Icon', 'acf' ),
507 'dashicons-editor-contract' => esc_html__( 'Contract Icon', 'acf' ),
508 'dashicons-editor-customchar' => esc_html__( 'Custom Character Icon', 'acf' ),
509 'dashicons-editor-expand' => esc_html__( 'Expand Icon', 'acf' ),
510 'dashicons-editor-help' => esc_html__( 'Help Icon', 'acf' ),
511 'dashicons-editor-indent' => esc_html__( 'Indent Icon', 'acf' ),
512 'dashicons-editor-insertmore' => esc_html__( 'Insert More Icon', 'acf' ),
513 'dashicons-editor-italic' => esc_html__( 'Italic Icon', 'acf' ),
514 'dashicons-editor-justify' => esc_html__( 'Justify Icon', 'acf' ),
515 'dashicons-editor-kitchensink' => esc_html__( 'Kitchen Sink Icon', 'acf' ),
516 'dashicons-editor-ltr' => esc_html__( 'LTR Icon', 'acf' ),
517 'dashicons-editor-ol' => esc_html__( 'Ordered List Icon', 'acf' ),
518 'dashicons-editor-ol-rtl' => esc_html__( 'Ordered List RTL Icon', 'acf' ),
519 'dashicons-editor-outdent' => esc_html__( 'Outdent Icon', 'acf' ),
520 'dashicons-editor-paragraph' => esc_html__( 'Paragraph Icon', 'acf' ),
521 'dashicons-editor-paste-text' => esc_html__( 'Paste Text Icon', 'acf' ),
522 'dashicons-editor-paste-word' => esc_html__( 'Paste Word Icon', 'acf' ),
523 'dashicons-editor-quote' => esc_html__( 'Quote Icon', 'acf' ),
524 'dashicons-editor-removeformatting' => esc_html__( 'Remove Formatting Icon', 'acf' ),
525 'dashicons-editor-rtl' => esc_html__( 'RTL Icon', 'acf' ),
526 'dashicons-editor-spellcheck' => esc_html__( 'Spellcheck Icon', 'acf' ),
527 'dashicons-editor-strikethrough' => esc_html__( 'Strikethrough Icon', 'acf' ),
528 'dashicons-editor-table' => esc_html__( 'Table Icon', 'acf' ),
529 'dashicons-editor-textcolor' => esc_html__( 'Text Color Icon', 'acf' ),
530 'dashicons-editor-ul' => esc_html__( 'Unordered List Icon', 'acf' ),
531 'dashicons-editor-underline' => esc_html__( 'Underline Icon', 'acf' ),
532 'dashicons-editor-unlink' => esc_html__( 'Unlink Icon', 'acf' ),
533 'dashicons-editor-video' => esc_html__( 'Video Icon', 'acf' ),
534 'dashicons-ellipsis' => esc_html__( 'Ellipsis Icon', 'acf' ),
535 'dashicons-email' => esc_html__( 'Email Icon', 'acf' ),
536 'dashicons-email-alt' => esc_html__( 'Email (alt) Icon', 'acf' ),
537 'dashicons-email-alt2' => esc_html__( 'Email (alt2) Icon', 'acf' ),
538 'dashicons-embed-audio' => esc_html__( 'Embed Audio Icon', 'acf' ),
539 'dashicons-embed-generic' => esc_html__( 'Embed Generic Icon', 'acf' ),
540 'dashicons-embed-photo' => esc_html__( 'Embed Photo Icon', 'acf' ),
541 'dashicons-embed-post' => esc_html__( 'Embed Post Icon', 'acf' ),
542 'dashicons-embed-video' => esc_html__( 'Embed Video Icon', 'acf' ),
543 'dashicons-excerpt-view' => esc_html__( 'Excerpt View Icon', 'acf' ),
544 'dashicons-exit' => esc_html__( 'Exit Icon', 'acf' ),
545 'dashicons-external' => esc_html__( 'External Icon', 'acf' ),
546 'dashicons-facebook' => esc_html__( 'Facebook Icon', 'acf' ),
547 'dashicons-facebook-alt' => esc_html__( 'Facebook (alt) Icon', 'acf' ),
548 'dashicons-feedback' => esc_html__( 'Feedback Icon', 'acf' ),
549 'dashicons-filter' => esc_html__( 'Filter Icon', 'acf' ),
550 'dashicons-flag' => esc_html__( 'Flag Icon', 'acf' ),
551 'dashicons-food' => esc_html__( 'Food Icon', 'acf' ),
552 'dashicons-format-aside' => esc_html__( 'Aside Icon', 'acf' ),
553 'dashicons-format-audio' => esc_html__( 'Audio Icon', 'acf' ),
554 'dashicons-format-chat' => esc_html__( 'Chat Icon', 'acf' ),
555 'dashicons-format-gallery' => esc_html__( 'Gallery Icon', 'acf' ),
556 'dashicons-format-image' => esc_html__( 'Image Icon', 'acf' ),
557 'dashicons-format-quote' => esc_html__( 'Quote Icon', 'acf' ),
558 'dashicons-format-status' => esc_html__( 'Status Icon', 'acf' ),
559 'dashicons-format-video' => esc_html__( 'Video Icon', 'acf' ),
560 'dashicons-forms' => esc_html__( 'Forms Icon', 'acf' ),
561 'dashicons-fullscreen-alt' => esc_html__( 'Fullscreen (alt) Icon', 'acf' ),
562 'dashicons-fullscreen-exit-alt' => esc_html__( 'Fullscreen Exit (alt) Icon', 'acf' ),
563 'dashicons-games' => esc_html__( 'Games Icon', 'acf' ),
564 'dashicons-google' => esc_html__( 'Google Icon', 'acf' ),
565 'dashicons-grid-view' => esc_html__( 'Grid View Icon', 'acf' ),
566 'dashicons-groups' => esc_html__( 'Groups Icon', 'acf' ),
567 'dashicons-hammer' => esc_html__( 'Hammer Icon', 'acf' ),
568 'dashicons-heading' => esc_html__( 'Heading Icon', 'acf' ),
569 'dashicons-heart' => esc_html__( 'Heart Icon', 'acf' ),
570 'dashicons-hidden' => esc_html__( 'Hidden Icon', 'acf' ),
571 'dashicons-hourglass' => esc_html__( 'Hourglass Icon', 'acf' ),
572 'dashicons-html' => esc_html__( 'HTML Icon', 'acf' ),
573 'dashicons-id' => esc_html__( 'ID Icon', 'acf' ),
574 'dashicons-id-alt' => esc_html__( 'ID (alt) Icon', 'acf' ),
575 'dashicons-image-crop' => esc_html__( 'Crop Icon', 'acf' ),
576 'dashicons-image-filter' => esc_html__( 'Filter Icon', 'acf' ),
577 'dashicons-image-flip-horizontal' => esc_html__( 'Flip Horizontal Icon', 'acf' ),
578 'dashicons-image-flip-vertical' => esc_html__( 'Flip Vertical Icon', 'acf' ),
579 'dashicons-image-rotate' => esc_html__( 'Rotate Icon', 'acf' ),
580 'dashicons-image-rotate-left' => esc_html__( 'Rotate Left Icon', 'acf' ),
581 'dashicons-image-rotate-right' => esc_html__( 'Rotate Right Icon', 'acf' ),
582 'dashicons-images-alt' => esc_html__( 'Images (alt) Icon', 'acf' ),
583 'dashicons-images-alt2' => esc_html__( 'Images (alt2) Icon', 'acf' ),
584 'dashicons-index-card' => esc_html__( 'Index Card Icon', 'acf' ),
585 'dashicons-info' => esc_html__( 'Info Icon', 'acf' ),
586 'dashicons-info-outline' => esc_html__( 'Info Outline Icon', 'acf' ),
587 'dashicons-insert' => esc_html__( 'Insert Icon', 'acf' ),
588 'dashicons-insert-after' => esc_html__( 'Insert After Icon', 'acf' ),
589 'dashicons-insert-before' => esc_html__( 'Insert Before Icon', 'acf' ),
590 'dashicons-instagram' => esc_html__( 'Instagram Icon', 'acf' ),
591 'dashicons-laptop' => esc_html__( 'Laptop Icon', 'acf' ),
592 'dashicons-layout' => esc_html__( 'Layout Icon', 'acf' ),
593 'dashicons-leftright' => esc_html__( 'Left Right Icon', 'acf' ),
594 'dashicons-lightbulb' => esc_html__( 'Lightbulb Icon', 'acf' ),
595 'dashicons-linkedin' => esc_html__( 'LinkedIn Icon', 'acf' ),
596 'dashicons-list-view' => esc_html__( 'List View Icon', 'acf' ),
597 'dashicons-location' => esc_html__( 'Location Icon', 'acf' ),
598 'dashicons-location-alt' => esc_html__( 'Location (alt) Icon', 'acf' ),
599 'dashicons-lock' => esc_html__( 'Lock Icon', 'acf' ),
600 'dashicons-marker' => esc_html__( 'Marker Icon', 'acf' ),
601 'dashicons-media-archive' => esc_html__( 'Archive Icon', 'acf' ),
602 'dashicons-media-audio' => esc_html__( 'Audio Icon', 'acf' ),
603 'dashicons-media-code' => esc_html__( 'Code Icon', 'acf' ),
604 'dashicons-media-default' => esc_html__( 'Default Icon', 'acf' ),
605 'dashicons-media-document' => esc_html__( 'Document Icon', 'acf' ),
606 'dashicons-media-interactive' => esc_html__( 'Interactive Icon', 'acf' ),
607 'dashicons-media-spreadsheet' => esc_html__( 'Spreadsheet Icon', 'acf' ),
608 'dashicons-media-text' => esc_html__( 'Text Icon', 'acf' ),
609 'dashicons-media-video' => esc_html__( 'Video Icon', 'acf' ),
610 'dashicons-megaphone' => esc_html__( 'Megaphone Icon', 'acf' ),
611 'dashicons-menu' => esc_html__( 'Menu Icon', 'acf' ),
612 'dashicons-menu-alt' => esc_html__( 'Menu (alt) Icon', 'acf' ),
613 'dashicons-menu-alt2' => esc_html__( 'Menu (alt2) Icon', 'acf' ),
614 'dashicons-menu-alt3' => esc_html__( 'Menu (alt3) Icon', 'acf' ),
615 'dashicons-microphone' => esc_html__( 'Microphone Icon', 'acf' ),
616 'dashicons-migrate' => esc_html__( 'Migrate Icon', 'acf' ),
617 'dashicons-minus' => esc_html__( 'Minus Icon', 'acf' ),
618 'dashicons-money' => esc_html__( 'Money Icon', 'acf' ),
619 'dashicons-money-alt' => esc_html__( 'Money (alt) Icon', 'acf' ),
620 'dashicons-move' => esc_html__( 'Move Icon', 'acf' ),
621 'dashicons-nametag' => esc_html__( 'Nametag Icon', 'acf' ),
622 'dashicons-networking' => esc_html__( 'Networking Icon', 'acf' ),
623 'dashicons-no' => esc_html__( 'No Icon', 'acf' ),
624 'dashicons-no-alt' => esc_html__( 'No (alt) Icon', 'acf' ),
625 'dashicons-open-folder' => esc_html__( 'Open Folder Icon', 'acf' ),
626 'dashicons-palmtree' => esc_html__( 'Palm Tree Icon', 'acf' ),
627 'dashicons-paperclip' => esc_html__( 'Paperclip Icon', 'acf' ),
628 'dashicons-pdf' => esc_html__( 'PDF Icon', 'acf' ),
629 'dashicons-performance' => esc_html__( 'Performance Icon', 'acf' ),
630 'dashicons-pets' => esc_html__( 'Pets Icon', 'acf' ),
631 'dashicons-phone' => esc_html__( 'Phone Icon', 'acf' ),
632 'dashicons-pinterest' => esc_html__( 'Pinterest Icon', 'acf' ),
633 'dashicons-playlist-audio' => esc_html__( 'Playlist Audio Icon', 'acf' ),
634 'dashicons-playlist-video' => esc_html__( 'Playlist Video Icon', 'acf' ),
635 'dashicons-plugins-checked' => esc_html__( 'Plugins Checked Icon', 'acf' ),
636 'dashicons-plus' => esc_html__( 'Plus Icon', 'acf' ),
637 'dashicons-plus-alt' => esc_html__( 'Plus (alt) Icon', 'acf' ),
638 'dashicons-plus-alt2' => esc_html__( 'Plus (alt2) Icon', 'acf' ),
639 'dashicons-podio' => esc_html__( 'Podio Icon', 'acf' ),
640 'dashicons-portfolio' => esc_html__( 'Portfolio Icon', 'acf' ),
641 'dashicons-post-status' => esc_html__( 'Post Status Icon', 'acf' ),
642 'dashicons-pressthis' => esc_html__( 'Pressthis Icon', 'acf' ),
643 'dashicons-printer' => esc_html__( 'Printer Icon', 'acf' ),
644 'dashicons-privacy' => esc_html__( 'Privacy Icon', 'acf' ),
645 'dashicons-products' => esc_html__( 'Products Icon', 'acf' ),
646 'dashicons-randomize' => esc_html__( 'Randomize Icon', 'acf' ),
647 'dashicons-reddit' => esc_html__( 'Reddit Icon', 'acf' ),
648 'dashicons-redo' => esc_html__( 'Redo Icon', 'acf' ),
649 'dashicons-remove' => esc_html__( 'Remove Icon', 'acf' ),
650 'dashicons-rest-api' => esc_html__( 'REST API Icon', 'acf' ),
651 'dashicons-rss' => esc_html__( 'RSS Icon', 'acf' ),
652 'dashicons-saved' => esc_html__( 'Saved Icon', 'acf' ),
653 'dashicons-schedule' => esc_html__( 'Schedule Icon', 'acf' ),
654 'dashicons-screenoptions' => esc_html__( 'Screen Options Icon', 'acf' ),
655 'dashicons-search' => esc_html__( 'Search Icon', 'acf' ),
656 'dashicons-share' => esc_html__( 'Share Icon', 'acf' ),
657 'dashicons-share-alt' => esc_html__( 'Share (alt) Icon', 'acf' ),
658 'dashicons-share-alt2' => esc_html__( 'Share (alt2) Icon', 'acf' ),
659 'dashicons-shield' => esc_html__( 'Shield Icon', 'acf' ),
660 'dashicons-shield-alt' => esc_html__( 'Shield (alt) Icon', 'acf' ),
661 'dashicons-shortcode' => esc_html__( 'Shortcode Icon', 'acf' ),
662 'dashicons-slides' => esc_html__( 'Slides Icon', 'acf' ),
663 'dashicons-smartphone' => esc_html__( 'Smartphone Icon', 'acf' ),
664 'dashicons-smiley' => esc_html__( 'Smiley Icon', 'acf' ),
665 'dashicons-sort' => esc_html__( 'Sort Icon', 'acf' ),
666 'dashicons-sos' => esc_html__( 'Sos Icon', 'acf' ),
667 'dashicons-spotify' => esc_html__( 'Spotify Icon', 'acf' ),
668 'dashicons-star-empty' => esc_html__( 'Star Empty Icon', 'acf' ),
669 'dashicons-star-filled' => esc_html__( 'Star Filled Icon', 'acf' ),
670 'dashicons-star-half' => esc_html__( 'Star Half Icon', 'acf' ),
671 'dashicons-sticky' => esc_html__( 'Sticky Icon', 'acf' ),
672 'dashicons-store' => esc_html__( 'Store Icon', 'acf' ),
673 'dashicons-superhero' => esc_html__( 'Superhero Icon', 'acf' ),
674 'dashicons-superhero-alt' => esc_html__( 'Superhero (alt) Icon', 'acf' ),
675 'dashicons-table-col-after' => esc_html__( 'Table Col After Icon', 'acf' ),
676 'dashicons-table-col-before' => esc_html__( 'Table Col Before Icon', 'acf' ),
677 'dashicons-table-col-delete' => esc_html__( 'Table Col Delete Icon', 'acf' ),
678 'dashicons-table-row-after' => esc_html__( 'Table Row After Icon', 'acf' ),
679 'dashicons-table-row-before' => esc_html__( 'Table Row Before Icon', 'acf' ),
680 'dashicons-table-row-delete' => esc_html__( 'Table Row Delete Icon', 'acf' ),
681 'dashicons-tablet' => esc_html__( 'Tablet Icon', 'acf' ),
682 'dashicons-tag' => esc_html__( 'Tag Icon', 'acf' ),
683 'dashicons-tagcloud' => esc_html__( 'Tagcloud Icon', 'acf' ),
684 'dashicons-testimonial' => esc_html__( 'Testimonial Icon', 'acf' ),
685 'dashicons-text' => esc_html__( 'Text Icon', 'acf' ),
686 'dashicons-text-page' => esc_html__( 'Text Page Icon', 'acf' ),
687 'dashicons-thumbs-down' => esc_html__( 'Thumbs Down Icon', 'acf' ),
688 'dashicons-thumbs-up' => esc_html__( 'Thumbs Up Icon', 'acf' ),
689 'dashicons-tickets' => esc_html__( 'Tickets Icon', 'acf' ),
690 'dashicons-tickets-alt' => esc_html__( 'Tickets (alt) Icon', 'acf' ),
691 'dashicons-tide' => esc_html__( 'Tide Icon', 'acf' ),
692 'dashicons-translation' => esc_html__( 'Translation Icon', 'acf' ),
693 'dashicons-trash' => esc_html__( 'Trash Icon', 'acf' ),
694 'dashicons-twitch' => esc_html__( 'Twitch Icon', 'acf' ),
695 'dashicons-twitter' => esc_html__( 'Twitter Icon', 'acf' ),
696 'dashicons-twitter-alt' => esc_html__( 'Twitter (alt) Icon', 'acf' ),
697 'dashicons-undo' => esc_html__( 'Undo Icon', 'acf' ),
698 'dashicons-universal-access' => esc_html__( 'Universal Access Icon', 'acf' ),
699 'dashicons-universal-access-alt' => esc_html__( 'Universal Access (alt) Icon', 'acf' ),
700 'dashicons-unlock' => esc_html__( 'Unlock Icon', 'acf' ),
701 'dashicons-update' => esc_html__( 'Update Icon', 'acf' ),
702 'dashicons-update-alt' => esc_html__( 'Update (alt) Icon', 'acf' ),
703 'dashicons-upload' => esc_html__( 'Upload Icon', 'acf' ),
704 'dashicons-vault' => esc_html__( 'Vault Icon', 'acf' ),
705 'dashicons-video-alt' => esc_html__( 'Video (alt) Icon', 'acf' ),
706 'dashicons-video-alt2' => esc_html__( 'Video (alt2) Icon', 'acf' ),
707 'dashicons-video-alt3' => esc_html__( 'Video (alt3) Icon', 'acf' ),
708 'dashicons-visibility' => esc_html__( 'Visibility Icon', 'acf' ),
709 'dashicons-warning' => esc_html__( 'Warning Icon', 'acf' ),
710 'dashicons-welcome-add-page' => esc_html__( 'Add Page Icon', 'acf' ),
711 'dashicons-welcome-comments' => esc_html__( 'Comments Icon', 'acf' ),
712 'dashicons-welcome-learn-more' => esc_html__( 'Learn More Icon', 'acf' ),
713 'dashicons-welcome-view-site' => esc_html__( 'View Site Icon', 'acf' ),
714 'dashicons-welcome-widgets-menus' => esc_html__( 'Widgets Menus Icon', 'acf' ),
715 'dashicons-welcome-write-blog' => esc_html__( 'Write Blog Icon', 'acf' ),
716 'dashicons-whatsapp' => esc_html__( 'WhatsApp Icon', 'acf' ),
717 'dashicons-wordpress' => esc_html__( 'WordPress Icon', 'acf' ),
718 'dashicons-wordpress-alt' => esc_html__( 'WordPress (alt) Icon', 'acf' ),
719 'dashicons-xing' => esc_html__( 'Xing Icon', 'acf' ),
720 'dashicons-yes' => esc_html__( 'Yes Icon', 'acf' ),
721 'dashicons-yes-alt' => esc_html__( 'Yes (alt) Icon', 'acf' ),
722 'dashicons-youtube' => esc_html__( 'YouTube Icon', 'acf' ),
723 );
724
725 return apply_filters( 'acf/fields/icon_picker/dashicons', $dashicons );
726 }
727
728 /**
729 * Returns the schema used by the REST API.
730 *
731 * @since 6.3
732 *
733 * @param array $field The main field array.
734 * @return array
735 */
736 public function get_rest_schema( array $field ): array {
737 return array(
738 'type' => array( 'object', 'null' ),
739 'required' => ! empty( $field['required'] ),
740 'properties' => array(
741 'type' => array(
742 'description' => esc_html__( 'The type of icon to save.', 'acf' ),
743 'type' => array( 'string' ),
744 'required' => true,
745 'enum' => array_keys( $this->get_tabs() ),
746 ),
747 'value' => array(
748 'description' => esc_html__( 'The value of icon to save.', 'acf' ),
749 'type' => array( 'string', 'int' ),
750 'required' => true,
751 ),
752 ),
753 );
754 }
755
756 /**
757 * Validates a value sent via the REST API.
758 *
759 * @since 6.3
760 *
761 * @param boolean $valid The current validity boolean.
762 * @param array|null $value The value of the field.
763 * @param array $field The main field array.
764 * @return boolean|WP_Error
765 */
766 public function validate_rest_value( $valid, $value, $field ) {
767 if ( is_null( $value ) ) {
768 if ( ! empty( $field['required'] ) ) {
769 return new WP_Error(
770 'rest_property_required',
771 /* translators: %s - field name */
772 sprintf( __( '%s is a required property of acf.', 'acf' ), $field['name'] )
773 );
774 } else {
775 return $valid;
776 }
777 }
778
779 if ( ! empty( $value['type'] ) && 'media_library' === $value['type'] ) {
780 $param = sprintf( '%s[%s][value]', $field['prefix'], $field['name'] );
781 $data = array(
782 'param' => $param,
783 'value' => (int) $value['value'],
784 );
785
786 if ( ! is_int( $value['value'] ) || 'attachment' !== get_post_type( $value['value'] ) ) {
787 /* translators: %s - field/param name */
788 $error = sprintf( __( '%s requires a valid attachment ID when type is set to media_library.', 'acf' ), $param );
789 return new WP_Error( 'rest_invalid_param', $error, $data );
790 }
791 }
792
793 return $valid;
794 }
795 }
796
797 acf_register_field_type( 'acf_field_icon_picker' );
798 endif;
799