diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa131ae..d5dd2e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" env: - PLUGIN_VERSION: 1.3.44 + PLUGIN_VERSION: 1.3.45 WP_PROJECT_TYPE: plugin WP_VERSION: latest WP_MULTISITE: 0 diff --git a/includes/lib/transifex-live-integration-picker.php b/includes/lib/transifex-live-integration-picker.php index cb2b8c0..315a56b 100644 --- a/includes/lib/transifex-live-integration-picker.php +++ b/includes/lib/transifex-live-integration-picker.php @@ -78,7 +78,7 @@ function render() { // Otherwise remove the part from url string until the language prefix // e.g el/sample_page =>sample_page if (strpos($url_path, $lang ) !== false && $url_path !== $lang && strpos($url_path, $lang .'/' ) === false) { - $source_url_path = '/' . $url_path; + $source_url_path = '/' . ltrim( $url_path, '/' ); } else { $source_url_path = (substr($url_path, 0, strlen($lang)) === $lang) ? substr($url_path, strlen($lang)) : $url_path; } diff --git a/includes/lib/transifex-live-integration-rewrite.php b/includes/lib/transifex-live-integration-rewrite.php index 0a14052..4ae3e16 100644 --- a/includes/lib/transifex-live-integration-rewrite.php +++ b/includes/lib/transifex-live-integration-rewrite.php @@ -245,6 +245,32 @@ function post_link_hook( $permalink, $post, $leavename ) { return $retlink; } + /** + * Filters and processes the given field value to handle URLs and localize content. + * + * This function determines whether the provided field value is a valid URL. If it is a URL, + * it localizes the URL by calling the `reverse_hard_link` method. If the field value is not a URL, + * the method `the_content_hook` is invoked to localize all anchor (``) href links within the text content. + * + * This function can be triggered as following: + * e.g add_filter('acf/format_value', [$rewrite, 'custom_field_link_hook'], 10, 3 ); + * + * @param string $field_value The field value to be processed, which can be a URL or custom content. + * @return string The processed field value after handling URLs or applying content hooks. + */ + function custom_field_link_hook($field_value) { + if (filter_var($field_value, FILTER_VALIDATE_URL)) { + if ( !Transifex_Live_Integration_Validators::is_hard_link_ok( $field_value ) ) { + return $field_value; + } + $field_value = $this->reverse_hard_link( $this->lang, $field_value, $this->languages_map, $this->source_language, $this->rewrite_pattern ); + } else { + $field_value = $this->the_content_hook($field_value); + } + + return $field_value; + } + /* * WP post_type_archive_link filter, filters archive links * @param string $link The link to filter @@ -372,11 +398,11 @@ function the_content_hook( $string) { } /* - * WP comment_form_field_comment filter, to add a hidden field to the comment form + * WP comment_form_field_comment filter, to add a hidden field to the comment form * that will be used to redirect the user to the same page after submitting the comment. * We append the the comment field HTML with the hidden field. * @param string $comment_form_field_comment The comment field HTML - * @return string The filtered comment field HTML + * @return string The filtered comment field HTML */ function add_redirect_to_comments_form_hook( $comment_form_field_comment) { Plugin_Debug::logTrace(); diff --git a/readme.md b/readme.md index 2808e01..4c2e0b5 100755 --- a/readme.md +++ b/readme.md @@ -69,6 +69,9 @@ Ex. $updated_content = apply_filters('tx_link', $original_content); * It is also recommended to use [widgets](https://codex.wordpress.org/Widgets_API) in your theme instead of custom code, since this allows you to make your integration more future proof against incompatibilities with 3rd party modules. == Changelog == += 1.3.45 = +Add support for custom post links hook + = 1.3.44 = Fix for language picker diff --git a/readme.txt b/readme.txt index e1acfef..b3a33ad 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: txmatthew, ThemeBoy, brooksx Tags: transifex, localize, localization, multilingual, international, SEO Requires at least: 3.5.2 Tested up to: 6.5.3 -Stable tag: 1.3.44 +Stable tag: 1.3.45 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -78,6 +78,9 @@ Ex. $updated_content = apply_filters('tx_link', $original_content); It is also recommended to use [widgets](https://codex.wordpress.org/Widgets_API) in your theme instead of custom code, since this allows you to make your integration more future proof against incompatibilities with 3rd party modules. == Changelog == += 1.3.45 = +Add support for custom post links hook + = 1.3.44 = Fix for language picker diff --git a/transifex-live-integration-main.php b/transifex-live-integration-main.php index 5cf7102..4be7486 100755 --- a/transifex-live-integration-main.php +++ b/transifex-live-integration-main.php @@ -22,9 +22,6 @@ static function do_plugin( $is_admin, $version ) { $settings = Transifex_Live_Integration_Defaults::settings(); } - if (!isset($settings['is_subdirectory_install'])) { - $settings['is_subdirectory_install'] = 0; - } $live_settings = Transifex_Live_Integration_Defaults::transifex_settings(); $debug_mode = ($settings['debug']) ? true : false; @@ -160,6 +157,10 @@ static function do_plugin( $is_admin, $version ) { // Add filter for custom content that is not triggered by any other hook add_filter('tx_link', [ $rewrite,'the_content_hook'], 10 ,1); add_filter( 'comment_form_field_comment', [ $rewrite, 'add_redirect_to_comments_form_hook'], 10, 1); + + // Add filters for custom post types + add_filter( 'post_type_link', [$rewrite, 'pre_post_link_hook'], 10, 3 ); + add_filter( 'post_type_link', [$rewrite, 'post_link_hook'], 10, 3 ); } } $subdirectory = Transifex_Live_Integration_Static_Factory::create_subdirectory( $settings, $rewrite_options ); diff --git a/transifex-live-integration.php b/transifex-live-integration.php index 0282f4e..c37c231 100755 --- a/transifex-live-integration.php +++ b/transifex-live-integration.php @@ -5,13 +5,13 @@ * * @link https://help.transifex.com/en/articles/6261241-wordpress * @package TransifexLiveIntegration - * @version 1.3.44 + * @version 1.3.45 * * @wordpress-plugin * Plugin Name: International SEO by Transifex * Plugin URI: https://help.transifex.com/en/articles/6261241-wordpress * Description: Translate your WordPress powered website using Transifex. - * Version: 1.3.44 + * Version: 1.3.45 * License: GNU General Public License * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: transifex-live-integration @@ -75,7 +75,7 @@ } define( 'LANG_PARAM', 'lang' ); -$version = '1.3.44'; +$version = '1.3.45'; require_once( dirname( __FILE__ ) . '/transifex-live-integration-main.php' ); Transifex_Live_Integration::do_plugin( is_admin(), $version );