From 473d53f43d0a0d26019c9f9cf7222f2fa76cf817 Mon Sep 17 00:00:00 2001 From: Alexandre Faustino Date: Tue, 17 Oct 2023 14:06:41 +0100 Subject: [PATCH] Some improvements on David remarks --- assets/js/order-script.js | 2 +- includes/class-wcpdf-font-synchronizer.php | 20 ++------------ includes/class-wcpdf-settings.php | 32 ++++++++-------------- readme.txt | 4 +-- 4 files changed, 18 insertions(+), 40 deletions(-) diff --git a/assets/js/order-script.js b/assets/js/order-script.js index aa385afce..1329189fe 100644 --- a/assets/js/order-script.js +++ b/assets/js/order-script.js @@ -1,6 +1,6 @@ jQuery( function( $ ) { - $( document.body ).on( 'click', '#doaction, #doaction2', function( e ) { + $( '.tablenav' ).on( 'click', '#doaction, #doaction2', function( e ) { let actionselected = $( this ).attr( "id" ).substr( 2 ); let action = $( 'select[name="' + actionselected + '"]' ).val(); diff --git a/includes/class-wcpdf-font-synchronizer.php b/includes/class-wcpdf-font-synchronizer.php index afbb20a81..0db2fe263 100644 --- a/includes/class-wcpdf-font-synchronizer.php +++ b/includes/class-wcpdf-font-synchronizer.php @@ -49,7 +49,7 @@ public function __construct() { * @return void */ public function sync( $destination, $merge_with_local = true ) { - $destination = trailingslashit( $this->normalize_path( $destination ) ); + $destination = trailingslashit( wp_normalize_path( $destination ) ); $plugin_fonts = $this->get_plugin_fonts(); $dompdf_fonts = $this->get_dompdf_fonts(); @@ -91,7 +91,7 @@ public function sync( $destination, $merge_with_local = true ) { * @return void */ public function delete_font_files( $filenames ) { - $plugin_folder = $this->normalize_path( WPO_WCPDF()->plugin_path() ); + $plugin_folder = wp_normalize_path( WPO_WCPDF()->plugin_path() ); $extensions = array( '.ttf', '.ufm', '.ufm.php', '.afm', '.afm.php' ); foreach ( $filenames as $filename ) { // never delete files in our own plugin folder @@ -211,20 +211,6 @@ public function get_plugin_fonts() { ); } - /** - * Normalize a filesystem path. - * - * @param string $path Path to normalize. - * @return string Normalized path. - */ - public function normalize_path( $path ) { - if ( ! empty( $path ) ) { - return function_exists( 'wp_normalize_path' ) ? wp_normalize_path( $path ) : str_replace( '\\', '/', $path ); - } else { - return $path; - } - } - /** * Apply path normalization to a font list * @@ -237,7 +223,7 @@ public function normalize_font_paths( $fonts ) { continue; } foreach ( $filenames as $variant => $filename ) { - $fonts[$font_name][$variant] = $this->normalize_path( $filename ); + $fonts[$font_name][$variant] = wp_normalize_path( $filename ); } } return $fonts; diff --git a/includes/class-wcpdf-settings.php b/includes/class-wcpdf-settings.php index 138ae260c..b4f991530 100644 --- a/includes/class-wcpdf-settings.php +++ b/includes/class-wcpdf-settings.php @@ -560,7 +560,7 @@ public function get_output_mode() { public function get_template_path() { // return default path if no template selected if ( empty( $this->general_settings['template_path'] ) ) { - return $this->normalize_path( WPO_WCPDF()->plugin_path() . '/templates/Simple' ); + return wp_normalize_path( WPO_WCPDF()->plugin_path() . '/templates/Simple' ); } $installed_templates = $this->get_installed_templates(); @@ -569,18 +569,18 @@ public function get_template_path() { return array_search( $selected_template, $installed_templates ); } else { // unknown template or full template path (filter override) - $template_path = $this->normalize_path( $selected_template ); + $template_path = wp_normalize_path( $selected_template ); // add base path, checking if it's not already there // alternative setups like Bedrock have WP_CONTENT_DIR & ABSPATH separated if ( defined( 'WP_CONTENT_DIR' ) && ! empty( WP_CONTENT_DIR ) && false !== strpos( WP_CONTENT_DIR, ABSPATH ) ) { - $base_path = $this->normalize_path( ABSPATH ); + $base_path = wp_normalize_path( ABSPATH ); } else { - $base_path = $this->normalize_path( WP_CONTENT_DIR ); + $base_path = wp_normalize_path( WP_CONTENT_DIR ); } if ( ! empty( $template_path ) && false === strpos( $template_path, $base_path ) ) { - $template_path = $this->normalize_path( $base_path . $template_path ); + $template_path = wp_normalize_path( $base_path . $template_path ); } } @@ -616,7 +616,7 @@ public function get_installed_templates( $force_reload = false ) { $dirs = (array) glob( $template_path . '*' , GLOB_ONLYDIR ); foreach ( $dirs as $dir ) { - $clean_dir = $this->normalize_path( $dir ); + $clean_dir = wp_normalize_path( $dir ); $template_name = basename( $clean_dir ); // let child theme override parent theme $group = ( $template_source == 'child-theme' ) ? 'theme' : $template_source; @@ -626,7 +626,7 @@ public function get_installed_templates( $force_reload = false ) { if ( empty( $installed_templates ) ) { // fallback to Simple template for servers with glob() disabled - $simple_template_path = $this->normalize_path( $template_paths['default'] . 'Simple' ); + $simple_template_path = wp_normalize_path( $template_paths['default'] . 'Simple' ); $installed_templates[$simple_template_path] = 'default/Simple'; } @@ -709,19 +709,11 @@ public function maybe_delete_flush_rewrite_rules_transient() { public function get_relative_template_path( $absolute_path ) { if ( defined( 'WP_CONTENT_DIR' ) && ! empty( WP_CONTENT_DIR ) && false !== strpos( WP_CONTENT_DIR, ABSPATH ) ) { - $base_path = $this->normalize_path( ABSPATH ); + $base_path = wp_normalize_path( ABSPATH ); } else { - $base_path = $this->normalize_path( WP_CONTENT_DIR ); - } - return str_replace( $base_path, '', $this->normalize_path( $absolute_path ) ); - } - - public function normalize_path( $path ) { - if ( ! empty( $path ) ) { - return function_exists( 'wp_normalize_path' ) ? wp_normalize_path( $path ) : str_replace( '\\', '/', $path ); - } else { - return $path; + $base_path = wp_normalize_path( WP_CONTENT_DIR ); } + return str_replace( $base_path, '', wp_normalize_path( $absolute_path ) ); } public function maybe_migrate_template_paths( $settings_section = null ) { @@ -731,12 +723,12 @@ public function maybe_migrate_template_paths( $settings_section = null ) { } $installed_templates = $this->get_installed_templates( true ); - $selected_template = $this->normalize_path( $this->general_settings['template_path'] ); + $selected_template = wp_normalize_path( $this->general_settings['template_path'] ); $template_match = ''; if ( ! in_array( $selected_template, $installed_templates ) && substr_count( $selected_template, '/' ) > 1 ) { // search for path match foreach ( $installed_templates as $path => $template_id ) { - $path = $this->normalize_path( $path ); + $path = wp_normalize_path( $path ); // check if the last part of the path matches if ( substr( $path, -strlen( $selected_template ) ) === $selected_template ) { $template_match = $template_id; diff --git a/readme.txt b/readme.txt index eb421e915..9b686a54c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: pomegranate, alexmigf, yordansoares, kluver, dpeyou, dwpriv, jhosagid Donate link: https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-bundle/ Tags: woocommerce, pdf, ubl, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic -Requires at least: 3.5 +Requires at least: 4.4 Tested up to: 6.3 Requires PHP: 7.2 Stable tag: 3.7.0 @@ -43,7 +43,7 @@ In addition to a number of default settings (including a custom header/logo) and = Minimum Requirements = * WooCommerce 3.0 or later -* WordPress 3.5 or later +* WordPress 4.4 or later = Automatic installation = Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't even need to leave your web browser. To do an automatic install of PDF Invoices & Packing Slips for WooCommerce, log in to your WordPress admin panel, navigate to the Plugins menu and click Add New.