@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,68 +21,68 @@ discard block |
||
| 21 | 21 | public function init() { |
| 22 | 22 | global $wp_filesystem; |
| 23 | 23 | |
| 24 | - if ( empty( $wp_filesystem ) ) { |
|
| 25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
| 24 | + if (empty($wp_filesystem)) { |
|
| 25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
| 26 | 26 | WP_Filesystem(); |
| 27 | 27 | global $wp_filesystem; |
| 28 | 28 | } |
| 29 | 29 | $this->wp_filesystem = $wp_filesystem; |
| 30 | 30 | |
| 31 | 31 | $this->export_dir = $this->export_location(); |
| 32 | - $this->export_url = $this->export_location( true ); |
|
| 32 | + $this->export_url = $this->export_location(true); |
|
| 33 | 33 | $this->export = 'invoicing'; |
| 34 | 34 | $this->filetype = 'csv'; |
| 35 | 35 | $this->per_page = 20; |
| 36 | 36 | |
| 37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
| 37 | + do_action('wpinv_class_reports_init', $this); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function includes() { |
| 41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
| 41 | + do_action('wpinv_class_reports_includes', $this); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function actions() { |
| 45 | - if ( is_admin() ) { |
|
| 46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 ); |
|
| 47 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
| 48 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
| 45 | + if (is_admin()) { |
|
| 46 | + add_action('admin_menu', array($this, 'add_submenu'), 10); |
|
| 47 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
| 48 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
| 49 | 49 | |
| 50 | 50 | // Export Invoices. |
| 51 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
| 52 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
| 53 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
| 54 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
| 51 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
| 52 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
| 53 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
| 54 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
| 55 | 55 | } |
| 56 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
| 56 | + do_action('wpinv_class_reports_actions', $this); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function add_submenu() { |
| 60 | 60 | global $wpi_reports_page; |
| 61 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
| 61 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page')); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function reports_page() { |
| 65 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
| 66 | - wp_enqueue_script( 'postbox' ); |
|
| 65 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
| 66 | + wp_enqueue_script('postbox'); |
|
| 67 | 67 | } |
| 68 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
| 69 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 68 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
| 69 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
| 73 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export'; |
|
| 72 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
| 73 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export'; |
|
| 74 | 74 | ?> |
| 75 | 75 | <div class="wrap wpi-reports-wrap"> |
| 76 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
| 76 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
| 77 | 77 | <h2 class="nav-tab-wrapper wp-clearfix"> |
| 78 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
| 79 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
| 78 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
| 79 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
| 80 | 80 | </h2> |
| 81 | 81 | <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>"> |
| 82 | 82 | <?php |
| 83 | - do_action( 'wpinv_reports_page_top' ); |
|
| 84 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
| 85 | - do_action( 'wpinv_reports_page_bottom' ); |
|
| 83 | + do_action('wpinv_reports_page_top'); |
|
| 84 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
| 85 | + do_action('wpinv_reports_page_bottom'); |
|
| 86 | 86 | ?> |
| 87 | 87 | </div> |
| 88 | 88 | <?php |
@@ -90,97 +90,97 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | public function export() { |
| 92 | 92 | $statuses = wpinv_get_invoice_statuses(); |
| 93 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
| 93 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
| 94 | 94 | ?> |
| 95 | 95 | <div class="metabox-holder"> |
| 96 | 96 | <div id="post-body"> |
| 97 | 97 | <div id="post-body-content"> |
| 98 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
| 98 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
| 99 | 99 | |
| 100 | 100 | <div class="postbox wpi-export-invoices"> |
| 101 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
| 101 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
| 102 | 102 | <div class="inside"> |
| 103 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
| 103 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
| 104 | 104 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
| 105 | - <?php echo wpinv_html_date_field( array( |
|
| 105 | + <?php echo wpinv_html_date_field(array( |
|
| 106 | 106 | 'id' => 'wpi_export_from_date', |
| 107 | 107 | 'name' => 'from_date', |
| 108 | 108 | 'data' => array( |
| 109 | 109 | 'dateFormat' => 'yy-mm-dd' |
| 110 | 110 | ), |
| 111 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
| 111 | + 'placeholder' => __('From date', 'invoicing') ) |
|
| 112 | 112 | ); ?> |
| 113 | - <?php echo wpinv_html_date_field( array( |
|
| 113 | + <?php echo wpinv_html_date_field(array( |
|
| 114 | 114 | 'id' => 'wpi_export_to_date', |
| 115 | 115 | 'name' => 'to_date', |
| 116 | 116 | 'data' => array( |
| 117 | 117 | 'dateFormat' => 'yy-mm-dd' |
| 118 | 118 | ), |
| 119 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
| 119 | + 'placeholder' => __('To date', 'invoicing') ) |
|
| 120 | 120 | ); ?> |
| 121 | 121 | <span id="wpinv-status-wrap"> |
| 122 | - <?php echo wpinv_html_select( array( |
|
| 122 | + <?php echo wpinv_html_select(array( |
|
| 123 | 123 | 'options' => $statuses, |
| 124 | 124 | 'name' => 'status', |
| 125 | 125 | 'id' => 'wpi_export_status', |
| 126 | 126 | 'show_option_all' => false, |
| 127 | 127 | 'show_option_none' => false, |
| 128 | 128 | 'class' => '', |
| 129 | - ) ); ?> |
|
| 130 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
| 129 | + )); ?> |
|
| 130 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
| 131 | 131 | </span> |
| 132 | 132 | <span id="wpinv-submit-wrap"> |
| 133 | 133 | <input type="hidden" value="invoices" name="export" /> |
| 134 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
| 134 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
| 135 | 135 | </span> |
| 136 | 136 | </form> |
| 137 | 137 | </div> |
| 138 | 138 | </div> |
| 139 | 139 | |
| 140 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
| 140 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
| 141 | 141 | </div> |
| 142 | 142 | </div> |
| 143 | 143 | </div> |
| 144 | 144 | <?php |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public function export_location( $relative = false ) { |
|
| 147 | + public function export_location($relative = false) { |
|
| 148 | 148 | $upload_dir = wp_upload_dir(); |
| 149 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
| 150 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
| 149 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
| 150 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
| 151 | 151 | |
| 152 | - return trailingslashit( $export_location ); |
|
| 152 | + return trailingslashit($export_location); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | public function check_export_location() { |
| 156 | 156 | try { |
| 157 | - if ( empty( $this->wp_filesystem ) ) { |
|
| 158 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
| 157 | + if (empty($this->wp_filesystem)) { |
|
| 158 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
| 162 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
| 161 | + if (is_wp_error($this->wp_filesystem)) { |
|
| 162 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
| 166 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
| 165 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
| 166 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
| 167 | 167 | |
| 168 | - if ( $is_dir && $is_writeable ) { |
|
| 168 | + if ($is_dir && $is_writeable) { |
|
| 169 | 169 | return true; |
| 170 | - } else if ( $is_dir && !$is_writeable ) { |
|
| 171 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
| 172 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
| 170 | + } else if ($is_dir && !$is_writeable) { |
|
| 171 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
| 172 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | return true; |
| 176 | 176 | } else { |
| 177 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
| 178 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
| 177 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
| 178 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | return true; |
| 182 | 182 | } |
| 183 | - } catch ( Exception $e ) { |
|
| 183 | + } catch (Exception $e) { |
|
| 184 | 184 | return $e->getMessage(); |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -188,130 +188,130 @@ discard block |
||
| 188 | 188 | public function ajax_export() { |
| 189 | 189 | $response = array(); |
| 190 | 190 | $response['success'] = false; |
| 191 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
| 191 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
| 192 | 192 | |
| 193 | - if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) { |
|
| 194 | - wp_send_json( $response ); |
|
| 193 | + if (empty($_POST['data']) || !current_user_can('manage_options')) { |
|
| 194 | + wp_send_json($response); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - parse_str( $_POST['data'], $data ); |
|
| 197 | + parse_str($_POST['data'], $data); |
|
| 198 | 198 | |
| 199 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
| 199 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
| 200 | 200 | |
| 201 | 201 | $_REQUEST = (array)$data; |
| 202 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
| 203 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
| 204 | - wp_send_json( $response ); |
|
| 202 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
| 203 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
| 204 | + wp_send_json($response); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
| 208 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
| 209 | - wp_send_json( $response ); |
|
| 207 | + if (($error = $this->check_export_location(true)) !== true) { |
|
| 208 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
| 209 | + wp_send_json($response); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - $this->set_export_params( $_REQUEST ); |
|
| 212 | + $this->set_export_params($_REQUEST); |
|
| 213 | 213 | |
| 214 | 214 | $return = $this->process_export_step(); |
| 215 | 215 | $done = $this->get_export_status(); |
| 216 | 216 | |
| 217 | - if ( $return ) { |
|
| 217 | + if ($return) { |
|
| 218 | 218 | $this->step += 1; |
| 219 | 219 | |
| 220 | 220 | $response['success'] = true; |
| 221 | 221 | $response['msg'] = ''; |
| 222 | 222 | |
| 223 | - if ( $done >= 100 ) { |
|
| 223 | + if ($done >= 100) { |
|
| 224 | 224 | $this->step = 'done'; |
| 225 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
| 225 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
| 226 | 226 | $new_file = $this->export_dir . $new_filename; |
| 227 | 227 | |
| 228 | - if ( file_exists( $this->file ) ) { |
|
| 229 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
| 228 | + if (file_exists($this->file)) { |
|
| 229 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( file_exists( $new_file ) ) { |
|
| 233 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
| 232 | + if (file_exists($new_file)) { |
|
| 233 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $response['data']['step'] = $this->step; |
| 238 | 238 | $response['data']['done'] = $done; |
| 239 | 239 | } else { |
| 240 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
| 240 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - wp_send_json( $response ); |
|
| 243 | + wp_send_json($response); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - public function set_export_params( $request ) { |
|
| 246 | + public function set_export_params($request) { |
|
| 247 | 247 | $this->empty = false; |
| 248 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
| 249 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
| 248 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
| 249 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
| 250 | 250 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
| 251 | 251 | $this->file = $this->export_dir . $this->filename; |
| 252 | 252 | |
| 253 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
| 253 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | public function get_columns() { |
| 257 | 257 | $columns = array( |
| 258 | - 'id' => __( 'ID', 'invoicing' ), |
|
| 259 | - 'date' => __( 'Date', 'invoicing' ) |
|
| 258 | + 'id' => __('ID', 'invoicing'), |
|
| 259 | + 'date' => __('Date', 'invoicing') |
|
| 260 | 260 | ); |
| 261 | 261 | |
| 262 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
| 262 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | protected function get_export_file() { |
| 266 | 266 | $file = ''; |
| 267 | 267 | |
| 268 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
| 269 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
| 268 | + if ($this->wp_filesystem->exists($this->file)) { |
|
| 269 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
| 270 | 270 | } else { |
| 271 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
| 271 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return $file; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - protected function attach_export_data( $data = '' ) { |
|
| 278 | - $filedata = $this->get_export_file(); |
|
| 279 | - $filedata .= $data; |
|
| 277 | + protected function attach_export_data($data = '') { |
|
| 278 | + $filedata = $this->get_export_file(); |
|
| 279 | + $filedata .= $data; |
|
| 280 | 280 | |
| 281 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
| 281 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
| 282 | 282 | |
| 283 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
| 283 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
| 284 | 284 | $columns = $this->get_columns(); |
| 285 | - $columns = empty( $columns ) ? 0 : 1; |
|
| 285 | + $columns = empty($columns) ? 0 : 1; |
|
| 286 | 286 | |
| 287 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
| 287 | + $this->empty = count($rows) == $columns ? true : false; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | public function print_columns() { |
| 291 | 291 | $column_data = ''; |
| 292 | 292 | $columns = $this->get_columns(); |
| 293 | 293 | $i = 1; |
| 294 | - foreach( $columns as $key => $column ) { |
|
| 295 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
| 296 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
| 294 | + foreach ($columns as $key => $column) { |
|
| 295 | + $column_data .= '"' . addslashes($column) . '"'; |
|
| 296 | + $column_data .= $i == count($columns) ? '' : ','; |
|
| 297 | 297 | $i++; |
| 298 | 298 | } |
| 299 | 299 | $column_data .= "\r\n"; |
| 300 | 300 | |
| 301 | - $this->attach_export_data( $column_data ); |
|
| 301 | + $this->attach_export_data($column_data); |
|
| 302 | 302 | |
| 303 | 303 | return $column_data; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | public function process_export_step() { |
| 307 | - if ( $this->step < 2 ) { |
|
| 308 | - @unlink( $this->file ); |
|
| 307 | + if ($this->step < 2) { |
|
| 308 | + @unlink($this->file); |
|
| 309 | 309 | $this->print_columns(); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | $return = $this->print_rows(); |
| 313 | 313 | |
| 314 | - if ( $return ) { |
|
| 314 | + if ($return) { |
|
| 315 | 315 | return true; |
| 316 | 316 | } else { |
| 317 | 317 | return false; |
@@ -320,23 +320,23 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | public function get_export_status() { |
| 322 | 322 | $status = 100; |
| 323 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
| 323 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | public function get_export_data() { |
| 327 | 327 | $data = array( |
| 328 | 328 | 0 => array( |
| 329 | 329 | 'id' => '', |
| 330 | - 'data' => date( 'F j, Y' ) |
|
| 330 | + 'data' => date('F j, Y') |
|
| 331 | 331 | ), |
| 332 | 332 | 1 => array( |
| 333 | 333 | 'id' => '', |
| 334 | - 'data' => date( 'F j, Y' ) |
|
| 334 | + 'data' => date('F j, Y') |
|
| 335 | 335 | ) |
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
| 339 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
| 338 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
| 339 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
| 340 | 340 | |
| 341 | 341 | return $data; |
| 342 | 342 | } |
@@ -346,20 +346,20 @@ discard block |
||
| 346 | 346 | $data = $this->get_export_data(); |
| 347 | 347 | $columns = $this->get_columns(); |
| 348 | 348 | |
| 349 | - if ( $data ) { |
|
| 350 | - foreach ( $data as $row ) { |
|
| 349 | + if ($data) { |
|
| 350 | + foreach ($data as $row) { |
|
| 351 | 351 | $i = 1; |
| 352 | - foreach ( $row as $key => $column ) { |
|
| 353 | - if ( array_key_exists( $key, $columns ) ) { |
|
| 354 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
| 355 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
| 352 | + foreach ($row as $key => $column) { |
|
| 353 | + if (array_key_exists($key, $columns)) { |
|
| 354 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
| 355 | + $row_data .= $i == count($columns) ? '' : ','; |
|
| 356 | 356 | $i++; |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | $row_data .= "\r\n"; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $this->attach_export_data( $row_data ); |
|
| 362 | + $this->attach_export_data($row_data); |
|
| 363 | 363 | |
| 364 | 364 | return $row_data; |
| 365 | 365 | } |
@@ -368,46 +368,46 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // Export Invoices. |
| 371 | - public function set_invoices_export( $request ) { |
|
| 372 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
| 373 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
| 374 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
| 371 | + public function set_invoices_export($request) { |
|
| 372 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
| 373 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
| 374 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - public function get_invoices_columns( $columns = array() ) { |
|
| 377 | + public function get_invoices_columns($columns = array()) { |
|
| 378 | 378 | $columns = array( |
| 379 | - 'id' => __( 'ID', 'invoicing' ), |
|
| 380 | - 'number' => __( 'Number', 'invoicing' ), |
|
| 381 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 382 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 383 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
| 384 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 385 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 386 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 387 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
| 388 | - 'email' => __( 'Email', 'invoicing' ), |
|
| 389 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
| 390 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
| 391 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 392 | - 'city' => __( 'City', 'invoicing' ), |
|
| 393 | - 'state' => __( 'State', 'invoicing' ), |
|
| 394 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 395 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
| 396 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 397 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 398 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
| 399 | - 'ip' => __( 'IP', 'invoicing' ), |
|
| 400 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
| 401 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
| 402 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
| 403 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
| 404 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
| 379 | + 'id' => __('ID', 'invoicing'), |
|
| 380 | + 'number' => __('Number', 'invoicing'), |
|
| 381 | + 'date' => __('Date', 'invoicing'), |
|
| 382 | + 'amount' => __('Amount', 'invoicing'), |
|
| 383 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
| 384 | + 'status' => __('Status', 'invoicing'), |
|
| 385 | + 'tax' => __('Tax', 'invoicing'), |
|
| 386 | + 'discount' => __('Discount', 'invoicing'), |
|
| 387 | + 'user_id' => __('User ID', 'invoicing'), |
|
| 388 | + 'email' => __('Email', 'invoicing'), |
|
| 389 | + 'first_name' => __('First Name', 'invoicing'), |
|
| 390 | + 'last_name' => __('Last Name', 'invoicing'), |
|
| 391 | + 'address' => __('Address', 'invoicing'), |
|
| 392 | + 'city' => __('City', 'invoicing'), |
|
| 393 | + 'state' => __('State', 'invoicing'), |
|
| 394 | + 'country' => __('Country', 'invoicing'), |
|
| 395 | + 'zip' => __('Zipcode', 'invoicing'), |
|
| 396 | + 'phone' => __('Phone', 'invoicing'), |
|
| 397 | + 'company' => __('Company', 'invoicing'), |
|
| 398 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
| 399 | + 'ip' => __('IP', 'invoicing'), |
|
| 400 | + 'gateway' => __('Gateway', 'invoicing'), |
|
| 401 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
| 402 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
| 403 | + 'currency' => __('Currency', 'invoicing'), |
|
| 404 | + 'due_date' => __('Due Date', 'invoicing'), |
|
| 405 | 405 | ); |
| 406 | 406 | |
| 407 | 407 | return $columns; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - public function get_invoices_data( $response = array() ) { |
|
| 410 | + public function get_invoices_data($response = array()) { |
|
| 411 | 411 | $args = array( |
| 412 | 412 | 'limit' => $this->per_page, |
| 413 | 413 | 'page' => $this->step, |
@@ -415,35 +415,35 @@ discard block |
||
| 415 | 415 | 'orderby' => 'date', |
| 416 | 416 | ); |
| 417 | 417 | |
| 418 | - if ( $this->status != 'any' ) { |
|
| 418 | + if ($this->status != 'any') { |
|
| 419 | 419 | $args['status'] = $this->status; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
| 422 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
| 423 | 423 | $args['date_query'] = array( |
| 424 | 424 | array( |
| 425 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
| 426 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
| 425 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
| 426 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
| 427 | 427 | 'inclusive' => true |
| 428 | 428 | ) |
| 429 | 429 | ); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $invoices = wpinv_get_invoices( $args ); |
|
| 432 | + $invoices = wpinv_get_invoices($args); |
|
| 433 | 433 | |
| 434 | 434 | $data = array(); |
| 435 | 435 | |
| 436 | - if ( !empty( $invoices ) ) { |
|
| 437 | - foreach ( $invoices as $invoice ) { |
|
| 436 | + if (!empty($invoices)) { |
|
| 437 | + foreach ($invoices as $invoice) { |
|
| 438 | 438 | $row = array( |
| 439 | 439 | 'id' => $invoice->ID, |
| 440 | 440 | 'number' => $invoice->get_number(), |
| 441 | - 'date' => $invoice->get_invoice_date( false ), |
|
| 442 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
| 443 | - 'status_nicename' => $invoice->get_status( true ), |
|
| 441 | + 'date' => $invoice->get_invoice_date(false), |
|
| 442 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
| 443 | + 'status_nicename' => $invoice->get_status(true), |
|
| 444 | 444 | 'status' => $invoice->get_status(), |
| 445 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
| 446 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
| 445 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
| 446 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
| 447 | 447 | 'user_id' => $invoice->get_user_id(), |
| 448 | 448 | 'email' => $invoice->get_email(), |
| 449 | 449 | 'first_name' => $invoice->get_first_name(), |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | 'due_date' => $invoice->needs_payment() ? $invoice->get_due_date() : '', |
| 465 | 465 | ); |
| 466 | 466 | |
| 467 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
| 467 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | return $data; |
@@ -480,29 +480,29 @@ discard block |
||
| 480 | 480 | 'return' => 'ids', |
| 481 | 481 | ); |
| 482 | 482 | |
| 483 | - if ( $this->status != 'any' ) { |
|
| 483 | + if ($this->status != 'any') { |
|
| 484 | 484 | $args['status'] = $this->status; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
| 487 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
| 488 | 488 | $args['date_query'] = array( |
| 489 | 489 | array( |
| 490 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
| 491 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
| 490 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
| 491 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
| 492 | 492 | 'inclusive' => true |
| 493 | 493 | ) |
| 494 | 494 | ); |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - $invoices = wpinv_get_invoices( $args ); |
|
| 498 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
| 497 | + $invoices = wpinv_get_invoices($args); |
|
| 498 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
| 499 | 499 | $status = 100; |
| 500 | 500 | |
| 501 | - if ( $total > 0 ) { |
|
| 502 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
| 501 | + if ($total > 0) { |
|
| 502 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - if ( $status > 100 ) { |
|
| 505 | + if ($status > 100) { |
|
| 506 | 506 | $status = 100; |
| 507 | 507 | } |
| 508 | 508 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -14,73 +14,73 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function init() { |
| 17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
| 17 | + do_action('wpinv_class_notes_init', $this); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function includes() { |
| 21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
| 21 | + do_action('wpinv_class_notes_includes', $this); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function actions() { |
| 25 | 25 | // Secure inovice notes |
| 26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
| 27 | 27 | |
| 28 | 28 | // Count comments |
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
| 29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
| 30 | 30 | |
| 31 | 31 | // Delete comments count cache whenever there is a new comment or a comment status changes |
| 32 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 33 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 32 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
| 33 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
| 34 | 34 | |
| 35 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
| 35 | + do_action('wpinv_class_notes_actions', $this); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function set_invoice_note_type( $query ) { |
|
| 39 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 38 | + public function set_invoice_note_type($query) { |
|
| 39 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 40 | 40 | |
| 41 | - if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) { |
|
| 41 | + if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) { |
|
| 42 | 42 | $query->query_vars['type__in'] = $this->comment_type; |
| 43 | 43 | $query->query_vars['type__not_in'] = ''; |
| 44 | 44 | } else { |
| 45 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
| 46 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
| 47 | - $key = array_search( $this->comment_type, $type_in ); |
|
| 48 | - unset( $query->query_vars['type__in'][$key] ); |
|
| 49 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
| 45 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
| 46 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
| 47 | + $key = array_search($this->comment_type, $type_in); |
|
| 48 | + unset($query->query_vars['type__in'][$key]); |
|
| 49 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
| 50 | 50 | $query->query_vars['type__in'] = ''; |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
| 55 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
| 54 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
| 55 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
| 56 | 56 | $query->query_vars['type__not_in'][] = $this->comment_type; |
| 57 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
| 57 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
| 58 | 58 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
| 59 | 59 | $query->query_vars['type__not_in'][] = $this->comment_type; |
| 60 | 60 | } |
| 61 | 61 | } else { |
| 62 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
| 62 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | return $query; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 69 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 70 | 70 | $args = array( |
| 71 | 71 | 'post_id' => $invoice_id, |
| 72 | 72 | 'orderby' => 'comment_ID', |
| 73 | 73 | 'order' => 'ASC', |
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | - if ( $type == 'customer' ) { |
|
| 76 | + if ($type == 'customer') { |
|
| 77 | 77 | $args['meta_key'] = '_wpi_customer_note'; |
| 78 | 78 | $args['meta_value'] = 1; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 81 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
| 82 | 82 | |
| 83 | - return get_comments( $args ); |
|
| 83 | + return get_comments($args); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | 93 | public function delete_comments_count_cache() { |
| 94 | - delete_transient( 'wpinv_count_comments' ); |
|
| 94 | + delete_transient('wpinv_count_comments'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * @param int $post_id Post ID. |
| 103 | 103 | * @return object |
| 104 | 104 | */ |
| 105 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 105 | + public function wp_count_comments($stats, $post_id) { |
|
| 106 | 106 | global $wpdb; |
| 107 | 107 | |
| 108 | - if ( 0 === $post_id ) { |
|
| 109 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
| 108 | + if (0 === $post_id) { |
|
| 109 | + $stats = get_transient('wpinv_count_comments'); |
|
| 110 | 110 | |
| 111 | - if ( ! $stats ) { |
|
| 111 | + if (!$stats) { |
|
| 112 | 112 | $stats = array(); |
| 113 | 113 | |
| 114 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
| 114 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
| 115 | 115 | |
| 116 | 116 | $total = 0; |
| 117 | 117 | $approved = array( |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | 'post-trashed' => 'post-trashed', |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - foreach ( (array) $count as $row ) { |
|
| 125 | + foreach ((array)$count as $row) { |
|
| 126 | 126 | // Do not count post-trashed toward totals. |
| 127 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
| 127 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
| 128 | 128 | $total += $row['num_comments']; |
| 129 | 129 | } |
| 130 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 131 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 130 | + if (isset($approved[$row['comment_approved']])) { |
|
| 131 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $stats['total_comments'] = $total; |
| 136 | 136 | $stats['all'] = $total; |
| 137 | - foreach ( $approved as $key ) { |
|
| 138 | - if ( empty( $stats[ $key ] ) ) { |
|
| 139 | - $stats[ $key ] = 0; |
|
| 137 | + foreach ($approved as $key) { |
|
| 138 | + if (empty($stats[$key])) { |
|
| 139 | + $stats[$key] = 0; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $stats = (object) $stats; |
|
| 144 | - set_transient( 'wpinv_count_comments', $stats ); |
|
| 143 | + $stats = (object)$stats; |
|
| 144 | + set_transient('wpinv_count_comments', $stats); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 6 | - if( empty( $field ) || empty( $value ) ) { |
|
| 5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 6 | + if (empty($field) || empty($value)) { |
|
| 7 | 7 | return false; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $posts = array(); |
| 11 | 11 | |
| 12 | - switch( strtolower( $field ) ) { |
|
| 12 | + switch (strtolower($field)) { |
|
| 13 | 13 | case 'id': |
| 14 | - $item = new WPInv_Item( $value ); |
|
| 14 | + $item = new WPInv_Item($value); |
|
| 15 | 15 | |
| 16 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
| 16 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
| 17 | 17 | return $item; |
| 18 | 18 | } |
| 19 | 19 | return false; |
@@ -22,16 +22,16 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | case 'slug': |
| 24 | 24 | case 'name': |
| 25 | - $posts = get_posts( array( |
|
| 25 | + $posts = get_posts(array( |
|
| 26 | 26 | 'post_type' => 'wpi_item', |
| 27 | 27 | 'name' => $value, |
| 28 | 28 | 'posts_per_page' => 1, |
| 29 | 29 | 'post_status' => 'any' |
| 30 | - ) ); |
|
| 30 | + )); |
|
| 31 | 31 | |
| 32 | 32 | break; |
| 33 | 33 | case 'custom_id': |
| 34 | - if ( empty( $value ) || empty( $type ) ) { |
|
| 34 | + if (empty($value) || empty($type)) { |
|
| 35 | 35 | return false; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | 'post_status' => 'any', |
| 52 | 52 | 'orderby' => 'ID', |
| 53 | 53 | 'order' => 'ASC', |
| 54 | - 'meta_query' => array( $meta_query ) |
|
| 54 | + 'meta_query' => array($meta_query) |
|
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - $posts = get_posts( $args ); |
|
| 57 | + $posts = get_posts($args); |
|
| 58 | 58 | |
| 59 | 59 | break; |
| 60 | 60 | |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ( !empty( $posts[0] ) ) { |
|
| 66 | - $item = new WPInv_Item( $posts[0]->ID ); |
|
| 65 | + if (!empty($posts[0])) { |
|
| 66 | + $item = new WPInv_Item($posts[0]->ID); |
|
| 67 | 67 | |
| 68 | - if ( !empty( $item ) && $item->post_type == 'wpi_item' ) { |
|
| 68 | + if (!empty($item) && $item->post_type == 'wpi_item') { |
|
| 69 | 69 | return $item; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | -function wpinv_get_item( $item = 0 ) { |
|
| 77 | - if ( is_numeric( $item ) ) { |
|
| 78 | - $item = get_post( $item ); |
|
| 79 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
| 76 | +function wpinv_get_item($item = 0) { |
|
| 77 | + if (is_numeric($item)) { |
|
| 78 | + $item = get_post($item); |
|
| 79 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
| 80 | 80 | return null; |
| 81 | 81 | return $item; |
| 82 | 82 | } |
@@ -89,150 +89,150 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $item = get_posts($args); |
| 91 | 91 | |
| 92 | - if ( $item ) { |
|
| 92 | + if ($item) { |
|
| 93 | 93 | return $item[0]; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | return null; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 100 | - if( empty( $item_id ) ) { |
|
| 99 | +function wpinv_is_free_item($item_id = 0) { |
|
| 100 | + if (empty($item_id)) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $item = new WPInv_Item( $item_id ); |
|
| 104 | + $item = new WPInv_Item($item_id); |
|
| 105 | 105 | |
| 106 | 106 | return $item->is_free(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 110 | - if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) { |
|
| 109 | +function wpinv_item_is_editable($item = 0) { |
|
| 110 | + if (!empty($item) && is_a($item, 'WP_Post')) { |
|
| 111 | 111 | $item = $item->ID; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if ( empty( $item ) ) { |
|
| 114 | + if (empty($item)) { |
|
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $item = new WPInv_Item( $item ); |
|
| 118 | + $item = new WPInv_Item($item); |
|
| 119 | 119 | |
| 120 | - return (bool) $item->is_editable(); |
|
| 120 | + return (bool)$item->is_editable(); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 124 | - if( empty( $item_id ) ) { |
|
| 123 | +function wpinv_get_item_price($item_id = 0) { |
|
| 124 | + if (empty($item_id)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $item = new WPInv_Item( $item_id ); |
|
| 128 | + $item = new WPInv_Item($item_id); |
|
| 129 | 129 | |
| 130 | 130 | return $item->get_price(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
| 134 | - if( empty( $item_id ) ) { |
|
| 133 | +function wpinv_is_recurring_item($item_id = 0) { |
|
| 134 | + if (empty($item_id)) { |
|
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $item = new WPInv_Item( $item_id ); |
|
| 138 | + $item = new WPInv_Item($item_id); |
|
| 139 | 139 | |
| 140 | 140 | return $item->is_recurring(); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 144 | - if( empty( $item_id ) ) { |
|
| 143 | +function wpinv_item_price($item_id = 0) { |
|
| 144 | + if (empty($item_id)) { |
|
| 145 | 145 | return false; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $price = wpinv_get_item_price( $item_id ); |
|
| 149 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 148 | + $price = wpinv_get_item_price($item_id); |
|
| 149 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 150 | 150 | |
| 151 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 151 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 155 | - if ( empty( $item_id ) ) { |
|
| 154 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 155 | + if (empty($item_id)) { |
|
| 156 | 156 | $item_id = get_the_ID(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $price = wpinv_item_price( $item_id ); |
|
| 159 | + $price = wpinv_item_price($item_id); |
|
| 160 | 160 | |
| 161 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
| 161 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
| 162 | 162 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
| 163 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
| 163 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
| 164 | 164 | |
| 165 | - if ( $echo ) { |
|
| 165 | + if ($echo) { |
|
| 166 | 166 | echo $formatted_price; |
| 167 | 167 | } else { |
| 168 | 168 | return $formatted_price; |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 173 | - if ( is_null( $amount_override ) ) { |
|
| 174 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 172 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 173 | + if (is_null($amount_override)) { |
|
| 174 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 175 | 175 | } else { |
| 176 | 176 | $original_price = $amount_override; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $price = $original_price; |
| 180 | 180 | |
| 181 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 181 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 185 | - if( empty( $item_id ) ) { |
|
| 184 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 185 | + if (empty($item_id)) { |
|
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - $item = new WPInv_Item( $item_id ); |
|
| 189 | + $item = new WPInv_Item($item_id); |
|
| 190 | 190 | |
| 191 | 191 | return $item->get_custom_singular_name(); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function wpinv_get_item_types() { |
| 195 | 195 | $item_types = array( |
| 196 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 197 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 196 | + 'custom' => __('Standard', 'invoicing'), |
|
| 197 | + 'fee' => __('Fee', 'invoicing'), |
|
| 198 | 198 | ); |
| 199 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 199 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function wpinv_item_types() { |
| 203 | 203 | $item_types = wpinv_get_item_types(); |
| 204 | 204 | |
| 205 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 205 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | -function wpinv_get_item_type( $item_id ) { |
|
| 209 | - if( empty( $item_id ) ) { |
|
| 208 | +function wpinv_get_item_type($item_id) { |
|
| 209 | + if (empty($item_id)) { |
|
| 210 | 210 | return false; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $item = new WPInv_Item( $item_id ); |
|
| 213 | + $item = new WPInv_Item($item_id); |
|
| 214 | 214 | |
| 215 | 215 | return $item->get_type(); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function wpinv_item_type( $item_id ) { |
|
| 218 | +function wpinv_item_type($item_id) { |
|
| 219 | 219 | $item_types = wpinv_get_item_types(); |
| 220 | 220 | |
| 221 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 221 | + $item_type = wpinv_get_item_type($item_id); |
|
| 222 | 222 | |
| 223 | - if ( empty( $item_type ) ) { |
|
| 223 | + if (empty($item_type)) { |
|
| 224 | 224 | $item_type = '-'; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 227 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 228 | 228 | |
| 229 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 229 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
| 232 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
| 233 | 233 | global $wpinv_logs; |
| 234 | 234 | |
| 235 | - if ( empty( $wpinv_logs ) ) { |
|
| 235 | + if (empty($wpinv_logs)) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | 'log_type' => 'wpi_item' |
| 242 | 242 | ); |
| 243 | 243 | |
| 244 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
| 244 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
| 245 | 245 | |
| 246 | 246 | $log_meta = array( |
| 247 | 247 | 'user_info' => $user_info, |
@@ -251,253 +251,253 @@ discard block |
||
| 251 | 251 | 'invoice_id'=> $invoice_id, |
| 252 | 252 | ); |
| 253 | 253 | |
| 254 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
| 254 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
| 258 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 257 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
| 258 | + if ('wpi_item' !== get_post_type($item_id)) |
|
| 259 | 259 | return; |
| 260 | 260 | |
| 261 | 261 | global $wpinv_logs; |
| 262 | 262 | |
| 263 | - if ( empty( $wpinv_logs ) ) { |
|
| 263 | + if (empty($wpinv_logs)) { |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Remove all log entries related to this item |
| 268 | - $wpinv_logs->delete_logs( $item_id ); |
|
| 268 | + $wpinv_logs->delete_logs($item_id); |
|
| 269 | 269 | } |
| 270 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
| 270 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
| 271 | 271 | |
| 272 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 273 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 272 | +function wpinv_get_random_item($post_ids = true) { |
|
| 273 | + wpinv_get_random_items(1, $post_ids); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 277 | - if ( $post_ids ) { |
|
| 278 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 276 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 277 | + if ($post_ids) { |
|
| 278 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 279 | 279 | } else { |
| 280 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 280 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 283 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 284 | 284 | |
| 285 | - return get_posts( $args ); |
|
| 285 | + return get_posts($args); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | -function wpinv_get_item_token( $url = '' ) { |
|
| 288 | +function wpinv_get_item_token($url = '') { |
|
| 289 | 289 | $args = array(); |
| 290 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
| 291 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
| 290 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
| 291 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
| 292 | 292 | |
| 293 | - $parts = parse_url( $url ); |
|
| 293 | + $parts = parse_url($url); |
|
| 294 | 294 | $options = array(); |
| 295 | 295 | |
| 296 | - if ( isset( $parts['query'] ) ) { |
|
| 297 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 296 | + if (isset($parts['query'])) { |
|
| 297 | + wp_parse_str($parts['query'], $query_args); |
|
| 298 | 298 | |
| 299 | - if ( ! empty( $query_args['o'] ) ) { |
|
| 300 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
| 299 | + if (!empty($query_args['o'])) { |
|
| 300 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
| 301 | 301 | |
| 302 | - if ( in_array( 'ip', $options ) ) { |
|
| 302 | + if (in_array('ip', $options)) { |
|
| 303 | 303 | $args['ip'] = wpinv_get_ip(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( in_array( 'ua', $options ) ) { |
|
| 306 | + if (in_array('ua', $options)) { |
|
| 307 | 307 | $ua = wpinv_get_user_agent(); |
| 308 | - $args['user_agent'] = rawurlencode( $ua ); |
|
| 308 | + $args['user_agent'] = rawurlencode($ua); |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
| 313 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
| 314 | 314 | |
| 315 | 315 | $args['secret'] = $secret; |
| 316 | 316 | $args['token'] = false; |
| 317 | 317 | |
| 318 | - $url = add_query_arg( $args, $url ); |
|
| 319 | - $parts = parse_url( $url ); |
|
| 318 | + $url = add_query_arg($args, $url); |
|
| 319 | + $parts = parse_url($url); |
|
| 320 | 320 | |
| 321 | - if ( ! isset( $parts['path'] ) ) { |
|
| 321 | + if (!isset($parts['path'])) { |
|
| 322 | 322 | $parts['path'] = ''; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
| 325 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
| 326 | 326 | |
| 327 | 327 | return $token; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | -function wpinv_validate_url_token( $url = '' ) { |
|
| 330 | +function wpinv_validate_url_token($url = '') { |
|
| 331 | 331 | $ret = false; |
| 332 | - $parts = parse_url( $url ); |
|
| 332 | + $parts = parse_url($url); |
|
| 333 | 333 | |
| 334 | - if ( isset( $parts['query'] ) ) { |
|
| 335 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 334 | + if (isset($parts['query'])) { |
|
| 335 | + wp_parse_str($parts['query'], $query_args); |
|
| 336 | 336 | |
| 337 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
| 337 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
| 338 | 338 | 'item', |
| 339 | 339 | 'ttl', |
| 340 | 340 | 'token' |
| 341 | - ) ); |
|
| 341 | + )); |
|
| 342 | 342 | |
| 343 | 343 | $remove = array(); |
| 344 | 344 | |
| 345 | - foreach( $query_args as $key => $value ) { |
|
| 346 | - if( false === in_array( $key, $allowed ) ) { |
|
| 345 | + foreach ($query_args as $key => $value) { |
|
| 346 | + if (false === in_array($key, $allowed)) { |
|
| 347 | 347 | $remove[] = $key; |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if( ! empty( $remove ) ) { |
|
| 352 | - $url = remove_query_arg( $remove, $url ); |
|
| 351 | + if (!empty($remove)) { |
|
| 352 | + $url = remove_query_arg($remove, $url); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
| 356 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 355 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
| 356 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
| 359 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
| 360 | 360 | $ret = true; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
| 365 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
| 368 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
| 369 | 369 | $cart_items = wpinv_get_cart_contents(); |
| 370 | 370 | |
| 371 | 371 | $ret = false; |
| 372 | 372 | |
| 373 | - if ( is_array( $cart_items ) ) { |
|
| 374 | - foreach ( $cart_items as $item ) { |
|
| 375 | - if ( $item['id'] == $item_id ) { |
|
| 373 | + if (is_array($cart_items)) { |
|
| 374 | + foreach ($cart_items as $item) { |
|
| 375 | + if ($item['id'] == $item_id) { |
|
| 376 | 376 | $ret = true; |
| 377 | 377 | break; |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
| 382 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
| 385 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
| 386 | 386 | $tax = 0; |
| 387 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 388 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
| 389 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
| 387 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
| 388 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
| 389 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
| 390 | 390 | |
| 391 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
| 391 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
| 394 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | -function wpinv_cart_item_price( $item ) { |
|
| 397 | +function wpinv_cart_item_price($item) { |
|
| 398 | 398 | $use_taxes = wpinv_use_taxes(); |
| 399 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
| 400 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
| 401 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
| 402 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
| 403 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 404 | - |
|
| 405 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 406 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
| 399 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
| 400 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
| 401 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
| 402 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
| 403 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 404 | + |
|
| 405 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
| 406 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
| 407 | 407 | $price += $tax; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
| 410 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
| 411 | 411 | $price -= $tax; |
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 415 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 416 | 416 | |
| 417 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
| 417 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | -function wpinv_cart_item_subtotal( $item ) { |
|
| 421 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
| 422 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
| 420 | +function wpinv_cart_item_subtotal($item) { |
|
| 421 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
| 422 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
| 423 | 423 | |
| 424 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
| 424 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | -function wpinv_cart_item_tax( $item ) { |
|
| 427 | +function wpinv_cart_item_tax($item) { |
|
| 428 | 428 | $tax = ''; |
| 429 | 429 | $tax_rate = ''; |
| 430 | 430 | |
| 431 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
| 432 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 433 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
| 434 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 431 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
| 432 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 433 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
| 434 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 435 | 435 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - $tax = $tax . $tax_rate; |
|
| 438 | + $tax = $tax . $tax_rate; |
|
| 439 | 439 | |
| 440 | - if ( $tax === '' ) { |
|
| 440 | + if ($tax === '') { |
|
| 441 | 441 | $tax = 0; // Zero tax |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
| 444 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
| 447 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
| 448 | 448 | $price = 0; |
| 449 | 449 | |
| 450 | 450 | // Set custom price |
| 451 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
| 451 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
| 452 | 452 | $price = $cart_item['custom_price']; |
| 453 | 453 | } else { |
| 454 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
| 454 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
| 455 | 455 | |
| 456 | - if ( $variable_prices ) { |
|
| 457 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
| 456 | + if ($variable_prices) { |
|
| 457 | + $prices = wpinv_get_variable_prices($item_id); |
|
| 458 | 458 | |
| 459 | - if ( $prices ) { |
|
| 460 | - if( ! empty( $options ) ) { |
|
| 461 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
| 459 | + if ($prices) { |
|
| 460 | + if (!empty($options)) { |
|
| 461 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
| 462 | 462 | } else { |
| 463 | 463 | $price = false; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if( ! $variable_prices || false === $price ) { |
|
| 468 | + if (!$variable_prices || false === $price) { |
|
| 469 | 469 | // Get the standard Item price if not using variable prices |
| 470 | - $price = wpinv_get_item_price( $item_id ); |
|
| 470 | + $price = wpinv_get_item_price($item_id); |
|
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
| 475 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
| 474 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
| 475 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
| 478 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
| 482 | - if( isset( $item['item_number'] ) ) { |
|
| 483 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
| 481 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
| 482 | + if (isset($item['item_number'])) { |
|
| 483 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
| 484 | 484 | } else { |
| 485 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
| 485 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
| 486 | 486 | } |
| 487 | 487 | return $price_id; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
| 491 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
| 492 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
| 493 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
| 494 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
| 490 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
| 491 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
| 492 | + $prices = wpinv_get_variable_prices($item['id']); |
|
| 493 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
| 494 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
| 498 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
| 497 | +function wpinv_get_cart_item_name($item = array()) { |
|
| 498 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
| 499 | 499 | |
| 500 | - if ( empty( $item_title ) ) { |
|
| 500 | + if (empty($item_title)) { |
|
| 501 | 501 | $item_title = $item['id']; |
| 502 | 502 | } |
| 503 | 503 | |
@@ -507,23 +507,23 @@ discard block |
||
| 507 | 507 | } |
| 508 | 508 | */ |
| 509 | 509 | |
| 510 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
| 510 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
| 513 | +function wpinv_has_variable_prices($item_id = 0) { |
|
| 514 | 514 | return false; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
| 517 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
| 518 | 518 | $cart_items = wpinv_get_cart_contents(); |
| 519 | 519 | |
| 520 | - if ( !is_array( $cart_items ) ) { |
|
| 520 | + if (!is_array($cart_items)) { |
|
| 521 | 521 | return false; // Empty cart |
| 522 | 522 | } else { |
| 523 | - foreach ( $cart_items as $position => $item ) { |
|
| 524 | - if ( $item['id'] == $item_id ) { |
|
| 525 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
| 526 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
| 523 | + foreach ($cart_items as $position => $item) { |
|
| 524 | + if ($item['id'] == $item_id) { |
|
| 525 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
| 526 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
| 527 | 527 | return $position; |
| 528 | 528 | } |
| 529 | 529 | } else { |
@@ -536,80 +536,80 @@ discard block |
||
| 536 | 536 | return false; // Not found |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | -function wpinv_get_cart_item_quantity( $item ) { |
|
| 540 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 541 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 539 | +function wpinv_get_cart_item_quantity($item) { |
|
| 540 | + if (wpinv_item_quantities_enabled()) { |
|
| 541 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 542 | 542 | } else { |
| 543 | 543 | $quantity = 1; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - if ( $quantity < 1 ) { |
|
| 546 | + if ($quantity < 1) { |
|
| 547 | 547 | $quantity = 1; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
| 550 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 554 | - if ( empty( $item ) ) { |
|
| 553 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 554 | + if (empty($item)) { |
|
| 555 | 555 | return NULL; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - if ( is_int( $item ) ) { |
|
| 559 | - $item = new WPInv_Item( $item ); |
|
| 558 | + if (is_int($item)) { |
|
| 559 | + $item = new WPInv_Item($item); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 562 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 563 | 563 | return NULL; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 566 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 567 | 567 | |
| 568 | - if ( !$html && $suffix ) { |
|
| 569 | - $suffix = strip_tags( $suffix ); |
|
| 568 | + if (!$html && $suffix) { |
|
| 569 | + $suffix = strip_tags($suffix); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 572 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 576 | - if ( empty( $item ) ) { |
|
| 575 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 576 | + if (empty($item)) { |
|
| 577 | 577 | return NULL; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if ( is_int( $item ) ) { |
|
| 581 | - $item = new WPInv_Item( $item ); |
|
| 580 | + if (is_int($item)) { |
|
| 581 | + $item = new WPInv_Item($item); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 584 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 585 | 585 | return NULL; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
| 588 | + do_action('wpinv_pre_delete_item', $item); |
|
| 589 | 589 | |
| 590 | - wp_delete_post( $item->ID, $force_delete ); |
|
| 590 | + wp_delete_post($item->ID, $force_delete); |
|
| 591 | 591 | |
| 592 | - do_action( 'wpinv_post_delete_item', $item ); |
|
| 592 | + do_action('wpinv_post_delete_item', $item); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | -function wpinv_can_delete_item( $post_id ) { |
|
| 596 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
| 595 | +function wpinv_can_delete_item($post_id) { |
|
| 596 | + $return = current_user_can('manage_options') ? true : false; |
|
| 597 | 597 | |
| 598 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
| 598 | + if ($return && wpinv_item_in_use($post_id)) { |
|
| 599 | 599 | $return = false; // Don't delete item already use in invoices. |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
| 602 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | function wpinv_admin_action_delete() { |
| 606 | 606 | $screen = get_current_screen(); |
| 607 | 607 | |
| 608 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
| 608 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
| 609 | 609 | $post_ids = array(); |
| 610 | 610 | |
| 611 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
| 612 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
| 611 | + foreach ($_REQUEST['post'] as $post_id) { |
|
| 612 | + if (!wpinv_can_delete_item($post_id)) { |
|
| 613 | 613 | continue; |
| 614 | 614 | } |
| 615 | 615 | |
@@ -619,86 +619,86 @@ discard block |
||
| 619 | 619 | $_REQUEST['post'] = $post_ids; |
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
| 623 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
| 622 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
| 623 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
| 624 | 624 | |
| 625 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
| 626 | - if ( $post->post_type == 'wpi_item' ) { |
|
| 627 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
| 625 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
| 626 | + if ($post->post_type == 'wpi_item') { |
|
| 627 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
| 628 | 628 | return true; |
| 629 | 629 | } |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | return $check; |
| 633 | 633 | } |
| 634 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
| 634 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
| 635 | 635 | |
| 636 | -function wpinv_item_in_use( $item_id ) { |
|
| 636 | +function wpinv_item_in_use($item_id) { |
|
| 637 | 637 | global $wpdb, $wpi_items_in_use; |
| 638 | 638 | |
| 639 | - if ( !$item_id > 0 ) { |
|
| 639 | + if (!$item_id > 0) { |
|
| 640 | 640 | return false; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if ( !empty( $wpi_items_in_use ) ) { |
|
| 644 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
| 643 | + if (!empty($wpi_items_in_use)) { |
|
| 644 | + if (isset($wpi_items_in_use[$item_id])) { |
|
| 645 | 645 | return $wpi_items_in_use[$item_id]; |
| 646 | 646 | } |
| 647 | 647 | } else { |
| 648 | 648 | $wpi_items_in_use = array(); |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - $statuses = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
| 651 | + $statuses = array_keys(wpinv_get_invoice_statuses(true)); |
|
| 652 | 652 | |
| 653 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 654 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
| 653 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 654 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
| 655 | 655 | |
| 656 | 656 | $wpi_items_in_use[$item_id] = $in_use; |
| 657 | 657 | |
| 658 | 658 | return $in_use; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
| 661 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
| 662 | 662 | // Set some defaults |
| 663 | 663 | $defaults = array( |
| 664 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 665 | - 'title' => '', // Required. Item title. |
|
| 666 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 667 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 668 | - 'status' => 'pending', // Optional. pending, publish |
|
| 669 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 670 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 671 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 672 | - 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 673 | - 'excerpt' => '', // Optional. Item short description |
|
| 664 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 665 | + 'title' => '', // Required. Item title. |
|
| 666 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 667 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 668 | + 'status' => 'pending', // Optional. pending, publish |
|
| 669 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 670 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 671 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 672 | + 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 673 | + 'excerpt' => '', // Optional. Item short description |
|
| 674 | 674 | /* Recurring item fields */ |
| 675 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 676 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 677 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 678 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 679 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 680 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 681 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
| 675 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 676 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 677 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 678 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 679 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 680 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 681 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
| 682 | 682 | ); |
| 683 | 683 | |
| 684 | - $data = wp_parse_args( $args, $defaults ); |
|
| 684 | + $data = wp_parse_args($args, $defaults); |
|
| 685 | 685 | |
| 686 | - if ( empty( $data['type'] ) ) { |
|
| 686 | + if (empty($data['type'])) { |
|
| 687 | 687 | $data['type'] = 'custom'; |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - if ( !empty( $data['custom_id'] ) ) { |
|
| 691 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
| 690 | + if (!empty($data['custom_id'])) { |
|
| 691 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
| 692 | 692 | } else { |
| 693 | 693 | $item = NULL; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - if ( !empty( $item ) ) { |
|
| 697 | - if ( $force_update ) { |
|
| 698 | - if ( empty( $args['ID'] ) ) { |
|
| 696 | + if (!empty($item)) { |
|
| 697 | + if ($force_update) { |
|
| 698 | + if (empty($args['ID'])) { |
|
| 699 | 699 | $args['ID'] = $item->ID; |
| 700 | 700 | } |
| 701 | - return wpinv_update_item( $args, $wp_error ); |
|
| 701 | + return wpinv_update_item($args, $wp_error); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | return $item; |
@@ -709,19 +709,19 @@ discard block |
||
| 709 | 709 | $meta['custom_id'] = $data['custom_id']; |
| 710 | 710 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
| 711 | 711 | $meta['custom_name'] = $data['custom_name']; |
| 712 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
| 712 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
| 713 | 713 | $meta['editable'] = (int)$data['editable']; |
| 714 | 714 | $meta['vat_rule'] = $data['vat_rule']; |
| 715 | 715 | $meta['vat_class'] = '_standard'; |
| 716 | 716 | |
| 717 | - if ( !empty( $data['is_recurring'] ) ) { |
|
| 717 | + if (!empty($data['is_recurring'])) { |
|
| 718 | 718 | $meta['is_recurring'] = $data['is_recurring']; |
| 719 | 719 | $meta['recurring_period'] = $data['recurring_period']; |
| 720 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
| 721 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
| 720 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
| 721 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
| 722 | 722 | $meta['free_trial'] = $data['free_trial']; |
| 723 | 723 | $meta['trial_period'] = $data['trial_period']; |
| 724 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
| 724 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
| 725 | 725 | } else { |
| 726 | 726 | $meta['is_recurring'] = 0; |
| 727 | 727 | $meta['recurring_period'] = ''; |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | $meta['trial_interval'] = ''; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | - $post_data = array( |
|
| 735 | + $post_data = array( |
|
| 736 | 736 | 'post_title' => $data['title'], |
| 737 | 737 | 'post_excerpt' => $data['excerpt'], |
| 738 | 738 | 'post_status' => $data['status'], |
@@ -740,86 +740,86 @@ discard block |
||
| 740 | 740 | ); |
| 741 | 741 | |
| 742 | 742 | $item = new WPInv_Item(); |
| 743 | - $return = $item->create( $post_data, $wp_error ); |
|
| 743 | + $return = $item->create($post_data, $wp_error); |
|
| 744 | 744 | |
| 745 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
| 745 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
| 746 | 746 | return $item; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
| 749 | + if ($wp_error && is_wp_error($return)) { |
|
| 750 | 750 | return $return; |
| 751 | 751 | } |
| 752 | 752 | return 0; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 756 | - $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL; |
|
| 755 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 756 | + $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL; |
|
| 757 | 757 | |
| 758 | - if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) { |
|
| 759 | - if ( $wp_error ) { |
|
| 760 | - return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) ); |
|
| 758 | + if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) { |
|
| 759 | + if ($wp_error) { |
|
| 760 | + return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing')); |
|
| 761 | 761 | } |
| 762 | 762 | return 0; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - if ( !empty( $args['custom_id'] ) ) { |
|
| 766 | - $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) ); |
|
| 765 | + if (!empty($args['custom_id'])) { |
|
| 766 | + $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type)); |
|
| 767 | 767 | |
| 768 | - if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) { |
|
| 769 | - if ( $wp_error ) { |
|
| 770 | - return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) ); |
|
| 768 | + if (!empty($item_exists) && $item_exists->ID != $args['ID']) { |
|
| 769 | + if ($wp_error) { |
|
| 770 | + return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing')); |
|
| 771 | 771 | } |
| 772 | 772 | return 0; |
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' ); |
|
| 776 | + $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval'); |
|
| 777 | 777 | |
| 778 | 778 | $post_data = array(); |
| 779 | - if ( isset( $args['title'] ) ) { |
|
| 779 | + if (isset($args['title'])) { |
|
| 780 | 780 | $post_data['post_title'] = $args['title']; |
| 781 | 781 | } |
| 782 | - if ( isset( $args['excerpt'] ) ) { |
|
| 782 | + if (isset($args['excerpt'])) { |
|
| 783 | 783 | $post_data['post_excerpt'] = $args['excerpt']; |
| 784 | 784 | } |
| 785 | - if ( isset( $args['status'] ) ) { |
|
| 785 | + if (isset($args['status'])) { |
|
| 786 | 786 | $post_data['post_status'] = $args['status']; |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | - foreach ( $meta_fields as $meta_field ) { |
|
| 790 | - if ( isset( $args[ $meta_field ] ) ) { |
|
| 791 | - $value = $args[ $meta_field ]; |
|
| 789 | + foreach ($meta_fields as $meta_field) { |
|
| 790 | + if (isset($args[$meta_field])) { |
|
| 791 | + $value = $args[$meta_field]; |
|
| 792 | 792 | |
| 793 | - switch ( $meta_field ) { |
|
| 793 | + switch ($meta_field) { |
|
| 794 | 794 | case 'price': |
| 795 | - $value = wpinv_round_amount( $value ); |
|
| 795 | + $value = wpinv_round_amount($value); |
|
| 796 | 796 | break; |
| 797 | 797 | case 'recurring_interval': |
| 798 | 798 | case 'recurring_limit': |
| 799 | 799 | case 'trial_interval': |
| 800 | - $value = absint( $value ); |
|
| 800 | + $value = absint($value); |
|
| 801 | 801 | break; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - $post_data['meta'][ $meta_field ] = $value; |
|
| 804 | + $post_data['meta'][$meta_field] = $value; |
|
| 805 | 805 | }; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - if ( empty( $post_data ) ) { |
|
| 809 | - if ( $wp_error ) { |
|
| 810 | - return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) ); |
|
| 808 | + if (empty($post_data)) { |
|
| 809 | + if ($wp_error) { |
|
| 810 | + return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing')); |
|
| 811 | 811 | } |
| 812 | 812 | return 0; |
| 813 | 813 | } |
| 814 | 814 | $post_data['ID'] = $args['ID']; |
| 815 | 815 | |
| 816 | - $return = $item->update( $post_data, $wp_error ); |
|
| 816 | + $return = $item->update($post_data, $wp_error); |
|
| 817 | 817 | |
| 818 | - if ( $return && !empty( $item ) && !is_wp_error( $return ) ) { |
|
| 818 | + if ($return && !empty($item) && !is_wp_error($return)) { |
|
| 819 | 819 | return $item; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - if ( $wp_error && is_wp_error( $return ) ) { |
|
| 822 | + if ($wp_error && is_wp_error($return)) { |
|
| 823 | 823 | return $return; |
| 824 | 824 | } |
| 825 | 825 | return 0; |
@@ -1,56 +1,56 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined('ABSPATH') ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | -do_action( 'wpinv_invalid_invoice_before_display' ); ?><!DOCTYPE html> |
|
| 5 | +do_action('wpinv_invalid_invoice_before_display'); ?><!DOCTYPE html> |
|
| 6 | 6 | <html <?php language_attributes(); ?>> |
| 7 | 7 | <head> |
| 8 | 8 | <meta charset="UTF-8"> |
| 9 | 9 | <title><?php wp_title() ?></title> |
| 10 | - <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
|
| 10 | + <meta charset="<?php bloginfo('charset'); ?>" /> |
|
| 11 | 11 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 12 | 12 | <meta name="robots" content="noindex,nofollow"> |
| 13 | - <?php do_action( 'wpinv_invalid_invoice_head' ); ?> |
|
| 13 | + <?php do_action('wpinv_invalid_invoice_head'); ?> |
|
| 14 | 14 | </head> |
| 15 | 15 | <body class="body wpinv wpinv-print wpinv-invalid-invoice"> |
| 16 | - <?php do_action( 'wpinv_invalid_invoice_body_start' ); ?> |
|
| 16 | + <?php do_action('wpinv_invalid_invoice_body_start'); ?> |
|
| 17 | 17 | <div class="container wpinv-wrap"> |
| 18 | 18 | <!-- ///// Start Header --> |
| 19 | 19 | <htmlpageheader name="wpinv-pdf-header"> |
| 20 | - <?php do_action( 'wpinv_invalid_invoice_before_header' ); ?> |
|
| 20 | + <?php do_action('wpinv_invalid_invoice_before_header'); ?> |
|
| 21 | 21 | <div class="row wpinv-header"> |
| 22 | 22 | <div class="col-xs-12 wpinv-business"> |
| 23 | - <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
| 24 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
| 25 | - <img class="logo" src="<?php echo esc_url( $logo ); ?>"> |
|
| 23 | + <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
| 24 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
| 25 | + <img class="logo" src="<?php echo esc_url($logo); ?>"> |
|
| 26 | 26 | <?php } else { ?> |
| 27 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
| 27 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
| 28 | 28 | <?php } ?> |
| 29 | 29 | </a> |
| 30 | 30 | </div> |
| 31 | 31 | </div> |
| 32 | - <?php do_action( 'wpinv_invalid_invoice_after_header' ); ?> |
|
| 32 | + <?php do_action('wpinv_invalid_invoice_after_header'); ?> |
|
| 33 | 33 | </htmlpageheader> |
| 34 | 34 | <!-- End Header ///// --> |
| 35 | 35 | |
| 36 | - <?php do_action( 'wpinv_invalid_invoice_before_content' ); ?> |
|
| 36 | + <?php do_action('wpinv_invalid_invoice_before_content'); ?> |
|
| 37 | 37 | |
| 38 | - <?php do_action( 'wpinv_invalid_invoice_content' ); ?> |
|
| 38 | + <?php do_action('wpinv_invalid_invoice_content'); ?> |
|
| 39 | 39 | |
| 40 | - <?php do_action( 'wpinv_invalid_invoice_after_content' ); ?> |
|
| 40 | + <?php do_action('wpinv_invalid_invoice_after_content'); ?> |
|
| 41 | 41 | |
| 42 | 42 | <!-- ///// Start Footer --> |
| 43 | 43 | <htmlpagefooter name="wpinv-pdf-footer"> |
| 44 | - <?php do_action( 'wpinv_invalid_invoice_before_footer' ); ?> |
|
| 44 | + <?php do_action('wpinv_invalid_invoice_before_footer'); ?> |
|
| 45 | 45 | <div class="row wpinv-footer"> |
| 46 | 46 | <div class="col-sm-12"> |
| 47 | 47 | <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div> |
| 48 | 48 | </div> |
| 49 | 49 | </div> |
| 50 | - <?php do_action( 'wpinv_invalid_invoice_after_footer' ); ?> |
|
| 50 | + <?php do_action('wpinv_invalid_invoice_after_footer'); ?> |
|
| 51 | 51 | </htmlpagefooter> |
| 52 | 52 | <!-- End Footer ///// --> |
| 53 | 53 | </div> |
| 54 | - <?php do_action( 'wpinv_invalid_invoice_body_end' ); ?> |
|
| 54 | + <?php do_action('wpinv_invalid_invoice_body_end'); ?> |
|
| 55 | 55 | </body> |
| 56 | 56 | </html> |
| 57 | 57 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if (!defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | abstract class Wpinv_DB { |
| 7 | 7 | |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | * @since 1.0.0 |
| 67 | 67 | * @return object |
| 68 | 68 | */ |
| 69 | - public function get( $row_id ) { |
|
| 69 | + public function get($row_id) { |
|
| 70 | 70 | global $wpdb; |
| 71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 71 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | * @since 1.0.0 |
| 79 | 79 | * @return object |
| 80 | 80 | */ |
| 81 | - public function get_by( $column, $row_id ) { |
|
| 81 | + public function get_by($column, $row_id) { |
|
| 82 | 82 | global $wpdb; |
| 83 | - $column = esc_sql( $column ); |
|
| 84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
| 83 | + $column = esc_sql($column); |
|
| 84 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id)); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | * @since 1.0.0 |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function get_column( $column, $row_id ) { |
|
| 94 | + public function get_column($column, $row_id) { |
|
| 95 | 95 | global $wpdb; |
| 96 | - $column = esc_sql( $column ); |
|
| 97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 96 | + $column = esc_sql($column); |
|
| 97 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | * @since 1.0.0 |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
| 107 | + public function get_column_by($column, $column_where, $column_value) { |
|
| 108 | 108 | global $wpdb; |
| 109 | - $column_where = esc_sql( $column_where ); |
|
| 110 | - $column = esc_sql( $column ); |
|
| 111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
| 109 | + $column_where = esc_sql($column_where); |
|
| 110 | + $column = esc_sql($column); |
|
| 111 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value)); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,31 +118,31 @@ discard block |
||
| 118 | 118 | * @since 1.0.0 |
| 119 | 119 | * @return int |
| 120 | 120 | */ |
| 121 | - public function insert( $data, $type = '' ) { |
|
| 121 | + public function insert($data, $type = '') { |
|
| 122 | 122 | global $wpdb; |
| 123 | 123 | |
| 124 | 124 | // Set default values |
| 125 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
| 125 | + $data = wp_parse_args($data, $this->get_column_defaults()); |
|
| 126 | 126 | |
| 127 | - do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
| 127 | + do_action('wpinv_pre_insert_' . $type, $data); |
|
| 128 | 128 | |
| 129 | 129 | // Initialise column format array |
| 130 | 130 | $column_formats = $this->get_columns(); |
| 131 | 131 | |
| 132 | 132 | // Force fields to lower case |
| 133 | - $data = array_change_key_case( $data ); |
|
| 133 | + $data = array_change_key_case($data); |
|
| 134 | 134 | |
| 135 | 135 | // White list columns |
| 136 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 136 | + $data = array_intersect_key($data, $column_formats); |
|
| 137 | 137 | |
| 138 | 138 | // Reorder $column_formats to match the order of columns given in $data |
| 139 | - $data_keys = array_keys( $data ); |
|
| 140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 139 | + $data_keys = array_keys($data); |
|
| 140 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
| 141 | 141 | |
| 142 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
| 142 | + $wpdb->insert($this->table_name, $data, $column_formats); |
|
| 143 | 143 | $wpdb_insert_id = $wpdb->insert_id; |
| 144 | 144 | |
| 145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
| 145 | + do_action('wpinv_post_insert_' . $type, $wpdb_insert_id, $data); |
|
| 146 | 146 | |
| 147 | 147 | return $wpdb_insert_id; |
| 148 | 148 | } |
@@ -154,18 +154,18 @@ discard block |
||
| 154 | 154 | * @since 1.0.0 |
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
| 157 | + public function update($row_id, $data = array(), $where = '') { |
|
| 158 | 158 | |
| 159 | 159 | global $wpdb; |
| 160 | 160 | |
| 161 | 161 | // Row ID must be positive integer |
| 162 | - $row_id = absint( $row_id ); |
|
| 162 | + $row_id = absint($row_id); |
|
| 163 | 163 | |
| 164 | - if( empty( $row_id ) ) { |
|
| 164 | + if (empty($row_id)) { |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if( empty( $where ) ) { |
|
| 168 | + if (empty($where)) { |
|
| 169 | 169 | $where = $this->primary_key; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | $column_formats = $this->get_columns(); |
| 174 | 174 | |
| 175 | 175 | // Force fields to lower case |
| 176 | - $data = array_change_key_case( $data ); |
|
| 176 | + $data = array_change_key_case($data); |
|
| 177 | 177 | |
| 178 | 178 | // White list columns |
| 179 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 179 | + $data = array_intersect_key($data, $column_formats); |
|
| 180 | 180 | |
| 181 | 181 | // Reorder $column_formats to match the order of columns given in $data |
| 182 | - $data_keys = array_keys( $data ); |
|
| 183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 182 | + $data_keys = array_keys($data); |
|
| 183 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
| 184 | 184 | |
| 185 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
| 185 | + if (false === $wpdb->update($this->table_name, $data, array($where => $row_id), $column_formats)) { |
|
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -196,18 +196,18 @@ discard block |
||
| 196 | 196 | * @since 1.0.0 |
| 197 | 197 | * @return bool |
| 198 | 198 | */ |
| 199 | - public function delete( $row_id = 0 ) { |
|
| 199 | + public function delete($row_id = 0) { |
|
| 200 | 200 | |
| 201 | 201 | global $wpdb; |
| 202 | 202 | |
| 203 | 203 | // Row ID must be positive integer |
| 204 | - $row_id = absint( $row_id ); |
|
| 204 | + $row_id = absint($row_id); |
|
| 205 | 205 | |
| 206 | - if( empty( $row_id ) ) { |
|
| 206 | + if (empty($row_id)) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
| 210 | + if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id))) { |
|
| 211 | 211 | return false; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @param string $table The table name |
| 222 | 222 | * @return bool If the table name exists |
| 223 | 223 | */ |
| 224 | - public function table_exists( $table ) { |
|
| 224 | + public function table_exists($table) { |
|
| 225 | 225 | global $wpdb; |
| 226 | - $table = sanitize_text_field( $table ); |
|
| 226 | + $table = sanitize_text_field($table); |
|
| 227 | 227 | |
| 228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
| 228 | + return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE '%s'", $table)) === $table; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @return bool Returns if the customers table was installed and upgrade routine run |
| 236 | 236 | */ |
| 237 | 237 | public function installed() { |
| 238 | - return $this->table_exists( $this->table_name ); |
|
| 238 | + return $this->table_exists($this->table_name); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | } |
@@ -1,25 +1,25 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | 6 | // Load colours |
| 7 | -$bg = wpinv_get_option( 'email_background_color', '#f5f5f5' ); |
|
| 8 | -$body = wpinv_get_option( 'email_body_background_color', '#fdfdfd' ); |
|
| 9 | -$base = wpinv_get_option( 'email_base_color', '#557da2' ); |
|
| 10 | -$base_text = wpinv_light_or_dark( $base, '#202020', '#ffffff' ); |
|
| 11 | -$text = wpinv_get_option( 'email_text_color', '#505050' ); |
|
| 7 | +$bg = wpinv_get_option('email_background_color', '#f5f5f5'); |
|
| 8 | +$body = wpinv_get_option('email_body_background_color', '#fdfdfd'); |
|
| 9 | +$base = wpinv_get_option('email_base_color', '#557da2'); |
|
| 10 | +$base_text = wpinv_light_or_dark($base, '#202020', '#ffffff'); |
|
| 11 | +$text = wpinv_get_option('email_text_color', '#505050'); |
|
| 12 | 12 | |
| 13 | -$bg_darker_10 = wpinv_hex_darker( $bg, 10 ); |
|
| 14 | -$body_darker_10 = wpinv_hex_darker( $body, 10 ); |
|
| 15 | -$base_lighter_20 = wpinv_hex_lighter( $base, 20 ); |
|
| 16 | -$base_lighter_40 = wpinv_hex_lighter( $base, 40 ); |
|
| 17 | -$text_lighter_20 = wpinv_hex_lighter( $text, 20 ); |
|
| 13 | +$bg_darker_10 = wpinv_hex_darker($bg, 10); |
|
| 14 | +$body_darker_10 = wpinv_hex_darker($body, 10); |
|
| 15 | +$base_lighter_20 = wpinv_hex_lighter($base, 20); |
|
| 16 | +$base_lighter_40 = wpinv_hex_lighter($base, 40); |
|
| 17 | +$text_lighter_20 = wpinv_hex_lighter($text, 20); |
|
| 18 | 18 | |
| 19 | 19 | // !important; is a gmail hack to prevent styles being stripped if it doesn't like something. |
| 20 | 20 | ?> |
| 21 | 21 | #wrapper { |
| 22 | - background-color: <?php echo esc_attr( $bg ); ?>; |
|
| 22 | + background-color: <?php echo esc_attr($bg); ?>; |
|
| 23 | 23 | margin: 0; |
| 24 | 24 | -webkit-text-size-adjust: none !important; |
| 25 | 25 | padding: 3%; |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | #template_container { |
| 42 | 42 | box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important; |
| 43 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
| 44 | - border: 1px solid <?php echo esc_attr( $bg_darker_10 ); ?>; |
|
| 43 | + background-color: <?php echo esc_attr($body); ?>; |
|
| 44 | + border: 1px solid <?php echo esc_attr($bg_darker_10); ?>; |
|
| 45 | 45 | border-radius: 3px !important; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | #template_header { |
| 49 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
| 49 | + background-color: <?php echo esc_attr($base); ?>; |
|
| 50 | 50 | border-radius: 3px 3px 0 0 !important; |
| 51 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 51 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 52 | 52 | border-bottom: 0; |
| 53 | 53 | font-weight: bold; |
| 54 | 54 | line-height: 100%; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | #template_header h1 { |
| 64 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 64 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | #template_footer td { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | #template_footer #credit { |
| 74 | 74 | border:0; |
| 75 | - color: <?php echo esc_attr( $base_lighter_40 ); ?>; |
|
| 75 | + color: <?php echo esc_attr($base_lighter_40); ?>; |
|
| 76 | 76 | font-family: Arial; |
| 77 | 77 | font-size:12px; |
| 78 | 78 | line-height:125%; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | #body_content { |
| 84 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
| 84 | + background-color: <?php echo esc_attr($body); ?>; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | #body_content table td { |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | #body_content_inner { |
| 104 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 104 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 105 | 105 | font-family: Arial,Helvetica,sans-serif; |
| 106 | 106 | font-size: 14px; |
| 107 | 107 | line-height: 150%; |
@@ -109,17 +109,17 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | .td { |
| 112 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 113 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 112 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 113 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | .text { |
| 117 | - color: <?php echo esc_attr( $text ); ?>; |
|
| 117 | + color: <?php echo esc_attr($text); ?>; |
|
| 118 | 118 | font-family: Arial,Helvetica,sans-serif; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | .link { |
| 122 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 122 | + color: <?php echo esc_attr($base); ?>; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | #header_wrapper { |
@@ -128,19 +128,19 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | h1 { |
| 131 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 131 | + color: <?php echo esc_attr($base); ?>; |
|
| 132 | 132 | font-family: Arial,Helvetica,sans-serif; |
| 133 | 133 | font-size: 30px; |
| 134 | 134 | font-weight: 300; |
| 135 | 135 | line-height: 150%; |
| 136 | 136 | margin: 0; |
| 137 | 137 | text-align: <?php echo is_rtl() ? 'right' : 'left'; ?>; |
| 138 | - text-shadow: 0 1px 0 <?php echo esc_attr( $base_lighter_20 ); ?>; |
|
| 138 | + text-shadow: 0 1px 0 <?php echo esc_attr($base_lighter_20); ?>; |
|
| 139 | 139 | -webkit-font-smoothing: antialiased; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | h2 { |
| 143 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 143 | + color: <?php echo esc_attr($base); ?>; |
|
| 144 | 144 | display: block; |
| 145 | 145 | font-family: Arial,Helvetica,sans-serif; |
| 146 | 146 | font-size: 18px; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | h3 { |
| 154 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 154 | + color: <?php echo esc_attr($base); ?>; |
|
| 155 | 155 | display: block; |
| 156 | 156 | font-family: Arial,Helvetica,sans-serif; |
| 157 | 157 | font-size: 16px; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | a { |
| 165 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 165 | + color: <?php echo esc_attr($base); ?>; |
|
| 166 | 166 | font-weight: normal; |
| 167 | 167 | text-decoration: underline; |
| 168 | 168 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | .table-bordered { |
| 183 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 183 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 184 | 184 | border-collapse: collapse; |
| 185 | 185 | border-spacing: 0; |
| 186 | 186 | width: 100%; |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | .table-bordered th, |
| 190 | 190 | .table-bordered td { |
| 191 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 192 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 191 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 192 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 193 | 193 | font-size: 14px; |
| 194 | 194 | } |
| 195 | 195 | .small { |
@@ -288,9 +288,9 @@ discard block |
||
| 288 | 288 | text-decoration: none; |
| 289 | 289 | } |
| 290 | 290 | .btn-default { |
| 291 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 292 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
| 293 | - border-color: <?php echo esc_attr( $base ); ?>; |
|
| 291 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 292 | + background-color: <?php echo esc_attr($base); ?>; |
|
| 293 | + border-color: <?php echo esc_attr($base); ?>; |
|
| 294 | 294 | } |
| 295 | 295 | .btn-primary { |
| 296 | 296 | color: #fff; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | 6 | global $wpinv_euvat, $ajax_cart_details; |
@@ -11,152 +11,152 @@ discard block |
||
| 11 | 11 | $quantities_enabled = wpinv_item_quantities_enabled(); |
| 12 | 12 | $use_taxes = wpinv_use_taxes(); |
| 13 | 13 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
| 14 | -$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
| 15 | -$tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
| 14 | +$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
| 15 | +$tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
| 16 | 16 | |
| 17 | -do_action( 'wpinv_before_email_items', $invoice ); ?> |
|
| 17 | +do_action('wpinv_before_email_items', $invoice); ?> |
|
| 18 | 18 | <div id="wpinv-email-items"> |
| 19 | - <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3> |
|
| 19 | + <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3> |
|
| 20 | 20 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
| 21 | 21 | <thead> |
| 22 | 22 | <tr class="wpinv_cart_header_row"> |
| 23 | - <?php do_action( 'wpinv_email_items_table_header_first' ); ?> |
|
| 24 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
| 25 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
| 26 | - <?php if ( $quantities_enabled ) { ?> |
|
| 27 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
| 23 | + <?php do_action('wpinv_email_items_table_header_first'); ?> |
|
| 24 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
| 25 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
| 26 | + <?php if ($quantities_enabled) { ?> |
|
| 27 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
| 28 | 28 | <?php } ?> |
| 29 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
| 29 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
| 30 | 30 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
| 31 | 31 | <?php } ?> |
| 32 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
| 33 | - <?php do_action( 'wpinv_email_items_table_header_last' ); ?> |
|
| 32 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
| 33 | + <?php do_action('wpinv_email_items_table_header_last'); ?> |
|
| 34 | 34 | </tr> |
| 35 | 35 | </thead> |
| 36 | 36 | <tbody> |
| 37 | 37 | <?php |
| 38 | - do_action( 'wpinv_email_items_before' ); |
|
| 39 | - if ( $cart_items ) { |
|
| 40 | - foreach ( $cart_items as $key => $item ) { |
|
| 41 | - $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL; |
|
| 38 | + do_action('wpinv_email_items_before'); |
|
| 39 | + if ($cart_items) { |
|
| 40 | + foreach ($cart_items as $key => $item) { |
|
| 41 | + $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL; |
|
| 42 | 42 | ?> |
| 43 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
| 44 | - <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?> |
|
| 43 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
| 44 | + <?php do_action('wpinv_email_items_table_body_first', $item); ?> |
|
| 45 | 45 | <td class="wpinv_cart_item_name text-left"> |
| 46 | 46 | <?php |
| 47 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
| 47 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
| 48 | 48 | echo '<div class="wpinv_cart_item_image">'; |
| 49 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
| 49 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
| 50 | 50 | echo '</div>'; |
| 51 | 51 | } |
| 52 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
| 52 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
| 53 | 53 | echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>'; |
| 54 | 54 | |
| 55 | - $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice ); |
|
| 56 | - if ( !empty( $summary ) ) { |
|
| 55 | + $summary = apply_filters('wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice); |
|
| 56 | + if (!empty($summary)) { |
|
| 57 | 57 | echo '<p class="small">' . $summary . '</p>'; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - do_action( 'wpinv_email_cart_item_title_after', $item, $key ); |
|
| 60 | + do_action('wpinv_email_cart_item_title_after', $item, $key); |
|
| 61 | 61 | ?> |
| 62 | 62 | </td> |
| 63 | 63 | <td class="wpinv_cart_item_price text-right"> |
| 64 | 64 | <?php |
| 65 | - echo wpinv_cart_item_price( $item ); |
|
| 66 | - do_action( 'wpinv_email_cart_item_price_after', $item, $key ); |
|
| 65 | + echo wpinv_cart_item_price($item); |
|
| 66 | + do_action('wpinv_email_cart_item_price_after', $item, $key); |
|
| 67 | 67 | ?> |
| 68 | 68 | </td> |
| 69 | - <?php if ( $quantities_enabled ) { ?> |
|
| 69 | + <?php if ($quantities_enabled) { ?> |
|
| 70 | 70 | <td class="wpinv_cart_item_qty text-right"> |
| 71 | 71 | <?php |
| 72 | - echo wpinv_get_cart_item_quantity( $item ); |
|
| 73 | - do_action( 'wpinv_email_item_quantitiy', $item, $key ); |
|
| 72 | + echo wpinv_get_cart_item_quantity($item); |
|
| 73 | + do_action('wpinv_email_item_quantitiy', $item, $key); |
|
| 74 | 74 | ?> |
| 75 | 75 | </td> |
| 76 | 76 | <?php } ?> |
| 77 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
| 77 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
| 78 | 78 | <td class="wpinv_cart_item_tax text-right"> |
| 79 | 79 | <?php |
| 80 | - echo wpinv_cart_item_tax( $item ); |
|
| 81 | - do_action( 'wpinv_email_item_tax', $item, $key ); |
|
| 80 | + echo wpinv_cart_item_tax($item); |
|
| 81 | + do_action('wpinv_email_item_tax', $item, $key); |
|
| 82 | 82 | ?> |
| 83 | 83 | </td> |
| 84 | 84 | <?php } ?> |
| 85 | 85 | <td class="wpinv_cart_item_subtotal text-right"> |
| 86 | 86 | <?php |
| 87 | - echo wpinv_cart_item_subtotal( $item ); |
|
| 88 | - do_action( 'wpinv_email_item_subtotal', $item, $key ); |
|
| 87 | + echo wpinv_cart_item_subtotal($item); |
|
| 88 | + do_action('wpinv_email_item_subtotal', $item, $key); |
|
| 89 | 89 | ?> |
| 90 | 90 | </td> |
| 91 | - <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?> |
|
| 91 | + <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?> |
|
| 92 | 92 | </tr> |
| 93 | 93 | <?php } ?> |
| 94 | 94 | <?php } ?> |
| 95 | - <?php do_action( 'wpinv_email_items_middle' ); ?> |
|
| 96 | - <?php do_action( 'wpinv_email_items_after' ); ?> |
|
| 95 | + <?php do_action('wpinv_email_items_middle'); ?> |
|
| 96 | + <?php do_action('wpinv_email_items_after'); ?> |
|
| 97 | 97 | </tbody> |
| 98 | 98 | <tfoot> |
| 99 | - <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?> |
|
| 100 | - <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?> |
|
| 99 | + <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?> |
|
| 100 | + <?php if (has_action('wpinv_email_footer_buttons')) { ?> |
|
| 101 | 101 | <tr class="wpinv_cart_footer_row"> |
| 102 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
| 103 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
| 104 | - <?php do_action( 'wpinv_email_footer_buttons' ); ?> |
|
| 102 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
| 103 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
| 104 | + <?php do_action('wpinv_email_footer_buttons'); ?> |
|
| 105 | 105 | </td> |
| 106 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
| 106 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
| 107 | 107 | </tr> |
| 108 | 108 | <?php } ?> |
| 109 | 109 | |
| 110 | - <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?> |
|
| 110 | + <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?> |
|
| 111 | 111 | <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"> |
| 112 | - <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?> |
|
| 113 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
| 114 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
| 112 | + <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?> |
|
| 113 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
| 114 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
| 115 | 115 | </td> |
| 116 | 116 | <td class="wpinv_cart_subtotal text-right"> |
| 117 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span> |
|
| 117 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span> |
|
| 118 | 118 | </td> |
| 119 | - <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?> |
|
| 119 | + <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?> |
|
| 120 | 120 | </tr> |
| 121 | 121 | <?php } ?> |
| 122 | 122 | |
| 123 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
| 123 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
| 124 | 124 | <tr class="wpinv_cart_footer_row wpinv_cart_discount_row"> |
| 125 | - <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?> |
|
| 126 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right"> |
|
| 127 | - <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong> |
|
| 125 | + <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?> |
|
| 126 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right"> |
|
| 127 | + <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong> |
|
| 128 | 128 | </td> |
| 129 | 129 | <td class="wpinv_cart_discount text-right"> |
| 130 | - <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span> |
|
| 130 | + <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span> |
|
| 131 | 131 | </td> |
| 132 | - <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?> |
|
| 132 | + <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?> |
|
| 133 | 133 | </tr> |
| 134 | 134 | <?php } ?> |
| 135 | 135 | |
| 136 | - <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?> |
|
| 136 | + <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?> |
|
| 137 | 137 | <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"> |
| 138 | - <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?> |
|
| 139 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
| 138 | + <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?> |
|
| 139 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
| 140 | 140 | <strong><?php echo $tax_label; ?>:</strong> |
| 141 | 141 | </td> |
| 142 | 142 | <td class="wpinv_cart_tax text-right"> |
| 143 | - <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span> |
|
| 143 | + <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span> |
|
| 144 | 144 | </td> |
| 145 | - <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?> |
|
| 145 | + <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?> |
|
| 146 | 146 | </tr> |
| 147 | 147 | <?php } ?> |
| 148 | 148 | |
| 149 | 149 | <tr class="wpinv_cart_footer_row"> |
| 150 | - <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?> |
|
| 151 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
| 152 | - <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
| 150 | + <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?> |
|
| 151 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
| 152 | + <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
| 153 | 153 | </td> |
| 154 | 154 | <td class="wpinv_cart_total text-right"> |
| 155 | - <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span> |
|
| 155 | + <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span> |
|
| 156 | 156 | </td> |
| 157 | - <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?> |
|
| 157 | + <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?> |
|
| 158 | 158 | </tr> |
| 159 | 159 | </tfoot> |
| 160 | 160 | </table> |
| 161 | 161 | </div> |
| 162 | -<?php do_action( 'wpinv_after_email_items', $invoice ); ?> |
|
| 163 | 162 | \ No newline at end of file |
| 163 | +<?php do_action('wpinv_after_email_items', $invoice); ?> |
|
| 164 | 164 | \ No newline at end of file |
@@ -5,138 +5,138 @@ |
||
| 5 | 5 | |
| 6 | 6 | global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session; |
| 7 | 7 | $invoice = wpinv_get_invoice_cart(); |
| 8 | -$cart_items = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
| 8 | +$cart_items = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
| 9 | 9 | $quantities_enabled = wpinv_item_quantities_enabled(); |
| 10 | 10 | $use_taxes = wpinv_use_taxes(); |
| 11 | 11 | $tax_label = $wpinv_euvat->tax_label(); |
| 12 | -$tax_title = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
| 12 | +$tax_title = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
| 13 | 13 | ?> |
| 14 | 14 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
| 15 | 15 | <thead> |
| 16 | 16 | <tr class="wpinv_cart_header_row"> |
| 17 | - <?php do_action( 'wpinv_checkout_table_header_first' ); ?> |
|
| 18 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
| 19 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
| 20 | - <?php if ( $quantities_enabled ) { ?> |
|
| 21 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
| 17 | + <?php do_action('wpinv_checkout_table_header_first'); ?> |
|
| 18 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
| 19 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
| 20 | + <?php if ($quantities_enabled) { ?> |
|
| 21 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
| 22 | 22 | <?php } ?> |
| 23 | - <?php if ( $use_taxes ) { ?> |
|
| 23 | + <?php if ($use_taxes) { ?> |
|
| 24 | 24 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
| 25 | 25 | <?php } ?> |
| 26 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
| 27 | - <?php do_action( 'wpinv_checkout_table_header_last' ); ?> |
|
| 26 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
| 27 | + <?php do_action('wpinv_checkout_table_header_last'); ?> |
|
| 28 | 28 | </tr> |
| 29 | 29 | </thead> |
| 30 | 30 | <tbody> |
| 31 | 31 | <?php |
| 32 | - do_action( 'wpinv_cart_items_before' ); |
|
| 32 | + do_action('wpinv_cart_items_before'); |
|
| 33 | 33 | |
| 34 | - if ( $cart_items ) { |
|
| 35 | - foreach ( $cart_items as $key => $item ) { |
|
| 36 | - $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL; |
|
| 34 | + if ($cart_items) { |
|
| 35 | + foreach ($cart_items as $key => $item) { |
|
| 36 | + $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL; |
|
| 37 | 37 | ?> |
| 38 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
| 39 | - <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?> |
|
| 38 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
| 39 | + <?php do_action('wpinv_checkout_table_body_first', $item); ?> |
|
| 40 | 40 | <td class="wpinv_cart_item_name text-left"> |
| 41 | 41 | <?php |
| 42 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
| 42 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
| 43 | 43 | echo '<div class="wpinv_cart_item_image">'; |
| 44 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
| 44 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
| 45 | 45 | echo '</div>'; |
| 46 | 46 | } |
| 47 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
| 47 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
| 48 | 48 | echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>'; |
| 49 | - $summary = apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice ); |
|
| 50 | - if ( !empty( $summary ) ) { |
|
| 49 | + $summary = apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice); |
|
| 50 | + if (!empty($summary)) { |
|
| 51 | 51 | echo $summary; |
| 52 | 52 | } |
| 53 | 53 | ?> |
| 54 | 54 | </td> |
| 55 | 55 | <td class="wpinv_cart_item_price text-right"> |
| 56 | 56 | <?php |
| 57 | - echo wpinv_cart_item_price( $item ); |
|
| 58 | - do_action( 'wpinv_checkout_cart_item_price_after', $item, $key ); |
|
| 57 | + echo wpinv_cart_item_price($item); |
|
| 58 | + do_action('wpinv_checkout_cart_item_price_after', $item, $key); |
|
| 59 | 59 | ?> |
| 60 | 60 | </td> |
| 61 | - <?php if ( $quantities_enabled ) { ?> |
|
| 61 | + <?php if ($quantities_enabled) { ?> |
|
| 62 | 62 | <td class="wpinv_cart_item_qty text-right"> |
| 63 | 63 | <?php |
| 64 | - echo wpinv_get_cart_item_quantity( $item ); |
|
| 65 | - do_action( 'wpinv_cart_item_quantitiy', $item, $key ); |
|
| 64 | + echo wpinv_get_cart_item_quantity($item); |
|
| 65 | + do_action('wpinv_cart_item_quantitiy', $item, $key); |
|
| 66 | 66 | ?> |
| 67 | 67 | </td> |
| 68 | 68 | <?php } ?> |
| 69 | - <?php if ( $use_taxes ) { ?> |
|
| 69 | + <?php if ($use_taxes) { ?> |
|
| 70 | 70 | <td class="wpinv_cart_item_tax text-right"> |
| 71 | 71 | <?php |
| 72 | - echo wpinv_cart_item_tax( $item ); |
|
| 72 | + echo wpinv_cart_item_tax($item); |
|
| 73 | 73 | //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() ); |
| 74 | - do_action( 'wpinv_cart_item_tax', $item, $key ); |
|
| 74 | + do_action('wpinv_cart_item_tax', $item, $key); |
|
| 75 | 75 | ?> |
| 76 | 76 | </td> |
| 77 | 77 | <?php } ?> |
| 78 | 78 | <td class="wpinv_cart_item_subtotal text-right"> |
| 79 | 79 | <?php |
| 80 | - echo wpinv_cart_item_subtotal( $item ); |
|
| 81 | - do_action( 'wpinv_cart_item_subtotal', $item, $key ); |
|
| 80 | + echo wpinv_cart_item_subtotal($item); |
|
| 81 | + do_action('wpinv_cart_item_subtotal', $item, $key); |
|
| 82 | 82 | ?> |
| 83 | 83 | </td> |
| 84 | - <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?> |
|
| 84 | + <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?> |
|
| 85 | 85 | </tr> |
| 86 | 86 | <?php } ?> |
| 87 | 87 | <?php } ?> |
| 88 | - <?php do_action( 'wpinv_cart_items_middle' ); ?> |
|
| 89 | - <?php do_action( 'wpinv_cart_items_after' ); ?> |
|
| 88 | + <?php do_action('wpinv_cart_items_middle'); ?> |
|
| 89 | + <?php do_action('wpinv_cart_items_after'); ?> |
|
| 90 | 90 | </tbody> |
| 91 | 91 | <tfoot> |
| 92 | 92 | <?php $cart_columns = wpinv_checkout_cart_columns(); ?> |
| 93 | - <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?> |
|
| 93 | + <?php if (has_action('wpinv_cart_footer_buttons')) { ?> |
|
| 94 | 94 | <tr class="wpinv_cart_footer_row"> |
| 95 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
| 96 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
| 97 | - <?php do_action( 'wpinv_cart_footer_buttons' ); ?> |
|
| 95 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
| 96 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
| 97 | + <?php do_action('wpinv_cart_footer_buttons'); ?> |
|
| 98 | 98 | </td> |
| 99 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
| 99 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
| 100 | 100 | </tr> |
| 101 | 101 | <?php } ?> |
| 102 | 102 | |
| 103 | - <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?> |
|
| 104 | - <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
| 105 | - <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?> |
|
| 106 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
| 107 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
| 103 | + <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?> |
|
| 104 | + <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
| 105 | + <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?> |
|
| 106 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
| 107 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
| 108 | 108 | </td> |
| 109 | 109 | <td class="wpinv_cart_subtotal text-right"> |
| 110 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span> |
|
| 110 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span> |
|
| 111 | 111 | </td> |
| 112 | - <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?> |
|
| 112 | + <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?> |
|
| 113 | 113 | </tr> |
| 114 | 114 | <?php } ?> |
| 115 | 115 | |
| 116 | - <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?> |
|
| 116 | + <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?> |
|
| 117 | 117 | |
| 118 | - <?php if ( $use_taxes ) { ?> |
|
| 119 | - <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
| 120 | - <?php do_action( 'wpinv_checkout_table_tax_first' ); ?> |
|
| 121 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
| 118 | + <?php if ($use_taxes) { ?> |
|
| 119 | + <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
| 120 | + <?php do_action('wpinv_checkout_table_tax_first'); ?> |
|
| 121 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
| 122 | 122 | <strong><?php echo $tax_label; ?>:</strong> |
| 123 | 123 | </td> |
| 124 | 124 | <td class="wpinv_cart_tax text-right"> |
| 125 | - <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span> |
|
| 125 | + <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span> |
|
| 126 | 126 | </td> |
| 127 | - <?php do_action( 'wpinv_checkout_table_tax_last' ); ?> |
|
| 127 | + <?php do_action('wpinv_checkout_table_tax_last'); ?> |
|
| 128 | 128 | </tr> |
| 129 | 129 | <?php } ?> |
| 130 | 130 | |
| 131 | 131 | <tr class="wpinv_cart_footer_row wpinv_cart_total_row"> |
| 132 | - <?php do_action( 'wpinv_checkout_table_footer_first' ); ?> |
|
| 133 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
| 134 | - <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
| 132 | + <?php do_action('wpinv_checkout_table_footer_first'); ?> |
|
| 133 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
| 134 | + <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
| 135 | 135 | </td> |
| 136 | 136 | <td class="wpinv_cart_total text-right"> |
| 137 | - <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span> |
|
| 137 | + <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span> |
|
| 138 | 138 | </td> |
| 139 | - <?php do_action( 'wpinv_checkout_table_footer_last' ); ?> |
|
| 139 | + <?php do_action('wpinv_checkout_table_footer_last'); ?> |
|
| 140 | 140 | </tr> |
| 141 | 141 | </tfoot> |
| 142 | 142 | </table> |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | class WPInv_Item { |
| 6 | 6 | public $ID = 0; |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | public $filter; |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function __construct( $_id = false, $_args = array() ) { |
|
| 51 | - $item = WP_Post::get_instance( $_id ); |
|
| 52 | - return $this->setup_item( $item ); |
|
| 50 | + public function __construct($_id = false, $_args = array()) { |
|
| 51 | + $item = WP_Post::get_instance($_id); |
|
| 52 | + return $this->setup_item($item); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function setup_item( $item ) { |
|
| 56 | - if( ! is_object( $item ) ) { |
|
| 55 | + private function setup_item($item) { |
|
| 56 | + if (!is_object($item)) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! is_a( $item, 'WP_Post' ) ) { |
|
| 60 | + if (!is_a($item, 'WP_Post')) { |
|
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if( 'wpi_item' !== $item->post_type ) { |
|
| 64 | + if ('wpi_item' !== $item->post_type) { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - foreach ( $item as $key => $value ) { |
|
| 69 | - switch ( $key ) { |
|
| 68 | + foreach ($item as $key => $value) { |
|
| 69 | + switch ($key) { |
|
| 70 | 70 | default: |
| 71 | 71 | $this->$key = $value; |
| 72 | 72 | break; |
@@ -76,38 +76,38 @@ discard block |
||
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function __get( $key ) { |
|
| 80 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 81 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 79 | + public function __get($key) { |
|
| 80 | + if (method_exists($this, 'get_' . $key)) { |
|
| 81 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 82 | 82 | } else { |
| 83 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 83 | + return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function create( $data = array(), $wp_error = false ) { |
|
| 88 | - if ( $this->ID != 0 ) { |
|
| 87 | + public function create($data = array(), $wp_error = false) { |
|
| 88 | + if ($this->ID != 0) { |
|
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $defaults = array( |
| 93 | 93 | 'post_type' => 'wpi_item', |
| 94 | 94 | 'post_status' => 'draft', |
| 95 | - 'post_title' => __( 'New Invoice Item', 'invoicing' ) |
|
| 95 | + 'post_title' => __('New Invoice Item', 'invoicing') |
|
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | - $args = wp_parse_args( $data, $defaults ); |
|
| 98 | + $args = wp_parse_args($data, $defaults); |
|
| 99 | 99 | |
| 100 | - do_action( 'wpinv_item_pre_create', $args ); |
|
| 100 | + do_action('wpinv_item_pre_create', $args); |
|
| 101 | 101 | |
| 102 | - $id = wp_insert_post( $args, $wp_error ); |
|
| 102 | + $id = wp_insert_post($args, $wp_error); |
|
| 103 | 103 | if ($wp_error && is_wp_error($id)) { |
| 104 | 104 | return $id; |
| 105 | 105 | } |
| 106 | - if ( !$id ) { |
|
| 106 | + if (!$id) { |
|
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $item = WP_Post::get_instance( $id ); |
|
| 110 | + $item = WP_Post::get_instance($id); |
|
| 111 | 111 | |
| 112 | 112 | if (!empty($item) && !empty($data['meta'])) { |
| 113 | 113 | $this->ID = $item->ID; |
@@ -115,47 +115,47 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Set custom id if not set. |
| 118 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 119 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
| 118 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 119 | + $this->save_metas(array('custom_id' => $id)); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - do_action( 'wpinv_item_create', $id, $args ); |
|
| 122 | + do_action('wpinv_item_create', $id, $args); |
|
| 123 | 123 | |
| 124 | - return $this->setup_item( $item ); |
|
| 124 | + return $this->setup_item($item); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function update( $data = array(), $wp_error = false ) { |
|
| 128 | - if ( !$this->ID > 0 ) { |
|
| 127 | + public function update($data = array(), $wp_error = false) { |
|
| 128 | + if (!$this->ID > 0) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $data['ID'] = $this->ID; |
| 133 | 133 | |
| 134 | - do_action( 'wpinv_item_pre_update', $data ); |
|
| 134 | + do_action('wpinv_item_pre_update', $data); |
|
| 135 | 135 | |
| 136 | - $id = wp_update_post( $data, $wp_error ); |
|
| 136 | + $id = wp_update_post($data, $wp_error); |
|
| 137 | 137 | if ($wp_error && is_wp_error($id)) { |
| 138 | 138 | return $id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( !$id ) { |
|
| 141 | + if (!$id) { |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $item = WP_Post::get_instance( $id ); |
|
| 145 | + $item = WP_Post::get_instance($id); |
|
| 146 | 146 | if (!empty($item) && !empty($data['meta'])) { |
| 147 | 147 | $this->ID = $item->ID; |
| 148 | 148 | $this->save_metas($data['meta']); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Set custom id if not set. |
| 152 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 153 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
| 152 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 153 | + $this->save_metas(array('custom_id' => $id)); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - do_action( 'wpinv_item_update', $id, $data ); |
|
| 156 | + do_action('wpinv_item_update', $id, $data); |
|
| 157 | 157 | |
| 158 | - return $this->setup_item( $item ); |
|
| 158 | + return $this->setup_item($item); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | public function get_ID() { |
@@ -163,119 +163,119 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function get_name() { |
| 166 | - return get_the_title( $this->ID ); |
|
| 166 | + return get_the_title($this->ID); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | public function get_title() { |
| 170 | - return get_the_title( $this->ID ); |
|
| 170 | + return get_the_title($this->ID); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function get_status() { |
| 174 | - return get_post_status( $this->ID ); |
|
| 174 | + return get_post_status($this->ID); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function get_summary() { |
| 178 | - return get_the_excerpt( $this->ID ); |
|
| 178 | + return get_the_excerpt($this->ID); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | public function get_price() { |
| 182 | - if ( ! isset( $this->price ) ) { |
|
| 183 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 182 | + if (!isset($this->price)) { |
|
| 183 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 184 | 184 | |
| 185 | - if ( $this->price ) { |
|
| 186 | - $this->price = wpinv_sanitize_amount( $this->price ); |
|
| 185 | + if ($this->price) { |
|
| 186 | + $this->price = wpinv_sanitize_amount($this->price); |
|
| 187 | 187 | } else { |
| 188 | 188 | $this->price = 0; |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID ); |
|
| 192 | + return apply_filters('wpinv_get_item_price', $this->price, $this->ID); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public function get_vat_rule() { |
| 196 | 196 | global $wpinv_euvat; |
| 197 | 197 | |
| 198 | - if( !isset( $this->vat_rule ) ) { |
|
| 199 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true ); |
|
| 198 | + if (!isset($this->vat_rule)) { |
|
| 199 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true); |
|
| 200 | 200 | |
| 201 | - if ( empty( $this->vat_rule ) ) { |
|
| 201 | + if (empty($this->vat_rule)) { |
|
| 202 | 202 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical'; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID ); |
|
| 206 | + return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | public function get_vat_class() { |
| 210 | - if( !isset( $this->vat_class ) ) { |
|
| 211 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true ); |
|
| 210 | + if (!isset($this->vat_class)) { |
|
| 211 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true); |
|
| 212 | 212 | |
| 213 | - if ( empty( $this->vat_class ) ) { |
|
| 213 | + if (empty($this->vat_class)) { |
|
| 214 | 214 | $this->vat_class = '_standard'; |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID ); |
|
| 218 | + return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | public function get_type() { |
| 222 | - if( ! isset( $this->type ) ) { |
|
| 223 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true ); |
|
| 222 | + if (!isset($this->type)) { |
|
| 223 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true); |
|
| 224 | 224 | |
| 225 | - if ( empty( $this->type ) ) { |
|
| 225 | + if (empty($this->type)) { |
|
| 226 | 226 | $this->type = 'custom'; |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID ); |
|
| 230 | + return apply_filters('wpinv_get_item_type', $this->type, $this->ID); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | public function get_custom_id() { |
| 234 | - $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true ); |
|
| 234 | + $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true); |
|
| 235 | 235 | |
| 236 | - return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID ); |
|
| 236 | + return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | public function get_custom_name() { |
| 240 | - $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true ); |
|
| 240 | + $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true); |
|
| 241 | 241 | |
| 242 | - return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID ); |
|
| 242 | + return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | public function get_custom_singular_name() { |
| 246 | - $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true ); |
|
| 246 | + $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true); |
|
| 247 | 247 | |
| 248 | - return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID ); |
|
| 248 | + return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | public function get_editable() { |
| 252 | - $editable = get_post_meta( $this->ID, '_wpinv_editable', true ); |
|
| 252 | + $editable = get_post_meta($this->ID, '_wpinv_editable', true); |
|
| 253 | 253 | |
| 254 | - return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID ); |
|
| 254 | + return apply_filters('wpinv_item_get_editable', $editable, $this->ID); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | public function get_excerpt() { |
| 258 | - $excerpt = get_the_excerpt( $this->ID ); |
|
| 258 | + $excerpt = get_the_excerpt($this->ID); |
|
| 259 | 259 | |
| 260 | - return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID ); |
|
| 260 | + return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | public function get_is_recurring() { |
| 264 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true ); |
|
| 264 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true); |
|
| 265 | 265 | |
| 266 | - return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID ); |
|
| 266 | + return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID); |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - public function get_recurring_period( $full = false ) { |
|
| 271 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true ); |
|
| 270 | + public function get_recurring_period($full = false) { |
|
| 271 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true); |
|
| 272 | 272 | |
| 273 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 273 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 274 | 274 | $period = 'D'; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ( $full ) { |
|
| 278 | - switch( $period ) { |
|
| 277 | + if ($full) { |
|
| 278 | + switch ($period) { |
|
| 279 | 279 | case 'D': |
| 280 | 280 | $period = 'day'; |
| 281 | 281 | break; |
@@ -291,40 +291,40 @@ discard block |
||
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID ); |
|
| 294 | + return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | public function get_recurring_interval() { |
| 298 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true ); |
|
| 298 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true); |
|
| 299 | 299 | |
| 300 | - if ( !$interval > 0 ) { |
|
| 300 | + if (!$interval > 0) { |
|
| 301 | 301 | $interval = 1; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID ); |
|
| 304 | + return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | public function get_recurring_limit() { |
| 308 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true ); |
|
| 308 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true); |
|
| 309 | 309 | |
| 310 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID ); |
|
| 310 | + return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | public function get_free_trial() { |
| 314 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true ); |
|
| 314 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true); |
|
| 315 | 315 | |
| 316 | - return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID ); |
|
| 316 | + return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - public function get_trial_period( $full = false ) { |
|
| 320 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true ); |
|
| 319 | + public function get_trial_period($full = false) { |
|
| 320 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true); |
|
| 321 | 321 | |
| 322 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 322 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 323 | 323 | $period = 'D'; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( $full ) { |
|
| 327 | - switch( $period ) { |
|
| 326 | + if ($full) { |
|
| 327 | + switch ($period) { |
|
| 328 | 328 | case 'D': |
| 329 | 329 | $period = 'day'; |
| 330 | 330 | break; |
@@ -340,47 +340,47 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID ); |
|
| 343 | + return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | public function get_trial_interval() { |
| 347 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) ); |
|
| 347 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true)); |
|
| 348 | 348 | |
| 349 | - if ( !$interval > 0 ) { |
|
| 349 | + if (!$interval > 0) { |
|
| 350 | 350 | $interval = 1; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID ); |
|
| 353 | + return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | public function get_the_price() { |
| 357 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) ); |
|
| 357 | + $item_price = wpinv_price(wpinv_format_amount($this->price)); |
|
| 358 | 358 | |
| 359 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
| 359 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | public function is_recurring() { |
| 363 | 363 | $is_recurring = $this->get_is_recurring(); |
| 364 | 364 | |
| 365 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID ); |
|
| 365 | + return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | public function has_free_trial() { |
| 369 | 369 | $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false; |
| 370 | 370 | |
| 371 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID ); |
|
| 371 | + return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | public function is_free() { |
| 375 | 375 | $is_free = false; |
| 376 | 376 | |
| 377 | - $price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 377 | + $price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 378 | 378 | |
| 379 | - if ( (float)$price == 0 ) { |
|
| 379 | + if ((float)$price == 0) { |
|
| 380 | 380 | $is_free = true; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID ); |
|
| 383 | + return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); |
|
| 384 | 384 | |
| 385 | 385 | } |
| 386 | 386 | |
@@ -389,15 +389,15 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | $is_editable = $editable === 0 || $editable === '0' ? false : true; |
| 391 | 391 | |
| 392 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID ); |
|
| 392 | + return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - public function save_metas( $metas = array() ) { |
|
| 396 | - if ( empty( $metas ) ) { |
|
| 395 | + public function save_metas($metas = array()) { |
|
| 396 | + if (empty($metas)) { |
|
| 397 | 397 | return false; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - foreach ( $metas as $meta_key => $meta_value ) { |
|
| 400 | + foreach ($metas as $meta_key => $meta_value) { |
|
| 401 | 401 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key; |
| 402 | 402 | |
| 403 | 403 | $this->update_meta($meta_key, $meta_value); |
@@ -406,66 +406,66 @@ discard block |
||
| 406 | 406 | return true; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 410 | - if ( empty( $meta_key ) ) { |
|
| 409 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 410 | + if (empty($meta_key)) { |
|
| 411 | 411 | return false; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 414 | + $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 415 | 415 | |
| 416 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 416 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 419 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
| 420 | 420 | global $wpi_session; |
| 421 | 421 | |
| 422 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
| 422 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
| 423 | 423 | |
| 424 | - if ( ! wpinv_get_cart_contents() ) { |
|
| 424 | + if (!wpinv_get_cart_contents()) { |
|
| 425 | 425 | // We can only get item type fees when the cart is empty |
| 426 | 426 | $type = 'custom'; |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
| 430 | - foreach( $fees as $key => $fee ) { |
|
| 431 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 432 | - unset( $fees[ $key ] ); |
|
| 429 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
| 430 | + foreach ($fees as $key => $fee) { |
|
| 431 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
| 432 | + unset($fees[$key]); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
| 437 | + if (!empty($fees) && !empty($item_id)) { |
|
| 438 | 438 | // Remove fees that don't belong to the specified Item |
| 439 | - foreach ( $fees as $key => $fee ) { |
|
| 440 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
| 441 | - unset( $fees[ $key ] ); |
|
| 439 | + foreach ($fees as $key => $fee) { |
|
| 440 | + if ((int)$item_id !== (int)$fee['custom_id']) { |
|
| 441 | + unset($fees[$key]); |
|
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - if ( ! empty( $fees ) ) { |
|
| 446 | + if (!empty($fees)) { |
|
| 447 | 447 | // Remove fees that belong to a specific item but are not in the cart |
| 448 | - foreach( $fees as $key => $fee ) { |
|
| 449 | - if( empty( $fee['custom_id'] ) ) { |
|
| 448 | + foreach ($fees as $key => $fee) { |
|
| 449 | + if (empty($fee['custom_id'])) { |
|
| 450 | 450 | continue; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
| 454 | - unset( $fees[ $key ] ); |
|
| 453 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
| 454 | + unset($fees[$key]); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - return ! empty( $fees ) ? $fees : array(); |
|
| 459 | + return !empty($fees) ? $fees : array(); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | public function can_purchase() { |
| 463 | 463 | $can_purchase = true; |
| 464 | 464 | |
| 465 | - if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 465 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 466 | 466 | $can_purchase = false; |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 469 | + return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 470 | 470 | } |
| 471 | 471 | } |