Support » Plugin: WordPress Popular Posts » WordPress Popular Posts not showing

  • Resolved ktsiterip

    (@ktsiterip)



    Hi
    I updated to the new version (4.1.0) a couple of hours ago
    However now its not showing at all
    I’ve cleared cache (I use Comet Cache – which was working fine before)
    I also disabled Comet Cache but still not having any luck!
    Should I clear WordPress Popular Posts own cache (not sure if that would make any difference)
    Thank you – and also thanks for such a good plugin!

    The page I need help with: [log in to see the link]

Viewing 15 replies - 16 through 30 (of 53 total)
  • ktsiterip

    (@ktsiterip)

    I’m an idiot!
    Ok, I have added the missing ; and emptied comet and cloudflare caches, but I’m still not seeing the popular posts content
    Im sorry this is so difficult – I guess other people might have the same issue though?
    Dont worry if in the end we cant get this fixed – I’ll just turn off Rocket Loader

    Plugin Author Hector Cabrera

    (@hcabrera)

    Don’t worry about it, I won’t give up so easily 😛

    Alright, let’s try this next:

    1. Disable Comet Cache for now.
    2. Go to Plugins > Editor and pick WordPress Popular Posts from the dropdown at the right.
    3. Under Plugin Files, click on includes > class-wordpress-popular-posts-widget.php to edit it.
    4. Find:
      <script type="text/javascript">
          window.addEventListener('DOMContentLoaded', function() {
              var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
      
              if ( 'undefined' != typeof WordPressPopularPosts ) {
                  WordPressPopularPosts.get(
                      wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                      'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                      function( response ){
                          wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
      
                          var event = null;
      
                          if ( 'function' === typeof(Event) ) {
                              event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                          } // Fallback for older browsers
                          else {
                              if ( document.createEvent ) {
                                  event = document.createEvent('Event');
                                  event.initEvent( "wpp-onload", true, false );
                              }
                          }
      
                          if ( event ) {
                              wpp_widget_container.dispatchEvent( event );
                          }
                      }
                  );
              }
          });
      </script>

      and replace it with:

      <script type="text/javascript">
          window.addEventListener('DOMContentLoaded', function() {
      
              console.log( 'DOMContentLoaded' );
      
              var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
      
              console.log( wpp_widget_container, WordPressPopularPosts );
      
              if ( 'undefined' != typeof WordPressPopularPosts ) {
      
                  console.log( 'WordPressPopularPosts found' );
      
                  WordPressPopularPosts.get(
                      wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                      'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                      function( response ){
                          wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
      
                          var event = null;
      
                          if ( 'function' === typeof(Event) ) {
                              event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                          } // Fallback for older browsers
                          else {
                              if ( document.createEvent ) {
                                  event = document.createEvent('Event');
                                  event.initEvent( "wpp-onload", true, false );
                              }
                          }
      
                          if ( event ) {
                              wpp_widget_container.dispatchEvent( event );
                          }
                      }
                  );
              }
          });
      </script>
    5. Click on Update file to save changes.

    Let me know when it’s done so I can have a look.

    ktsiterip

    (@ktsiterip)

    Hi Hector!
    I turned off comet cache
    and made the change to class-wordpress-popular-posts-widget.php – have a look now

    Plugin Author Hector Cabrera

    (@hcabrera)

    Aha! I think we’re getting closer!

    Try this:

    <script type="text/javascript">
        window.addEventListener('DOMContentLoaded', function() {
    
            console.log( 'DOMContentLoaded' );
    
            var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
            console.log( wpp_widget_container, WordPressPopularPosts );
    
            if ( 'undefined' != typeof WordPressPopularPosts ) {
    
                console.log( 'WordPressPopularPosts found' );
    
                WordPressPopularPosts.get(
                    wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                    'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                    function( response ){
                        wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                        var event = null;
    
                        if ( 'function' === typeof(Event) ) {
                            event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                        } /* Fallback for older browsers */
                        else {
                            if ( document.createEvent ) {
                                event = document.createEvent('Event');
                                event.initEvent( "wpp-onload", true, false );
                            }
                        }
    
                        if ( event ) {
                            wpp_widget_container.dispatchEvent( event );
                        }
                    }
                );
            }
        });
    </script>
    ktsiterip

    (@ktsiterip)

    Hi Hector!
    I’ve tried that code a couple of times – am I missing something – getting a blank site again

    <script type="text/javascript">
        window.addEventListener('DOMContentLoaded', function() {
    
            console.log( 'DOMContentLoaded' );
    
            var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
            console.log( wpp_widget_container, WordPressPopularPosts );
    
            if ( 'undefined' != typeof WordPressPopularPosts ) {
    
                console.log( 'WordPressPopularPosts found' );
    
                WordPressPopularPosts.get(
                    wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                    'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                    function( response ){
                        wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                        var event = null;
    
                        if ( 'function' === typeof(Event) ) {
                            event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                        } /* Fallback for older browsers */
                        else {
                            if ( document.createEvent ) {
                                event = document.createEvent('Event');
                                event.initEvent( "wpp-onload", true, false );
                            }
                        }
    
                        if ( event ) {
                            wpp_widget_container.dispatchEvent( event );
                        }
                    }
                );
            }
        });
    </script>
    Plugin Author Hector Cabrera

    (@hcabrera)

    No, it seems you copied everything correctly this time 😛

    Revert back to the original code (see above) and try again.

    ktsiterip

    (@ktsiterip)

    Now, for whatever reason the first new code causes a blank site (aaaah!)

    with the ? at start and php at end it looks like this

    I cant think why it does not work!

    ?>
    
                <script type="text/javascript">
        window.addEventListener('DOMContentLoaded', function() {
    
            console.log( 'DOMContentLoaded' );
    
            var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
            console.log( wpp_widget_container, WordPressPopularPosts );
    
            if ( 'undefined' != typeof WordPressPopularPosts ) {
    
                console.log( 'WordPressPopularPosts found' );
    
                WordPressPopularPosts.get(
                    wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                    'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                    function( response ){
                        wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                        var event = null;
    
                        if ( 'function' === typeof(Event) ) {
                            event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                        } // Fallback for older browsers
                        else {
                            if ( document.createEvent ) {
                                event = document.createEvent('Event');
                                event.initEvent( "wpp-onload", true, false );
                            }
                        }
    
                        if ( event ) {
                            wpp_widget_container.dispatchEvent( event );
                        }
                    }
                );
            }
        });
    </script>
    
                <?php
    Plugin Author Hector Cabrera

    (@hcabrera)

    Seems that you deleted something you shouldn’t have.

    Here’s the full code:

    <?php
    
    class WPP_Widget extends WP_Widget {
    
        /**
         * Administrative settings.
         *
         * @since	2.3.3
         * @var		array
         */
        private $admin_options = array();
    
        public function __construct(){
    
            // Create the widget
            parent::__construct(
                'wpp',
                'WordPress Popular Posts',
                array(
                    'classname'		=>	'popular-posts',
                    'description'	=>	__( 'The most Popular Posts on your blog.', 'wordpress-popular-posts' )
                )
            );
    
            $this->admin_options = WPP_Settings::get( 'admin_options' );
    
            // Widget's AJAX hook
            if ( $this->admin_options['tools']['ajax'] ) {
                add_action( 'wp_ajax_wpp_get_popular', array( $this, 'get_popular') );
                add_action( 'wp_ajax_nopriv_wpp_get_popular', array( $this, 'get_popular') );
            }
    
        }
    
        /**
         * Outputs the content of the widget.
         *
         * @since	1.0.0
         * @param	array	args		The array of form elements
         * @param	array	instance	The current instance of the widget
         */
        public function widget( $args, $instance ){
            /**
             * @var string $name
             * @var string $id
             * @var string $description
             * @var string $class
             * @var string $before_widget
             * @var string $after_widget
             * @var string $before_title
             * @var string $after_title
             * @var string $widget_id
             * @var string $widget_name
             */
            extract( $args, EXTR_SKIP );
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
    
            $markup = ( $instance['markup']['custom_html'] || has_filter('wpp_custom_html') || has_filter('wpp_post') )
                  ? 'custom'
                  : 'regular';
    
            echo "\n" . $before_widget . "\n";
    
            // Has user set a title?
            if ( '' != $instance['title'] ) {
    
                $title = apply_filters( 'widget_title', $instance['title'] );
    
                if (
                    $instance['markup']['custom_html']
                    && $instance['markup']['title-start'] != ""
                    && $instance['markup']['title-end'] != ""
                ) {
                    echo htmlspecialchars_decode( $instance['markup']['title-start'], ENT_QUOTES) . $title . htmlspecialchars_decode($instance['markup']['title-end'], ENT_QUOTES );
                } else {
                    echo $before_title . $title . $after_title;
                }
            }
    
            // Expose Widget ID for customization
            $instance['widget_id'] = $widget_id;
    
            // Get posts
            if ( $this->admin_options['tools']['ajax'] && !is_customize_preview() ) {
    
                if ( empty( $before_widget ) || !preg_match( '/id="[^"]*"/', $before_widget ) ) {
                ?>
                <p><?php printf( __('Error: cannot ajaxify WordPress Popular Posts on this theme. It\'s missing the <em>id</em> attribute on before_widget (see <a href="%s" target="_blank" rel="nofollow">register_sidebar</a> for more)', 'wordpress-popular-posts'), 'https://codex.wordpress.org/Function_Reference/register_sidebar' ); ?>.</p>
                <?php
                } else {
                ?>
                <script type="text/javascript">
                    window.addEventListener('DOMContentLoaded', function() {
                        var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
                        if ( 'undefined' != typeof WordPressPopularPosts ) {
                            WordPressPopularPosts.get(
                                wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                                'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                                function( response ){
                                    wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                                    var event = null;
    
                                    if ( 'function' === typeof(Event) ) {
                                        event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                                    } // Fallback for older browsers
                                    else {
                                        if ( document.createEvent ) {
                                            event = document.createEvent('Event');
                                            event.initEvent( "wpp-onload", true, false );
                                        }
                                    }
    
                                    if ( event ) {
                                        wpp_widget_container.dispatchEvent( event );
                                    }
                                }
                            );
                        }
                    });
                </script>
                <?php
                }
            } else {
                $this->get_popular( $instance );
            }
    
            echo "\n" . $after_widget . "\n";
    
        }
    
        /**
         * Generates the administration form for the widget.
         *
         * @since	1.0.0
         * @param	array	instance	The array of keys and values for the widget.
         */
        public function form( $instance ){
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
            $wpp_image = WPP_Image::get_instance();
    
            include( plugin_dir_path( __FILE__ ) . '/widget-form.php' );
    
        }
    
        /**
         * Processes the widget's options to be saved.
         *
         * @since	1.0.0
         * @param	array	new_instance	The previous instance of values before the update.
         * @param	array	old_instance	The new instance of values to be generated via the update.
         * @return	array	instance		Updated instance.
         */
        public function update( $new_instance, $old_instance ){
    
            $wpp_image = WPP_Image::get_instance();
    
            $instance = $old_instance;
    
            $instance['title'] = htmlspecialchars( stripslashes_deep(strip_tags( $new_instance['title'] )), ENT_QUOTES );
            $instance['limit'] = ( WPP_Helper::is_number($new_instance['limit']) && $new_instance['limit'] > 0 )
              ? $new_instance['limit']
              : 10;
            $instance['range'] = $new_instance['range'];
            $instance['time_quantity'] = ( WPP_Helper::is_number($new_instance['time_quantity']) && $new_instance['time_quantity'] > 0 )
              ? $new_instance['time_quantity']
              : 24;
            $instance['time_unit'] = $new_instance['time_unit'];
            $instance['order_by'] = $new_instance['order_by'];
    
            // FILTERS
            // user did not set a post type name, so we fall back to default
            $instance['post_type'] = ( '' == $new_instance['post_type'] )
              ? 'post,page'
              : $new_instance['post_type'];
    
            $instance['freshness'] = isset( $new_instance['freshness'] );
    
            // Post / Page / CTP filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['pid'] = '';
            }
            else {
                $instance['pid'] = implode( ",", $ids );
            }
    
            // Taxonomy filter
            $instance['taxonomy'] = $new_instance['taxonomy'];
            $instance['cat'] = ''; // Deprecated in 4.0.0!
    
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,-]|', '', $new_instance['term_id'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['term_id'] = '';
            }
            else {
                $instance['term_id'] = implode( ",", $ids );
            }
    
            // Author filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['author'] = '';
            }
            else {
                $instance['author'] = implode( ",", $ids );
            }
    
            $instance['shorten_title']['words'] = $new_instance['shorten_title-words'];
            $instance['shorten_title']['active'] = isset( $new_instance['shorten_title-active'] );
            $instance['shorten_title']['length'] = ( WPP_Helper::is_number($new_instance['shorten_title-length']) && $new_instance['shorten_title-length'] > 0 )
              ? $new_instance['shorten_title-length']
              : 25;
    
            $instance['post-excerpt']['keep_format'] = isset( $new_instance['post-excerpt-format'] );
            $instance['post-excerpt']['words'] = $new_instance['post-excerpt-words'];
            $instance['post-excerpt']['active'] = isset( $new_instance['post-excerpt-active'] );
            $instance['post-excerpt']['length'] = ( WPP_Helper::is_number($new_instance['post-excerpt-length']) && $new_instance['post-excerpt-length'] > 0 )
              ? $new_instance['post-excerpt-length']
              : 55;
    
            $instance['thumbnail']['active'] = false;
            $instance['thumbnail']['width'] = 15;
            $instance['thumbnail']['height'] = 15;
    
            // can create thumbnails
            if ( $wpp_image->can_create_thumbnails() ) {
    
                $instance['thumbnail']['active'] = isset( $new_instance['thumbnail-active'] );
                $instance['thumbnail']['build'] = $new_instance['thumbnail-size-source'];
    
                // Use predefined thumbnail sizes
                if ( 'predefined' == $new_instance['thumbnail-size-source'] ) {
    
                    $default_thumbnail_sizes = $wpp_image->get_image_sizes();
                    $size = $default_thumbnail_sizes[ $new_instance['thumbnail-size'] ];
    
                    $instance['thumbnail']['width'] = $size['width'];
                    $instance['thumbnail']['height'] = $size['height'];
                    $instance['thumbnail']['crop'] = $size['crop'];
    
                } // Set thumbnail size manually
                else {
                    if ( WPP_Helper::is_number($new_instance['thumbnail-width']) && WPP_Helper::is_number($new_instance['thumbnail-height']) ) {
                        $instance['thumbnail']['width'] = $new_instance['thumbnail-width'];
                        $instance['thumbnail']['height'] = $new_instance['thumbnail-height'];
                        $instance['thumbnail']['crop'] = true;
                    }
                }
    
            }
    
            $instance['rating'] = isset( $new_instance['rating'] );
            $instance['stats_tag']['comment_count'] = isset( $new_instance['comment_count'] );
            $instance['stats_tag']['views'] = isset( $new_instance['views'] );
            $instance['stats_tag']['author'] = isset( $new_instance['author'] );
            $instance['stats_tag']['date']['active'] = isset( $new_instance['date'] );
            $instance['stats_tag']['date']['format'] = empty($new_instance['date_format'])
              ? 'F j, Y'
              : $new_instance['date_format'];
    
            $instance['stats_tag']['taxonomy']['active'] = isset( $new_instance['stats_taxonomy'] );
            $instance['stats_tag']['taxonomy']['name'] = isset( $new_instance['stats_taxonomy_name'] ) ? $new_instance['stats_taxonomy_name'] : 'category';
            $instance['stats_tag']['category'] = isset( $new_instance['stats_taxonomy'] ); // Deprecated in 4.0.0!
    
            $instance['markup']['custom_html'] = isset( $new_instance['custom_html'] );
            $instance['markup']['wpp-start'] = empty($new_instance['wpp-start'])
              ? htmlspecialchars( '<ul class="wpp-list">', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-start'], ENT_QUOTES );
    
            $instance['markup']['wpp-end'] = empty($new_instance['wpp-end'])
              ? htmlspecialchars( '</ul>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-end'], ENT_QUOTES );
    
            $instance['markup']['post-html'] = empty($new_instance['post-html'])
              ? htmlspecialchars( '<li>{thumb} {title} {stats}</li>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['post-html'], ENT_QUOTES );
    
            $instance['markup']['title-start'] = empty($new_instance['title-start'])
              ? ''
              : htmlspecialchars( $new_instance['title-start'], ENT_QUOTES );
    
            $instance['markup']['title-end'] = empty($new_instance['title-end'])
              ? '' :
              htmlspecialchars( $new_instance['title-end'], ENT_QUOTES );
    
            return $instance;
    
        }
    
        /**
         * Returns HTML list via AJAX
         *
         * @since	2.3.3
         */
        public function get_popular( $instance = null ) {
    
            if ( defined('DOING_AJAX') && DOING_AJAX ) {
    
                if ( isset( $_GET['id'] ) && WPP_helper::is_number( $_GET['id'] ) ) {
    
                    $id = $_GET['id'];
                    $widget_instances = $this->get_settings();
    
                    if ( isset( $widget_instances[$id] ) ) {
                        $instance = $widget_instances[$id];
    
                        if ( !isset( $instance['widget_id'] ) ) {
                            $instance['widget_id'] = $this->id;
                        }
                    }
    
                }
    
            }
    
            if ( is_array( $instance ) && !empty( $instance ) ) {
    
                // Return cached results
                if ( $this->admin_options['tools']['cache']['active'] ) {
    
                    $transient_name = md5( json_encode($instance) );
                    $popular_posts = get_transient( $transient_name );
    
                    if ( false === $popular_posts ) {
    
                        $popular_posts = new WPP_Query( $instance );
    
                        switch( $this->admin_options['tools']['cache']['interval']['time'] ){
    
                            case 'minute':
                                $time = 60;
                            break;
    
                            case 'hour':
                                $time = 60 * 60;
                            break;
    
                            case 'day':
                                $time = 60 * 60 * 24;
                            break;
    
                            case 'week':
                                $time = 60 * 60 * 24 * 7;
                            break;
    
                            case 'month':
                                $time = 60 * 60 * 24 * 30;
                            break;
    
                            case 'year':
                                $time = 60 * 60 * 24 * 365;
                            break;
    
                            default:
                                $time = 60 * 60;
                            break;
    
                        }
    
                        $expiration = $time * $this->admin_options['tools']['cache']['interval']['value'];
    
                        // Store transient
                        set_transient( $transient_name, $popular_posts, $expiration );
    
                        // Store transient in WPP transients array for garbage collection
                        $wpp_transients = get_option('wpp_transients');
    
                        if ( !$wpp_transients ) {
                            $wpp_transients = array( $transient_name );
                            add_option( 'wpp_transients', $wpp_transients );
                        } else {
                            if ( !in_array($transient_name, $wpp_transients) ) {
                                $wpp_transients[] = $transient_name;
                                update_option( 'wpp_transients', $wpp_transients );
                            }
                        }
    
                    }
    
                } // Get popular posts
                else {
                    $popular_posts = new WPP_Query( $instance );
                }
    
                $output = new WPP_Output( $popular_posts->get_posts(), $instance );
    
                echo ( $this->admin_options['tools']['cache']['active'] ? '<!-- cached -->' : '' );
                $output->output();
    
            }
    
            if (
                defined('DOING_AJAX') 
                && DOING_AJAX && !is_preview() 
                && !( is_singular() && isset( $_GET['fl_builder'] ) )
            ) {
                wp_die();
            }
    
        }
    
    } // end class WPP_Widget
    ktsiterip

    (@ktsiterip)

    Ha!
    Its me being an idiot, Im sure, but even putting the full code in causes a blank site
    Luckily I have a copy of the original code, which still works!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Great!

    Just replace this line then:

    } // Fallback for older browsers

    with:

    } /* Fallback for older browsers */

    And save changes.

    ktsiterip

    (@ktsiterip)

    Ok!
    So I’ve done that and now have the below – site is loading, popular posts are not

    <?php
    
    class WPP_Widget extends WP_Widget {
    
        /**
         * Administrative settings.
         *
         * @since	2.3.3
         * @var		array
         */
        private $admin_options = array();
    
        public function __construct(){
    
            // Create the widget
            parent::__construct(
                'wpp',
                'WordPress Popular Posts',
                array(
                    'classname'		=>	'popular-posts',
                    'description'	=>	__( 'The most Popular Posts on your blog.', 'wordpress-popular-posts' )
                )
            );
    
            $this->admin_options = WPP_Settings::get( 'admin_options' );
    
            // Widget's AJAX hook
            if ( $this->admin_options['tools']['ajax'] ) {
                add_action( 'wp_ajax_wpp_get_popular', array( $this, 'get_popular') );
                add_action( 'wp_ajax_nopriv_wpp_get_popular', array( $this, 'get_popular') );
            }
    
        }
    
        /**
         * Outputs the content of the widget.
         *
         * @since	1.0.0
         * @param	array	args		The array of form elements
         * @param	array	instance	The current instance of the widget
         */
        public function widget( $args, $instance ){
            /**
             * @var string $name
             * @var string $id
             * @var string $description
             * @var string $class
             * @var string $before_widget
             * @var string $after_widget
             * @var string $before_title
             * @var string $after_title
             * @var string $widget_id
             * @var string $widget_name
             */
            extract( $args, EXTR_SKIP );
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
    
            $markup = ( $instance['markup']['custom_html'] || has_filter('wpp_custom_html') || has_filter('wpp_post') )
                  ? 'custom'
                  : 'regular';
    
            echo "\n" . $before_widget . "\n";
    
            // Has user set a title?
            if ( '' != $instance['title'] ) {
    
                $title = apply_filters( 'widget_title', $instance['title'] );
    
                if (
                    $instance['markup']['custom_html']
                    && $instance['markup']['title-start'] != ""
                    && $instance['markup']['title-end'] != ""
                ) {
                    echo htmlspecialchars_decode( $instance['markup']['title-start'], ENT_QUOTES) . $title . htmlspecialchars_decode($instance['markup']['title-end'], ENT_QUOTES );
                } else {
                    echo $before_title . $title . $after_title;
                }
            }
    
            // Expose Widget ID for customization
            $instance['widget_id'] = $widget_id;
    
            // Get posts
            if ( $this->admin_options['tools']['ajax'] && !is_customize_preview() ) {
    
                if ( empty( $before_widget ) || !preg_match( '/id="[^"]*"/', $before_widget ) ) {
                ?>
                <p><?php printf( __('Error: cannot ajaxify WordPress Popular Posts on this theme. It\'s missing the <em>id</em> attribute on before_widget (see <a href="%s" target="_blank" rel="nofollow">register_sidebar</a> for more)', 'wordpress-popular-posts'), 'https://codex.wordpress.org/Function_Reference/register_sidebar' ); ?>.</p>
                <?php
                } else {
                ?>
                <script type="text/javascript">
                    window.addEventListener('DOMContentLoaded', function() {
                        var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
                        if ( 'undefined' != typeof WordPressPopularPosts ) {
                            WordPressPopularPosts.get(
                                wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                                'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                                function( response ){
                                    wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                                    var event = null;
    
                                    if ( 'function' === typeof(Event) ) {
                                        event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                                   } /* Fallback for older browsers */
                                    else {
                                        if ( document.createEvent ) {
                                            event = document.createEvent('Event');
                                            event.initEvent( "wpp-onload", true, false );
                                        }
                                    }
    
                                    if ( event ) {
                                        wpp_widget_container.dispatchEvent( event );
                                    }
                                }
                            );
                        }
                    });
                </script>
                <?php
                }
            } else {
                $this->get_popular( $instance );
            }
    
            echo "\n" . $after_widget . "\n";
    
        }
    
        /**
         * Generates the administration form for the widget.
         *
         * @since	1.0.0
         * @param	array	instance	The array of keys and values for the widget.
         */
        public function form( $instance ){
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
            $wpp_image = WPP_Image::get_instance();
    
            include( plugin_dir_path( __FILE__ ) . '/widget-form.php' );
    
        }
    
        /**
         * Processes the widget's options to be saved.
         *
         * @since	1.0.0
         * @param	array	new_instance	The previous instance of values before the update.
         * @param	array	old_instance	The new instance of values to be generated via the update.
         * @return	array	instance		Updated instance.
         */
        public function update( $new_instance, $old_instance ){
    
            $wpp_image = WPP_Image::get_instance();
    
            $instance = $old_instance;
    
            $instance['title'] = htmlspecialchars( stripslashes_deep(strip_tags( $new_instance['title'] )), ENT_QUOTES );
            $instance['limit'] = ( WPP_Helper::is_number($new_instance['limit']) && $new_instance['limit'] > 0 )
              ? $new_instance['limit']
              : 10;
            $instance['range'] = $new_instance['range'];
            $instance['time_quantity'] = ( WPP_Helper::is_number($new_instance['time_quantity']) && $new_instance['time_quantity'] > 0 )
              ? $new_instance['time_quantity']
              : 24;
            $instance['time_unit'] = $new_instance['time_unit'];
            $instance['order_by'] = $new_instance['order_by'];
    
            // FILTERS
            // user did not set a post type name, so we fall back to default
            $instance['post_type'] = ( '' == $new_instance['post_type'] )
              ? 'post,page'
              : $new_instance['post_type'];
    
            $instance['freshness'] = isset( $new_instance['freshness'] );
    
            // Post / Page / CTP filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['pid'] = '';
            }
            else {
                $instance['pid'] = implode( ",", $ids );
            }
    
            // Taxonomy filter
            $instance['taxonomy'] = $new_instance['taxonomy'];
            $instance['cat'] = ''; // Deprecated in 4.0.0!
    
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,-]|', '', $new_instance['term_id'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['term_id'] = '';
            }
            else {
                $instance['term_id'] = implode( ",", $ids );
            }
    
            // Author filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['author'] = '';
            }
            else {
                $instance['author'] = implode( ",", $ids );
            }
    
            $instance['shorten_title']['words'] = $new_instance['shorten_title-words'];
            $instance['shorten_title']['active'] = isset( $new_instance['shorten_title-active'] );
            $instance['shorten_title']['length'] = ( WPP_Helper::is_number($new_instance['shorten_title-length']) && $new_instance['shorten_title-length'] > 0 )
              ? $new_instance['shorten_title-length']
              : 25;
    
            $instance['post-excerpt']['keep_format'] = isset( $new_instance['post-excerpt-format'] );
            $instance['post-excerpt']['words'] = $new_instance['post-excerpt-words'];
            $instance['post-excerpt']['active'] = isset( $new_instance['post-excerpt-active'] );
            $instance['post-excerpt']['length'] = ( WPP_Helper::is_number($new_instance['post-excerpt-length']) && $new_instance['post-excerpt-length'] > 0 )
              ? $new_instance['post-excerpt-length']
              : 55;
    
            $instance['thumbnail']['active'] = false;
            $instance['thumbnail']['width'] = 15;
            $instance['thumbnail']['height'] = 15;
    
            // can create thumbnails
            if ( $wpp_image->can_create_thumbnails() ) {
    
                $instance['thumbnail']['active'] = isset( $new_instance['thumbnail-active'] );
                $instance['thumbnail']['build'] = $new_instance['thumbnail-size-source'];
    
                // Use predefined thumbnail sizes
                if ( 'predefined' == $new_instance['thumbnail-size-source'] ) {
    
                    $default_thumbnail_sizes = $wpp_image->get_image_sizes();
                    $size = $default_thumbnail_sizes[ $new_instance['thumbnail-size'] ];
    
                    $instance['thumbnail']['width'] = $size['width'];
                    $instance['thumbnail']['height'] = $size['height'];
                    $instance['thumbnail']['crop'] = $size['crop'];
    
                } // Set thumbnail size manually
                else {
                    if ( WPP_Helper::is_number($new_instance['thumbnail-width']) && WPP_Helper::is_number($new_instance['thumbnail-height']) ) {
                        $instance['thumbnail']['width'] = $new_instance['thumbnail-width'];
                        $instance['thumbnail']['height'] = $new_instance['thumbnail-height'];
                        $instance['thumbnail']['crop'] = true;
                    }
                }
    
            }
    
            $instance['rating'] = isset( $new_instance['rating'] );
            $instance['stats_tag']['comment_count'] = isset( $new_instance['comment_count'] );
            $instance['stats_tag']['views'] = isset( $new_instance['views'] );
            $instance['stats_tag']['author'] = isset( $new_instance['author'] );
            $instance['stats_tag']['date']['active'] = isset( $new_instance['date'] );
            $instance['stats_tag']['date']['format'] = empty($new_instance['date_format'])
              ? 'F j, Y'
              : $new_instance['date_format'];
    
            $instance['stats_tag']['taxonomy']['active'] = isset( $new_instance['stats_taxonomy'] );
            $instance['stats_tag']['taxonomy']['name'] = isset( $new_instance['stats_taxonomy_name'] ) ? $new_instance['stats_taxonomy_name'] : 'category';
            $instance['stats_tag']['category'] = isset( $new_instance['stats_taxonomy'] ); // Deprecated in 4.0.0!
    
            $instance['markup']['custom_html'] = isset( $new_instance['custom_html'] );
            $instance['markup']['wpp-start'] = empty($new_instance['wpp-start'])
              ? htmlspecialchars( '<ul class="wpp-list">', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-start'], ENT_QUOTES );
    
            $instance['markup']['wpp-end'] = empty($new_instance['wpp-end'])
              ? htmlspecialchars( '</ul>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-end'], ENT_QUOTES );
    
            $instance['markup']['post-html'] = empty($new_instance['post-html'])
              ? htmlspecialchars( '<li>{thumb} {title} {stats}</li>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['post-html'], ENT_QUOTES );
    
            $instance['markup']['title-start'] = empty($new_instance['title-start'])
              ? ''
              : htmlspecialchars( $new_instance['title-start'], ENT_QUOTES );
    
            $instance['markup']['title-end'] = empty($new_instance['title-end'])
              ? '' :
              htmlspecialchars( $new_instance['title-end'], ENT_QUOTES );
    
            return $instance;
    
        }
    
        /**
         * Returns HTML list via AJAX
         *
         * @since	2.3.3
         */
        public function get_popular( $instance = null ) {
    
            if ( defined('DOING_AJAX') && DOING_AJAX ) {
    
                if ( isset( $_GET['id'] ) && WPP_helper::is_number( $_GET['id'] ) ) {
    
                    $id = $_GET['id'];
                    $widget_instances = $this->get_settings();
    
                    if ( isset( $widget_instances[$id] ) ) {
                        $instance = $widget_instances[$id];
    
                        if ( !isset( $instance['widget_id'] ) ) {
                            $instance['widget_id'] = $this->id;
                        }
                    }
    
                }
    
            }
    
            if ( is_array( $instance ) && !empty( $instance ) ) {
    
                // Return cached results
                if ( $this->admin_options['tools']['cache']['active'] ) {
    
                    $transient_name = md5( json_encode($instance) );
                    $popular_posts = get_transient( $transient_name );
    
                    if ( false === $popular_posts ) {
    
                        $popular_posts = new WPP_Query( $instance );
    
                        switch( $this->admin_options['tools']['cache']['interval']['time'] ){
    
                            case 'minute':
                                $time = 60;
                            break;
    
                            case 'hour':
                                $time = 60 * 60;
                            break;
    
                            case 'day':
                                $time = 60 * 60 * 24;
                            break;
    
                            case 'week':
                                $time = 60 * 60 * 24 * 7;
                            break;
    
                            case 'month':
                                $time = 60 * 60 * 24 * 30;
                            break;
    
                            case 'year':
                                $time = 60 * 60 * 24 * 365;
                            break;
    
                            default:
                                $time = 60 * 60;
                            break;
    
                        }
    
                        $expiration = $time * $this->admin_options['tools']['cache']['interval']['value'];
    
                        // Store transient
                        set_transient( $transient_name, $popular_posts, $expiration );
    
                        // Store transient in WPP transients array for garbage collection
                        $wpp_transients = get_option('wpp_transients');
    
                        if ( !$wpp_transients ) {
                            $wpp_transients = array( $transient_name );
                            add_option( 'wpp_transients', $wpp_transients );
                        } else {
                            if ( !in_array($transient_name, $wpp_transients) ) {
                                $wpp_transients[] = $transient_name;
                                update_option( 'wpp_transients', $wpp_transients );
                            }
                        }
    
                    }
    
                } // Get popular posts
                else {
                    $popular_posts = new WPP_Query( $instance );
                }
    
                $output = new WPP_Output( $popular_posts->get_posts(), $instance );
    
                echo ( $this->admin_options['tools']['cache']['active'] ? '<!-- cached -->' : '' );
                $output->output();
    
            }
    
            if (
                defined('DOING_AJAX') 
                && DOING_AJAX && !is_preview() 
                && !( is_singular() && isset( $_GET['fl_builder'] ) )
            ) {
                wp_die();
            }
    
        }
    
    } // end class WPP_Widget
    Plugin Author Hector Cabrera

    (@hcabrera)

    Sorry for the dumb question but, did you click on Update file? I’m still seeing the old code.

    ktsiterip

    (@ktsiterip)

    No problem!
    Im actually doing it via FTP rather than the editor as we have our editor locked for security
    But yes, I have definitely uploaded the following

    <?php
    
    class WPP_Widget extends WP_Widget {
    
        /**
         * Administrative settings.
         *
         * @since	2.3.3
         * @var		array
         */
        private $admin_options = array();
    
        public function __construct(){
    
            // Create the widget
            parent::__construct(
                'wpp',
                'WordPress Popular Posts',
                array(
                    'classname'		=>	'popular-posts',
                    'description'	=>	__( 'The most Popular Posts on your blog.', 'wordpress-popular-posts' )
                )
            );
    
            $this->admin_options = WPP_Settings::get( 'admin_options' );
    
            // Widget's AJAX hook
            if ( $this->admin_options['tools']['ajax'] ) {
                add_action( 'wp_ajax_wpp_get_popular', array( $this, 'get_popular') );
                add_action( 'wp_ajax_nopriv_wpp_get_popular', array( $this, 'get_popular') );
            }
    
        }
    
        /**
         * Outputs the content of the widget.
         *
         * @since	1.0.0
         * @param	array	args		The array of form elements
         * @param	array	instance	The current instance of the widget
         */
        public function widget( $args, $instance ){
            /**
             * @var string $name
             * @var string $id
             * @var string $description
             * @var string $class
             * @var string $before_widget
             * @var string $after_widget
             * @var string $before_title
             * @var string $after_title
             * @var string $widget_id
             * @var string $widget_name
             */
            extract( $args, EXTR_SKIP );
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
    
            $markup = ( $instance['markup']['custom_html'] || has_filter('wpp_custom_html') || has_filter('wpp_post') )
                  ? 'custom'
                  : 'regular';
    
            echo "\n" . $before_widget . "\n";
    
            // Has user set a title?
            if ( '' != $instance['title'] ) {
    
                $title = apply_filters( 'widget_title', $instance['title'] );
    
                if (
                    $instance['markup']['custom_html']
                    && $instance['markup']['title-start'] != ""
                    && $instance['markup']['title-end'] != ""
                ) {
                    echo htmlspecialchars_decode( $instance['markup']['title-start'], ENT_QUOTES) . $title . htmlspecialchars_decode($instance['markup']['title-end'], ENT_QUOTES );
                } else {
                    echo $before_title . $title . $after_title;
                }
            }
    
            // Expose Widget ID for customization
            $instance['widget_id'] = $widget_id;
    
            // Get posts
            if ( $this->admin_options['tools']['ajax'] && !is_customize_preview() ) {
    
                if ( empty( $before_widget ) || !preg_match( '/id="[^"]*"/', $before_widget ) ) {
                ?>
                <p><?php printf( __('Error: cannot ajaxify WordPress Popular Posts on this theme. It\'s missing the <em>id</em> attribute on before_widget (see <a href="%s" target="_blank" rel="nofollow">register_sidebar</a> for more)', 'wordpress-popular-posts'), 'https://codex.wordpress.org/Function_Reference/register_sidebar' ); ?>.</p>
                <?php
                } else {
                ?>
                <script type="text/javascript">
        window.addEventListener('DOMContentLoaded', function() {
    
            console.log( 'DOMContentLoaded' );
    
            var wpp_widget_container = document.getElementById('<?php echo $widget_id; ?>');
    
            console.log( wpp_widget_container, WordPressPopularPosts );
    
            if ( 'undefined' != typeof WordPressPopularPosts ) {
    
                console.log( 'WordPressPopularPosts found' );
    
                WordPressPopularPosts.get(
                    wpp_params.ajax_url + ( wpp_params.rest_api && 1 == wpp_params.rest_api ? 'widget' : '' ),
                    'action=wpp_get_popular&id=<?php echo $this->number; ?>',
                    function( response ){
                        wpp_widget_container.innerHTML += ( wpp_params.rest_api && 1 == wpp_params.rest_api ) ? JSON.parse( response ).widget : response;
    
                        var event = null;
    
                        if ( 'function' === typeof(Event) ) {
                            event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                        } /* Fallback for older browsers */
                        else {
                            if ( document.createEvent ) {
                                event = document.createEvent('Event');
                                event.initEvent( "wpp-onload", true, false );
                            }
                        }
    
                        if ( event ) {
                            wpp_widget_container.dispatchEvent( event );
                        }
                    }
                );
            }
        });
    </script>
                <?php
                }
            } else {
                $this->get_popular( $instance );
            }
    
            echo "\n" . $after_widget . "\n";
    
        }
    
        /**
         * Generates the administration form for the widget.
         *
         * @since	1.0.0
         * @param	array	instance	The array of keys and values for the widget.
         */
        public function form( $instance ){
    
            $instance = WPP_Helper::merge_array_r(
                WPP_Settings::$defaults[ 'widget_options' ],
                (array) $instance
            );
            $wpp_image = WPP_Image::get_instance();
    
            include( plugin_dir_path( __FILE__ ) . '/widget-form.php' );
    
        }
    
        /**
         * Processes the widget's options to be saved.
         *
         * @since	1.0.0
         * @param	array	new_instance	The previous instance of values before the update.
         * @param	array	old_instance	The new instance of values to be generated via the update.
         * @return	array	instance		Updated instance.
         */
        public function update( $new_instance, $old_instance ){
    
            $wpp_image = WPP_Image::get_instance();
    
            $instance = $old_instance;
    
            $instance['title'] = htmlspecialchars( stripslashes_deep(strip_tags( $new_instance['title'] )), ENT_QUOTES );
            $instance['limit'] = ( WPP_Helper::is_number($new_instance['limit']) && $new_instance['limit'] > 0 )
              ? $new_instance['limit']
              : 10;
            $instance['range'] = $new_instance['range'];
            $instance['time_quantity'] = ( WPP_Helper::is_number($new_instance['time_quantity']) && $new_instance['time_quantity'] > 0 )
              ? $new_instance['time_quantity']
              : 24;
            $instance['time_unit'] = $new_instance['time_unit'];
            $instance['order_by'] = $new_instance['order_by'];
    
            // FILTERS
            // user did not set a post type name, so we fall back to default
            $instance['post_type'] = ( '' == $new_instance['post_type'] )
              ? 'post,page'
              : $new_instance['post_type'];
    
            $instance['freshness'] = isset( $new_instance['freshness'] );
    
            // Post / Page / CTP filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['pid'] = '';
            }
            else {
                $instance['pid'] = implode( ",", $ids );
            }
    
            // Taxonomy filter
            $instance['taxonomy'] = $new_instance['taxonomy'];
            $instance['cat'] = ''; // Deprecated in 4.0.0!
    
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,-]|', '', $new_instance['term_id'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['term_id'] = '';
            }
            else {
                $instance['term_id'] = implode( ",", $ids );
            }
    
            // Author filter
            $ids = array_filter( explode( ",", rtrim(preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ), ",") ), 'is_numeric' );
            // Got no valid IDs, clear
            if ( empty( $ids ) ) {
                $instance['author'] = '';
            }
            else {
                $instance['author'] = implode( ",", $ids );
            }
    
            $instance['shorten_title']['words'] = $new_instance['shorten_title-words'];
            $instance['shorten_title']['active'] = isset( $new_instance['shorten_title-active'] );
            $instance['shorten_title']['length'] = ( WPP_Helper::is_number($new_instance['shorten_title-length']) && $new_instance['shorten_title-length'] > 0 )
              ? $new_instance['shorten_title-length']
              : 25;
    
            $instance['post-excerpt']['keep_format'] = isset( $new_instance['post-excerpt-format'] );
            $instance['post-excerpt']['words'] = $new_instance['post-excerpt-words'];
            $instance['post-excerpt']['active'] = isset( $new_instance['post-excerpt-active'] );
            $instance['post-excerpt']['length'] = ( WPP_Helper::is_number($new_instance['post-excerpt-length']) && $new_instance['post-excerpt-length'] > 0 )
              ? $new_instance['post-excerpt-length']
              : 55;
    
            $instance['thumbnail']['active'] = false;
            $instance['thumbnail']['width'] = 15;
            $instance['thumbnail']['height'] = 15;
    
            // can create thumbnails
            if ( $wpp_image->can_create_thumbnails() ) {
    
                $instance['thumbnail']['active'] = isset( $new_instance['thumbnail-active'] );
                $instance['thumbnail']['build'] = $new_instance['thumbnail-size-source'];
    
                // Use predefined thumbnail sizes
                if ( 'predefined' == $new_instance['thumbnail-size-source'] ) {
    
                    $default_thumbnail_sizes = $wpp_image->get_image_sizes();
                    $size = $default_thumbnail_sizes[ $new_instance['thumbnail-size'] ];
    
                    $instance['thumbnail']['width'] = $size['width'];
                    $instance['thumbnail']['height'] = $size['height'];
                    $instance['thumbnail']['crop'] = $size['crop'];
    
                } // Set thumbnail size manually
                else {
                    if ( WPP_Helper::is_number($new_instance['thumbnail-width']) && WPP_Helper::is_number($new_instance['thumbnail-height']) ) {
                        $instance['thumbnail']['width'] = $new_instance['thumbnail-width'];
                        $instance['thumbnail']['height'] = $new_instance['thumbnail-height'];
                        $instance['thumbnail']['crop'] = true;
                    }
                }
    
            }
    
            $instance['rating'] = isset( $new_instance['rating'] );
            $instance['stats_tag']['comment_count'] = isset( $new_instance['comment_count'] );
            $instance['stats_tag']['views'] = isset( $new_instance['views'] );
            $instance['stats_tag']['author'] = isset( $new_instance['author'] );
            $instance['stats_tag']['date']['active'] = isset( $new_instance['date'] );
            $instance['stats_tag']['date']['format'] = empty($new_instance['date_format'])
              ? 'F j, Y'
              : $new_instance['date_format'];
    
            $instance['stats_tag']['taxonomy']['active'] = isset( $new_instance['stats_taxonomy'] );
            $instance['stats_tag']['taxonomy']['name'] = isset( $new_instance['stats_taxonomy_name'] ) ? $new_instance['stats_taxonomy_name'] : 'category';
            $instance['stats_tag']['category'] = isset( $new_instance['stats_taxonomy'] ); // Deprecated in 4.0.0!
    
            $instance['markup']['custom_html'] = isset( $new_instance['custom_html'] );
            $instance['markup']['wpp-start'] = empty($new_instance['wpp-start'])
              ? htmlspecialchars( '<ul class="wpp-list">', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-start'], ENT_QUOTES );
    
            $instance['markup']['wpp-end'] = empty($new_instance['wpp-end'])
              ? htmlspecialchars( '</ul>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['wpp-end'], ENT_QUOTES );
    
            $instance['markup']['post-html'] = empty($new_instance['post-html'])
              ? htmlspecialchars( '<li>{thumb} {title} {stats}</li>', ENT_QUOTES )
              : htmlspecialchars( $new_instance['post-html'], ENT_QUOTES );
    
            $instance['markup']['title-start'] = empty($new_instance['title-start'])
              ? ''
              : htmlspecialchars( $new_instance['title-start'], ENT_QUOTES );
    
            $instance['markup']['title-end'] = empty($new_instance['title-end'])
              ? '' :
              htmlspecialchars( $new_instance['title-end'], ENT_QUOTES );
    
            return $instance;
    
        }
    
        /**
         * Returns HTML list via AJAX
         *
         * @since	2.3.3
         */
        public function get_popular( $instance = null ) {
    
            if ( defined('DOING_AJAX') && DOING_AJAX ) {
    
                if ( isset( $_GET['id'] ) && WPP_helper::is_number( $_GET['id'] ) ) {
    
                    $id = $_GET['id'];
                    $widget_instances = $this->get_settings();
    
                    if ( isset( $widget_instances[$id] ) ) {
                        $instance = $widget_instances[$id];
    
                        if ( !isset( $instance['widget_id'] ) ) {
                            $instance['widget_id'] = $this->id;
                        }
                    }
    
                }
    
            }
    
            if ( is_array( $instance ) && !empty( $instance ) ) {
    
                // Return cached results
                if ( $this->admin_options['tools']['cache']['active'] ) {
    
                    $transient_name = md5( json_encode($instance) );
                    $popular_posts = get_transient( $transient_name );
    
                    if ( false === $popular_posts ) {
    
                        $popular_posts = new WPP_Query( $instance );
    
                        switch( $this->admin_options['tools']['cache']['interval']['time'] ){
    
                            case 'minute':
                                $time = 60;
                            break;
    
                            case 'hour':
                                $time = 60 * 60;
                            break;
    
                            case 'day':
                                $time = 60 * 60 * 24;
                            break;
    
                            case 'week':
                                $time = 60 * 60 * 24 * 7;
                            break;
    
                            case 'month':
                                $time = 60 * 60 * 24 * 30;
                            break;
    
                            case 'year':
                                $time = 60 * 60 * 24 * 365;
                            break;
    
                            default:
                                $time = 60 * 60;
                            break;
    
                        }
    
                        $expiration = $time * $this->admin_options['tools']['cache']['interval']['value'];
    
                        // Store transient
                        set_transient( $transient_name, $popular_posts, $expiration );
    
                        // Store transient in WPP transients array for garbage collection
                        $wpp_transients = get_option('wpp_transients');
    
                        if ( !$wpp_transients ) {
                            $wpp_transients = array( $transient_name );
                            add_option( 'wpp_transients', $wpp_transients );
                        } else {
                            if ( !in_array($transient_name, $wpp_transients) ) {
                                $wpp_transients[] = $transient_name;
                                update_option( 'wpp_transients', $wpp_transients );
                            }
                        }
    
                    }
    
                } // Get popular posts
                else {
                    $popular_posts = new WPP_Query( $instance );
                }
    
                $output = new WPP_Output( $popular_posts->get_posts(), $instance );
    
                echo ( $this->admin_options['tools']['cache']['active'] ? '<!-- cached -->' : '' );
                $output->output();
    
            }
    
            if (
                defined('DOING_AJAX') 
                && DOING_AJAX && !is_preview() 
                && !( is_singular() && isset( $_GET['fl_builder'] ) )
            ) {
                wp_die();
            }
    
        }
    
    } // end class WPP_Widget
    Plugin Author Hector Cabrera

    (@hcabrera)

    Something not right, then. Is Comet Cache enabled? This is what I see when I check your site’s source code:

    ktsiterip

    (@ktsiterip)

    Hi Hector!
    No comet cache is off – I’ll empty cloudflare cache, see if that makes a difference
    Edit – oddly enough its showing correctly on Chrome, but not on FF

    Chrome:

    event = new Event( "wpp-onload", {"bubbles": true, "cancelable": false} );
                        } /* Fallback for older browsers */
                        else {

    FF
    } // Fallback for older browsers else {

    • This reply was modified 3 months ago by  ktsiterip.
    • This reply was modified 3 months ago by  ktsiterip.
Viewing 15 replies - 16 through 30 (of 53 total)
  • You must be logged in to reply to this topic.