WooCommerce Products Per Page - Version 1.1.3

Version Description

  • 20/12/2014 =

  • Improvement - Improved code quality

  • Improvement - Replace $woocommerce global with WC() singleton

  • Improvement - Create WooCommerce_Products_Per_Page() singleton

  • Improvement - Bit clearer structure

  • Remove - Return void comment tags

Download this release

Release Info

Developer sormano
Plugin Icon 128x128 WooCommerce Products Per Page
Version 1.1.3
Comparing to
See all releases

Code changes from version 1.1.2 to 1.1.3

includes/class-wppp-dropdown.php CHANGED
@@ -2,15 +2,15 @@
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
  /**
5
- * Class WPPP_Dropdown
6
  *
7
- * Products per page dropdown class
8
  *
9
  * @class WPPP_Dropdown
10
  * @version 1.1.0
11
  * @author Jeroen Sormani
12
  */
13
- class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
14
 
15
 
16
  /**
@@ -29,16 +29,12 @@ class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
29
  *
30
  * @since 1.0.0
31
  */
32
- public function __construct( $products_per_page_options = null ) {
33
 
34
- parent::__construct();
35
-
36
- $this->products_per_page = $this->wppp_prep_ppp( $products_per_page_options );
37
-
38
- if ( false == $products_per_page_options ) :
39
- $this->products_per_page_options = $this->wppp_prep_ppp( apply_filters( 'wppp_products_per_page', $this->settings['productsPerPage'] ) );
40
- endif;
41
 
 
42
  $this->wppp_dropdown();
43
 
44
  }
@@ -74,6 +70,9 @@ class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
74
  $cat = '';
75
  $cat = $wp_query->get_queried_object();
76
 
 
 
 
77
  // Set action url if option behaviour is true
78
  // Paste QUERY string after for filter and orderby support
79
  $query_string = ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . add_query_arg( array( 'wppp_ppp' => false ), $_SERVER['QUERY_STRING'] ) : null;
@@ -91,20 +90,20 @@ class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
91
 
92
  // Only show on product categories
93
  if ( woocommerce_products_will_display() ) :
94
- ?>
95
 
96
- <form method="<?php echo $method; ?>" <?php echo $action; ?> style='float: right;' class="form-wppp-select products-per-page">
 
 
 
 
97
 
98
- <?php do_action( 'wppp_before_dropdown' ); ?>
99
 
100
- <select name="wppp_ppp" onchange="this.form.submit()" class="select wppp-select">
101
 
102
- <?php
103
- global $woocommerce;
104
- foreach( $this->products_per_page_options as $key => $value ) :
105
 
106
  // Get the right match for the selected option
107
- $ppp_session = $woocommerce->session->get( 'products_per_page' );
108
  if( isset( $_POST['wppp_ppp'] ) ) :
109
  $selected_match = $_POST['wppp_ppp'];
110
  elseif( isset( $_GET['wppp_ppp'] ) ):
@@ -115,23 +114,25 @@ class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
115
  $selected_match = $this->settings['default_ppp'];
116
  endif;
117
 
118
- ?>
119
- <option value="<?php echo $value; ?>" <?php selected( $value, $selected_match ); ?>>
120
  <?php
121
  $ppp_text = apply_filters( 'wppp_ppp_text', __( '%s products per page', 'woocommerce-products-per-page' ), $value );
122
  printf( $ppp_text, $value == -1 ? __( 'All', 'woocommerce-products-per-page' ) : $value ); // Set to 'All' when value is -1
123
- ?>
124
- </option>
125
- <?php
126
 
127
  endforeach;
128
- ?>
129
- </select>
130
 
131
- <?php do_action( 'wppp_after_dropdown' ); ?>
 
 
 
 
 
 
132
 
133
- </form>
134
- <?php
135
  endif;
136
 
137
  }
@@ -152,4 +153,4 @@ class WPPP_Dropdown extends Woocommerce_Products_Per_Page {
152
 
153
  }
154
 
155
- }
2
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
 
4
  /**
5
+ * Class WPPP_Dropdown.
6
  *
7
+ * Products per page dropdown class.
8
  *
9
  * @class WPPP_Dropdown
10
  * @version 1.1.0
11
  * @author Jeroen Sormani
12
  */
