WooCommerce PDF Invoices - Version 3.0.9

Version Description

  • October 26, 2019 =

  • Improved: Custom logo upload setting by using the native media library.

Download this release

Release Info

Developer baaaaas
Plugin Icon 128x128 WooCommerce PDF Invoices
Version 3.0.9
Comparing to
See all releases

Code changes from version 3.0.8 to 3.0.9

bootstrap.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce PDF Invoices
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
5
  * Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
6
- * Version: 3.0.8
7
  * Author: Bas Elbers
8
  * Author URI: http://wcpdfinvoices.com
9
  * License: GPL-2.0+
@@ -11,12 +11,12 @@
11
  * Text Domain: woocommerce-pdf-invoices
12
  * Domain Path: /lang
13
  * WC requires at least: 3.0.0
14
- * WC tested up to: 3.7.0
15
  */
16
 
17
  defined( 'ABSPATH' ) || exit;
18
 
19
- define( 'WPI_VERSION', '3.0.8' );
20
 
21
  /**
22
  * Load WooCommerce PDF Invoices plugin.
@@ -41,8 +41,8 @@ function _bewpi_load_plugin() {
41
  /**
42
  * Main instance of BE_WooCommerce_PDF_Invoices.
43
  *
44
- * @since 2.9.1
45
  * @return BE_WooCommerce_PDF_Invoices
 
46
  */
47
  function WPI() {
48
  return BE_WooCommerce_PDF_Invoices::instance();
@@ -63,6 +63,14 @@ add_action( 'plugins_loaded', '_bewpi_load_plugin', 10 );
63
  * @since 2.5.0
64
  */
65
  function _bewpi_on_plugin_update() {
 
 
 
 
 
 
 
 
66
  if ( WPI_VERSION !== get_site_option( 'bewpi_version' ) ) {
67
  WPI()->setup_directories();
68
  WPI()->setup_options();
3
  * Plugin Name: WooCommerce PDF Invoices
4
  * Plugin URI: https://wordpress.org/plugins/woocommerce-pdf-invoices
5
  * Description: Automatically generate and attach customizable PDF Invoices to WooCommerce emails and connect with Dropbox, Google Drive, OneDrive or Egnyte.
6
+ * Version: 3.0.9
7
  * Author: Bas Elbers
8
  * Author URI: http://wcpdfinvoices.com
9
  * License: GPL-2.0+
11
  * Text Domain: woocommerce-pdf-invoices
12
  * Domain Path: /lang
13
  * WC requires at least: 3.0.0
14
+ * WC tested up to: 3.7.1
15
  */
16
 
17
  defined( 'ABSPATH' ) || exit;
18
 
19
+ define( 'WPI_VERSION', '3.0.9' );
20
 
21
  /**
22
  * Load WooCommerce PDF Invoices plugin.
41
  /**
42
  * Main instance of BE_WooCommerce_PDF_Invoices.
43
  *
 
44
  * @return BE_WooCommerce_PDF_Invoices
45
+ * @since 2.9.1
46
  */
47
  function WPI() {
48
  return BE_WooCommerce_PDF_Invoices::instance();
63
  * @since 2.5.0
64
  */
65
  function _bewpi_on_plugin_update() {
66
+ // As per 3.0.9 we need to change the company logo to the attachment id.
67
+ $company_logo_url = WPI()->get_option( 'template', 'company_logo' );
68
+ if ( version_compare( WPI_VERSION, '3.0.9' ) >= 0 && ! empty( $company_logo_url ) && filter_var( $company_logo_url, FILTER_VALIDATE_URL ) ) {
69
+ $template_settings = get_option( 'bewpi_template_settings' );
70
+ $template_settings['bewpi_company_logo'] = (string) attachment_url_to_postid( $company_logo_url );
71
+ update_option( 'bewpi_template_settings', $template_settings );
72
+ }
73
+
74
  if ( WPI_VERSION !== get_site_option( 'bewpi_version' ) ) {
75
  WPI()->setup_directories();
76
  WPI()->setup_options();
includes/abstracts/abstract-document.php CHANGED
@@ -135,14 +135,16 @@ if ( ! class_exists( 'BEWPI_Abstract_Document' ) ) {
135
  $mpdf_params['orientation']
136
  );
137
 
138
- // add company logo image as a variable.
139
- $wp_upload_dir = wp_upload_dir();
140
- $image_url = $this->template_options['bewpi_company_logo'];
141
- if ( ! empty( $image_url ) ) {
142
  // use absolute path due to probability of (local)host misconfiguration.
143
  // problems with shared hosting when one ip is configured to multiple users/environments.
144
- $image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url );
145
- $mpdf->company_logo = file_get_contents( $image_path );
 
 
146
  }
147
 
148
  // Show legacy paid watermark.
135
  $mpdf_params['orientation']
136
  );
137
 
138
+ // Add company logo image as a variable.
139
+ // As of 3.0.9 we've improved the media upload settings feature and so bewpi_company_logo contains the id of the attachment.
140
+ $attachment = WPI()->get_option( 'template', 'company_logo' );
141
+ if ( ! empty( $attachment ) ) {
142
  // use absolute path due to probability of (local)host misconfiguration.
143
  // problems with shared hosting when one ip is configured to multiple users/environments.
144
+ $attachment_path = get_attached_file( $attachment );
145
+ if ( false !== $attachment_path ) {
146
+ $mpdf->company_logo = file_get_contents( $attachment_path );
147
+ }
148
  }
149
 
150
  // Show legacy paid watermark.
includes/abstracts/abstract-invoice.php CHANGED
@@ -567,10 +567,7 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
567
 
568
  $total_rows[ 'fee_' . $id ] = array(
569
  'label' => $fee['name'] . ':',
570
- 'value' => wc_price( 'excl' === $tax_display ? $fee['line_total'] : (double) $fee['line_total'] + (double) $fee['line_tax'], array(
571
- 'currency' => WPI()->get_currency( $this->order ),
572
- )
573
- ),
574
  );
575
  }
576
  }
@@ -595,10 +592,7 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
595
  } else {
596
  $total_rows['tax'] = array(
597
  'label' => WC()->countries->tax_or_vat() . ':',
598
- 'value' => wc_price( $this->order->get_total_tax(), array(
599
- 'currency' => WPI()->get_currency( $this->order ),
600
- )
601
- ),
602
  );
603
  }
604
  }
