WordPress Infinite Scroll – Ajax Load More - Version 2.0.5

Version Description

  • Updating db table structure
  • Adding upgrader_process_complete checker
Download this release

Release Info

Developer dcooney
Plugin Icon 128x128 WordPress Infinite Scroll – Ajax Load More
Version 2.0.5
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.5

Files changed (4) hide show
  1. README.txt +9 -1
  2. admin/admin.php +70 -44
  3. ajax-load-more.php +20 -29
  4. core/repeater/default.php +1 -1
README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://connekthq.com/donate/
4
  Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category
5
  Requires at least: 3.6
6
  Tested up to: 3.9.1
7
- Stable tag: 2.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -134,6 +134,14 @@ How to install Ajax Load More.
134
 
135
  == Changelog ==
136
 
 
 
 
 
 
 
 
 
137
  = 2.0.3 =
138
  * Fixed issue with WP auto updates overriding the default repeater. Please deactivate and then activate your plugin.
139
 
4
  Tags: ajax, query, loop, paging, filter, jquery, shortcode builder, shortcode, search, tags, category
5
  Requires at least: 3.6
6
  Tested up to: 3.9.1
7
+ Stable tag: 2.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
134
 
135
  == Changelog ==
136
 
137
+ = 2.0.5 =
138
+ * Updating db table structure
139
+ * Adding upgrader_process_complete checker
140
+
141
+ = 2.0.4 =
142
+ * Adding plugin version to wpdb table.
143
+ * Removed legacy repeater code.
144
+
145
  = 2.0.3 =
146
  * Fixed issue with WP auto updates overriding the default repeater. Please deactivate and then activate your plugin.
147
 
admin/admin.php CHANGED
@@ -2,11 +2,62 @@
2
 
3
  /* Admin function */
4
 
5
-
6
  add_action( 'admin_head', 'alm_admin_vars' );
7
  add_action( 'wp_ajax_alm_save_repeater', 'alm_save_repeater' ); // Ajax Save Repeater
