Plugin Directory

Changeset 1754497


Ignore:
Timestamp:
10/28/2017 06:37:24 PM (8 years ago)
Author:
mathewemoore
Message:

1.0.2

  • Feature: added backend settings menu
  • Feature: added option to choose post types to use
  • Feature: added option to change number of 'posts_per_page' in AJAX calls
  • Feature: added WYSIWYG option to append custom content to AJAX calls
  • Feature: added WordPress default admin notices
  • Change: now using native WordPress spinner gif for AJAX calls
  • Change: adjusted AJAX output for mobile devices in case no sidebars active
  • Change: remove default GeneratePress blog pagination when plugin is enabled
  • Fix: prefixed plugin class variables
Location:
infinite-scroll-generatepress
Files:
3 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • infinite-scroll-generatepress/trunk/css/style.css

    r1752187 r1754497  
    11#matts_inf_scroll_loading {
    2   background-image: url('../images/loading.gif');
    3   background-size: 40px 40px;
     2  background-image: url('/wp-includes/images/spinner-2x.gif');
     3  background-size: 30px 30px;
    44  background-position: center;
    55  background-repeat: no-repeat;
  • infinite-scroll-generatepress/trunk/gp_infinite_scroll.php

    r1752187 r1754497  
    44* Plugin URI: https://northwoodsdigital.com/
    55* Description: A very lightweight infinite scroll plugin for your blog running the GeneratePress Theme by Tom Usborne. Just install and activate this plugin to enable infinite scroll on your blog.
    6 * Version: 1.0.1
     6* Version: 1.0.2
    77* Author: Mathew Moore
    88* Author URI: https://profiles.wordpress.org/mathewemoore
     
    2828if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    2929
    30 if ( !class_exists( 'Matts_Infinite_Scroll_Plugin' ) ) {
    31   class Matts_Infinite_Scroll_Plugin
     30if ( !class_exists( 'Infinite_Scroll_GeneratePress' ) ) {
     31  class Infinite_Scroll_GeneratePress
    3232  {
    3333    // Setup some global variables to use throughout this plugin
    34     private $post_type = 'post';
    35     private $posts_per_page = '2';
     34    private $post_types;
     35    private $posts_per_page;
     36    private $ifsg_options;
    3637
    3738    public function __construct()
    3839    {
     40      $this->ifsg_options = get_option( 'ifsg_settings' );
     41      $this->post_types = (!empty($this->ifsg_options['ifsg_text_field_0']) ? $this->ifsg_options['ifsg_text_field_0'] : '');
     42      $this->posts_per_page = $this->ifsg_options['ifsg_text_field_1'];
    3943      // Include( INF_SCROLL_PLUGIN_DIR . 'js/ajax-loader.js');
    40       add_action('wp_enqueue_scripts', array($this,'matt_infinite_scroll'));
     44      add_action('wp_enqueue_scripts', array($this,'ifsg_wp_enqueue_scripts'));
    4145      // Ajax for Larger Screens
    4246      add_action( 'wp_ajax_nopriv_post_template_load', array($this, 'post_template_load' ));
     
    4549      add_action( 'wp_ajax_nopriv_post_template_load_small', array($this, 'post_template_load_small' ));
    4650      add_action( 'wp_ajax_post_template_load_small', array($this, 'post_template_load_small' ));
     51      // Add WordPress Buitin Admin Notices
     52      add_action( 'admin_notices', array($this, 'isgp_default_admin_notices' ));
     53      add_action('wp_head', array($this, 'isgp_remove_paging_navigation'));
     54
    4755      // Setup the Plugin Directory Location
    48       define( 'PLUGIN_DIR', plugin_dir_url( __FILE__ ) );
    49       define( 'TEMPLATE_DIR', get_template_directory_uri() );
    50     }
    51     public function matt_infinite_scroll()
     56      if ( ! defined( 'INF_SCROLL_GP' ))  {
     57        define( 'INF_SCROLL_GP', plugin_dir_url( __FILE__ ) );
     58      }
     59      require_once( dirname(__FILE__) . '/admin/settings.php');
     60    }
     61
     62    public function isgp_default_admin_notices()
     63    {
     64      settings_errors();
     65    }
     66
     67    public function isgp_remove_paging_navigation(){
     68      if (!empty($this->ifsg_options['ifsg_text_field_0']) & !empty($this->ifsg_options['ifsg_text_field_1'])){
     69        echo '<style type="text/css">.paging-navigation {display: none;}</style>';
     70      }
     71    }
     72
     73    public function infinite_scroll_total_posts()
     74    {
     75      // function to get total number of published posts for the specified post types
     76      if (!empty($this->ifsg_options['ifsg_text_field_1'])){
     77        $totalcount = array();
     78          foreach ($this->post_types as $post_type)
     79          {
     80            $post_count = wp_count_posts($post_type);
     81            $totalcount[] = $post_count->publish;
     82          }
     83          return array_sum($totalcount);
     84      } else {return '0';}
     85    }
     86
     87    public function ifsg_wp_enqueue_scripts()
    5288    {
    5389      if ( is_home() ) { // Run this script on the blog page only
    5490        // Load CSS & Javascript Assets
    55         wp_register_style('matt_infinite_scroll_css',  PLUGIN_DIR . 'css/style.css', '1.0.0', true);
    56         wp_enqueue_style('matt_infinite_scroll_css');
    57 
    58         wp_register_script('matt_infinite_scroll',  PLUGIN_DIR . 'js/ajax-loader.js', array('jquery'), '1.0.0', true);
    59         wp_enqueue_script('matt_infinite_scroll');
    60 
    61         $count_posts = wp_count_posts($this->post_type);
    62         $published_posts = $count_posts->publish;
    63 
    64         wp_localize_script( 'matt_infinite_scroll', 'matt_inf_scroll', array(
     91        wp_register_style('ifsg_plugin_css',  INF_SCROLL_GP . 'css/style.css', '1.0.0', true);
     92        wp_enqueue_style('ifsg_plugin_css');
     93
     94        wp_register_script('ifsg_plugin_scripts',  INF_SCROLL_GP . 'js/ajax-loader.js', array('jquery'), '1.0.0', true);
     95        wp_enqueue_script('ifsg_plugin_scripts');
     96
     97        echo '<input type="hidden" name="inf_scroll_gp_ajax_nonce" id="inf_scroll_gp_ajax_nonce" value="' . wp_create_nonce( 'inf_scroll_gp_ajax_nonce' ) . '" />';
     98
     99        wp_localize_script( 'ifsg_plugin_scripts', 'ifsg_ajax_scripts', array(
    65100          'ajax_url' => admin_url( 'admin-ajax.php' ),
    66101          'plugins_url' => plugins_url( '/', __FILE__ ),
    67           'total_posts' => $published_posts,
     102          'total_posts' => $this->infinite_scroll_total_posts(),
    68103        ));
    69104      }
    70105    }
     106
    71107    public function post_template_load(){ // Larger Screens
     108      // Verify AJAX nonce or die
     109      check_ajax_referer( 'inf_scroll_gp_ajax_nonce', 'security' );
     110
    72111        $offset = esc_html($_POST['offset']);
    73         $count_posts = wp_count_posts($this->post_type);
     112        // $count_posts = wp_count_posts($this->post_type);
    74113
    75114        // WP_Query arguments
     
    77116
    78117        $args = array(
    79             'post_type'    => array( $this->post_type ),
     118            'post_type'    => $this->post_types,
    80119            'post_status'  => array( 'publish' ),
    81120            'order'        => 'DESC',
     
    99138        // Restore original Post Data
    100139        wp_reset_postdata();
    101         /* ?>
    102           <?php
    103140          // Custom Content Block 1
    104           <div class="inside-article inf_ad_block">
    105           </div>
    106           ?>
    107         <?php */
     141
     142          if ( !empty($this->ifsg_options['ifsg_text_field_2'] ) ) { ?>
     143
     144              <div class="inside-article inf_ad_block">
     145              <?php echo $this->ifsg_options['ifsg_text_field_2']; ?>
     146              </div>
     147
     148            <?php
     149          }
    108150      }
    109151    die();
    110152    }
    111153    public function post_template_load_small(){ // Small screens
     154      // Verify AJAX nonce or die
     155      check_ajax_referer( 'inf_scroll_gp_ajax_nonce', 'security' );
     156
    112157        $offset = esc_html($_POST['offset']);
    113         $count_posts = wp_count_posts($this->post_type);
     158        // $count_posts = wp_count_posts($this->post_type);
    114159
    115160        // WP_Query arguments
     
    117162
    118163        $args = array(
    119           'post_type'    => array( $this->post_type ),
     164          'post_type'    => $this->post_types,
    120165          'post_status'  => array( 'publish' ),
    121166          'order'        => 'DESC',
     
    137182          }
    138183        } else {
     184          return false;
    139185          // no posts found
    140186        }
    141187        // Restore original Post Data
    142188        wp_reset_postdata();
    143         /* ?>
    144           <?php
    145189          // Custom Content Block 1
    146           <div class="inside-article inf_ad_block">
    147           </div>
    148           ?>
    149         <?php */
     190
     191          if ( !empty($this->ifsg_options['ifsg_text_field_2'] ) ) { ?>
     192
     193              <div class="inside-article inf_ad_block">
     194              <?php echo $this->ifsg_options['ifsg_text_field_2']; ?>
     195              </div>
     196
     197            <?php
     198          }
    150199      }
    151200    die();
     
    153202  }
    154203
    155 $Matts_Infinite_Scroll_Plugin = new Matts_Infinite_Scroll_Plugin();
     204$Infinite_Scroll_GeneratePress = new Infinite_Scroll_GeneratePress();
    156205}
  • infinite-scroll-generatepress/trunk/js/ajax-loader.js

    r1752187 r1754497  
    1 var matt_inf_scroll_processing;
     1var ifsg_ajax_scripts_processing;
    22
    33jQuery(document).ready(function($) {
     
    55      $(window).scroll(function() {
    66
    7         if (matt_inf_scroll_processing)
     7        if (ifsg_ajax_scripts_processing)
    88          return false;
    99
    10           if( ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.85) && matt_inf_scroll.total_posts > $('.type-post').size() ) {
    11                 matt_inf_scroll_processing = true;
    12                 var last_id = $(".type-post:last").attr("id");
    13                 var last_id_small = $(".type-post:last").attr("id");
     10          if( ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.85) && ifsg_ajax_scripts.total_posts > $('article').size() ) {
     11                ifsg_ajax_scripts_processing = true;
     12
     13                var last_id = $('article').attr("id");
     14                var last_id_small = $('article').attr("id");
    1415                // loadMoreData(last_id);
    1516                if ( $(window).width() > 768) {
    1617                  // processing = true;
    17                   //Add your javascript for large screens here
     18                  // javascript for large screens here
    1819                  loadMoreData(last_id);
    1920                  // loadMoreDataSmall(last_id_small);
     
    2122                else {
    2223                  // processing = true;
    23                   //Add your javascript for small screens here
     24                  // javascript for small screens here
    2425                  loadMoreDataSmall(last_id_small);
    2526                }
     
    3031      $.ajax(
    3132            {
    32                 url: matt_inf_scroll.ajax_url,
     33                url: ifsg_ajax_scripts.ajax_url,
    3334                type : 'post',
    3435                data : {
    3536                  action : 'post_template_load',
     37                  security: $( '#inf_scroll_gp_ajax_nonce' ).val(),
    3638                  post_id : last_id,
    37                   offset : $('.type-post').size(),
     39                  offset : $('article').size(),
    3840                },
    3941                beforeSend: function(response)
     
    4345                success: function( response ) {
    4446                        $('#matts_inf_scroll_loading').remove();
    45                         $('.site-main').append(response);
    46                     matt_inf_scroll_processing = false;
    47                     console.log($('.type-post').size());
    48                 }
     47                    if(response) { // check for non-empty response
     48                      $('#main').append(response);
     49                      ifsg_ajax_scripts_processing = false;
     50                    }
     51                    else {
     52                      ifsg_ajax_scripts_processing = true;
     53                    }
     54                },
    4955              });
    5056          return false;
     
    5460      $.ajax(
    5561            {
    56                 url: matt_inf_scroll.ajax_url,
     62                url: ifsg_ajax_scripts.ajax_url,
    5763                type : 'post',
    5864                data : {
    5965                  action : 'post_template_load_small',
     66                  security: $( '#inf_scroll_gp_ajax_nonce' ).val(),
    6067                  post_id : last_id_small,
    61                   offset : $('.type-post').size(),
     68                  offset : $('article').size(),
    6269                },
    6370                beforeSend: function(response)
     
    6774                success: function( response ) {
    6875                    $('#matts_inf_scroll_loading').remove();
    69                     $('.inside-right-sidebar').append(response);
    70                     matt_inf_scroll_processing = false;
    71                     console.log($('.type-post').size());
     76                    if(response) { // check for non-empty response
     77                      $('#content').children('div:last').append(response);
     78                      ifsg_ajax_scripts_processing = false;
     79                    }
     80                    else {
     81                      ifsg_ajax_scripts_processing = true;
     82                    }
    7283                }
    7384            });
  • infinite-scroll-generatepress/trunk/readme.txt

    r1752187 r1754497  
    1 === Infinite Scroll for GeneratePress ===
     1=== Infinite Scroll for GeneratePress ===
    22Contributors: mathewemoore
    33Tags: generatepress, infinite scroll
     
    66Tested up to: 4.8.2
    77Requires PHP: 5.6
    8 Stable tag: 1.0.1
     8Stable tag: 1.0.2
    99License: GPLv2 or later
    1010
     
    1414
    1515Infinite Scroll for GeneratePress is a super lightweight plugin to enable infinite scroll functionality on your WordPress blog running the GeneratePress theme.
     16
     17[youtube https://youtu.be/NueysU2XLlc ]
    1618
    1719[→ Get More Information](https://northwoodsdigital.com/plugins/generatepress-infinite-scroll)
     
    3941* Click 'Install Now'
    4042* Activate the plugin
     43* Visit the plugin settings page from the WordPress Dashboard and enable your options
    4144
    4245= Uploading in WordPress Dashboard =
     
    4447* Navigate to 'Add New' in the plugins dashboard
    4548* Navigate to the 'Upload' section
    46 3. Select `generatepress-infinite-scroll.zip` from your computer
     493. Select `infinite-scroll-generatepress.zip` from your computer
    47504. Click 'Install Now'
    48515. Activate the plugin in the Plugin dashboard
     526. Visit the plugin settings page from the WordPress Dashboard and enable your options
    4953
    5054= Using FTP =
    5155
    52561. Download `generatepress-infinite-scroll.zip`
    53 2. Extract the `generatepress-infinite-scroll.zip` directory to your computer
    54 3. Upload the `generatepress-infinite-scroll.zip` directory to the `/wp-content/plugins/` directory
     572. Extract the `infinite-scroll-generatepress.zip` directory to your computer
     583. Upload the `infinite-scroll-generatepress.zip` directory to the `/wp-content/plugins/` directory
    55594. Activate the plugin in the Plugin dashboard
     606. Visit the plugin settings page from the WordPress Dashboard and enable your options
    5661
    5762== Frequently Asked Questions ==
     
    5964[→ Contact Me](https://northwoodsdigital.com/contact)
    6065
     66== Screenshots ==
     67
     681. Admin Settings for Infinite Scroll GenereatePress
     69
    6170== Changelog ==
     71
     72= 1.0.2 =
     73
     74* Feature: added backend settings menu
     75* Feature: added option to choose post types to use
     76* Feature: added option to change number of 'posts_per_page' in AJAX calls
     77* Feature: added WYSIWYG option to append custom content to AJAX calls
     78* Feature: added WordPress default admin notices
     79
     80* Change: now using native WordPress spinner gif for AJAX calls
     81* Change: adjusted AJAX output for mobile devices in case no sidebars active
     82* Change: remove default GeneratePress blog pagination when plugin is enabled
     83
     84* Fix: prefixed plugin class variables
    6285
    6386= 1.0.1 =
     
    6891== Upgrade Notice ==
    6992
     93= 1.0.2 =
     94Visit the plugin settings page from the WordPress Dashboard and enable your options after updating.
     95
    7096* None
Note: See TracChangeset for help on using the changeset viewer.