@@ -638,179 +632,6 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
638
  return apply_filters( 'wpi_get_invoice_total_rows', $total_rows, $this );
639
  }
640
 
641
- /**
642
- * Backwards compatibility.
643
- *
644
- * @deprecated Use `generate()` instead.
645
- *
646
- * @param string $destination pdf generation mode.
647
- */
648
- public function save( $destination = 'F', $html_templates = array() ) {
649
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8', 'generate' );
650
- $this->generate( $destination );
651
- }
652
-
653
- /**
654
- * Display company logo or name
655
- *
656
- * @deprecated See minimal template.
657
- */
658
- public function get_company_logo_html() {
659
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8', 'WPI()->templater()->get_meta( \'_vat_number\' )' );
660
- $logo_url = $this->template_options['bewpi_company_logo'];
661
- if ( ! empty( $logo_url ) ) {
662
- // mPDF' stablest method to display an image is to use their "Image data as a Variable" (https://mpdf.github.io/what-else-can-i-do/images.html) option.
663
- $src = apply_filters( 'bewpi_company_logo_url', 'var:company_logo' );
664
- printf( '<img class="company-logo" src="%s"/>', esc_attr( $src ) );
665
- } else {
666
- // show company name if company logo isn't uploaded.
667
- $company_name = $this->template_options['bewpi_company_name'];
668
- printf( '<h1 class="company-logo">%s</h1>', esc_html( $company_name ) );
669
- }
670
- }
671
-
672
- /**
673
- * Get VAT number from WooCommerce EU VAT Number plugin.
674
- *
675
- * @deprecated See minimal template.
676
- */
677
- public function display_vat_number() {
678
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8', 'WPI()->templater()->get_meta( \'_vat_number\' )' );
679
- // WC backwards compatibility.
680
- $order_id = BEWPI_WC_Order_Compatibility::get_id( $this->order );
681
-
682
- $vat_number = get_post_meta( $order_id, '_vat_number', true );
683
- if ( ! empty( $vat_number ) ) {
684
- echo '<span>' . sprintf( __( 'VAT Number: %s', 'woocommerce-pdf-invoices' ), $vat_number ) . '</span>';
685
- }
686
- }
687
-
688
- /**
689
- * Get PO Number from WooCommerce Purchase Order Gateway plugin.
690
- *
691
- * @deprecated See minimal template.
692
- */
693
- public function display_purchase_order_number() {
694
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8', 'WPI()->templater()->get_meta( \'_po_number\' )' );
695
- // WC backwards compatibility.
696
- $payment_method = BEWPI_WC_Order_Compatibility::get_prop( $this->order, 'payment_method' );
697
- if ( isset( $payment_method ) && 'woocommerce_gateway_purchase_order' === $payment_method ) {
698
- // WC backwards compatibility.
699
- $order_id = BEWPI_WC_Order_Compatibility::get_id( $this->order );
700
- $po_number = get_post_meta( $order_id, '_po_number', true );
701
- if ( ! empty( $po_number ) ) {
702
- echo '<span>' . sprintf( __( 'Purchase Order Number: %s', 'woocommerce-gateway-purchase-order' ), $po_number ) . '</span>';
703
- }
704
- }
705
- }
706
-
707
- /**
708
- * Outline columns for within pdf template files.
709
- *
710
- * @param int $taxes_count number of tax classes.
711
- *
712
- * @deprecated See minimal template.
713
- */
714
- public function outlining_columns_html( $taxes_count = 0 ) {
715
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
716
- $columns_count = $this->get_columns_count( $taxes_count );
717
- $colspan = $this->get_colspan( $columns_count );
718
- ?>
719
- <style>
720
- <?php
721
- // Create css for outlining the product cells.
722
- $righter_product_row_tds_css = "";
723
- for ( $td = $colspan['left'] + 1; $td <= $columns_count; $td++ ) {
724
- if ( $td !== $columns_count ) {
725
- $righter_product_row_tds_css .= "tr.product-row td:nth-child(" . $td . "),";
726
- } else {
727
- $righter_product_row_tds_css .= "tr.product-row td:nth-child(" . $td . ")";
728
- $righter_product_row_tds_css .= "{ width: " . ( 50 / $colspan['right'] ) . "%; }";
729
- }
730
- }
731
- echo $righter_product_row_tds_css;
732
- ?>
733
- tr.product-row td:nth-child(1) {
734
- width: <?php echo $this->desc_cell_width; ?>;
735
- }
736
- </style>
737
- <?php
738
- }
739
-
740
- /**
741
- * Number of columns.
742
- *
743
- * @param int $tax_count number of taxes.
744
- *
745
- * @deprecated See minimal template.
746
- * @return int
747
- */
748
- public function get_columns_count( $tax_count = 0 ) {
749
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
750
- $columns_count = 4;
751
-
752
- if ( $this->template_options['bewpi_show_sku'] ) {
753
- $columns_count ++;
754
- }
755
-
756
- if ( $this->template_options['bewpi_show_tax'] && wc_tax_enabled() && empty( $legacy_order ) ) {
757
- $columns_count += $tax_count;
758
- }
759
-
760
- return $columns_count;
761
- }
762
-
763
- /**
764
- * Calculates colspan for table footer cells
765
- *
766
- * @deprecated See minimal template solution.
767
- *
768
- * @param int $columns_count number of columns.
769
- *
770
- * @return array
771
- */
772
- public function get_colspan( $columns_count = 0 ) {
773
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
774
- $colspan = array();
775
- $number_of_left_half_columns = 3;
776
- $this->desc_cell_width = '30%';
777
-
778
- // The product table will be split into 2 where on the right 5 columns are the max.
779
- if ( $columns_count <= 4 ) :
780
- $number_of_left_half_columns = 1;
781
- $this->desc_cell_width = '48%';
782
- elseif ( $columns_count <= 6 ) :
783
- $number_of_left_half_columns = 2;
784
- $this->desc_cell_width = '35.50%';
785
- endif;
786
-
787
- $colspan['left'] = $number_of_left_half_columns;
788
- $colspan['right'] = $columns_count - $number_of_left_half_columns;
789
- $colspan['right_left'] = round( ( $colspan['right'] / 2 ), 0, PHP_ROUND_HALF_DOWN );
790
- $colspan['right_right'] = round( ( $colspan['right'] / 2 ), 0, PHP_ROUND_HALF_UP );
791
-
792
- return $colspan;
793
- }
794
-
795
- /**
796
- * Check if order has only virtual products.
797
- *
798
- * @return bool
799
- *
800
- * @deprecated moved to WPI()->templater().
801
- * @since 2.5.3
802
- */
803
- public function has_only_virtual_products() {
804
- foreach ( $this->order->get_items( 'line_item' ) as $item ) {
805
- $product = $this->order->get_product_from_item( $item );
806
- if ( ! $product || ! $product->is_virtual() ) {
807
- return false;
808
- }
809
- }
810
-
811
- return true;
812
- }
813
-
814
  /**
815
  * Check if invoice needs zero rated vat.
816
  *
@@ -835,78 +656,6 @@ abstract class BEWPI_Abstract_Invoice extends BEWPI_Abstract_Document {
835
  return new DateTime( $this->date );
836
  }
837
 
838
- /**
839
- * Checks if invoice needs to have a zero rated VAT.
840
- *
841
- * @deprecated See minimal template.
842
- * @return bool
843
- */
844
- public function display_zero_rated_vat() {
845
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
846
- // WC backwards compatibility.
847
- $order_id = BEWPI_WC_Order_Compatibility::get_id( $this->order );
848
-
849
- $is_vat_valid = get_post_meta( $order_id, '_vat_number_is_valid', true );
850
- if ( ! $is_vat_valid ) {
851
- return false;
852
- }
853
-
854
- $is_tax_removed = count( $this->order->get_tax_totals() ) === 0;
855
- if ( ! $is_tax_removed ) {
856
- return false;
857
- }
858
-
859
- return true;
860
- }
861
-
862
- /**
863
- * @param $str
864
- *
865
- * @deprecated moved to BEWPI_Template Class.
866
- *
867
- * @return mixed
868
- */
869
- private function replace_placeholders( $str ) {
870
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
871
- // WC backwards compatibility.
872
- $order_id = BEWPI_WC_Order_Compatibility::get_id( $this->order );
873
-
874
- $placeholders = apply_filters( 'bewpi_placeholders', array(
875
- '[payment_method]' => BEWPI_WC_Order_Compatibility::get_prop( $this->order, 'payment_method_title' ),
876
- '[shipping_method]' => $this->order->get_shipping_method(),
877
- ), $order_id );
878
-
879
- foreach ( $placeholders as $placeholder => $value ) {
880
- $str = str_replace( $placeholder, $value, $str );
881
- }
882
-
883
- return $str;
884
- }
885
-
886
- /**
887
- * @deprecated instead use 'WPI()->templater()->get_option()'.
888
- */
889
- public function left_footer_column_html() {
890
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8', 'WPI()->templater()->get_option( \'bewpi_left_footer_column\' )' );
891
- $left_footer_column_text = $this->template_options['bewpi_left_footer_column'];
892
- if ( ! empty( $left_footer_column_text ) ) {
893
- echo '<p>' . nl2br( $this->replace_placeholders( $left_footer_column_text ) ) . '</p>';
894
- }
895
- }
896
-
897
- /**
898
- * @deprecated instead use 'WPI()->templater()->get_option()'.
899
- */
900
- public function right_footer_column_html() {
901
- _deprecated_function( __FUNCTION__, 'WooCommerce PDF Invoices v2.8' );
902
- $right_footer_column_text = $this->template_options['bewpi_right_footer_column'];
903
- if ( ! empty( $right_footer_column_text ) ) {
904
- echo '<p>' . nl2br( $this->replace_placeholders( $right_footer_column_text ) ) . '</p>';
905
- } else {
906
- echo '<p>' . sprintf( __( '%s of %s', 'woocommerce-pdf-invoices' ), '{PAGENO}', '{nbpg}' ) . '</p>';
907
- }
908
- }
909
-
910
  /**
911
  * Set order item totals colspan.
912
  *
567
 
568
  $total_rows[ 'fee_' . $id ] = array(
569
  'label' => $fee['name'] . ':',
570
+ 'value' => wc_price( 'excl' === $tax_display ? $fee['line_total'] : (float) $fee['line_total'] + (float) $fee['line_tax'], array( 'currency' => WPI()->get_currency( $this->order ) ) ),
 
 
 
571
  );
572
  }
573
  }
592
  } else {
593
  $total_rows['tax'] = array(
594
  'label' => WC()->countries->tax_or_vat() . ':',
595
+ 'value' => wc_price( $this->order->get_total_tax(), array( 'currency' => WPI()->get_currency( $this->order ) ) ),
 
 
 
596
  );
597
  }
598
  }
632
  return apply_filters( 'wpi_get_invoice_total_rows', $total_rows, $this );
633
  }
634
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
  /**
636
  * Check if invoice needs zero rated vat.
637
  *
656
  return new DateTime( $this->date );
657
  }
658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  /**
660
  * Set order item totals colspan.
661
  *
includes/abstracts/abstract-settings.php CHANGED
@@ -217,7 +217,7 @@ abstract class BEWPI_Abstract_Settings {
217
  </h2>
218
  <form method="post"
219
  action="options.php?tab=<?php echo self::$current_tab; ?>&key=<?php echo md5( WPI()->get_plugin_slug() ); ?>"
220
- enctype="multipart/form-data" <?php echo esc_html( $width ); ?>>
221
  <?php
222
  settings_fields( self::$setting->settings_key );
223
  do_settings_sections( self::$setting->settings_key );
@@ -357,7 +357,7 @@ abstract class BEWPI_Abstract_Settings {
357
  ?>
358
  <option
359
  value="<?php echo esc_attr( $key ); ?>" <?php selected( $options[ $args['name'] ], $key ); ?>><?php echo esc_html( $label ); ?></option>
360
- <?php
361
  endforeach;
362
  ?>
363
  </select>
@@ -434,7 +434,7 @@ abstract class BEWPI_Abstract_Settings {
434
  <input id="<?php echo $args['id']; ?>"
435
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
436
  type="<?php echo $args['type']; ?>"
437
- value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number( (int) date_i18n( 'Y', current_time( 'timestamp' ) ) ) + 1 ); ?>"
438
  <?php
439
  if ( isset( $args['attrs'] ) ) {
440
  foreach ( $args['attrs'] as $attr ) {
@@ -500,6 +500,70 @@ abstract class BEWPI_Abstract_Settings {
500
  <?php
501
  }
502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  /**
504
  * Gets all default settings values from the settings array.
505
  *
@@ -594,5 +658,6 @@ abstract class BEWPI_Abstract_Settings {
594
  *
595
  * @return mixed
596
  */
