Plugin Directory

Changeset 3265363


Ignore:
Timestamp:
04/02/2025 01:32:02 AM (11 months ago)
Author:
wplingua
Message:

2.5.4

Location:
wplingua
Files:
473 added
47 edited

Legend:

Unmodified
Added
Removed
  • wplingua/trunk/data.php

    r3258836 r3265363  
    1111 */
    1212
    13  /**
    14   * Get JSON elements to translate
    15   *
    16   * @return array
    17   */
     13/**
     14 * Get JSON elements to translate
     15 *
     16 * @return array
     17 */
    1818function wplng_data_json_to_translate() {
    1919    return apply_filters(
     
    493493 */
    494494
    495  /**
    496   * Get options for switcher insertion
    497   *
    498   * @return array
    499   */
     495/**
     496 * Get options for switcher insertion
     497 *
     498 * @return array
     499 */
    500500function wplng_data_switcher_valid_insert() {
    501501    return array(
     
    634634 */
    635635
    636  /**
    637   * Get all languages data
    638   *
    639   * @return array
    640   */
     636/**
     637 * Get all languages data
     638 *
     639 * @return array
     640 */
    641641function wplng_data_languages() {
    642642    return array(
  • wplingua/trunk/inc/admin/admin-bar.php

    r3262485 r3265363  
    277277        array(
    278278            'id'    => 'wplingua-edit-translations',
    279             'title' => __( 'Edit translations', 'wplingua' ),
     279            'title' => __( 'Translations', 'wplingua' ),
    280280            'href'  => $url,
    281281        )
  • wplingua/trunk/inc/admin/admin.php

    r3262485 r3265363  
    1010 * Add a link for edit translations on page and post list
    1111 *
    12  * @param array $actions An array of row action links (string)
     12 * @param array   $actions An array of row action links (string)
    1313 * @param WP_Post $post The post object
    1414 * @return array
  • wplingua/trunk/inc/admin/assets.php

    r3242916 r3265363  
    5656        WPLNG_PLUGIN_VERSION
    5757    );
    58 
    5958}
    6059
     
    108107        WPLNG_PLUGIN_VERSION
    109108    );
    110 
    111109}
    112110
     
    235233        WPLNG_PLUGIN_VERSION
    236234    );
    237 
    238235}
    239236
     
    257254     */
    258255
    259      wp_enqueue_script( 'jquery' );
    260 
    261      /**
    262       * Enqueue wpLingua JS scripts
    263       */
     256    wp_enqueue_script( 'jquery' );
     257
     258    /**
     259     * Enqueue wpLingua JS scripts
     260     */
    264261
    265262    wp_enqueue_script(
     
    280277        WPLNG_PLUGIN_VERSION
    281278    );
    282 
    283279}
    284280
     
    302298     */
    303299
    304      wp_enqueue_script( 'jquery' );
    305 
    306      /**
    307       * Enqueue wpLingua JS scripts
    308       */
     300    wp_enqueue_script( 'jquery' );
     301
     302    /**
     303     * Enqueue wpLingua JS scripts
     304     */
    309305
    310306    wp_enqueue_script(
     
    325321        WPLNG_PLUGIN_VERSION
    326322    );
    327 
    328323}
    329324
     
    391386
    392387    }
    393 
    394388}
    395389
     
    457451
    458452    }
    459 
    460453}
    461454
  • wplingua/trunk/inc/admin/option-page.php

    r3249995 r3265363  
    252252        exit();
    253253    }
    254 
    255254}
    256255
  • wplingua/trunk/inc/admin/slug-cpt.php

    r3201266 r3265363  
    5151 * quick edit action from the list of actions on the slugs list page.
    5252 *
    53  * @param array     $actions An array of row action links.
    54  * @param WP_Post   $post    The post object.
     53 * @param array   $actions An array of row action links.
     54 * @param WP_Post $post    The post object.
    5555 *
    5656 * @return array
     
    129129        );
    130130    } else {
    131         // If more than one language target id, 
     131        // If more than one language target id,
    132132        // then use full, partially and reviewed status options.
    133133        $options = array_merge(
     
    296296 * @param string[] $classes An array of post class names.
    297297 * @param string[] $css_class An array of additional class names added to the post.
    298  * @param int $post_id The post ID.
     298 * @param int      $post_id The post ID.
    299299 * @return string[]
    300300 */
     
    375375 *
    376376 * @param string $column The name of the column to display.
    377  * @param int $post_id The current post ID.
     377 * @param int    $post_id The current post ID.
    378378 * @return void
    379379 */
     
    409409 *
    410410 * @param string[] $actions An array of row action links.
    411  * @param WP_Post $post The post object.
     411 * @param WP_Post  $post The post object.
    412412 * @return string[]
    413413 */
  • wplingua/trunk/inc/admin/slug-meta.php

    r3242916 r3265363  
    2727        'low'                               // Priority within the context
    2828    );
    29 
    3029}
    3130
     
    4443    echo wplng_slug_editor_get_html( $post );
    4544    echo '</div>';
    46 
    4745}
    4846
     
    434432
    435433                    $has_same_slugs = true;
    436                     $same_slugs_counter++;
     434                    ++$same_slugs_counter;
    437435
    438436                    $temp = preg_replace(
  • wplingua/trunk/inc/admin/switcher-nav-menu.php

    r3145632 r3265363  
    7676             */
    7777
    78              // Infinite nav menu switcher
    79              // Update the edit fields event listen
     78            // Infinite nav menu switcher
     79            // Update the edit fields event listen
    8080
    8181            let wplngNewValidate = document.getElementById('submit-posttype-wplingua-endpoints');
     
    270270 * Print option in wpLingua nav menu
    271271 *
    272  * @param string $item_id
     272 * @param string  $item_id
    273273 * @param WP_Post $menu_item
    274274 * @return void
  • wplingua/trunk/inc/admin/translation-cpt.php

    r3201266 r3265363  
    5151 * translations list in the WordPress admin area.
    5252 *
    53  * @param array $actions An array of row action links.
     53 * @param array  $actions An array of row action links.
    5454 * @param object $post The post object.
    5555 * @return array The modified array of row action links.
     
    146146 * Filter translations by status: Apply custom query on CPT for translation_status.
    147147 *
    148  * This function modifies the query for the 'wplng_translation' post type in the admin edit screen. 
     148 * This function modifies the query for the 'wplng_translation' post type in the admin edit screen.
    149149 * It applies a meta query based on the specified translation status.
    150150 *
     
    276276 * @param string[] $classes An array of post class names.
    277277 * @param string[] $css_class An array of additional class names added to the post.
    278  * @param int $post_id The post ID.
     278 * @param int      $post_id The post ID.
    279279 * @return string[]
    280280 */
     
    355355 *
    356356 * @param string $column The name of the column to display.
    357  * @param int $post_id The current post ID.
     357 * @param int    $post_id The current post ID.
    358358 * @return void
    359359 */
     
    389389 *
    390390 * @param string[] $actions An array of row action links.
    391  * @param WP_Post $post The post object.
     391 * @param WP_Post  $post The post object.
    392392 * @return string[]
    393393 */
  • wplingua/trunk/inc/admin/translation-edit-modal.php

    r3201266 r3265363  
    179179        return;
    180180    }
    181 
    182181}
  • wplingua/trunk/inc/admin/translation-meta.php

    r3258836 r3265363  
    2727        'low'                                       // Priority within the context
    2828    );
    29 
    3029}
    3130
     
    4645    echo wplng_translation_editor_get_html( $post );
    4746    echo '</div>';
    48 
    4947}
    5048
     
    5856function wplng_translation_editor_get_html( $post ) {
    5957
    60     //used later for security
     58    // used later for security
    6159    $html = wp_nonce_field(
    6260        basename( __FILE__ ),
     
    413411     */
    414412
    415      $meta_return = update_post_meta(
     413    $meta_return = update_post_meta(
    416414        $post_id,
    417415        'wplng_translation_translations',
  • wplingua/trunk/inc/api-call/translate.php

    r3242916 r3265363  
    3838 * - message : Error description
    3939 *
    40  * @param array $texts
     40 * @param array  $texts
    4141 * @param string $language_source_id
    4242 * @param string $language_target_id
  • wplingua/trunk/inc/api-key.php

    r3249995 r3265363  
    304304    wplng_clear_translations_cache();
    305305    wplng_clear_slugs_cache();
    306 
    307 }
     306}
  • wplingua/trunk/inc/args.php

    r3254383 r3265363  
    222222     */
    223223
    224      $args['count_texts'] = count( $texts );
     224    $args['count_texts'] = count( $texts );
    225225
    226226    /**
  • wplingua/trunk/inc/assets.php

    r3258836 r3265363  
    101101
    102102    }
    103 
    104103}
    105104
  • wplingua/trunk/inc/buffering.php

    r3258836 r3265363  
    8888
    8989    ob_start( 'wplng_ob_callback_page' );
    90 
    9190}
    9291
  • wplingua/trunk/inc/dictionary.php

    r3097678 r3265363  
    110110
    111111    usort(
    112         $entries_clear, function( $a, $b ) {
     112        $entries_clear,
     113        function ( $a, $b ) {
    113114            return strlen( $b['source'] ) - strlen( $a['source'] );
    114115        }
  • wplingua/trunk/inc/dom/exclusion-put-tags.php

    r3097678 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $excluded_elements
     13 * @param array  $excluded_elements
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/exclusion-replace-tags.php

    r3201266 r3265363  
    1414 *
    1515 * @param object $dom The DOM object to process.
    16  * @param array $excluded_elements An array of HTML parts to replace the exclusion tags.
     16 * @param array  $excluded_elements An array of HTML parts to replace the exclusion tags.
    1717 * @return object The modified DOM object.
    1818 */
     
    4848        }
    4949
    50         $counter++;
     50        ++$counter;
    5151    }
    5252
  • wplingua/trunk/inc/dom/load-progress.php

    r3145632 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/mode-editor.php

    r3145632 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/replace-attr-dir.php

    r3057068 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/replace-attr-lang.php

    r3145632 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/replace-body-class.php

    r3057068 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/replace-links.php

    r3251920 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
     
    6666            $element->attr['srcset'] = esc_attr( $url_link_media_applied );
    6767        }
    68 
    6968    }
    7069
  • wplingua/trunk/inc/dom/translate-attr-html.php

    r3251920 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/translate-attr-texts.php

    r3251920 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/translate-js.php

    r3227135 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/translate-json.php

    r3227135 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/dom/translate-node-texts.php

    r3251920 r3265363  
    1111 *
    1212 * @param object $dom
    13  * @param array $args
     13 * @param array  $args
    1414 * @return object
    1515 */
  • wplingua/trunk/inc/heartbeat.php

    r3258924 r3265363  
    1919    $deleted   = array();
    2020
     21    // Prevents frequent execution if the last heartbeat was within 10 minutes
    2122    if ( ! empty( $last_beat )
    2223        && ( $last_beat + ( MINUTE_IN_SECONDS * 10 ) ) > $now
     
    2627    }
    2728
     29    // Update last heartbeat timestamp
    2830    update_option( 'wplng_hb_last_update', $now );
    2931
     32    // Retrieve only post IDs for better performance
    3033    $args = array(
    3134        'post_type'              => 'wplng_translation',
     
    3538        'update_post_meta_cache' => false,
    3639        'cache_results'          => false,
     40        'fields'                 => 'ids', // Retrieve only post IDs
    3741    );
    3842
    39     $the_query = new WP_Query( $args );
     43    $post_ids = get_posts( $args );
    4044
    41     while ( $the_query->have_posts() ) {
     45    if ( empty( $post_ids ) ) {
     46        wp_send_json_success();
     47        return;
     48    }
     49
     50    foreach ( $post_ids as $id ) {
    4251
    4352        if ( $counter <= 0 ) {
     
    4554        }
    4655
    47         $the_query->the_post();
    48 
    49         $id   = get_the_ID();
    5056        $meta = get_post_meta( $id );
    5157
    52         if ( ! isset( $meta['wplng_translation_original'][0] )
     58        // Validate translation metadata
     59        if ( empty( $meta['wplng_translation_original'][0] )
    5360            || ! is_string( $meta['wplng_translation_original'][0] )
    54             || $meta['wplng_translation_original'][0] !== trim( $meta['wplng_translation_original'][0] )
     61            || trim( $meta['wplng_translation_original'][0] ) === ''
    5562            || empty( $meta['wplng_translation_translations'][0] )
    56             || ! isset( $meta['wplng_translation_md5'][0] )
     63            || empty( $meta['wplng_translation_md5'][0] )
    5764        ) {
    58             $counter--;
     65            --$counter;
    5966
    6067            $deleted[] = array(
    6168                'reason' => 'Invalid translation',
    62                 'title'  => get_the_title(),
     69                'title'  => get_the_title( $id ),
    6370                'id'     => $id,
    6471            );
    6572
     73            // Permanently delete the invalid translation
    6674            wp_delete_post( $id, true );
    6775        }
    6876    }
    6977
    70     wp_reset_postdata();
    71 
    72     /**
    73      * Print debug data in debug.log file
    74      */
    75 
     78    // Debug logging (if enabled)
    7679    if ( true === WPLNG_DEBUG_BEAT ) {
    77 
    7880        $debug = array(
    7981            'title'   => 'wpLingua HeartBeat debug',
     
    8284        );
    8385
    84         error_log(
    85             var_export(
    86                 $debug,
    87                 true
    88             )
    89         );
     86        error_log( var_export( $debug, true ) );
    9087    }
    9188
  • wplingua/trunk/inc/languages.php

    r3258836 r3265363  
    145145 * Get language name translated from language ID or data
    146146 *
    147  * @param mixed $language Language ID or data
     147 * @param mixed  $language Language ID or data
    148148 * @param string $language_target Language ID
    149149 * @return string Language name translated
     
    513513            $languages[] = wplng_get_language_by_id( $language_id_alow );
    514514        }
    515    
     515
    516516        $wplng_languages_allow = $languages;
    517517    }
  • wplingua/trunk/inc/link-media.php

    r3254383 r3265363  
    4242
    4343        $source_clear = esc_attr( $entry['source'] );
    44         $source_clear = str_replace( 
    45             '[WPLNG_BACKSLASH]', 
    46             '\\', 
    47             $source_clear 
     44        $source_clear = str_replace(
     45            '[WPLNG_BACKSLASH]',
     46            '\\',
     47            $source_clear
    4848        );
    4949
     
    125125
    126126    usort(
    127         $entries_clear, function( $a, $b ) {
     127        $entries_clear,
     128        function ( $a, $b ) {
    128129            return strlen( $b['source'] ) - strlen( $a['source'] );
    129130        }
  • wplingua/trunk/inc/parser/json.php

    r3251920 r3265363  
    1111 *
    1212 * @param string $json
    13  * @param array $parents
     13 * @param array  $parents
    1414 * @return array Texts
    1515 */
  • wplingua/trunk/inc/search.php

    r3094255 r3265363  
    8888     */
    8989
    90      $query->set( 's', $translated_search );
     90    $query->set( 's', $translated_search );
    9191}
    9292
  • wplingua/trunk/inc/shortcode.php

    r3251920 r3265363  
    1010 * wpLingua Shortcode : [wplng_notranslate]
    1111 *
    12  * @param array $atts
     12 * @param array  $atts
    1313 * @param string $content
    1414 * @return string
     
    2727 * wpLingua Shortcode : [wplng_only]
    2828 *
    29  * @param array $atts
     29 * @param array  $atts
    3030 * @param string $content
    3131 * @return string
     
    3939        array(
    4040            'lang' => false,
    41         ), $atts
     41        ),
     42        $atts
    4243    );
    4344
     
    7374    }
    7475
     76    $content = wp_kses_post( $content );
     77    $content = do_shortcode( $content );
     78
    7579    $html  = '<span class="notranslate">';
    76     $html .= wp_kses_post( do_shortcode( $content ) );
     80    $html .= $content;
    7781    $html .= '</span>';
    7882
     
    97101            'flags'  => false,
    98102            'class'  => false,
    99         ), $atts
     103        ),
     104        $atts
    100105    );
    101106
  • wplingua/trunk/inc/slug.php

    r3254383 r3265363  
    1010 * Get the original slug from a translation (without "/")
    1111 *
    12  * @param string $slug
    13  * @param string $language_id
     12 * @param string      $slug
     13 * @param string      $language_id
    1414 * @param array|false $slugs_translations
    1515 * @return array Original slug
     
    114114 * Get a translated slug
    115115 *
    116  * @param string $slug
    117  * @param string $language_id
     116 * @param string      $slug
     117 * @param string      $language_id
    118118 * @param array|false $slugs_translations
    119119 * @return string Translated slug
     
    372372
    373373    $slug_to_delete = array();
    374 
    375     $slugs = array();
    376     $args  = array(
     374    $slugs          = array();
     375    $args           = array(
    377376        'post_type'              => 'wplng_slug',
    378377        'posts_per_page'         => -1,
     
    381380        'update_post_meta_cache' => false,
    382381        'cache_results'          => false,
    383     );
    384 
    385     $the_query = new WP_Query( $args );
    386 
    387     while ( $the_query->have_posts() ) {
    388 
    389         $the_query->the_post();
    390 
    391         $slug_id = get_the_ID();
    392         $meta    = get_post_meta( $slug_id );
    393 
    394         /**
    395          * Check and clear source slug
    396          */
    397 
     382        'fields'                 => 'ids', // Only retrieve post IDs
     383    );
     384
     385    // Get all slug IDs
     386    $post_ids = get_posts( $args );
     387
     388    if ( empty( $post_ids ) ) {
     389        return $slugs;
     390    }
     391
     392    foreach ( $post_ids as $slug_id ) {
     393        $meta = get_post_meta( $slug_id );
     394
     395        // Check for valid source slug
    398396        if ( ! isset( $meta['wplng_slug_original'][0] )
    399397            || ! is_string( $meta['wplng_slug_original'][0] )
     
    404402        $source = sanitize_title( $meta['wplng_slug_original'][0] );
    405403
    406         if ( 'index-php' === $source
    407             || 'wp-includes' === $source
    408             || 'wp-json' === $source
    409             || 'go' === $source
    410             || 'refer' === $source
    411             || 'recommend' === $source
    412             || 'recommends' === $source
     404        // Skip unwanted slugs and mark them for deletion
     405        if ( in_array(
     406            $source,
     407            array(
     408                'index-php',
     409                'wp-includes',
     410                'wp-json',
     411                'go',
     412                'refer',
     413                'recommend',
     414                'recommends',
     415            ),
     416            true
     417        )
    413418        ) {
    414419            $slug_to_delete[] = $slug_id;
     
    416421        }
    417422
    418         /**
    419          * Check and clear slug translations, setup review array
    420          */
    421 
     423        // Check for translations and build translation array
    422424        if ( empty( $meta['wplng_slug_translations'][0] ) ) {
    423425            continue;
    424426        }
    425427
    426         $translations_meta = json_decode(
    427             $meta['wplng_slug_translations'][0],
    428             true
    429         );
    430 
    431         $translations = array();
     428        $translations      = array();
     429        $translations_meta = json_decode( $meta['wplng_slug_translations'][0], true );
     430
     431        if ( ! is_array( $translations_meta ) ) {
     432            continue;
     433        }
    432434
    433435        foreach ( $translations_meta as $translation_meta ) {
    434436
    435             /**
    436              * Language ID
    437              */
    438 
     437            // Validate language ID
    439438            if ( empty( $translation_meta['language_id'] )
    440439                || ! wplng_is_valid_language_id( $translation_meta['language_id'] )
     
    445444            $language_id = sanitize_key( $translation_meta['language_id'] );
    446445
    447             /**
    448              * Slug translation
    449              */
    450 
     446            // Check and validate slug translation
    451447            if ( empty( $translation_meta['translation'] )
    452448                || ! is_string( $translation_meta['translation'] )
     
    457453            }
    458454
    459             $translation = sanitize_title( $translation_meta['translation'] );
    460 
    461             $translations[ $language_id ] = $translation;
    462         }
    463 
     455            // Sanitize and add valid translation
     456            $translations[ $language_id ] = sanitize_title( $translation_meta['translation'] );
     457        }
     458
     459        // Add source and translations to slugs array
    464460        $slugs[] = array(
    465461            'source'       => $source,
    466462            'translations' => $translations,
    467463        );
    468 
    469     }
    470 
    471     wp_reset_postdata();
    472 
     464    }
     465
     466    // Delete invalid slugs, limit to 32 deletions
    473467    if ( ! empty( $slug_to_delete ) ) {
    474         foreach ( $slug_to_delete as $key => $id ) {
    475             if ( $key >= 32 ) {
    476                 break;
    477             }
     468
     469        foreach ( array_slice( $slug_to_delete, 0, 32 ) as $id ) {
    478470            wp_delete_post( $id, true );
    479471        }
    480         set_transient(
    481             'wplng_cached_slugs',
    482             $slugs,
    483             30
    484         );
     472
     473        // Cache slugs for 30 seconds after deletion
     474        set_transient( 'wplng_cached_slugs', $slugs, 30 );
     475
    485476    } else {
    486         set_transient(
    487             'wplng_cached_slugs',
    488             $slugs,
    489             MONTH_IN_SECONDS
    490         );
     477        // Cache slugs for a month if no deletions occurred
     478        set_transient( 'wplng_cached_slugs', $slugs, MONTH_IN_SECONDS );
    491479    }
    492480
     
    551539function wplng_get_slug_saved_from_original( $original ) {
    552540
    553     $translation = false;
    554     $original    = trim( strtolower( $original ) );
     541    $original = trim( strtolower( $original ) );
     542
     543    if ( empty( $original ) ) {
     544        return false;
     545    }
    555546
    556547    $args = array(
     
    564555            ),
    565556        ),
    566     );
    567 
    568     $the_query = new WP_Query( $args );
    569 
    570     // The Loop
    571     while ( $the_query->have_posts() ) {
    572 
    573         $the_query->the_post();
    574 
    575         $meta = get_post_meta( get_the_ID() );
    576 
    577         if ( ! isset( $meta['wplng_slug_original'][0] )
    578             || ! is_string( $meta['wplng_slug_original'][0] )
     557        'fields'         => 'ids',
     558    );
     559
     560    $posts = get_posts( $args );
     561
     562    if ( empty( $posts ) ) {
     563        return false;
     564    }
     565
     566    foreach ( $posts as $post_id ) {
     567
     568        $meta = get_post_meta( $post_id );
     569
     570        if ( isset( $meta['wplng_slug_original'][0] )
     571            && is_string( $meta['wplng_slug_original'][0] )
     572            && $meta['wplng_slug_original'][0] === $original
    579573        ) {
    580             continue;
    581         }
    582 
    583         if ( $meta['wplng_slug_original'][0] === $original ) {
    584             $translation = get_post();
    585             break;
    586         }
    587     }
    588 
    589     wp_reset_postdata();
    590 
    591     return $translation;
     574            return get_post( $post_id );
     575        }
     576    }
     577
     578    return false;
    592579}
    593580
  • wplingua/trunk/inc/switcher-nav-menu.php

    r3262485 r3265363  
    6969        ),
    7070    );
    71 
    7271}
    7372
     
    277276            $new_items[] = $new_item;
    278277
    279             $offset++;
     278            ++$offset;
    280279        }
    281280
     
    355354            $new_items[] = $new_item;
    356355
    357             $offset++;
     356            ++$offset;
    358357        }
    359358    } // End foreach $items
     
    366365 * Add attribute in nav menu switcher
    367366 *
    368  * @param array $atts
     367 * @param array   $atts
    369368 * @param WP_Post $menu_item
    370369 * @return array
  • wplingua/trunk/inc/translation.php

    r3258924 r3265363  
    1111 *
    1212 * @param string $text
    13  * @param array $translations
     13 * @param array  $translations
    1414 * @return string
    1515 */
     
    6868function wplng_get_translation_saved_from_original( $original ) {
    6969
    70     $translation = false;
     70    if ( empty( $original ) ) {
     71        return false;
     72    }
    7173
    7274    $args = array(
     
    8082            ),
    8183        ),
    82     );
    83 
    84     $the_query = new WP_Query( $args );
    85 
    86     // The Loop
    87     while ( $the_query->have_posts() ) {
    88 
    89         $the_query->the_post();
    90 
    91         $meta = get_post_meta( get_the_ID() );
    92 
    93         if ( ! isset( $meta['wplng_translation_original'][0] )
    94             || ! is_string( $meta['wplng_translation_original'][0] )
     84        'fields'         => 'ids',
     85    );
     86
     87    $posts = get_posts( $args );
     88
     89    if ( empty( $posts ) ) {
     90        return false;
     91    }
     92
     93    foreach ( $posts as $post_id ) {
     94
     95        $meta = get_post_meta( $post_id );
     96
     97        if ( isset( $meta['wplng_translation_original'][0] )
     98            && is_string( $meta['wplng_translation_original'][0] )
     99            && $meta['wplng_translation_original'][0] === $original
    95100        ) {
    96             continue;
    97         }
    98 
    99         if ( $meta['wplng_translation_original'][0] === $original ) {
    100             $translation = get_post();
    101             break;
    102         }
    103     }
    104 
    105     wp_reset_postdata();
    106 
    107     return $translation;
     101            return get_post( $post_id );
     102        }
     103    }
     104
     105    return false;
    108106}
    109107
     
    117115
    118116    $translations = array();
    119     $args         = array(
     117
     118    $args = array(
    120119        'post_type'              => 'wplng_translation',
    121120        'posts_per_page'         => -1,
     
    124123        'update_post_meta_cache' => false,
    125124        'cache_results'          => false,
    126     );
    127 
    128     $the_query = new WP_Query( $args );
    129 
    130     while ( $the_query->have_posts() ) {
    131 
    132         $the_query->the_post();
    133 
    134         $id   = get_the_ID();
     125        'fields'                 => 'ids', // Retrieve only post IDs for better performance
     126    );
     127
     128    $post_ids = get_posts( $args );
     129
     130    if ( empty( $post_ids ) ) {
     131        return array();
     132    }
     133
     134    foreach ( $post_ids as $id ) {
     135
    135136        $meta = get_post_meta( $id );
    136137
    137         if ( ! isset( $meta['wplng_translation_original'][0] )
     138        // Ensure 'wplng_translation_original' exists and is a valid string
     139        if ( empty( $meta['wplng_translation_original'][0] )
    138140            || ! is_string( $meta['wplng_translation_original'][0] )
    139             || $meta['wplng_translation_original'][0] !== trim( $meta['wplng_translation_original'][0] )
     141            || trim( $meta['wplng_translation_original'][0] ) === ''
    140142        ) {
    141143            continue;
    142144        }
    143145
    144         $source = wplng_text_esc( $meta['wplng_translation_original'][0] );
     146        $source = wplng_text_esc( trim( $meta['wplng_translation_original'][0] ) );
    145147
    146148        $translation = array(
     
    151153        );
    152154
    153         // Get translation for current language target
     155        // Ensure 'wplng_translation_translations' exists
    154156        if ( empty( $meta['wplng_translation_translations'][0] ) ) {
    155157            continue;
    156158        }
    157159
    158         $translations_meta = json_decode(
    159             $meta['wplng_translation_translations'][0],
    160             true
    161         );
     160        $translations_meta = json_decode( $meta['wplng_translation_translations'][0], true );
     161
     162        // Ensure JSON decoding was successful
     163        if ( ! is_array( $translations_meta ) ) {
     164            continue;
     165        }
    162166
    163167        foreach ( $translations_meta as $translation_meta ) {
    164 
     168            // Validate each translation entry
    165169            if ( empty( $translation_meta['language_id'] )
    166170                || ! wplng_is_valid_language_id( $translation_meta['language_id'] )
    167                 || $translation_meta['translation'] === '[WPLNG_EMPTY]'
     171                || (
     172                    isset( $translation_meta['translation'] )
     173                    && $translation_meta['translation'] === '[WPLNG_EMPTY]'
     174                )
    168175            ) {
    169176                continue;
     
    180187            }
    181188
    182             if ( isset( $translation_meta['status'] ) && is_int( $translation_meta['status'] ) ) {
     189            if ( isset( $translation_meta['status'] )
     190                && is_int( $translation_meta['status'] )
     191            ) {
    183192                $translation['review'][] = $language_id;
    184193            }
    185194        }
    186195
     196        // Skip entries with no valid translations
    187197        if ( empty( $translation['translations'] ) ) {
    188198            continue;
     
    192202    }
    193203
    194     wp_reset_postdata();
    195 
     204    // Cache translations for better performance
    196205    set_transient(
    197206        'wplng_cached_translations',
     
    202211    return $translations;
    203212}
     213
    204214
    205215
     
    261271 * @param string $language_id
    262272 * @param string $original
    263  * @param array $translation
     273 * @param array  $translation
    264274 * @return int|false Post ID or false on failure
    265275 */
     
    457467 * @param object $post
    458468 * @param string $language_id
    459  * @param array $translation
     469 * @param array  $translation
    460470 * @return int|false Post ID, false on failure
    461471 */
     
    589599 * Save a list of translations
    590600 *
    591  * @param array $translations
     601 * @param array  $translations
    592602 * @param string $language_target_id
    593603 * @return array $translations with post IDs
     
    627637 * @param string $target_language_id
    628638 * @param string $original
    629  * @param array $translation
     639 * @param array  $translation
    630640 * @return array $translation with post ID
    631641 */
     
    653663        wplng_clear_translations_cache();
    654664    }
    655 
    656665}
    657666
  • wplingua/trunk/inc/translator/html.php

    r3251920 r3265363  
    1111 *
    1212 * @param string $html
    13  * @param array $args
     13 * @param array  $args
    1414 * @return string
    1515 */
  • wplingua/trunk/inc/translator/js.php

    r3225204 r3265363  
    1414 *
    1515 * @param string $js The JavaScript code to translate.
    16  * @param array $args Additional arguments for translation processing.
     16 * @param array  $args Additional arguments for translation processing.
    1717 * @return string The translated JavaScript code.
    1818 */
  • wplingua/trunk/inc/translator/json.php

    r3258836 r3265363  
    1111 *
    1212 * @param string $json
    13  * @param array $args
     13 * @param array  $args
    1414 * @return string
    1515 */
     
    191191
    192192                $debug_type      = 'String - JSON';
    193                 $args['parents'] = array_merge( $args['parents'], [ $key ] );
     193                $args['parents'] = array_merge( $args['parents'], array( $key ) );
    194194
    195195                $array_translated[ $key ] = wplng_translate_json(
  • wplingua/trunk/inc/url.php

    r3254383 r3265363  
    150150    return apply_filters(
    151151        'wplng_url_is_translatable',
    152         wplng_url_is_translatable_no_filter( $url )
     152        wplng_url_is_translatable_no_filter( $url ),
     153        $url
    153154    );
    154155}
  • wplingua/trunk/inc/util.php

    r3258845 r3265363  
    234234 *
    235235 * @param string $element
    236  * @param array $parents
     236 * @param array  $parents
    237237 * @return bool
    238238 */
     
    297297             */
    298298
    299              $is_translatable = true;
     299            $is_translatable = true;
    300300
    301301        } elseif (
  • wplingua/trunk/loader.php

    r3262485 r3265363  
    1010 */
    1111
    12  // Require data functions
     12// Require data functions
    1313require_once WPLNG_PLUGIN_PATH . '/data.php';
    1414
  • wplingua/trunk/readme.txt

    r3262485 r3265363  
    55Requires at least: 6.0
    66Tested up to: 6.7
    7 Stable tag: 2.5.3
     7Stable tag: 2.5.4
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    191191
    192192== Changelog ==
     193
     194= 2.5.4 =
     195
     196* Better admin UX
     197* Better shortcode: wplng_only
     198* Better hook: wplng_url_is_translatable filter
     199* Review and optimize the queries (slug and translation)
     200* Re-format all code with better formater
    193201
    194202= 2.5.3 =
  • wplingua/trunk/wplingua.php

    r3262485 r3265363  
    88 * Text Domain: wplingua
    99 * Domain Path: /languages/
    10  * Version: 2.5.3
     10 * Version: 2.5.4
    1111 * Requires PHP: 7.4
    1212 * License: GPL v2 or later
     
    2525define( 'WPLNG_API_VERSION', '2.0' );
    2626define( 'WPLNG_API_SSLVERIFY', true );
    27 define( 'WPLNG_PLUGIN_VERSION', '2.5.3' );
     27define( 'WPLNG_PLUGIN_VERSION', '2.5.4' );
    2828define( 'WPLNG_PLUGIN_FILE', plugin_basename( __FILE__ ) );
    29 define( 'WPLNG_PLUGIN_PATH', dirname( __FILE__ ) );
     29define( 'WPLNG_PLUGIN_PATH', __DIR__ );
    3030define( 'WPLNG_PHP_MIN_VERSION', '7.4' );
    3131define( 'WPLNG_MAX_TRANSLATIONS', 256 );
     
    287287         */
    288288
    289          // Manage URL with REQUEST_URI and start OB
     289        // Manage URL with REQUEST_URI and start OB
    290290        add_action( 'init', 'wplng_ob_start', 1 );
    291291
     
    323323
    324324    }
    325 
    326325}
    327326wplng_start();
Note: See TracChangeset for help on using the changeset viewer.