Skip to content

Commit

Permalink
Merge pull request #35 from LinkNacional/dev
Browse files Browse the repository at this point in the history
1.3.0 - new template and new PDF settings
  • Loading branch information
brunoferreiralkn authored Nov 1, 2023
2 parents ecf4860 + 6e914f4 commit 773d399
Show file tree
Hide file tree
Showing 19 changed files with 594 additions and 101 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 1.3.0 - 01/11/23
- Add default footer setting
- Add text_before_payment_link setting
- Add setting for sender details
- Adjust existing templates to handle the new settings
- Add new template

### 1.2.1 - 20/10/23
- Adjust to get logo with curl, adjust to work in directory installed wordpress.

Expand Down
9 changes: 8 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.linknacional.com/wordpress/plugins/
Tags: woocommerce, invoice, payment
Requires at least: 5.7
Tested up to: 6.3
Stable tag: 1.2.1
Stable tag: 1.3.0
Requires PHP: 7.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -64,6 +64,13 @@ The Invoice Payment for WooCommerce plugin is now live and working.

== Changelog ==

= 1.3.0 =
* Add default footer setting
* Add text_before_payment_link setting
* Add setting for sender details
* Adjust existing templates to handle the new settings
* Add new template

= 1.2.1 =
* Adjust to get logo with curl, adjust to work in directory installed wordpress.

Expand Down
123 changes: 63 additions & 60 deletions admin/class-wc-invoice-payment-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,28 @@ public function render_settings_page(): void {
return;
}

wp_enqueue_editor();

if ( ! empty($_POST)) {
$global_pdf_template = sanitize_text_field($_POST['lkn_wcip_payment_global_template']);
$template_logo_url = sanitize_text_field($_POST['lkn_wcip_template_logo_url']);
$default_footer = wp_kses_post($_POST['lkn_wcip_default_footer']);
$sender_details = wp_kses_post($_POST['lkn_wcip_sender_details']);
$text_before_payment_link = wp_kses_post($_POST['lkn_wcip_text_before_payment_link']);

update_option('lkn_wcip_global_pdf_template_id', $global_pdf_template);
update_option('lkn_wcip_template_logo_url', $template_logo_url);
update_option('lkn_wcip_default_footer', $default_footer);
update_option('lkn_wcip_sender_details', $sender_details);
update_option('lkn_wcip_text_before_payment_link', $text_before_payment_link);
}

$templates_list = $this->handler_invoice_templates->get_templates_list();
$global_template = get_option('lkn_wcip_global_pdf_template_id', 'linknacional');
$template_logo_url = get_option('lkn_wcip_template_logo_url');
$default_footer = get_option('lkn_wcip_default_footer');
$sender_details = get_option('lkn_wcip_sender_details');
$text_before_payment_link = get_option('lkn_wcip_text_before_payment_link');

$html_templates_list = implode(array_map(function ($template) use ($global_template): string {
$template_id = $template['id'];
Expand Down Expand Up @@ -226,7 +237,7 @@ class="wcip-form-wrap"
</h2>
<div class="invoice-row-wrap">
<div class="invoice-column-wrap">
<div class="input-row-wrap">
<div class="input-row-wrap input-row-wrap-global-settings">
<label for="lkn_wcip_payment_global_template">
<?php _e('Default PDF template for invoices', 'wc-invoice-payment'); ?>
</label>
Expand All @@ -242,7 +253,7 @@ class="regular-text"
<div style="position: relative;"><img id="lkn-wcip-preview-img" /></div>
</div>

<div class="input-row-wrap">
<div class="input-row-wrap input-row-wrap-global-settings">
<label for="lkn_wcip_payment_global_template">
<?php _e('Logo URL', 'wc-invoice-payment'); ?>
</label>
Expand All @@ -254,6 +265,36 @@ class="regular-text"
value="<?php echo $template_logo_url; ?>"
>
</div>

<div class="input-row-wrap input-row-wrap-global-settings">
<label for="lkn_wcip_default_footer">
<?php _e('Default footer', 'wc-invoice-payment'); ?>
</label>
<textarea
name="lkn_wcip_default_footer"
id="lkn_wcip_default_footer"
><?php echo $default_footer; ?></textarea>
</div>

<div class="input-row-wrap input-row-wrap-global-settings">
<label for="lkn_wcip_sender_details">
<?php _e('Sender details', 'wc-invoice-payment'); ?>
</label>
<textarea
name="lkn_wcip_sender_details"
id="lkn_wcip_sender_details"
><?php echo $sender_details; ?></textarea>
</div>

<div class="input-row-wrap input-row-wrap-global-settings">
<label for="lkn_wcip_text_before_payment_link">
<?php _e('Text before payment link', 'wc-invoice-payment'); ?>
</label>
<textarea
name="lkn_wcip_text_before_payment_link"
id="lkn_wcip_text_before_payment_link"
><?php echo $text_before_payment_link; ?></textarea>
</div>
</div>
</div>
<div class="action-btn">
Expand All @@ -262,6 +303,13 @@ class="regular-text"
</div>
</form>
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
startTinyMce('lkn_wcip_default_footer', 'submit')
startTinyMce('lkn_wcip_sender_details', 'submit')
startTinyMce('lkn_wcip_text_before_payment_link', 'submit')
})
</script>
<?php
}