8
  add_action( 'wp_ajax_nopriv_alm_save_repeater', 'alm_save_repeater' ); // Ajax Save Repeater
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  /*
11
  * alm_admin_vars
12
  * Create admin variables and ajax nonce
@@ -25,36 +76,6 @@ function alm_admin_vars() { ?>
25
  <?php }
26
 
27
 
28
-
29
- /**
30
- * alm_update_default
31
- * Update default repeater if plugin versions do not match. This means the plugin has been updated.
32
- *
33
- * @since 2.0.0
34
- */
35
-
36
- add_action( 'admin_init', 'alm_update_default' );
37
- function alm_update_default() {
38
- global $wpdb;
39
- $table_name = $wpdb->prefix . "alm";
40
-
41
- //If alm table is present
42
- if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
43
- $version = $wpdb->get_var("SELECT pluginVersion FROM $table_name WHERE id = 1");
44
-
45
- if($version != ALM_VERSION){
46
- //Write to repeater file
47
- $defaultRepeater = $wpdb->get_var("SELECT repeaterDefault FROM $table_name WHERE id = 1");
48
- $f = ALM_PATH. '/core/repeater/default.php'; // File
49
- $o = fopen($f, 'w+'); //Open file
50
- $w = fwrite($o, $defaultRepeater); //Save the file
51
- $r = fread($o, 100000); //Read it
52
- fclose($o); //now close it
53
- }
54
- }
55
-
56
-
57
- }
58
  /**
59
  * alm_admin_menu
60
  * Create Admin Menu
@@ -68,7 +89,7 @@ function alm_admin_menu() {
68
  $icon = ALM_ADMIN_URL . "/img/alm-logo-16x16.png";
69
  add_menu_page( 'Ajax Load More', 'Ajax Load More', 'edit_theme_options', 'ajax-load-more', 'alm_settings_page', $icon, 81 );
70
  add_submenu_page( 'ajax-load-more', 'Settings', 'Settings', 'edit_theme_options', 'ajax-load-more', 'alm_settings_page');
71
- add_submenu_page( 'ajax-load-more', 'Repeaters', 'Repeaters', 'edit_theme_options', 'ajax-load-more-repeaters', 'alm_repeater_page');
72
  add_submenu_page( 'ajax-load-more', 'Shortcode Builder', 'Shortcode Builder', 'edit_theme_options', 'ajax-load-more-shortcode-builder', 'alm_shortcode_builder_page');
73
  add_submenu_page( 'ajax-load-more', 'Examples', 'Examples', 'edit_theme_options', 'ajax-load-more-examples', 'alm_example_page');
74
  add_submenu_page( 'ajax-load-more', 'Add-ons', 'Add-ons', 'edit_theme_options', 'ajax-load-more-add-ons', 'alm_add_ons_page');
@@ -128,8 +149,8 @@ function alm_repeater_page(){ ?>
128
  <div class="admin ajax-load-more" id="alm-repeaters">
129
  <div class="wrap">
130
  <div class="header-wrap">
131
- <h2><?php _e('Ajax load More: Repeaters', ALM_NAME); ?></h2>
132
- <p><?php _e('The library of available repeaters', ALM_NAME); ?></p>
133
  </div>
134
  <div class="alm-main form-table repeaters">
135
  <!-- Repeaters -->
@@ -142,16 +163,16 @@ function alm_repeater_page(){ ?>
142
  $contents = fread ($handle, filesize ($filename));
143
  fclose ($handle);
144
  ?>
145
- <h3 class="heading"><?php _e('Default Repeater', ALM_NAME); ?></h3>
146
  <div class="expand-wrap">
147
  <div class="section-title">
148
- <p><?php _e('Enter the HTML and PHP for the default repeater.', ALM_NAME); ?></p>
149
  </div>
150
  <div class="wrap repeater-wrap" data-name="default">
151
  <div class="textarea-wrap">
152
  <textarea rows="10" class="_alm_repeater"><?php echo $contents; ?></textarea>
153
  </div>
154
- <input type="submit" value="Save Repeater" class="button button-primary save-repeater">
155
  <div class="saved-response">&nbsp;</div>
156
  <!-- <div class="restore-default"><a href="javascript:void(0);"><?php _e('Restore Default', ALM_NAME); ?></a></div> -->
157
  </div>
@@ -234,7 +255,7 @@ function alm_repeater_page(){ ?>
234
  </div>
235
  <aside class="alm-sidebar">
236
  <div class="cta">
237
- <h3><?php _e('Repeater Help', ALM_NAME); ?></h3>
238
  <?php
239
  global $wpdb;
240
 
@@ -243,17 +264,17 @@ function alm_repeater_page(){ ?>
243
 
244
  ?>
245
  <div class="item">
246
- <p><strong><?php _e('What is a repeater?', ALM_NAME); ?></strong></p>
247
- <p><?php _e('A repeater is a snippet of code that will execute over and over within a <a href="http://codex.wordpress.org/The_Loop" target="_blank">WordPress loop</a>.</p>', ALM_NAME); ?></p>
248
  </div>
249
  <div class="item">
250
- <p><strong><?php _e('Can I include PHP in the repeater?', ALM_NAME); ?></strong></p>
251
  <p><?php _e('Yes, PHP and core WordPress functions such as, <code>the_title()</code> and <code>the_permalink()</code> are required.</p>', ALM_NAME); ?></p>
252
  </div>
253
  <div class="item">
254
  <p><strong><?php _e('Tips and Tricks', ALM_NAME); ?></strong></p>
255
  <ul>
256
- <li><?php _e('Always open and close your repeater with an HTML element. In some rare cases data may not be displayed.<br/>e.g. <code>&lt;li> &lt;/li></code> or <code>&lt;div> &lt;/div></code>', ALM_NAME); ?><br/> </li>
257
  </ul>
258
  </div>
259
  </div>
@@ -295,8 +316,13 @@ function alm_save_repeater(){
295
  //Save to database
296
  global $wpdb;
297
  $table_name = $wpdb->prefix . "alm";
298
- $data_update = array('repeaterDefault' => "$c", 'pluginVersion' => ALM_VERSION);
299
- $data_where = array('id' => "1");
 
 
 
 
 
300
  $wpdb->update($table_name , $data_update, $data_where);
301
 
302
  //Our results
2
 
3
  /* Admin function */
