11<?php
2+
23/**
34 * Plugin Name: CC Admin Popover Row Actions
45 * Plugin URI: https://github.com/CodeCornTech/mu-cc-admin-popover-row-actions
56 * Description: Converte le row-actions della WP List Table in un popover apribile dal badge ID , con flag bilaterali ( define + filter ) e asset singleton .
6- * Version: 1.0.2
7+ * Version: 1.0.3
78 * Author: CodeCorn™
89 * Author URI: https://github.com/CodeCornTech
910 * License: MIT
1011 * Text Domain: cc-admin-popover-row-actions
1112 *
1213 * @package CodeCorn\CC_Admin_Popover_Row_Actions
1314 */
14- defined ( 'ABSPATH ' ) || exit;
15+ defined ('ABSPATH ' ) || exit;
1516
16- /**
17- * Definisce una costante solo se non già definita .
18- *
19- * @param string $k Nome della costante .
20- * @param mixed $v Valore della costante ( qualsiasi tipo accettato da define ) .
21- * @return bool true se definita ora , false se già esiste o se define fallisce .
22- */
23- if ( ! function_exists ( 'cc_def ' ) ) {
24- function cc_def ( $ k , $ v ) {
25- return ! defined ( $ k ) && define ( $ k , $ v );
17+ if (! function_exists ('cc_def ' )) {
18+ /**
19+ * Definisce una costante solo se non già definita .
20+ *
21+ * @param string $k Nome della costante .
22+ * @param mixed $v Valore della costante ( qualsiasi tipo accettato da define ) .
23+ * @return bool true se definita ora , false se già esiste o se define fallisce .
24+ */
25+ function cc_def (string $ k , $ v )
26+ {
27+ return ! defined ($ k ) && define ($ k , $ v );
2628 }
2729}
2830
2931/** @var non-empty-string $plugin_vers */
30- $ plugin_vers = '1.0.2 ' ;
32+ $ plugin_vers = '1.0.3 ' ;
3133/** @var non-empty-string $plugin_dir Percorso assoluto directory del plugin */
3234$ plugin_dir = __DIR__ ;
3335/** @var non-empty-string $assets_path Path relativo degli assets dentro il plugin */
3436$ assets_path = 'codecorn/admin-popover-row-actions/assets ' ;
3537/** @var non-empty-string $assets_dir Percorso assoluto assets */
3638$ assets_dir = "{$ plugin_dir }/ {$ assets_path }" ;
3739/** @var non-empty-string $assets_url URL assoluto assets */
38- $ assets_url = plugins_url ( $ assets_path , __FILE__ );
40+ $ assets_url = plugins_url ($ assets_path , __FILE__ );
3941
40- cc_def ( 'CC_APRA_VERS ' , $ plugin_vers );
41- cc_def ( 'CC_APRA_SLUG ' , 'cc-admin-popover-row-actions ' );
42- cc_def ( 'CC_APRA_NS ' , 'cc_apra ' );
43- cc_def ( 'CC_APRA_DIR ' , $ plugin_dir );
44- cc_def ( 'CC_APRA_ASSETS_DIR ' , $ assets_dir );
45- cc_def ( 'CC_APRA_ASSETS_URL ' , $ assets_url );
46- cc_def ( 'CC_APRA_DEFAULT_POST_TYPES ' , array ( 'wp_ar_clients ' , 'wp_ar_requests ' ) ); // array OK su PHP 7+.
42+ cc_def ('CC_APRA_VERS ' , $ plugin_vers );
43+ cc_def ('CC_APRA_SLUG ' , 'cc-admin-popover-row-actions ' );
44+ cc_def ('CC_APRA_NS ' , 'cc_apra ' );
45+ cc_def ('CC_APRA_DIR ' , $ plugin_dir );
46+ cc_def ('CC_APRA_ASSETS_DIR ' , $ assets_dir );
47+ cc_def ('CC_APRA_ASSETS_URL ' , $ assets_url );
48+ cc_def ('CC_APRA_DEFAULT_POST_TYPES ' , array ('wp_ar_clients ' , 'wp_ar_requests ' ) ); // array OK su PHP 7+.
4749
4850/**
4951 * ===== Bilateral flags ( defaults da define , i filtri vincono ) =====
@@ -85,18 +87,19 @@ function cc_def( $k, $v ) {
8587 * @param string|array<string|int|float>|null $csv Stringa CSV o array già fornito .
8688 * @return array<int,string> Lista normalizzata .
8789 */
88- function cc_apra_csv_list ( $ csv ): array {
89- if ( is_array ( $ csv ) ) {
90- return array_values ( array_filter ( array_map ( 'strval ' , $ csv ) ) );
90+ function cc_apra_csv_list ($ csv ): array
91+ {
92+ if (is_array ($ csv )) {
93+ return array_values (array_filter (array_map ('strval ' , $ csv )));
9194 }
9295 $ csv = (string ) $ csv ;
93- if ( $ csv === '' ) {
96+ if ($ csv === '' ) {
9497 return array ();
9598 }
9699 return array_values (
97100 array_unique (
98101 array_filter (
99- array_map ( 'trim ' , explode ( ', ' , $ csv ) )
102+ array_map ('trim ' , explode (', ' , $ csv) )
100103 )
101104 )
102105 );
@@ -108,7 +111,8 @@ function cc_apra_csv_list( $csv ): array {
108111 * @param array<string,string>|string|null $val Array associativo o JSON string .
109112 * @return array{ table:string , primaryCell:string , triggerLink:string , rowActions:string }
110113 */
111- function cc_apra_norm_selectors ( $ val ): array {
114+ function cc_apra_norm_selectors ($ val ): array
115+ {
112116 $ defaults = array (
113117 'table ' => '.wp-list-table.table-view-list ' ,
114118 'primaryCell ' => 'td.column-primary ' ,
@@ -117,18 +121,18 @@ function cc_apra_norm_selectors( $val ): array {
117121 );
118122
119123 // Supporto define come JSON string .
120- if ( is_string ( $ val ) ) {
121- $ dec = json_decode ( $ val , true );
122- if ( is_array ( $ dec ) ) {
124+ if (is_string ($ val) ) {
125+ $ dec = json_decode ($ val , true );
126+ if (is_array ($ dec) ) {
123127 $ val = $ dec ;
124128 }
125129 }
126130
127- if ( ! is_array ( $ val ) ) {
131+ if (! is_array ($ val) ) {
128132 $ val = array ();
129133 }
130134
131- $ val = array_intersect_key ( $ val , $ defaults );
135+ $ val = array_intersect_key ($ val , $ defaults );
132136
133137 /** @var array{ table:string , primaryCell:string , triggerLink:string , rowActions:string } */
134138 $ out = $ val + $ defaults ;
@@ -147,35 +151,36 @@ function cc_apra_norm_selectors( $val ): array {
147151 * ($name is 'post_types' ? array<int,string> : mixed)
148152 * )
149153 */
150- function cc_apra_get_flag ( $ name , $ default ) {
154+ function cc_apra_get_flag ($ name , $ default )
155+ {
151156 // leggi eventuale define
152157 $ defined = null ;
153- switch ( $ name ) {
158+ switch ($ name ) {
154159 case 'enabled ' :
155- $ defined = defined ( 'CC_APRA_ENABLED ' ) ? (bool ) CC_APRA_ENABLED : null ;
160+ $ defined = defined ('CC_APRA_ENABLED ' ) ? (bool ) CC_APRA_ENABLED : null ;
156161 break ;
157162
158163 case 'on_hover ' :
159- $ defined = defined ( 'CC_APRA_ON_HOVER ' ) ? (bool ) CC_APRA_ON_HOVER : null ;
164+ $ defined = defined ('CC_APRA_ON_HOVER ' ) ? (bool ) CC_APRA_ON_HOVER : null ;
160165 break ;
161166
162167 case 'hide_quick_edit ' :
163- $ defined = defined ( 'CC_APRA_HIDE_QUICK_EDIT ' ) ? (bool ) CC_APRA_HIDE_QUICK_EDIT : null ;
168+ $ defined = defined ('CC_APRA_HIDE_QUICK_EDIT ' ) ? (bool ) CC_APRA_HIDE_QUICK_EDIT : null ;
164169 break ;
165170
166171 case 'post_types ' :
167172 // priorità ai define specifici , altrimenti default globale
168- if ( defined ( 'CC_APRA_POST_TYPES ' ) ) {
169- $ defined = cc_apra_csv_list ( CC_APRA_POST_TYPES );
170- } elseif ( defined ( 'CC_APRA_DEFAULT_POST_TYPES ' ) ) {
171- $ defined = (array ) constant ( 'CC_APRA_DEFAULT_POST_TYPES ' );
173+ if (defined ('CC_APRA_POST_TYPES ' ) ) {
174+ $ defined = cc_apra_csv_list (CC_APRA_POST_TYPES );
175+ } elseif (defined ('CC_APRA_DEFAULT_POST_TYPES ' ) ) {
176+ $ defined = (array ) constant ('CC_APRA_DEFAULT_POST_TYPES ' );
172177 }
173178 break ;
174179
175180 case 'selectors ' :
176- if ( defined ( 'CC_APRA_SELECTORS ' ) ) {
181+ if (defined ('CC_APRA_SELECTORS ' ) ) {
177182 // accetta array o JSON string nel define
178- $ defined = cc_apra_norm_selectors ( constant ( 'CC_APRA_SELECTORS ' ) );
183+ $ defined = cc_apra_norm_selectors (constant ('CC_APRA_SELECTORS ' ) );
179184 }
180185 break ;
181186 }
@@ -192,8 +197,8 @@ function cc_apra_get_flag( $name, $default ) {
192197 'selectors ' => 'cc_apra_selectors ' ,
193198 );
194199
195- $ tag = $ filter_map [ $ name ] ?? null ;
196- if ( $ tag ) {
200+ $ tag = $ filter_map [$ name ] ?? null ;
201+ if ($ tag ) {
197202 /**
198203 * Filtri di configurazione .
199204 * passa anche $screen per i filtri più evoluti sui selectors
@@ -208,15 +213,15 @@ function cc_apra_get_flag( $name, $default ) {
208213 * @param WP_Screen $screen Oggetto schermo corrente , utile per personalizzazioni contestuali .
209214 * @return mixed
210215 */
211- $ screen = function_exists ( 'get_current_screen ' ) ? get_current_screen () : null ;
212- $ base = apply_filters ( $ tag , $ base , $ screen );
216+ $ screen = function_exists ('get_current_screen ' ) ? get_current_screen () : null ;
217+ $ base = apply_filters ($ tag , $ base , $ screen );
213218 }
214219
215220 // Normalizzazioni finali per sicurezza
216- if ( $ name === 'post_types ' ) {
217- $ base = cc_apra_csv_list ( $ base ?: ( defined ( 'CC_APRA_DEFAULT_POST_TYPES ' ) ? constant ( 'CC_APRA_DEFAULT_POST_TYPES ' ) : array () ) );
218- } elseif ( $ name === 'selectors ' ) {
219- $ base = cc_apra_norm_selectors ( $ base );
221+ if ($ name === 'post_types ' ) {
222+ $ base = cc_apra_csv_list ($ base ?: (defined ('CC_APRA_DEFAULT_POST_TYPES ' ) ? constant ('CC_APRA_DEFAULT_POST_TYPES ' ) : array ()) );
223+ } elseif ($ name === 'selectors ' ) {
224+ $ base = cc_apra_norm_selectors ($ base );
220225 }
221226
222227 return $ base ;
@@ -232,19 +237,19 @@ function cc_apra_get_flag( $name, $default ) {
232237 */
233238add_action (
234239 'current_screen ' ,
235- function ( $ screen ) {
236- if ( ! $ screen || $ screen ->base !== 'edit ' ) {
240+ function ($ screen ) {
241+ if (! $ screen || $ screen ->base !== 'edit ' ) {
237242 return ;
238243 }
239244
240- $ enabled = cc_apra_get_flag ( 'enabled ' , true );
241- $ post_types = cc_apra_get_flag ( 'post_types ' , constant ( 'CC_APRA_DEFAULT_POST_TYPES ' ) ); // default CPT tuo
245+ $ enabled = cc_apra_get_flag ('enabled ' , true );
246+ $ post_types = cc_apra_get_flag ('post_types ' , constant ('CC_APRA_DEFAULT_POST_TYPES ' ) ); // default CPT tuo
242247
243- if ( ! $ enabled || ! in_array ( $ screen ->post_type , (array ) $ post_types , true ) ) {
248+ if (! $ enabled || ! in_array ($ screen ->post_type , (array ) $ post_types , true ) ) {
244249 return ;
245250 }
246251
247- add_action ( 'admin_enqueue_scripts ' , 'cc_apra_enqueue_assets ' , 20 );
252+ add_action ('admin_enqueue_scripts ' , 'cc_apra_enqueue_assets ' , 20 );
248253 }
249254);
250255
@@ -256,24 +261,25 @@ function ( $screen ) {
256261 * @param string $hook Hook corrente di enqueue ( non usato ) .
257262 * @return void
258263 */
259- function cc_apra_enqueue_assets ( $ hook ) {
264+ function cc_apra_enqueue_assets ($ hook )
265+ {
260266 static $ done = false ;
261- if ( $ done ) {
267+ if ($ done ) {
262268 return ;
263269 }
264270 $ done = true ;
265271
266272 // Flags risolte ( filter > define ).
267273 /** @var bool $enabled */
268- $ enabled = (bool ) cc_apra_get_flag ( 'enabled ' , true );
274+ $ enabled = (bool ) cc_apra_get_flag ('enabled ' , true );
269275 /** @var bool $onHover */
270- $ onHover = (bool ) cc_apra_get_flag ( 'on_hover ' , true );
276+ $ onHover = (bool ) cc_apra_get_flag ('on_hover ' , true );
271277 /** @var bool $hideQuick */
272- $ hideQuick = (bool ) cc_apra_get_flag ( 'hide_quick_edit ' , true );
278+ $ hideQuick = (bool ) cc_apra_get_flag ('hide_quick_edit ' , true );
273279 /** @var array<int,string> $postTypes */
274- $ postTypes = array_values ( (array ) cc_apra_get_flag ( 'post_types ' , constant ( 'CC_APRA_DEFAULT_POST_TYPES ' ) ) );
280+ $ postTypes = array_values ((array ) cc_apra_get_flag ('post_types ' , constant ('CC_APRA_DEFAULT_POST_TYPES ' )) );
275281 /** @var array{ table:string , primaryCell:string , triggerLink:string , rowActions:string } $selectors */
276- $ selectors = cc_apra_get_flag ( 'selectors ' , cc_apra_norm_selectors ( array () ) );
282+ $ selectors = cc_apra_get_flag ('selectors ' , cc_apra_norm_selectors (array ()) );
277283
278284 // flags risolte (filter > define)
279285 $ data = array (
@@ -285,34 +291,34 @@ function cc_apra_enqueue_assets( $hook ) {
285291 );
286292
287293 // ===== CSS critico =====
288- $ critical_path = constant ( 'CC_APRA_ASSETS_DIR ' ) . '/css/critical.css ' ;
289- $ critical_css = file_exists ( $ critical_path ) ? trim ( (string ) file_get_contents ( $ critical_path ) ) : '' ;
294+ $ critical_path = constant ('CC_APRA_ASSETS_DIR ' ) . '/css/critical.css ' ;
295+ $ critical_css = file_exists ($ critical_path ) ? trim ((string ) file_get_contents ($ critical_path) ) : '' ;
290296 /**
291297 * Permette di modificare il CSS critico iniettato inline .
292298 *
293299 * @param string $critical_css CSS da iniettare .
294300 * @return string
295301 */
296- $ critical_css = apply_filters ( 'cc_apra_critical_css ' , $ critical_css );
302+ $ critical_css = apply_filters ('cc_apra_critical_css ' , $ critical_css );
297303
298304 // Registra ed inietta
299- wp_register_script ( 'cc-apra-pre ' , constant ( 'CC_APRA_ASSETS_URL ' ) . '/js/pre.js ' , array ( 'jquery ' ), constant ( 'CC_APRA_VERS ' ), true );
300- wp_register_script ( 'cc-apra-first ' , constant ( 'CC_APRA_ASSETS_URL ' ) . '/js/first.js ' , array ( 'jquery ' , 'cc-apra-pre ' ), constant ( 'CC_APRA_VERS ' ), true );
301- wp_register_script ( 'cc-apra-init ' , constant ( 'CC_APRA_ASSETS_URL ' ) . '/js/init.js ' , array ( 'jquery ' , 'cc-apra-first ' ), constant ( 'CC_APRA_VERS ' ), true );
305+ wp_register_script ('cc-apra-pre ' , constant ('CC_APRA_ASSETS_URL ' ) . '/js/pre.js ' , array ('jquery ' ), constant ('CC_APRA_VERS ' ), true );
306+ wp_register_script ('cc-apra-first ' , constant ('CC_APRA_ASSETS_URL ' ) . '/js/first.js ' , array ('jquery ' , 'cc-apra-pre ' ), constant ('CC_APRA_VERS ' ), true );
307+ wp_register_script ('cc-apra-init ' , constant ('CC_APRA_ASSETS_URL ' ) . '/js/init.js ' , array ('jquery ' , 'cc-apra-first ' ), constant ('CC_APRA_VERS ' ), true );
302308
303309 // Localize opzioni ai JS
304- wp_localize_script ( 'cc-apra-pre ' , 'CC_APRA ' , $ data );
310+ wp_localize_script ('cc-apra-pre ' , 'CC_APRA ' , $ data );
305311
306312 // Enqueue
307- wp_enqueue_script ( 'cc-apra-pre ' );
308- wp_enqueue_script ( 'cc-apra-first ' );
309- wp_enqueue_script ( 'cc-apra-init ' );
313+ wp_enqueue_script ('cc-apra-pre ' );
314+ wp_enqueue_script ('cc-apra-first ' );
315+ wp_enqueue_script ('cc-apra-init ' );
310316
311317 // CSS inline come singleton
312- if ( $ critical_css ) {
318+ if ($ critical_css ) {
313319 $ style_handle = 'cc-apra-critical ' ; // handle “fittizio” : agganciamo al core per garantire stampa nel footer admin
314- wp_register_style ( $ style_handle , false , array (), constant ( 'CC_APRA_VERS ' ) );
315- wp_enqueue_style ( $ style_handle );
316- wp_add_inline_style ( $ style_handle , $ critical_css );
320+ wp_register_style ($ style_handle , false , array (), constant ('CC_APRA_VERS ' ) );
321+ wp_enqueue_style ($ style_handle );
322+ wp_add_inline_style ($ style_handle , $ critical_css );
317323 }
318324}
0 commit comments