Skip to content

Commit 2112c84

Browse files
committed
Add wc_dev_get_session JS utility, bump dates, version, readme
1 parent a2fa1c5 commit 2112c84

8 files changed

Lines changed: 98 additions & 14 deletions

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WooCommerce Dev Helper
22
======================
33

4-
This is a simple and opinionated plugin for helping develop/debug WooCommerce & extensions.
4+
This is a simple and opinionated plugin for helping develop/debug WooCommerce & extensions. DO NOT USE ON A PRODUCTION SERVER.
55

66
### Use Forwarded URLs
77

@@ -26,6 +26,7 @@ Allows minutes and hours-long Membership lengths for quicker testing.
2626
* `wp_var_dump()` - helper for `var_dump`, allowing you to return the output instead of printing
2727
* `wp_var_log()` - helper for `error_log` that uses `print_r()` or optionally `wp_var_dump()`
2828
* `wp_print_r()` - helper for `print_r` that wraps the output in `<pre>` HTML tags
29+
* `wc_dev_session` - JS helper to get all the current session data in console
2930

3031
### Misc
3132

@@ -39,11 +40,14 @@ Download and install just like any other WordPress plugin. If you want to be rea
3940

4041
## Changelog
4142

43+
### 0.5.0 - 2017.01.19
44+
* Feature - Dump the current session in AJAX to display in browser console
45+
4246
### 0.4.2 - 2016.10.21
43-
* Tweak - Filter the human access length for membership plans that have a length in minutes or hours set via this helper plugin (Memberships 1.7.2+)
47+
* Tweak - Filter the human access length for membership plans that have a length in minutes or hours set via this helper plugin (Memberships 1.7.2+)
4448

4549
### 0.4.1 - 2016.10.18
46-
* Fix - Minutes and hours-long periods in membership plans did not work properly or when creating a user membership in admin and setting the length from the membership plan default
50+
* Fix - Minutes and hours-long periods in membership plans did not work properly or when creating a user membership in admin and setting the length from the membership plan default
4751