4
 
 
5
  add_action( 'admin_head', 'alm_admin_vars' );
6
  add_action( 'wp_ajax_alm_save_repeater', 'alm_save_repeater' ); // Ajax Save Repeater
7
  add_action( 'wp_ajax_nopriv_alm_save_repeater', 'alm_save_repeater' ); // Ajax Save Repeater
8
 
9
+
10
+ /**
11
+ * alm_core_update
12
+ * Update default repeater on plugin update.
13
+ * Add 'name' column if it doesnt exist.
14
+ * If plugin versions do not match the plugin has been updated and we need to update our repeaters.
15
+ *
16
+ * @since 2.0.5
17
+ */
18
+
19
+ add_action('upgrader_process_complete', 'alm_core_update');
20
+ function alm_core_update() {
21
+ global $wpdb;
22
+ $table_name = $wpdb->prefix . "alm";
23
+
24
+ //If alm table exists
25
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
26
+
27
+ // Updated 2.0.5
28
+ // Check column 'name' exists in $wpdb - this is an upgrade checker.
29
+ $row = $wpdb->get_results("SELECT COLUMN_NAME FROM $table_name.COLUMNS WHERE column_name = 'name'");
30
+ if(empty($row)){
31
+ $wpdb->query("ALTER TABLE $table_name ADD name TEXT NOT NULL");
32
+ $wpdb->update($table_name , array('name' => 'default'), array('id' => 1));
33
+ }
34
+
35
+ // ********
36
+ // @TO-DO
37
+ // ********
38
+ // Upgrade test, will remove in future versions
39
+ $row2 = $wpdb->get_results("SELECT COLUMN_NAME FROM $table_name.COLUMNS WHERE column_name = 'test'");
40
+ if(empty($row2)){
41
+ $wpdb->query("ALTER TABLE $table_name ADD test TEXT NOT NULL");
42
+ $wpdb->update($table_name , array('test' => 'test value'), array('id' => 1));
43
+ }
44
+
45
+
46
+ // Compare versions of repeaters, if template versions do not match, update the repeater with value from DB
47
+ $version = $wpdb->get_var("SELECT pluginVersion FROM $table_name WHERE name = 'default'");
48
+ if($version != ALM_VERSION){ // First, make sure versions do not match.
49
+ //Write to repeater file
50
+ $data = $wpdb->get_var("SELECT repeaterDefault FROM $table_name WHERE name = 'default'");
51
+ $f = ALM_PATH. '/core/repeater/default.php'; // File
52
+ $o = fopen($f, 'w+'); //Open file
53
+ $w = fwrite($o, $data); //Save the file
54
+ $r = fread($o, 100000); //Read it
55
+ fclose($o); //now close it
56
+ }
57
+ }
58
+ }
59
+
60
+
61
  /*
62
  * alm_admin_vars
63
  * Create admin variables and ajax nonce
76
  <?php }
77
 
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  /**
80
  * alm_admin_menu
81
  * Create Admin Menu
89
  $icon = ALM_ADMIN_URL . "/img/alm-logo-16x16.png";
90
  add_menu_page( 'Ajax Load More', 'Ajax Load More', 'edit_theme_options', 'ajax-load-more', 'alm_settings_page', $icon, 81 );
91
  add_submenu_page( 'ajax-load-more', 'Settings', 'Settings', 'edit_theme_options', 'ajax-load-more', 'alm_settings_page');
92
+ add_submenu_page( 'ajax-load-more', 'Repeater Templates', 'Repeater Templates', 'edit_theme_options', 'ajax-load-more-repeaters', 'alm_repeater_page');
93
  add_submenu_page( 'ajax-load-more', 'Shortcode Builder', 'Shortcode Builder', 'edit_theme_options', 'ajax-load-more-shortcode-builder', 'alm_shortcode_builder_page');
94
  add_submenu_page( 'ajax-load-more', 'Examples', 'Examples', 'edit_theme_options', 'ajax-load-more-examples', 'alm_example_page');
95
  add_submenu_page( 'ajax-load-more', 'Add-ons', 'Add-ons', 'edit_theme_options', 'ajax-load-more-add-ons', 'alm_add_ons_page');
149
  <div class="admin ajax-load-more" id="alm-repeaters">
150
  <div class="wrap">
151
  <div class="header-wrap">
152
+ <h2><?php _e('Ajax load More: Repeater Templates', ALM_NAME); ?></h2>
153
+ <p><?php _e('The library of available templates to use throughout your theme', ALM_NAME); ?></p>
154
  </div>
155
  <div class="alm-main form-table repeaters">
156
  <!-- Repeaters -->
163
  $contents = fread ($handle, filesize ($filename));
164
  fclose ($handle);
165
  ?>
166
+ <h3 class="heading"><?php _e('Default Repeater Template', ALM_NAME); ?></h3>
167
  <div class="expand-wrap">
168
  <div class="section-title">
169
+ <p><?php _e('Enter the HTML and PHP for the default template.', ALM_NAME); ?></p>
170
  </div>
171
  <div class="wrap repeater-wrap" data-name="default">
172
  <div class="textarea-wrap">
173
  <textarea rows="10" class="_alm_repeater"><?php echo $contents; ?></textarea>
174
  </div>
175
+ <input type="submit" value="Save Template" class="button button-primary save-repeater">
176
  <div class="saved-response">&nbsp;</div>
177
  <!-- <div class="restore-default"><a href="javascript:void(0);"><?php _e('Restore Default', ALM_NAME); ?></a></div> -->
178
  </div>
255
  </div>
256
  <aside class="alm-sidebar">
257
  <div class="cta">
258
+ <h3><?php _e('Templating Help', ALM_NAME); ?></h3>
259
  <?php
260
  global $wpdb;
261
 
264
 
265
  ?>
266
  <div class="item">
267
+ <p><strong><?php _e('What is a repeater template?', ALM_NAME); ?></strong></p>
268
+ <p><?php _e('A repeater template is a snippet of code that will execute over and over within a <a href="http://codex.wordpress.org/The_Loop" target="_blank">WordPress loop</a>.</p>', ALM_NAME); ?></p>
269
  </div>
270
  <div class="item">
271
+ <p><strong><?php _e('Can I include PHP in the repeater template?', ALM_NAME); ?></strong></p>
272
  <p><?php _e('Yes, PHP and core WordPress functions such as, <code>the_title()</code> and <code>the_permalink()</code> are required.</p>', ALM_NAME); ?></p>
273
  </div>
274
  <div class="item">
275
  <p><strong><?php _e('Tips and Tricks', ALM_NAME); ?></strong></p>
276
  <ul>
277
+ <li><?php _e('Always open and close your templates with an HTML element. In some rare cases data may not be displayed.<br/>e.g. <code>&lt;li> &lt;/li></code> or <code>&lt;div> &lt;/div></code>', ALM_NAME); ?><br/> </li>
278
  </ul>
279
  </div>
280
  </div>
316
  //Save to database
317
  global $wpdb;
318
  $table_name = $wpdb->prefix . "alm";
319
+ if($n === 'default'){
320
+ $data_update = array('repeaterDefault' => "$c", 'pluginVersion' => ALM_VERSION);
321
+ $data_where = array('name' => "default");
322
+ }else{
323
+ $data_update = array('repeaterDefault' => "$c", 'pluginVersion' => ALM_REPEATER_VERSION);
324
+ $data_where = array('name' => $n);
325
+ }
326
  $wpdb->update($table_name , $data_update, $data_where);
327
 
328
  //Our results
ajax-load-more.php CHANGED
@@ -6,61 +6,52 @@ Description: A simple solution for Ajax loading of WordPress Posts and Pages.
6
  Author: Darren Cooney
7
  Twitter: @KaptonKaos
8
  Author URI: http://connekthq.com
9
- Version: 2.0.3
10
  License: GPL
11
  Copyright: Darren Cooney & Connekt Media
12
  */
