Skip to content

Commit

Permalink
Add setting to select template
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitbohra committed May 9, 2019
1 parent a1025f0 commit 60c6e8f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions includes/class-invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,21 @@ public static function generate_pdf() {
wp_die( 'Invalid request.' );
}

// Get template.
$munim_settings_template = get_option( 'munim_settings_template', [] );
$munim_template_path = MUNIM_PLUGIN_DIR . 'templates/' . $munim_settings_template['template'];

// Get HTML.
ob_start();
include MUNIM_PLUGIN_DIR . 'templates/minimal/invoice.php';
include $munim_template_path . '/invoice.php';
$html = ob_get_contents();
ob_end_clean();

// Generate pdf.
$dompdf = new DOMPDF();
$dompdf->loadHtml( $html );
$dompdf->setPaper( 'A4', 'portrait' );
$dompdf->setBasePath( MUNIM_PLUGIN_DIR . '/templates/minimal' );
$dompdf->setBasePath( $munim_template_path );
$dompdf->render();
$dompdf->stream(
Helpers::get_file_name( $invoice_id ),
Expand Down
28 changes: 28 additions & 0 deletions includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,34 @@ public static function register_settings() {
'type' => 'text',
]
);

// Template Settings.
$args = [
'id' => self::$options_prefix . 'template',
'title' => 'Munim Settings > Template',
'object_types' => [ 'options-page' ],
'option_key' => self::$options_prefix . 'template',
'tab_group' => 'munim_settings',
'tab_title' => 'Template',
'display_cb' => [ __CLASS__, 'render_settings' ],
'parent_slug' => 'admin.php?page=munim_settings_business',
];

$template_settings = new_cmb2_box( $args );
$screenshot_path = MUNIM_PLUGIN_URL . 'templates/';

$template_settings->add_field(
[
'name' => 'Use',
'id' => 'template',
'type' => 'radio_inline',
'options' => array(
'minimal' => __( 'Minimal <br/> <br/><img width="200px" src="' . $screenshot_path . 'minimal/screenshot.png" />', 'munim' ),
'modern' => __( 'Modern <br/> <br/><img width="200px" src="' . $screenshot_path . 'modern/screenshot.png" />', 'munim' ),
),
'default' => 'minimal',
]
);
}

/**
Expand Down
Binary file added templates/minimal/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion templates/modern/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

</td>
<td class="border-left" style="background-color: #e9e9e9">
<?php echo $invoice_data['munimji_invoice_total']; ?>
<?php echo $invoice_data['munim_invoice_total']; ?>
</td>
</tr>
</tbody>
Expand Down
Binary file added templates/modern/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
delete_option( 'munim_settings_business' );
delete_option( 'munim_settings_invoice' );
delete_option( 'munim_settings_bank' );
delete_option( 'munim_settings_template' );

0 comments on commit 60c6e8f

Please sign in to comment.