AfterShip – WooCommerce Tracking - Version 1.3.4

Version Description

  • Fix the custom track message tailing space problem
Download this release

Release Info

Developer aftership
Plugin Icon 128x128 AfterShip – WooCommerce Tracking
Version 1.3.4
Comparing to
See all releases

Code changes from version 1.3.3 to 1.3.4

Files changed (3) hide show
  1. aftership.php +1 -1
  2. class-aftership-settings.php +202 -192
  3. readme.txt +4 -1
aftership.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: AfterShip - WooCommerce Tracking
4
  Plugin URI: http://aftership.com/
5
  Description: Add tracking number and carrier name to WooCommerce, display tracking info at order history page, auto import tracking numbers to AfterShip.
6
- Version: 1.3.3
7
  Author: AfterShip
8
  Author URI: http://aftership.com
9
 
3
  Plugin Name: AfterShip - WooCommerce Tracking
4
  Plugin URI: http://aftership.com/
5
  Description: Add tracking number and carrier name to WooCommerce, display tracking info at order history page, auto import tracking numbers to AfterShip.
6
+ Version: 1.3.4
7
  Author: AfterShip
8
  Author URI: http://aftership.com
9
 
class-aftership-settings.php CHANGED
@@ -15,136 +15,136 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
15
  /**
16
  * Required functions
17
  */
18
- if ( ! class_exists( 'AfterShip_Dependencies' ) )
19
- require_once 'class-aftership-dependencies.php';
20
 
21
  class AfterShip_Settings
