24
24
* diversa da $label
25
25
* - $capability => per specificare quale capability deve
26
26
* possedere l'utente per visualizzare la voce del menu
27
+ * - $icon => icona del menu, di default l'ingranaggio; i valori
28
+ * accettati sono gli stessi di $icon_url
27
29
*
28
30
* Ricordati di caricare la classe nel bootstrap del tuo plugin.
29
31
*/
@@ -77,10 +79,27 @@ class MenuPage
77
79
protected $ capability = 'manage_options ' ;
78
80
79
81
/**
80
- * Priorità della voce di menu nel filtro WordPress admin_menu
82
+ * Priorità della voce di menu nel filtro WordPress admin_menu.
83
+ *
84
+ * IMPORTANTE: Per i sottomenu, va impostato un valore superiore a
85
+ * quello del menu parent, altrimenti il sottomenu darà un 404.
81
86
*/
82
87
protected $ filterPriority = 10 ;
83
88
89
+ /**
90
+ * Icona da usare per la voce di menu; va usato solo per i menu parent,
91
+ * di default è l'icona dell'ingranaggio.
92
+ *
93
+ * Puoi passare una URL oppure uno di questi tre:
94
+ * - Pass a base64-encoded SVG using a data URI, which will be colored to
95
+ * match the color scheme. This should begin with 'data:image/svg+xml;base64,'.
96
+ * - Pass the name of a Dashicons helper class to use a font icon,
97
+ * e.g. 'dashicons-chart-pie'.
98
+ * - Pass 'none' to leave div.wp-menu-image empty so an icon can be
99
+ * added via CSS.
100
+ */
101
+ protected $ icon = '' ;
102
+
84
103
/**
85
104
* Specifica qui i plugin che devono essere presenti affinché
86
105
* la voce di menu venga mostrata; usa lo stesso formato
@@ -106,6 +125,7 @@ public function __construct( array $attributes = [] )
106
125
$ this ->parentSlug = $ attributes ['parentSlug ' ] ?? $ this ->parentSlug ;
107
126
$ this ->menuLabel = $ attributes ['menuLabel ' ] ?? $ this ->menuLabel ;
108
127
$ this ->capability = $ attributes ['capability ' ] ?? $ this ->capability ;
128
+ $ this ->icon = $ attributes ['icon ' ] ?? $ this ->icon ;
109
129
$ this ->filterPriority = $ attributes ['filterPriority ' ] ?? $ this ->filterPriority ;
110
130
$ this ->requiredPlugins = $ attributes ['requiredPlugins ' ] ?? $ this ->requiredPlugins ;
111
131
@@ -140,13 +160,13 @@ public function admin_menu()
140
160
// Caso in cui l'etichetta del menu madre è diversa da quella
141
161
// della sottovoce di menu (https://wordpress.stackexchange.com/a/66499/86662)
142
162
if ( ! empty ( $ this ->menuLabel ) ) {
143
- add_menu_page ( $ this ->menuLabel , $ this ->menuLabel , $ this ->capability , $ this ->slug , '__return_true ' , '' , $ this ->position );
163
+ add_menu_page ( $ this ->menuLabel , $ this ->menuLabel , $ this ->capability , $ this ->slug , '__return_true ' , $ this -> icon , $ this ->position );
144
164
add_submenu_page ( $ this ->slug , $ this ->label , $ this ->label , $ this ->capability , $ this ->slug , [ $ this , 'view ' ] );
145
165
}
146
166
// Caso in cui non ci interessa differenziare, ad es. perché non ci sono
147
167
// altre pagine di menu nel menu madre
148
168
else {
149
- add_menu_page ( $ this ->label , $ this ->label , $ this ->capability , $ this ->slug , [ $ this , 'view ' ], '' , $ this ->position );
169
+ add_menu_page ( $ this ->label , $ this ->label , $ this ->capability , $ this ->slug , [ $ this , 'view ' ], $ this -> icon , $ this ->position );
150
170
}
151
171
}
152
172
}
0 commit comments