@@ -231,12 +231,19 @@ public function modify_wpml_behaviour() {
231231 * Register settings page
232232 */
233233 public function register_administration_page () {
234- add_menu_page ( __ ( 'Settings ' , 'wpml-compatibility-test-tools ' ), __ ( 'Multilingual Tools ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'wctt ' , array (
234+ add_menu_page ( __ ( 'Dashboard ' , 'wpml-compatibility-test-tools ' ), __ ( 'Multilingual Tools ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'mt ' , array (
235235 $ this ,
236236 'load_template '
237237 ), WPML_CTT_PLUGIN_URL . '/res/img/wctt-icon.png ' );
238- add_submenu_page ( 'wctt ' , __ ( 'Settings ' , 'wpml-compatibility-test-tools ' ), __ ( 'Settings ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'wctt ' );
239- add_submenu_page ( 'wctt ' , __ ( 'Configuration Generator ' , 'wpml-compatibility-test-tools ' ), __ ( 'Configuration Generator ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'wctt-generator ' , array (
238+ add_submenu_page ( 'mt ' , __ ( 'Overview ' , 'wpml-compatibility-test-tools ' ), __ ( 'Overview ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'mt ' , array (
239+ $ this ,
240+ 'load_template '
241+ ) );
242+ add_submenu_page ( 'mt ' , __ ( 'Settings ' , 'wpml-compatibility-test-tools ' ), __ ( 'Settings ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'mt-settings ' , array (
243+ $ this ,
244+ 'load_template '
245+ ) );
246+ add_submenu_page ( 'mt ' , __ ( 'Configuration Generator ' , 'wpml-compatibility-test-tools ' ), __ ( 'Configuration Generator ' , 'wpml-compatibility-test-tools ' ), 'manage_options ' , 'mt-generator ' , array (
240247 $ this ,
241248 'load_template '
242249 ) );
@@ -249,11 +256,18 @@ public function load_template() {
249256 $ screen = get_current_screen ();
250257
251258 switch ( $ screen ->id ) {
252- case 'toplevel_page_wctt ' :
259+ case 'toplevel_page_mt ' :
260+ add_filter ( 'wpml_config_array ' , array ( $ this , 'save_configuration_for_debug ' ) );
261+ add_filter ( 'wpml_parse_config_file ' , array ( $ this , 'display_configuration_for_debug ' ) );
262+
263+ require WPML_CTT_ABS_PATH . 'menus/settings/overview.php ' ;
264+ break ;
265+
266+ case 'multilingual-tools_page_mt-settings ' :
253267 require WPML_CTT_ABS_PATH . 'menus/settings/settings.php ' ;
254268 break ;
255269
256- case 'multilingual-tools_page_wctt -generator ' :
270+ case 'multilingual-tools_page_mt -generator ' :
257271 require WPML_CTT_ABS_PATH . 'menus/settings/generator.php ' ;
258272 break ;
259273 }
@@ -263,7 +277,7 @@ public function load_template() {
263277 * Add scripts only for plugin pages
264278 */
265279 public function add_scripts ( $ hook ) {
266- if ( in_array ( $ hook , array ( 'toplevel_page_wctt ' , 'multilingual-tools_page_wctt -generator ' ) ) ) {
280+ if ( in_array ( $ hook , array ( 'toplevel_page_mt ' , 'multilingual-tools_page_mt-settings ' , ' multilingual-tools_page_mt -generator ' ) ) ) {
267281 wp_enqueue_script ( 'wctt-scripts ' , WPML_CTT_PLUGIN_URL . '/res/js/wctt-script.js ' , array ( 'jquery ' ), WPML_CTT_VERSION );
268282 wp_localize_script ( 'wctt-scripts ' , 'ajax_object ' , array ( 'ajax_url ' => admin_url ( 'admin-ajax.php ' ) ) );
269283 }
@@ -273,7 +287,7 @@ public function add_scripts( $hook ) {
273287 * Add styles only for plugin pages
274288 */
275289 public function add_styles ( $ hook ) {
276- if ( in_array ( $ hook , array ( 'toplevel_page_wctt ' , 'multilingual-tools_page_wctt -generator ' ) ) ) {
290+ if ( in_array ( $ hook , array ( 'toplevel_page_mt ' , 'multilingual-tools_page_mt-settings ' , ' multilingual-tools_page_mt -generator ' ) ) ) {
277291 wp_register_style ( 'wctt-generator-style ' , WPML_CTT_PLUGIN_URL . '/res/css/wctt-style.css ' , WPML_CTT_VERSION );
278292 wp_enqueue_style ( 'wctt-generator-style ' );
279293 }
@@ -514,4 +528,84 @@ public function generate_shortcodes( $dom, $root ) {
514528 }
515529 }
516530 }
531+
532+ /**
533+ * Save current configuration in a global variable to display later.
534+ *
535+ * @global array $wpml_config_debug
536+ * @param array $config
537+ * @return array
538+ */
539+ function save_configuration_for_debug ( $ config ) {
540+ global $ wpml_config_debug ;
541+
542+ // Check which sections have content and assign a title for each section.
543+ $ wpml_config_debug = array ();
544+ if ( ! empty ( $ config ['wpml-config ' ]['custom-types ' ]['custom-type ' ] ) ) {
545+ $ wpml_config_debug ['Custom posts ' ] = $ config ['wpml-config ' ]['custom-types ' ]['custom-type ' ];
546+ }
547+ if ( ! empty ( $ config ['wpml-config ' ]['taxonomies ' ]['taxonomy ' ] ) ) {
548+ $ wpml_config_debug ['Custom taxonomies ' ] = $ config ['wpml-config ' ]['taxonomies ' ]['taxonomy ' ];
549+ }
550+ if ( ! empty ( $ config ['wpml-config ' ]['custom-fields ' ]['custom-field ' ] ) ) {
551+ $ wpml_config_debug ['Custom fields translation ' ] = $ config ['wpml-config ' ]['custom-fields ' ]['custom-field ' ];
552+ }
553+ if ( ! empty ( $ config ['wpml-config ' ]['custom-term-fields ' ]['custom-term-field ' ] ) ) {
554+ $ wpml_config_debug ['Custom Term Meta Translation ' ] = $ config ['wpml-config ' ]['custom-term-fields ' ]['custom-term-field ' ];
555+ }
556+ if ( ! empty ( $ config ['wpml-config ' ]['shortcodes ' ]['shortcode ' ] ) ) {
557+ $ wpml_config_debug ['Shortcodes ' ] = $ config ['wpml-config ' ]['shortcodes ' ]['shortcode ' ];
558+ }
559+ if ( ! empty ( $ config ['wpml-config ' ]['admin-texts ' ]['key ' ] ) ) {
560+ $ wpml_config_debug ['Admin Strings to Translate ' ] = $ config ['wpml-config ' ]['admin-texts ' ]['key ' ];
561+ }
562+ if ( ! empty ( $ config ['wpml-config ' ]['language-switcher-settings ' ]['key ' ] ) ) {
563+ $ wpml_config_debug ['Language Switcher Settings ' ] = $ config ['wpml-config ' ]['language-switcher-settings ' ]['key ' ];
564+ }
565+
566+ return $ config ;
567+ }
568+
569+ /**
570+ * Intercept wpml-config.xml parsing to display loaded configuration files
571+ * for debugging purposes.
572+ *
573+ * @global object $sitepress
574+ * @param string $file
575+ * @return string
576+ */
577+ function display_configuration_for_debug ( $ file ) {
578+ // Get url and name.
579+ if ( is_object ( $ file ) ) {
580+ $ url = ICL_REMOTE_WPML_CONFIG_FILES_INDEX . 'wpml-config/ ' . $ file ->admin_text_context . '/wpml-config.xml ' ;
581+ $ name = $ file ->admin_text_context ;
582+ $ class = 'dashicons-admin-site ' ;
583+ } else {
584+ $ url = str_replace ( WP_CONTENT_DIR , WP_CONTENT_URL , $ file );
585+ $ name = basename ( dirname ( $ url ) );
586+ $ class = '' ;
587+ }
588+
589+ // Display link to file.
590+ echo '<a href=" ' . $ url . '"> ' . $ name . '</a> ' ;
591+ if ( ! empty ( $ class ) ) {
592+ echo ' <span class="dashicons ' . $ class . '"></span> ' ;
593+ }
594+ echo '<br /> ' ;
595+
596+ // Display validation errors if any found.
597+ if ( is_string ( $ file ) && file_exists ( $ file ) ) {
598+ $ validate = new WPML_XML_Config_Validate ( WPML_PLUGIN_PATH . '/res/xsd/wpml-config.xsd ' );
599+ $ validate ->from_file ($ file );
600+ $ errors = wp_list_pluck ( $ validate ->get_errors (), 'message ' );
601+ if ( ! empty ( $ errors ) ) {
602+ $ errors = array_unique ( $ errors );
603+ // TODO: add some style.
604+ echo '<p> ' . implode ( '<br> ' , $ errors ) . '</p> ' ;
605+ }
606+ }
607+
608+ return $ file ;
609+ }
610+
517611}
0 commit comments