22
  {
23
- /**
24
- * Holds the values to be used in the fields callbacks
25
- */
26
- private $options;
27
-
28
- private $plugins;
29
-
30
- /**
31
- * Start up
32
- */
33
- public function __construct()
34
- {
35
- $this->plugins[] = array(
36
- 'value' => 'aftership',
37
- 'label' => 'AfterShip',
38
- 'path' => 'aftership-woocommerce-tracking/aftership.php'
39
- );
40
- $this->plugins[] = array(
41
- 'value' => 'wc-shipment-tracking',
42
- 'label' => 'WooCommerce Shipment Tracking',
43
- 'path' => 'woocommerce-shipment-tracking/shipment-tracking.php'
44
- );
45
-
46
- add_action('admin_menu', array($this, 'add_plugin_page'));
47
- add_action('admin_init', array($this, 'page_init'));
48
- add_action('admin_print_styles', array($this, 'admin_styles'));
49
- add_action('admin_print_scripts', array(&$this, 'library_scripts'));
50
- }
51
-
52
-
53
- public function admin_styles()
54
- {
55
- wp_enqueue_style('aftership_styles_chosen', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.min.css');
56
- wp_enqueue_style('aftership_styles', plugins_url(basename(dirname(__FILE__))) . '/assets/css/admin.css');
57
- }
58
-
59
- public function library_scripts()
60
- {
61
- wp_enqueue_script('aftership_styles_chosen_jquery', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.jquery.min.js');
62
- wp_enqueue_script('aftership_styles_chosen_proto', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.proto.min.js');
63
- wp_enqueue_script('aftership_script_util', plugins_url(basename(dirname(__FILE__))) . '/assets/js/util.js');
64
- wp_enqueue_script('aftership_script_couriers', plugins_url(basename(dirname(__FILE__))) . '/assets/js/couriers.js');
65
- wp_enqueue_script('aftership_script_setting', plugins_url(basename(dirname(__FILE__))) . '/assets/js/setting.js');
66
- }
67
-
68
- /**
69
- * Add options page
70
- */
71
- public function add_plugin_page()
72
- {
73
- // This page will be under "Settings"
74
- add_options_page(
75
- 'AfterShip Settings Admin',
76
- 'AfterShip',
77
- 'manage_options',
78
- 'aftership-setting-admin',
79
- array($this, 'create_admin_page')
80
- );
81
- }
82
-
83
- /**
84
- * Options page callback
85
- */
86
- public function create_admin_page()
87
- {
88
- // Set class property
89
- $this->options = get_option('aftership_option_name');
90
- ?>
91
- <div class="wrap">
92
- <?php screen_icon(); ?>
93
- <h2>AfterShip Settings</h2>
94
-
95
- <form method="post" action="options.php">
96
- <?php
97
- // This prints out all hidden setting fields
98
- settings_fields('aftership_option_group');
99
- do_settings_sections('aftership-setting-admin');
100
- submit_button();
101
- ?>
102
- </form>
103
- </div>
104
- <?php
105
- }
106
-
107
- /**
108
- * Register and add settings
109
- */
110
- public function page_init()
111
- {
112
- register_setting(
113
- 'aftership_option_group', // Option group
114
- 'aftership_option_name', // Option name
115
- array($this, 'sanitize') // Sanitize
116
- );
117
-
118
- add_settings_section(
119
- 'aftership_setting_section_id', // ID
120
- '', // Title
121
- array($this, 'print_section_info'), // Callback
122
- 'aftership-setting-admin' // Page
123
- );
124
-
125
- add_settings_field(
126
- 'plugin',
127
- 'Plugin',
128
- array($this, 'plugin_callback'),
129
- 'aftership-setting-admin',
130
- 'aftership_setting_section_id'
131
- );
132
-
133
- add_settings_field(
134
- 'couriers',
135
- 'Couriers',
136
- array($this, 'couriers_callback'),
137
- 'aftership-setting-admin',
138
- 'aftership_setting_section_id'
139
- );
140
-
141
- add_settings_field(
142
- 'use_track_button',
143
- 'Display Track Button at Order History Page',
144
- array($this, 'track_button_callback'),
145
- 'aftership-setting-admin',
146
- 'aftership_setting_section_id'
147
- );
148
 
149
  add_settings_field(
150
  'track_message',
@@ -153,87 +153,97 @@ class AfterShip_Settings
153
  'aftership-setting-admin',
154
  'aftership_setting_section_id'
155
  );
156
- }
157
-
158
- /**
159
- * Sanitize each setting field as needed
160
- *
161
- * @param array $input Contains all settings fields as array keys
162
- */
163
- public function sanitize($input)
164
- {
165
- $new_input = array();
166
 
167
- if (isset($input['couriers'])) {
168
- $new_input['couriers'] = sanitize_text_field($input['couriers']);
169
- }
 
 
 
 
 
 
 
 
 
170
 
171
- if (isset($input['plugin'])) {
172
- $new_input['plugin'] = sanitize_text_field($input['plugin']);
173
- }
174
 
175
  if (isset($input['track_message_1'])) {
176
- $new_input['track_message_1'] = sanitize_text_field($input['track_message_1']);
 
 
 
 
177
  }
178
 
179
  if (isset($input['track_message_2'])) {
180
- $new_input['track_message_2'] = sanitize_text_field($input['track_message_2']);
 
 
 
 
181
  }
182
 
183
  if (isset($input['use_track_button'])) {
184
- $new_input['use_track_button'] = true;
185
- }
186
 
187
- return $new_input;
188
- }
189
 
190
- /**
191
- * Print the Section text
192
- */
193
- public function print_section_info()
194
- {
195
- //print 'Enter your settings below:';
196
- }
197
 
198
- public function couriers_callback(){
 
199
 
200
- $couriers = array();
201
- if (isset($this->options['couriers'])){
202
- $couriers = explode(',', $this->options['couriers']);
203
- }
204
 
205
  // print_r($couriers);
206
- echo '<select data-placeholder="Please select couriers" id="couriers_select" class="chosen-select " multiple style="width:100%">';
207
- echo '</select>';
208
  // echo '<br><a href="https://www.aftership.com/settings/courier" target="_blank">Update carrier list</a>';
209
- echo '<input type="hidden" id="couriers" name="aftership_option_name[couriers]" value="' . implode(",", $couriers) . '"/>';
210
 
211
- }
212
 
213
- public function plugin_callback()
214
- {
215
 
216
- $options = "";
217
- foreach ($this->plugins as $plugin) {
218
- //print_r($plugin);
219
- if (AfterShip_Dependencies::plugin_active_check($plugin['path'])) {
220
- $option = '<option value="' . $plugin['value'] . '"';
221
 
222
- if (isset($this->options['plugin']) && esc_attr($this->options['plugin']) == $plugin['value']) {
223
- $option .= ' selected="selected"';
224
- }
225
 
226
- $option .= '>' . $plugin['label'] . '</option>';
227
- $options .= $option;
228
- }
229
- }
230
 
231
- printf(
232
- '<select id="plugin" name="aftership_option_name[plugin]" class="aftership_dropdown">' . $options . '</select>'
233
- );
234
- }
235
 
236
- public function track_message_callback(){
 
237
  printf(
238
  '<input type="text" id="track_message_1" name="aftership_option_name[track_message_1]" value="%s" style="width:100%%">',
239
  isset($this->options['track_message_1']) ? $this->options['track_message_1'] : 'Your order was shipped via '
@@ -251,15 +261,15 @@ class AfterShip_Settings
251
  );
252
  }
253
 
254
- public function track_button_callback()
255
- {
256
- printf(
257
- '<label><input type="checkbox" id="use_track_button" name="aftership_option_name[use_track_button]" %s>Use Track Button</label>',
258
- (isset($this->options['use_track_button']) && $this->options['use_track_button'] === true) ? 'checked="checked"' : ''
259
- );
260
- }
261
  }
262
 
263
 
264
  if (is_admin())
265
- $aftership_settings = new AfterShip_Settings();
15
  /**
16
  * Required functions
17
  */
18
+ if (!class_exists('AfterShip_Dependencies'))
19
+ require_once 'class-aftership-dependencies.php';
20
 
21
  class AfterShip_Settings
22
  {
23
+ /**
24
+ * Holds the values to be used in the fields callbacks
25
+ */
26
+ private $options;
27
+
28
+ private $plugins;
29
+
30
+ /**
31
+ * Start up
32
+ */
33
+ public function __construct()
34
+ {
35
+ $this->plugins[] = array(
36
+ 'value' => 'aftership',
37
+ 'label' => 'AfterShip',
38
+ 'path' => 'aftership-woocommerce-tracking/aftership.php'
39
+ );
40
+ $this->plugins[] = array(
41
+ 'value' => 'wc-shipment-tracking',
42
+ 'label' => 'WooCommerce Shipment Tracking',
43
+ 'path' => 'woocommerce-shipment-tracking/shipment-tracking.php'
44
+ );
45
+
46
+ add_action('admin_menu', array($this, 'add_plugin_page'));
47
+ add_action('admin_init', array($this, 'page_init'));
48
+ add_action('admin_print_styles', array($this, 'admin_styles'));
49
+ add_action('admin_print_scripts', array(&$this, 'library_scripts'));
50
+ }
51
+
52
+
53
+ public function admin_styles()
54
+ {
55
+ wp_enqueue_style('aftership_styles_chosen', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.min.css');
56
+ wp_enqueue_style('aftership_styles', plugins_url(basename(dirname(__FILE__))) . '/assets/css/admin.css');
57
+ }
58
+
59
+ public function library_scripts()
60
+ {
61
+ wp_enqueue_script('aftership_styles_chosen_jquery', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.jquery.min.js');
62
+ wp_enqueue_script('aftership_styles_chosen_proto', plugins_url(basename(dirname(__FILE__))) . '/assets/plugin/chosen/chosen.proto.min.js');
63
+ wp_enqueue_script('aftership_script_util', plugins_url(basename(dirname(__FILE__))) . '/assets/js/util.js');
64
+ wp_enqueue_script('aftership_script_couriers', plugins_url(basename(dirname(__FILE__))) . '/assets/js/couriers.js');
65
+ wp_enqueue_script('aftership_script_setting', plugins_url(basename(dirname(__FILE__))) . '/assets/js/setting.js');
66
+ }
67
+
68
+ /**
69
+ * Add options page
70
+ */
71
+ public function add_plugin_page()
72
+ {
73
+ // This page will be under "Settings"
74
+ add_options_page(
75
+ 'AfterShip Settings Admin',
76
+ 'AfterShip',
77
+ 'manage_options',
78
+ 'aftership-setting-admin',
79
+ array($this, 'create_admin_page')
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Options page callback
85
+ */
86
+ public function create_admin_page()
87
+ {
88
+ // Set class property
89
+ $this->options = get_option('aftership_option_name');
90
+ ?>
91
+ <div class="wrap">
92
+ <?php screen_icon(); ?>
93
+ <h2>AfterShip Settings</h2>
94
+
95
+ <form method="post" action="options.php">
96
+ <?php
97
+ // This prints out all hidden setting fields
98
+ settings_fields('aftership_option_group');
99
+ do_settings_sections('aftership-setting-admin');
100
+ submit_button();
101
+ ?>
102
+ </form>
103
+ </div>
104
+ <?php
105
+ }
106
+
107
+ /**
108
+ * Register and add settings
109
+ */
110
+ public function page_init()
111
+ {
112
+ register_setting(
113
+ 'aftership_option_group', // Option group
114
+ 'aftership_option_name', // Option name
115
+ array($this, 'sanitize') // Sanitize
116
+ );
117
+
118
+ add_settings_section(
119
+ 'aftership_setting_section_id', // ID
120
+ '', // Title
121
+ array($this, 'print_section_info'), // Callback
122
+ 'aftership-setting-admin' // Page
123
+ );
124
+
125
+ add_settings_field(
126
+ 'plugin',
127
+ 'Plugin',
128
+ array($this, 'plugin_callback'),
129
+ 'aftership-setting-admin',
130
+ 'aftership_setting_section_id'
131
+ );
132
+
133
+ add_settings_field(
134
+ 'couriers',
135
+ 'Couriers',
136
+ array($this, 'couriers_callback'),
137
+ 'aftership-setting-admin',
138
+ 'aftership_setting_section_id'
139
+ );
140
+
141
+ add_settings_field(
142
+ 'use_track_button',
143
+ 'Display Track Button at Order History Page',
144
+ array($this, 'track_button_callback'),
145
+ 'aftership-setting-admin',
146
+ 'aftership_setting_section_id'
147
+ );
148
 
149
  add_settings_field(
150
  'track_message',
153
  'aftership-setting-admin',
154
  'aftership_setting_section_id'
155
  );
156
+ }
 
 
 
 
 
 
 
 
 
157
 
158
+ /**
159
+ * Sanitize each setting field as needed
160
+ *
161
+ * @param array $input Contains all settings fields as array keys
162
+ */
163
+ public function sanitize($input)
164
+ {
165
+ $new_input = array();
166
+
167
+ if (isset($input['couriers'])) {
168
+ $new_input['couriers'] = sanitize_text_field($input['couriers']);
169
+ }
170
 
171
+ if (isset($input['plugin'])) {
172
+ $new_input['plugin'] = sanitize_text_field($input['plugin']);
173
+ }
174
 
175
  if (isset($input['track_message_1'])) {
176
+ $postfix = '';
177
+ if (substr($input['track_message_1'], -1) == ' ') {
178
+ $postfix = ' ';
179
+ }
180
+ $new_input['track_message_1'] = sanitize_text_field($input['track_message_1']) . $postfix;
181
  }
182
 
183
  if (isset($input['track_message_2'])) {
184
+ $postfix = '';
185
+ if (substr($input['track_message_2'], -1) == ' ') {
186
+ $postfix = ' ';
187
+ }
188
+ $new_input['track_message_2'] = sanitize_text_field($input['track_message_2']) . $postfix;
189
  }
190
 
191
  if (isset($input['use_track_button'])) {
192
+ $new_input['use_track_button'] = true;
193
+ }
194
 
195
+ return $new_input;
196
+ }
197
 
198
+ /**
199
+ * Print the Section text
200
+ */
201
+ public function print_section_info()
202
+ {
203
+ //print 'Enter your settings below:';
204
+ }
205
 
206
+ public function couriers_callback()
207
+ {
208
 
209
+ $couriers = array();
210
+ if (isset($this->options['couriers'])) {
211
+ $couriers = explode(',', $this->options['couriers']);
212
+ }
213
 
214
  // print_r($couriers);
215
+ echo '<select data-placeholder="Please select couriers" id="couriers_select" class="chosen-select " multiple style="width:100%">';
216
+ echo '</select>';
217
  // echo '<br><a href="https://www.aftership.com/settings/courier" target="_blank">Update carrier list</a>';
218
+ echo '<input type="hidden" id="couriers" name="aftership_option_name[couriers]" value="' . implode(",", $couriers) . '"/>';
219
 
220
+ }
221
 
222
+ public function plugin_callback()
223
+ {
224
 
225
+ $options = "";
226
+ foreach ($this->plugins as $plugin) {
227
+ //print_r($plugin);
228
+ if (AfterShip_Dependencies::plugin_active_check($plugin['path'])) {
229
+ $option = '<option value="' . $plugin['value'] . '"';
230
 
231
+ if (isset($this->options['plugin']) && esc_attr($this->options['plugin']) == $plugin['value']) {
232
+ $option .= ' selected="selected"';
233
+ }
234
 
235
+ $option .= '>' . $plugin['label'] . '</option>';
236
+ $options .= $option;
237
+ }
238
+ }
239
 
240
+ printf(
241
+ '<select id="plugin" name="aftership_option_name[plugin]" class="aftership_dropdown">' . $options . '</select>'
242
+ );
243
+ }
244
 
245
+ public function track_message_callback()
246
+ {
247
  printf(
248
  '<input type="text" id="track_message_1" name="aftership_option_name[track_message_1]" value="%s" style="width:100%%">',
249
  isset($this->options['track_message_1']) ? $this->options['track_message_1'] : 'Your order was shipped via '
261
  );
262
  }
263
 
264
+ public function track_button_callback()
265
+ {
266
+ printf(
267
+ '<label><input type="checkbox" id="use_track_button" name="aftership_option_name[use_track_button]" %s>Use Track Button</label>',
268
+ (isset($this->options['use_track_button']) && $this->options['use_track_button'] === true) ? 'checked="checked"' : ''
269
+ );
270
+ }
271
  }
272
 
273
 
274
  if (is_admin())
275
+ $aftership_settings = new AfterShip_Settings();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.aftership.com/
4
  Tags: shipping, tracking, ups, usps, fedex, dhl, tnt, dpd, post, shipment, woocommerce, tracking number, aftership, package tracking, fulfilment, tracking link, carrier, courier, woo commerce, woocommerce shipment tracking, shipping details plugin, widget, shipstation, track, package
5
  Requires at least: 2.9
6
  Tested up to: 4.0
7
- Stable tag: 1.3.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -95,6 +95,9 @@ You'll find the FAQ on [AfterShip.com](https://aftership.uservoice.com/knowledge
95
 
96
  == Changelog ==
97
 
 
 
 
98
  = 1.3.3 =
99
  * Add the fields config
100
 
4
  Tags: shipping, tracking, ups, usps, fedex, dhl, tnt, dpd, post, shipment, woocommerce, tracking number, aftership, package tracking, fulfilment, tracking link, carrier, courier, woo commerce, woocommerce shipment tracking, shipping details plugin, widget, shipstation, track, package
5
  Requires at least: 2.9
6
  Tested up to: 4.0
7
+ Stable tag: 1.3.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
95
 
96
  == Changelog ==
97
 
98
+ = 1.3.4 =
99
+ * Fix the custom track message tailing space problem
100
+
101
  = 1.3.3 =
102
  * Add the fields config
103