WooCommerce PDF Invoices & Packing Slips - Version 2.0.5

Version Description

  • Feature: Remove temporary files (Status tab)
  • Fix: Page number replacement
  • Tweak: Fallback functions for MB String extension
  • Tweak: Improved wpo_wcpdf_check_privs usability for my account privileges
  • Legacy support: added wc_price alias for format_price method in document
Download this release

Release Info

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

Code changes from version 2.0.4 to 2.0.5

includes/class-wcpdf-main.php CHANGED
@@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  if ( !class_exists( '\\WPO\\WC\\PDF_Invoices\\Main' ) ) :
13
 
14
  class Main {
15
-
16
  function __construct() {
17
  add_action( 'wp_ajax_generate_wpo_wcpdf', array($this, 'generate_pdf_ajax' ) );
18
  add_filter( 'woocommerce_email_attachments', array( $this, 'attach_pdf_to_email' ), 99, 3 );
@@ -30,6 +30,16 @@ class Main {
30
  if ( file_exists( $template_path . '/template-functions.php' ) ) {
31
  require_once( $template_path . '/template-functions.php' );
32
  }
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
  /**
@@ -60,14 +70,14 @@ class Main {
60
 
61
  // do not process low stock notifications, user emails etc!
62
  if ( in_array( $email_id, array( 'no_stock', 'low_stock', 'backorder', 'customer_new_account', 'customer_reset_password' ) ) || get_post_type( $order_id ) != 'shop_order' ) {
63
- return $attachments;
64
  }
65
 
66
  $tmp_path = $this->get_tmp_path('attachments');
67
 
68
  // clear pdf files from temp folder (from http://stackoverflow.com/a/13468943/1446634)
69
  // array_map('unlink', ( glob( $tmp_path.'*.pdf' ) ? glob( $tmp_path.'*.pdf' ) : array() ) );
70
-
71
  // disable deprecation notices during email sending
72
  add_filter( 'wcpdf_disable_deprecation_notices', '__return_true' );
73
 
@@ -89,7 +99,7 @@ class Main {
89
  file_put_contents ( $pdf_path, $pdf_data );
90
  $attachments[] = $pdf_path;
91
 
92
- do_action( 'wpo_wcpdf_email_attachment', $pdf_path, $document_type );
93
  } catch (Exception $e) {
94
  error_log($e->getMessage());
95
  continue;
@@ -110,7 +120,7 @@ class Main {
110
  }
111
  $attach_documents = apply_filters('wpo_wcpdf_attach_documents', $attach_documents );
112
 
113
- $document_types = array();
114
  foreach ($attach_documents as $document_type => $attach_to_email_ids ) {
115
  // legacy settings: convert abbreviated email_ids
116
  foreach ($attach_to_email_ids as $key => $attach_to_email_id) {
@@ -133,7 +143,7 @@ class Main {
133
  */
134
  public function generate_pdf_ajax() {
135
  // Check the nonce
136
- if( empty( $_GET['action'] ) || ! is_user_logged_in() || !check_admin_referer( $_GET['action'] ) ) {
137
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
138
  }
139
 
@@ -157,25 +167,38 @@ class Main {
157
  // Process oldest first: reverse $order_ids array
158
  $order_ids = array_reverse($order_ids);
159
 
 
 
 
 
 
 
 
 
160
  // Check the user privileges
161
- if( apply_filters( 'wpo_wcpdf_check_privs', !current_user_can( 'manage_woocommerce_orders' ) && !current_user_can( 'edit_shop_orders' ) && !isset( $_GET['my-account'] ), $order_ids ) ) {
162
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
163
  }
164
 
165
  // User call from my-account page
166
  if ( !current_user_can('manage_options') && isset( $_GET['my-account'] ) ) {
167
  // Only for single orders!
168
  if ( count( $order_ids ) > 1 ) {
169
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
170
  }
171
 
172
  // Check if current user is owner of order IMPORTANT!!!
173
- $order = WCX::get_order ( $order_ids[0] );
174
- if ( WCX_Order::get_prop( $order, 'customer_id' ) != get_current_user_id() ) {
175
- wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
176
  }
177
  }
178
-
 
 
 
 
 
 
179
  // if we got here, we're safe to go!
180
  try {
181
  $document = wcpdf_get_document( $document_type, $order_ids, true );
@@ -210,11 +233,11 @@ class Main {
210
  */
211
  public function get_tmp_path ( $type = '' ) {
212
  $tmp_base = $this->get_tmp_base();
213
- // check if tmp folder exists => if not, initialize
214
  if ( !@is_dir( $tmp_base ) ) {
215
  $this->init_tmp( $tmp_base );
216
  }
217
-
218
  if ( empty( $type ) ) {
219
  return $tmp_base;
220
  }
@@ -249,11 +272,11 @@ class Main {
249
  public function get_tmp_base () {
250
  // wp_upload_dir() is used to set the base temp folder, under which a
251
  // 'wpo_wcpdf' folder and several subfolders are created
252
- //
253
  // wp_upload_dir() will:
254
  // * default to WP_CONTENT_DIR/uploads
255
  // * UNLESS the ‘UPLOADS’ constant is defined in wp-config (http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder)
256
- //
257
  // May also be overridden by the wpo_wcpdf_tmp_path filter
258
 
259
  $upload_dir = wp_upload_dir();
@@ -341,12 +364,92 @@ class Main {
341
  // check order total & setting
342
  $order_total = $order->get_total();
343
  if ( $order_total == 0 && isset( $document_settings['disable_free'] ) ) {
344
- return false;
345
  }
346
 
347
  return $attach;
348
  }
349
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  /**
351
  * Enable PHP error output
352
  */
@@ -359,4 +462,4 @@ class Main {
359
 
360
  endif; // class_exists
361
 
362
- return new Main();
12
  if ( !class_exists( '\\WPO\\WC\\PDF_Invoices\\Main' ) ) :
13
 
14
  class Main {
15
+
16
  function __construct() {
17
  add_action( 'wp_ajax_generate_wpo_wcpdf', array($this, 'generate_pdf_ajax' ) );
18
  add_filter( 'woocommerce_email_attachments', array( $this, 'attach_pdf_to_email' ), 99, 3 );
30
  if ( file_exists( $template_path . '/template-functions.php' ) ) {
31
  require_once( $template_path . '/template-functions.php' );
32
  }
33
+
34
+ // page numbers & currency filters
35
+ add_action( 'wpo_wcpdf_get_html', array($this, 'format_page_number_placeholders' ), 10, 2 );
36
+ add_action( 'wpo_wcpdf_after_dompdf_render', array($this, 'page_number_replacements' ), 9, 2 );
37
+ if ( isset( WPO_WCPDF()->settings->general_settings['currency_font'] ) ) {
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
  /**
70
 
71
  // do not process low stock notifications, user emails etc!
72
  if ( in_array( $email_id, array( 'no_stock', 'low_stock', 'backorder', 'customer_new_account', 'customer_reset_password' ) ) || get_post_type( $order_id ) != 'shop_order' ) {
73
+ return $attachments;
74
  }
75
 
76
  $tmp_path = $this->get_tmp_path('attachments');
77
 
78
  // clear pdf files from temp folder (from http://stackoverflow.com/a/13468943/1446634)
79
  // array_map('unlink', ( glob( $tmp_path.'*.pdf' ) ? glob( $tmp_path.'*.pdf' ) : array() ) );
80
+
81
  // disable deprecation notices during email sending
82
  add_filter( 'wcpdf_disable_deprecation_notices', '__return_true' );
83
 
99
  file_put_contents ( $pdf_path, $pdf_data );
100
  $attachments[] = $pdf_path;
101
 
102
+ do_action( 'wpo_wcpdf_email_attachment', $pdf_path, $document_type );
103
  } catch (Exception $e) {
104
  error_log($e->getMessage());
105
  continue;
120
  }
121
  $attach_documents = apply_filters('wpo_wcpdf_attach_documents', $attach_documents );
122
 
123
+ $document_types = array();
124
  foreach ($attach_documents as $document_type => $attach_to_email_ids ) {
125
  // legacy settings: convert abbreviated email_ids
126
  foreach ($attach_to_email_ids as $key => $attach_to_email_id) {
143
  */
144
  public function generate_pdf_ajax() {
145
  // Check the nonce
146
+ if( empty( $_GET['action'] ) || !check_admin_referer( $_GET['action'] ) ) {
147
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
148
  }
149
 
167
  // Process oldest first: reverse $order_ids array
168
  $order_ids = array_reverse($order_ids);
169
 
170
+ // set default is allowed
171
+ $allowed = true;
172
+
173
+ // check if user is logged in
174
+ if ( ! is_user_logged_in() ) {
175
+ $allowed = false;
176
+ }
177
+
178
  // Check the user privileges
179
+ if( !( current_user_can( 'manage_woocommerce_orders' ) || current_user_can( 'edit_shop_orders' ) ) && !isset( $_GET['my-account'] ) ) {
180
+ $allowed = false;
181
  }
182
 
183
  // User call from my-account page
184
  if ( !current_user_can('manage_options') && isset( $_GET['my-account'] ) ) {
185
  // Only for single orders!
186
  if ( count( $order_ids ) > 1 ) {
187
+ $allowed = false;
188
  }
189
 
190
  // Check if current user is owner of order IMPORTANT!!!
191
+ if ( ! current_user_can( 'view_order', $order_ids[0] ) ) {
192
+ $allowed = false;
 
193
  }
194
  }
195
+
196
+ $allowed = apply_filters( 'wpo_wcpdf_check_privs', $allowed, $order_ids );
197
+
198
+ if ( ! $allowed ) {
199
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'woocommerce-pdf-invoices-packing-slips' ) );
200
+ }
201
+
202
  // if we got here, we're safe to go!
203
  try {
204
  $document = wcpdf_get_document( $document_type, $order_ids, true );
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 );
239
  }
240
+
241
  if ( empty( $type ) ) {
242
  return $tmp_base;
243
  }
272
  public function get_tmp_base () {
273
  // wp_upload_dir() is used to set the base temp folder, under which a
274
  // 'wpo_wcpdf' folder and several subfolders are created
275
+ //
276
  // wp_upload_dir() will:
277
  // * default to WP_CONTENT_DIR/uploads
278
  // * UNLESS the ‘UPLOADS’ constant is defined in wp-config (http://codex.wordpress.org/Editing_wp-config.php#Moving_uploads_folder)
279
+ //
280
  // May also be overridden by the wpo_wcpdf_tmp_path filter
281
 
282
  $upload_dir = wp_upload_dir();
364
  // check order total & setting
365
  $order_total = $order->get_total();
366
  if ( $order_total == 0 && isset( $document_settings['disable_free'] ) ) {
367
+ return false;
368
  }
369
 
370
  return $attach;
371
  }
372
+
373
+ /**
374
+ * Adds spans around placeholders to be able to make replacement (page count) and css (page number)
375
+ */
376
+ public function format_page_number_placeholders ( $html, $document ) {
377
+ $html = str_replace('{{PAGE_COUNT}}', '<span class="pagecount">{{PAGE_COUNT}}</span>', $html);
378
+ $html = str_replace('{{PAGE_NUM}}', '<span class="pagenum"></span>', $html );
379
+ return $html;
380
+ }
381
+
382
+ /**
383
+ * Replace {{PAGE_COUNT}} placeholder with total page count
384
+ */
385
+ public function page_number_replacements ( $dompdf, $html ) {
386
+ $placeholder = '{{PAGE_COUNT}}';
387
+ // create placeholder version with ASCII 0 spaces (dompdf 0.8)
388
+ $placeholder_0 = '';
389
+ $placeholder_chars = str_split($placeholder);
390
+ foreach ($placeholder_chars as $placeholder_char) {
391
+ $placeholder_0 .= chr(0).$placeholder_char;
392
+ }
393
+
394
+ // check if placeholder is used
395
+ if (strpos($html, $placeholder) !== false ) {
396
+ foreach ($dompdf->get_canvas()->get_cpdf()->objects as &$object) {
397
+ if (array_key_exists("c", $object) && strpos($object["c"], $placeholder) !== false ) {
398
+ $object["c"] = str_replace( array($placeholder,$placeholder_0) , $dompdf->get_canvas()->get_page_count() , $object["c"] );
399
+ } elseif (array_key_exists("c", $object) && strpos($object["c"], $placeholder_0) !== false ) {
400
+ $object["c"] = str_replace( array($placeholder,$placeholder_0) , chr(0).$dompdf->get_canvas()->get_page_count() , $object["c"] );
401
+ }
402
+ }
403
+ }
404
+
405
+ return $dompdf;
406
+ }
407
+
408
+ /**
409
+ * Use currency symbol font (when enabled in options)
410
+ */
411
+ public function use_currency_font ( $document_type, $document ) {
412
+ add_filter( 'woocommerce_currency_symbol', array( $this, 'wrap_currency_symbol' ), 10, 2);
413
+ add_action( 'wpo_wcpdf_custom_styles', array($this, 'currency_symbol_font_styles' ) );
414
+ }
415
+
416
+ public function wrap_currency_symbol( $currency_symbol, $currency ) {
417
+ $currency_symbol = sprintf( '<span class="wcpdf-currency-symbol">%s</span>', $currency_symbol );
418
+ return $currency_symbol;
419
+ }
420
+
421
+ public function currency_symbol_font_styles () {
422
+ ?>
423
+ .wcpdf-currency-symbol { font-family: 'Currencies'; }
424
+ <?php
425
+ }
426
+
427
+ /**
428
+ * Remove attachments older than 1 week (daily, hooked into wp_scheduled_delete )
429
+ */
430
+ public function attachments_cleanup() {
431
+ if ( !function_exists("glob") || !function_exists('filemtime')) {
432
+ // glob is disabled
433
+ return;
434
+ }
435
+
436
+ $delete_timestamp = time() - ( DAY_IN_SECONDS * 7 );
437
+
438
+ $tmp_path = WPO_WCPDF()->main->get_tmp_path('attachments');
439
+
440
+ if ( $files = glob( $tmp_path.'*.pdf' ) ) { // get all pdf files
441
+ foreach( $files as $file ) {
442
+ if( is_file( $file ) ) {
443
+ $file_timestamp = filemtime( $file );
444
+ if ( !empty( $file_timestamp ) && $file_timestamp < $delete_timestamp ) {
445
+ @unlink($file);
446
+ }
447
+ }
448
+ }
449
+ }
450
+
451
+ }
452
+
453
  /**
454
  * Enable PHP error output
455
  */
462
 
463
  endif; // class_exists
464
 
465
+ return new Main();
includes/class-wcpdf-settings-debug.php CHANGED
@@ -38,6 +38,45 @@ class Settings_Debug {
38
  }
39
  ?>
40
  </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  <?php
42
  include( WPO_WCPDF()->plugin_path() . '/includes/views/dompdf-status.php' );
43
  }
38
  }
39
  ?>
40
  </form>
41
+ <form method="post">
42
+ <input type="hidden" name="wpo_wcpdf_debug_tools_action" value="clear_tmp">
43
+ <input type="submit" name="submit" id="submit" class="button" value="<?php _e( 'Remove temporary files', 'woocommerce-pdf-invoices-packing-slips' ); ?>">
44
+ <?php
45
+ if (isset($_POST['wpo_wcpdf_debug_tools_action']) && $_POST['wpo_wcpdf_debug_tools_action'] == 'clear_tmp') {
46
+ $tmp_path = WPO_WCPDF()->main->get_tmp_path('attachments');
47
+
48
+ if ( !function_exists("glob") ) {
49
+ // glob is disabled
50
+ printf('<div class="notice notice-error"><p>%s<br><code>%s</code></p></div>', __( "Unable to read temporary folder contents!", 'woocommerce-pdf-invoices-packing-slips' ), $tmp_path);
51
+ } else {
52
+ $success = 0;
53
+ $error = 0;
54
+ if ( $files = glob($tmp_path.'*.pdf') ) { // get all pdf files
55
+ foreach($files as $file) {
56
+ if(is_file($file)) {
57
+ // delete file
58
+ if ( unlink($file) === true ) {
59
+ $success++;
60
+ } else {
61
+ $error++;
62
+ }
63
+ }
64
+ }
65
+
66
+ if ($error > 0) {
67
+ $message = sprintf( __( 'Unable to delete %d files! (deleted %d)', 'woocommerce-pdf-invoices-packing-slips' ), $error, $success);
68
+ printf('<div class="notice notice-error"><p>%s</p></div>', $message);
69
+ } else {
70
+ $message = sprintf( __( 'Successfully deleted %d files!', 'woocommerce-pdf-invoices-packing-slips' ), $success );
71
+ printf('<div class="notice notice-success"><p>%s</p></div>', $message);
72
+ }
73
+ } else {
74
+ printf('<div class="notice notice-success"><p>%s</p></div>', __( 'Nothing to delete!', 'woocommerce-pdf-invoices-packing-slips' ) );
75
+ }
76
+ }
77
+ }
78
+ ?>
79
+ </form>
80
  <?php
81
  include( WPO_WCPDF()->plugin_path() . '/includes/views/dompdf-status.php' );
82
  }
includes/compatibility/mb-string-compatibility.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * mb_string compatibility - something's better than nothing!
4
+ * Taken from dompdf 0.6
5
+ */
6
+ if (!extension_loaded('mbstring')) {
7
+ if ( ! defined( 'MB_OVERLOAD_MAIL' ) ) define('MB_OVERLOAD_MAIL', 1);
8
+ if ( ! defined( 'MB_OVERLOAD_STRING' ) ) define('MB_OVERLOAD_STRING', 2);
9
+ if ( ! defined( 'MB_OVERLOAD_REGEX' ) ) define('MB_OVERLOAD_REGEX', 4);
10
+ if ( ! defined( 'MB_CASE_UPPER' ) ) define('MB_CASE_UPPER', 0);
11
+ if ( ! defined( 'MB_CASE_LOWER' ) ) define('MB_CASE_LOWER', 1);
12
+ if ( ! defined( 'MB_CASE_TITLE' ) ) define('MB_CASE_TITLE', 2);
13
+
14
+ if (!function_exists('mb_convert_encoding')) {
15
+ function mb_convert_encoding($data, $to_encoding, $from_encoding = 'UTF-8') {
16
+ if (str_replace('-', '', strtolower($to_encoding)) === 'utf8') {
17
+ return utf8_encode($data);
18
+ }
19
+
20
+ return utf8_decode($data);
21
+ }
22
+ }
23
+
24
+ if (!function_exists('mb_detect_encoding')) {
25
+ function mb_detect_encoding($data, $encoding_list = array('iso-8859-1'), $strict = false) {
26
+ return 'iso-8859-1';
27
+ }
28
+ }
29
+
30
+ if (!function_exists('mb_detect_order')) {
31
+ function mb_detect_order($encoding_list = array('iso-8859-1')) {
32
+ return 'iso-8859-1';
33
+ }
34
+ }
35
+
36
+ if (!function_exists('mb_internal_encoding')) {
37
+ function mb_internal_encoding($encoding = null) {
38
+ if (isset($encoding)) {
39
+ return true;
40
+ }
41
+
42
+ return 'iso-8859-1';
43
+ }
44
+ }
45
+ if (!function_exists('mb_strlen')) {
46
+ function mb_strlen($str, $encoding = 'iso-8859-1') {
47
+ switch (str_replace('-', '', strtolower($encoding))) {
48
+ case "utf8": return strlen(utf8_encode($str));
49
+ case "8bit": return strlen($str);
50
+ default: return strlen(utf8_decode($str));
51
+ }
52
+ }
53
+ }
54
+
55
+ if (!function_exists('mb_strpos')) {
56
+ function mb_strpos($haystack, $needle, $offset = 0) {
57
+ return strpos($haystack, $needle, $offset);
58
+ }
59
+ }
60
+
61
+ if (!function_exists('mb_strrpos')) {
62
+ function mb_strrpos($haystack, $needle, $offset = 0) {
63
+ return strrpos($haystack, $needle, $offset);
64
+ }
65
+ }
66
+
67
+ if (!function_exists('mb_strtolower')) {
68
+ function mb_strtolower( $str ) {
69
+ return strtolower($str);
70
+ }
71
+ }
72
+
73
+ if (!function_exists('mb_strtoupper')) {
74
+ function mb_strtoupper( $str ) {
75
+ return strtoupper($str);
76
+ }
77
+ }
78
+
79
+ if (!function_exists('mb_substr')) {
80
+ function mb_substr($string, $start, $length = null, $encoding = 'iso-8859-1') {
81
+ if ( is_null($length) ) {
82
+ return substr($string, $start);
83
+ }
84
+
85
+ return substr($string, $start, $length);
86
+ }
87
+ }
88
+
89
+ if (!function_exists('mb_substr_count')) {
90
+ function mb_substr_count($haystack, $needle, $encoding = 'iso-8859-1') {
91
+ return substr_count($haystack, $needle);
92
+ }
93
+ }
94
+
95
+ if (!function_exists('mb_encode_numericentity')) {
96
+ function mb_encode_numericentity($str, $convmap, $encoding) {
97
+ return htmlspecialchars($str);
98
+ }
99
+ }
100
+
101
+ if (!function_exists('mb_convert_case')) {
102
+ function mb_convert_case($str, $mode = MB_CASE_UPPER, $encoding = array()) {
103
+ switch($mode) {
104
+ case MB_CASE_UPPER: return mb_strtoupper($str);
105
+ case MB_CASE_LOWER: return mb_strtolower($str);
106
+ case MB_CASE_TITLE: return ucwords(mb_strtolower($str));
107
+ default: return $str;
108
+ }
109
+ }
110
+ }
111
+
112
+ if (!function_exists('mb_list_encodings')) {
113
+ function mb_list_encodings() {
114
+ return array(
115
+ "ISO-8859-1",
116
+ "UTF-8",
117
+ "8bit",
118
+ );
119
+ }
120
+ }
121
+ }
includes/documents/abstract-wcpdf-order-document-methods.php CHANGED
@@ -946,7 +946,10 @@ abstract class Order_Document_Methods extends Order_Document {
946
 
947
  return $formatted_price;
948
  }
949
-
 
 
 
950
  /**
951
  * Gets price - formatted for display.
952
  *
946
 
947
  return $formatted_price;
948
  }
949
+ public function wc_price( $price, $args = array() ) {
950
+ return $this->format_price( $price, $args );
951
+ }
952
+
953
  /**
954
  * Gets price - formatted for display.
955
  *
includes/documents/abstract-wcpdf-order-document.php CHANGED
@@ -117,13 +117,6 @@ abstract class Order_Document {
117
  $wpo_wcpdf->export->template_type = $this->type;
118
  }
119
  }
120
-
121
- // self filtering
122
- add_action( 'wpo_wcpdf_get_html', array($this, 'format_page_number_placeholders' ), 10, 2 );
123
- add_action( 'wpo_wcpdf_after_dompdf_render', array($this, 'page_number_replacements' ), 9, 2 );
124
- if ( isset( WPO_WCPDF()->settings->general_settings['currency_font'] ) ) {
125
- add_action( 'wpo_wcpdf_before_pdf', array($this, 'use_currency_font' ), 10, 2 );
126
- }
127
 
128
  }
129
 
@@ -613,52 +606,6 @@ abstract class Order_Document {
613
  return ob_get_clean();
614
  }
615
 
616
- /**
617
- * Adds spans around placeholders to be able to make replacement (page count) and css (page number)
618
- */
619
- public function format_page_number_placeholders ( $html, $document ) {
620
- $html = str_replace('{{PAGE_COUNT}}', '<span class="pagecount">{{PAGE_COUNT}}</span>', $html);
621
- $html = str_replace('{{PAGE_NUM}}', '<span class="pagenum"></span>', $html );
622
- return $html;
623
- }
624
-
625
- /**
626
- * Replace {{PAGE_COUNT}} placeholder with total page count
627
- */
628
- public function page_number_replacements ( $dompdf, $html ) {
629
- $placeholder = '{{PAGE_COUNT}}';
630
-
631
- // check if placeholder is used
632
- if (strpos($html, $placeholder) !== false ) {
633
- foreach ($dompdf->get_canvas()->get_cpdf()->objects as &$object) {
634
- if (array_key_exists("c", $object) && strpos($object["c"], $placeholder) !== false) {
635
- $object["c"] = str_replace( $placeholder , $dompdf->get_canvas()->get_page_count() , $object["c"] );
636
- }
637
- }
638
- }
639
-
640
- return $dompdf;
641
- }
642
-
643
- /**
644
- * Use currency symbol font (when enabled in options)
645
- */
646
- public function use_currency_font ( $document_type, $document ) {
647
- add_filter( 'woocommerce_currency_symbol', array( $this, 'wrap_currency_symbol' ), 10, 2);
648
- add_action( 'wpo_wcpdf_custom_styles', array($this, 'currency_symbol_font_styles' ) );
649
- }
650
-
651
- public function wrap_currency_symbol( $currency_symbol, $currency ) {
652
- $currency_symbol = sprintf( '<span class="wcpdf-currency-symbol">%s</span>', $currency_symbol );
653
- return $currency_symbol;
654
- }
655
-
656
- public function currency_symbol_font_styles () {
657
- ?>
658
- .wcpdf-currency-symbol { font-family: 'Currencies'; }
659
- <?php
660
- }
661
-
662
  /*
663
  |--------------------------------------------------------------------------
664
  | Settings helper functions
117
  $wpo_wcpdf->export->template_type = $this->type;
118
  }
119
  }
 
 
 
 
 
 
 
120
 
121
  }
122
 
606
  return ob_get_clean();
607
  }
608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
  /*
610
  |--------------------------------------------------------------------------
611
  | Settings helper functions
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-
4
  Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic
5
  Requires at least: 3.5
6
  Tested up to: 4.8
7
- Stable tag: 2.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -102,6 +102,13 @@ There's a setting on the Status tab of the settings page that allows you to togg
102
 
103
  **2.0 is a BIG update! Make a full site backup before upgrading**
104
 
 
 
 
 
 
 
 
105
  = 2.0.4 =
106
  * Fix: Apply filters for custom invoice number formatting in document too
107
  * Fix: Parent fallback for missing dates from refunds
@@ -584,5 +591,5 @@ There's a setting on the Status tab of the settings page that allows you to togg
584
 
585
  == Upgrade Notice ==
586
 
587
- = 2.0.4 =
588
  **2.0 is a BIG update! Make a full site backup before upgrading!**
4
  Tags: woocommerce, pdf, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic
5
  Requires at least: 3.5
6
  Tested up to: 4.8
7
+ Stable tag: 2.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
102
 
103
  **2.0 is a BIG update! Make a full site backup before upgrading**
104
 
105
+ = 2.0.5 =
106
+ * Feature: Remove temporary files (Status tab)
107
+ * Fix: Page number replacement
108
+ * Tweak: Fallback functions for MB String extension
109
+ * Tweak: Improved wpo_wcpdf_check_privs usability for my account privileges
110
+ * Legacy support: added wc_price alias for format_price method in document
111
+
112
  = 2.0.4 =
113
  * Fix: Apply filters for custom invoice number formatting in document too
114
  * Fix: Parent fallback for missing dates from refunds
591
 
592
  == Upgrade Notice ==
593
 
594
+ = 2.0.5 =
595
  **2.0 is a BIG update! Make a full site backup before upgrading!**
vendor/dompdf/dompdf/src/FrameDecorator/Table.php CHANGED
@@ -195,9 +195,11 @@ class Table extends AbstractFrameDecorator
195
  public static function find_parent_table(Frame $frame)
196
  {
197
 
198
- while ($frame = $frame->get_parent())
199
- if ($frame->is_table())
200
  break;
 
 
201
 
202
  return $frame;
203
  }
195
  public static function find_parent_table(Frame $frame)
196
  {
197
 
198
+ while ($frame = $frame->get_parent()) {
199
+ if ($frame->is_table()) {
200
  break;
201
+ }
202
+ }
203
 
204
  return $frame;
205
  }
woocommerce-pdf-invoices-packingslips.php CHANGED
@@ -3,7 +3,7 @@
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.0.4
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
@@ -19,7 +19,7 @@ if ( !class_exists( 'WPO_WCPDF' ) ) :
19
 
20
  class WPO_WCPDF {
21
 
22
- public $version = '2.0.4';
23
  public $plugin_basename;
24
  public $legacy_mode;
25
 
@@ -174,6 +174,9 @@ class WPO_WCPDF {
174
  // Backwards compatibility with self
175
  include_once( $this->plugin_path() . '/includes/legacy/class-wcpdf-legacy.php' );
176
  include_once( $this->plugin_path() . '/includes/legacy/class-wcpdf-legacy-deprecated-hooks.php' );
 
 
 
177
  }
178
 
179
 
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.0.5
7
  * Author: Ewout Fernhout
8
  * Author URI: http://www.wpovernight.com
9
  * License: GPLv2 or later
19
 
20
  class WPO_WCPDF {
21
 
22
+ public $version = '2.0.5';
23
  public $plugin_basename;
24
  public $legacy_mode;
25
 
174
  // Backwards compatibility with self
175
  include_once( $this->plugin_path() . '/includes/legacy/class-wcpdf-legacy.php' );
176
  include_once( $this->plugin_path() . '/includes/legacy/class-wcpdf-legacy-deprecated-hooks.php' );
177
+
178
+ // PHP MB String fallback functions
179
+ include_once( $this->plugin_path() . '/includes/compatibility/mb-string-compatibility.php' );
180
  }
181
 
182