WooCommerce PDF Invoices & Packing Slips - Version 2.1.9

Version Description

  • Feature: Automatic cleanup of temporary attachments folder (settings in Status tab)
  • Fix: prevent infinite loop on sites without uploads folder
  • Fix: tag replacements for externally hosted images (CDN)
Download this release

Release Info

Developer pomegranate
Plugin Icon 128x128 WooCommerce PDF Invoices & Packing Slips
Version 2.1.9
Comparing to
See all releases

Code changes from version 2.1.8 to 2.1.9

assets/css/settings-styles.css CHANGED
@@ -54,6 +54,10 @@ img.wpo-helper {
54
  position: relative;
55
  }
56
 
 
 
 
 
57
  .extensions .expanded:before {
58
  border-color: #111 transparent transparent transparent;
59
  left: -1.17em;
@@ -70,6 +74,7 @@ img.wpo-helper {
70
  .extensions table td {
71
  vertical-align: top;
72
  }
 
73
  .dropbox-logo {
74
  margin-bottom: -10px;
75
  margin-right: 10px;
@@ -140,4 +145,4 @@ table.wcpdf_documents_settings_list td.title {
140
  .edit-next-number:hover {
141
  opacity:1;
142
  cursor:pointer;
143
- }
54
  position: relative;
55
  }
56
 
57
+ .extensions li:not(.expanded) {
58
+ cursor:pointer;
59
+ }
60
+
61
  .extensions .expanded:before {
62
  border-color: #111 transparent transparent transparent;
63
  left: -1.17em;
74
  .extensions table td {
75
  vertical-align: top;
76
  }
77
+
78
  .dropbox-logo {
79
  margin-bottom: -10px;
80
  margin-right: 10px;
145
  .edit-next-number:hover {
146
  opacity:1;
147
  cursor:pointer;
148
+ }
includes/class-wcpdf-install.php CHANGED
@@ -76,7 +76,7 @@ class Install {
76
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
77
 
78
  // check if tmp folder exists => if not, initialize
79
- if ( !@is_dir( $tmp_base ) ) {
80
  WPO_WCPDF()->main->init_tmp( $tmp_base );
81
  }
82
 
@@ -162,11 +162,14 @@ class Install {
162
  // 'display_email' => '',
163
  // 'display_phone' => '',
164
  ),
165
- // 'wpo_wcpdf_settings_debug' => array(
166
- // 'legacy_mode' => '',
167
- // 'enable_debug' => '',
168
- // 'html_output' => '',
169
- // ),
 
 
 
170
  );
171
  foreach ($settings_defaults as $option => $defaults) {
172
  update_option( $option, $defaults );
@@ -188,7 +191,7 @@ class Install {
188
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
189
 
190
  // check if tmp folder exists => if not, initialize
191
- if ( !@is_dir( $tmp_base ) ) {
192
  WPO_WCPDF()->main->init_tmp( $tmp_base );
193
  } else {
194
  $font_path = WPO_WCPDF()->main->get_tmp_path( 'fonts' );
@@ -331,6 +334,14 @@ class Install {
331
  // delete_option( 'wpo_wcpdf_next_invoice_number' ); // clean up after ourselves
332
  }
333
 
 
 
 
 
 
 
 
 
334
  }
335
 
336
  /**
@@ -343,6 +354,11 @@ class Install {
343
  // make sure fonts match with version: copy from plugin folder
344
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
345
 
 
 
 
 
 
346
  // check if tmp folder exists => if not, initialize
347
  if ( !@is_dir( $tmp_base ) ) {
348
  WPO_WCPDF()->main->init_tmp( $tmp_base );
76
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
77
 
78
  // check if tmp folder exists => if not, initialize
79
+ if ( $tmp_base !== false && !@is_dir( $tmp_base ) ) {
80
  WPO_WCPDF()->main->init_tmp( $tmp_base );
81
  }
82
 
162
  // 'display_email' => '',
163
  // 'display_phone' => '',
164
  ),
165
+ 'wpo_wcpdf_settings_debug' => array(
166
+ // 'legacy_mode' => '',
167
+ // 'enable_debug' => '',
168
+ // 'html_output' => '',
169
+ // 'html_output' => '',
170
+ 'enable_cleanup' => 1,
171
+ 'cleanup_days' => 7,
172
+ ),
173
  );
174
  foreach ($settings_defaults as $option => $defaults) {
175
  update_option( $option, $defaults );
191
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
192
 
193
  // check if tmp folder exists => if not, initialize
194
+ if ( $tmp_base !== false && !@is_dir( $tmp_base ) ) {
195
  WPO_WCPDF()->main->init_tmp( $tmp_base );
196
  } else {
197
  $font_path = WPO_WCPDF()->main->get_tmp_path( 'fonts' );
334
  // delete_option( 'wpo_wcpdf_next_invoice_number' ); // clean up after ourselves
335
  }
336
 
337
+ // 2.1.9: set cleanup defaults
338
+ if ( $installed_version == 'versionless' || version_compare( $installed_version, '2.1.9', '<' ) ) {
339
+ $debug_settings = get_option( 'wpo_wcpdf_settings_debug', array() );
340
+ $debug_settings['enable_cleanup'] = 1;
341
+ $debug_settings['cleanup_days'] = 7;
342
+ update_option( 'wpo_wcpdf_settings_debug', $debug_settings );
343
+ }
344
+
345
  }
346
 
347
  /**
354
  // make sure fonts match with version: copy from plugin folder
355
  $tmp_base = WPO_WCPDF()->main->get_tmp_base();
356
 
357
+ // don't continue if we don't have an upload dir
358
+ if ($tmp_base === false) {
359
+ return false;
360
+ }
361
+
362
  // check if tmp folder exists => if not, initialize
363
  if ( !@is_dir( $tmp_base ) ) {
364
  WPO_WCPDF()->main->init_tmp( $tmp_base );
includes/class-wcpdf-main.php CHANGED
@@ -38,8 +38,8 @@ class Main {
38
  add_action( 'wpo_wcpdf_before_pdf', array($this, 'use_currency_font' ), 10, 2 );
39
  }
40
 
41
- // scheduled attachments cleanup - disabled for now
42
- // add_action( 'wp_scheduled_delete', array( $this, 'attachments_cleanup') );
43
  }
44
 
45
  /**
@@ -233,6 +233,12 @@ class Main {
233
  */
234
  public function get_tmp_path ( $type = '' ) {
235
  $tmp_base = $this->get_tmp_base();
 
 
 
 
 
 
236
  // check if tmp folder exists => if not, initialize
237
  if ( !@is_dir( $tmp_base ) ) {
238
  $this->init_tmp( $tmp_base );
@@ -280,8 +286,18 @@ class Main {
280
  // May also be overridden by the wpo_wcpdf_tmp_path filter
281
 
282
  $upload_dir = wp_upload_dir();
283
- $upload_base = trailingslashit( $upload_dir['basedir'] );
284
- $tmp_base = trailingslashit( apply_filters( 'wpo_wcpdf_tmp_path', $upload_base . 'wpo_wcpdf/' ) );
 
 
 
 
 
 
 
 
 
 
285
  return $tmp_base;
286
  }
287
 
@@ -465,12 +481,19 @@ class Main {
465
  * Remove attachments older than 1 week (daily, hooked into wp_scheduled_delete )
466
  */
467
  public function attachments_cleanup() {
468
- if ( !function_exists("glob") || !function_exists('filemtime')) {
469
- // glob is disabled
470
  return;
471
  }
472
 
473
- $delete_timestamp = time() - ( DAY_IN_SECONDS * 7 );
 
 
 
 
 
 
 
474
 
475
  $tmp_path = $this->get_tmp_path('attachments');
476
 
@@ -484,7 +507,6 @@ class Main {
484
  }
485
  }
486
  }
487
-
488
  }
489
 
490
  /**
38
  add_action( 'wpo_wcpdf_before_pdf', array($this, 'use_currency_font' ), 10, 2 );
39
  }
40
 
41
+ // scheduled attachments cleanup (following settings on Status tab)
42
+ add_action( 'wp_scheduled_delete', array( $this, 'attachments_cleanup') );
43
  }
44
 
45
  /**
233
  */
234
  public function get_tmp_path ( $type = '' ) {
235
  $tmp_base = $this->get_tmp_base();
236
+
237
+ // don't continue if we don't have an upload dir
238
+ if ($tmp_base === false) {
239
+ return false;
240
+ }
241
+
242
  // check if tmp folder exists => if not, initialize
243
  if ( !@is_dir( $tmp_base ) ) {
244
  $this->init_tmp( $tmp_base );
286
  // May also be overridden by the wpo_wcpdf_tmp_path filter
287
 
288
  $upload_dir = wp_upload_dir();
289
+ if (!empty($upload_dir['error'])) {
290
+ $tmp_base = false;
291
+ } else {
292
+ $upload_base = trailingslashit( $upload_dir['basedir'] );
293
+ $tmp_base = $upload_base . 'wpo_wcpdf/';
294
+ }
295
+
296
+ $tmp_base = apply_filters( 'wpo_wcpdf_tmp_path', $tmp_base );
297
+ if ($tmp_base !== false) {
298
+ $tmp_base = trailingslashit( $tmp_base );
299
+ }
300
+
301
  return $tmp_base;
302
  }
303
 
481
  * Remove attachments older than 1 week (daily, hooked into wp_scheduled_delete )
482
  */
483
  public function attachments_cleanup() {
484
+ if ( !function_exists("glob") || !function_exists('filemtime') ) {
485
+ // glob is required
486
  return;
487
  }
488
 
489
+
490
+ if ( !isset( WPO_WCPDF()->settings->debug_settings['enable_cleanup'] ) ) {
491
+ return;
492
+ }
493
+
494
+
495
+ $cleanup_age_days = isset(WPO_WCPDF()->settings->debug_settings['cleanup_days']) ? floatval(WPO_WCPDF()->settings->debug_settings['cleanup_days']) : 7.0;
496
+ $delete_timestamp = time() - ( intval ( DAY_IN_SECONDS * $cleanup_age_days ) );
497
 
498
  $tmp_path = $this->get_tmp_path('attachments');
499
 
507
  }
508
  }
509
  }
 
510
  }
511
 
512
  /**
includes/class-wcpdf-settings-callbacks.php CHANGED
@@ -52,7 +52,7 @@ class Settings_Callbacks {
52
  extract( $this->normalize_settings_args( $args ) );
53
 
54
  // output checkbox
55
- printf( '<input type="checkbox" id="%1$s" name="%2$s" value="%3$s"%4$s />', $id, $setting_name, $value, checked( $value, $current, false ) );
56
 
57
  // output description.
58
  if ( isset( $description ) ) {
@@ -80,7 +80,7 @@ class Settings_Callbacks {
80
  $type = 'text';
81
  }
82
 
83
- printf( '<input type="%1$s" id="%2$s" name="%3$s" value="%4$s" size="%5$s" placeholder="%6$s"/>', $type, $id, $setting_name, esc_attr( $current ), $size, $placeholder );
84
 
85
  // output description.
86
  if ( isset( $description ) ) {
@@ -88,6 +88,53 @@ class Settings_Callbacks {
88
  }
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  // Single text option (not part of any settings array)
92
  public function singular_text_element( $args ) {
93
  $option_name = $args['option_name'];
52
  extract( $this->normalize_settings_args( $args ) );
53
 
54
  // output checkbox
55
+ printf( '<input type="checkbox" id="%1$s" name="%2$s" value="%3$s" %4$s %5$s/>', $id, $setting_name, $value, checked( $value, $current, false ), !empty($disabled) ? 'disabled="disabled"' : '' );
56
 
57
  // output description.
58
  if ( isset( $description ) ) {
80
  $type = 'text';
81
  }
82
 
83
+ printf( '<input type="%1$s" id="%2$s" name="%3$s" value="%4$s" size="%5$s" placeholder="%6$s" %7$s/>', $type, $id, $setting_name, esc_attr( $current ), $size, $placeholder, !empty($disabled) ? 'disabled="disabled"' : '' );
84
 
85
  // output description.
86
  if ( isset( $description ) ) {
88
  }
89
  }
90
 
91
+ /**
92
+ * Combined checkbox & text input callback.
93
+ *
94
+ * args:
95
+ * option_name - name of the main option
96
+ * id - key of the setting
97
+ * value - value if not 1 (optional)
98
+ * default - default setting (optional)
99
+ * description - description (optional)
100
+ *
101
+ * @return void.
102
+ */
103
+ public function checkbox_text_input( $args ) {
104
+ $args = $this->normalize_settings_args( $args );
105
+ extract( $args );
106
+ unset($args['description']); // already extracted, should only be used here
107
+
108
+ // get checkbox
109
+ ob_start();
110
+ $this->checkbox( $args );
111
+ $checkbox = ob_get_clean();
112
+
113
+ // get text input for insertion in wrapper
114
+ $input_args = array(
115
+ 'id' => $args['text_input_id'],
116
+ 'default' => isset( $args['text_input_default'] ) ? (string) $args['text_input_default'] : NULL,
117
+ 'size' => isset( $args['text_input_size'] ) ? $args['text_input_size'] : NULL,
118
+ ) + $args;
119
+ unset($input_args['current']);
120
+
121
+ ob_start();
122
+ $this->text_input( $input_args );
123
+ $text_input = ob_get_clean();
124
+
125
+ if (!empty($text_input_wrap)) {
126
+ printf( "{$checkbox} {$text_input_wrap}", $text_input);
127
+ } else {
128
+ echo "{$checkbox} {$text_input}";
129
+ }
130
+
131
+ // output description.
132
+ if ( isset( $description ) ) {
133
+ printf( '<p class="description">%s</p>', $description );
134
+ }
135
+ }
136
+
137
+
138
  // Single text option (not part of any settings array)
139
  public function singular_text_element( $args ) {
140
  $option_name = $args['option_name'];
includes/class-wcpdf-settings-debug.php CHANGED
@@ -158,6 +158,25 @@ class Settings_Debug {
158
  __( '<b>Caution!</b> This setting may reveal errors (from other plugins) in other places on your site too, therefor this is not recommended to leave it enabled on live sites.', 'woocommerce-pdf-invoices-packing-slips' ),
159
  )
160
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  array(
162
  'type' => 'setting',
163
  'id' => 'html_output',
158
  __( '<b>Caution!</b> This setting may reveal errors (from other plugins) in other places on your site too, therefor this is not recommended to leave it enabled on live sites.', 'woocommerce-pdf-invoices-packing-slips' ),
159
  )
160
  ),
161
+ array(
162
+ 'type' => 'setting',
163
+ 'id' => 'enable_cleanup',
164
+ 'title' => __( 'Enable automatic cleanup', 'woocommerce-pdf-invoices-packing-slips' ),
165
+ 'callback' => 'checkbox_text_input',
166
+ 'section' => 'debug_settings',
167
+ 'args' => array(
168
+ 'option_name' => $option_name,
169
+ 'id' => 'enable_cleanup',
170
+ 'disabled' => ( !function_exists("glob") || !function_exists('filemtime') ) ? 1 : NULL,
171
+ 'text_input_wrap' => __( "every %s days", 'woocommerce-pdf-invoices-packing-slips' ),
172
+ 'text_input_size' => 4,
173
+ 'text_input_id' => 'cleanup_days',
174
+ 'text_input_default'=> 7,
175
+ 'description' => ( function_exists("glob") && function_exists('filemtime') ) ?
176
+ __( "Automatically clean up PDF files stored in the temporary folder (used for email attachments)", 'woocommerce-pdf-invoices-packing-slips' ) :
177
+ __( '<b>Disabled:</b> The PHP functions glob and filemtime are required for automatic cleanup but not enabled on your server.', 'woocommerce-pdf-invoices-packing-slips' ),
178
+ )
179
+ ),
180
  array(
181
  'type' => 'setting',
182
  'id' => 'html_output',
includes/documents/abstract-wcpdf-order-document-methods.php CHANGED
@@ -728,8 +728,8 @@ abstract class Order_Document_Methods extends Order_Document {
728
  if ( substr( $thumbnail_url, 0, 2 ) === "//" ) {
729
  $prefix = is_ssl() ? 'https://' : 'http://';
730
  $https_thumbnail_url = $prefix . ltrim( $thumbnail_url, '/' );
 
731
  }
732
- $thumbnail_img_tag_url = str_replace($thumbnail_url, $https_thumbnail_url, $thumbnail_img_tag_url);
733
  $thumbnail = $thumbnail_img_tag_url;
734
  } else {
735
  // load img with http url when filtered
728
  if ( substr( $thumbnail_url, 0, 2 ) === "//" ) {
729
  $prefix = is_ssl() ? 'https://' : 'http://';
730
  $https_thumbnail_url = $prefix . ltrim( $thumbnail_url, '/' );
731
+ $thumbnail_img_tag_url = str_replace($thumbnail_url, $https_thumbnail_url, $thumbnail_img_tag_url);
732
  }
 
733
  $thumbnail = $thumbnail_img_tag_url;
734
  } else {
735
  // load img with http url when filtered
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice,
5
  Requires at least: 3.5
6
  Tested up to: 4.9
7
  Requires PHP: 5.3
8
- Stable tag: 2.1.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -103,6 +103,11 @@ There's a setting on the Status tab of the settings page that allows you to togg
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
106
  = 2.1.8 =
107
  * Fix: Fatal error on PHP 5.X
108
 
@@ -253,5 +258,5 @@ There's a setting on the Status tab of the settings page that allows you to togg
253
 
254
  == Upgrade Notice ==
255
 
256
- = 2.1.8 =
257
  2.X is a BIG update! Make a full site backup before upgrading if you were using version 1.X!
5
  Requires at least: 3.5
6
  Tested up to: 4.9
7
  Requires PHP: 5.3
8
+ Stable tag: 2.1.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
103
 
104
  == Changelog ==
105
 
106
+ = 2.1.9 =
107
+ * Feature: Automatic cleanup of temporary attachments folder (settings in Status tab)
108
+ * Fix: prevent infinite loop on sites without uploads folder
109
+ * Fix: tag replacements for externally hosted images (CDN)
110
+
111
  = 2.1.8 =
112
  * Fix: Fatal error on PHP 5.X
113
 
258
 
259
  == Upgrade Notice ==
260
 
261
+ = 2.1.9 =
262
  2.X is a BIG update! Make a full site backup before upgrading if you were using version 1.X!
woocommerce-pdf-invoices-packingslips.php CHANGED
@@ -3,14 +3,14 @@
3
  * Plugin Name: WooCommerce PDF Invoices & Packing Slips
4
  * Plugin URI: http://www.wpovernight.com
5
  * Description: Create, print & email PDF invoices & packing slips for WooCommerce orders.
6
- * Version: 2.1.8
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
10
  * License URI: http://www.opensource.org/licenses/gpl-license.php
11
  * Text Domain: woocommerce-pdf-invoices-packing-slips
12
  * WC requires at least: 2.2.0
13
- * WC tested up to: 3.3.0
14
  */
15
 
16
  if ( ! defined( 'ABSPATH' ) ) {
@@ -21,7 +21,7 @@ if ( !class_exists( 'WPO_WCPDF' ) ) :
21
 
22
  class WPO_WCPDF {
23
 
24
- public $version = '2.1.8';
25
  public $plugin_basename;
26
  public $legacy_mode;
27
 
3
  * Plugin Name: WooCommerce PDF Invoices & Packing Slips
4
  * Plugin URI: http://www.wpovernight.com
5
  * Description: Create, print & email PDF invoices & packing slips for WooCommerce orders.
6
+ * Version: 2.1.9
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
10
  * License URI: http://www.opensource.org/licenses/gpl-license.php
11
  * Text Domain: woocommerce-pdf-invoices-packing-slips
12
  * WC requires at least: 2.2.0
13
+ * WC tested up to: 3.4.0
14
  */
15
 
16
  if ( ! defined( 'ABSPATH' ) ) {
21
 
22
  class WPO_WCPDF {
23
 
24
+ public $version = '2.1.9';
25
  public $plugin_basename;
26
  public $legacy_mode;
27