597
- protected function display_custom_settings() {}
 
598
  }
217
  </h2>
218
  <form method="post"
219
  action="options.php?tab=<?php echo self::$current_tab; ?>&key=<?php echo md5( WPI()->get_plugin_slug() ); ?>"
220
+ enctype="multipart/form-data" <?php echo $width; ?>>
221
  <?php
222
  settings_fields( self::$setting->settings_key );
223
  do_settings_sections( self::$setting->settings_key );
357
  ?>
358
  <option
359
  value="<?php echo esc_attr( $key ); ?>" <?php selected( $options[ $args['name'] ], $key ); ?>><?php echo esc_html( $label ); ?></option>
360
+ <?php
361
  endforeach;
362
  ?>
363
  </select>
434
  <input id="<?php echo $args['id']; ?>"
435
  name="<?php echo $args['page'] . '[' . $args['name'] . ']'; ?>"
436
  type="<?php echo $args['type']; ?>"
437
+ value="<?php echo esc_attr( ( false !== $next_invoice_number ) ? $next_invoice_number : BEWPI_Abstract_Invoice::get_max_invoice_number( (int) date_i18n( 'Y', current_time( 'timestamp' ) ) ) + 1 ); ?>"
438
  <?php
439
  if ( isset( $args['attrs'] ) ) {
440
  foreach ( $args['attrs'] as $attr ) {
500
  <?php
501
  }
502
 
503
+ /**
504
+ * Add additional file option callback.
505
+ *
506
+ * @param array $args Field arguments.
507
+ */
508
+ public function upload_callback( $args ) {
509
+ $options = get_option( $args['page'] );
510
+ $attachment_id = $options[ $args['name'] ];
511
+ $file_url = wp_get_attachment_url( $attachment_id );
512
+ ?>
513
+ <p class="form-field">
514
+ <input type="hidden" class="file_id" name="<?php echo esc_attr( $args['page'] . '[' . $args['name'] . ']' ); ?>" value="<?php echo esc_attr( $attachment_id ); ?>"/>
515
+ <input type="<?php echo esc_attr( $args['type'] ); ?>" class="file_url" placeholder="<?php echo esc_attr( $file_url ); ?>" value="<?php echo esc_attr( $file_url ); ?>"/>
516
+ <button class="button upload_image_button" data-uploader_button_text="<?php _e( 'Use file', 'woocommerce-pdf-invoices' ); ?>"><?php _e( 'Upload', 'woocommerce-pdf-invoices' ); ?></button>
517
+ </p>
518
+ <script type="text/javascript">
519
+ // Uploading files
520
+ var file_frame;
521
+ var file_target_input;
522
+ var file_id_input;
523
+
524
+ jQuery('.upload_image_button').live('click', function (event) {
525
+
526
+ event.preventDefault();
527
+
528
+ file_target_input = jQuery(this).closest('.form-field').find('.file_url');
529
+ file_id_input = jQuery(this).closest('.form-field').find('.file_id');
530
+
531
+ // If the media frame already exists, reopen it.
532
+ if (file_frame) {
533
+ file_frame.open();
534
+ return;
535
+ }
536
+
537
+ // Create the media frame.
538
+ file_frame = wp.media.frames.file_frame = wp.media({
539
+ title: jQuery(this).data('uploader_title'),
540
+ button: {
541
+ text: jQuery(this).data('uploader_button_text')
542
+ },
543
+ multiple: false // Set to true to allow multiple files to be selected,
544
+ });
545
+
546
+ // When an image is selected, run a callback.
547
+ file_frame.on('select', function () {
548
+ // We set multiple to false so only get one image from the uploader
549
+ attachment = file_frame.state().get('selection').first().toJSON();
550
+
551
+ jQuery(file_target_input).val(attachment.url);
552
+ jQuery(file_id_input).val(attachment.id);
553
+ });
554
+
555
+ // Finally, open the modal
556
+ file_frame.open();
557
+ });
558
+
559
+ jQuery('.upload_image_button').closest('.form-field').find('.file_url').on('change', function (event) {
560
+ file_id_input = jQuery(this).closest('.form-field').find('.file_id');
561
+ jQuery(file_id_input).val('');
562
+ });
563
+ </script>
564
+ <?php
565
+ }
566
+
567
  /**
568
  * Gets all default settings values from the settings array.
569
  *
658
  *
659
  * @return mixed
660
  */
661
+ protected function display_custom_settings() {
662
+ }
663
  }
