Version Description
- 06.27.2018 =
- Dev - Disable plugin if running Storefront 2.3+. This plugin is now included in Storefront core.
Download this release
Release Info
Developer | woothemes |
Plugin | Storefront Product Pagination |
Version | 1.2.4 |
Comparing to | |
See all releases |
Code changes from version 1.2.3 to 1.2.4
- assets/css/style.css +0 -0
- assets/css/style.scss +0 -0
- assets/js/customizer.js +0 -0
- assets/js/customizer.min.js +0 -0
- classes/class-storefront-product-pagination.php +349 -0
- functions/functions.php +10 -0
- index.php +0 -0
- languages/storefront-product-pagination.pot +0 -0
- readme.txt +5 -3
- storefront-product-pagination.php +14 -357
assets/css/style.css
CHANGED
File without changes
|
assets/css/style.scss
CHANGED
File without changes
|
assets/js/customizer.js
CHANGED
File without changes
|
assets/js/customizer.min.js
CHANGED
File without changes
|
classes/class-storefront-product-pagination.php
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Main Storefront_Product_Pagination Class
|
4 |
+
*
|
5 |
+
* @class Storefront_Product_Pagination
|
6 |
+
* @version 1.0.0
|
7 |
+
* @since 1.0.0
|
8 |
+
* @package Storefront_Product_Pagination
|
9 |
+
*/
|
10 |
+
final class Storefront_Product_Pagination {
|
11 |
+
/**
|
12 |
+
* Storefront_Product_Pagination The single instance of Storefront_Product_Pagination.
|
13 |
+
*
|
14 |
+
* @var object
|
15 |
+
* @access private
|
16 |
+
* @since 1.0.0
|
17 |
+
*/
|
18 |
+
private static $_instance = null;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* The token.
|
22 |
+
*
|
23 |
+
* @var string
|
24 |
+
* @access public
|
25 |
+
* @since 1.0.0
|
26 |
+
*/
|
27 |
+
public $token;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* The version number.
|
31 |
+
*
|
32 |
+
* @var string
|
33 |
+
* @access public
|
34 |
+
* @since 1.0.0
|
35 |
+
*/
|
36 |
+
public $version;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The admin object.
|
40 |
+
*
|
41 |
+
* @var object
|
42 |
+
* @access public
|
43 |
+
* @since 1.0.0
|
44 |
+
*/
|
45 |
+
public $admin;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Constructor function.
|
49 |
+
*
|
50 |
+
* @access public
|
51 |
+
* @since 1.0.0
|
52 |
+
* @return void
|
53 |
+
*/
|
54 |
+
public function __construct() {
|
55 |
+
$this->token = 'storefront-product-pagination';
|
56 |
+
$this->plugin_url = plugin_dir_url( __FILE__ );
|
57 |
+
$this->plugin_path = plugin_dir_path( __FILE__ );
|
58 |
+
$this->version = '1.2.4';
|
59 |
+
|
60 |
+
register_activation_hook( __FILE__, array( $this, 'install' ) );
|
61 |
+
|
62 |
+
add_action( 'init', array( $this, 'spp_load_plugin_textdomain' ) );
|
63 |
+
|
64 |
+
add_action( 'init', array( $this, 'spp_setup' ) );
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Main Storefront_Product_Pagination Instance
|
69 |
+
*
|
70 |
+
* Ensures only one instance of Storefront_Product_Pagination is loaded or can be loaded.
|
71 |
+
*
|
72 |
+
* @since 1.0.0
|
73 |
+
* @static
|
74 |
+
* @see Storefront_Product_Pagination()
|
75 |
+
* @return Main Storefront_Product_Pagination instance
|
76 |
+
*/
|
77 |
+
public static function instance() {
|
78 |
+
if ( is_null( self::$_instance ) ) {
|
79 |
+
self::$_instance = new self();
|
80 |
+
}
|
81 |
+
|
82 |
+
return self::$_instance;
|
83 |
+
} // End instance()
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Load the localisation file.
|
87 |
+
*
|
88 |
+
* @access public
|
89 |
+
* @since 1.0.0
|
90 |
+
* @return void
|
91 |
+
*/
|
92 |
+
public function spp_load_plugin_textdomain() {
|
93 |
+
load_plugin_textdomain( 'storefront-product-pagination', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Cloning is forbidden.
|
98 |
+
*
|
99 |
+
* @since 1.0.0
|
100 |
+
*/
|
101 |
+
public function __clone() {
|
102 |
+
_doing_it_wrong( __FUNCTION__, esc_attr( __( 'Cheatin’ huh?' ) ), '1.0.0' );
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Unserializing instances of this class is forbidden.
|
107 |
+
*
|
108 |
+
* @since 1.0.0
|
109 |
+
*/
|
110 |
+
public function __wakeup() {
|
111 |
+
_doing_it_wrong( __FUNCTION__, esc_attr( __( 'Cheatin’ huh?' ) ), '1.0.0' );
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Installation.
|
116 |
+
* Runs on activation. Logs the version number and assigns a notice message to a WordPress option.
|
117 |
+
*
|
118 |
+
* @access public
|
119 |
+
* @since 1.0.0
|
120 |
+
* @return void
|
121 |
+
*/
|
122 |
+
public function install() {
|
123 |
+
$this->_log_version_number();
|
124 |
+
|
125 |
+
// Get theme customizer url.
|
126 |
+
$url = admin_url() . 'customize.php?';
|
127 |
+
$url .= 'url=' . urlencode( site_url() . '?storefront-customizer=true' );
|
128 |
+
$url .= '&return=' . urlencode( admin_url() . 'plugins.php' );
|
129 |
+
$url .= '&storefront-customizer=true';
|
130 |
+
|
131 |
+
$notices = get_option( 'spp_activation_notice', array() );
|
132 |
+
$notices[] = sprintf( __( '%sThanks for installing the Storefront Product Pagination extension. Configure the settings in the %sCustomizer%s.%s %sOpen the Customizer%s', 'storefront-product-pagination' ), '<p>', '<a href="' . esc_url( $url ) . '">', '</a>', '</p>', '<p><a href="' . esc_url( $url ) . '" class="button button-primary">', '</a></p>' );
|
133 |
+
|
134 |
+
update_option( 'spp_activation_notice', $notices );
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Log the plugin version number.
|
139 |
+
*
|
140 |
+
* @access private
|
141 |
+
* @since 1.0.0
|
142 |
+
* @return void
|
143 |
+
*/
|
144 |
+
private function _log_version_number() {
|
145 |
+
// Log the version number.
|
146 |
+
update_option( $this->token . '-version', $this->version );
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Setup all the things.
|
151 |
+
* Only executes if Storefront or a child theme using Storefront as a parent is active and the extension specific filter returns true.
|
152 |
+
* Child themes can disable this extension using the storefront_extension_boilerplate_enabled filter
|
153 |
+
*
|
154 |
+
* @return void
|
155 |
+
*/
|
156 |
+
public function spp_setup() {
|
157 |
+
$theme = wp_get_theme();
|
158 |
+
|
159 |
+
if ( 'Storefront' === $theme->name || 'storefront' === $theme->template && apply_filters( 'storefront_product_pagination_supported', true ) ) {
|
160 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'spp_styles' ), 999 );
|
161 |
+
add_action( 'customize_register', array( $this, 'spp_customize_register' ) );
|
162 |
+
add_action( 'customize_preview_init', array( $this, 'spp_customize_preview_js' ) );
|
163 |
+
add_action( 'admin_notices', array( $this, 'spp_customizer_notice' ) );
|
164 |
+
|
165 |
+
add_action( 'woocommerce_after_single_product_summary', array( $this, 'spp_single_product_pagination' ), 30 );
|
166 |
+
|
167 |
+
// Hide the 'More' section in the customizer.
|
168 |
+
add_filter( 'storefront_customizer_more', '__return_false' );
|
169 |
+
} else {
|
170 |
+
add_action( 'admin_notices', array( $this, 'spp_install_storefront_notice' ) );
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Admin notice
|
176 |
+
* Checks the notice setup in install(). If it exists display it then delete the option so it's not displayed again.
|
177 |
+
*
|
178 |
+
* @since 1.0.0
|
179 |
+
* @return void
|
180 |
+
*/
|
181 |
+
public function spp_customizer_notice() {
|
182 |
+
$notices = get_option( 'spp_activation_notice' );
|
183 |
+
|
184 |
+
if ( $notices = get_option( 'spp_activation_notice' ) ) {
|
185 |
+
|
186 |
+
foreach ( $notices as $notice ) {
|
187 |
+
echo '<div class="updated">' . wp_kses_post( $notice ) . '</div>';
|
188 |
+
}
|
189 |
+
|
190 |
+
delete_option( 'spp_activation_notice' );
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Storefront install
|
196 |
+
* If the user activates the plugin while having a different parent theme active, prompt them to install Storefront.
|
197 |
+
*
|
198 |
+
* @since 1.0.0
|
199 |
+
* @return void
|
200 |
+
*/
|
201 |
+
public function spp_install_storefront_notice() {
|
202 |
+
echo '<div class="notice is-dismissible updated">
|
203 |
+
<p>' . wp_kses_post( __( 'Storefront Product Pagination requires that you use Storefront as your parent theme.', 'storefront-product-pagination' ) ) . ' <a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-theme&theme=storefront' ), 'install-theme_storefront' ) ) .'">' . wp_kses_post( __( 'Install Storefront now', 'storefront-product-pagination' ) ) . '</a></p>
|
204 |
+
</div>';
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Customizer Controls and settings
|
209 |
+
*
|
210 |
+
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
211 |
+
*/
|
212 |
+
public function spp_customize_register( $wp_customize ) {
|
213 |
+
/**
|
214 |
+
* Add a new section
|
215 |
+
*/
|
216 |
+
$wp_customize->add_section( 'spp_section' , array(
|
217 |
+
'title' => __( 'Product Pagination', 'storefront-product-pagination' ),
|
218 |
+
'priority' => 55,
|
219 |
+
) );
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Color picker
|
223 |
+
*/
|
224 |
+
$wp_customize->add_setting( 'spp_background_color', array(
|
225 |
+
'default' => apply_filters( 'spp_default_background_color', 'ffffff' ),
|
226 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
227 |
+
'transport' => 'postMessage', // Refreshes instantly via js. See customizer.js. (default = refresh).
|
228 |
+
) );
|
229 |
+
|
230 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'spp_background_color', array(
|
231 |
+
'label' => __( 'Background color', 'storefront-product-pagination' ),
|
232 |
+
'description' => __( 'Background color for the product pagination links', 'storefront-product-pagination' ),
|
233 |
+
'section' => 'spp_section',
|
234 |
+
'settings' => 'spp_background_color',
|
235 |
+
'priority' => 30,
|
236 |
+
) ) );
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Same category
|
240 |
+
*/
|
241 |
+
$wp_customize->add_setting( 'spp_same_cat', array(
|
242 |
+
'default' => false,
|
243 |
+
) );
|
244 |
+
|
245 |
+
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'spp_same_cat', array(
|
246 |
+
'label' => __( 'Display products in same category', 'storefront-product-pagination' ),
|
247 |
+
'description' => __( 'When enabled, pagination will only display links to products in the same category as the one currently being viewed.', 'storefront-product-pagination' ),
|
248 |
+
'section' => 'spp_section',
|
249 |
+
'settings' => 'spp_same_cat',
|
250 |
+
'type' => 'checkbox',
|
251 |
+
'priority' => 40,
|
252 |
+
) ) );
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Enqueue CSS and custom styles.
|
257 |
+
*
|
258 |
+
* @since 1.0.0
|
259 |
+
* @return void
|
260 |
+
*/
|
261 |
+
public function spp_styles() {
|
262 |
+
wp_enqueue_style( 'spp-styles', plugins_url( '../assets/css/style.css', __FILE__ ) );
|
263 |
+
|
264 |
+
$heading_background_color = get_theme_mod( 'spp_background_color', apply_filters( 'spp_default_background_color', '#ffffff' ) );
|
265 |
+
|
266 |
+
$spp_style = '
|
267 |
+
.storefront-single-product-pagination a {
|
268 |
+
background-color: ' . $heading_background_color . ';
|
269 |
+
}';
|
270 |
+
|
271 |
+
wp_add_inline_style( 'spp-styles', $spp_style );
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
|
276 |
+
*
|
277 |
+
* @since 1.0.0
|
278 |
+
*/
|
279 |
+
public function spp_customize_preview_js() {
|
280 |
+
wp_enqueue_script( 'spp-customizer', plugins_url( '../assets/js/customizer.min.js', __FILE__ ), array( 'customize-preview' ), '1.0.0', true );
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Single product pagination
|
285 |
+
* Display links to the next/previous products on the single product page
|
286 |
+
*
|
287 |
+
* @since 1.0.0
|
288 |
+
* @return void
|
289 |
+
* @uses previous_post_link(), next_post_link()
|
290 |
+
*/
|
291 |
+
function spp_single_product_pagination() {
|
292 |
+
$placeholder = '<img src="' . wc_placeholder_img_src() . '" />';
|
293 |
+
$same_cat = get_theme_mod( 'spp_same_cat', false );
|
294 |
+
$taxonomy = 'category';
|
295 |
+
$in_same_term = false;
|
296 |
+
|
297 |
+
if ( true === $same_cat ) {
|
298 |
+
$in_same_term = true;
|
299 |
+
$taxonomy = 'product_cat';
|
300 |
+
}
|
301 |
+
|
302 |
+
$previous_product = get_previous_post( $same_cat, '', $taxonomy );
|
303 |
+
$next_product = get_next_post( $same_cat, '', $taxonomy );
|
304 |
+
|
305 |
+
$previous_product_thumbnail = '';
|
306 |
+
$next_product_thumbnail = '';
|
307 |
+
|
308 |
+
$previous_product_data = '';
|
309 |
+
$next_product_data = '';
|
310 |
+
|
311 |
+
// If a next/previous product exists, get the thumbnail (or place holder).
|
312 |
+
if ( $previous_product ) {
|
313 |
+
$previous_product_data = new WC_Product( $previous_product->ID );
|
314 |
+
$previous_product_thumbnail = get_the_post_thumbnail( $previous_product->ID, 'shop_catalog' );
|
315 |
+
|
316 |
+
if ( ! $previous_product_thumbnail ) {
|
317 |
+
$previous_product_thumbnail = $placeholder;
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
if ( $next_product ) {
|
322 |
+
$next_product_data = new WC_Product( $next_product->ID );
|
323 |
+
$next_product_thumbnail = get_the_post_thumbnail( $next_product->ID, 'shop_catalog' );
|
324 |
+
|
325 |
+
if ( ! $next_product_thumbnail ) {
|
326 |
+
$next_product_thumbnail = $placeholder;
|
327 |
+
}
|
328 |
+
}
|
329 |
+
|
330 |
+
// Output the links.
|
331 |
+
if ( $next_product || $previous_product ) {
|
332 |
+
|
333 |
+
echo '<nav class="storefront-single-product-pagination">';
|
334 |
+
|
335 |
+
echo '<h2>' . esc_attr( __( 'More products', 'storefront-product-pagination' ) ) . '</h2>';
|
336 |
+
|
337 |
+
if ( $previous_product && $previous_product_data->is_visible() ) {
|
338 |
+
previous_post_link( '%link', $previous_product_thumbnail . '<span class="title">%title</span>', $in_same_term, '', $taxonomy );
|
339 |
+
}
|
340 |
+
|
341 |
+
if ( $next_product && $next_product_data->is_visible() ) {
|
342 |
+
next_post_link( '%link', $next_product_thumbnail . '<span class="title">%title</span>', $in_same_term, '', $taxonomy );
|
343 |
+
}
|
344 |
+
|
345 |
+
echo '</nav>';
|
346 |
+
|
347 |
+
}
|
348 |
+
}
|
349 |
+
} // End Class
|
functions/functions.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Returns the main instance of Storefront_Product_Pagination to prevent the need to use globals.
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @return object Storefront_Product_Pagination
|
7 |
+
*/
|
8 |
+
function storefront_product_pagination() {
|
9 |
+
return Storefront_Product_Pagination::instance();
|
10 |
+
} // End storefront_product_pagination()
|
index.php
CHANGED
File without changes
|
languages/storefront-product-pagination.pot
CHANGED
File without changes
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Storefront Product Pagination ===
|
2 |
Contributors: jameskoster, tiagonoronha, automattic
|
3 |
Tags: woocommerce, ecommerce, products, storefront, pagination, next, previous
|
4 |
-
Requires at least: 4.0
|
5 |
-
Tested up to: 4.9
|
6 |
-
Stable tag: 1.2.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -36,6 +36,8 @@ The links will appear on any single product page, providing there is more than o
|
|
36 |
|
37 |
== Changelog ==
|
38 |
|
|
|
|
|
39 |
|
40 |
= 1.2.3 - 01.29.2018 =
|
41 |
* Fix - Replaced wrong text domains. Correct text domain is `storefront-product-pagination`.
|
1 |
=== Storefront Product Pagination ===
|
2 |
Contributors: jameskoster, tiagonoronha, automattic
|
3 |
Tags: woocommerce, ecommerce, products, storefront, pagination, next, previous
|
4 |
+
Requires at least: 4.0
|
5 |
+
Tested up to: 4.9
|
6 |
+
Stable tag: 1.2.4
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
36 |
|
37 |
== Changelog ==
|
38 |
|
39 |
+
= 1.2.4 - 06.27.2018 =
|
40 |
+
* Dev - Disable plugin if running Storefront 2.3+. This plugin is now included in Storefront core.
|
41 |
|
42 |
= 1.2.3 - 01.29.2018 =
|
43 |
* Fix - Replaced wrong text domains. Correct text domain is `storefront-product-pagination`.
|
storefront-product-pagination.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
* Plugin Name: Storefront Product Pagination
|
4 |
* Plugin URI: http://woothemes.com/storefront/
|
5 |
* Description: Add unobstrusive links to next/previous products on your WooCommerce single product pages.
|
6 |
-
* Version: 1.2.
|
7 |
* Author: WooThemes
|
8 |
* Author URI: http://woothemes.com/
|
9 |
-
* Requires at least: 4.0
|
10 |
-
* Tested up to: 4.
|
11 |
*
|
12 |
* Text Domain: storefront-product-pagination
|
13 |
* Domain Path: /languages/
|
@@ -21,364 +21,21 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
21 |
exit; // Exit if accessed directly.
|
22 |
}
|
23 |
|
24 |
-
|
25 |
/**
|
26 |
-
*
|
27 |
*
|
28 |
-
* @since
|
29 |
-
* @return
|
30 |
*/
|
31 |
-
function
|
32 |
-
|
33 |
-
} // End storefront_product_pagination()
|
34 |
-
|
35 |
-
storefront_product_pagination();
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Main Storefront_Product_Pagination Class
|
39 |
-
*
|
40 |
-
* @class Storefront_Product_Pagination
|
41 |
-
* @version 1.0.0
|
42 |
-
* @since 1.0.0
|
43 |
-
* @package Storefront_Product_Pagination
|
44 |
-
*/
|
45 |
-
final class Storefront_Product_Pagination {
|
46 |
-
/**
|
47 |
-
* Storefront_Product_Pagination The single instance of Storefront_Product_Pagination.
|
48 |
-
*
|
49 |
-
* @var object
|
50 |
-
* @access private
|
51 |
-
* @since 1.0.0
|
52 |
-
*/
|
53 |
-
private static $_instance = null;
|
54 |
-
|
55 |
-
/**
|
56 |
-
* The token.
|
57 |
-
*
|
58 |
-
* @var string
|
59 |
-
* @access public
|
60 |
-
* @since 1.0.0
|
61 |
-
*/
|
62 |
-
public $token;
|
63 |
-
|
64 |
-
/**
|
65 |
-
* The version number.
|
66 |
-
*
|
67 |
-
* @var string
|
68 |
-
* @access public
|
69 |
-
* @since 1.0.0
|
70 |
-
*/
|
71 |
-
public $version;
|
72 |
-
|
73 |
-
/**
|
74 |
-
* The admin object.
|
75 |
-
*
|
76 |
-
* @var object
|
77 |
-
* @access public
|
78 |
-
* @since 1.0.0
|
79 |
-
*/
|
80 |
-
public $admin;
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Constructor function.
|
84 |
-
*
|
85 |
-
* @access public
|
86 |
-
* @since 1.0.0
|
87 |
-
* @return void
|
88 |
-
*/
|
89 |
-
public function __construct() {
|
90 |
-
$this->token = 'storefront-product-pagination';
|
91 |
-
$this->plugin_url = plugin_dir_url( __FILE__ );
|
92 |
-
$this->plugin_path = plugin_dir_path( __FILE__ );
|
93 |
-
$this->version = '1.2.3';
|
94 |
-
|
95 |
-
register_activation_hook( __FILE__, array( $this, 'install' ) );
|
96 |
-
|
97 |
-
add_action( 'init', array( $this, 'spp_load_plugin_textdomain' ) );
|
98 |
-
|
99 |
-
add_action( 'init', array( $this, 'spp_setup' ) );
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Main Storefront_Product_Pagination Instance
|
104 |
-
*
|
105 |
-
* Ensures only one instance of Storefront_Product_Pagination is loaded or can be loaded.
|
106 |
-
*
|
107 |
-
* @since 1.0.0
|
108 |
-
* @static
|
109 |
-
* @see Storefront_Product_Pagination()
|
110 |
-
* @return Main Storefront_Product_Pagination instance
|
111 |
-
*/
|
112 |
-
public static function instance() {
|
113 |
-
if ( is_null( self::$_instance ) ) {
|
114 |
-
self::$_instance = new self();
|
115 |
-
}
|
116 |
-
|
117 |
-
return self::$_instance;
|
118 |
-
} // End instance()
|
119 |
-
|
120 |
-
/**
|
121 |
-
* Load the localisation file.
|
122 |
-
*
|
123 |
-
* @access public
|
124 |
-
* @since 1.0.0
|
125 |
-
* @return void
|
126 |
-
*/
|
127 |
-
public function spp_load_plugin_textdomain() {
|
128 |
-
load_plugin_textdomain( 'storefront-product-pagination', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Cloning is forbidden.
|
133 |
-
*
|
134 |
-
* @since 1.0.0
|
135 |
-
*/
|
136 |
-
public function __clone() {
|
137 |
-
_doing_it_wrong( __FUNCTION__, esc_attr( __( 'Cheatin’ huh?' ) ), '1.0.0' );
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Unserializing instances of this class is forbidden.
|
142 |
-
*
|
143 |
-
* @since 1.0.0
|
144 |
-
*/
|
145 |
-
public function __wakeup() {
|
146 |
-
_doing_it_wrong( __FUNCTION__, esc_attr( __( 'Cheatin’ huh?' ) ), '1.0.0' );
|
147 |
-
}
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
*
|
153 |
-
* @access public
|
154 |
-
* @since 1.0.0
|
155 |
-
* @return void
|
156 |
-
*/
|
157 |
-
public function install() {
|
158 |
-
$this->_log_version_number();
|
159 |
-
|
160 |
-
// Get theme customizer url.
|
161 |
-
$url = admin_url() . 'customize.php?';
|
162 |
-
$url .= 'url=' . urlencode( site_url() . '?storefront-customizer=true' );
|
163 |
-
$url .= '&return=' . urlencode( admin_url() . 'plugins.php' );
|
164 |
-
$url .= '&storefront-customizer=true';
|
165 |
-
|
166 |
-
$notices = get_option( 'spp_activation_notice', array() );
|
167 |
-
$notices[] = sprintf( __( '%sThanks for installing the Storefront Product Pagination extension. Configure the settings in the %sCustomizer%s.%s %sOpen the Customizer%s', 'storefront-product-pagination' ), '<p>', '<a href="' . esc_url( $url ) . '">', '</a>', '</p>', '<p><a href="' . esc_url( $url ) . '" class="button button-primary">', '</a></p>' );
|
168 |
-
|
169 |
-
update_option( 'spp_activation_notice', $notices );
|
170 |
-
}
|
171 |
|
172 |
-
|
173 |
-
* Log the plugin version number.
|
174 |
-
*
|
175 |
-
* @access private
|
176 |
-
* @since 1.0.0
|
177 |
-
* @return void
|
178 |
-
*/
|
179 |
-
private function _log_version_number() {
|
180 |
-
// Log the version number.
|
181 |
-
update_option( $this->token . '-version', $this->version );
|
182 |
}
|
|
|
183 |
|
184 |
-
|
185 |
-
* Setup all the things.
|
186 |
-
* Only executes if Storefront or a child theme using Storefront as a parent is active and the extension specific filter returns true.
|
187 |
-
* Child themes can disable this extension using the storefront_extension_boilerplate_enabled filter
|
188 |
-
*
|
189 |
-
* @return void
|
190 |
-
*/
|
191 |
-
public function spp_setup() {
|
192 |
-
$theme = wp_get_theme();
|
193 |
-
|
194 |
-
if ( 'Storefront' === $theme->name || 'storefront' === $theme->template && apply_filters( 'storefront_product_pagination_supported', true ) ) {
|
195 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'spp_styles' ), 999 );
|
196 |
-
add_action( 'customize_register', array( $this, 'spp_customize_register' ) );
|
197 |
-
add_action( 'customize_preview_init', array( $this, 'spp_customize_preview_js' ) );
|
198 |
-
add_action( 'admin_notices', array( $this, 'spp_customizer_notice' ) );
|
199 |
-
|
200 |
-
add_action( 'woocommerce_after_single_product_summary', array( $this, 'spp_single_product_pagination' ), 30 );
|
201 |
-
|
202 |
-
// Hide the 'More' section in the customizer.
|
203 |
-
add_filter( 'storefront_customizer_more', '__return_false' );
|
204 |
-
} else {
|
205 |
-
add_action( 'admin_notices', array( $this, 'spp_install_storefront_notice' ) );
|
206 |
-
}
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Admin notice
|
211 |
-
* Checks the notice setup in install(). If it exists display it then delete the option so it's not displayed again.
|
212 |
-
*
|
213 |
-
* @since 1.0.0
|
214 |
-
* @return void
|
215 |
-
*/
|
216 |
-
public function spp_customizer_notice() {
|
217 |
-
$notices = get_option( 'spp_activation_notice' );
|
218 |
-
|
219 |
-
if ( $notices = get_option( 'spp_activation_notice' ) ) {
|
220 |
-
|
221 |
-
foreach ( $notices as $notice ) {
|
222 |
-
echo '<div class="updated">' . wp_kses_post( $notice ) . '</div>';
|
223 |
-
}
|
224 |
-
|
225 |
-
delete_option( 'spp_activation_notice' );
|
226 |
-
}
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Storefront install
|
231 |
-
* If the user activates the plugin while having a different parent theme active, prompt them to install Storefront.
|
232 |
-
*
|
233 |
-
* @since 1.0.0
|
234 |
-
* @return void
|
235 |
-
*/
|
236 |
-
public function spp_install_storefront_notice() {
|
237 |
-
echo '<div class="notice is-dismissible updated">
|
238 |
-
<p>' . wp_kses_post( __( 'Storefront Product Pagination requires that you use Storefront as your parent theme.', 'storefront-product-pagination' ) ) . ' <a href="' . esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-theme&theme=storefront' ), 'install-theme_storefront' ) ) .'">' . wp_kses_post( __( 'Install Storefront now', 'storefront-product-pagination' ) ) . '</a></p>
|
239 |
-
</div>';
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Customizer Controls and settings
|
244 |
-
*
|
245 |
-
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
246 |
-
*/
|
247 |
-
public function spp_customize_register( $wp_customize ) {
|
248 |
-
/**
|
249 |
-
* Add a new section
|
250 |
-
*/
|
251 |
-
$wp_customize->add_section( 'spp_section' , array(
|
252 |
-
'title' => __( 'Product Pagination', 'storefront-product-pagination' ),
|
253 |
-
'priority' => 55,
|
254 |
-
) );
|
255 |
-
|
256 |
-
/**
|
257 |
-
* Color picker
|
258 |
-
*/
|
259 |
-
$wp_customize->add_setting( 'spp_background_color', array(
|
260 |
-
'default' => apply_filters( 'spp_default_background_color', 'ffffff' ),
|
261 |
-
'sanitize_callback' => 'sanitize_hex_color',
|
262 |
-
'transport' => 'postMessage', // Refreshes instantly via js. See customizer.js. (default = refresh).
|
263 |
-
) );
|
264 |
-
|
265 |
-
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'spp_background_color', array(
|
266 |
-
'label' => __( 'Background color', 'storefront-product-pagination' ),
|
267 |
-
'description' => __( 'Background color for the product pagination links', 'storefront-product-pagination' ),
|
268 |
-
'section' => 'spp_section',
|
269 |
-
'settings' => 'spp_background_color',
|
270 |
-
'priority' => 30,
|
271 |
-
) ) );
|
272 |
-
|
273 |
-
/**
|
274 |
-
* Same category
|
275 |
-
*/
|
276 |
-
$wp_customize->add_setting( 'spp_same_cat', array(
|
277 |
-
'default' => false,
|
278 |
-
) );
|
279 |
-
|
280 |
-
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'spp_same_cat', array(
|
281 |
-
'label' => __( 'Display products in same category', 'storefront-product-pagination' ),
|
282 |
-
'description' => __( 'When enabled, pagination will only display links to products in the same category as the one currently being viewed.', 'storefront-product-pagination' ),
|
283 |
-
'section' => 'spp_section',
|
284 |
-
'settings' => 'spp_same_cat',
|
285 |
-
'type' => 'checkbox',
|
286 |
-
'priority' => 40,
|
287 |
-
) ) );
|
288 |
-
}
|
289 |
-
|
290 |
-
/**
|
291 |
-
* Enqueue CSS and custom styles.
|
292 |
-
*
|
293 |
-
* @since 1.0.0
|
294 |
-
* @return void
|
295 |
-
*/
|
296 |
-
public function spp_styles() {
|
297 |
-
wp_enqueue_style( 'spp-styles', plugins_url( '/assets/css/style.css', __FILE__ ) );
|
298 |
-
|
299 |
-
$heading_background_color = get_theme_mod( 'spp_background_color', apply_filters( 'spp_default_background_color', '#ffffff' ) );
|
300 |
-
|
301 |
-
$spp_style = '
|
302 |
-
.storefront-single-product-pagination a {
|
303 |
-
background-color: ' . $heading_background_color . ';
|
304 |
-
}';
|
305 |
-
|
306 |
-
wp_add_inline_style( 'spp-styles', $spp_style );
|
307 |
-
}
|
308 |
-
|
309 |
-
/**
|
310 |
-
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
|
311 |
-
*
|
312 |
-
* @since 1.0.0
|
313 |
-
*/
|
314 |
-
public function spp_customize_preview_js() {
|
315 |
-
wp_enqueue_script( 'spp-customizer', plugins_url( '/assets/js/customizer.min.js', __FILE__ ), array( 'customize-preview' ), '1.0.0', true );
|
316 |
-
}
|
317 |
-
|
318 |
-
/**
|
319 |
-
* Single product pagination
|
320 |
-
* Display links to the next/previous products on the single product page
|
321 |
-
*
|
322 |
-
* @since 1.0.0
|
323 |
-
* @return void
|
324 |
-
* @uses previous_post_link(), next_post_link()
|
325 |
-
*/
|
326 |
-
function spp_single_product_pagination() {
|
327 |
-
$placeholder = '<img src="' . wc_placeholder_img_src() . '" />';
|
328 |
-
$same_cat = get_theme_mod( 'spp_same_cat', false );
|
329 |
-
$taxonomy = 'category';
|
330 |
-
$in_same_term = false;
|
331 |
-
|
332 |
-
if ( true === $same_cat ) {
|
333 |
-
$in_same_term = true;
|
334 |
-
$taxonomy = 'product_cat';
|
335 |
-
}
|
336 |
-
|
337 |
-
$previous_product = get_previous_post( $same_cat, '', $taxonomy );
|
338 |
-
$next_product = get_next_post( $same_cat, '', $taxonomy );
|
339 |
-
|
340 |
-
$previous_product_thumbnail = '';
|
341 |
-
$next_product_thumbnail = '';
|
342 |
-
|
343 |
-
$previous_product_data = '';
|
344 |
-
$next_product_data = '';
|
345 |
-
|
346 |
-
// If a next/previous product exists, get the thumbnail (or place holder).
|
347 |
-
if ( $previous_product ) {
|
348 |
-
$previous_product_data = new WC_Product( $previous_product->ID );
|
349 |
-
$previous_product_thumbnail = get_the_post_thumbnail( $previous_product->ID, 'shop_catalog' );
|
350 |
-
|
351 |
-
if ( ! $previous_product_thumbnail ) {
|
352 |
-
$previous_product_thumbnail = $placeholder;
|
353 |
-
}
|
354 |
-
}
|
355 |
-
|
356 |
-
if ( $next_product ) {
|
357 |
-
$next_product_data = new WC_Product( $next_product->ID );
|
358 |
-
$next_product_thumbnail = get_the_post_thumbnail( $next_product->ID, 'shop_catalog' );
|
359 |
-
|
360 |
-
if ( ! $next_product_thumbnail ) {
|
361 |
-
$next_product_thumbnail = $placeholder;
|
362 |
-
}
|
363 |
-
}
|
364 |
-
|
365 |
-
// Output the links.
|
366 |
-
if ( $next_product || $previous_product ) {
|
367 |
-
|
368 |
-
echo '<nav class="storefront-single-product-pagination">';
|
369 |
-
|
370 |
-
echo '<h2>' . esc_attr( __( 'More products', 'storefront-product-pagination' ) ) . '</h2>';
|
371 |
-
|
372 |
-
if ( $previous_product && $previous_product_data->is_visible() ) {
|
373 |
-
previous_post_link( '%link', $previous_product_thumbnail . '<span class="title">%title</span>', $in_same_term, '', $taxonomy );
|
374 |
-
}
|
375 |
-
|
376 |
-
if ( $next_product && $next_product_data->is_visible() ) {
|
377 |
-
next_post_link( '%link', $next_product_thumbnail . '<span class="title">%title</span>', $in_same_term, '', $taxonomy );
|
378 |
-
}
|
379 |
-
|
380 |
-
echo '</nav>';
|
381 |
-
|
382 |
-
}
|
383 |
-
}
|
384 |
-
} // End Class
|
3 |
* Plugin Name: Storefront Product Pagination
|
4 |
* Plugin URI: http://woothemes.com/storefront/
|
5 |
* Description: Add unobstrusive links to next/previous products on your WooCommerce single product pages.
|
6 |
+
* Version: 1.2.4
|
7 |
* Author: WooThemes
|
8 |
* Author URI: http://woothemes.com/
|
9 |
+
* Requires at least: 4.0
|
10 |
+
* Tested up to: 4.9
|
11 |
*
|
12 |
* Text Domain: storefront-product-pagination
|
13 |
* Domain Path: /languages/
|
21 |
exit; // Exit if accessed directly.
|
22 |
}
|
23 |
|
|
|
24 |
/**
|
25 |
+
* Only load plugin if Storefront version is under 2.3.0.
|
26 |
*
|
27 |
+
* @since 1.2.4
|
28 |
+
* @return void
|
29 |
*/
|
30 |
+
function storefront_product_pagination_init() {
|
31 |
+
global $storefront_version;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
if ( class_exists( 'Storefront' ) && version_compare( $storefront_version, '2.3.0', '<' ) ) {
|
34 |
+
require 'classes/class-storefront-product-pagination.php';
|
35 |
+
require 'functions/functions.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
storefront_product_pagination();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
+
} // end storefront_product_pagination_init()
|
40 |
|
41 |
+
add_action( 'after_setup_theme', 'storefront_product_pagination_init' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|