4852
### 0.4.0 - 2016.06.06
4953
* Feature - Added minutes and hours Subscription periods for quicker Subscriptions testing
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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-2017, 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+
class WC_Dev_Helper_Ajax {
22+
23+
24+
/**
25+
* Add AJAX actions.
26+
*
27+
* @since 0.5.0
28+
*/
29+
public function __construct() {
30+
31+
add_action( 'wp_ajax_wc_dev_helper_get_session', array( $this, 'get_session_data' ) );
32+
add_action( 'wp_ajax_nopriv_wc_dev_helper_get_session', array( $this, 'get_session_data' ) );
33+
}
34+
35+
36+
/**
37+
* Get session data from WooCommerce for the current user.
38+
*
39+
* @since 0.5.0
40+
*/
41+
public function get_session_data() {
42+
43+
/* @type \WC_Session_Handler $session_handler */
44+
$session_handler = WC()->session;
45+
46+
wp_send_json( $session_handler->get_session_data() );
47+
}
48+
49+
50+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @package WC-Dev-Helper/Classes
1414
* @author SkyVerge
15-
* @copyright Copyright (c) 2015, SkyVerge, Inc.
15+
* @copyright Copyright (c) 2015-2017, SkyVerge, Inc.
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @package WC-Dev-Helper/Classes
1414
* @author SkyVerge
15-
* @copyright Copyright (c) 2015, SkyVerge, Inc.
15+
* @copyright Copyright (c) 2015-2017, SkyVerge, Inc.
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @package WC-Dev-Helper/Classes
1414
* @author SkyVerge
15-
* @copyright Copyright (c) 2015, SkyVerge, Inc.
15+
* @copyright Copyright (c) 2015-2017, SkyVerge, Inc.
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

includes/wc-dev-helper-functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @package WC-Dev-Helper/Classes
1414
* @author SkyVerge
15-
* @copyright Copyright (c) 2015, SkyVerge, Inc.
15+
* @copyright Copyright (c) 2015-2017, SkyVerge, Inc.
1616
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
1717
*/
1818

@@ -129,18 +129,18 @@ function wp_var_log( $var, $dump = false ) {
129129

130130

131131
if ( ! function_exists( 'wp_print_r' ) ) :
132-
132+
133133
/**
134134
* Print human-readable information about a variable
135135
* wrapping it in pre-formatted HTML tags
136-
*
136+
*
137137
* example usage: wp_print_r( $var );
138138
*
139139
* @since 0.4.0
140140
* @param $var
141141
*/
142142
function wp_print_r( $var ) {
143-
143+
144144
echo '<pre>'; print_r( $var ); echo '</pre>';
145145
}
146146

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "woocommerce-dev-helper",
3-
"version": "0.4.2",
3+
"version": "0.5.0",
44
"author": "SkyVerge Team",
55
"homepage": "http://www.skyverge.com",
66
"repository": {

woocommerce-dev-helper.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
* Description: A simple plugin for helping develop/debug WooCommerce & extensions
66
* Author: SkyVerge
77
* Author URI: http://www.skyverge.com
8-
* Version: 0.4.2
8+
* Version: 0.5.0
99
* Text Domain: woocommerce-dev-helper
1010
* Domain Path: /i18n/languages/
1111
*
12-
* Copyright: (c) 2015-2016 SkyVerge [info@skyverge.com]
12+
* Copyright: (c) 2015-2017 SkyVerge [info@skyverge.com]
1313
*
1414
* License: GNU General Public License v3.0
1515
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
1616
*
1717
* @package WooCommerce-Dev-Helper
1818
* @author SkyVerge
1919
* @category Development
20-
* @copyright Copyright (c) 2012-2016, SkyVerge
20+
* @copyright Copyright (c) 2012-2017, SkyVerge
2121
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
2222
*/
2323

@@ -29,6 +29,9 @@ class WC_Dev_Helper {
2929
/** @var \WC_Dev_Helper instance */
3030
protected static $instance;
3131

32+
/** @var \WC_Dev_Helper_Ajax instance */
33+
protected $ajax;
34+
3235
/** @var \WC_Dev_Helper_Use_Forwarded_URLs instance */
3336
protected $use_forwarded_urls;
3437

@@ -60,6 +63,9 @@ public function __construct() {
6063

6164
// remove WC strong password script
6265
add_action( 'wp_print_scripts', array( $this, 'remove_wc_password_meter' ), 100 );
66+
67+
// add some inline JS
68+
add_action( 'wp_footer', array( $this, 'enqueue_scripts' ) );
6369
}
6470

6571

@@ -85,13 +91,37 @@ public function remove_wc_password_meter() {
8591
}
8692

8793

94+
/**
95+
* Add inline JavaScript.
96+
*
97+
* @since 0.5.0
98+
*/
99+
public function enqueue_scripts() {
100+
101+
?>
102+
<script type="text/javascript">
103+
function wc_dev_get_session() {
104+
jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', { action: 'wc_dev_helper_get_session' }, function( response ) {
105+
console.log( response );
106+
});
107+
}
108+
</script>
109+
<?php
110+
}
111+
112+
88113
/**
89114
* Include required files
90115
*
91116
* @since 0.1.0
92117
*/
93118
public function includes() {
94119

120+
require_once( $this->get_plugin_path() . '/includes/class-wc-dev-helper-ajax.php' );
121+
if ( $this->is_plugin_active( 'woocommerce.php' ) && is_ajax() ) {
122+
$this->ajax = new WC_Dev_Helper_Ajax();
123+
}
124+
95125
// use forwarded URLs
96126
require_once( $this->get_plugin_path() . '/includes/class-wc-dev-helper-use-forwarded-urls.php' );
97127
$this->use_forwarded_urls = new WC_Dev_Helper_Use_Forwarded_URLs();

0 commit comments

Comments
 (0)