PluginProbe ʕ •ᴥ•ʔ
Menu Icons by Themeisle – Add Icons to Navigation Menus / 0.13.24
Menu Icons by Themeisle – Add Icons to Navigation Menus v0.13.24
0.13.24 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 / vendor / codeinwp / icon-picker / includes / fields / base.php
menu-icons / vendor / codeinwp / icon-picker / includes / fields Last commit date
base.php 7 years ago cmb.php 7 years ago
base.php
105 lines
1 <?php
2
3 if ( ! function_exists( 'wp_get_attachment_image_url' ) ) {
4 /**
5 * Get the URL of an image attachment.
6 *
7 * @since WordPress 4.4.0
8 *
9 * @param int $attachment_id Image attachment ID.
10 * @param string|array $size Optional. Image size to retrieve. Accepts any valid image size, or an array
11 * of width and height values in pixels (in that order). Default 'thumbnail'.
12 * @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
13 * @return string|false Attachment URL or false if no image is available.
14 */
15 function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
16 $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
17 return isset( $image['0'] ) ? $image['0'] : false;
18 }
19 }
20
21
22 /**
23 * Get Icon URL
24 *
25 * @since 0.2.0
26 *
27 * @param string $type Icon type.
28 * @param mixed $id Icon ID.
29 * @param string $size Optional. Icon size, defaults to 'thumbnail'.
30 *
31 * @return string
32 */
33 function icon_picker_get_icon_url( $type, $id, $size = 'thumbnail' ) {
34 $url = '';
35
36 if ( ! in_array( $type, array( 'image', 'svg' ), true ) ) {
37 return $url;
38 }
39
40 if ( empty( $id ) ) {
41 return $url;
42 }
43
44 return wp_get_attachment_image_url( $id, $size, false );
45 }
46
47
48 /**
49 * The Icon Picker Field
50 *
51 * @since 0.2.0
52 *
53 * @param mixed $args {
54 * }
55 * @param bool $echo Whether to return the field or print it. Defaults to TRUE.
56 *
57 * @return mixed
58 */
59 function icon_picker_field( $args, $echo = true ) {
60 $defaults = array(
61 'id' => '',
62 'name' => '',
63 'value' => array(
64 'type' => '',
65 'icon' => '',
66 ),
67 'select' => sprintf( '<a class="ipf-select">%s</a>', esc_html__( 'Select Icon', 'icon-picker-field' ) ),
68 'remove' => sprintf( '<a class="ipf-remove button hidden">%s</a>', esc_html__( 'Remove', 'icon-picker-field' ) ),
69 );
70
71 $args = wp_parse_args( $args, $defaults );
72 $args['value'] = wp_parse_args( $args['value'], $defaults['value'] );
73
74 $field = sprintf( '<div id="%s" class="ipf">', $args['id'] );
75 $field .= $args['select'];
76 $field .= $args['remove'];
77
78 foreach ( $args['value'] as $key => $value ) {
79 $field .= sprintf(
80 '<input type="hidden" id="%s" name="%s" class="%s" value="%s" />',
81 esc_attr( "{$args['id']}-{$key}" ),
82 esc_attr( "{$args['name']}[{$key}]" ),
83 esc_attr( "ipf-{$key}" ),
84 esc_attr( $value )
85 );
86 }
87
88 // This won't be saved. It's here for the preview.
89 $field .= sprintf(
90 '<input type="hidden" class="url" value="%s" />',
91 esc_attr( icon_picker_get_icon_url( $args['value']['type'], $args['value']['icon'] ) )
92 );
93 $field .= '</div>';
94
95 if ( $echo ) {
96 echo $field; // xss ok
97 } else {
98 return $field;
99 }
100 }
101
102
103 // Add-ons for other plugins.
104
105