13
 
14
 
15
- define('ALM_VERSION', '2.0.3');
16
- define('ALM_RELEASE', 'June 12, 2014');
17
 
18
  /*
19
  * alm_install
20
- * Activation hook - Create Default repeater and directory dynamically.
21
- * This is so we can provide updates without overriding the current repeaters.
22
  *
23
  * @since 2.0.0
24
  */
25
 
26
  register_activation_hook( __FILE__, 'alm_install' );
27
- function alm_install() {
28
-
29
- //Removed creation of core repeater file, it is now included directly in the /repeater/ dir.
30
- /*
31
- $alm_path = plugin_dir_path(__FILE__);
32
- //Create direcotry if it doesn't exist
33
- if (!file_exists($alm_path.'core/repeater')) {
34
- mkdir($alm_path.'core/repeater', 0777, true);
35
- }
36
-
37
- //Check for default.php, if null create it
38
- $filename = plugin_dir_path(__FILE__).'core/repeater/default.php';
39
- $defaultContent = '<li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>';
40
- if (!file_exists($filename)) {
41
- $handle = fopen($filename, 'w') or die('Cannot open file: '.$my_file); //implicitly creates file
42
- fwrite($handle, $defaultContent);
43
- fclose($handle);
44
- }
45
- */
46
-
47
  global $wpdb;
48
  $table_name = $wpdb->prefix . "alm";
49
  $defaultRepeater = '<li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>';
50
 
51
- //Create table, if it doesn't exist.
52
  if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
53
  $sql = "CREATE TABLE $table_name (
54
  id mediumint(9) NOT NULL AUTO_INCREMENT,
 
55
  repeaterDefault longtext NOT NULL,
56
  pluginVersion text NOT NULL,
57
  UNIQUE KEY id (id)
58
  );";
