Skip to content

Commit 0d307e9

Browse files
Merge pull request #37 from OnTheGoSystems/compdev-863
- Fixed Configuration Generator ignoring capitalization in custom field names, shortcode tags, and shortcode attributes: https://onthegosystems.myjetbrains.com/youtrack/issue/compdev-863/ - Fixed remote XML configuration file links returning 404 errors in Overview page: https://onthegosystems.myjetbrains.com/youtrack/issue/compdev-959
2 parents d2f01dd + 4e84c44 commit 0d307e9

3 files changed

Lines changed: 110 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.3.0
2+
3+
## Bugfix
4+
5+
- Fixed Configuration Generator ignoring capitalization in custom field names, shortcode tags, and shortcode attributes
6+
- Fixed remote XML configuration file links returning 404 errors in Overview page
7+
18
# 2.2.6
29

310
## Improvements

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

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public function generate_basic_content_types( $dom, $root, $content, $checkbox,
574574
}
575575

576576
if ( isset( $checkbox[ $c ] ) ) {
577-
$child_node = $dom->createElement( $child, sanitize_key( $c ) );
577+
$child_node = $dom->createElement( $child, sanitize_text_field( $c ) );
578578
$child_node = $parent_node->appendChild( $child_node );
579579
$child_node_attr = $dom->createAttribute( $attribute );
580580
$child_node_attr->value = wpml_ctt_validate_radio( $radio[ $c ] );
@@ -632,7 +632,7 @@ public function generate_shortcodes( $dom, $root ) {
632632
foreach ( $shortcodes as $shortcode ) {
633633

634634
$shortcode_index = array_search( $shortcode, $shortcodes, true );
635-
$shortcode = str_replace( ' ', '', sanitize_html_class( $shortcode, "Invalid_shortcode" ) );
635+
$shortcode = sanitize_text_field( str_replace( ' ', '', $shortcode ) );
636636

637637
$shortcode_node = $dom->createElement( 'shortcode' );
638638
$shortcode_node = $shortcodes_node->appendChild( $shortcode_node );
@@ -652,12 +652,12 @@ public function generate_shortcodes( $dom, $root ) {
652652
if ( ! empty( $attributes_array ) ) {
653653

654654
foreach ( $attributes_array as $a ) {
655-
$attribute_node = $dom->createElement( 'attribute', sanitize_html_class( $a, "Invalid_attribute" ) );
655+
$attribute_node = $dom->createElement( 'attribute', sanitize_text_field( $a ) );
656656
$attributes_node->appendChild( $attribute_node );
657657
}
658658

659659
} else {
660-
$attribute_node = $dom->createElement( 'attribute', sanitize_html_class( $attribute, "Invalid_attribute" ) );
660+
$attribute_node = $dom->createElement( 'attribute', sanitize_text_field( $attribute ) );
661661
$attributes_node->appendChild( $attribute_node );
662662
}
663663
}
@@ -702,6 +702,99 @@ function save_configuration_for_debug( $config ) {
702702
return $config;
703703
}
704704

705+
/**
706+
* Get plugin or theme name from directory slug.
707+
*
708+
* @param string $slug Directory name (e.g., 'bb-plugin', 'avada')
709+
*
710+
* @return string|false Plugin/theme name or false if not found
711+
*/
712+
function get_plugin_or_theme_name_from_slug( $slug ) {
713+
static $cache = array();
714+
715+
// Return cached result if available
716+
if ( isset( $cache[ $slug ] ) ) {
717+
return $cache[ $slug ];
718+
}
719+
720+
if ( ! function_exists( 'get_plugins' ) ) {
721+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
722+
}
723+
724+
$all_plugins = get_plugins();
725+
726+
foreach ( $all_plugins as $plugin_path => $plugin_data ) {
727+
// Plugin path format: "plugin-folder/plugin-file.php"
728+
$plugin_folder = dirname( $plugin_path );
729+
730+
if ( $plugin_folder === $slug ) {
731+
$cache[ $slug ] = $plugin_data['Name'];
732+
return $plugin_data['Name'];
733+
}
734+
}
735+
736+
$theme = wp_get_theme( $slug );
737+
if ( $theme->exists() ) {
738+
$theme_name = $theme->get( 'Name' );
739+
$cache[ $slug ] = $theme_name;
740+
return $theme_name;
741+
}
742+
743+
return false;
744+
}
745+
746+
/**
747+
* Get the correct folder ID from wpml_config_index based on admin_text_context.
748+
*
749+
* @param string $admin_text_context
750+
*
751+
* @return string
752+
*/
753+
function get_remote_config_folder_id( $admin_text_context ) {
754+
static $cache = array();
755+
756+
if ( isset( $cache[ $admin_text_context ] ) ) {
757+
return $cache[ $admin_text_context ];
758+
}
759+
760+
$config_index = get_option( 'wpml_config_index', array() );
761+
762+
if ( empty( $config_index ) ) {
763+
$result = strtolower( $admin_text_context );
764+
$cache[ $admin_text_context ] = $result;
765+
return $result;
766+
}
767+
768+
$plugin_or_theme_name = $this->get_plugin_or_theme_name_from_slug( $admin_text_context );
769+
770+
$sections = array( 'global', 'plugins', 'themes' );
771+
772+
foreach ( $sections as $section ) {
773+
if ( ! isset( $config_index->$section ) || ! is_array( $config_index->$section ) ) {
774+
continue;
775+
}
776+
777+
foreach ( $config_index->$section as $config_item ) {
778+
if ( ! isset( $config_item->path ) || ! isset( $config_item->name ) ) {
779+
continue;
780+
}
781+
782+
if ( $plugin_or_theme_name && $config_item->name === $plugin_or_theme_name ) {
783+
$path_parts = explode( '/', $config_item->path );
784+
if ( isset( $path_parts[1] ) && ! empty( $path_parts[1] ) ) {
785+
$result = $path_parts[1];
786+
$cache[ $admin_text_context ] = $result;
787+
return $result;
788+
}
789+
}
790+
}
791+
}
792+
793+
$result = strtolower( $admin_text_context );
794+
$cache[ $admin_text_context ] = $result;
795+
return $result;
796+
}
797+
705798
/**
706799
* Intercept wpml-config.xml parsing to display loaded configuration files
707800
* for debugging purposes.
@@ -714,9 +807,10 @@ function save_configuration_for_debug( $config ) {
714807
function display_configuration_for_debug( $file ) {
715808
// Get url and name.
716809
if ( is_object( $file ) ) {
717-
$url = ICL_REMOTE_WPML_CONFIG_FILES_INDEX . 'wpml-config/' . $file->admin_text_context . '/wpml-config.xml';
718-
$name = $file->admin_text_context;
719-
$class = 'dashicons-admin-site';
810+
$folder_id = $this->get_remote_config_folder_id( $file->admin_text_context );
811+
$url = ICL_REMOTE_WPML_CONFIG_FILES_INDEX . 'wpml-config/' . $folder_id . '/wpml-config.xml';
812+
$name = $file->admin_text_context;
813+
$class = 'dashicons-admin-site';
720814
} else {
721815
$url = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $file );
722816
$name = basename( dirname( $url ) );

multilingual-tools.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Description: Set of tools to test themes and plugins multilingual compatibility.
66
Author: OnTheGoSystems
77
Author URI: https://www.onthegosystems.com/
8-
Version: 2.2.6
8+
Version: 2.3.0
99
*/
1010

11-
define('WPML_CTT_VERSION', '2.2.6');
11+
define('WPML_CTT_VERSION', '2.3.0');
1212
define('WPML_CTT_PATH', dirname(__FILE__));
1313
define('WPML_CTT_ABS_PATH', plugin_dir_path(__FILE__));
1414
define('WPML_CTT_FOLDER', basename(WPML_CTT_PATH));

0 commit comments

Comments
 (0)