@@ -23,6 +23,13 @@ class View_Logs_Page {
2323 */
2424 public const ADMIN_PAGE_SLUG = 'wpgraphql-logging-view ' ;
2525
26+ /**
27+ * The hook suffix for the admin page.
28+ *
29+ * @var string
30+ */
31+ protected string $ page_hook = '' ;
32+
2633 /**
2734 * The instance of the view logs page.
2835 *
@@ -61,7 +68,7 @@ public function setup(): void {
6168 public function register_settings_page (): void {
6269
6370 // Add submenu under GraphQL menu using the correct parent slug.
64- $ menu_page = add_menu_page (
71+ $ this -> page_hook = add_menu_page (
6572 esc_html__ ( 'GraphQL Logs ' , 'wpgraphql-logging ' ),
6673 esc_html__ ( 'GraphQL Logs ' , 'wpgraphql-logging ' ),
6774 'manage_options ' ,
@@ -80,7 +87,49 @@ public function register_settings_page(): void {
8087 );
8188
8289 // Updates the list table when filters are applied.
83- add_action ( 'load- ' . $ menu_page , [ $ this , 'process_page_actions_before_rendering ' ], 10 , 0 );
90+ add_action ( 'load- ' . $ this ->page_hook , [ $ this , 'process_page_actions_before_rendering ' ], 10 , 0 );
91+
92+ // Enqueue scripts for the admin page.
93+ add_action ( 'admin_enqueue_scripts ' , [ $ this , 'enqueue_admin_scripts ' ] );
94+ }
95+
96+ /**
97+ * Enqueues scripts and styles for the admin page.
98+ *
99+ * @param string $hook_suffix The current admin page.
100+ */
101+ public function enqueue_admin_scripts ( string $ hook_suffix ): void {
102+ if ( $ hook_suffix !== $ this ->page_hook ) {
103+ return ;
104+ }
105+
106+ // Enqueue WordPress's built-in datepicker and slider.
107+ wp_enqueue_script ( 'jquery-ui-datepicker ' );
108+ wp_enqueue_script ( 'jquery-ui-slider ' );
109+
110+ // Enqueue the timepicker addon script and styles from a CDN.
111+ wp_enqueue_script (
112+ 'jquery-ui-timepicker-addon ' ,
113+ 'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.js ' ,
114+ [ 'jquery-ui-datepicker ' , 'jquery-ui-slider ' ],
115+ '1.6.3 ' ,
116+ true
117+ );
118+ wp_enqueue_style (
119+ 'jquery-ui-timepicker-addon-style ' ,
120+ 'https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.3/jquery-ui-timepicker-addon.min.css ' ,
121+ [],
122+ '1.6.3 '
123+ );
124+
125+ // Enqueue the base jQuery UI styles.
126+ wp_enqueue_style ( 'jquery-ui-style ' , 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css ' , [], '1.12.1 ' );
127+
128+ // Add inline script to initialize the datetimepicker.
129+ wp_add_inline_script (
130+ 'jquery-ui-timepicker-addon ' ,
131+ 'jQuery(document).ready(function($){ $(".wpgraphql-logging-datepicker").datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "HH:mm:ss" }); }); '
132+ );
84133 }
85134
86135 /**
0 commit comments