Plugin Directory

Changeset 3377775


Ignore:
Timestamp:
10/14/2025 12:25:31 AM (4 months ago)
Author:
wplingua
Message:

2.9.3

Location:
wplingua
Files:
484 added
9 edited

Legend:

Unmodified
Added
Removed
  • wplingua/trunk/inc/admin/option-page-settings.php

    r3375376 r3377775  
    251251        echo esc_html__( 'This is the language of your website, defined by the associated API key. Make sure your website language is also correctly set in WordPress options (Settings ➔ General ➔ Website Language).', 'wplingua' );
    252252        echo '<hr>';
    253         echo esc_html__( 'If you have mistakenly entered the wrong language, contact wpLingua support to request a correction.', 'wplingua' );
    254         echo ' ';
    255         echo '<a href="https://wplingua.com/support/" target="_blank">';
    256         echo esc_html__( 'wplingua.com : Contact support', 'wplingua' );
    257         echo '</a>';
     253        echo esc_html__( 'If you have mistakenly selected the wrong language, you can delete the API key in the site options below and request a new API key.', 'wplingua' );
    258254        echo '</p>';
    259255        echo '</div>';
  • wplingua/trunk/inc/admin/slug-cpt.php

    r3346685 r3377775  
    9090
    9191
     92/**
     93 * Filters the query for the 'wplng_slug' post type in the WordPress admin area.
     94 *
     95 * This function modifies the main query in the admin area to include a meta query
     96 * that filters posts of type 'wplng_slug' based on the meta key
     97 * 'wplng_slug_original_language_id'. Only posts where this meta key matches
     98 * the current website's language ID (retrieved via `wplng_get_language_website_id()`)
     99 * will be included in the results.
     100 *
     101 * @param WP_Query $query The current query instance.
     102 * @return void
     103 */
     104function wplng_filter_wplng_slug_posts( $query ) {
     105
     106    // Check if we are in the admin area, working with the main query,
     107    // and the post type is 'wplng_translation'.
     108    if ( is_admin()
     109        && $query->is_main_query()
     110        && $query->get('post_type') === 'wplng_slug'
     111    ) {
     112        $query->set( 'meta_query',
     113            array(
     114                array(
     115                    'key'     => 'wplng_slug_original_language_id',
     116                    'value'   => wplng_get_language_website_id(),
     117                    'compare' => '='
     118                ),
     119            )
     120        );
     121    }
     122}
     123
    92124
    93125/**
  • wplingua/trunk/inc/admin/translation-cpt.php

    r3346685 r3377775  
    8686
    8787/**
     88 * Filters the query for the 'wplng_translation' post type in the WordPress admin area.
     89 *
     90 * This function modifies the main query in the admin area to include a meta query
     91 * that filters posts of type 'wplng_translation' based on the meta key
     92 * 'wplng_translation_original_language_id'. Only posts where this meta key matches
     93 * the current website's language ID (retrieved via `wplng_get_language_website_id()`)
     94 * will be included in the results.
     95 *
     96 * @param WP_Query $query The current query instance.
     97 * @return void
     98 */
     99function wplng_filter_wplng_translation_posts( $query ) {
     100
     101    // Check if we are in the admin area, working with the main query,
     102    // and the post type is 'wplng_translation'.
     103    if ( is_admin()
     104        && $query->is_main_query()
     105        && $query->get('post_type') === 'wplng_translation'
     106    ) {
     107        $query->set( 'meta_query',
     108            array(
     109                array(
     110                    'key'     => 'wplng_translation_original_language_id',
     111                    'value'   => wplng_get_language_website_id(),
     112                    'compare' => '='
     113                ),
     114            )
     115        );
     116    }
     117}
     118
     119
     120/**
    88121 * Filter translations by status: Display option on CPT list
    89122 *
  • wplingua/trunk/inc/api-call/translate.php

    r3335611 r3377775  
    8585    $api_key = wplng_get_api_key();
    8686
    87     if ( empty( $api_key ) ) {
     87    if ( ! wplng_is_valid_api_key_format( $api_key ) ) {
    8888        return array();
    8989    }
  • wplingua/trunk/inc/heartbeat.php

    r3305387 r3377775  
    88
    99/**
    10  * HeartBeat: Clear bad translations
     10 * HeartBeat: Clear bad translations and slugs
    1111 *
    1212 * @return void
     
    1414function wplng_ajax_heartbeat() {
    1515
    16     $last_beat = get_option( 'wplng_hb_last_update' );
    17     $now       = time();
    18     $counter   = 25;
    19     $deleted   = array();
     16    $language_website_id = wplng_get_language_website_id();
     17    $last_beat           = get_option( 'wplng_hb_last_update' );
     18    $now                 = time();
     19    $counter             = 100;
     20    $deleted             = array();
    2021
    2122    // Prevents frequent execution if the last heartbeat was within 10 minutes
     
    3031    update_option( 'wplng_hb_last_update', $now );
    3132
    32     // Retrieve only post IDs for better performance
    33     $args = array(
    34         'post_type'              => 'wplng_translation',
    35         'posts_per_page'         => -1,
    36         'no_found_rows'          => true,
    37         'update_post_term_cache' => false,
    38         'update_post_meta_cache' => false,
    39         'cache_results'          => false,
    40         'fields'                 => 'ids', // Retrieve only post IDs
     33    /**
     34     * Check translations
     35     */
     36
     37    $translation_ids = get_posts(
     38        array(
     39            'post_type'              => 'wplng_translation',
     40            'posts_per_page'         => -1,
     41            'no_found_rows'          => true,
     42            'update_post_term_cache' => false,
     43            'update_post_meta_cache' => false,
     44            'cache_results'          => false,
     45            'fields'                 => 'ids',
     46        )
    4147    );
    4248
    43     $post_ids = get_posts( $args );
    44 
    45     if ( empty( $post_ids ) ) {
    46         wp_send_json_success();
    47         return;
    48     }
    49 
    50     foreach ( $post_ids as $id ) {
     49    foreach ( $translation_ids as $id ) {
    5150
    5251        if ( $counter <= 0 ) {
     
    6362            || empty( $meta['wplng_translation_md5'][0] )
    6463        ) {
     64
    6565            --$counter;
    6666
    6767            $deleted[] = array(
    68                 'reason' => 'Invalid translation',
     68                'reason' => 'Delete translation - Invalid data',
    6969                'title'  => get_the_title( $id ),
    7070                'id'     => $id,
     
    7373            // Permanently delete the invalid translation
    7474            wp_delete_post( $id, true );
     75            continue;
     76        }
     77
     78        // Check language of the translation
     79        if ( empty( $meta['wplng_translation_original_language_id'][0] )
     80            || $meta['wplng_translation_original_language_id'][0] !== $language_website_id
     81        ) {
     82
     83            --$counter;
     84
     85            $deleted[] = array(
     86                'reason' => 'Delete translation - Incorrect original language',
     87                'title'  => get_the_title( $id ),
     88                'id'     => $id,
     89            );
     90
     91            // Permanently delete the translation
     92            wp_delete_post( $id, true );
     93            continue;
    7594        }
    7695    }
    7796
    78     // Debug logging (if enabled)
     97    /**
     98     * Check slugs
     99     */
     100
     101    $slug_ids = get_posts(
     102        array(
     103            'post_type'              => 'wplng_slug',
     104            'posts_per_page'         => -1,
     105            'no_found_rows'          => true,
     106            'update_post_term_cache' => false,
     107            'update_post_meta_cache' => false,
     108            'cache_results'          => false,
     109            'fields'                 => 'ids', // Retrieve only post IDs
     110        )
     111    );
     112
     113    foreach ( $slug_ids as $id ) {
     114
     115        if ( $counter <= 0 ) {
     116            break;
     117        }
     118
     119        $meta = get_post_meta( $id );
     120
     121        // Validate translation metadata
     122        if ( empty( $meta['wplng_slug_original'][0] )
     123            || ! is_string( $meta['wplng_slug_original'][0] )
     124            || trim( $meta['wplng_slug_original'][0] ) === ''
     125            || empty( $meta['wplng_slug_translations'][0] )
     126            || empty( $meta['wplng_slug_md5'][0] )
     127        ) {
     128
     129            --$counter;
     130
     131            $deleted[] = array(
     132                'reason' => 'Delete slug - Invalid data',
     133                'title'  => get_the_title( $id ),
     134                'id'     => $id,
     135            );
     136
     137            // Permanently delete the invalid slug
     138            wp_delete_post( $id, true );
     139            continue;
     140        }
     141
     142        // Check language of the translation
     143        if ( empty( $meta['wplng_slug_original_language_id'][0] )
     144            || $meta['wplng_slug_original_language_id'][0] !== $language_website_id
     145        ) {
     146
     147            --$counter;
     148
     149            $deleted[] = array(
     150                'reason' => 'Delete slug - Incorrect original language',
     151                'title'  => get_the_title( $id ),
     152                'id'     => $id,
     153            );
     154
     155            // Permanently delete the translation
     156            wp_delete_post( $id, true );
     157            continue;
     158        }
     159    }
     160
     161    /**
     162     * Debug logging (if enabled)
     163     */
     164
    79165    if ( true === WPLNG_DEBUG_BEAT ) {
    80166        $debug = array(
  • wplingua/trunk/inc/slug.php

    r3305387 r3377775  
    381381        'cache_results'          => false,
    382382        'fields'                 => 'ids', // Only retrieve post IDs
     383        'meta_query'             => array(
     384            array(
     385                'key'     => 'wplng_slug_original_language_id',
     386                'value'   => wplng_get_language_website_id(),
     387                'compare' => '='
     388            ),
     389        ),
    383390    );
    384391
     
    556563        ),
    557564        'fields'         => 'ids',
     565        'meta_query'             => array(
     566            array(
     567                'key'     => 'wplng_slug_original_language_id',
     568                'value'   => wplng_get_language_website_id(),
     569                'compare' => '='
     570            ),
     571        ),
    558572    );
    559573
  • wplingua/trunk/inc/translation.php

    r3305387 r3377775  
    8383        ),
    8484        'fields'         => 'ids',
     85        'meta_query'             => array(
     86            array(
     87                'key'     => 'wplng_translation_original_language_id',
     88                'value'   => wplng_get_language_website_id(),
     89                'compare' => '='
     90            ),
     91        ),
    8592    );
    8693
     
    124131        'cache_results'          => false,
    125132        'fields'                 => 'ids', // Retrieve only post IDs for better performance
     133        'meta_query'             => array(
     134            array(
     135                'key'     => 'wplng_translation_original_language_id',
     136                'value'   => wplng_get_language_website_id(),
     137                'compare' => '='
     138            ),
     139        ),
    126140    );
    127141
  • wplingua/trunk/readme.txt

    r3375376 r3377775  
    55Requires at least: 6.0
    66Tested up to: 6.8
    7 Stable tag: 2.9.2
     7Stable tag: 2.9.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    192192== Changelog ==
    193193
     194= 2.9.3 =
     195
     196* Check original language on translations
     197* HeartBeat:
     198 * Check and clear bad slugs
     199 * Clear translations with bad original language
     200 * Clear more slugs or translation per occurrence
     201* Better API key management
     202
    194203= 2.9.2 =
    195204
  • wplingua/trunk/wplingua.php

    r3375376 r3377775  
    88 * Text Domain: wplingua
    99 * Domain Path: /languages/
    10  * Version: 2.9.2
     10 * Version: 2.9.3
    1111 * Requires PHP: 7.4
    1212 * License: GPL v2 or later
     
    2525define( 'WPLNG_API_VERSION', '3.0' );
    2626define( 'WPLNG_API_SSLVERIFY', true );
    27 define( 'WPLNG_PLUGIN_VERSION', '2.9.2' );
     27define( 'WPLNG_PLUGIN_VERSION', '2.9.3' );
    2828define( 'WPLNG_PLUGIN_FILE', plugin_basename( __FILE__ ) );
    2929define( 'WPLNG_PLUGIN_PATH', __DIR__ );
     
    197197        add_action( 'admin_print_scripts-edit.php', 'wplng_translation_list_assets' );
    198198
     199        // Only show translations for the website languages
     200        add_action( 'pre_get_posts', 'wplng_filter_wplng_translation_posts' );
     201
    199202        // Remove Quick edit from translations list
    200203        add_filter( 'post_row_actions', 'wplng_translation_remove_quick_edit', 10, 2 );
     
    249252        // Enqueue Script for wplng_slug admin: List
    250253        add_action( 'admin_print_scripts-edit.php', 'wplng_slug_list_assets' );
     254
     255        // Only show slugs for the website languages
     256        add_action( 'pre_get_posts', 'wplng_filter_wplng_slug_posts' );
    251257
    252258        // Remove Quick edit from slugs list
Note: See TracChangeset for help on using the changeset viewer.