13
+ class WPPP_Dropdown {
14
 
15
 
16
  /**
29
  *
30
  * @since 1.0.0
31
  */
32
+ public function __construct() {
33
 
34
+ // Get all the settings
35
+ $this->settings = WooCommerce_Products_Per_page()->settings;
 
 
 
 
 
36
 
37
+ // Create the dropdown
38
  $this->wppp_dropdown();
39
 
40
  }
70
  $cat = '';
71
  $cat = $wp_query->get_queried_object();
72
 
73
+ // Set the products per page options (e.g. 4, 8, 12)
74
+ $products_per_page_options = $this->wppp_prep_ppp( apply_filters( 'wppp_products_per_page', $this->settings['productsPerPage'] ) );
75
+
76
  // Set action url if option behaviour is true
77
  // Paste QUERY string after for filter and orderby support
78
  $query_string = ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . add_query_arg( array( 'wppp_ppp' => false ), $_SERVER['QUERY_STRING'] ) : null;
90
 
91
  // Only show on product categories
92
  if ( woocommerce_products_will_display() ) :
 
93
 
94
+ do_action( 'wppp_before_dropdown_form' );
95
+
96
+ ?><form method="<?php echo $method; ?>" <?php echo $action; ?> style='float: right;' class="form-wppp-select products-per-page"><?php
97
+
98
+ do_action( 'wppp_before_dropdown' );
99
 
100
+ ?><select name="wppp_ppp" onchange="this.form.submit()" class="select wppp-select"><?php
101
 
 
102
 
103
+ foreach( $products_per_page_options as $key => $value ) :
 
 
104
 
105
  // Get the right match for the selected option
106
+ $ppp_session = WC()->session->get( 'products_per_page' );
107
  if( isset( $_POST['wppp_ppp'] ) ) :
108
  $selected_match = $_POST['wppp_ppp'];
109
  elseif( isset( $_GET['wppp_ppp'] ) ):
114
  $selected_match = $this->settings['default_ppp'];
115
  endif;
116
 
117
+
118
+ ?><option value="<?php echo $value; ?>" <?php selected( $value, $selected_match ); ?>>
119
  <?php
120
  $ppp_text = apply_filters( 'wppp_ppp_text', __( '%s products per page', 'woocommerce-products-per-page' ), $value );
121
  printf( $ppp_text, $value == -1 ? __( 'All', 'woocommerce-products-per-page' ) : $value ); // Set to 'All' when value is -1
122
+
123
+ ?></option><?php
124
+
125
 
126
  endforeach;
 
 
127
 
128
+ ?></select><?php
129
+
130
+ do_action( 'wppp_after_dropdown' );
131
+
132
+ ?></form><?php
133
+
134
+ do_action( 'wppp_after_dropdown_form' );
135
 
 
 
136
  endif;
137
 
138
  }
153
 
154
  }
155
 
156
+ }
includes/class-wppp-settings.php CHANGED
@@ -11,17 +11,18 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11
  * @author Jeroen Sormani
12
  */
13
 
