Plugin Directory

Changeset 3098877


Ignore:
Timestamp:
06/06/2024 06:15:11 PM (22 months ago)
Author:
seojacky
Message:

Update to version 1.5 from GitHub

Location:
wpglobus-multilingual-comments
Files:
9 added
2 deleted
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wpglobus-multilingual-comments/tags/1.5/readme.txt

    r3086829 r3098877  
    55Tested up to: 6.5
    66Requires PHP: 7.4
    7 Stable tag: 1.4
     7Stable tag: 1.5
    88License: GPL-3.0-or-later
    99License URI: https://spdx.org/licenses/GPL-3.0-or-later.html
     
    3232== Frequently Asked Questions ==
    3333
    34 = What languages does this WordPress plugin support? =
    35 Unfortunately, it currently supports multilingual comments only for English and Russian.
     34= What does the Multilingual Comments for WPGlobus plugin do?
     35The Multilingual Comments for WPGlobus plugin allows you to create multilingual comments using the WPGlobus plugin. It filters comments based on the language of the current post, adds a language selection field to the comment form, and allows bulk editing of comment languages in the admin panel.
    3636
    37 = How to extend language support in this plugin? =
    38 Contact this [plugin's support](https://wordpress.org/support/plugin/wpglobus-multilingual-comments/).
     37= How do I add a language to a comment?
     38When a user leaves a comment, the plugin automatically adds a hidden field with the current post's language. This language is saved with the comment.
     39
     40= How do I filter comments by language?
     41The plugin automatically filters comments based on the current post's language. You will only see comments that match the post's language.
     42
     43= How do I bulk change the language of comments?
     44In the WordPress admin panel, go to the "Comments" section. Select the comments you want to edit, and in the bulk actions menu, choose the desired language (e.g., "Assign en" or "Assign ru"). The plugin will automatically change the language of the selected comments.
     45
     46= Does the plugin support other multilingual plugins?
     47The Multilingual Comments for WPGlobus plugin is designed only to work with WPGlobus.
     48
    3949
    4050== Changelog ==
     51= 1.5 - 06.06.2024 =
     52* Changed Description
     53* Expanded language support
     54* Checked WordPress Security Standards
     55
    4156= 1.4 - 15.05.2024 =
    4257* Changed Description
  • wpglobus-multilingual-comments/tags/1.5/wpglobus-multilingual-comments.php

    r3086829 r3098877  
    33 * Plugin Name: Multilingual Comments for WPGlobus
    44 * Description: Multilingual Comments for WPGlobus - an unofficial plugin for creating multilingual comments using the WPGlobus plugin.
    5  * Version: 1.4
     5 * Version: 1.5
    66 * Author: seojacky
    77 * Author URI: https://t.me/big_jacky
     
    1212 * Text Domain: wpglobus-multilingual-comments
    1313 * Domain Path: /languages
    14 */
     14 */
    1515
    1616if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1717
     18// Load plugin text domain for translations
     19function wpglobus_multilingual_comments_load_textdomain() {
     20    load_plugin_textdomain( 'wpglobus-multilingual-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     21}
     22add_action( 'plugins_loaded', 'wpglobus_multilingual_comments_load_textdomain' );
     23
    1824// Function for filtering comments based on the language of the current post
    1925function comment_language_filter_comments_by_post_language($comments) {
    20     // Get the language of the current post
    21     $post_language = get_locale() === 'ru_RU' ? 'ru_RU' : 'en_US';
     26    // Get the language of the current post   
     27    $post_language = WPGlobus::Config()->language;
    2228
    2329    // Filter comments by the language of the current post
     
    2935    return $filtered_comments;
    3036}
    31 
    32 // Переопределяем функцию, отвечающую за вывод комментариев
    3337add_filter('comments_array', 'comment_language_filter_comments_by_post_language', 10, 2);
    3438
    35 // Override the function responsible for displaying comments
    36 add_filter('comment_form_default_fields', function($fields) {
    37     // Получаем текущий язык
    38     $current_language = get_locale();
     39// Add language selection field to the comment form
     40function comment_language_add_language_field($fields) {
     41    // Get the current language
     42    $current_language = WPGlobus::Config()->language;
    3943
    4044    // Add language selection field if language is defined
    4145    if (!empty($current_language)) {
    4246        $fields['comment_language'] = '<p class="comment-form-language" style="display:none"><label for="comment_language">' . esc_html__('Language', 'wpglobus-multilingual-comments') . '</label>' .
    43             '<select id="comment_language" name="comment_language">' .
    44             '<option value="' . esc_attr($current_language) . '" selected>' . esc_html($current_language) . '</option>' .
    45             '</select></p>';
     47            '<input id="comment_language" name="comment_language" type="hidden" value="' . esc_attr($current_language) . '">' .
     48            wp_nonce_field('save_comment_language', 'comment_language_nonce', true, false) . // Add nonce field
     49            '</p>';
    4650    }
    4751
    4852    return $fields;
    49 }, 20);
     53}
     54add_filter('comment_form_default_fields', 'comment_language_add_language_field', 20);
    5055
    5156// Save the selected language when sending a comment
    52 // Add nonce field to the comment form
    53 
     57function comment_language_save_comment_meta($comment_id) {
     58    if (isset($_POST['comment_language_nonce']) && wp_verify_nonce($_POST['comment_language_nonce'], 'save_comment_language')) {
     59        if (isset($_POST['comment_language'])) {
     60            $comment_language = sanitize_text_field($_POST['comment_language']);
     61            add_comment_meta($comment_id, 'comment_language', $comment_language, true);
     62        }
     63    }
     64}
     65add_action('comment_post', 'comment_language_save_comment_meta');
    5466
    5567// Add the "Language" column to the comments admin panel
    56 add_filter('manage_edit-comments_columns', 'comment_language_add_language_column');
    5768function comment_language_add_language_column($columns) {
    5869    $columns['language'] = __('Language', 'wpglobus-multilingual-comments');
    5970    return $columns;
    6071}
     72add_filter('manage_edit-comments_columns', 'comment_language_add_language_column');
    6173
    6274// Output the language data in the "Language" column
    63 add_action('manage_comments_custom_column', 'comment_language_display_language_column_data', 10, 2);
    6475function comment_language_display_language_column_data($column, $comment_id) {
    6576    if ($column === 'language') {
     
    7384    }
    7485}
     86add_action('manage_comments_custom_column', 'comment_language_display_language_column_data', 10, 2);
    7587
    7688// Add actions for mass editing of comments
    77 add_filter('bulk_actions-edit-comments', 'comment_language_add_language_bulk_actions');
    7889function comment_language_add_language_bulk_actions($actions) {
    79     $actions['assign_en_US'] = __('Assign en_US', 'wpglobus-multilingual-comments');
    80     $actions['assign_ru_RU'] = __('Assign ru_RU', 'wpglobus-multilingual-comments');
     90    $languages = WPGlobus::Config()->enabled_languages;
     91    foreach ($languages as $language) {
     92        $assign = esc_html__('Assign', 'wpglobus-multilingual-comments') . ' ' . strtoupper($language);
     93        $actions['assign_' . $language] = $assign;
     94    }
    8195    return $actions;
    8296}
     97add_filter('bulk_actions-edit-comments', 'comment_language_add_language_bulk_actions');
    8398
    8499// Handling actions for bulk editing of comments
    85 add_filter('handle_bulk_actions-edit-comments', 'comment_language_handle_language_bulk_actions', 10, 3);
    86100function comment_language_handle_language_bulk_actions($redirect_to, $action, $comment_ids) {
    87     if ($action == 'assign_en_US' || $action == 'assign_ru_RU') {
    88         $language = str_replace('assign_', '', $action);
    89         foreach ($comment_ids as $comment_id) {
    90             update_comment_meta($comment_id, 'comment_language', $language);
     101    $languages = WPGlobus::Config()->enabled_languages;
     102    foreach ($languages as $language) {
     103        if ($action == 'assign_' . $language) {
     104            foreach ($comment_ids as $comment_id) {
     105                update_comment_meta($comment_id, 'comment_language', $language);
     106            }
     107            $redirect_to = add_query_arg('bulk_language_updated', count($comment_ids), $redirect_to);
     108            break;
    91109        }
    92         $redirect_to = add_query_arg('bulk_language_updated', count($comment_ids), $redirect_to);
    93110    }
    94111    return $redirect_to;
    95112}
     113add_filter('handle_bulk_actions-edit-comments', 'comment_language_handle_language_bulk_actions', 10, 3);
     114?>
  • wpglobus-multilingual-comments/trunk/readme.txt

    r3086829 r3098877  
    55Tested up to: 6.5
    66Requires PHP: 7.4
    7 Stable tag: 1.4
     7Stable tag: 1.5
    88License: GPL-3.0-or-later
    99License URI: https://spdx.org/licenses/GPL-3.0-or-later.html
     
    3232== Frequently Asked Questions ==
    3333
    34 = What languages does this WordPress plugin support? =
    35 Unfortunately, it currently supports multilingual comments only for English and Russian.
     34= What does the Multilingual Comments for WPGlobus plugin do?
     35The Multilingual Comments for WPGlobus plugin allows you to create multilingual comments using the WPGlobus plugin. It filters comments based on the language of the current post, adds a language selection field to the comment form, and allows bulk editing of comment languages in the admin panel.
    3636
    37 = How to extend language support in this plugin? =
    38 Contact this [plugin's support](https://wordpress.org/support/plugin/wpglobus-multilingual-comments/).
     37= How do I add a language to a comment?
     38When a user leaves a comment, the plugin automatically adds a hidden field with the current post's language. This language is saved with the comment.
     39
     40= How do I filter comments by language?
     41The plugin automatically filters comments based on the current post's language. You will only see comments that match the post's language.
     42
     43= How do I bulk change the language of comments?
     44In the WordPress admin panel, go to the "Comments" section. Select the comments you want to edit, and in the bulk actions menu, choose the desired language (e.g., "Assign en" or "Assign ru"). The plugin will automatically change the language of the selected comments.
     45
     46= Does the plugin support other multilingual plugins?
     47The Multilingual Comments for WPGlobus plugin is designed only to work with WPGlobus.
     48
    3949
    4050== Changelog ==
     51= 1.5 - 06.06.2024 =
     52* Changed Description
     53* Expanded language support
     54* Checked WordPress Security Standards
     55
    4156= 1.4 - 15.05.2024 =
    4257* Changed Description
  • wpglobus-multilingual-comments/trunk/wpglobus-multilingual-comments.php

    r3086829 r3098877  
    33 * Plugin Name: Multilingual Comments for WPGlobus
    44 * Description: Multilingual Comments for WPGlobus - an unofficial plugin for creating multilingual comments using the WPGlobus plugin.
    5  * Version: 1.4
     5 * Version: 1.5
    66 * Author: seojacky
    77 * Author URI: https://t.me/big_jacky
     
    1212 * Text Domain: wpglobus-multilingual-comments
    1313 * Domain Path: /languages
    14 */
     14 */
    1515
    1616if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1717
     18// Load plugin text domain for translations
     19function wpglobus_multilingual_comments_load_textdomain() {
     20    load_plugin_textdomain( 'wpglobus-multilingual-comments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     21}
     22add_action( 'plugins_loaded', 'wpglobus_multilingual_comments_load_textdomain' );
     23
    1824// Function for filtering comments based on the language of the current post
    1925function comment_language_filter_comments_by_post_language($comments) {
    20     // Get the language of the current post
    21     $post_language = get_locale() === 'ru_RU' ? 'ru_RU' : 'en_US';
     26    // Get the language of the current post   
     27    $post_language = WPGlobus::Config()->language;
    2228
    2329    // Filter comments by the language of the current post
     
    2935    return $filtered_comments;
    3036}
    31 
    32 // Переопределяем функцию, отвечающую за вывод комментариев
    3337add_filter('comments_array', 'comment_language_filter_comments_by_post_language', 10, 2);
    3438
    35 // Override the function responsible for displaying comments
    36 add_filter('comment_form_default_fields', function($fields) {
    37     // Получаем текущий язык
    38     $current_language = get_locale();
     39// Add language selection field to the comment form
     40function comment_language_add_language_field($fields) {
     41    // Get the current language
     42    $current_language = WPGlobus::Config()->language;
    3943
    4044    // Add language selection field if language is defined
    4145    if (!empty($current_language)) {
    4246        $fields['comment_language'] = '<p class="comment-form-language" style="display:none"><label for="comment_language">' . esc_html__('Language', 'wpglobus-multilingual-comments') . '</label>' .
    43             '<select id="comment_language" name="comment_language">' .
    44             '<option value="' . esc_attr($current_language) . '" selected>' . esc_html($current_language) . '</option>' .
    45             '</select></p>';
     47            '<input id="comment_language" name="comment_language" type="hidden" value="' . esc_attr($current_language) . '">' .
     48            wp_nonce_field('save_comment_language', 'comment_language_nonce', true, false) . // Add nonce field
     49            '</p>';
    4650    }
    4751
    4852    return $fields;
    49 }, 20);
     53}
     54add_filter('comment_form_default_fields', 'comment_language_add_language_field', 20);
    5055
    5156// Save the selected language when sending a comment
    52 // Add nonce field to the comment form
    53 
     57function comment_language_save_comment_meta($comment_id) {
     58    if (isset($_POST['comment_language_nonce']) && wp_verify_nonce($_POST['comment_language_nonce'], 'save_comment_language')) {
     59        if (isset($_POST['comment_language'])) {
     60            $comment_language = sanitize_text_field($_POST['comment_language']);
     61            add_comment_meta($comment_id, 'comment_language', $comment_language, true);
     62        }
     63    }
     64}
     65add_action('comment_post', 'comment_language_save_comment_meta');
    5466
    5567// Add the "Language" column to the comments admin panel
    56 add_filter('manage_edit-comments_columns', 'comment_language_add_language_column');
    5768function comment_language_add_language_column($columns) {
    5869    $columns['language'] = __('Language', 'wpglobus-multilingual-comments');
    5970    return $columns;
    6071}
     72add_filter('manage_edit-comments_columns', 'comment_language_add_language_column');
    6173
    6274// Output the language data in the "Language" column
    63 add_action('manage_comments_custom_column', 'comment_language_display_language_column_data', 10, 2);
    6475function comment_language_display_language_column_data($column, $comment_id) {
    6576    if ($column === 'language') {
     
    7384    }
    7485}
     86add_action('manage_comments_custom_column', 'comment_language_display_language_column_data', 10, 2);
    7587
    7688// Add actions for mass editing of comments
    77 add_filter('bulk_actions-edit-comments', 'comment_language_add_language_bulk_actions');
    7889function comment_language_add_language_bulk_actions($actions) {
    79     $actions['assign_en_US'] = __('Assign en_US', 'wpglobus-multilingual-comments');
    80     $actions['assign_ru_RU'] = __('Assign ru_RU', 'wpglobus-multilingual-comments');
     90    $languages = WPGlobus::Config()->enabled_languages;
     91    foreach ($languages as $language) {
     92        $assign = esc_html__('Assign', 'wpglobus-multilingual-comments') . ' ' . strtoupper($language);
     93        $actions['assign_' . $language] = $assign;
     94    }
    8195    return $actions;
    8296}
     97add_filter('bulk_actions-edit-comments', 'comment_language_add_language_bulk_actions');
    8398
    8499// Handling actions for bulk editing of comments
    85 add_filter('handle_bulk_actions-edit-comments', 'comment_language_handle_language_bulk_actions', 10, 3);
    86100function comment_language_handle_language_bulk_actions($redirect_to, $action, $comment_ids) {
    87     if ($action == 'assign_en_US' || $action == 'assign_ru_RU') {
    88         $language = str_replace('assign_', '', $action);
    89         foreach ($comment_ids as $comment_id) {
    90             update_comment_meta($comment_id, 'comment_language', $language);
     101    $languages = WPGlobus::Config()->enabled_languages;
     102    foreach ($languages as $language) {
     103        if ($action == 'assign_' . $language) {
     104            foreach ($comment_ids as $comment_id) {
     105                update_comment_meta($comment_id, 'comment_language', $language);
     106            }
     107            $redirect_to = add_query_arg('bulk_language_updated', count($comment_ids), $redirect_to);
     108            break;
    91109        }
    92         $redirect_to = add_query_arg('bulk_language_updated', count($comment_ids), $redirect_to);
    93110    }
    94111    return $redirect_to;
    95112}
     113add_filter('handle_bulk_actions-edit-comments', 'comment_language_handle_language_bulk_actions', 10, 3);
     114?>
Note: See TracChangeset for help on using the changeset viewer.