Skip to content

Commit

Permalink
Merge pull request #288 from transifex/devel
Browse files Browse the repository at this point in the history
Release 1.3.45
  • Loading branch information
foteinigk authored Aug 13, 2024
2 parents 47996b0 + f28af30 commit d16404f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/transifex-live-integration-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 28 additions & 2 deletions includes/lib/transifex-live-integration-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<a>`) 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
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions transifex-live-integration-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions transifex-live-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );

0 comments on commit d16404f

Please sign in to comment.