Skip to content

Commit de4a28f

Browse files
committed
Add Memberships support and new Subscription periods
1 parent 7efffc1 commit de4a28f

8 files changed

Lines changed: 243 additions & 30 deletions

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ We like [ForwardHQ](https://fwd.wf) for this, along with a `ForwardFile` in your
1414
Adds a "renew" link to each subscription under WooCommerce > Subscriptions for easy renewal processing. This is particularly useful for testing
1515
payment gateways that supports subscriptions.
1616

17+
Allows a minutes and hours-long Subscription periods for quicker testing.
18+
19+
### Memberships
20+
21+
Allows a minutes and hours-long Membership length for quicker testing.
22+
1723
### Global Functions
1824

1925
* `wp_debug_backtrace()` - helper for using the `debug_backtrace()` function with a bit more sanity
2026
* `wp_var_dump()` - helper for `var_dump`, allowing you to return the output instead of printing
2127
* `wp_var_log()` - helper for `error_log` that uses `print_r()` or optionally `wp_var_dump()`
28+
* `wp_print_r()` - helper for `print_r` that wraps the output in `<pre>` HTML tags
2229

2330
### Misc
2431

@@ -32,6 +39,11 @@ Download and install just like any other WordPress plugin. If you want to be rea
3239

3340
## Changelog
3441

42+
### 0.4.0 - 2016.06.06
43+
* Feature - Added minutes and hours Subscription periods for quicker Subscriptions testing
44+
* Feature - Added Memberships support with minutes and hours Memberships periods for quicker access and dripping testing
45+
* Feature = Added `wp_print_r` helper function
46+
3547
### 0.3.0 - 2015.12.28
3648
* Feature - Removes WooCommerce 2.5+ strong password requirement for customer registration
3749

i18n/languages/woocommerce-dev-helper.pot

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
1-
# Copyright (C) 2015 SkyVerge
1+
# Copyright (C) 2016 SkyVerge
22
# This file is distributed under the GNU General Public License v3.0.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: WooCommerce Dev Helper 0.3.0\n"
5+
"Project-Id-Version: WooCommerce Dev Helper 0.4.0\n"
66
"Report-Msgid-Bugs-To: "
77
"https://github.com/skyverge/woocommerce-dev-helper/issues\n"
88
"POT-Creation-Date: 2015-07-26 19:51:27+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=utf-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12+
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
1515

16-
#: includes/class-wc-dev-helper-subscriptions.php:91
16+
#: includes/class-wc-dev-helper-memberships.php:55
17+
msgid "minute(s)"
18+
msgstr ""
19+
20+
#: includes/class-wc-dev-helper-memberships.php:56
21+
msgid "hour(s)"
22+
msgstr ""
23+
24+
#: includes/class-wc-dev-helper-subscriptions.php:97
1725
msgid "Renew"
1826
msgstr ""
1927

20-
#: includes/class-wc-dev-helper-subscriptions.php:144
28+
#: includes/class-wc-dev-helper-subscriptions.php:150
2129
msgid "Subscription renewal processed. %sView Renewal Order%s"
2230
msgstr ""
2331

24-
#: includes/class-wc-dev-helper-subscriptions.php:167
32+
#: includes/class-wc-dev-helper-subscriptions.php:173
2533
msgid "Action Failed, Invalid Nonce"
2634
msgstr ""
2735

28-
#: includes/class-wc-dev-helper-subscriptions.php:196
36+
#: includes/class-wc-dev-helper-subscriptions.php:202
2937
msgid "Subscription Renewal Processed"
3038
msgstr ""
3139

32-
#: woocommerce-dev-helper.php:205
40+
#: woocommerce-dev-helper.php:261
3341
msgid "You cannot clone instances of WooCommerce Dev Helper."
3442
msgstr ""
3543

36-
#: woocommerce-dev-helper.php:215
44+
#: woocommerce-dev-helper.php:271
3745
msgid "You cannot unserialize instances of WooCommerce Dev Helper."
3846
msgstr ""
3947

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* WooCommerce Dev Helper
4+
*
5+
* This source file is subject to the GNU General Public License v3.0
6+
* that is bundled with this package in the file license.txt.
7+
* It is also available through the world-wide-web at this URL:
8+
* http://www.gnu.org/licenses/gpl-3.0.html
9+
* If you did not receive a copy of the license and are unable to
10+
* obtain it through the world-wide-web, please send an email
11+
* to license@skyverge.com so we can send you a copy immediately.
12+
*
13+
* @package WC-Dev-Helper/Classes
14+
* @author SkyVerge
15+
* @copyright Copyright (c) 2015, SkyVerge, Inc.
16+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
17+
*/
18+
19+
defined( 'ABSPATH' ) or exit;
20+
21+
/**
22+
* Memberships Class
23+
*
24+
* This provides some helpers for development work on WooCommerce Memberships
25+
*
26+
* @since 0.4.0
27+
*/
28+
class WC_Dev_Helper_Memberships {
29+
30+
31+
/**
32+
* Memberships helper
33+
*
34+
* @since 0.4.0
35+
*/
36+
public function __construct() {
37+
38+
if ( is_admin() && ! is_ajax() ) {
39+
40+
add_filter( 'wc_memberships_plan_access_period_options', array( $this, 'add_membership_plan_access_period_options' ) );
41+
}
42+
}
43+
44+
45+
/**
46+
* Allow minutes and hours-long access period options for plans
47+
*
48+
* @since 1.6.0-1
49+
* @param array $periods
50+
* @return array
51+
*/
52+
public function add_membership_plan_access_period_options( $periods ) {
53+
54+
$new_periods = array(
55+
'minutes' => __( 'minute(s)', 'woocommerce-dev-helper' ),
56+
'hours' => __( 'hour(s)', 'woocommerce-dev-helper' ),
57+
);
58+
59+
return array_merge( $new_periods, $periods );
60+
}
61+
62+
63+
}

includes/class-wc-dev-helper-subscriptions.php

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

19-
defined( 'ABSPATH' ) || exit;
19+
defined( 'ABSPATH' ) or exit;
2020

2121
/**
2222
* Subscriptions Class
@@ -36,7 +36,7 @@ class WC_Dev_Helper_Subscriptions {
3636
*/
3737
public function __construct() {
3838

39-
// Without this, and when using forwarded URLs, WC Subscriptions believes the site to be "duplicate" and disables updating the payment method
39+
// without this, and when using forwarded URLs, WC Subscriptions believes the site to be "duplicate" and disables updating the payment method
4040
add_filter( 'woocommerce_subscriptions_is_duplicate_site', '__return_false' );
4141

4242
// add the renew action to the Subscriptions list table
@@ -46,13 +46,19 @@ public function __construct() {
4646
add_filter( 'woocommerce_subscriptions_list_table_actions', array( $this, 'add_renew_action' ), 10, 2 );
4747
}
4848

49-
// process the renewa action
49+
// process the renewal action
5050
if ( $this->is_subs_gte_2_0() ) {
5151
add_action( 'load-edit.php', array( $this, 'process_renew_action' ) );
5252
add_action( 'admin_notices', array( $this, 'maybe_render_renewal_success_message' ) );
5353
} else {
5454
add_action( 'load-woocommerce_page_subscriptions', array( $this, 'process_pre_subs_2_0_renew_action' ) );
5555
}
56+
57+
// add support for minutes and hours-long Subscription period for quicker testing
58+
add_filter( 'woocommerce_subscription_available_time_periods', array( $this, 'new_subscription_periods' ) );
59+
add_filter( 'woocommerce_subscription_periods', array( $this, 'new_subscription_periods' ) );
60+
add_filter( 'woocommerce_subscription_trial_periods', array( $this, 'new_subscription_periods' ) );
61+
add_filter( 'woocommerce_subscription_lengths', array( $this, 'new_subscription_lengths' ) );
5662
}
5763

5864

@@ -211,4 +217,53 @@ protected function is_subs_gte_2_0() {
211217
}
212218

213219

220+
/**
221+
* Add the minute / hour into available subscription period options
222+
*
223+
* @since 0.4.0
224+
* @param array $subscription_periods associative array of available periods
225+
* @return array with updated periods
226+
*/
227+
public function new_subscription_periods( $subscription_periods ) {
228+
229+
$new_periods = array(
230+
'minute' => 'minute',
231+
'hour' => 'hour',
232+
);
233+
234+
return array_merge( $new_periods, $subscription_periods);
235+
}
236+
237+
238+
/**
239+
* Add subscription lengths for our new "minute" and "hour" period
240+
*
241+
* @since 0.4.0
242+
* @param array $lengths associative array of available lengths
243+
* @return array - updated lengths
244+
*/
245+
public function new_subscription_lengths( $lengths ) {
246+
// start range with 0 => all time
247+
$minute_durations = array( 'all time', '1 minute' );
248+
$minute_steps = range( 5, 60, 5 );
249+
250+
// add possible steps for subscription duration
251+
foreach( $minute_steps as $number ) {
252+
$minute_durations[ $number ] = $number . ' minutes';
253+
}
254+
255+
$hour_durations = array( 'all time', '1 hour' );
256+
$hour_steps = range( 2, 6 );
257+
258+
foreach ( $hour_steps as $number ) {
259+
$hour_durations[ $number ] = $number . ' hours';
260+
}
261+
262+
$lengths['minute'] = $minute_durations;
263+
$lengths['hour'] = $hour_durations;
264+
265+
return $lengths;
266+
}
267+
268+
214269
}