14
- class WPPP_Settings extends Woocommerce_Products_Per_Page {
15
 
16
 
17
  /**
18
- * Construct.
19
  *
20
  * @since 1.0.0
21
  */
22
  public function __construct() {
23
 
24
- parent::__construct();
 
25
 
26
  }
27
 
@@ -35,6 +36,10 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
35
  */
36
  public function wppp_settings_init() {
37
 
 
 
 
 
38
  register_setting( 'wppp_settings', 'wppp_settings' );
39
 
40
  add_settings_section(
@@ -109,13 +114,13 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
109
 
110
  <h2><?php _e( 'WooCommerce Products Per Page', 'woocommerce-products-per-page' ); ?></h2>
111
 
112
- <form method="POST" action="options.php">
113
- <?php
114
  settings_fields( 'wppp_settings' );
115
  do_settings_sections( 'wppp_settings' );
116
  submit_button();
117
- ?>
118
- </form>
119
 
120
  </div><?php
121
 
@@ -132,10 +137,20 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
132
  public function wppp_settings_field_location() {
133
 
134
  ?><select name="wppp_settings[location]" class="">
135
- <option value="top" <?php selected( $this->settings['location'], 'top' ); ?>> <?php _e( 'Top', 'woocommerce-products-per-page' ); ?></option>
136
- <option value="bottom" <?php selected( $this->settings['location'], 'bottom' ); ?>> <?php _e( 'Bottom', 'woocommerce-products-per-page' ); ?></option>
137
- <option value="topbottom" <?php selected( $this->settings['location'], 'topbottom' ); ?>> <?php _e( 'Top/Bottom', 'woocommerce-products-per-page' ); ?></option>
138
- <option value="none" <?php selected( $this->settings['location'], 'none' ); ?>> <?php _e( 'None', 'woocommerce-products-per-page' ); ?></option>
 
 
 
 
 
 
 
 
 
 
139
  </select><?php
140
 
141
  }
@@ -151,8 +166,8 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
151
  public function wppp_settings_field_ppp_list() {
152
 
153
  ?><label for="products_per_page">
154
- <input type="text" id="products_per_page" name="wppp_settings[productsPerPage]" value="<?php echo $this->settings['productsPerPage']; ?>">
155
- <?php _e( 'Seperated by spaces <em>(-1 for all products)</em>', 'woocommerce-products-per-page' ); ?></label><?php
156
 
157
  }
158
 
@@ -167,7 +182,7 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
167
  public function wppp_settings_field_default_ppp() {
168
 
169
  ?><label for="default_ppp">
170
- <input type="number" id="default_ppp" name="wppp_settings[default_ppp]" value="<?php echo $this->settings['default_ppp']; ?>">
171
  <em><?php _e( '-1 for all products', 'woocommerce-products-per-page' ); ?></em>
172
  </label><?php
173
 
@@ -184,7 +199,7 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
184
  public function wppp_settings_field_shop_columns() {
185
 
186
  ?><label for="shop_columns">
187
- <input type="number" id="shop_columns" name="wppp_settings[shop_columns]" value="<?php echo $this->settings['shop_columns']; ?>">
188
  </label><?php
189
 
190
  }
@@ -200,7 +215,7 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
200
  public function wppp_settings_field_behaviour() {
201
 
202
  ?><label for="behaviour">
203
- <input type="checkbox" id="behaviour" name="wppp_settings[behaviour]" value="1" <?php @checked( $this->settings['behaviour'], 1 ); ?>>
204
  <?php _e( 'When checked and a new number of PPP is selected, the visitor will be send to the first page of the product category', 'woocommerce-products-per-page' ); ?>
205
  </label>
206
  <style>
@@ -255,8 +270,8 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
255
 
256
  ?><label for="method">
257
  <select name="wppp_settings[method]" class="">
258
- <option value="post" <?php @selected( $this->settings['method'], 'post' ); ?>> <?php _e( 'POST', 'woocommerce-products-per-page' ); ?></option>
259
- <option value="get" <?php @selected( $this->settings['method'], 'get' ); ?>> <?php _e( 'GET', 'woocommerce-products-per-page' ); ?></option>
260
  </select>
261
  <?php _e( 'GET sends the products per page via the url, POST does this on the background', 'woocommerce-products-per-page' ); ?>
262
  </label><?php
@@ -276,5 +291,3 @@ class WPPP_Settings extends Woocommerce_Products_Per_Page {
276
  }
277
 
278
  }
279
-
280
- ?>
11
  * @author Jeroen Sormani
12
  */
13
 
14
+ class WPPP_Settings {
15
 
16
 
17
  /**
18
+ * Constructor.
19
  *
20
  * @since 1.0.0
21
  */
22
  public function __construct() {
23
 
24
+ // Init settings
25
+ add_action( 'admin_init', array( $this, 'wppp_settings_init' ) );
26
 
27
  }
28
 
36
  */
37
  public function wppp_settings_init() {
38
 
39
+ // Get all the settings
40
+ WooCommerce_Products_Per_page()->settings = WooCommerce_Products_Per_page()->settings;
41
+
42
+
43
  register_setting( 'wppp_settings', 'wppp_settings' );
44
 
45
  add_settings_section(
114
 
115
  <h2><?php _e( 'WooCommerce Products Per Page', 'woocommerce-products-per-page' ); ?></h2>
116
 
117
+ <form method="POST" action="options.php"><?php
118
+
119
  settings_fields( 'wppp_settings' );
120
  do_settings_sections( 'wppp_settings' );
121
  submit_button();
122
+
123
+ ?></form>
124
 
125
  </div><?php
126
 
137
  public function wppp_settings_field_location() {
138
 
139
  ?><select name="wppp_settings[location]" class="">
140
+
141
+ <option value="top" <?php selected( WooCommerce_Products_Per_page()->settings['location'], 'top' ); ?>><?php
142
+ _e( 'Top', 'woocommerce-products-per-page' );
143
+ ?></option>
144
+ <option value="bottom" <?php selected( WooCommerce_Products_Per_page()->settings['location'], 'bottom' ); ?>><?php
145
+ _e( 'Bottom', 'woocommerce-products-per-page' );
146
+ ?></option>
147
+ <option value="topbottom" <?php selected( WooCommerce_Products_Per_page()->settings['location'], 'topbottom' ); ?>><?php
148
+ _e( 'Top/Bottom', 'woocommerce-products-per-page' );
149
+ ?></option>
150
+ <option value="none" <?php selected( WooCommerce_Products_Per_page()->settings['location'], 'none' ); ?>><?php
151
+ _e( 'None', 'woocommerce-products-per-page' );
152
+ ?></option>
153
+
154
  </select><?php
155
 
156
  }
166
  public function wppp_settings_field_ppp_list() {
167
 
168
  ?><label for="products_per_page">
169
+ <input type="text" id="products_per_page" name="wppp_settings[productsPerPage]" value="<?php echo WooCommerce_Products_Per_page()->settings['productsPerPage']; ?>"><?php
170
+ _e( 'Seperated by spaces <em>(-1 for all products)</em>', 'woocommerce-products-per-page' ); ?></label><?php
171
 
172
  }
173
 
182
  public function wppp_settings_field_default_ppp() {
183
 
184
  ?><label for="default_ppp">
185
+ <input type="number" id="default_ppp" name="wppp_settings[default_ppp]" value="<?php echo WooCommerce_Products_Per_page()->settings['default_ppp']; ?>">
186
  <em><?php _e( '-1 for all products', 'woocommerce-products-per-page' ); ?></em>
187
  </label><?php
188
 
199
  public function wppp_settings_field_shop_columns() {
200
 
201
  ?><label for="shop_columns">
202
+ <input type="number" id="shop_columns" name="wppp_settings[shop_columns]" value="<?php echo WooCommerce_Products_Per_page()->settings['shop_columns']; ?>">
203
  </label><?php
204
 
205
  }
215
  public function wppp_settings_field_behaviour() {
216
 
217
  ?><label for="behaviour">
218
+ <input type="checkbox" id="behaviour" name="wppp_settings[behaviour]" value="1" <?php @checked( WooCommerce_Products_Per_page()->settings['behaviour'], 1 ); ?>>
219
  <?php _e( 'When checked and a new number of PPP is selected, the visitor will be send to the first page of the product category', 'woocommerce-products-per-page' ); ?>
220
  </label>
221
  <style>
270
 
271
  ?><label for="method">
272
  <select name="wppp_settings[method]" class="">
273
+ <option value="post" <?php @selected( WooCommerce_Products_Per_page()->settings['method'], 'post' ); ?>> <?php _e( 'POST', 'woocommerce-products-per-page' ); ?></option>
274
+ <option value="get" <?php @selected( WooCommerce_Products_Per_page()->settings['method'], 'get' ); ?>> <?php _e( 'GET', 'woocommerce-products-per-page' ); ?></option>
275
  </select>
276
  <?php _e( 'GET sends the products per page via the url, POST does this on the background', 'woocommerce-products-per-page' ); ?>
277
  </label><?php
291
  }
292
 
293
  }
 
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: sormano
3
  Donate link: http://www.jeroensormani.com/donate/
4
  Tags: Products per page, woocommerce, woocommerce products, woocommerce products per page, woocommerce displayed products, woocommerce quantity products, woocommerce amount of products, woocommerce number of products, woocommerce shown products
5
  Requires at least: 3.6.0
6
- Tested up to: 4.0
7
- Stable tag: 1.1.2
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -13,7 +13,7 @@ WooCommerce Products Per Page is a easy-to-setup plugin that integrates a 'produ
13
  == Description ==
14
  WooCommerce Products Per Page dropdown is easy to install and has several other product page configurations. When activated the plugin already works and has multiple settings you can set to your desire.
15
 
16
- Options like:
17
 
18
  - Dropdown position (top or bottom, top and bottom)
19
  - List op options products per page to show to your visitors
@@ -43,18 +43,30 @@ Options like:
43
 
44
  == Changelog ==
45
 
46
- = 1.1.2 = 11/09/2014
 
 
 
 
 
 
 
 
 
47
  * WC 2.2 compatibility fix
48
 
49
- = 1.1.1 = 18/08/2014
 
50
  * Proper translation for 'All'
51
  * Products in admin area aren't influenced anymore
52
  * Removed unneeded comments
53
 
54
  = 1.1.0.1 =
 
55
  * Removed - Duplicated main file with wrong name
56
 
57
  = 1.1.0 =
 
58
  * Complete plugin rewrite
59
  * Added setting for HTTP method (defaults to POST)
60
  * Easier use in themes/templates
@@ -63,41 +75,51 @@ Options like:
63
  * Inserted override for themes that would override the posts_per_page in query
64
 
65
  = 1.0.10 =
 
66
  * Fix - Notices in debug mode
67
 
68
  = 1.0.9 =
 
69
  * Improvement - For dropdown on product showing pages only
70
  * Improvement - Compatibility for WC 2.1.X
71
  * Fix - WC 2.1.X now saves PPP with empty cart
72
 
73
  = 1.0.8 =
 
74
  * Fix - Bug on tag archive pages
75
  * Tweak - Dropdown only shows on pages which show products
76
 
77
  = 1.0.7 =
 
78
  * Added support for filters/orders
79
 
80
  = 1.0.5/1.0.6 =
 
81
  * Added French translation (thanks to [whoaloic](http://profiles.wordpress.org/whoaloic))
82
  * Fixed WooCommerce 2.0.X compatibily
83
  * Now is capable for WooCommerce 2.0.X and 2.1.X
84
 
85
  = 1.0.4 =
 
86
  * Added option to control behaviour of select*
87
  * Added filter on option text*
88
  * Improved coding to Wordpress coding standards
89
 
90
  = 1.0.3 =
 
91
  * Fixed dutch translation*
92
 
93
  = 1.0.2 =
 
94
  * Added Dutch translation*
95
  * Added 'None' to the dropdown locations*
96
  * Now uses WC sessions instead of cookies*
97
  * Gave higher priority to hook "loop_shop_per_page"*
98
 
99
  = 1.0.1 =
 
100
  * Small update for cookies
101
 
102
  = 1.0.0 =
 
103
  * Initial release
3
  Donate link: http://www.jeroensormani.com/donate/
4
  Tags: Products per page, woocommerce, woocommerce products, woocommerce products per page, woocommerce displayed products, woocommerce quantity products, woocommerce amount of products, woocommerce number of products, woocommerce shown products
5
  Requires at least: 3.6.0
6
+ Tested up to: 4.1
7
+ Stable tag: 1.1.3
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
13
  == Description ==
14
  WooCommerce Products Per Page dropdown is easy to install and has several other product page configurations. When activated the plugin already works and has multiple settings you can set to your desire.
15
 
16
+ Options like:
17
 
18
  - Dropdown position (top or bottom, top and bottom)
19
  - List op options products per page to show to your visitors
43
 
44
  == Changelog ==
45
 
46
+ = 1.1.3 - 20/12/2014 =
47
+
48
+ * Improvement - Improved code quality
49
+ * Improvement - Replace $woocommerce global with WC() singleton
50
+ * Improvement - Create WooCommerce_Products_Per_Page() singleton
51
+ * Improvement - Bit clearer structure
52
+ * Remove - Return void comment tags
53
+
54
+ = 1.1.2 - 11/08/2014 =
55
+
56
  * WC 2.2 compatibility fix
57
 
58
+ = 1.1.1 - 18/08/2014 =
59
+
60
  * Proper translation for 'All'
61
  * Products in admin area aren't influenced anymore
62
  * Removed unneeded comments
63
 
64
  = 1.1.0.1 =
65
+
66
  * Removed - Duplicated main file with wrong name
67
 
68
  = 1.1.0 =
69
+
70
  * Complete plugin rewrite
71
  * Added setting for HTTP method (defaults to POST)
72
  * Easier use in themes/templates
75
  * Inserted override for themes that would override the posts_per_page in query
76
 
77
  = 1.0.10 =
78
+
79
  * Fix - Notices in debug mode
80
 
81
  = 1.0.9 =
82
+
83
  * Improvement - For dropdown on product showing pages only
84
  * Improvement - Compatibility for WC 2.1.X
85
  * Fix - WC 2.1.X now saves PPP with empty cart
86
 
87
  = 1.0.8 =
88
+
89
  * Fix - Bug on tag archive pages
90
  * Tweak - Dropdown only shows on pages which show products
91
 
92
  = 1.0.7 =
93
+
94
  * Added support for filters/orders
95
 
96
  = 1.0.5/1.0.6 =
97
+
98
  * Added French translation (thanks to [whoaloic](http://profiles.wordpress.org/whoaloic))
99
  * Fixed WooCommerce 2.0.X compatibily
100
  * Now is capable for WooCommerce 2.0.X and 2.1.X
101
 
102
  = 1.0.4 =
103
+
104
  * Added option to control behaviour of select*
105
  * Added filter on option text*
106
  * Improved coding to Wordpress coding standards
107
 
108
  = 1.0.3 =
109
+
110
  * Fixed dutch translation*
111
 
112
  = 1.0.2 =
113
+
114
  * Added Dutch translation*
115
  * Added 'None' to the dropdown locations*
116
  * Now uses WC sessions instead of cookies*
117
  * Gave higher priority to hook "loop_shop_per_page"*
118
 
119
  = 1.0.1 =
120
+
121
  * Small update for cookies
122
 
123
  = 1.0.0 =
124
+
125
  * Initial release
woocommerce-products-per-page.php CHANGED
@@ -1,11 +1,11 @@
1
- <?PHP
2
  /*
3
- Plugin Name: Woocommerce Products Per Page
4
- Plugin URI: http://www.jeroensormani.com/
5
- Description: Integrate a 'products per page' dropdown on your WooCommerce website! Set-up in <strong>seconds</strong>!
6
- Version: 1.1.2
7
- Author: Jeroen Sormani
8
- Author URI: http://www.jeroensormani.com
9
 
10
  * Copyright Jeroen Sormani
11
  *
@@ -52,12 +52,20 @@ class Woocommerce_Products_Per_Page {
52
  public $settings;
53
 
54
 
 
 
 
 
 
 
 
 
 
 
55
  /**
56
  * Construct.
57
  *
58
  * @since 1.0.0
59
- *
60
- * @return void.
61
  */
62
  public function __construct() {
63
 
@@ -71,14 +79,7 @@ class Woocommerce_Products_Per_Page {
71
  endif;
72
  endif;
73
 
74
- // Initialise settings
75
- $this->wppp_init_settings();
76
-
77
- // Initialize hooks
78
- $this->wppp_hooks();
79
-
80
- // Load textdomain
81
- load_plugin_textdomain( 'woocommerce-products-per-page', false, basename( dirname( __FILE__ ) ) . '/languages' );
82
 
83
  }
84
 
@@ -95,9 +96,6 @@ class Woocommerce_Products_Per_Page {
95
  // Add admin settings page
96
  add_action( 'admin_menu', array( $this, 'wppp_settings_page_menu' ) );
97
 
98
- // Init settings
99
- add_action( 'admin_init', array( $this, 'wppp_init_settings_page' ) );
100
-
101
  // Add filter for product columns
102
  add_filter( 'loop_shop_columns', array( $this, 'wppp_loop_shop_columns' ) );
103
 
@@ -115,29 +113,67 @@ class Woocommerce_Products_Per_Page {
115
 
116
 
117
  /**
118
- * Initialize admin settings page.
119
  *
120
- * @since 1.1.0
 
121
  *
122
- * @return void.
 
123
  */
124
- public function wppp_settings_page_menu() {
125
- add_options_page( 'WooCommerce Products Per Page', 'Products Per Page', 'manage_options', 'wppp_settings', array( $this, 'wppp_settings_page' ) );
 
 
 
 
 
 
126
  }
127
 
128
 
129
  /**
130
- * Initialize admin settings page.
131
  *
132
- * @since 1.0.0
133
  *
134
- * @return void.
135
  */
136
- public function wppp_settings_page() {
137
 
138
- global $wppp_settings;
139
- $wppp_settings->wppp_render_settings_page();
 
 
 
 
 
 
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
 
@@ -152,7 +188,7 @@ class Woocommerce_Products_Per_Page {
152
  */
153
  public function wppp_init_settings() {
154
 
155
- if ( !get_option( 'wppp_settings' ) ) :
156
  add_option( 'wppp_settings', $this->wppp_settings_defaults() );
157
  endif;
158
 
@@ -182,7 +218,7 @@ class Woocommerce_Products_Per_Page {
182
  // Set default settings
183
  $settings = apply_filters( 'wppp_settings_defaults', array(
184
  'location' => 'topbottom',
185
- 'productsPerPage' => $ppp_default,
186
  'default_ppp' => apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ),
187
  'shop_columns' => apply_filters( 'loop_shop_columns', 4 ),
188
  'behaviour' => '0',
@@ -194,29 +230,6 @@ class Woocommerce_Products_Per_Page {
194
  }
195
 
196
 
197
- /**
198
- * Initialise admin settings.
199
- *
200
- * Initializes settings, but doesn't display them.
201
- *
202
- * @since 1.1.0
203
- *
204
- * @return void.
205
- */
206
- public function wppp_init_settings_page() {
207
-
208
- /**
209
- * Settings page class
210
- */
211
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-wppp-settings.php';
212
-
213
- global $wppp_settings;
214
- $wppp_settings = new WPPP_Settings();
215
- $wppp_settings->wppp_settings_init();
216
-
217
- }
218
-
219
-
220
  /**
221
  * Shop columns.
222
  *
@@ -254,8 +267,8 @@ class Woocommerce_Products_Per_Page {
254
  return $_POST['wppp_ppp'];
255
  elseif ( isset( $_GET['wppp_ppp'] ) ) :
256
  return $_GET['wppp_ppp'];
257
- elseif ( $woocommerce->session->__isset( 'products_per_page' ) ) :
258
- return $woocommerce->session->__get( 'products_per_page' );
259
  else :
260
  return $this->settings['default_ppp'];
261
  endif;
@@ -289,8 +302,6 @@ class Woocommerce_Products_Per_Page {
289
  * Add the dropdown to the category/shop pages.
290
  *
291
  * @since 1.0.0
292
- *
293
- * @return void.
294
  */
295
  public function wppp_shop_hooks() {
296
 
@@ -311,8 +322,6 @@ class Woocommerce_Products_Per_Page {
311
  *
312
  * @since 1.0.0
313
  * @deprecated 1.1.0 Use wppp_dropdown() instead.
314
- *
315
- * @return void.
316
  */
317
  public function wppp_dropdown_object() {
318
  $this->wppp_dropdown();
@@ -325,8 +334,6 @@ class Woocommerce_Products_Per_Page {
325
  * Include dropdown class and create an instance.
326
  *
327
  * @since 1.0.0
328
- *
329
- * @return void.
330
  */
331
  public function wppp_dropdown() {
332
 
@@ -345,17 +352,11 @@ class Woocommerce_Products_Per_Page {
345
  * Set an initial session for WC 2.1.X users. Cookies are set automatically prior 2.1.X.
346
  *
347
  * @since 1.0.0
348
- *
349
- * @global object $woocommerce WooCommerce global object.
350
- *
351
- * @return void.
352
  */
353
  public function wppp_set_customer_session() {
354
 
355
- global $woocommerce;
356
-
357
- if ( $woocommerce->version > '2.1' && ! is_admin() ) :
358
- $woocommerce->session->set_customer_session_cookie( true );
359
  endif;
360
 
361
  }
@@ -367,19 +368,13 @@ class Woocommerce_Products_Per_Page {
367
  * Set products per page in session.
368
  *
369
  * @since 1.1.0
370
- *
371
- * @global object $woocommerce WooCommerce global object.
372
- *
373
- * @return void.
374
  */
375
  public function wppp_submit_check() {
376
 
377
- global $woocommerce;
378
-
379
  if ( isset( $_POST['wppp_ppp'] ) ) :
380
- $woocommerce->session->set( 'products_per_page', $_POST['wppp_ppp'] );
381
  elseif ( isset( $_GET['wppp_ppp'] ) ) :
382
- $woocommerce->session->set( 'products_per_page', $_GET['wppp_ppp'] );
383
  endif;
384
 
385
  }
@@ -387,6 +382,29 @@ class Woocommerce_Products_Per_Page {
387
 
388
  }
389
 
390
- global $wppp;
391
- $wppp = new woocommerce_products_per_page();
392
- $wppp->wppp_shop_hooks();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
  /*
3
+ * Plugin Name: Woocommerce Products Per Page
4
+ * Plugin URI: http://www.jeroensormani.com/
5
+ * Description: Integrate a 'products per page' dropdown on your WooCommerce website! Set-up in <strong>seconds</strong>!
6
+ * Version: 1.1.3
7
+ * Author: Jeroen Sormani
8
+ * Author URI: http://www.jeroensormani.com
9
 
10
  * Copyright Jeroen Sormani
11
  *
52
  public $settings;
53
 
54
 
55
+ /**
56
+ * Instace of Woocommerce_Products_Per_Page.
57
+ *
58
+ * @since 1.1.3
59
+ * @access private
60
+ * @var object $instance The instance of Woocommerce_Products_Per_Page.
61
+ */
62
+ private static $instance;
63
+
64
+
65
  /**
66
  * Construct.
67
  *
68
  * @since 1.0.0
 
 
69
  */
70
  public function __construct() {
71
 
79
  endif;
80
  endif;
81
 
82
+ $this->init();
 
 
 
 
 
 
 
83
 
84
  }
85
 
96
  // Add admin settings page
97
  add_action( 'admin_menu', array( $this, 'wppp_settings_page_menu' ) );
98
 
 
 
 
99
  // Add filter for product columns
100
  add_filter( 'loop_shop_columns', array( $this, 'wppp_loop_shop_columns' ) );
101
 
113
 
114
 
115
  /**
116
+ * Instance.
117
  *
118
+ * An global instance of the class. Used to retrieve the instance
119
+ * to use on other files/plugins/themes.
120
  *
121
+ * @since 1.0.3
122
+ * @return object Instance of the class.
123
  */
124
+ public static function instance() {
125
+
126
+ if ( is_null( self::$instance ) ) :
127
+ self::$instance = new self();
128
+ endif;
129
+
130
+ return self::$instance;
131
+
132
  }
133
 
134
 
135
  /**
136
+ * init.
137
  *
138
+ * Initialize plugin parts.
139
  *
140
+ * @since 1.0.0
141
  */
142
+ public function init() {
143
 
144
+ if ( is_admin() ) :
145
+
146
+ /**
147
+ * Settings page class
148
+ */
149
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wppp-settings.php';
150
+ $this->wppp_settings = new WPPP_Settings();
151
+
152
+ endif;
153
 
154
+
155
+ // Initialise settings
156
+ $this->wppp_init_settings();
157
+
158
+ // Initialize hooks
159
+ $this->wppp_hooks();
160
+
161
+ // Load textdomain
162
+ load_plugin_textdomain( 'woocommerce-products-per-page', false, basename( dirname( __FILE__ ) ) . '/languages' );
163
+
164
+ }
165
+
166
+
167
+ /**
168
+ * Initialize admin settings page.
169
+ *
170
+ * @since 1.1.0
171
+ */
172
+ public function wppp_settings_page_menu() {
173
+ add_options_page( 'WooCommerce Products Per Page', 'Products Per Page', 'manage_options', 'wppp_settings', array(
174
+ $this->wppp_settings,
175
+ 'wppp_render_settings_page'
176
+ ) );
177
  }
178
 
179
 
188
  */
189
  public function wppp_init_settings() {
190
 
191
+ if ( ! get_option( 'wppp_settings' ) ) :
192
  add_option( 'wppp_settings', $this->wppp_settings_defaults() );
193
  endif;
194
 
218
  // Set default settings
219
  $settings = apply_filters( 'wppp_settings_defaults', array(
220
  'location' => 'topbottom',
221
+ 'productsPerPage' => $ppp_default,
222
  'default_ppp' => apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ),
223
  'shop_columns' => apply_filters( 'loop_shop_columns', 4 ),
224
  'behaviour' => '0',
230
  }
231
 
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  /**
234
  * Shop columns.
235
  *
267
  return $_POST['wppp_ppp'];
268
  elseif ( isset( $_GET['wppp_ppp'] ) ) :
269
  return $_GET['wppp_ppp'];
270
+ elseif ( WC()->session->__isset( 'products_per_page' ) ) :
271
+ return WC()->session->__get( 'products_per_page' );
272
  else :
273
  return $this->settings['default_ppp'];
274
  endif;
302
  * Add the dropdown to the category/shop pages.
303
  *
304
  * @since 1.0.0
 
 
305
  */
306
  public function wppp_shop_hooks() {
307
 
322
  *
323
  * @since 1.0.0
324
  * @deprecated 1.1.0 Use wppp_dropdown() instead.
 
 
325
  */
326
  public function wppp_dropdown_object() {
327
  $this->wppp_dropdown();
334
  * Include dropdown class and create an instance.
335
  *
336
  * @since 1.0.0
 
 
337
  */
338
  public function wppp_dropdown() {
339
 
352
  * Set an initial session for WC 2.1.X users. Cookies are set automatically prior 2.1.X.
353
  *
354
  * @since 1.0.0
 
 
 
 
355
  */
356
  public function wppp_set_customer_session() {
357
 
358
+ if ( WC()->version > '2.1' && ! is_admin() ) :
359
+ WC()->session->set_customer_session_cookie( true );
 
 
360
  endif;
361
 
362
  }
368
  * Set products per page in session.
369
  *
370
  * @since 1.1.0
 
 
 
 
371
  */
372
  public function wppp_submit_check() {
373
 
 
 
374
  if ( isset( $_POST['wppp_ppp'] ) ) :
375
+ WC()->session->set( 'products_per_page', $_POST['wppp_ppp'] );
376
  elseif ( isset( $_GET['wppp_ppp'] ) ) :
377
+ WC()->session->set( 'products_per_page', $_GET['wppp_ppp'] );
378
  endif;
379
 
380
  }
382
 
383
  }
384
 
385
+
386
+ /**
387
+ * The main function responsible for returning the Woocommerce_Products_Per_Page object.
388
+ *
389
+ * Use this function like you would a global variable, except without needing to declare the global.
390
+ *
391
+ * Example: <?php Woocommerce_Products_Per_Page()->method_name(); ?>
392
+ *
393
+ * @since 1.0.3
394
+ *
395
+ * @return object Woocommerce_Products_Per_Page class object.
396
+ */
397
+ if ( ! function_exists( 'Woocommerce_Products_Per_Page' ) ) :
398
+
399
+ function Woocommerce_Products_Per_Page() {
400
+ return Woocommerce_Products_Per_Page::instance();
401
+ }
402
+
403
+ endif;
404
+
405
+ Woocommerce_Products_Per_Page();
406
+ Woocommerce_Products_Per_Page()->wppp_shop_hooks();
407
+
408
+
409
+ // Backwards compatibility
410
+ $_GLOBALS['wppp'] = Woocommerce_Products_Per_Page();