Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-jacob committed Nov 26, 2024
2 parents d90ca67 + 7012256 commit d0f8c93
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
49 changes: 39 additions & 10 deletions inc/slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ function wplng_slug_original_path( $path, $language_id ) {
*/
function wplng_slug_translate( $slug, $language_id, $slugs_translations = false ) {

if ( ! wplng_text_is_translatable( $slug ) ) {
if ( ! wplng_text_is_translatable( $slug )
|| wplng_str_contains( $slug, '.' )
) {
return $slug;
}

Expand All @@ -128,7 +130,7 @@ function wplng_slug_translate( $slug, $language_id, $slugs_translations = false

$slug_translation_exist = false;

foreach ( $slugs_translations as $key => $slug_translations ) {
foreach ( $slugs_translations as $slug_translations ) {

if ( $slug !== $slug_translations['source']
|| ! isset( $slug_translations['translations'][ $language_id ] )
Expand Down Expand Up @@ -219,6 +221,7 @@ function wplng_slug_translate_path( $path, $language_id ) {
if ( wplng_text_is_translatable( $slug )
&& ! wplng_str_starts_with( $slug, '#' )
&& ! wplng_str_starts_with( $slug, '?' )
&& ! wplng_str_contains( $slug, '.' )
) {
$path_translated .= wplng_slug_translate(
$slug,
Expand All @@ -243,7 +246,6 @@ function wplng_slug_translate_path( $path, $language_id ) {
}

return $path_translated;

}


Expand All @@ -261,7 +263,9 @@ function wplng_create_slug( $slug ) {

$slug = sanitize_title( $slug );

if ( '' === $slug ) {
if ( '' === $slug
|| wplng_is_valid_language_id( $slug )
) {
return false;
}

Expand Down Expand Up @@ -354,6 +358,8 @@ function wplng_create_slug( $slug ) {
*/
function wplng_get_slugs_from_query() {

$slug_to_delete = array();

$slugs = array();
$args = array(
'post_type' => 'wplng_slug',
Expand All @@ -370,7 +376,8 @@ function wplng_get_slugs_from_query() {

$the_query->the_post();

$meta = get_post_meta( get_the_ID() );
$slug_id = get_the_ID();
$meta = get_post_meta( $slug_id );

/**
* Check and clear source slug
Expand All @@ -382,7 +389,15 @@ function wplng_get_slugs_from_query() {
continue;
}

$source = esc_attr( $meta['wplng_slug_original'][0] );
$source = sanitize_title( $meta['wplng_slug_original'][0] );

if ( 'index-php' === $source
|| 'wp-includes' === $source
|| 'wp-json' === $source
) {
$slug_to_delete[] = $slug_id;
continue;
}

/**
* Check and clear slug translations, setup review array
Expand Down Expand Up @@ -439,10 +454,24 @@ function wplng_get_slugs_from_query() {

wp_reset_postdata();

set_transient(
'wplng_cached_slugs',
$slugs
);
if ( ! empty( $slug_to_delete ) ) {
foreach ( $slug_to_delete as $key => $id ) {
if ( $key >= 32 ) {
break;
}
wp_delete_post( $id, true );
}
set_transient(
'wplng_cached_slugs',
$slugs,
30
);
} else {
set_transient(
'wplng_cached_slugs',
$slugs
);
}

return $slugs;
}
Expand Down
34 changes: 12 additions & 22 deletions inc/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ function wplng_url_translate( $url, $language_target_id = '' ) {
return $url;
}

// Check if it's an WooCommece AJAX URL
if ( wplng_str_contains( $url, '?wc-ajax=' ) ) {
return $url;
}

// Check if URL is an anchor link for the current page
if ( '#' === substr( $url, 0, 1 ) ) {
return $url;
}

$languages_target = wplng_get_languages_target();

if ( '' === $language_target_id ) {
Expand Down Expand Up @@ -150,16 +140,23 @@ function wplng_url_is_translatable( $url = '' ) {
$is_translatable = false;
}

// Check if is wp-login.php
// Check if URL is an anchor link for the current page
if ( $is_translatable
&& wplng_str_contains( $url, 'wp-login.php' )
&& '#' === substr( $url, 0, 1 )
) {
$is_translatable = false;
return $url;
}

// Check if is a /feed/
if ( $is_translatable
&& wplng_str_ends_with( $url, '/feed/' )
&& (
wplng_str_contains( $url, 'wp-login.php' )
|| wplng_str_ends_with( $url, '/feed/' )
|| wplng_str_contains( $url, 'wp-comments-post.php' )
|| wplng_str_contains( $url, 'wp-register.php' )
|| wplng_str_contains( $url, '/wp-json/' )
|| wplng_str_contains( $url, '/wp-includes/' )
|| wplng_str_contains( $url, '?wc-ajax=' )
)
) {
$is_translatable = false;
}
Expand All @@ -175,13 +172,6 @@ function wplng_url_is_translatable( $url = '' ) {
$is_translatable = false;
}

// Check if is wp-comments-post.php
if ( $is_translatable
&& wplng_str_contains( $url, 'wp-comments-post.php' )
) {
$is_translatable = false;
}

// Check if is in wp-uploads
if ( $is_translatable
&& wplng_str_contains( $url, wp_make_link_relative( content_url() ) )
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://wplingua.com/
Tags: translate, translation, multilingual, localization, language
Requires at least: 6.0
Tested up to: 6.7
Stable tag: 2.1.2
Stable tag: 2.1.3
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -174,6 +174,11 @@ No, not at the moment but in the meantime, you can easily display the language s

== Changelog ==

= 2.1.3 =

* Better untranslatable URL detection
* Automatic bad slug deletion

= 2.1.2 =

* Better plugin translations loading
Expand Down
6 changes: 3 additions & 3 deletions wplingua.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Plugin URI: https://wplingua.com/
* Description: An all-in-one solution that makes your websites multilingual and translates them automatically, without word or page limits. The highlights: a free first language, an on-page visual editor for editing translations, a customizable language switcher, search engine optimization (SEO), self-hosted data and more!
* Author: wpLingua Team
* Author URI: https://github.com/julien-jacob/wplingua
* Author URI: https://wplingua.com/
* Text Domain: wplingua
* Domain Path: /languages/
* Version: 2.1.2
* Version: 2.1.3
* Requires PHP: 7.4
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -24,7 +24,7 @@
define( 'WPLNG_API_URL', 'https://api.wplingua.com' );
define( 'WPLNG_API_VERSION', '2.0' );
define( 'WPLNG_API_SSLVERIFY', true );
define( 'WPLNG_PLUGIN_VERSION', '2.1.2' );
define( 'WPLNG_PLUGIN_VERSION', '2.1.3' );
define( 'WPLNG_PLUGIN_FILE', plugin_basename( __FILE__ ) );
define( 'WPLNG_PLUGIN_PATH', dirname( __FILE__ ) );
define( 'WPLNG_MAX_TRANSLATIONS', 256 );
Expand Down

0 comments on commit d0f8c93

Please sign in to comment.