Skip to content

Commit

Permalink
New: advanced tab with Number tools integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Sep 19, 2023
1 parent e00f82e commit 51e597d
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 134 deletions.
3 changes: 2 additions & 1 deletion assets/css/debug-tools.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ form#wpo-wcpdf-settings {
margin-left: 0 !important;
}
#debug-tools {
width: 50%;
width: 100%;
margin-top: 2em;
}

#debug-tools .wrapper {
Expand Down
8 changes: 6 additions & 2 deletions assets/css/settings-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ body.woocommerce_page_wpo_wcpdf_options_page {
margin: 15px 0 0;
}

.nav-tab-wrapper a.nav-tab {
.nav-tab-wrapper:not( .wcpdf_debug_settings_sections > .nav-tab-wrapper) a.nav-tab {
background: transparent;
border: none;
border-bottom: 3px solid transparent;
Expand All @@ -272,7 +272,7 @@ body.woocommerce_page_wpo_wcpdf_options_page {
font-size: 15px;
}

.nav-tab-wrapper a.nav-tab.nav-tab-active {
.nav-tab-wrapper:not( .wcpdf_debug_settings_sections > .nav-tab-wrapper) a.nav-tab.nav-tab-active {
border-bottom: 3px solid #51266b;
}

Expand Down Expand Up @@ -435,6 +435,10 @@ body.woocommerce_page_wpo_wcpdf_options_page {
font-size: 12px;
}

#wpo-wcpdf-settings .system-status-table {
margin-top: 2em;
}

#wpo-wcpdf-preview-wrapper[data-preview-states="1"] .sidebar {
flex: 0 0 100%;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wcpdf-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct() {
add_filter( 'wpo_wcpdf_pdf_filters', array( $this, 'pdf_currency_filters' ) );
add_filter( 'wpo_wcpdf_html_filters', array( $this, 'html_currency_filters' ) );

// scheduled attachments cleanup (following settings on Status tab)
// scheduled attachments cleanup (following settings on Advanced tab)
add_action( 'wp_scheduled_delete', array( $this, 'schedule_temporary_files_cleanup' ) );

// remove private data
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wcpdf-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function check_auto_increment_increment() {
$row = $wpdb->get_row( "SHOW VARIABLES LIKE 'auto_increment_increment'" );
if ( ! empty( $row ) && ! empty( $row->Value ) && $row->Value != 1 ) {
/* translators: database row value */
$error = wp_kses_post( sprintf( __( "<strong>Warning!</strong> Your database has an AUTO_INCREMENT step size of %d, your invoice numbers may not be sequential. Enable the 'Calculate document numbers (slow)' setting in the Status tab to use an alternate method." , 'woocommerce-pdf-invoices-packing-slips' ), intval( $row->Value ) ) );
$error = wp_kses_post( sprintf( __( "<strong>Warning!</strong> Your database has an AUTO_INCREMENT step size of %d, your invoice numbers may not be sequential. Enable the 'Calculate document numbers (slow)' setting in the Advanced tab to use an alternate method." , 'woocommerce-pdf-invoices-packing-slips' ), intval( $row->Value ) ) );
printf( '<div class="error"><p>%s</p></div>', $error );
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ public function settings_page() {

// add status and upgrade tabs last in row
$settings_tabs['debug'] = array(
'title' => __( 'Status', 'woocommerce-pdf-invoices-packing-slips' ),
'title' => __( 'Advanced', 'woocommerce-pdf-invoices-packing-slips' ),
'preview_states' => 1,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public function get_thumbnail ( $product ) {
* which turns the function 'imagecreatefromwebp()' inexistent,
* leading to display an error in DOMPDF.
*
* Check 'System configuration' in the Status tab for 'webp' support.
* Check 'System configuration' in the Advanced tab for 'webp' support.
*/
if ( 'webp' === wp_check_filetype( $thumbnail_path )['ext'] && ! function_exists( 'imagecreatefromwebp' ) ) {
$thumbnail = '';
Expand Down
2 changes: 1 addition & 1 deletion includes/settings/class-wcpdf-settings-callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function media_upload( $args ) {
if ( 'webp' === wp_check_filetype( $attachment_src )['ext'] && ! function_exists( 'imagecreatefromwebp' ) ) {
printf(
'<div class="notice notice-warning inline" style="display:inline-block; width:auto;"><p>%s</p></div>',
wp_kses_post( 'File type <strong>webp</strong> is not supported by your server! Please check your <strong>System Configurations</strong> under the <strong>Status</strong> tab.', 'woocommerce-pdf-invoices-packing-slips' )
wp_kses_post( 'File type <strong>webp</strong> is not supported by your server! Please check your <strong>System Configurations</strong> under the <strong>Advanced</strong> tab.', 'woocommerce-pdf-invoices-packing-slips' )
);
}

Expand Down
64 changes: 46 additions & 18 deletions includes/settings/class-wcpdf-settings-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Settings_Debug {

protected static $_instance = null;
public $sections;

public static function instance() {
if ( is_null( self::$_instance ) ) {
Expand All @@ -19,28 +20,61 @@ public static function instance() {
}

public function __construct() {
$this->sections = array(
'settings' => __( 'Settings', 'woocommerce-pdf-invoices-packing-slips' ),
'status' => __( 'Status', 'woocommerce-pdf-invoices-packing-slips' ),
'tools' => __( 'Tools', 'woocommerce-pdf-invoices-packing-slips' ),
'numbers' => __( 'Numbers', 'woocommerce-pdf-invoices-packing-slips' ),
);

add_action( 'admin_init', array( $this, 'init_settings' ) );
add_action( 'wpo_wcpdf_settings_output_debug', array( $this, 'output' ), 10, 1 );
add_action( 'wpo_wcpdf_after_settings_page', array( $this, 'debug_tools' ), 10, 2 );

add_action( 'wpo_wcpdf_after_settings_page', array( $this, 'dompdf_status' ), 20, 2 );

add_action( 'wp_ajax_wpo_wcpdf_debug_tools', array( $this, 'ajax_debug_tools' ) );
}

public function output( $section ) {
settings_fields( "wpo_wcpdf_settings_debug" );
do_settings_sections( "wpo_wcpdf_settings_debug" );
public function output( $active_section ) {
$active_section = ! empty( $active_section ) ? $active_section : 'settings';

?>
<div class="wcpdf_debug_settings_sections">
<h2 class="nav-tab-wrapper">
<?php
foreach ( $this->sections as $section => $title ) {
$active = ( $section == $active_section ) ? 'nav-tab-active' : '';
printf( '<a href="%1$s" class="nav-tab nav-tab-%2$s %3$s">%4$s</a>', esc_url( add_query_arg( 'section', $section ) ), esc_attr( $section ), $active, esc_html( $title ) );
}
?>
</h2>
</div>
<?php

switch ( $active_section ) {
case 'settings':
$this->display_settings();
break;
case 'status':
$this->display_status();
break;
case 'tools':
$this->display_tools();
break;
}
}

public function display_settings() {
settings_fields( 'wpo_wcpdf_settings_debug' );
do_settings_sections( 'wpo_wcpdf_settings_debug' );

submit_button();
}

public function display_status() {
include( WPO_WCPDF()->plugin_path() . '/includes/views/advanced-status.php' );
}

public function debug_tools( $tab, $section ) {
if ( $tab !== 'debug' ) {
return;
}
public function display_tools() {
?>
<h3><?php _e( 'Tools', 'woocommerce-pdf-invoices-packing-slips' ); ?></h3>
<div id="debug-tools">
<div class="wrapper">
<?php do_action( 'wpo_wcpdf_before_debug_tools', $this ); ?>
Expand Down Expand Up @@ -482,12 +516,6 @@ public function get_setting_types() {
return apply_filters( 'wpo_wcpdf_setting_types', $setting_types );
}

public function dompdf_status( $tab, $section ) {
if ( $tab === 'debug' ) {
include( WPO_WCPDF()->plugin_path() . '/includes/views/dompdf-status.php' );
}
}

public function init_settings() {
// Register settings.
$page = $option_group = $option_name = 'wpo_wcpdf_settings_debug';
Expand All @@ -496,7 +524,7 @@ public function init_settings() {
array(
'type' => 'section',
'id' => 'debug_settings',
'title' => __( 'Debug settings', 'woocommerce-pdf-invoices-packing-slips' ),
'title' => '',
'callback' => 'section',
),
array(
Expand Down
Loading

0 comments on commit 51e597d

Please sign in to comment.