Plugin Directory

Changeset 3450961


Ignore:
Timestamp:
01/31/2026 11:25:36 AM (2 months ago)
Author:
solankisoftware
Message:

v-2.9 :: Fix AJAX ratio bar instant updates for post and comment like/dislike, improve copy posts button design, and resolve shortcode bugs

Location:
like-dislike-posts-products
Files:
26 added
7 edited

Legend:

Unmodified
Added
Removed
  • like-dislike-posts-products/trunk/assets/css/styles.css

    r3437177 r3450961  
    256256}
    257257.ldppp_ratings_ratio_percent {
    258   width: 40px;
     258  width: 50px;
    259259  text-align: left;
    260260  color: #555;
     
    366366}
    367367
     368.ldppp-copy-posts-wrapper {
     369    display: grid;
     370}
  • like-dislike-posts-products/trunk/assets/js/scripts.js

    r3406209 r3450961  
    158158        }
    159159
    160         // Update ratio bar
     160        // Update ratio bar inside the main wrapper
    161161        const wrapper = jQuery('#ldppp_AjaxLike').closest('.ldppp_like-dislike');
    162162        ldppp_update_ratio_bar(like, dislike, wrapper);
     163
     164        // Also update any standalone ratio bar shortcodes for this post
     165        const postId = jQuery('#ldppp_AjaxLike').data('id');
     166        if (postId) {
     167            jQuery('.ldppp_ratio_bar[data-postid="' + postId + '"]').each(function () {
     168                ldppp_update_ratio_bar(like, dislike, jQuery(this));
     169            });
     170        }
    163171    }
    164172
     
    186194            const ratings = jQuery(this).val();
    187195            const postID = jQuery(this).attr('data-id');
     196            const $rateContainer = jQuery(this).closest('.ldppp_rate');
     197            console.log('Rating clicked (ldppp_start_rates) - postID:', postID, 'rating:', ratings);
    188198
    189199            jQuery.ajax({
     
    198208                },
    199209                success: function(response) {
     210                    console.log('AJAX response received:', response);
     211                   
    200212                    const value = jQuery('#ldppp_star' + response.ratings + '').val();
    201213                    jQuery("input[name='ldppp_start_rates']").next().removeClass('ldppp_rated_class');
     
    203215                    jQuery('#ldppp_totalratings').text('(' + response.totalratings + ')');
    204216                    jQuery('#ldppp_avgratings').text(response.avg_ratings + '/5');
     217
     218                    // Update the ratings ratio wrapper instantly
     219                    if (response.rating_counts && response.total_votes) {
     220                        console.log('Updating ratings wrapper');
     221                        ldppp_update_ratings_ratio_wrapper(response.rating_counts, $rateContainer);
     222                    } else {
     223                        console.log('Missing rating_counts or total_votes:', response);
     224                    }
     225                },
     226                error: function(xhr, status, error) {
     227                    console.error('Rating update failed:', error, xhr);
    205228                }
    206229            });
     
    215238            const id = jQuery(this).attr('id').replace(/[^0-9]/gi, '');
    216239            const f_id = parseInt(id, 10);
     240            const $rateContainer = jQuery(this).closest('.ldppp_rate');
     241            console.log('Rating clicked (ldppp_check_id/shop) - postID:', postID, 'rating:', ratings);
    217242
    218243            jQuery.ajax({
     
    227252                },
    228253                success: function(response) {
     254                    console.log('AJAX response received (shop):', response);
     255                   
    229256                    jQuery('.' + newStr).children().removeClass('ldppp_rated_class');
    230257                    jQuery('#ldppp_star' + f_id + '').next().addClass('ldppp_rated_class');
    231258                    jQuery('#ldppp_totalratings' + postID).text('(' + response.totalratings + ')');
    232259                    jQuery('#ldppp_avgratings' + postID).text(response.avg_ratings + '/5');
    233                 }
    234             });
    235         });
     260
     261                    // Update the ratings ratio wrapper instantly
     262                    if (response.rating_counts && response.total_votes) {
     263                        console.log('Updating ratings wrapper (shop)');
     264                        ldppp_update_ratings_ratio_wrapper(response.rating_counts, $rateContainer);
     265                    } else {
     266                        console.log('Missing rating_counts or total_votes (shop):', response);
     267                    }
     268                },
     269                error: function(xhr, status, error) {
     270                    console.error('Rating update failed (shop):', error, xhr);
     271                }
     272            });
     273        });
     274    }
     275
     276    /**
     277     * Update ratings ratio wrapper with new distribution
     278     */
     279    function ldppp_update_ratings_ratio_wrapper(rating_counts, $rateContainer) {
     280        console.log('ldppp_update_ratings_ratio_wrapper called with:', rating_counts, '$rateContainer:', $rateContainer);
     281       
     282        // Try to find the closest ldppp_post_align_center wrapper (used in posts)
     283        let $wrapper = $rateContainer.closest('.ldppp_post_align_center');
     284        let $ratioWrapper = null;
     285
     286        if ($wrapper.length) {
     287            // For posts in functions.php - wrapper exists
     288            console.log('Found post wrapper (ldppp_post_align_center)');
     289            $ratioWrapper = $wrapper.next('.ldppp_ratings_ratio_wrapper');
     290        } else {
     291            // For products in single_page.php and shop_achieve.php - no wrapper
     292            // Look for the next sibling or find it after the avgratings wrapper
     293            console.log('No post wrapper found, looking for product wrapper');
     294            $ratioWrapper = $rateContainer.nextAll('.ldppp_ratings_ratio_wrapper').first();
     295           
     296            // If not found, try looking after the avgratings_totalratings_wrapper
     297            if (!$ratioWrapper.length) {
     298                const $avgWrapper = $rateContainer.nextAll('.ldppp_avgratings_totalratings_wrapper').first();
     299                console.log('Checked avgratings wrapper, found:', $avgWrapper.length);
     300                if ($avgWrapper.length) {
     301                    $ratioWrapper = $avgWrapper.nextAll('.ldppp_ratings_ratio_wrapper').first();
     302                }
     303            }
     304        }
     305
     306        console.log('Found ratio wrapper:', $ratioWrapper.length, 'HTML:', $ratioWrapper.html() ? $ratioWrapper.html().substring(0, 100) : 'empty');
     307
     308        if ($ratioWrapper.length) {
     309            // Update each star rating row from 5 stars down to 1 star
     310            for (let i = 5; i >= 1; i--) {
     311                const percent = rating_counts[i] ? rating_counts[i].percent : 0;
     312                const $row = $ratioWrapper.find('[data-star="' + i + '"]');
     313               
     314                console.log('Star ' + i + ': looking for [data-star="' + i + '"], found:', $row.length, ', percent:', percent);
     315               
     316                if ($row.length) {
     317                    // Update width and percentage text
     318                    $row.find('.ldppp_ratings_ratio_fill').css('width', percent + '%');
     319                    $row.find('.ldppp_ratings_ratio_percent').text(percent + '%');
     320                    console.log('Updated star ' + i);
     321                }
     322            }
     323        } else {
     324            console.log('ERROR: Could not find ldppp_ratings_ratio_wrapper!');
     325        }
    236326    }
    237327
     
    286376        const displayType = ldppp_count_ajax.display_type;
    287377
    288         const like_percent = total > 0 ? Math.round((likes / total) * 100) : 0;
    289         const dislike_percent = total > 0 ? Math.round((dislikes / total) * 100) : 0;
     378        const like_percent = total > 0 ? Math.round((likes / total) * 100) : 50;
     379        const dislike_percent = total > 0 ? Math.round((dislikes / total) * 100) : 50;
    290380
    291381        const likeText = displayType === 'percentage' ? like_percent + '%' : likes;
     
    295385        $wrapper.find('.ldppp_comment_dislike-count').text(dislikeText);
    296386
    297         // Update ratio bars
    298         $wrapper.find('.ldppp_comment_ratio_like')
    299             .css('width', like_percent + '%')
    300             .find('.ldppp_comment_ratio_text').text(like_percent + '%');
    301 
    302         $wrapper.find('.ldppp_comment_ratio_dislike')
    303             .css('width', dislike_percent + '%')
    304             .find('.ldppp_comment_ratio_text').text(dislike_percent + '%');
     387        // Update ratio bars - they are located after the main wrapper div
     388        const $ratioBar = $wrapper.next('.ldppp_comment_ratio_bar');
     389        if ($ratioBar.length) {
     390            $ratioBar.find('.ldppp_comment_ratio_like')
     391                .css('width', like_percent + '%')
     392                .find('.ldppp_comment_ratio_text').text(like_percent + '%');
     393
     394            $ratioBar.find('.ldppp_comment_ratio_dislike')
     395                .css('width', dislike_percent + '%')
     396                .find('.ldppp_comment_ratio_text').text(dislike_percent + '%');
     397        }
    305398
    306399        // Reset icons
  • like-dislike-posts-products/trunk/files/shop_achieve.php

    r3362707 r3450961  
    180180    $ldppp_counterShow .= '</div>';
    181181   
     182    // Add rating progress bar
     183    $ldppp_auto_display_rating_progressbar = get_option('ldppp_auto_display_rating_progressbar', 'yes');
     184    if (isset($ldppp_auto_display_rating_progressbar) && $ldppp_auto_display_rating_progressbar == 'yes') {
     185        // Calculate rating distribution
     186        $rating_counts = array();
     187        for ($i = 1; $i <= 5; $i++) {
     188            $rating_counts[$i] = (int) $wpdb->get_var(
     189                $wpdb->prepare("SELECT COUNT(*) FROM $ldppp_ratings WHERE post_id = %d AND ratings = %d", $post->ID, $i)
     190            );
     191        }
     192        $total_rating_votes = array_sum($rating_counts);
     193       
     194        $ldppp_counterShow .= '<div class="ldppp_ratings_ratio_wrapper">';
     195        for ($i = 5; $i >= 1; $i--) {
     196            $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
     197            $ldppp_counterShow .= '
     198                <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
     199                    <span class="ldppp_star_label">' . esc_html($i) . '★</span>
     200                    <div class="ldppp_ratings_ratio_bar">
     201                        <div class="ldppp_ratings_ratio_fill" style="width:' . esc_attr($percent) . '%;"></div>
     202                    </div>
     203                    <span class="ldppp_ratings_ratio_percent">' . esc_html($percent) . '%</span>
     204                </div>
     205            ';
     206        }
     207        $ldppp_counterShow .= '</div>';
     208    }
     209   
    182210    $ldppp_allowed_html = array(
    183211        'input' => array(
     
    199227            'class' => array(),
    200228            'id' => array(),
     229            'data-star' => array(),
     230            'style' => array(),
    201231        ),
    202232    );
  • like-dislike-posts-products/trunk/files/single_page.php

    r3362713 r3450961  
    192192    $ldppp_counterShow .= '</div>';
    193193   
     194    // Add rating progress bar
     195    $ldppp_auto_display_rating_progressbar = get_option('ldppp_auto_display_rating_progressbar', 'yes');
     196    if (isset($ldppp_auto_display_rating_progressbar) && $ldppp_auto_display_rating_progressbar == 'yes') {
     197        // Calculate rating distribution
     198        $rating_counts = array();
     199        for ($i = 1; $i <= 5; $i++) {
     200            $rating_counts[$i] = (int) $wpdb->get_var(
     201                $wpdb->prepare("SELECT COUNT(*) FROM $ldppp_ratings WHERE post_id = %d AND ratings = %d", $post->ID, $i)
     202            );
     203        }
     204        $total_rating_votes = array_sum($rating_counts);
     205       
     206        $ldppp_counterShow .= '<div class="ldppp_ratings_ratio_wrapper">';
     207        for ($i = 5; $i >= 1; $i--) {
     208            $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
     209            $ldppp_counterShow .= '
     210                <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
     211                    <span class="ldppp_star_label">' . esc_html($i) . '★</span>
     212                    <div class="ldppp_ratings_ratio_bar">
     213                        <div class="ldppp_ratings_ratio_fill" style="width:' . esc_attr($percent) . '%;"></div>
     214                    </div>
     215                    <span class="ldppp_ratings_ratio_percent">' . esc_html($percent) . '%</span>
     216                </div>
     217            ';
     218        }
     219        $ldppp_counterShow .= '</div>';
     220    }
     221   
    194222    $ldppp_allowed_html = array(
    195223        'input' => array(
     
    211239            'class' => array(),
    212240            'id' => array(),
     241            'data-star' => array(),
     242            'style' => array(),
    213243        ),
    214244    );
  • like-dislike-posts-products/trunk/functions.php

    r3446224 r3450961  
    13361336                                $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
    13371337                                $ldppp_counterShow .= '
    1338                                     <div class="ldppp_ratings_ratio_row">
     1338                                    <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
    13391339                                        <span class="ldppp_star_label">' . esc_html($i) . '★</span>
    13401340                                        <div class="ldppp_ratings_ratio_bar">
     
    14221422                                $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
    14231423                                $ldppp_counterShow .= '
    1424                                     <div class="ldppp_ratings_ratio_row">
     1424                                    <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
    14251425                                        <span class="ldppp_star_label">' . esc_html($i) . '★</span>
    14261426                                        <div class="ldppp_ratings_ratio_bar">
     
    16121612                                    $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
    16131613                                    $ldppp_counterShow .= '
    1614                                         <div class="ldppp_ratings_ratio_row">
     1614                                        <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
    16151615                                            <span class="ldppp_star_label">' . esc_html($i) . '★</span>
    16161616                                            <div class="ldppp_ratings_ratio_bar">
     
    17021702                                    $percent = ($total_rating_votes > 0) ? round(($rating_counts[$i] / $total_rating_votes) * 100) : 0;
    17031703                                    $ldppp_counterShow .= '
    1704                                         <div class="ldppp_ratings_ratio_row">
     1704                                        <div class="ldppp_ratings_ratio_row" data-star="' . esc_attr($i) . '">
    17051705                                            <span class="ldppp_star_label">' . esc_html($i) . '★</span>
    17061706                                            <div class="ldppp_ratings_ratio_bar">
     
    18671867        );
    18681868    }
     1869
     1870    // Get rating counts for each star level
     1871    $total_votes = intval($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $ldppp_table_name WHERE post_id=%d", $postID)));
     1872    $rating_counts = array();
     1873    for ($i = 1; $i <= 5; $i++) {
     1874        $count = intval($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $ldppp_table_name WHERE post_id=%d AND ratings=%d", $postID, $i)));
     1875        $percent = ($total_votes > 0) ? round(($count / $total_votes) * 100) : 0;
     1876        $rating_counts[$i] = array('count' => $count, 'percent' => $percent);
     1877    }
     1878    $data['rating_counts'] = $rating_counts;
     1879    $data['total_votes'] = $total_votes;
     1880
    18691881    $data['success_msg'] = esc_html__( 'Rating Successfully Added.', 'like-dislike-posts-products' );
    18701882    $data['error_msg'] = esc_html__( 'Rating Not added.', 'like-dislike-posts-products' );
  • like-dislike-posts-products/trunk/ldppp_likes_dislikes.php

    r3446224 r3450961  
    33Plugin Name: Like Dislike, Star Ratings, Favorites & Post Views & Share & Copy Posts – Posts, Comments, Products
    44Description: A powerful engagement toolkit offering AJAX-based Like/Dislike buttons, Star Ratings, Favorites (Wishlist), Post Views counter, and Social Share features for posts, products, and comments.
    5 Version: 2.8
     5Version: 2.9
    66Author: Kirtikumar Solanki
    77Author URI: https://profiles.wordpress.org/solankisoftware/
     
    1616
    1717define( 'LDPPP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    18 define( 'LDPPP_VERSION', '2.8' );
     18define( 'LDPPP_VERSION', '2.9' );
    1919define( 'LDPPP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    2020
     
    8383function ldppp_pages(){
    8484    add_menu_page( 'Like/Dislike Posts', 'Posts Products Reactions & Ratings', 'administrator', 'ldppp-like-dislike-posts', 'ldppp_admin_view', 'dashicons-star-empty');
    85     add_submenu_page( 'Like/Dislike Posts1', 'Posts Like/Dislike1', 'administrator', 'ldppp-like-dislike-posts1', 'ldppp_admin_view1',59);
    8685}
    8786add_action('admin_menu', 'ldppp_pages');
     
    15551554            $percent = ( $total_rating_votes > 0 ) ? round( ( $rating_counts[$i] / $total_rating_votes ) * 100 ) : 0;
    15561555        ?>
    1557             <div class="ldppp_ratings_ratio_row">
     1556            <div class="ldppp_ratings_ratio_row" data-star="<?php echo esc_attr( $i ); ?>">
    15581557                <span class="ldppp_star_label"><?php echo esc_html( $i ); ?>★</span>
    15591558                <div class="ldppp_ratings_ratio_bar">
     
    19561955            align-items: center;
    19571956            gap: 5px;
     1957            width: fit-content;
    19581958            transition: background 0.3s ease;
    19591959        }
     
    19651965        .ldppp-copy-success-msg {
    19661966            display: inline-block;
    1967             margin-left: 10px;
    19681967            animation: fadeInOut 2s ease-in-out;
    19691968        }
  • like-dislike-posts-products/trunk/readme.txt

    r3446438 r3450961  
    1 === Like Dislike, Star Ratings, Favorites & Post Views & Share & Copy Posts – Posts, Comments, Products ===
     1=== Post Engagement – Posts, Comments, Products ===
    22Contributors: solankisoftware
    33Donate link: https://paypal.me/kirtikumar89
     
    55Requires at least: 4.7
    66Tested up to: 6.9
    7 Stable tag: 2.8
     7Stable tag: 2.9
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    1414== Description ==
    1515
    16 **Like Dislike, Star Ratings, Favorites & Post Views & Share & copy posts – Posts, Comments, Products** is a lightweight, user-friendly plugin that lets users engage with posts, comments, and WooCommerce products using **Like**, **Dislike**, **Star Rating**, **Post View Tracking**, and **Favorites** (wishlist-like system) and ** Copy posts**.
     16**Post Engagement – Posts, Comments, Products** is a lightweight, user-friendly plugin that lets users engage with posts, comments, and WooCommerce products using **Like**, **Dislike**, **Star Rating**, **Post View Tracking**, and **Favorites** (wishlist-like system) and ** Copy posts**.
    1717
    1818Built with performance in mind, the plugin uses AJAX for seamless interaction and offers customization for labels, icon colors, display positions, view counters, tooltips, and more.
     
    2323
    2424### 🎯 Key Features
     25**New in version 2.9:**
     26- Fixed comments ajax ratiobar intant changed comment changed like dislike
     27- Fixed issue in ratiobar ajax when post like dislike instant
     28- Fixed copy posts button design
     29- Fixed some bugs in shortcodes
    2530
    2631### 📋 Copy Posts Content (New in 2.8)
    27 
    2832**New in version 2.8:** 
    2933- Added **Copy Posts Content** feature
     
    180184
    181185---
    182 
    183 == Privacy & Supported Networks ==
    184 
    185 This plugin itself does not collect or send any personal data to external servers. 
    186 All Likes, Dislikes, Ratings, Favorites, and Post View counts are stored locally in your WordPress database.
    187 
    188 The social share buttons included in the plugin redirect users to external platforms. These platforms may collect data according to their own privacy policies. The following external services are used to enable sharing:
    189 
    190 | Network   | Share URL                                         | Privacy Policy                                                                 |
    191 |-----------|--------------------------------------------------|-------------------------------------------------------------------------------|
    192 | Facebook  | https://www.facebook.com/sharer/sharer.php       | [Privacy Policy](https://www.facebook.com/policy.php)                         |
    193 | Twitter   | https://twitter.com/intent/tweet                 | [Privacy Policy](https://twitter.com/privacy)                                  |
    194 | LinkedIn  | https://www.linkedin.com/shareArticle            | [Privacy Policy](https://www.linkedin.com/legal/privacy-policy)                |
    195 | Pinterest | https://pinterest.com/pin/create/button/        | [Privacy Policy](https://policy.pinterest.com/en/privacy-policy)               |
    196 | WhatsApp  | https://api.whatsapp.com/send                    | [Privacy Policy](https://www.whatsapp.com/legal/privacy-policy)                |
    197 | Gmail     | https://mail.google.com/mail/                     | [Privacy Policy](https://policies.google.com/privacy)                           |
    198 | Telegram  | https://t.me/share/url                            | [Privacy Policy](https://telegram.org/privacy)                                  |
    199 | Reddit    | https://www.reddit.com/submit                     | [Privacy Policy](https://www.redditinc.com/policies/privacy-policy)            |
    200 | Tumblr    | https://www.tumblr.com/widgets/share/tool        | [Privacy Policy](https://www.tumblr.com/policy/en/privacy)                      |
    201 | Email     | Uses browser-based default email client          | No external service                                                           |
    202 | Print     | Opens the print dialog in the user’s browser    | No external service                                                           |
    203 | Copy      | Copies the current page URL to clipboard        | No external service                                                           |
    204 
    205 > ⚠️ Note: Email, Print, and Copy actions are handled locally in the user’s browser. The plugin never sends this data to any external service.
    206 
    207186
    208187== Installation ==
     
    277256
    278257== Changelog ==
     258= 2.9 =
     259* Fixed comments ajax ratiobar intant changed comment changed like dislike
     260* Fixed issue in ratiobar ajax when post like dislike instant
     261* Fixed copy posts button design
     262* Fixed some bugs in shortcodes
     263
    279264= 2.8 =
    280265* New: Added Copy Posts Content feature.
     
    283268* Uses AJAX and browser clipboard API for seamless copying.
    284269* Improved UX with instant feedback messages.
    285 * Minor code cleanup and compatibility checks for WordPress 6.x.
     270* Minor code cleanup and compatibility checks for WordPress 6.9.
    286271* Added new shortcodes for manual placement:
    287272- `[ldppp_copy_posts]`
Note: See TracChangeset for help on using the changeset viewer.