Expand Down Expand Up @@ -418,7 +466,9 @@ class="regular-text"
value="<?php echo $invoice_template; ?>"
required
>
<option value="global"><?php _e('Default template', 'wc-invoice-payment'); ?></option>
<option value="global">
<?php _e('Default template', 'wc-invoice-payment'); ?>
</option>
<?php echo $html_templates_list; ?>
</select>
</div>
Expand Down Expand Up @@ -645,23 +695,7 @@ class="invoice-column-wrap"
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
wp.editor.initialize('lkn-wc-invoice-payment-footer-notes', {
tinymce: {
toolbar1: 'bold italic underline',
style_formats: [{
title: 'Underline',
inline: 'u'
}]
},
quicktags: true
})

const btnSubmit = document.getElementById('submit')
const footerNotesTextarea = document.getElementById('lkn-wc-invoice-payment-footer-notes')

btnSubmit.addEventListener('click', () => {
footerNotesTextarea.innerHTML = wp.editor.getContent('lkn-wc-invoice-payment-footer-notes')
})
startTinyMce('lkn-wc-invoice-payment-footer-notes', 'submit')
})
</script>
<?php
Expand Down Expand Up @@ -753,6 +787,8 @@ public function new_invoice_form(): void {
return "<option data-preview-url='$preview_url' value='$template_id'>$friendly_template_name</option>";
}, $templates_list));

$default_footer = get_option('lkn_wcip_default_footer');

// Get all WooCommerce enabled gateways
if ($gateways) {
foreach ($gateways as $gateway) {
Expand Down Expand Up @@ -849,7 +885,9 @@ class="regular-text"
class="regular-text"
required
>
<option value="global"><?php _e('Default template', 'wc-invoice-payment'); ?></option>
<option value="global">
<?php _e('Default template', 'wc-invoice-payment'); ?>
</option>
<?php echo $html_templates_list; ?>
</select>
</div>
Expand Down Expand Up @@ -987,31 +1025,15 @@ class="invoice-column-wrap"
name="lkn-wc-invoice-payment-footer-notes"
id="lkn-wc-invoice-payment-footer-notes"
class="regular-text"
></textarea>
><?php echo $default_footer; ?></textarea>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
wp.editor.initialize('lkn-wc-invoice-payment-footer-notes', {
tinymce: {
toolbar1: 'bold italic underline',
style_formats: [{
title: 'Underline',
inline: 'u'
}]
},
quicktags: true
})

const btnSubmit = document.getElementById('submit')
const footerNotesTextarea = document.getElementById('lkn-wc-invoice-payment-footer-notes')

btnSubmit.addEventListener('click', () => {
footerNotesTextarea.innerHTML = wp.editor.getContent('lkn-wc-invoice-payment-footer-notes')
})
startTinyMce('lkn-wc-invoice-payment-footer-notes', 'submit')
})
</script>
<?php
Expand Down Expand Up @@ -1060,16 +1082,7 @@ public function add_invoice_form_submit_handle(): void {
$email = sanitize_email($_POST['lkn_wcip_email']);
$expDate = sanitize_text_field($_POST['lkn_wcip_exp_date']);
$extraData = sanitize_text_field($_POST['lkn_wcip_extra_data']);
$footerNotes = wp_kses(
$_POST['lkn-wc-invoice-payment-footer-notes'],
array(
'b' => array(),
'i' => array(),
'em' => array(),
'strong' => array(),
'p' => array()
)
);
$footerNotes = wp_kses_post($_POST['lkn-wc-invoice-payment-footer-notes']);

$order = wc_create_order(
array(
Expand Down Expand Up @@ -1203,17 +1216,7 @@ public function edit_invoice_form_submit_handle(): void {
$expDate = sanitize_text_field($_POST['lkn_wcip_exp_date']);
$pdfTemplateId = sanitize_text_field($_POST['lkn_wcip_select_invoice_template']);
$extraData = wp_kses($_POST['lkn_wcip_extra_data'], array('br' => array()));
$footerNotes = wp_kses(
$_POST['lkn-wc-invoice-payment-footer-notes'],
array(
'b' => array(),
'i' => array(),
'em' => array(),
'strong' => array(),
'p' => array(),
'br' => array()
)
);
$footerNotes = wp_kses_post($_POST['lkn-wc-invoice-payment-footer-notes']);

$order->update_meta_data('wcip_extra_data', $extraData);
$order->update_meta_data('wcip_footer_notes', $footerNotes);
Expand Down
8 changes: 8 additions & 0 deletions admin/css/wc-invoice-payment-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
margin: 20px 0px;
}

.input-row-wrap-global-settings {
background-color: #FBFBFB;
border: 1px solid #ccc;
padding: 25px !important;
margin: 10px 0 10px;
font-size: 15px;
}

.invoice-column-wrap {
display: flex;
flex-direction: column;
Expand Down
25 changes: 25 additions & 0 deletions admin/js/wc-invoice-payment-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,28 @@ document.addEventListener('DOMContentLoaded', () => {
handlePreviewPdfTemplate(selectInvoiceTemplate, document.getElementById('lkn-wcip-preview-img'))
}
})

/**
* TinyMCE toolbar options doc: https://www.tiny.cloud/docs/advanced/available-toolbar-buttons/
*/
function startTinyMce (elementId, btnSubmitId) {
wp.editor.initialize(elementId, {
tinymce: {
toolbar1: 'bold italic underline forecolor backcolor fontsizeselect link',
content_style: 'body { font-family: Arial, sans-serif; }',
style_formats: [{
title: 'Underline',
inline: 'u'
}],
height: 150
},
quicktags: false
})

const btnSubmit = document.getElementById(btnSubmitId)
const footerNotesTextarea = document.getElementById(elementId)

btnSubmit.addEventListener('click', () => {
footerNotesTextarea.innerHTML = wp.editor.getContent(elementId)
})
}
Binary file added includes/templates/comlogo2/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 773d399

Please sign in to comment.