includes/admin/settings/class-template.php CHANGED
@@ -91,8 +91,6 @@ class BEWPI_Template_Settings extends BEWPI_Abstract_Settings {
91
  * @return array
92
  */
93
  private function get_fields() {
94
- $company_logo = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'thumbnail' );
95
-
96
  $settings = array(
97
  array(
98
  'id' => 'bewpi-template-name',
@@ -208,12 +206,12 @@ class BEWPI_Template_Settings extends BEWPI_Abstract_Settings {
208
  'id' => 'bewpi-company-logo',
209
  'name' => $this->prefix . 'company_logo',
210
  'title' => __( 'Company logo', 'woocommerce-pdf-invoices' ),
211
- 'callback' => array( $this, 'input_callback' ),
212
  'page' => $this->settings_key,
213
  'section' => 'header',
214
  'type' => 'text',
215
- 'desc' => sprintf( __( 'Use the <a href="%1$s">Media Library</a> to <a href="%2$s">upload</a> or choose a .jpg, .jpeg, .gif or .png file and copy and paste the <a href="%3$s" target="_blank">File URL</a>.', 'woocommerce-pdf-invoices' ), 'media-new.php', 'upload.php', 'https://codex.wordpress.org/Media_Library_Screen#Attachment_Details' ),
216
- 'default' => ( is_array( $company_logo ) ) ? $company_logo[0] : '',
217
  ),
218
  array(
219
  'id' => 'bewpi-company-name',
@@ -577,31 +575,10 @@ class BEWPI_Template_Settings extends BEWPI_Abstract_Settings {
577
  continue;
578
  }
579
 
580
- if ( 'bewpi_company_logo' === $key ) {
581
- continue;
582
- }
583
-
584
  // strip all html and php tags and properly handle quoted strings.
585
  $output[ $key ] = $this->strip_str( stripslashes( $input[ $key ] ) );
586
  }
587
 
588
- if ( isset( $input['bewpi_company_logo'] ) ) {
589
- if ( ! empty( $input['bewpi_company_logo'] ) ) {
590
- $image_url = $this->validate_image( $input['bewpi_company_logo'] );
591
- if ( $image_url ) {
592
- $output['bewpi_company_logo'] = $image_url;
593
- } else {
594
- add_settings_error(
595
- esc_attr( $this->settings_key ),
596
- 'file-not-found',
597
- __( 'Company logo not found. Upload the image to the Media Library and try again.', 'woocommerce-pdf-invoices' )
598
- );
599
- }
600
- } else {
601
- $output['bewpi_company_logo'] = '';
602
- }
603
- }
604
-
605
  if ( isset( $input['bewpi_reset_counter'] ) && $input['bewpi_reset_counter'] ) {
606
  set_transient( 'bewpi_next_invoice_number', intval( $input['bewpi_next_invoice_number'] ) );
607
  }
@@ -609,37 +586,6 @@ class BEWPI_Template_Settings extends BEWPI_Abstract_Settings {
609
  return apply_filters( 'bewpi_sanitized_' . $this->settings_key, $output, $input );
610
  }
611
 
612
- /**
613
- * Validate image against modified urls and check for extension.
614
- *
615
- * @param string $image_url source url of the image.
616
- *
617
- * @return bool|string false or image url.
618
- */
619
- public function validate_image( $image_url ) {
620
- $image_url = esc_url_raw( $image_url, array( 'http', 'https' ) );
621
- $query = array(
622
- 'post_type' => 'attachment',
623
- 'fields' => 'ids',
624
- 'meta_query' => array(
625
- array(
626
- 'key' => '_wp_attached_file',
627
- 'value' => basename( $image_url ),
628
- 'compare' => 'LIKE',
629
- ),
630
- )
631
- );
632
-
633
- $ids = get_posts( $query );
634
- if ( count( $ids ) === 0 ) {
635
- WPI()->logger()->error( sprintf( 'Image %s not found in post table.', basename( $image_url ) ) );
636
-
637
- return false;
638
- }
639
-
640
- return wp_get_attachment_image_url( $ids[0], 'full' );
641
- }
642
-
643
  /**
644
  * Sets template to default template when custom template has been deleted.
645
  */
91
  * @return array
92
  */
93
  private function get_fields() {
 
 
94
  $settings = array(
95
  array(
96
  'id' => 'bewpi-template-name',
206
  'id' => 'bewpi-company-logo',
207
  'name' => $this->prefix . 'company_logo',
208
  'title' => __( 'Company logo', 'woocommerce-pdf-invoices' ),
209
+ 'callback' => array( $this, 'upload_callback' ),
210
  'page' => $this->settings_key,
211
  'section' => 'header',
212
  'type' => 'text',
213
+ 'desc' => '',
214
+ 'default' => '',
215
  ),
216
  array(
217
  'id' => 'bewpi-company-name',
575
  continue;
576
  }
577
 
 
 
 
 
578
  // strip all html and php tags and properly handle quoted strings.
579
  $output[ $key ] = $this->strip_str( stripslashes( $input[ $key ] ) );
580
  }
581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
  if ( isset( $input['bewpi_reset_counter'] ) && $input['bewpi_reset_counter'] ) {
583
  set_transient( 'bewpi_next_invoice_number', intval( $input['bewpi_next_invoice_number'] ) );
584
  }
586
  return apply_filters( 'bewpi_sanitized_' . $this->settings_key, $output, $input );
587
  }
588
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  /**
590
  * Sets template to default template when custom template has been deleted.
591
  */
includes/class-debug-log.php CHANGED
@@ -88,6 +88,11 @@ if ( ! class_exists( 'BEWPI_Debug_Log' ) ) {
88
 
89
  // Generate line.
90
  $level_name = self::get_level_name( $level );
 
 
 
 
 
91
  $message = sprintf( 'WooCommerce PDF Invoices %s: %s', $level_name, $message );
92
 
93
  return error_log( $message );
88
 
89
  // Generate line.
90
  $level_name = self::get_level_name( $level );
91
+
92
+ if ( is_array( $message ) ) {
93
+ $message = print_r( $message, true );
94
+ }
95
+
96
  $message = sprintf( 'WooCommerce PDF Invoices %s: %s', $level_name, $message );
97
 
98
  return error_log( $message );
includes/class-template.php CHANGED
@@ -325,17 +325,6 @@ class BEWPI_Template {
325
  return (bool) WPI()->get_option( 'template', 'enable_advanced_table_content' );
326
  }
327
 
328
- /**
329
- * Get the company logo URL.
330
- *
331
- * @deprecated use 'esc_url_raw( WPI()->get_option( 'template', 'company_logo' )' instead.
332
- *
333
- * @return string The actual url from the Media Library.
334
- */
335
- public function get_logo_url() {
336
- return esc_url_raw( $this->get_option( 'bewpi_company_logo' ) );
337
- }
338
-
339
  /**
340
  * Get template options by key.
341
  *
325
  return (bool) WPI()->get_option( 'template', 'enable_advanced_table_content' );
326
  }
327
 
 
 
 
 
 
 
 
 
 
 
 
328
  /**
329
  * Get template options by key.
330
  *
includes/templates/invoice/simple/micro/header.php CHANGED
@@ -2,7 +2,7 @@
2
  <tr>
3
  <td class="logo" width="50%">
4
  <?php
5
- if ( WPI()->templater()->get_logo_url() ) {
6
  printf( '<img class="company-logo" src="var:company_logo"/>' );
7
  } else {
8
  printf( '<h1 class="company-logo">%s</h1>', esc_html( WPI()->templater()->get_option( 'bewpi_company_name' ) ) );
2
  <tr>
3
  <td class="logo" width="50%">
4
  <?php
5
+ if ( WPI()->get_option( 'template', 'company_logo' ) ) {
6
  printf( '<img class="company-logo" src="var:company_logo"/>' );
7
  } else {
8
  printf( '<h1 class="company-logo">%s</h1>', esc_html( WPI()->templater()->get_option( 'bewpi_company_name' ) ) );
includes/woocommerce-pdf-invoices.php CHANGED
@@ -367,9 +367,16 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
367
  $invoice->update();
368
  break;
369
  case 'debug':
370
- $invoice = new BEWPI_Invoice( $order_id );
371
- $full_path = $invoice->update();
372
- BEWPI_Invoice::view( $full_path );
 
 
 
 
 
 
 
373
  break;
374
  }
375
 
@@ -469,6 +476,10 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
469
  wp_enqueue_script( 'wc-enhanced-select' );
470
  wp_enqueue_script( 'jquery-ui-sortable' );
471
  }
 
 
 
 
472
  }
473
 
474
  /**
@@ -694,7 +705,6 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
694
  $invoice = new BEWPI_Invoice( $post->ID );
695
 
696
  if ( ! $invoice->get_full_path() ) {
697
-
698
  $this->show_invoice_button( __( 'Create', 'woocommerce-pdf-invoices' ), $post->ID, 'create', array( 'class="button grant_access order-page invoice wpi"' ) );
699
 
700
  } else {
@@ -755,18 +765,18 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
755
  ) );
756
  }
757
 
758
- // display button to view invoice in debug mode.
759
- if ( (bool) WPI()->get_option( 'debug', 'mpdf_debug' ) ) {
760
- $this->show_invoice_button( __( 'Debug', 'woocommerce-pdf-invoices' ), $post->ID, 'debug', array(
761
- 'class="button grant_access order-page invoice wpi"',
762
- 'target="_blank"',
763
- ) );
764
- }
765
-
766
  echo '</p>';
767
 
768
  }
769
 
 
 
 
 
 
 
 
 
770
  do_action( 'bewpi_order_page_after_meta_box_details_end', $post->ID );
771
  }
772
 
@@ -874,7 +884,7 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
874
  *
875
  * @param int $order_id order ID.
876
  *
877
- * @return BEWPI_Abstract_Invoice
878
  */
879
  public function get_invoice( $order_id ) {
880
 
@@ -884,9 +894,10 @@ if ( ! class_exists( 'BE_WooCommerce_PDF_Invoices' ) ) {
884
  /**
885
  * Set order for templater directly after creation to fetch order data.
886
  *
 
 
887
  * @since 2.9.3 Do not use second and third parameters since several plugins do not use them. This prevents a fatal error.
888
  *
889
- * @param int $order_id WC_Order ID.
890
  */
891
  public static function set_order( $order_id ) {
892
  $order = wc_get_order( $order_id );
367
  $invoice->update();
368
  break;
369
  case 'debug':
370
+ $full_path = BEWPI_Abstract_Invoice::exists( $order_id );
371
+ if ( false === $full_path ) {
372
+ $invoice = new BEWPI_Invoice( $order_id );
373
+ $full_path = $invoice->generate();
374
+ BEWPI_Invoice::view( $full_path );
375
+ } else {
376
+ $invoice = new BEWPI_Invoice( $order_id );
377
+ $full_path = $invoice->update();
378
+ BEWPI_Invoice::view( $full_path );
379
+ }
380
  break;
381
  }
382
 
476
  wp_enqueue_script( 'wc-enhanced-select' );
477
  wp_enqueue_script( 'jquery-ui-sortable' );
478
  }
479
+
480
+ if ( isset( $_GET['page'] ) && 'woocommerce-pdf-invoices' === $_GET['page'] ) {
481
+ wp_enqueue_media();
482
+ }
483
  }
484
 
485
  /**
705
  $invoice = new BEWPI_Invoice( $post->ID );
706
 
707
  if ( ! $invoice->get_full_path() ) {
 
708
  $this->show_invoice_button( __( 'Create', 'woocommerce-pdf-invoices' ), $post->ID, 'create', array( 'class="button grant_access order-page invoice wpi"' ) );
709
 
710
  } else {
765
  ) );
766
  }
767
 
 
 
 
 
 
 
 
 
768
  echo '</p>';
769
 
770
  }
771
 
772
+ // display button to view invoice in debug mode.
773
+ if ( (bool) WPI()->get_option( 'debug', 'mpdf_debug' ) ) {
774
+ $this->show_invoice_button( __( 'Debug', 'woocommerce-pdf-invoices' ), $post->ID, 'debug', array(
775
+ 'class="button grant_access order-page invoice wpi"',
776
+ 'target="_blank"',
777
+ ) );
778
+ }
779
+
780
  do_action( 'bewpi_order_page_after_meta_box_details_end', $post->ID );
781
  }
782
 
884
  *
885
  * @param int $order_id order ID.
886
  *
887
+ * @return BEWPI_Invoice
888
  */
889
  public function get_invoice( $order_id ) {
890
 
894
  /**
895
  * Set order for templater directly after creation to fetch order data.
896
  *
897
+ * @param int $order_id WC_Order ID.
898
+ *
899
  * @since 2.9.3 Do not use second and third parameters since several plugins do not use them. This prevents a fatal error.
900
  *
 
901
  */
902
  public static function set_order( $order_id ) {
903
  $order = wc_get_order( $order_id );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: woocommerce pdf invoices, invoice, packing slips, delivery note, packing list, shipping list, generate, pdf, woocommerce, attachment, email, customer invoice, processing, vat, tax, sequential, number, dropbox, google drive, onedrive, egnyte, cloud, storage
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
- Stable tag: 3.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -344,6 +344,10 @@ Since version 2.9.4 the plugin removed the ability to update the PDF invoice whe
344
 
345
  == Changelog ==
346
 
 
 
 
 
347
  = 3.0.8 - August 30, 2019 =
348
 
349
  - Fixed: Reset invoice counter not deleting invoices.
4
  Tags: woocommerce pdf invoices, invoice, packing slips, delivery note, packing list, shipping list, generate, pdf, woocommerce, attachment, email, customer invoice, processing, vat, tax, sequential, number, dropbox, google drive, onedrive, egnyte, cloud, storage
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 3.0.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
344
 
345
  == Changelog ==
346
 
347
+ = 3.0.9 - October 26, 2019 =
348
+
349
+ - Improved: Custom logo upload setting by using the native media library.
350
+
351
  = 3.0.8 - August 30, 2019 =
352
 
353
  - Fixed: Reset invoice counter not deleting invoices.
vendor/autoload_52.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
- return ComposerAutoloaderInit0f02450610b8e9fc1a93d22bdebc9db9::getLoader();
4
 
5
  require_once dirname(__FILE__) . '/composer'.'/autoload_real_52.php';
6
 
7
+ return ComposerAutoloaderInitce7bc2d44e1502c83506d47b51f806b3::getLoader();
vendor/composer/autoload_real_52.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
- class ComposerAutoloaderInit0f02450610b8e9fc1a93d22bdebc9db9 {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
@@ -19,9 +19,9 @@ class ComposerAutoloaderInit0f02450610b8e9fc1a93d22bdebc9db9 {
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit0f02450610b8e9fc1a93d22bdebc9db9', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit0f02450610b8e9fc1a93d22bdebc9db9', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);
2
 
3
  // autoload_real_52.php generated by xrstf/composer-php52
4
 
5
+ class ComposerAutoloaderInitce7bc2d44e1502c83506d47b51f806b3 {
6
  private static $loader;
7
 
8
  public static function loadClassLoader($class) {
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInitce7bc2d44e1502c83506d47b51f806b3', 'loadClassLoader'), true /*, true */);
23
  self::$loader = $loader = new xrstf_Composer52_ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitce7bc2d44e1502c83506d47b51f806b3', 'loadClassLoader'));
25
 
26
  $vendorDir = dirname(dirname(__FILE__));
27
  $baseDir = dirname($vendorDir);
vendor/composer/installed.json CHANGED
@@ -6,12 +6,12 @@
6
  "source": {
7
  "type": "git",
8
  "url": "https://github.com/baselbers/mpdf.git",
9
- "reference": "749605444814dd4da1dba745452e157597663b60"
10
  },
11
  "dist": {
12
  "type": "zip",
13
- "url": "https://api.github.com/repos/baselbers/mpdf/zipball/749605444814dd4da1dba745452e157597663b60",
14
- "reference": "749605444814dd4da1dba745452e157597663b60",
15
  "shasum": ""
16
  },
17
  "require": {
@@ -25,7 +25,7 @@
25
  "suggest": {
26
  "ext-zlib": "Needed for compression of embedded resources, such as fonts"
27
  },
28
- "time": "2018-07-11T13:01:15+00:00",
29
  "type": "library",
30
  "installation-source": "source",
31
  "autoload": {
6
  "source": {
7
  "type": "git",
8
  "url": "https://github.com/baselbers/mpdf.git",
9
+ "reference": "6669c158f87d5449107eed74df9546d749fd2eb0"
10
  },
11
  "dist": {
12
  "type": "zip",
13
+ "url": "https://api.github.com/repos/baselbers/mpdf/zipball/6669c158f87d5449107eed74df9546d749fd2eb0",
14
+ "reference": "6669c158f87d5449107eed74df9546d749fd2eb0",
15
  "shasum": ""
16
  },
17
  "require": {
25
  "suggest": {
26
  "ext-zlib": "Needed for compression of embedded resources, such as fonts"
27
  },
28
+ "time": "2019-10-26T08:09:39+00:00",
29
  "type": "library",
30
  "installation-source": "source",
31
  "autoload": {
vendor/mpdf/mpdf/mpdf.php CHANGED
@@ -26345,9 +26345,9 @@ class mPDF
26345
  if (isset($tpl['resources'])) {
26346
  $this->current_parser = $tpl['parser'];
26347
  reset($tpl['resources'][1]);
26348
- while (list($k, $v) = each($tpl['resources'][1])) {
26349
  if ($k == '/Shading') {
26350
- while (list($k2, $v2) = each($v[1])) {
26351
  $this->_out($k2 . " ", false);
26352
  $this->pdf_write_value($v2);
26353
  }
@@ -31088,7 +31088,7 @@ class mPDF
31088
  // A dictionary.
31089
  $this->_out("<<", false);
31090
  reset($value[1]);
31091
- while (list($k, $v) = each($value[1])) {
31092
  $this->_out($k . ' ',false);
31093
  $this->pdf_write_value($v);
31094
  }
26345
  if (isset($tpl['resources'])) {
26346
  $this->current_parser = $tpl['parser'];
26347
  reset($tpl['resources'][1]);
26348
+ foreach($tpl['resources'][1] as $k => $v) {
26349
  if ($k == '/Shading') {
26350
+ foreach($v[1] as $k2 => $v2) {
26351
  $this->_out($k2 . " ", false);
26352
  $this->pdf_write_value($v2);
26353
  }
31088
  // A dictionary.
31089
  $this->_out("<<", false);
31090
  reset($value[1]);
31091
+ foreach($value[1] as $k => $v) {
31092
  $this->_out($k . ' ',false);
31093
  $this->pdf_write_value($v);
31094
  }