Skip to content

Commit c90ce0f

Browse files
author
David Garcia Watkins
authored
Merge pull request #18 from OnTheGoSystems/develop
Release 2.0.0
2 parents c9ab127 + 194852d commit c90ce0f

14 files changed

Lines changed: 353 additions & 21 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.0.0
2+
3+
## Improvements
4+
5+
* Add a Overview screen which displays loaded configuration and validation errors.
6+
17
# 1.4.0
28

39
## Improvements

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multilingual Tools
22

3-
![Latest Stable Version](https://img.shields.io/badge/stable-1.4.0-green.svg?style=flat-squar)
3+
![Latest Stable Version](https://img.shields.io/badge/stable-2.0.0-green.svg?style=flat-squar)
44
![License](https://img.shields.io/badge/license-GPLv2-red.svg?style=flat-squar)
55

66

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "wordpress-plugin",
44
"description": "Set of tools related to WPML plugin bundle. Created with tendency to ease WPML compatibility testing process.",
55
"homepage": "https://wpml.org/documentation/related-projects/wpml-compatibility-test-tools-plugin/",
6-
"license": "GPL-2",
6+
"license": "GPL-2.0",
77
"require": {
88
"php": ">=5.2",
99
"composer/installers": "^1.2"

composer.lock

Lines changed: 140 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/wpml-compatibility-test-tools.class.php

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

inc/wpml-compatibility-test-tools.functions.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,41 @@ function wpml_ctt_load_alloptions() {
342342
}
343343

344344
return $alloptions;
345-
}
345+
}
346+
347+
/**
348+
* Display an entry from a wpml-config.xml file.
349+
*
350+
* @param array $entry
351+
*/
352+
function wpml_ctt_parse_entry( $entry ) {
353+
if ( isset( $entry['tag']['value'] ) ) {
354+
// This is for items from the shortcodes section.
355+
echo '<strong>' . $entry['tag']['value'] . '</strong>';
356+
if ( ! empty( $entry['attributes']['attribute'] ) ) {
357+
if ( isset( $entry['attributes']['attribute']['value'] ) ) {
358+
$entry['attributes']['attribute'] = array( $entry['attributes']['attribute'] );
359+
}
360+
$attributes = wp_list_pluck($entry['attributes']['attribute'], 'value' );
361+
echo ': ' . implode( ', ', $attributes );
362+
}
363+
echo '<br />';
364+
} else if ( isset( $entry['attr']['name'] ) ) {
365+
// This part if for admin-texts and language-switcher-settings.
366+
echo '<strong>' . $entry['attr']['name'] . '</strong>: ';
367+
echo $entry['value'] . '<br />';
368+
if ( ! empty( $entry['key'] ) ) {
369+
echo '<blockquote style="margin: 0 1em;">';
370+
foreach ( $entry['key'] as $key ) {
371+
wpml_ctt_parse_entry( $key );
372+
}
373+
echo '</blockquote>';
374+
}
375+
} else {
376+
// This is for any other type of entry.
377+
echo '<strong>' . $entry['value'] . '</strong>: ';
378+
foreach ( $entry['attr'] as $key => $value ) {
379+
echo $key . ' =&gt; ' . $value . '<br /> ';
380+
}
381+
}
382+
}

menus/settings/auto-translate-duplicate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<table id="wctt-settings" class="widefat general_options_table">
22
<thead>
33
<tr>
4-
<th><?php _e( 'Add language information to post duplicate', 'wpml-compatibility-test-tools' ) ?></th>
4+
<th><h3><?php _e( 'Add language information to post duplicate', 'wpml-compatibility-test-tools' ) ?></h3></th>
55
</tr>
66
</thead>
77
<tbody>

menus/settings/auto-translate-strings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<table id="wctt-settings" class="widefat general_options_table">
22
<thead>
33
<tr>
4-
<th><?php _e( 'Auto generate strings translations', 'wpml-compatibility-test-tools' ) ?></th>
4+
<th><h3><?php _e( 'Auto generate strings translations', 'wpml-compatibility-test-tools' ) ?></h3></th>
55
</tr>
66
</thead>
77
<tbody>
@@ -68,4 +68,4 @@
6868
</td>
6969
</tr>
7070
</tbody>
71-
</table>
71+
</table>

0 commit comments

Comments
 (0)