59
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
60
  dbDelta( $sql );
61
- //Insert default data
62
- $wpdb->insert($table_name , array('repeaterDefault' => $defaultRepeater, 'pluginVersion' => ALM_VERSION));
63
- }
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
 
6
  Author: Darren Cooney
7
  Twitter: @KaptonKaos
8
  Author URI: http://connekthq.com
9
+ Version: 2.0.5
10
  License: GPL
11
  Copyright: Darren Cooney & Connekt Media
12
  */
13
 
14
 
15
+ define('ALM_VERSION', '2.0.5');
16
+ define('ALM_RELEASE', 'June 13, 2014');
17
 
18
  /*
19
  * alm_install
20
+ * Create table for storing repeater
 
21
  *
22
  * @since 2.0.0
23
  */
24
 
25
  register_activation_hook( __FILE__, 'alm_install' );
26
+ function alm_install() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  global $wpdb;
28
  $table_name = $wpdb->prefix . "alm";
29
  $defaultRepeater = '<li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>';
30
 
31
+ //Create table, if it doesn't already exist.
32
  if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
33
  $sql = "CREATE TABLE $table_name (
34
  id mediumint(9) NOT NULL AUTO_INCREMENT,
35
+ name text NOT NULL,
36
  repeaterDefault longtext NOT NULL,
37
  pluginVersion text NOT NULL,
38
  UNIQUE KEY id (id)
39
  );";
40
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
41
  dbDelta( $sql );
42
+
43
+ //Insert default data in newly created table
44
+ $wpdb->insert($table_name , array('name' => 'default', 'repeaterDefault' => $defaultRepeater, 'pluginVersion' => ALM_VERSION));
45
+ }
46
+
47
+ // Updated 2.0.5
48
+ // Check column 'name' exists in $wpdb - this is an upgrade checker.
49
+ $row = $wpdb->get_results("SELECT COLUMN_NAME FROM $table_name.COLUMNS WHERE column_name = 'name'");
50
+ if(empty($row)){
51
+ $wpdb->query("ALTER TABLE $table_name ADD name text NOT NULL");
52
+ $wpdb->update($table_name , array('name' => 'default'), array('id' => 1));
53
+ }
54
+
55
  }
56
 
57
 
core/repeater/default.php CHANGED
@@ -1 +1 @@
1
- <li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="#" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>
1
+ <li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php the_excerpt(); ?></li>