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 / registry.php
menu-icons / vendor / codeinwp / icon-picker / includes Last commit date
fields 7 years ago types 2 years ago fontpack.php 7 years ago loader.php 7 years ago registry.php 7 years ago
registry.php
179 lines
1 <?php
2 /**
3 * Icon types registry
4 *
5 * @package Icon_Picker
6 * @author Dzikri Aziz <kvcrvt@gmail.com>
7 */
8
9 final class Icon_Picker_Types_Registry {
10
11 /**
12 * Icon_Picker_Types_Registry singleton
13 *
14 * @static
15 * @since 0.1.0
16 * @access protected
17 * @var Icon_Picker_Types_Registry
18 */
19 protected static $instance;
20
21 /**
22 * Base icon type class name
23 *
24 * @access protected
25 * @since 0.1.0
26 * @var string
27 */
28 protected $base_class = 'Icon_Picker_Type';
29
30 /**
31 * All types
32 *
33 * @access protected
34 * @since 0.1.0
35 * @var array
36 */
37 protected $types = array();
38
39
40 /**
41 * Get instance
42 *
43 * @static
44 * @since 0.1.0
45 * @param array $args Arguments.
46 *
47 * @return Icon_Picker_Types_Registry
48 */
49 public static function instance( $args = array() ) {
50 if ( is_null( self::$instance ) ) {
51 self::$instance = new self( $args );
52 }
53
54 return self::$instance;
55 }
56
57
58 /**
59 * Getter magic
60 *
61 * @since 0.1.0
62 * @param string $name Property name.
63 * @return mixed NULL if attribute doesn't exist.
64 */
65 public function __get( $name ) {
66 if ( isset( $this->$name ) ) {
67 return $this->$name;
68 }
69
70 return null;
71 }
72
73
74 /**
75 * Setter magic
76 *
77 * @since 0.1.0
78 * @return bool
79 */
80 public function __isset( $name ) {
81 return isset( $this->$name );
82 }
83
84
85 /**
86 * Constructor
87 *
88 * @since 0.1.0
89 * @access protected
90 * @return Icon_Picker_Types_Registry
91 */
92 protected function __construct() {
93 /**
94 * Fires when Icon Picker types registry is ready
95 *
96 * @since 0.1.0
97 * @param Icon_Picker_Types_Registry $this Icon_Picker_Types_Registry instance.
98 */
99 do_action( 'icon_picker_types_registry_init', $this );
100 }
101
102
103 /**
104 * Register icon type
105 *
106 * @since 0.1.0
107 * @param Icon_Picker_Type $type Icon type.
108 * @return void
109 */
110 public function add( Icon_Picker_Type $type ) {
111 if ( $this->is_valid_type( $type ) ) {
112 $this->types[ $type->id ] = $type;
113 }
114 }
115
116
117 /**
118 * Get icon type
119 *
120 * @since 0.1.0
121 * @param string $id Icon type ID.
122 * @return mixed Icon type or NULL if it's not registered.
123 */
124 public function get( $id ) {
125 if ( isset( $this->types[ $id ] ) ) {
126 return $this->types[ $id ];
127 }
128
129 return null;
130 }
131
132
133 /**
134 * Check if icon type is valid
135 *
136 * @since 0.1.0
137 * @param Icon_Picker_Type $type Icon type.
138 * @return bool
139 */
140 protected function is_valid_type( Icon_Picker_Type $type ) {
141 foreach ( array( 'id', 'controller' ) as $var ) {
142 $value = $type->$var;
143
144 if ( empty( $value ) ) {
145 trigger_error( esc_html( sprintf( 'Icon Picker: "%s" cannot be empty.', $var ) ) );
146 return false;
147 }
148 }
149
150 if ( isset( $this->types[ $type->id ] ) ) {
151 trigger_error( esc_html( sprintf( 'Icon Picker: Icon type %s is already registered. Please use a different ID.', $type->id ) ) );
152 return false;
153 }
154
155 return true;
156 }
157
158
159 /**
160 * Get all icon types for JS
161 *
162 * @since 0.1.0
163 * @return array
164 */
165 public function get_types_for_js() {
166 $types = array();
167 $names = array();
168
169 foreach ( $this->types as $type ) {
170 $types[ $type->id ] = $type->get_props();
171 $names[ $type->id ] = $type->name;
172 }
173
174 array_multisort( $names, SORT_ASC, $types );
175
176 return $types;
177 }
178 }
179