includes/class-wc-dev-helper-use-forwarded-urls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

19-
defined( 'ABSPATH' ) || exit;
19+
defined( 'ABSPATH' ) or exit;
2020

2121
/**
2222
* Forwarded URLs Class

includes/wc-dev-helper-functions.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

19-
defined( 'ABSPATH' ) || exit;
19+
defined( 'ABSPATH' ) or exit;
2020

2121

2222
if ( ! function_exists( 'wp_debug_backtrace' ) ) :
@@ -25,7 +25,7 @@
2525
* Helper function for the PHP debug_backtrace() function.
2626
* This is based on the Magento mageDebugBacktrace() function.
2727
*
28-
* Example usage: error_log(wp_debug_backtrace());
28+
* Example usage: error_log( wp_debug_backtrace() );
2929
*
3030
* @since 0.1.0
3131
* @param bool $return if true, returns the output, otherwise echo's
@@ -76,7 +76,7 @@ function wp_debug_backtrace( $return = true, $html = false, $show_first = true )
7676
* directive, null leaves it untouched. Useful when dumping variables
7777
* to the command line with Xdebug installed and html formatting is
7878
* not desired.
79-
* @return mixed Returns a string if $return is true, void otherwise
79+
* @return void|string Returns a string if $return is true, void otherwise
8080
*/
8181
function wp_var_dump( $var, $return = true, $html_errors = false ) {
8282

@@ -109,7 +109,7 @@ function wp_var_dump( $var, $return = true, $html_errors = false ) {
109109
/**
110110
* print_r or var_dump a variable to the error log, useful for logging.
111111
*
112-
* example usage: wp_var_log( $var )
112+
* example usage: wp_var_log( $var );
113113
*
114114
* @since 0.1.0
115115
* @param mixed $var variable to log
@@ -126,3 +126,22 @@ function wp_var_log( $var, $dump = false ) {
126126
}
127127

128128
endif;
129+
130+
131+
if ( ! function_exists( 'wp_print_r' ) ) :
132+
133+
/**
134+
* Print human-readable information about a variable
135+
* wrapping it in pre-formatted HTML tags
136+
*
137+
* example usage: wp_print_r( $var );
138+
*
139+
* @since 0.4.0
140+
* @param $var
141+
*/
142+
function wp_print_r( $var ) {
143+
144+
echo '<pre>'; print_r( $var ); echo '</pre>';
145+
}
146+
147+
endif;

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "woocommerce-customizer",
3-
"version": "1.2.1",
2+
"name": "woocommerce-dev-helper",
3+
"version": "0.4.0",
44
"author": "SkyVerge Team",
55
"homepage": "http://www.skyverge.com",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/skyverge/woocommerce-customizer.git"
8+
"url": "https://github.com/skyverge/woocommerce-dev-helper.git"
99
},
1010
"bugs": {
11-
"url": "https://github.com/skyverge/woocommerce-customizer/issues"
11+
"url": "https://github.com/skyverge/woocommerce-dev-helper/issues"
1212
},
1313
"engines": {
1414
"node": ">= 0.10.0"

0 commit comments

Comments
 (0)