@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
| 26 | - define( 'WPINV_VERSION', '2.8.9' ); |
|
| 26 | + define( 'WPINV_VERSION', '2.8.9' ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $GLOBALS['invoicing']; |
|
| 46 | + return $GLOBALS['invoicing']; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
| 15 | 15 | * @package GetPaid |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -defined( 'ABSPATH' ) || exit; |
|
| 18 | +defined('ABSPATH') || exit; |
|
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
| 22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
| 26 | - define( 'WPINV_VERSION', '2.8.9' ); |
|
| 25 | +if (!defined('WPINV_VERSION')) { |
|
| 26 | + define('WPINV_VERSION', '2.8.9'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
| 31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | function getpaid() { |
| 41 | 41 | |
| 42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
| 42 | + if (empty($GLOBALS['invoicing'])) { |
|
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @since 2.0.8 |
| 53 | 53 | */ |
| 54 | 54 | function getpaid_deactivation_hook() { |
| 55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
| 55 | + update_option('wpinv_flush_permalinks', 1); |
|
| 56 | 56 | } |
| 57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
| 57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // Kickstart the plugin. |
| 67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
| 67 | +add_action('plugins_loaded', 'getpaid', -100); |
|
@@ -4,99 +4,99 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Displays an invoice. |
| 11 | 11 | * |
| 12 | 12 | * @param WPInv_Invoice $invoice. |
| 13 | 13 | */ |
| 14 | -function getpaid_invoice( $invoice ) { |
|
| 15 | - if ( ! empty( $invoice ) ) { |
|
| 16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
| 14 | +function getpaid_invoice($invoice) { |
|
| 15 | + if (!empty($invoice)) { |
|
| 16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
| 19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Displays the invoice footer. |
| 23 | 23 | */ |
| 24 | -function getpaid_invoice_footer( $invoice ) { |
|
| 25 | - if ( ! empty( $invoice ) ) { |
|
| 26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
| 24 | +function getpaid_invoice_footer($invoice) { |
|
| 25 | + if (!empty($invoice)) { |
|
| 26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
| 29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Displays the invoice top bar. |
| 33 | 33 | */ |
| 34 | -function getpaid_invoice_header( $invoice ) { |
|
| 35 | - if ( ! empty( $invoice ) ) { |
|
| 36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
| 34 | +function getpaid_invoice_header($invoice) { |
|
| 35 | + if (!empty($invoice)) { |
|
| 36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
| 39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Displays actions on the left side of the header. |
| 43 | 43 | */ |
| 44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
| 45 | - if ( ! empty( $invoice ) ) { |
|
| 46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
| 44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
| 45 | + if (!empty($invoice)) { |
|
| 46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
| 49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Displays actions on the right side of the invoice top bar. |
| 53 | 53 | */ |
| 54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
| 55 | - if ( ! empty( $invoice ) ) { |
|
| 56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
| 54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
| 55 | + if (!empty($invoice)) { |
|
| 56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
| 59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Displays the invoice title, logo etc. |
| 63 | 63 | */ |
| 64 | -function getpaid_invoice_details_top( $invoice ) { |
|
| 65 | - if ( ! empty( $invoice ) ) { |
|
| 66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
| 64 | +function getpaid_invoice_details_top($invoice) { |
|
| 65 | + if (!empty($invoice)) { |
|
| 66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
| 69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Displays the company logo. |
| 73 | 73 | */ |
| 74 | -function getpaid_invoice_logo( $invoice ) { |
|
| 75 | - if ( ! empty( $invoice ) ) { |
|
| 76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
| 74 | +function getpaid_invoice_logo($invoice) { |
|
| 75 | + if (!empty($invoice)) { |
|
| 76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
| 79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Displays the type of invoice. |
| 83 | 83 | */ |
| 84 | -function getpaid_invoice_type( $invoice ) { |
|
| 85 | - if ( ! empty( $invoice ) ) { |
|
| 86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
| 84 | +function getpaid_invoice_type($invoice) { |
|
| 85 | + if (!empty($invoice)) { |
|
| 86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
| 89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Displays the invoice details. |
| 93 | 93 | */ |
| 94 | -function getpaid_invoice_details_main( $invoice ) { |
|
| 95 | - if ( ! empty( $invoice ) ) { |
|
| 96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
| 94 | +function getpaid_invoice_details_main($invoice) { |
|
| 95 | + if (!empty($invoice)) { |
|
| 96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
| 99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 127 | 127 | */ |
| 128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
| 128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 141 | 141 | */ |
| 142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | 151 | function wpinv_template_path() { |
| 152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
| 152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | 160 | function wpinv_get_theme_template_dir_name() { |
| 161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -170,58 +170,58 @@ discard block |
||
| 170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
| 171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 172 | 172 | */ |
| 173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
| 173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
| 178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
| 178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
| 179 | 179 | |
| 180 | 180 | // Setup possible parts |
| 181 | 181 | $templates = array(); |
| 182 | - if ( isset( $name ) ) { |
|
| 182 | + if (isset($name)) { |
|
| 183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
| 184 | 184 | } |
| 185 | 185 | $templates[] = $slug . '.php'; |
| 186 | 186 | |
| 187 | 187 | // Allow template parts to be filtered |
| 188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 188 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
| 189 | 189 | |
| 190 | 190 | // Return the part that is found |
| 191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 191 | + return wpinv_locate_tmpl($templates, $load, false); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
| 194 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
| 195 | 195 | // No file found yet |
| 196 | 196 | $located = false; |
| 197 | 197 | |
| 198 | 198 | // Try to find a template file |
| 199 | - foreach ( (array)$template_names as $template_name ) { |
|
| 199 | + foreach ((array) $template_names as $template_name) { |
|
| 200 | 200 | |
| 201 | 201 | // Continue if template is empty |
| 202 | - if ( empty( $template_name ) ) { |
|
| 202 | + if (empty($template_name)) { |
|
| 203 | 203 | continue; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Trim off any slashes from the template name |
| 207 | - $template_name = ltrim( $template_name, '/' ); |
|
| 207 | + $template_name = ltrim($template_name, '/'); |
|
| 208 | 208 | |
| 209 | 209 | // try locating this template file by looping through the template paths |
| 210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 210 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
| 211 | 211 | |
| 212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
| 212 | + if (file_exists($template_path . $template_name)) { |
|
| 213 | 213 | $located = $template_path . $template_name; |
| 214 | 214 | break; |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( ! empty( $located ) ) { |
|
| 218 | + if (!empty($located)) { |
|
| 219 | 219 | break; |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
| 224 | - load_template( $located, $require_once ); |
|
| 223 | + if ((true == $load) && !empty($located)) { |
|
| 224 | + load_template($located, $require_once); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return $located; |
@@ -231,73 +231,73 @@ discard block |
||
| 231 | 231 | $template_dir = wpinv_get_theme_template_dir_name(); |
| 232 | 232 | |
| 233 | 233 | $file_paths = array( |
| 234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 234 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
| 235 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
| 236 | 236 | 100 => wpinv_get_templates_dir(), |
| 237 | 237 | ); |
| 238 | 238 | |
| 239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 239 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
| 240 | 240 | |
| 241 | 241 | // sort the file paths based on priority |
| 242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 242 | + ksort($file_paths, SORT_NUMERIC); |
|
| 243 | 243 | |
| 244 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 244 | + return array_map('trailingslashit', $file_paths); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | function wpinv_checkout_meta_tags() { |
| 248 | 248 | |
| 249 | 249 | $pages = array(); |
| 250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 250 | + $pages[] = wpinv_get_option('success_page'); |
|
| 251 | + $pages[] = wpinv_get_option('failure_page'); |
|
| 252 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
| 253 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
| 254 | 254 | |
| 255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
| 255 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
| 256 | 256 | return; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
| 260 | 260 | } |
| 261 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
| 261 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
| 262 | 262 | |
| 263 | -function wpinv_add_body_classes( $class ) { |
|
| 264 | - $classes = (array)$class; |
|
| 263 | +function wpinv_add_body_classes($class) { |
|
| 264 | + $classes = (array) $class; |
|
| 265 | 265 | |
| 266 | - if ( wpinv_is_checkout() ) { |
|
| 266 | + if (wpinv_is_checkout()) { |
|
| 267 | 267 | $classes[] = 'wpinv-checkout'; |
| 268 | 268 | $classes[] = 'wpinv-page'; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ( wpinv_is_success_page() ) { |
|
| 271 | + if (wpinv_is_success_page()) { |
|
| 272 | 272 | $classes[] = 'wpinv-success'; |
| 273 | 273 | $classes[] = 'wpinv-page'; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
| 276 | + if (wpinv_is_failed_transaction_page()) { |
|
| 277 | 277 | $classes[] = 'wpinv-failed-transaction'; |
| 278 | 278 | $classes[] = 'wpinv-page'; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( wpinv_is_invoice_history_page() ) { |
|
| 281 | + if (wpinv_is_invoice_history_page()) { |
|
| 282 | 282 | $classes[] = 'wpinv-history'; |
| 283 | 283 | $classes[] = 'wpinv-page'; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
| 286 | + if (wpinv_is_subscriptions_history_page()) { |
|
| 287 | 287 | $classes[] = 'wpinv-subscription'; |
| 288 | 288 | $classes[] = 'wpinv-page'; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - if ( wpinv_is_test_mode() ) { |
|
| 291 | + if (wpinv_is_test_mode()) { |
|
| 292 | 292 | $classes[] = 'wpinv-test-mode'; |
| 293 | 293 | $classes[] = 'wpinv-page'; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - return array_unique( $classes ); |
|
| 296 | + return array_unique($classes); |
|
| 297 | 297 | } |
| 298 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
| 298 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
| 299 | 299 | |
| 300 | -function wpinv_html_select( $args = array() ) { |
|
| 300 | +function wpinv_html_select($args = array()) { |
|
| 301 | 301 | $defaults = array( |
| 302 | 302 | 'options' => array(), |
| 303 | 303 | 'name' => null, |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | 'selected' => 0, |
| 307 | 307 | 'placeholder' => null, |
| 308 | 308 | 'multiple' => false, |
| 309 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
| 310 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
| 309 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
| 310 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
| 311 | 311 | 'data' => array(), |
| 312 | 312 | 'onchange' => null, |
| 313 | 313 | 'required' => false, |
@@ -315,79 +315,79 @@ discard block |
||
| 315 | 315 | 'readonly' => false, |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - $args = wp_parse_args( $args, $defaults ); |
|
| 318 | + $args = wp_parse_args($args, $defaults); |
|
| 319 | 319 | |
| 320 | 320 | $attrs = array( |
| 321 | 321 | 'name' => $args['name'], |
| 322 | 322 | 'id' => $args['id'], |
| 323 | - 'class' => 'wpinv-select ' . implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ), |
|
| 324 | - 'multiple' => ! empty( $args['multiple'] ), |
|
| 325 | - 'readonly' => ! empty( $args['readonly'] ), |
|
| 326 | - 'disabled' => ! empty( $args['disabled'] ), |
|
| 327 | - 'required' => ! empty( $args['required'] ), |
|
| 328 | - 'onchange' => ! empty( $args['onchange'] ), |
|
| 323 | + 'class' => 'wpinv-select ' . implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))), |
|
| 324 | + 'multiple' => !empty($args['multiple']), |
|
| 325 | + 'readonly' => !empty($args['readonly']), |
|
| 326 | + 'disabled' => !empty($args['disabled']), |
|
| 327 | + 'required' => !empty($args['required']), |
|
| 328 | + 'onchange' => !empty($args['onchange']), |
|
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | - if ( $args['placeholder'] ) { |
|
| 331 | + if ($args['placeholder']) { |
|
| 332 | 332 | $attrs['data-placeholder'] = $args['placeholder']; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if ( $args['onchange'] ) { |
|
| 335 | + if ($args['onchange']) { |
|
| 336 | 336 | $attrs['onchange'] = $args['onchange']; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - foreach ( $args['data'] as $key => $value ) { |
|
| 339 | + foreach ($args['data'] as $key => $value) { |
|
| 340 | 340 | $attrs["data-$key"] = $value; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | echo '<select '; |
| 344 | 344 | |
| 345 | - foreach ( $attrs as $attr => $value ) { |
|
| 345 | + foreach ($attrs as $attr => $value) { |
|
| 346 | 346 | |
| 347 | - if ( false === $value ) { |
|
| 347 | + if (false === $value) { |
|
| 348 | 348 | continue; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if ( true === $value ) { |
|
| 352 | - echo ' ' . esc_attr( $attr ); |
|
| 351 | + if (true === $value) { |
|
| 352 | + echo ' ' . esc_attr($attr); |
|
| 353 | 353 | } else { |
| 354 | - echo ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; |
|
| 354 | + echo ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"'; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | echo '>'; |
| 360 | 360 | |
| 361 | - if ( $args['show_option_all'] ) { |
|
| 362 | - if ( $args['multiple'] ) { |
|
| 363 | - $selected = in_array( 0, $args['selected'] ); |
|
| 361 | + if ($args['show_option_all']) { |
|
| 362 | + if ($args['multiple']) { |
|
| 363 | + $selected = in_array(0, $args['selected']); |
|
| 364 | 364 | } else { |
| 365 | - $selected = empty( $args['selected'] ); |
|
| 365 | + $selected = empty($args['selected']); |
|
| 366 | 366 | } |
| 367 | - echo '<option value="all"' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
| 367 | + echo '<option value="all"' . selected($selected, true, false) . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - if ( ! empty( $args['options'] ) ) { |
|
| 370 | + if (!empty($args['options'])) { |
|
| 371 | 371 | |
| 372 | - if ( $args['show_option_none'] ) { |
|
| 373 | - if ( $args['multiple'] ) { |
|
| 374 | - $selected = in_array( '', $args['selected'], true ); |
|
| 372 | + if ($args['show_option_none']) { |
|
| 373 | + if ($args['multiple']) { |
|
| 374 | + $selected = in_array('', $args['selected'], true); |
|
| 375 | 375 | } else { |
| 376 | 376 | $selected = $args['selected'] === ''; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - echo '<option value=""' . selected( $selected, true, false ) . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
| 379 | + echo '<option value=""' . selected($selected, true, false) . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - foreach ( $args['options'] as $key => $option ) { |
|
| 382 | + foreach ($args['options'] as $key => $option) { |
|
| 383 | 383 | |
| 384 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
| 385 | - $selected = in_array( $key, $args['selected'], true ); |
|
| 384 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
| 385 | + $selected = in_array($key, $args['selected'], true); |
|
| 386 | 386 | } else { |
| 387 | 387 | $selected = $args['selected'] === $key; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - echo '<option value="' . esc_attr( $key ) . '"' . selected( $selected, true, false ) . '>' . esc_html( $option ) . '</option>'; |
|
| 390 | + echo '<option value="' . esc_attr($key) . '"' . selected($selected, true, false) . '>' . esc_html($option) . '</option>'; |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | -function wpinv_item_dropdown( $args = array() ) { |
|
| 398 | +function wpinv_item_dropdown($args = array()) { |
|
| 399 | 399 | $defaults = array( |
| 400 | 400 | 'name' => 'wpi_item', |
| 401 | 401 | 'id' => 'wpi_item', |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | 'multiple' => false, |
| 404 | 404 | 'selected' => 0, |
| 405 | 405 | 'number' => -1, |
| 406 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
| 407 | - 'data' => array( 'search-type' => 'item' ), |
|
| 406 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
| 407 | + 'data' => array('search-type' => 'item'), |
|
| 408 | 408 | 'show_option_all' => false, |
| 409 | 409 | 'show_option_none' => false, |
| 410 | 410 | 'show_recurring' => false, |
| 411 | 411 | ); |
| 412 | 412 | |
| 413 | - $args = wp_parse_args( $args, $defaults ); |
|
| 413 | + $args = wp_parse_args($args, $defaults); |
|
| 414 | 414 | |
| 415 | 415 | $item_args = array( |
| 416 | 416 | 'post_type' => 'wpi_item', |
@@ -428,40 +428,40 @@ discard block |
||
| 428 | 428 | ), |
| 429 | 429 | ); |
| 430 | 430 | |
| 431 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
| 431 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
| 432 | 432 | |
| 433 | - $items = get_posts( $item_args ); |
|
| 433 | + $items = get_posts($item_args); |
|
| 434 | 434 | $options = array(); |
| 435 | - if ( $items ) { |
|
| 436 | - foreach ( $items as $item ) { |
|
| 437 | - $title = esc_html( $item->post_title ); |
|
| 435 | + if ($items) { |
|
| 436 | + foreach ($items as $item) { |
|
| 437 | + $title = esc_html($item->post_title); |
|
| 438 | 438 | |
| 439 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
| 440 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 439 | + if (!empty($args['show_recurring'])) { |
|
| 440 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - $options[ absint( $item->ID ) ] = $title; |
|
| 443 | + $options[absint($item->ID)] = $title; |
|
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // This ensures that any selected items are included in the drop down |
| 448 | - if ( is_array( $args['selected'] ) ) { |
|
| 449 | - foreach ( $args['selected'] as $item ) { |
|
| 450 | - if ( ! in_array( $item, $options ) ) { |
|
| 451 | - $title = get_the_title( $item ); |
|
| 452 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
| 453 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
| 448 | + if (is_array($args['selected'])) { |
|
| 449 | + foreach ($args['selected'] as $item) { |
|
| 450 | + if (!in_array($item, $options)) { |
|
| 451 | + $title = get_the_title($item); |
|
| 452 | + if (!empty($args['show_recurring'])) { |
|
| 453 | + $title .= wpinv_get_item_suffix($item, false); |
|
| 454 | 454 | } |
| 455 | - $options[ $item ] = $title; |
|
| 455 | + $options[$item] = $title; |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
| 459 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
| 460 | - $title = get_the_title( $args['selected'] ); |
|
| 461 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
| 462 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
| 458 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
| 459 | + if (!in_array($args['selected'], $options)) { |
|
| 460 | + $title = get_the_title($args['selected']); |
|
| 461 | + if (!empty($args['show_recurring'])) { |
|
| 462 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
| 463 | 463 | } |
| 464 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
| 464 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
@@ -497,16 +497,16 @@ discard block |
||
| 497 | 497 | ); |
| 498 | 498 | |
| 499 | 499 | $options = array(); |
| 500 | - if ( $items ) { |
|
| 501 | - foreach ( $items as $item ) { |
|
| 502 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
| 500 | + if ($items) { |
|
| 501 | + foreach ($items as $item) { |
|
| 502 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | return $options; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | -function wpinv_html_checkbox( $args = array() ) { |
|
| 509 | +function wpinv_html_checkbox($args = array()) { |
|
| 510 | 510 | $defaults = array( |
| 511 | 511 | 'name' => null, |
| 512 | 512 | 'current' => null, |
@@ -517,17 +517,17 @@ discard block |
||
| 517 | 517 | ), |
| 518 | 518 | ); |
| 519 | 519 | |
| 520 | - $args = wp_parse_args( $args, $defaults ); |
|
| 520 | + $args = wp_parse_args($args, $defaults); |
|
| 521 | 521 | |
| 522 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 522 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 523 | 523 | $attr = ''; |
| 524 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
| 524 | + if (!empty($args['options']['disabled'])) { |
|
| 525 | 525 | $attr .= ' disabled="disabled"'; |
| 526 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
| 526 | + } elseif (!empty($args['options']['readonly'])) { |
|
| 527 | 527 | $attr .= ' readonly'; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
| 530 | + $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
| 531 | 531 | |
| 532 | 532 | return $output; |
| 533 | 533 | } |
@@ -535,34 +535,34 @@ discard block |
||
| 535 | 535 | /** |
| 536 | 536 | * Displays a hidden field. |
| 537 | 537 | */ |
| 538 | -function getpaid_hidden_field( $name, $value ) { |
|
| 539 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' />"; |
|
| 538 | +function getpaid_hidden_field($name, $value) { |
|
| 539 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' />"; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
| 543 | 543 | * Displays a submit field. |
| 544 | 544 | */ |
| 545 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
| 546 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
| 545 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
| 546 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | -function wpinv_html_text( $args = array() ) { |
|
| 549 | +function wpinv_html_text($args = array()) { |
|
| 550 | 550 | // Backwards compatibility |
| 551 | - if ( func_num_args() > 1 ) { |
|
| 551 | + if (func_num_args() > 1) { |
|
| 552 | 552 | $args = func_get_args(); |
| 553 | 553 | |
| 554 | 554 | $name = $args[0]; |
| 555 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
| 556 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
| 557 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
| 555 | + $value = isset($args[1]) ? $args[1] : ''; |
|
| 556 | + $label = isset($args[2]) ? $args[2] : ''; |
|
| 557 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | $defaults = array( |
| 561 | 561 | 'id' => '', |
| 562 | - 'name' => isset( $name ) ? $name : 'text', |
|
| 563 | - 'value' => isset( $value ) ? $value : null, |
|
| 564 | - 'label' => isset( $label ) ? $label : null, |
|
| 565 | - 'desc' => isset( $desc ) ? $desc : null, |
|
| 562 | + 'name' => isset($name) ? $name : 'text', |
|
| 563 | + 'value' => isset($value) ? $value : null, |
|
| 564 | + 'label' => isset($label) ? $label : null, |
|
| 565 | + 'desc' => isset($desc) ? $desc : null, |
|
| 566 | 566 | 'placeholder' => '', |
| 567 | 567 | 'class' => 'regular-text', |
| 568 | 568 | 'disabled' => false, |
@@ -572,41 +572,41 @@ discard block |
||
| 572 | 572 | 'data' => false, |
| 573 | 573 | ); |
| 574 | 574 | |
| 575 | - $args = wp_parse_args( $args, $defaults ); |
|
| 575 | + $args = wp_parse_args($args, $defaults); |
|
| 576 | 576 | |
| 577 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 577 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 578 | 578 | $options = ''; |
| 579 | - if ( $args['required'] ) { |
|
| 579 | + if ($args['required']) { |
|
| 580 | 580 | $options .= ' required="required"'; |
| 581 | 581 | } |
| 582 | - if ( $args['readonly'] ) { |
|
| 582 | + if ($args['readonly']) { |
|
| 583 | 583 | $options .= ' readonly'; |
| 584 | 584 | } |
| 585 | - if ( $args['readonly'] ) { |
|
| 585 | + if ($args['readonly']) { |
|
| 586 | 586 | $options .= ' readonly'; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | $data = ''; |
| 590 | - if ( ! empty( $args['data'] ) ) { |
|
| 591 | - foreach ( $args['data'] as $key => $value ) { |
|
| 592 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 590 | + if (!empty($args['data'])) { |
|
| 591 | + foreach ($args['data'] as $key => $value) { |
|
| 592 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
| 593 | 593 | } |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 597 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 598 | - if ( ! empty( $args['desc'] ) ) { |
|
| 599 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 596 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 597 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 598 | + if (!empty($args['desc'])) { |
|
| 599 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
| 602 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
| 603 | 603 | |
| 604 | 604 | $output .= '</span>'; |
| 605 | 605 | |
| 606 | 606 | return $output; |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | -function wpinv_html_textarea( $args = array() ) { |
|
| 609 | +function wpinv_html_textarea($args = array()) { |
|
| 610 | 610 | $defaults = array( |
| 611 | 611 | 'name' => 'textarea', |
| 612 | 612 | 'value' => null, |
@@ -617,31 +617,31 @@ discard block |
||
| 617 | 617 | 'placeholder' => '', |
| 618 | 618 | ); |
| 619 | 619 | |
| 620 | - $args = wp_parse_args( $args, $defaults ); |
|
| 620 | + $args = wp_parse_args($args, $defaults); |
|
| 621 | 621 | |
| 622 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 622 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 623 | 623 | $disabled = ''; |
| 624 | - if ( $args['disabled'] ) { |
|
| 624 | + if ($args['disabled']) { |
|
| 625 | 625 | $disabled = ' disabled="disabled"'; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 629 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 630 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
| 628 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 629 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 630 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
| 631 | 631 | |
| 632 | - if ( ! empty( $args['desc'] ) ) { |
|
| 633 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 632 | + if (!empty($args['desc'])) { |
|
| 633 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 634 | 634 | } |
| 635 | 635 | $output .= '</span>'; |
| 636 | 636 | |
| 637 | 637 | return $output; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
| 640 | +function wpinv_html_ajax_user_search($args = array()) { |
|
| 641 | 641 | $defaults = array( |
| 642 | 642 | 'name' => 'user_id', |
| 643 | 643 | 'value' => null, |
| 644 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
| 644 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
| 645 | 645 | 'label' => null, |
| 646 | 646 | 'desc' => null, |
| 647 | 647 | 'class' => '', |
@@ -650,13 +650,13 @@ discard block |
||
| 650 | 650 | 'data' => false, |
| 651 | 651 | ); |
| 652 | 652 | |
| 653 | - $args = wp_parse_args( $args, $defaults ); |
|
| 653 | + $args = wp_parse_args($args, $defaults); |
|
| 654 | 654 | |
| 655 | 655 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
| 656 | 656 | |
| 657 | 657 | $output = '<span class="wpinv_user_search_wrap">'; |
| 658 | - $output .= wpinv_html_text( $args ); |
|
| 659 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
| 658 | + $output .= wpinv_html_text($args); |
|
| 659 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
| 660 | 660 | $output .= '</span>'; |
| 661 | 661 | |
| 662 | 662 | return $output; |
@@ -667,44 +667,44 @@ discard block |
||
| 667 | 667 | * |
| 668 | 668 | * @param string $template the template that is currently being used. |
| 669 | 669 | */ |
| 670 | -function wpinv_template( $template ) { |
|
| 670 | +function wpinv_template($template) { |
|
| 671 | 671 | global $post; |
| 672 | 672 | |
| 673 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
| 673 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
| 674 | 674 | |
| 675 | 675 | // If the user can view this invoice, display it. |
| 676 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
| 676 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
| 677 | 677 | |
| 678 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
| 678 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
| 679 | 679 | |
| 680 | 680 | // Else display an error message. |
| 681 | 681 | } else { |
| 682 | 682 | |
| 683 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
| 683 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
| 684 | 684 | |
| 685 | 685 | } |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | return $template; |
| 689 | 689 | } |
| 690 | -add_filter( 'template_include', 'wpinv_template', 1000, 1 ); |
|
| 690 | +add_filter('template_include', 'wpinv_template', 1000, 1); |
|
| 691 | 691 | |
| 692 | 692 | function wpinv_get_business_address() { |
| 693 | 693 | $business_address = wpinv_store_address(); |
| 694 | - $business_address = ! empty( $business_address ) ? wp_kses_post( wpautop( $business_address ) ) : ''; |
|
| 694 | + $business_address = !empty($business_address) ? wp_kses_post(wpautop($business_address)) : ''; |
|
| 695 | 695 | |
| 696 | 696 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
| 697 | 697 | |
| 698 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
| 698 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | /** |
| 702 | 702 | * Displays the company address. |
| 703 | 703 | */ |
| 704 | 704 | function wpinv_display_from_address() { |
| 705 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
| 705 | + wpinv_get_template('invoice/company-address.php'); |
|
| 706 | 706 | } |
| 707 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
| 707 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
| 708 | 708 | |
| 709 | 709 | /** |
| 710 | 710 | * Generates a watermark text for an invoice. |
@@ -712,9 +712,9 @@ discard block |
||
| 712 | 712 | * @param WPInv_Invoice $invoice |
| 713 | 713 | * @return string |
| 714 | 714 | */ |
| 715 | -function wpinv_watermark( $invoice ) { |
|
| 716 | - $watermark = wpinv_get_watermark( $invoice ); |
|
| 717 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
| 715 | +function wpinv_watermark($invoice) { |
|
| 716 | + $watermark = wpinv_get_watermark($invoice); |
|
| 717 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -723,37 +723,37 @@ discard block |
||
| 723 | 723 | * @param WPInv_Invoice $invoice |
| 724 | 724 | * @return string |
| 725 | 725 | */ |
| 726 | -function wpinv_get_watermark( $invoice ) { |
|
| 726 | +function wpinv_get_watermark($invoice) { |
|
| 727 | 727 | return $invoice->get_status_nicename(); |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
| 731 | 731 | * @deprecated |
| 732 | 732 | */ |
| 733 | -function wpinv_display_invoice_details( $invoice ) { |
|
| 734 | - return getpaid_invoice_meta( $invoice ); |
|
| 733 | +function wpinv_display_invoice_details($invoice) { |
|
| 734 | + return getpaid_invoice_meta($invoice); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
| 738 | 738 | * Displays invoice meta. |
| 739 | 739 | */ |
| 740 | -function getpaid_invoice_meta( $invoice ) { |
|
| 740 | +function getpaid_invoice_meta($invoice) { |
|
| 741 | 741 | |
| 742 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 742 | + $invoice = new WPInv_Invoice($invoice); |
|
| 743 | 743 | |
| 744 | 744 | // Ensure that we have an invoice. |
| 745 | - if ( 0 == $invoice->get_id() ) { |
|
| 745 | + if (0 == $invoice->get_id()) { |
|
| 746 | 746 | return; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // Get the invoice meta. |
| 750 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
| 750 | + $meta = getpaid_get_invoice_meta($invoice); |
|
| 751 | 751 | |
| 752 | 752 | // Display the meta. |
| 753 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
| 753 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
| 754 | 754 | |
| 755 | 755 | } |
| 756 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
| 756 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
| 757 | 757 | |
| 758 | 758 | /** |
| 759 | 759 | * Retrieves the address markup to use on Invoices. |
@@ -765,29 +765,29 @@ discard block |
||
| 765 | 765 | * @param string $separator How to separate address lines. |
| 766 | 766 | * @return string |
| 767 | 767 | */ |
| 768 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
| 768 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
| 769 | 769 | |
| 770 | 770 | // Retrieve the address markup... |
| 771 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
| 772 | - $format = wpinv_get_full_address_format( $country ); |
|
| 771 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
| 772 | + $format = wpinv_get_full_address_format($country); |
|
| 773 | 773 | |
| 774 | 774 | // ... and the replacements. |
| 775 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
| 775 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
| 776 | 776 | |
| 777 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
| 777 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
| 778 | 778 | |
| 779 | 779 | // Remove unavailable tags. |
| 780 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
| 780 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
| 781 | 781 | |
| 782 | 782 | // Clean up white space. |
| 783 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 784 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
| 783 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
| 784 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
| 785 | 785 | |
| 786 | 786 | // Break newlines apart and remove empty lines/trim commas and white space. |
| 787 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 787 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
| 788 | 788 | |
| 789 | 789 | // Add html breaks. |
| 790 | - $formatted_address = implode( $separator, $formatted_address ); |
|
| 790 | + $formatted_address = implode($separator, $formatted_address); |
|
| 791 | 791 | |
| 792 | 792 | // We're done! |
| 793 | 793 | return $formatted_address; |
@@ -799,118 +799,118 @@ discard block |
||
| 799 | 799 | * |
| 800 | 800 | * @param WPInv_Invoice $invoice |
| 801 | 801 | */ |
| 802 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
| 803 | - if ( ! empty( $invoice ) ) { |
|
| 804 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
| 802 | +function wpinv_display_to_address($invoice = 0) { |
|
| 803 | + if (!empty($invoice)) { |
|
| 804 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
| 807 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
| 808 | 808 | |
| 809 | 809 | |
| 810 | 810 | /** |
| 811 | 811 | * Displays invoice line items. |
| 812 | 812 | */ |
| 813 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
| 813 | +function wpinv_display_line_items($invoice_id = 0) { |
|
| 814 | 814 | |
| 815 | 815 | // Prepare the invoice. |
| 816 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 816 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 817 | 817 | |
| 818 | 818 | // Abort if there is no invoice. |
| 819 | - if ( 0 == $invoice->get_id() ) { |
|
| 819 | + if (0 == $invoice->get_id()) { |
|
| 820 | 820 | return; |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | // Line item columns. |
| 824 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
| 825 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
| 824 | + $columns = getpaid_invoice_item_columns($invoice); |
|
| 825 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
| 826 | 826 | |
| 827 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
| 827 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
| 828 | 828 | } |
| 829 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
| 829 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
| 830 | 830 | |
| 831 | 831 | /** |
| 832 | 832 | * Displays invoice subscriptions. |
| 833 | 833 | * |
| 834 | 834 | * @param WPInv_Invoice $invoice |
| 835 | 835 | */ |
| 836 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
| 836 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
| 837 | 837 | |
| 838 | 838 | // Subscriptions. |
| 839 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 839 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 840 | 840 | |
| 841 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
| 841 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
| 842 | 842 | return; |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 845 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
| 846 | 846 | |
| 847 | 847 | // Display related subscriptions. |
| 848 | - if ( is_array( $subscriptions ) ) { |
|
| 849 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
| 850 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
| 848 | + if (is_array($subscriptions)) { |
|
| 849 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
| 850 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
| 854 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
| 855 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
| 853 | + if ($main_subscription->get_total_payments() > 1) { |
|
| 854 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
| 855 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | } |
| 859 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
| 860 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
| 859 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
| 860 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
| 861 | 861 | |
| 862 | 862 | /** |
| 863 | 863 | * Displays invoice notices on invoices. |
| 864 | 864 | */ |
| 865 | 865 | function wpinv_display_invoice_notice() { |
| 866 | 866 | |
| 867 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 868 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 867 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 868 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 869 | 869 | |
| 870 | - if ( empty( $label ) && empty( $notice ) ) { |
|
| 870 | + if (empty($label) && empty($notice)) { |
|
| 871 | 871 | return; |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
| 875 | 875 | |
| 876 | - if ( ! empty( $label ) ) { |
|
| 877 | - echo "<h5>" . esc_html( $label ) . "</h5>"; |
|
| 876 | + if (!empty($label)) { |
|
| 877 | + echo "<h5>" . esc_html($label) . "</h5>"; |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - if ( ! empty( $notice ) ) { |
|
| 881 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
| 880 | + if (!empty($notice)) { |
|
| 881 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | echo '</div>'; |
| 885 | 885 | } |
| 886 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
| 886 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
| 887 | 887 | |
| 888 | 888 | /** |
| 889 | 889 | * @param WPInv_Invoice $invoice |
| 890 | 890 | */ |
| 891 | -function wpinv_display_invoice_notes( $invoice ) { |
|
| 891 | +function wpinv_display_invoice_notes($invoice) { |
|
| 892 | 892 | |
| 893 | 893 | // Retrieve the notes. |
| 894 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
| 894 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
| 895 | 895 | |
| 896 | 896 | // Abort if we have non. |
| 897 | - if ( empty( $notes ) ) { |
|
| 897 | + if (empty($notes)) { |
|
| 898 | 898 | return; |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | // Echo the note. |
| 902 | 902 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
| 903 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__( 'Notes', 'invoicing' ) . '</h2>'; |
|
| 903 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . esc_html__('Notes', 'invoicing') . '</h2>'; |
|
| 904 | 904 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
| 905 | 905 | |
| 906 | - foreach ( $notes as $note ) { |
|
| 907 | - wpinv_get_invoice_note_line_item( $note ); |
|
| 906 | + foreach ($notes as $note) { |
|
| 907 | + wpinv_get_invoice_note_line_item($note); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | echo '</ul>'; |
| 911 | 911 | echo '</div>'; |
| 912 | 912 | } |
| 913 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
| 913 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
| 914 | 914 | |
| 915 | 915 | /** |
| 916 | 916 | * Loads scripts on our invoice templates. |
@@ -918,37 +918,37 @@ discard block |
||
| 918 | 918 | function wpinv_display_style() { |
| 919 | 919 | |
| 920 | 920 | // Make sure that all scripts have been loaded. |
| 921 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
| 922 | - do_action( 'wp_enqueue_scripts' ); |
|
| 921 | + if (!did_action('wp_enqueue_scripts')) { |
|
| 922 | + do_action('wp_enqueue_scripts'); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | // Add global styles. |
| 926 | - if ( wp_is_block_theme() ) { |
|
| 927 | - wp_print_styles( 'global-styles' ); |
|
| 926 | + if (wp_is_block_theme()) { |
|
| 927 | + wp_print_styles('global-styles'); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | // Register the invoices style. |
| 931 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
| 931 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
| 932 | 932 | |
| 933 | 933 | // Load required styles |
| 934 | - wp_print_styles( 'wpinv-single-style' ); |
|
| 935 | - wp_print_styles( 'ayecode-ui' ); |
|
| 934 | + wp_print_styles('wpinv-single-style'); |
|
| 935 | + wp_print_styles('ayecode-ui'); |
|
| 936 | 936 | |
| 937 | 937 | // Maybe load custom css. |
| 938 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
| 938 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
| 939 | 939 | |
| 940 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
| 941 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
| 942 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
| 940 | + if (isset($custom_css) && !empty($custom_css)) { |
|
| 941 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
| 942 | + $custom_css = str_replace('>', '>', $custom_css); |
|
| 943 | 943 | echo '<style type="text/css">'; |
| 944 | - echo wp_kses_post( $custom_css ); |
|
| 944 | + echo wp_kses_post($custom_css); |
|
| 945 | 945 | echo '</style>'; |
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | wp_site_icon(); |
| 949 | 949 | } |
| 950 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
| 951 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
| 950 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
| 951 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
| 952 | 952 | |
| 953 | 953 | |
| 954 | 954 | /** |
@@ -960,41 +960,41 @@ discard block |
||
| 960 | 960 | // Retrieve the current invoice. |
| 961 | 961 | $invoice_id = getpaid_get_current_invoice_id(); |
| 962 | 962 | |
| 963 | - if ( empty( $invoice_id ) ) { |
|
| 963 | + if (empty($invoice_id)) { |
|
| 964 | 964 | |
| 965 | 965 | return aui()->alert( |
| 966 | 966 | array( |
| 967 | 967 | 'type' => 'warning', |
| 968 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
| 968 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
| 969 | 969 | ) |
| 970 | 970 | ); |
| 971 | 971 | |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | // Can the user view this invoice? |
| 975 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
| 975 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
| 976 | 976 | |
| 977 | 977 | return aui()->alert( |
| 978 | 978 | array( |
| 979 | 979 | 'type' => 'warning', |
| 980 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
| 980 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
| 981 | 981 | ) |
| 982 | 982 | ); |
| 983 | 983 | |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | // Ensure that it is not yet paid for. |
| 987 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 987 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 988 | 988 | |
| 989 | 989 | // Maybe mark it as viewed. |
| 990 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
| 990 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
| 991 | 991 | |
| 992 | - if ( $invoice->is_paid() ) { |
|
| 992 | + if ($invoice->is_paid()) { |
|
| 993 | 993 | |
| 994 | 994 | return aui()->alert( |
| 995 | 995 | array( |
| 996 | 996 | 'type' => 'success', |
| 997 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
| 997 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
| 998 | 998 | ) |
| 999 | 999 | ); |
| 1000 | 1000 | |
@@ -1004,15 +1004,15 @@ discard block |
||
| 1004 | 1004 | $wpi_checkout_id = $invoice_id; |
| 1005 | 1005 | |
| 1006 | 1006 | // Retrieve appropriate payment form. |
| 1007 | - $payment_form = new GetPaid_Payment_Form( wpinv_translate_post_id( $invoice->get_meta( 'force_payment_form' ) ) ); |
|
| 1008 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1007 | + $payment_form = new GetPaid_Payment_Form(wpinv_translate_post_id($invoice->get_meta('force_payment_form'))); |
|
| 1008 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1009 | 1009 | |
| 1010 | - if ( ! $payment_form->exists() ) { |
|
| 1010 | + if (!$payment_form->exists()) { |
|
| 1011 | 1011 | |
| 1012 | 1012 | return aui()->alert( |
| 1013 | 1013 | array( |
| 1014 | 1014 | 'type' => 'warning', |
| 1015 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
| 1015 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
| 1016 | 1016 | ) |
| 1017 | 1017 | ); |
| 1018 | 1018 | |
@@ -1021,29 +1021,29 @@ discard block |
||
| 1021 | 1021 | // Set the invoice. |
| 1022 | 1022 | $payment_form->invoice = $invoice; |
| 1023 | 1023 | |
| 1024 | - if ( ! $payment_form->is_default() ) { |
|
| 1024 | + if (!$payment_form->is_default()) { |
|
| 1025 | 1025 | |
| 1026 | 1026 | $items = array(); |
| 1027 | 1027 | $item_ids = array(); |
| 1028 | 1028 | |
| 1029 | - foreach ( $invoice->get_items() as $item ) { |
|
| 1030 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 1029 | + foreach ($invoice->get_items() as $item) { |
|
| 1030 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 1031 | 1031 | $item_ids[] = $item->get_id(); |
| 1032 | 1032 | $items[] = $item; |
| 1033 | 1033 | } |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 1037 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 1036 | + foreach ($payment_form->get_items() as $item) { |
|
| 1037 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 1038 | 1038 | $item_ids[] = $item->get_id(); |
| 1039 | 1039 | $items[] = $item; |
| 1040 | 1040 | } |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | - $payment_form->set_items( $items ); |
|
| 1043 | + $payment_form->set_items($items); |
|
| 1044 | 1044 | |
| 1045 | 1045 | } else { |
| 1046 | - $payment_form->set_items( $invoice->get_items() ); |
|
| 1046 | + $payment_form->set_items($invoice->get_items()); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | // Generate the html. |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | function wpinv_empty_cart_message() { |
| 1055 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1055 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
@@ -1070,76 +1070,76 @@ discard block |
||
| 1070 | 1070 | true |
| 1071 | 1071 | ); |
| 1072 | 1072 | } |
| 1073 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
| 1073 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
| 1074 | 1074 | |
| 1075 | 1075 | /** |
| 1076 | 1076 | * Filters the receipt page. |
| 1077 | 1077 | */ |
| 1078 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1078 | +function wpinv_filter_success_page_content($content) { |
|
| 1079 | 1079 | |
| 1080 | 1080 | // Maybe abort early. |
| 1081 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
| 1081 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
| 1082 | 1082 | return $content; |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | // Ensure this is our page. |
| 1086 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1086 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1087 | 1087 | |
| 1088 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
| 1089 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
| 1088 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
| 1089 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
| 1090 | 1090 | |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | return $content; |
| 1094 | 1094 | } |
| 1095 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1095 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1096 | 1096 | |
| 1097 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1098 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1097 | +function wpinv_invoice_link($invoice_id) { |
|
| 1098 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1099 | 1099 | |
| 1100 | - if ( empty( $invoice ) ) { |
|
| 1100 | + if (empty($invoice)) { |
|
| 1101 | 1101 | return null; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1104 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1105 | 1105 | |
| 1106 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1106 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 1110 | - if ( empty( $note ) ) { |
|
| 1109 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 1110 | + if (empty($note)) { |
|
| 1111 | 1111 | return null; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - if ( is_int( $note ) ) { |
|
| 1115 | - $note = get_comment( $note ); |
|
| 1114 | + if (is_int($note)) { |
|
| 1115 | + $note = get_comment($note); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 1118 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 1119 | 1119 | return null; |
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | - $note_classes = array( 'note' ); |
|
| 1123 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 1122 | + $note_classes = array('note'); |
|
| 1123 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 1124 | 1124 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
| 1125 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 1126 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 1125 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 1126 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 1127 | 1127 | |
| 1128 | 1128 | ob_start(); |
| 1129 | 1129 | ?> |
| 1130 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
| 1130 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
| 1131 | 1131 | <div class="note_content"> |
| 1132 | 1132 | |
| 1133 | - <?php echo wp_kses_post( wptexturize( $note->comment_content ) ); ?> |
|
| 1133 | + <?php echo wp_kses_post(wptexturize($note->comment_content)); ?> |
|
| 1134 | 1134 | |
| 1135 | - <?php if ( ! is_admin() ) : ?> |
|
| 1135 | + <?php if (!is_admin()) : ?> |
|
| 1136 | 1136 | <em class="small form-text text-muted mt-0"> |
| 1137 | 1137 | <?php |
| 1138 | 1138 | printf( |
| 1139 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
| 1140 | - esc_html( $note->comment_author ), |
|
| 1141 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
| 1142 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
| 1139 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
| 1140 | + esc_html($note->comment_author), |
|
| 1141 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
| 1142 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
| 1143 | 1143 | ); |
| 1144 | 1144 | ?> |
| 1145 | 1145 | </em> |
@@ -1147,21 +1147,21 @@ discard block |
||
| 1147 | 1147 | |
| 1148 | 1148 | </div> |
| 1149 | 1149 | |
| 1150 | - <?php if ( is_admin() ) : ?> |
|
| 1150 | + <?php if (is_admin()) : ?> |
|
| 1151 | 1151 | |
| 1152 | 1152 | <p class="meta px-4 py-2"> |
| 1153 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
| 1153 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
| 1154 | 1154 | <?php |
| 1155 | 1155 | printf( |
| 1156 | - esc_html__( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
| 1157 | - esc_html( $note->comment_author ), |
|
| 1158 | - esc_html( getpaid_format_date_value( $note->comment_date ) ), |
|
| 1159 | - esc_html( date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ) |
|
| 1156 | + esc_html__('%1$s - %2$s at %3$s', 'invoicing'), |
|
| 1157 | + esc_html($note->comment_author), |
|
| 1158 | + esc_html(getpaid_format_date_value($note->comment_date)), |
|
| 1159 | + esc_html(date_i18n(get_option('time_format'), strtotime($note->comment_date))) |
|
| 1160 | 1160 | ); |
| 1161 | 1161 | ?> |
| 1162 | 1162 | </abbr> |
| 1163 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
| 1164 | - <a href="#" class="delete_note" data-id="<?php echo esc_attr( $note->comment_ID ); ?>"><?php esc_html_e( 'Delete note', 'invoicing' ); ?></a> |
|
| 1163 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
| 1164 | + <a href="#" class="delete_note" data-id="<?php echo esc_attr($note->comment_ID); ?>"><?php esc_html_e('Delete note', 'invoicing'); ?></a> |
|
| 1165 | 1165 | <?php } ?> |
| 1166 | 1166 | </p> |
| 1167 | 1167 | |
@@ -1170,10 +1170,10 @@ discard block |
||
| 1170 | 1170 | </li> |
| 1171 | 1171 | <?php |
| 1172 | 1172 | $note_content = ob_get_clean(); |
| 1173 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 1173 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 1174 | 1174 | |
| 1175 | - if ( $echo ) { |
|
| 1176 | - echo wp_kses_post( $note_content ); |
|
| 1175 | + if ($echo) { |
|
| 1176 | + echo wp_kses_post($note_content); |
|
| 1177 | 1177 | } else { |
| 1178 | 1178 | return $note_content; |
| 1179 | 1179 | } |
@@ -1186,43 +1186,43 @@ discard block |
||
| 1186 | 1186 | * @return string |
| 1187 | 1187 | */ |
| 1188 | 1188 | function wpinv_get_policy_text() { |
| 1189 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
| 1189 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
| 1190 | 1190 | |
| 1191 | - $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) ); |
|
| 1191 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
| 1192 | 1192 | |
| 1193 | - if ( ! $privacy_page_id ) { |
|
| 1194 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
| 1193 | + if (!$privacy_page_id) { |
|
| 1194 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
| 1197 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
| 1198 | 1198 | |
| 1199 | 1199 | $find_replace = array( |
| 1200 | 1200 | '[wpinv_privacy_policy]' => $privacy_link, |
| 1201 | 1201 | ); |
| 1202 | 1202 | |
| 1203 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
| 1203 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
| 1204 | 1204 | |
| 1205 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
| 1205 | + return wp_kses_post(wpautop($privacy_text)); |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | function wpinv_oxygen_fix_conflict() { |
| 1209 | 1209 | global $ct_ignore_post_types; |
| 1210 | 1210 | |
| 1211 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
| 1211 | + if (!is_array($ct_ignore_post_types)) { |
|
| 1212 | 1212 | $ct_ignore_post_types = array(); |
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
| 1215 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
| 1216 | 1216 | |
| 1217 | - foreach ( $post_types as $post_type ) { |
|
| 1217 | + foreach ($post_types as $post_type) { |
|
| 1218 | 1218 | $ct_ignore_post_types[] = $post_type; |
| 1219 | 1219 | |
| 1220 | 1220 | // Ignore post type |
| 1221 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
| 1221 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 1225 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
| 1224 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
| 1225 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
@@ -1230,10 +1230,10 @@ discard block |
||
| 1230 | 1230 | * |
| 1231 | 1231 | * @param GetPaid_Payment_Form $form |
| 1232 | 1232 | */ |
| 1233 | -function getpaid_display_payment_form( $form ) { |
|
| 1233 | +function getpaid_display_payment_form($form) { |
|
| 1234 | 1234 | |
| 1235 | - if ( is_numeric( $form ) ) { |
|
| 1236 | - $form = new GetPaid_Payment_Form( wpinv_translate_post_id( $form ) ); |
|
| 1235 | + if (is_numeric($form)) { |
|
| 1236 | + $form = new GetPaid_Payment_Form(wpinv_translate_post_id($form)); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | $form->display(); |
@@ -1243,61 +1243,61 @@ discard block |
||
| 1243 | 1243 | /** |
| 1244 | 1244 | * Helper function to display a item payment form on the frontend. |
| 1245 | 1245 | */ |
| 1246 | -function getpaid_display_item_payment_form( $items ) { |
|
| 1246 | +function getpaid_display_item_payment_form($items) { |
|
| 1247 | 1247 | |
| 1248 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1249 | - $form->set_items( $items ); |
|
| 1248 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1249 | + $form->set_items($items); |
|
| 1250 | 1250 | |
| 1251 | - if ( 0 == count( $form->get_items() ) ) { |
|
| 1251 | + if (0 == count($form->get_items())) { |
|
| 1252 | 1252 | aui()->alert( |
| 1253 | 1253 | array( |
| 1254 | 1254 | 'type' => 'warning', |
| 1255 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1255 | + 'content' => __('No published items found', 'invoicing'), |
|
| 1256 | 1256 | ), |
| 1257 | 1257 | true |
| 1258 | 1258 | ); |
| 1259 | 1259 | return; |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
| 1263 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
| 1262 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
| 1263 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
| 1264 | 1264 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
| 1265 | 1265 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
| 1266 | 1266 | |
| 1267 | - $form->display( $extra_items ); |
|
| 1267 | + $form->display($extra_items); |
|
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | /** |
| 1271 | 1271 | * Helper function to display an invoice payment form on the frontend. |
| 1272 | 1272 | */ |
| 1273 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
| 1273 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
| 1274 | 1274 | |
| 1275 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1275 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1276 | 1276 | |
| 1277 | - if ( empty( $invoice ) ) { |
|
| 1277 | + if (empty($invoice)) { |
|
| 1278 | 1278 | aui()->alert( |
| 1279 | 1279 | array( |
| 1280 | 1280 | 'type' => 'warning', |
| 1281 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1281 | + 'content' => __('Invoice not found', 'invoicing'), |
|
| 1282 | 1282 | ), |
| 1283 | 1283 | true |
| 1284 | 1284 | ); |
| 1285 | 1285 | return; |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | - if ( $invoice->is_paid() ) { |
|
| 1288 | + if ($invoice->is_paid()) { |
|
| 1289 | 1289 | aui()->alert( |
| 1290 | 1290 | array( |
| 1291 | 1291 | 'type' => 'warning', |
| 1292 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1292 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
| 1293 | 1293 | ), |
| 1294 | 1294 | true |
| 1295 | 1295 | ); |
| 1296 | 1296 | return; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1300 | - $form->set_items( $invoice->get_items() ); |
|
| 1299 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1300 | + $form->set_items($invoice->get_items()); |
|
| 1301 | 1301 | |
| 1302 | 1302 | $form->display(); |
| 1303 | 1303 | } |
@@ -1305,24 +1305,24 @@ discard block |
||
| 1305 | 1305 | /** |
| 1306 | 1306 | * Helper function to convert item string to array. |
| 1307 | 1307 | */ |
| 1308 | -function getpaid_convert_items_to_array( $items ) { |
|
| 1309 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
| 1308 | +function getpaid_convert_items_to_array($items) { |
|
| 1309 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
| 1310 | 1310 | $prepared = array(); |
| 1311 | 1311 | |
| 1312 | - foreach ( $items as $item ) { |
|
| 1313 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
| 1312 | + foreach ($items as $item) { |
|
| 1313 | + $data = array_map('trim', explode('|', $item)); |
|
| 1314 | 1314 | |
| 1315 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
| 1315 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
| 1316 | 1316 | continue; |
| 1317 | 1317 | } |
| 1318 | 1318 | |
| 1319 | 1319 | $quantity = 1; |
| 1320 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
| 1320 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
| 1321 | 1321 | $quantity = (float) $data[1]; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | // WPML support. |
| 1325 | - $prepared[ wpinv_translate_post_id( $data[0] ) ] = $quantity; |
|
| 1325 | + $prepared[wpinv_translate_post_id($data[0])] = $quantity; |
|
| 1326 | 1326 | |
| 1327 | 1327 | } |
| 1328 | 1328 | |
@@ -1332,13 +1332,13 @@ discard block |
||
| 1332 | 1332 | /** |
| 1333 | 1333 | * Helper function to convert item array to string. |
| 1334 | 1334 | */ |
| 1335 | -function getpaid_convert_items_to_string( $items ) { |
|
| 1335 | +function getpaid_convert_items_to_string($items) { |
|
| 1336 | 1336 | $prepared = array(); |
| 1337 | 1337 | |
| 1338 | - foreach ( $items as $item => $quantity ) { |
|
| 1338 | + foreach ($items as $item => $quantity) { |
|
| 1339 | 1339 | $prepared[] = "$item|$quantity"; |
| 1340 | 1340 | } |
| 1341 | - return implode( ',', $prepared ); |
|
| 1341 | + return implode(',', $prepared); |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | /** |
@@ -1346,21 +1346,21 @@ discard block |
||
| 1346 | 1346 | * |
| 1347 | 1347 | * Provide a label and one of $form, $items or $invoice. |
| 1348 | 1348 | */ |
| 1349 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
| 1350 | - $label = sanitize_text_field( $label ); |
|
| 1349 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
| 1350 | + $label = sanitize_text_field($label); |
|
| 1351 | 1351 | |
| 1352 | - if ( ! empty( $form ) ) { |
|
| 1353 | - $form = esc_attr( $form ); |
|
| 1352 | + if (!empty($form)) { |
|
| 1353 | + $form = esc_attr($form); |
|
| 1354 | 1354 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - if ( ! empty( $items ) ) { |
|
| 1358 | - $items = esc_attr( $items ); |
|
| 1357 | + if (!empty($items)) { |
|
| 1358 | + $items = esc_attr($items); |
|
| 1359 | 1359 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | - if ( ! empty( $invoice ) ) { |
|
| 1363 | - $invoice = esc_attr( $invoice ); |
|
| 1362 | + if (!empty($invoice)) { |
|
| 1363 | + $invoice = esc_attr($invoice); |
|
| 1364 | 1364 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
| 1365 | 1365 | } |
| 1366 | 1366 | |
@@ -1371,17 +1371,17 @@ discard block |
||
| 1371 | 1371 | * |
| 1372 | 1372 | * @param WPInv_Invoice $invoice |
| 1373 | 1373 | */ |
| 1374 | -function getpaid_the_invoice_description( $invoice ) { |
|
| 1374 | +function getpaid_the_invoice_description($invoice) { |
|
| 1375 | 1375 | $description = $invoice->get_description(); |
| 1376 | 1376 | |
| 1377 | - if ( empty( $description ) ) { |
|
| 1377 | + if (empty($description)) { |
|
| 1378 | 1378 | return; |
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | - echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post( wpautop( $description ) ) . "</em></small>"; |
|
| 1381 | + echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>" . wp_kses_post(wpautop($description)) . "</em></small>"; |
|
| 1382 | 1382 | } |
| 1383 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
| 1384 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
| 1383 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
| 1384 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
| 1385 | 1385 | |
| 1386 | 1386 | /** |
| 1387 | 1387 | * Render element on a form. |
@@ -1389,79 +1389,79 @@ discard block |
||
| 1389 | 1389 | * @param array $element |
| 1390 | 1390 | * @param GetPaid_Payment_Form $form |
| 1391 | 1391 | */ |
| 1392 | -function getpaid_payment_form_element( $element, $form ) { |
|
| 1392 | +function getpaid_payment_form_element($element, $form) { |
|
| 1393 | 1393 | |
| 1394 | 1394 | // Set up the args. |
| 1395 | - $element_type = trim( $element['type'] ); |
|
| 1395 | + $element_type = trim($element['type']); |
|
| 1396 | 1396 | $element['form'] = $form; |
| 1397 | - extract( $element ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
| 1397 | + extract($element); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
| 1398 | 1398 | |
| 1399 | 1399 | // Try to locate the appropriate template. |
| 1400 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
| 1400 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
| 1401 | 1401 | |
| 1402 | 1402 | // Abort if this is not our element. |
| 1403 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1403 | + if (empty($located) || !file_exists($located)) { |
|
| 1404 | 1404 | return; |
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | // Generate the class and id of the element. |
| 1408 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
| 1409 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
| 1408 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
| 1409 | + $id = isset($id) ? $id : uniqid('gp'); |
|
| 1410 | 1410 | |
| 1411 | - $element_id = ! empty( $element['label'] ) ? sanitize_title( $element['label'] ) : $id; |
|
| 1412 | - $query_value = isset( $_GET[ $element_id ] ) ? wpinv_clean( urldecode_deep( $_GET[ $element_id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 1411 | + $element_id = !empty($element['label']) ? sanitize_title($element['label']) : $id; |
|
| 1412 | + $query_value = isset($_GET[$element_id]) ? wpinv_clean(urldecode_deep($_GET[$element_id])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 1413 | 1413 | |
| 1414 | 1414 | $element_id = 'getpaid-' . $element_id; |
| 1415 | - if ( ! empty( $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ] ) ) { |
|
| 1416 | - $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][ $form->get_id() ]; |
|
| 1415 | + if (!empty($GLOBALS['rendered_getpaid_forms'][$form->get_id()])) { |
|
| 1416 | + $element_id = $element_id . '-' . $GLOBALS['rendered_getpaid_forms'][$form->get_id()]; |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | // Echo the opening wrapper. |
| 1420 | - echo "<div class='getpaid-payment-form-element " . esc_attr( $wrapper_class ) . "'>"; |
|
| 1420 | + echo "<div class='getpaid-payment-form-element " . esc_attr($wrapper_class) . "'>"; |
|
| 1421 | 1421 | |
| 1422 | 1422 | // Fires before displaying a given element type's content. |
| 1423 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
| 1423 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
| 1424 | 1424 | |
| 1425 | 1425 | // Include the template for the element. |
| 1426 | 1426 | include $located; |
| 1427 | 1427 | |
| 1428 | 1428 | // Fires after displaying a given element type's content. |
| 1429 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
| 1429 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
| 1430 | 1430 | |
| 1431 | 1431 | // Echo the closing wrapper. |
| 1432 | 1432 | echo '</div>'; |
| 1433 | 1433 | } |
| 1434 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
| 1434 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
| 1435 | 1435 | |
| 1436 | 1436 | /** |
| 1437 | 1437 | * Render an element's edit page. |
| 1438 | 1438 | * |
| 1439 | 1439 | * @param WP_Post $post |
| 1440 | 1440 | */ |
| 1441 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
| 1441 | +function getpaid_payment_form_edit_element_template($post) { |
|
| 1442 | 1442 | |
| 1443 | 1443 | // Retrieve all elements. |
| 1444 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
| 1444 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
| 1445 | 1445 | |
| 1446 | - foreach ( $all_elements as $element ) { |
|
| 1446 | + foreach ($all_elements as $element) { |
|
| 1447 | 1447 | |
| 1448 | 1448 | // Try to locate the appropriate template. |
| 1449 | - $element = esc_attr( sanitize_key( $element ) ); |
|
| 1450 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
| 1449 | + $element = esc_attr(sanitize_key($element)); |
|
| 1450 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
| 1451 | 1451 | |
| 1452 | 1452 | // Continue if this is not our element. |
| 1453 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1453 | + if (empty($located) || !file_exists($located)) { |
|
| 1454 | 1454 | continue; |
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | // Include the template for the element. |
| 1458 | - echo "<div v-if=\"active_form_element.type=='" . esc_attr( $element ) . "'\">"; |
|
| 1458 | + echo "<div v-if=\"active_form_element.type=='" . esc_attr($element) . "'\">"; |
|
| 1459 | 1459 | include $located; |
| 1460 | 1460 | echo '</div>'; |
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | } |
| 1464 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
| 1464 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
| 1465 | 1465 | |
| 1466 | 1466 | /** |
| 1467 | 1467 | * Render an element's preview. |
@@ -1470,27 +1470,27 @@ discard block |
||
| 1470 | 1470 | function getpaid_payment_form_render_element_preview_template() { |
| 1471 | 1471 | |
| 1472 | 1472 | // Retrieve all elements. |
| 1473 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
| 1473 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
| 1474 | 1474 | |
| 1475 | - foreach ( $all_elements as $element ) { |
|
| 1475 | + foreach ($all_elements as $element) { |
|
| 1476 | 1476 | |
| 1477 | 1477 | // Try to locate the appropriate template. |
| 1478 | - $element = sanitize_key( $element ); |
|
| 1479 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
| 1478 | + $element = sanitize_key($element); |
|
| 1479 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
| 1480 | 1480 | |
| 1481 | 1481 | // Continue if this is not our element. |
| 1482 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1482 | + if (empty($located) || !file_exists($located)) { |
|
| 1483 | 1483 | continue; |
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | // Include the template for the element. |
| 1487 | - echo "<div v-if=\"form_element.type=='" . esc_html( $element ) . "'\">"; |
|
| 1487 | + echo "<div v-if=\"form_element.type=='" . esc_html($element) . "'\">"; |
|
| 1488 | 1488 | include $located; |
| 1489 | 1489 | echo '</div>'; |
| 1490 | 1490 | } |
| 1491 | 1491 | |
| 1492 | 1492 | } |
| 1493 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
| 1493 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
| 1494 | 1494 | |
| 1495 | 1495 | /** |
| 1496 | 1496 | * Shows a list of gateways that support recurring payments. |
@@ -1498,17 +1498,17 @@ discard block |
||
| 1498 | 1498 | function wpinv_get_recurring_gateways_text() { |
| 1499 | 1499 | $gateways = array(); |
| 1500 | 1500 | |
| 1501 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
| 1502 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
| 1503 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
| 1501 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
| 1502 | + if (wpinv_gateway_support_subscription($key)) { |
|
| 1503 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
| 1504 | 1504 | } |
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | - if ( empty( $gateways ) ) { |
|
| 1508 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
| 1507 | + if (empty($gateways)) { |
|
| 1508 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
| 1511 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
| 1512 | 1512 | |
| 1513 | 1513 | } |
| 1514 | 1514 | |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | * @return GetPaid_Template |
| 1519 | 1519 | */ |
| 1520 | 1520 | function getpaid_template() { |
| 1521 | - return getpaid()->get( 'template' ); |
|
| 1521 | + return getpaid()->get('template'); |
|
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | /** |
@@ -1527,8 +1527,8 @@ discard block |
||
| 1527 | 1527 | * @param array args |
| 1528 | 1528 | * @return string |
| 1529 | 1529 | */ |
| 1530 | -function getpaid_paginate_links( $args ) { |
|
| 1531 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
| 1530 | +function getpaid_paginate_links($args) { |
|
| 1531 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | /** |
@@ -1538,22 +1538,22 @@ discard block |
||
| 1538 | 1538 | * @param string state |
| 1539 | 1539 | * @return string |
| 1540 | 1540 | */ |
| 1541 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false ) { |
|
| 1541 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state', $echo = false) { |
|
| 1542 | 1542 | |
| 1543 | - $states = wpinv_get_country_states( $country ); |
|
| 1544 | - $uniqid = uniqid( '_' ); |
|
| 1543 | + $states = wpinv_get_country_states($country); |
|
| 1544 | + $uniqid = uniqid('_'); |
|
| 1545 | 1545 | |
| 1546 | - if ( ! empty( $states ) ) { |
|
| 1546 | + if (!empty($states)) { |
|
| 1547 | 1547 | |
| 1548 | 1548 | return aui()->select( |
| 1549 | 1549 | array( |
| 1550 | 1550 | 'options' => $states, |
| 1551 | - 'name' => esc_attr( $field_name ), |
|
| 1552 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
| 1553 | - 'value' => sanitize_text_field( $state ), |
|
| 1551 | + 'name' => esc_attr($field_name), |
|
| 1552 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
| 1553 | + 'value' => sanitize_text_field($state), |
|
| 1554 | 1554 | 'placeholder' => $placeholder, |
| 1555 | 1555 | 'required' => $required, |
| 1556 | - 'label' => wp_kses_post( $label ), |
|
| 1556 | + 'label' => wp_kses_post($label), |
|
| 1557 | 1557 | 'label_type' => 'vertical', |
| 1558 | 1558 | 'help_text' => $help_text, |
| 1559 | 1559 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1570,14 +1570,14 @@ discard block |
||
| 1570 | 1570 | |
| 1571 | 1571 | return aui()->input( |
| 1572 | 1572 | array( |
| 1573 | - 'name' => esc_attr( $field_name ), |
|
| 1574 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
| 1573 | + 'name' => esc_attr($field_name), |
|
| 1574 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
| 1575 | 1575 | 'placeholder' => $placeholder, |
| 1576 | 1576 | 'required' => $required, |
| 1577 | - 'label' => wp_kses_post( $label ), |
|
| 1577 | + 'label' => wp_kses_post($label), |
|
| 1578 | 1578 | 'label_type' => 'vertical', |
| 1579 | 1579 | 'help_text' => $help_text, |
| 1580 | - 'value' => sanitize_text_field( $state ), |
|
| 1580 | + 'value' => sanitize_text_field($state), |
|
| 1581 | 1581 | 'class' => 'getpaid-address-field wpinv_state', |
| 1582 | 1582 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
| 1583 | 1583 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1596,16 +1596,16 @@ discard block |
||
| 1596 | 1596 | * @param array $element |
| 1597 | 1597 | * @return string |
| 1598 | 1598 | */ |
| 1599 | -function getpaid_get_form_element_grid_class( $element ) { |
|
| 1599 | +function getpaid_get_form_element_grid_class($element) { |
|
| 1600 | 1600 | |
| 1601 | 1601 | $class = 'col-12'; |
| 1602 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
| 1602 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
| 1603 | 1603 | |
| 1604 | - if ( $width == 'half' ) { |
|
| 1604 | + if ($width == 'half') { |
|
| 1605 | 1605 | $class .= ' col-md-6'; |
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | - if ( $width == 'third' ) { |
|
| 1608 | + if ($width == 'third') { |
|
| 1609 | 1609 | $class .= ' col-md-4'; |
| 1610 | 1610 | } |
| 1611 | 1611 | |
@@ -1620,15 +1620,15 @@ discard block |
||
| 1620 | 1620 | * |
| 1621 | 1621 | * @return string |
| 1622 | 1622 | */ |
| 1623 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
| 1623 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
| 1624 | 1624 | |
| 1625 | 1625 | return add_query_arg( |
| 1626 | 1626 | array( |
| 1627 | 1627 | 'getpaid_embed' => 1, |
| 1628 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
| 1629 | - 'item' => $items ? urlencode( $items ) : false, |
|
| 1628 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
| 1629 | + 'item' => $items ? urlencode($items) : false, |
|
| 1630 | 1630 | ), |
| 1631 | - home_url( 'index.php' ) |
|
| 1631 | + home_url('index.php') |
|
| 1632 | 1632 | ); |
| 1633 | 1633 | |
| 1634 | 1634 | } |
@@ -1638,13 +1638,13 @@ discard block |
||
| 1638 | 1638 | * |
| 1639 | 1639 | * @return string |
| 1640 | 1640 | */ |
| 1641 | -function getpaid_filter_embed_template( $template ) { |
|
| 1641 | +function getpaid_filter_embed_template($template) { |
|
| 1642 | 1642 | |
| 1643 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
| 1644 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
| 1643 | + if (isset($_GET['getpaid_embed'])) { |
|
| 1644 | + wpinv_get_template('payment-forms/embed.php'); |
|
| 1645 | 1645 | exit; |
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | return $template; |
| 1649 | 1649 | } |
| 1650 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
| 1650 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
|
@@ -14,620 +14,620 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Define class properties. |
|
| 79 | - */ |
|
| 80 | - public function set_properties() { |
|
| 81 | - // Sessions. |
|
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | - |
|
| 86 | - // Init other objects. |
|
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Define plugin constants. |
|
| 102 | - */ |
|
| 103 | - public function define_constants() { |
|
| 104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | - $this->version = WPINV_VERSION; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Hook into actions and filters. |
|
| 111 | - * |
|
| 112 | - * @since 1.0.19 |
|
| 113 | - */ |
|
| 114 | - protected function init_hooks() { |
|
| 115 | - /* Internationalize the text strings used. */ |
|
| 116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | - |
|
| 118 | - // Init the plugin after WordPress inits. |
|
| 119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | - |
|
| 131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | - |
|
| 135 | - // Fires after registering actions. |
|
| 136 | - do_action( 'wpinv_actions', $this ); |
|
| 137 | - do_action( 'getpaid_actions', $this ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function plugins_loaded() { |
|
| 141 | - /* Internationalize the text strings used. */ |
|
| 142 | - $this->load_textdomain(); |
|
| 143 | - |
|
| 144 | - do_action( 'wpinv_loaded' ); |
|
| 145 | - |
|
| 146 | - // Fix oxygen page builder conflict |
|
| 147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | - wpinv_oxygen_fix_conflict(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Load Localisation files. |
|
| 154 | - * |
|
| 155 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | - * |
|
| 157 | - * Locales found in: |
|
| 158 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - */ |
|
| 163 | - public function load_textdomain() { |
|
| 164 | - // Determines the current locale. |
|
| 165 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | - $locale = determine_locale(); |
|
| 167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | - $locale = get_user_locale(); |
|
| 169 | - } else { |
|
| 170 | - $locale = get_locale(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Filter the locale to use for translations. |
|
| 175 | - */ |
|
| 176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | - |
|
| 178 | - unload_textdomain( 'invoicing' ); |
|
| 179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Include required core files used in admin and on the frontend. |
|
| 185 | - */ |
|
| 186 | - public function includes() { |
|
| 187 | - // Start with the settings. |
|
| 188 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | - |
|
| 190 | - // Packages/libraries. |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | - |
|
| 194 | - // Load functions. |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | - |
|
| 211 | - // Register autoloader. |
|
| 212 | - try { |
|
| 213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | - } catch ( Exception $e ) { |
|
| 215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | - |
|
| 241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | - GetPaid_Post_Types_Admin::init(); |
|
| 243 | - |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | - // load the user class only on the users.php page |
|
| 251 | - global $pagenow; |
|
| 252 | - if ( $pagenow == 'users.php' ) { |
|
| 253 | - new WPInv_Admin_Users(); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Register cli commands |
|
| 258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Class autoloader |
|
| 266 | - * |
|
| 267 | - * @param string $class_name The name of the class to load. |
|
| 268 | - * @access public |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function autoload( $class_name ) { |
|
| 273 | - // Normalize the class name... |
|
| 274 | - $class_name = strtolower( $class_name ); |
|
| 275 | - |
|
| 276 | - // ... and make sure it is our class. |
|
| 277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Next, prepare the file name from the class. |
|
| 282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | - |
|
| 284 | - // Base path of the classes. |
|
| 285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | - |
|
| 287 | - // And an array of possible locations in order of importance. |
|
| 288 | - $locations = array( |
|
| 289 | - "$plugin_path/includes", |
|
| 290 | - "$plugin_path/includes/data-stores", |
|
| 291 | - "$plugin_path/includes/gateways", |
|
| 292 | - "$plugin_path/includes/payments", |
|
| 293 | - "$plugin_path/includes/geolocation", |
|
| 294 | - "$plugin_path/includes/reports", |
|
| 295 | - "$plugin_path/includes/api", |
|
| 296 | - "$plugin_path/includes/admin", |
|
| 297 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | - include trailingslashit( $location ) . $file_name; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Inits hooks etc. |
|
| 310 | - */ |
|
| 311 | - public function init() { |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Checks if this is an IPN request and processes it. |
|
| 345 | - */ |
|
| 346 | - public function maybe_process_ipn() { |
|
| 347 | - // Ensure that this is an IPN request. |
|
| 348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | - |
|
| 354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | - exit; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - public function enqueue_scripts() { |
|
| 360 | - // Fires before adding scripts. |
|
| 361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | - |
|
| 363 | - $localize = array(); |
|
| 364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | - |
|
| 375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | - |
|
| 377 | - // reCaptcha. |
|
| 378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function wpinv_actions() { |
|
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Fires an action after verifying that a user can fire them. |
|
| 399 | - * |
|
| 400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | - * current user owns the invoice/subscription. |
|
| 402 | - */ |
|
| 403 | - public function maybe_do_authenticated_action() { |
|
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - |
|
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $wp_query; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Register widgets |
|
| 426 | - * |
|
| 427 | - */ |
|
| 428 | - public function register_widgets() { |
|
| 429 | - global $pagenow; |
|
| 430 | - |
|
| 431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | - |
|
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | - // don't initiate in these conditions. |
|
| 441 | - } else { |
|
| 442 | - // Only load allowed widgets. |
|
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | - $widgets = apply_filters( |
|
| 445 | - 'getpaid_widget_classes', |
|
| 446 | - array( |
|
| 447 | - 'WPInv_Checkout_Widget', |
|
| 448 | - 'WPInv_History_Widget', |
|
| 449 | - 'WPInv_Receipt_Widget', |
|
| 450 | - 'WPInv_Subscriptions_Widget', |
|
| 451 | - 'WPInv_Buy_Item_Widget', |
|
| 452 | - 'WPInv_Messages_Widget', |
|
| 453 | - 'WPInv_GetPaid_Widget', |
|
| 454 | - 'WPInv_Invoice_Widget', |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - // For each widget... |
|
| 459 | - foreach ( $widgets as $widget ) { |
|
| 460 | - // Abort early if it is excluded for this page. |
|
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 462 | - continue; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 468 | - } else { |
|
| 469 | - new $widget(); |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Upgrades the database. |
|
| 477 | - * |
|
| 478 | - * @since 2.0.2 |
|
| 479 | - */ |
|
| 480 | - public function maybe_upgrade_database() { |
|
| 481 | - // Ensure the database tables are up to date. |
|
| 482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | - |
|
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | - |
|
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $installer = new GetPaid_Installer(); |
|
| 491 | - |
|
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $upgrades = array( |
|
| 497 | - '0.0.5' => '004', |
|
| 498 | - '1.0.3' => '102', |
|
| 499 | - '2.0.0' => '118', |
|
| 500 | - '2.8.0' => '279', |
|
| 501 | - ); |
|
| 502 | - |
|
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Flushes the permalinks if needed. |
|
| 512 | - * |
|
| 513 | - * @since 2.0.8 |
|
| 514 | - */ |
|
| 515 | - public function maybe_flush_permalinks() { |
|
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | - |
|
| 518 | - if ( ! empty( $flush ) ) { |
|
| 519 | - flush_rewrite_rules(); |
|
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Remove our pages from yoast sitemaps. |
|
| 526 | - * |
|
| 527 | - * @since 1.0.19 |
|
| 528 | - * @param int[] $excluded_posts_ids |
|
| 529 | - */ |
|
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | - // Ensure that we have an array. |
|
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | - $excluded_posts_ids = array(); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // Prepare our pages. |
|
| 537 | - $our_pages = array(); |
|
| 538 | - |
|
| 539 | - // Checkout page. |
|
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | - |
|
| 542 | - // Success page. |
|
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | - |
|
| 545 | - // Failure page. |
|
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | - |
|
| 548 | - // History page. |
|
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | - |
|
| 551 | - // Subscriptions page. |
|
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | - |
|
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | - |
|
| 556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | - |
|
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Remove our pages from yoast sitemaps. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string[] $post_types |
|
| 566 | - */ |
|
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | - // Ensure that we have an array. |
|
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 570 | - $post_types = array(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Remove our post types. |
|
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Displays additional footer code. |
|
| 579 | - * |
|
| 580 | - * @since 2.0.0 |
|
| 581 | - */ |
|
| 582 | - public function wp_footer() { |
|
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Displays additional header code. |
|
| 588 | - * |
|
| 589 | - * @since 2.0.0 |
|
| 590 | - */ |
|
| 591 | - public function wp_head() { |
|
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Custom query vars. |
|
| 597 | - * |
|
| 598 | - */ |
|
| 599 | - public function custom_query_vars( $vars ) { |
|
| 600 | - $vars[] = 'getpaid-ipn'; |
|
| 601 | - return $vars; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Add rewrite tags and rules. |
|
| 606 | - * |
|
| 607 | - */ |
|
| 608 | - public function add_rewrite_rule() { |
|
| 609 | - $tag = 'getpaid-ipn'; |
|
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Processes non-query string ipns. |
|
| 616 | - * |
|
| 617 | - */ |
|
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | - |
|
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 627 | - nocache_headers(); |
|
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | - exit; |
|
| 631 | - } |
|
| 632 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | + return $this->data[ $prop ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Define class properties. |
|
| 79 | + */ |
|
| 80 | + public function set_properties() { |
|
| 81 | + // Sessions. |
|
| 82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | + |
|
| 86 | + // Init other objects. |
|
| 87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | + $this->set( 'api', new WPInv_API() ); |
|
| 89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Define plugin constants. |
|
| 102 | + */ |
|
| 103 | + public function define_constants() { |
|
| 104 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | + $this->version = WPINV_VERSION; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Hook into actions and filters. |
|
| 111 | + * |
|
| 112 | + * @since 1.0.19 |
|
| 113 | + */ |
|
| 114 | + protected function init_hooks() { |
|
| 115 | + /* Internationalize the text strings used. */ |
|
| 116 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | + |
|
| 118 | + // Init the plugin after WordPress inits. |
|
| 119 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | + |
|
| 131 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | + |
|
| 135 | + // Fires after registering actions. |
|
| 136 | + do_action( 'wpinv_actions', $this ); |
|
| 137 | + do_action( 'getpaid_actions', $this ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function plugins_loaded() { |
|
| 141 | + /* Internationalize the text strings used. */ |
|
| 142 | + $this->load_textdomain(); |
|
| 143 | + |
|
| 144 | + do_action( 'wpinv_loaded' ); |
|
| 145 | + |
|
| 146 | + // Fix oxygen page builder conflict |
|
| 147 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | + wpinv_oxygen_fix_conflict(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Load Localisation files. |
|
| 154 | + * |
|
| 155 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | + * |
|
| 157 | + * Locales found in: |
|
| 158 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + */ |
|
| 163 | + public function load_textdomain() { |
|
| 164 | + // Determines the current locale. |
|
| 165 | + if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | + $locale = determine_locale(); |
|
| 167 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | + $locale = get_user_locale(); |
|
| 169 | + } else { |
|
| 170 | + $locale = get_locale(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Filter the locale to use for translations. |
|
| 175 | + */ |
|
| 176 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | + |
|
| 178 | + unload_textdomain( 'invoicing' ); |
|
| 179 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Include required core files used in admin and on the frontend. |
|
| 185 | + */ |
|
| 186 | + public function includes() { |
|
| 187 | + // Start with the settings. |
|
| 188 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | + |
|
| 190 | + // Packages/libraries. |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | + |
|
| 194 | + // Load functions. |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | + |
|
| 211 | + // Register autoloader. |
|
| 212 | + try { |
|
| 213 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | + } catch ( Exception $e ) { |
|
| 215 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | + |
|
| 241 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | + GetPaid_Post_Types_Admin::init(); |
|
| 243 | + |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | + // load the user class only on the users.php page |
|
| 251 | + global $pagenow; |
|
| 252 | + if ( $pagenow == 'users.php' ) { |
|
| 253 | + new WPInv_Admin_Users(); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Register cli commands |
|
| 258 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Class autoloader |
|
| 266 | + * |
|
| 267 | + * @param string $class_name The name of the class to load. |
|
| 268 | + * @access public |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function autoload( $class_name ) { |
|
| 273 | + // Normalize the class name... |
|
| 274 | + $class_name = strtolower( $class_name ); |
|
| 275 | + |
|
| 276 | + // ... and make sure it is our class. |
|
| 277 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Next, prepare the file name from the class. |
|
| 282 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | + |
|
| 284 | + // Base path of the classes. |
|
| 285 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | + |
|
| 287 | + // And an array of possible locations in order of importance. |
|
| 288 | + $locations = array( |
|
| 289 | + "$plugin_path/includes", |
|
| 290 | + "$plugin_path/includes/data-stores", |
|
| 291 | + "$plugin_path/includes/gateways", |
|
| 292 | + "$plugin_path/includes/payments", |
|
| 293 | + "$plugin_path/includes/geolocation", |
|
| 294 | + "$plugin_path/includes/reports", |
|
| 295 | + "$plugin_path/includes/api", |
|
| 296 | + "$plugin_path/includes/admin", |
|
| 297 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | + include trailingslashit( $location ) . $file_name; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Inits hooks etc. |
|
| 310 | + */ |
|
| 311 | + public function init() { |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Checks if this is an IPN request and processes it. |
|
| 345 | + */ |
|
| 346 | + public function maybe_process_ipn() { |
|
| 347 | + // Ensure that this is an IPN request. |
|
| 348 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | + |
|
| 354 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | + exit; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + public function enqueue_scripts() { |
|
| 360 | + // Fires before adding scripts. |
|
| 361 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | + |
|
| 363 | + $localize = array(); |
|
| 364 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | + |
|
| 375 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | + |
|
| 377 | + // reCaptcha. |
|
| 378 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function wpinv_actions() { |
|
| 388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Fires an action after verifying that a user can fire them. |
|
| 399 | + * |
|
| 400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | + * current user owns the invoice/subscription. |
|
| 402 | + */ |
|
| 403 | + public function maybe_do_authenticated_action() { |
|
| 404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + |
|
| 408 | + if ( is_user_logged_in() ) { |
|
| 409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public function pre_get_posts( $wp_query ) { |
|
| 417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $wp_query; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Register widgets |
|
| 426 | + * |
|
| 427 | + */ |
|
| 428 | + public function register_widgets() { |
|
| 429 | + global $pagenow; |
|
| 430 | + |
|
| 431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | + |
|
| 439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | + // don't initiate in these conditions. |
|
| 441 | + } else { |
|
| 442 | + // Only load allowed widgets. |
|
| 443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | + $widgets = apply_filters( |
|
| 445 | + 'getpaid_widget_classes', |
|
| 446 | + array( |
|
| 447 | + 'WPInv_Checkout_Widget', |
|
| 448 | + 'WPInv_History_Widget', |
|
| 449 | + 'WPInv_Receipt_Widget', |
|
| 450 | + 'WPInv_Subscriptions_Widget', |
|
| 451 | + 'WPInv_Buy_Item_Widget', |
|
| 452 | + 'WPInv_Messages_Widget', |
|
| 453 | + 'WPInv_GetPaid_Widget', |
|
| 454 | + 'WPInv_Invoice_Widget', |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + // For each widget... |
|
| 459 | + foreach ( $widgets as $widget ) { |
|
| 460 | + // Abort early if it is excluded for this page. |
|
| 461 | + if ( in_array( $widget, $exclude ) ) { |
|
| 462 | + continue; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | + register_widget( $widget ); |
|
| 468 | + } else { |
|
| 469 | + new $widget(); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Upgrades the database. |
|
| 477 | + * |
|
| 478 | + * @since 2.0.2 |
|
| 479 | + */ |
|
| 480 | + public function maybe_upgrade_database() { |
|
| 481 | + // Ensure the database tables are up to date. |
|
| 482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | + |
|
| 484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | + |
|
| 486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $installer = new GetPaid_Installer(); |
|
| 491 | + |
|
| 492 | + if ( empty( $wpi_version ) ) { |
|
| 493 | + return $installer->upgrade_db( 0 ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $upgrades = array( |
|
| 497 | + '0.0.5' => '004', |
|
| 498 | + '1.0.3' => '102', |
|
| 499 | + '2.0.0' => '118', |
|
| 500 | + '2.8.0' => '279', |
|
| 501 | + ); |
|
| 502 | + |
|
| 503 | + foreach ( $upgrades as $key => $method ) { |
|
| 504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | + return $installer->upgrade_db( $method ); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Flushes the permalinks if needed. |
|
| 512 | + * |
|
| 513 | + * @since 2.0.8 |
|
| 514 | + */ |
|
| 515 | + public function maybe_flush_permalinks() { |
|
| 516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | + |
|
| 518 | + if ( ! empty( $flush ) ) { |
|
| 519 | + flush_rewrite_rules(); |
|
| 520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Remove our pages from yoast sitemaps. |
|
| 526 | + * |
|
| 527 | + * @since 1.0.19 |
|
| 528 | + * @param int[] $excluded_posts_ids |
|
| 529 | + */ |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | + // Ensure that we have an array. |
|
| 532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | + $excluded_posts_ids = array(); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // Prepare our pages. |
|
| 537 | + $our_pages = array(); |
|
| 538 | + |
|
| 539 | + // Checkout page. |
|
| 540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | + |
|
| 542 | + // Success page. |
|
| 543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | + |
|
| 545 | + // Failure page. |
|
| 546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | + |
|
| 548 | + // History page. |
|
| 549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | + |
|
| 551 | + // Subscriptions page. |
|
| 552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | + |
|
| 554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | + |
|
| 556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | + |
|
| 558 | + return array_unique( $excluded_posts_ids ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Remove our pages from yoast sitemaps. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string[] $post_types |
|
| 566 | + */ |
|
| 567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | + // Ensure that we have an array. |
|
| 569 | + if ( ! is_array( $post_types ) ) { |
|
| 570 | + $post_types = array(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Remove our post types. |
|
| 574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Displays additional footer code. |
|
| 579 | + * |
|
| 580 | + * @since 2.0.0 |
|
| 581 | + */ |
|
| 582 | + public function wp_footer() { |
|
| 583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Displays additional header code. |
|
| 588 | + * |
|
| 589 | + * @since 2.0.0 |
|
| 590 | + */ |
|
| 591 | + public function wp_head() { |
|
| 592 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Custom query vars. |
|
| 597 | + * |
|
| 598 | + */ |
|
| 599 | + public function custom_query_vars( $vars ) { |
|
| 600 | + $vars[] = 'getpaid-ipn'; |
|
| 601 | + return $vars; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Add rewrite tags and rules. |
|
| 606 | + * |
|
| 607 | + */ |
|
| 608 | + public function add_rewrite_rule() { |
|
| 609 | + $tag = 'getpaid-ipn'; |
|
| 610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Processes non-query string ipns. |
|
| 616 | + * |
|
| 617 | + */ |
|
| 618 | + public function maybe_process_new_ipn( $query ) { |
|
| 619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | + |
|
| 625 | + if ( ! empty( $gateway ) ) { |
|
| 626 | + $gateway = sanitize_text_field( $gateway ); |
|
| 627 | + nocache_headers(); |
|
| 628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | + exit; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | 633 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 1.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param string $prop The prop to set. |
| 57 | 57 | * @param mixed $value The value to retrieve. |
| 58 | 58 | */ |
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 59 | + public function set($prop, $value) { |
|
| 60 | + $this->data[$prop] = $value; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | * @param string $prop The prop to set. |
| 67 | 67 | * @return mixed The value. |
| 68 | 68 | */ |
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 69 | + public function get($prop) { |
|
| 70 | + if (isset($this->data[$prop])) { |
|
| 71 | + return $this->data[$prop]; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return null; |
@@ -79,30 +79,30 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function set_properties() { |
| 81 | 81 | // Sessions. |
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 82 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
| 84 | 84 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
| 85 | 85 | |
| 86 | 86 | // Init other objects. |
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 87 | + $this->set('notes', new WPInv_Notes()); |
|
| 88 | + $this->set('api', new WPInv_API()); |
|
| 89 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
| 90 | + $this->set('template', new GetPaid_Template()); |
|
| 91 | + $this->set('admin', new GetPaid_Admin()); |
|
| 92 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
| 93 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
| 94 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
| 95 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
| 96 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
| 97 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Define plugin constants. |
| 102 | 102 | */ |
| 103 | 103 | public function define_constants() { |
| 104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 104 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 105 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 106 | 106 | $this->version = WPINV_VERSION; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -113,38 +113,38 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | protected function init_hooks() { |
| 115 | 115 | /* Internationalize the text strings used. */ |
| 116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 116 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 117 | 117 | |
| 118 | 118 | // Init the plugin after WordPress inits. |
| 119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | - |
|
| 131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 119 | + add_action('init', array($this, 'init'), 1); |
|
| 120 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
| 121 | + add_action('init', array($this, 'wpinv_actions')); |
|
| 122 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
| 123 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
| 124 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
| 125 | + add_action('wp_head', array($this, 'wp_head')); |
|
| 126 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 127 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 128 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
| 129 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 130 | + |
|
| 131 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
| 132 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
| 133 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
| 134 | 134 | |
| 135 | 135 | // Fires after registering actions. |
| 136 | - do_action( 'wpinv_actions', $this ); |
|
| 137 | - do_action( 'getpaid_actions', $this ); |
|
| 136 | + do_action('wpinv_actions', $this); |
|
| 137 | + do_action('getpaid_actions', $this); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public function plugins_loaded() { |
| 141 | 141 | /* Internationalize the text strings used. */ |
| 142 | 142 | $this->load_textdomain(); |
| 143 | 143 | |
| 144 | - do_action( 'wpinv_loaded' ); |
|
| 144 | + do_action('wpinv_loaded'); |
|
| 145 | 145 | |
| 146 | 146 | // Fix oxygen page builder conflict |
| 147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 147 | + if (function_exists('ct_css_output')) { |
|
| 148 | 148 | wpinv_oxygen_fix_conflict(); |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public function load_textdomain() { |
| 164 | 164 | // Determines the current locale. |
| 165 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 165 | + if (function_exists('determine_locale')) { |
|
| 166 | 166 | $locale = determine_locale(); |
| 167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 167 | + } else if (function_exists('get_user_locale')) { |
|
| 168 | 168 | $locale = get_user_locale(); |
| 169 | 169 | } else { |
| 170 | 170 | $locale = get_locale(); |
@@ -173,11 +173,11 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * Filter the locale to use for translations. |
| 175 | 175 | */ |
| 176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 176 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 177 | 177 | |
| 178 | - unload_textdomain( 'invoicing' ); |
|
| 179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 178 | + unload_textdomain('invoicing'); |
|
| 179 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 180 | + load_plugin_textdomain('invoicing', false, plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | // Register autoloader. |
| 212 | 212 | try { |
| 213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | - } catch ( Exception $e ) { |
|
| 215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 213 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 214 | + } catch (Exception $e) { |
|
| 215 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
| 239 | 239 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
| 240 | 240 | |
| 241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 241 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 242 | 242 | GetPaid_Post_Types_Admin::init(); |
| 243 | 243 | |
| 244 | 244 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -249,15 +249,15 @@ discard block |
||
| 249 | 249 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
| 250 | 250 | // load the user class only on the users.php page |
| 251 | 251 | global $pagenow; |
| 252 | - if ( $pagenow == 'users.php' ) { |
|
| 252 | + if ($pagenow == 'users.php') { |
|
| 253 | 253 | new WPInv_Admin_Users(); |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // Register cli commands |
| 258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 258 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 259 | 259 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
| 260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 260 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
@@ -269,20 +269,20 @@ discard block |
||
| 269 | 269 | * @since 1.0.19 |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | - public function autoload( $class_name ) { |
|
| 272 | + public function autoload($class_name) { |
|
| 273 | 273 | // Normalize the class name... |
| 274 | - $class_name = strtolower( $class_name ); |
|
| 274 | + $class_name = strtolower($class_name); |
|
| 275 | 275 | |
| 276 | 276 | // ... and make sure it is our class. |
| 277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 277 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Next, prepare the file name from the class. |
| 282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 282 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 283 | 283 | |
| 284 | 284 | // Base path of the classes. |
| 285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 285 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 286 | 286 | |
| 287 | 287 | // And an array of possible locations in order of importance. |
| 288 | 288 | $locations = array( |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | "$plugin_path/includes/admin/meta-boxes", |
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | - include trailingslashit( $location ) . $file_name; |
|
| 300 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 301 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 302 | + include trailingslashit($location) . $file_name; |
|
| 303 | 303 | break; |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function init() { |
| 312 | 312 | // Fires before getpaid inits. |
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 313 | + do_action('before_getpaid_init', $this); |
|
| 314 | 314 | |
| 315 | 315 | // Maybe upgrade. |
| 316 | 316 | $this->maybe_upgrade_database(); |
@@ -327,17 +327,17 @@ discard block |
||
| 327 | 327 | ) |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 330 | + foreach ($gateways as $id => $class) { |
|
| 331 | + $this->gateways[$id] = new $class(); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 334 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
| 335 | 335 | GetPaid_Installer::rename_gateways_label(); |
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 336 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Fires after getpaid inits. |
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 340 | + do_action('getpaid_init', $this); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -345,52 +345,52 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function maybe_process_ipn() { |
| 347 | 347 | // Ensure that this is an IPN request. |
| 348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 348 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 349 | 349 | return; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 352 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
| 353 | 353 | |
| 354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 354 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 355 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 356 | 356 | exit; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | public function enqueue_scripts() { |
| 360 | 360 | // Fires before adding scripts. |
| 361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 361 | + do_action('getpaid_enqueue_scripts'); |
|
| 362 | 362 | |
| 363 | 363 | $localize = array(); |
| 364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 364 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 365 | 365 | $localize['thousands'] = wpinv_thousands_separator(); |
| 366 | 366 | $localize['decimals'] = wpinv_decimal_separator(); |
| 367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 367 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 368 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 369 | 369 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 370 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 371 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
| 372 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 373 | 373 | $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
| 374 | 374 | |
| 375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 375 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 376 | 376 | |
| 377 | 377 | // reCaptcha. |
| 378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 378 | + if (getpaid_is_recaptcha_enabled() && ($recaptcha_js = getpaid_recaptcha_api_url())) { |
|
| 379 | + wp_enqueue_script('recaptcha', $recaptcha_js, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 382 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
| 383 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
| 384 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | public function wpinv_actions() { |
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 388 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 389 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 392 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
| 393 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
@@ -401,21 +401,21 @@ discard block |
||
| 401 | 401 | * current user owns the invoice/subscription. |
| 402 | 402 | */ |
| 403 | 403 | public function maybe_do_authenticated_action() { |
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 404 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
| 405 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
| 406 | + $data = wp_unslash($_REQUEST); |
|
| 407 | 407 | |
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 408 | + if (is_user_logged_in()) { |
|
| 409 | + do_action("getpaid_authenticated_action_$key", $data); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 412 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 416 | + public function pre_get_posts($wp_query) { |
|
| 417 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | return $wp_query; |
@@ -430,17 +430,17 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
| 432 | 432 | // So we disable our widgets when editing a page with UX Builder. |
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 433 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
| 434 | 434 | return; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 437 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
| 438 | 438 | |
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 439 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
| 440 | 440 | // don't initiate in these conditions. |
| 441 | 441 | } else { |
| 442 | 442 | // Only load allowed widgets. |
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 443 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
| 444 | 444 | $widgets = apply_filters( |
| 445 | 445 | 'getpaid_widget_classes', |
| 446 | 446 | array( |
@@ -456,15 +456,15 @@ discard block |
||
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | 458 | // For each widget... |
| 459 | - foreach ( $widgets as $widget ) { |
|
| 459 | + foreach ($widgets as $widget) { |
|
| 460 | 460 | // Abort early if it is excluded for this page. |
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 461 | + if (in_array($widget, $exclude)) { |
|
| 462 | 462 | continue; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 466 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
| 467 | + register_widget($widget); |
|
| 468 | 468 | } else { |
| 469 | 469 | new $widget(); |
| 470 | 470 | } |
@@ -481,28 +481,28 @@ discard block |
||
| 481 | 481 | // Ensure the database tables are up to date. |
| 482 | 482 | GetPaid_Installer::maybe_create_db_tables(); |
| 483 | 483 | |
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 484 | + $wpi_version = get_option('wpinv_version', 0); |
|
| 485 | 485 | |
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 486 | + if ($wpi_version == WPINV_VERSION) { |
|
| 487 | 487 | return; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | $installer = new GetPaid_Installer(); |
| 491 | 491 | |
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 492 | + if (empty($wpi_version)) { |
|
| 493 | + return $installer->upgrade_db(0); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - $upgrades = array( |
|
| 496 | + $upgrades = array( |
|
| 497 | 497 | '0.0.5' => '004', |
| 498 | 498 | '1.0.3' => '102', |
| 499 | 499 | '2.0.0' => '118', |
| 500 | 500 | '2.8.0' => '279', |
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 503 | + foreach ($upgrades as $key => $method) { |
|
| 504 | + if (version_compare($wpi_version, $key, '<')) { |
|
| 505 | + return $installer->upgrade_db($method); |
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
| 513 | 513 | * @since 2.0.8 |
| 514 | 514 | */ |
| 515 | 515 | public function maybe_flush_permalinks() { |
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 516 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
| 517 | 517 | |
| 518 | - if ( ! empty( $flush ) ) { |
|
| 518 | + if (!empty($flush)) { |
|
| 519 | 519 | flush_rewrite_rules(); |
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 520 | + delete_option('wpinv_flush_permalinks'); |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
@@ -527,9 +527,9 @@ discard block |
||
| 527 | 527 | * @since 1.0.19 |
| 528 | 528 | * @param int[] $excluded_posts_ids |
| 529 | 529 | */ |
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 531 | 531 | // Ensure that we have an array. |
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 532 | + if (!is_array($excluded_posts_ids)) { |
|
| 533 | 533 | $excluded_posts_ids = array(); |
| 534 | 534 | } |
| 535 | 535 | |
@@ -537,25 +537,25 @@ discard block |
||
| 537 | 537 | $our_pages = array(); |
| 538 | 538 | |
| 539 | 539 | // Checkout page. |
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 540 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 541 | 541 | |
| 542 | 542 | // Success page. |
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 543 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 544 | 544 | |
| 545 | 545 | // Failure page. |
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 546 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 547 | 547 | |
| 548 | 548 | // History page. |
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 549 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 550 | 550 | |
| 551 | 551 | // Subscriptions page. |
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 552 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 553 | 553 | |
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 554 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 555 | 555 | |
| 556 | 556 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 557 | 557 | |
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 558 | + return array_unique($excluded_posts_ids); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -564,14 +564,14 @@ discard block |
||
| 564 | 564 | * @since 1.0.19 |
| 565 | 565 | * @param string[] $post_types |
| 566 | 566 | */ |
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 567 | + public function exclude_invoicing_post_types($post_types) { |
|
| 568 | 568 | // Ensure that we have an array. |
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 569 | + if (!is_array($post_types)) { |
|
| 570 | 570 | $post_types = array(); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // Remove our post types. |
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 574 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | * @since 2.0.0 |
| 581 | 581 | */ |
| 582 | 582 | public function wp_footer() { |
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 583 | + wpinv_get_template('frontend-footer.php'); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -589,14 +589,14 @@ discard block |
||
| 589 | 589 | * @since 2.0.0 |
| 590 | 590 | */ |
| 591 | 591 | public function wp_head() { |
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 592 | + wpinv_get_template('frontend-head.php'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
| 596 | 596 | * Custom query vars. |
| 597 | 597 | * |
| 598 | 598 | */ |
| 599 | - public function custom_query_vars( $vars ) { |
|
| 599 | + public function custom_query_vars($vars) { |
|
| 600 | 600 | $vars[] = 'getpaid-ipn'; |
| 601 | 601 | return $vars; |
| 602 | 602 | } |
@@ -607,26 +607,26 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | public function add_rewrite_rule() { |
| 609 | 609 | $tag = 'getpaid-ipn'; |
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 610 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
| 611 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
| 615 | 615 | * Processes non-query string ipns. |
| 616 | 616 | * |
| 617 | 617 | */ |
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 618 | + public function maybe_process_new_ipn($query) { |
|
| 619 | + if (is_admin() || !$query->is_main_query()) { |
|
| 620 | 620 | return; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 623 | + $gateway = get_query_var('getpaid-ipn'); |
|
| 624 | 624 | |
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 625 | + if (!empty($gateway)) { |
|
| 626 | + $gateway = sanitize_text_field($gateway); |
|
| 627 | 627 | nocache_headers(); |
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 628 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 629 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 630 | 630 | exit; |
| 631 | 631 | } |
| 632 | 632 | } |
@@ -14,143 +14,143 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Register the widget with WordPress. |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - |
|
| 23 | - $options = array( |
|
| 24 | - 'textdomain' => 'invoicing', |
|
| 25 | - 'block-icon' => 'controls-repeat', |
|
| 26 | - 'block-category' => 'widgets', |
|
| 27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | - 'class_name' => __CLASS__, |
|
| 29 | - 'base_id' => 'wpinv_subscriptions', |
|
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | - 'widget_ops' => array( |
|
| 32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | - ), |
|
| 35 | - 'arguments' => array( |
|
| 36 | - 'title' => array( |
|
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | - 'type' => 'text', |
|
| 40 | - 'desc_tip' => true, |
|
| 41 | - 'default' => '', |
|
| 42 | - 'advanced' => false, |
|
| 43 | - ), |
|
| 44 | - ), |
|
| 45 | - |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - parent::__construct( $options ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Retrieves current user's subscriptions. |
|
| 53 | - * |
|
| 54 | - * @return GetPaid_Subscriptions_Query |
|
| 55 | - */ |
|
| 56 | - public function get_subscriptions() { |
|
| 57 | - |
|
| 58 | - // Prepare license args. |
|
| 59 | - $args = array( |
|
| 60 | - 'customer_in' => get_current_user_id(), |
|
| 61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The Super block output function. |
|
| 70 | - * |
|
| 71 | - * @param array $args |
|
| 72 | - * @param array $widget_args |
|
| 73 | - * @param string $content |
|
| 74 | - * |
|
| 75 | - * @return mixed|string|bool |
|
| 76 | - */ |
|
| 77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | - |
|
| 79 | - // Ensure that the user is logged in. |
|
| 80 | - if ( ! is_user_logged_in() ) { |
|
| 81 | - |
|
| 82 | - return aui()->alert( |
|
| 83 | - array( |
|
| 84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | - 'type' => 'error', |
|
| 86 | - ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Are we displaying a single subscription? |
|
| 92 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Retrieve the user's subscriptions. |
|
| 97 | - $subscriptions = $this->get_subscriptions(); |
|
| 98 | - |
|
| 99 | - // Start the output buffer. |
|
| 100 | - ob_start(); |
|
| 101 | - |
|
| 102 | - // Backwards compatibility. |
|
| 103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | - |
|
| 105 | - // Display errors and notices. |
|
| 106 | - wpinv_print_errors(); |
|
| 107 | - |
|
| 108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | - |
|
| 110 | - // Print the table header. |
|
| 111 | - $this->print_table_header(); |
|
| 112 | - |
|
| 113 | - // Print table body. |
|
| 114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | - |
|
| 116 | - // Print table footer. |
|
| 117 | - $this->print_table_footer(); |
|
| 118 | - |
|
| 119 | - // Print the navigation. |
|
| 120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | - |
|
| 122 | - // Backwards compatibility. |
|
| 123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | - |
|
| 125 | - // Return the output. |
|
| 126 | - return ob_get_clean(); |
|
| 127 | - |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Retrieves the subscription columns. |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function get_subscriptions_table_columns() { |
|
| 17 | + /** |
|
| 18 | + * Register the widget with WordPress. |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + |
|
| 23 | + $options = array( |
|
| 24 | + 'textdomain' => 'invoicing', |
|
| 25 | + 'block-icon' => 'controls-repeat', |
|
| 26 | + 'block-category' => 'widgets', |
|
| 27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | + 'class_name' => __CLASS__, |
|
| 29 | + 'base_id' => 'wpinv_subscriptions', |
|
| 30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | + 'widget_ops' => array( |
|
| 32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | + ), |
|
| 35 | + 'arguments' => array( |
|
| 36 | + 'title' => array( |
|
| 37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | + 'type' => 'text', |
|
| 40 | + 'desc_tip' => true, |
|
| 41 | + 'default' => '', |
|
| 42 | + 'advanced' => false, |
|
| 43 | + ), |
|
| 44 | + ), |
|
| 45 | + |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + parent::__construct( $options ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Retrieves current user's subscriptions. |
|
| 53 | + * |
|
| 54 | + * @return GetPaid_Subscriptions_Query |
|
| 55 | + */ |
|
| 56 | + public function get_subscriptions() { |
|
| 57 | + |
|
| 58 | + // Prepare license args. |
|
| 59 | + $args = array( |
|
| 60 | + 'customer_in' => get_current_user_id(), |
|
| 61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The Super block output function. |
|
| 70 | + * |
|
| 71 | + * @param array $args |
|
| 72 | + * @param array $widget_args |
|
| 73 | + * @param string $content |
|
| 74 | + * |
|
| 75 | + * @return mixed|string|bool |
|
| 76 | + */ |
|
| 77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | + |
|
| 79 | + // Ensure that the user is logged in. |
|
| 80 | + if ( ! is_user_logged_in() ) { |
|
| 81 | + |
|
| 82 | + return aui()->alert( |
|
| 83 | + array( |
|
| 84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | + 'type' => 'error', |
|
| 86 | + ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Are we displaying a single subscription? |
|
| 92 | + if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Retrieve the user's subscriptions. |
|
| 97 | + $subscriptions = $this->get_subscriptions(); |
|
| 98 | + |
|
| 99 | + // Start the output buffer. |
|
| 100 | + ob_start(); |
|
| 101 | + |
|
| 102 | + // Backwards compatibility. |
|
| 103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | + |
|
| 105 | + // Display errors and notices. |
|
| 106 | + wpinv_print_errors(); |
|
| 107 | + |
|
| 108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | + |
|
| 110 | + // Print the table header. |
|
| 111 | + $this->print_table_header(); |
|
| 112 | + |
|
| 113 | + // Print table body. |
|
| 114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | + |
|
| 116 | + // Print table footer. |
|
| 117 | + $this->print_table_footer(); |
|
| 118 | + |
|
| 119 | + // Print the navigation. |
|
| 120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | + |
|
| 122 | + // Backwards compatibility. |
|
| 123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | + |
|
| 125 | + // Return the output. |
|
| 126 | + return ob_get_clean(); |
|
| 127 | + |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Retrieves the subscription columns. |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function get_subscriptions_table_columns() { |
|
| 136 | 136 | |
| 137 | - $columns = array( |
|
| 138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | - ); |
|
| 137 | + $columns = array( |
|
| 138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | + ); |
|
| 143 | 143 | |
| 144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | - } |
|
| 144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Displays the table header. |
|
| 149 | - * |
|
| 150 | - */ |
|
| 151 | - public function print_table_header() { |
|
| 147 | + /** |
|
| 148 | + * Displays the table header. |
|
| 149 | + * |
|
| 150 | + */ |
|
| 151 | + public function print_table_header() { |
|
| 152 | 152 | |
| 153 | - ?> |
|
| 153 | + ?> |
|
| 154 | 154 | |
| 155 | 155 | <table class="table table-bordered table-striped"> |
| 156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | <?php |
| 168 | 168 | |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Displays the table body. |
|
| 173 | - * |
|
| 174 | - * @param WPInv_Subscription[] $subscriptions |
|
| 175 | - */ |
|
| 176 | - public function print_table_body( $subscriptions ) { |
|
| 171 | + /** |
|
| 172 | + * Displays the table body. |
|
| 173 | + * |
|
| 174 | + * @param WPInv_Subscription[] $subscriptions |
|
| 175 | + */ |
|
| 176 | + public function print_table_body( $subscriptions ) { |
|
| 177 | 177 | |
| 178 | - if ( empty( $subscriptions ) ) { |
|
| 179 | - $this->print_table_body_no_subscriptions(); |
|
| 180 | - } else { |
|
| 181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | - } |
|
| 178 | + if ( empty( $subscriptions ) ) { |
|
| 179 | + $this->print_table_body_no_subscriptions(); |
|
| 180 | + } else { |
|
| 181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Displays the table body if no subscriptions were found. |
|
| 188 | - * |
|
| 189 | - */ |
|
| 190 | - public function print_table_body_no_subscriptions() { |
|
| 186 | + /** |
|
| 187 | + * Displays the table body if no subscriptions were found. |
|
| 188 | + * |
|
| 189 | + */ |
|
| 190 | + public function print_table_body_no_subscriptions() { |
|
| 191 | 191 | |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | <tbody> |
| 194 | 194 | |
| 195 | 195 | <tr> |
| 196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
| 197 | 197 | |
| 198 | 198 | <?php |
| 199 | - aui()->alert( |
|
| 200 | - array( |
|
| 201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | - 'type' => 'warning', |
|
| 203 | - ), |
|
| 199 | + aui()->alert( |
|
| 200 | + array( |
|
| 201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | + 'type' => 'warning', |
|
| 203 | + ), |
|
| 204 | 204 | true |
| 205 | - ); |
|
| 206 | - ?> |
|
| 205 | + ); |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
| 210 | 210 | |
| 211 | 211 | </tbody> |
| 212 | 212 | <?php |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Displays the table body if subscriptions were found. |
|
| 217 | - * |
|
| 218 | - * @param WPInv_Subscription[] $subscriptions |
|
| 219 | - */ |
|
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 215 | + /** |
|
| 216 | + * Displays the table body if subscriptions were found. |
|
| 217 | + * |
|
| 218 | + * @param WPInv_Subscription[] $subscriptions |
|
| 219 | + */ |
|
| 220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
| 221 | 221 | |
| 222 | - ?> |
|
| 222 | + ?> |
|
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | - wpinv_get_template( |
|
| 229 | - 'subscriptions/subscriptions-table-row.php', |
|
| 230 | - array( |
|
| 231 | - 'subscription' => $subscription, |
|
| 232 | - 'widget' => $this, |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - ?> |
|
| 228 | + wpinv_get_template( |
|
| 229 | + 'subscriptions/subscriptions-table-row.php', |
|
| 230 | + array( |
|
| 231 | + 'subscription' => $subscription, |
|
| 232 | + 'widget' => $this, |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + ?> |
|
| 236 | 236 | </tr> |
| 237 | 237 | <?php endforeach; ?> |
| 238 | 238 | |
| 239 | 239 | </tbody> |
| 240 | 240 | <?php |
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds row actions to a column |
|
| 245 | - * |
|
| 246 | - * @param string $content column content |
|
| 247 | - * @param WPInv_Subscription $subscription |
|
| 248 | - * @since 1.0.0 |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 252 | - |
|
| 253 | - // Prepare row actions. |
|
| 254 | - $actions = array(); |
|
| 255 | - |
|
| 256 | - // View subscription action. |
|
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | - |
|
| 261 | - // Filter the actions. |
|
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | - |
|
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | - $row_actions .= '</small>'; |
|
| 274 | - |
|
| 275 | - return $content . $row_actions; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Displays the table footer. |
|
| 280 | - * |
|
| 281 | - */ |
|
| 282 | - public function print_table_footer() { |
|
| 283 | - |
|
| 284 | - ?> |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds row actions to a column |
|
| 245 | + * |
|
| 246 | + * @param string $content column content |
|
| 247 | + * @param WPInv_Subscription $subscription |
|
| 248 | + * @since 1.0.0 |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function add_row_actions( $content, $subscription ) { |
|
| 252 | + |
|
| 253 | + // Prepare row actions. |
|
| 254 | + $actions = array(); |
|
| 255 | + |
|
| 256 | + // View subscription action. |
|
| 257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | + |
|
| 261 | + // Filter the actions. |
|
| 262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | + |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ( $actions as $key => $action ) { |
|
| 266 | + $key = sanitize_html_class( $key ); |
|
| 267 | + $action = wp_kses_post( $action ); |
|
| 268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | + $row_actions .= '</small>'; |
|
| 274 | + |
|
| 275 | + return $content . $row_actions; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Displays the table footer. |
|
| 280 | + * |
|
| 281 | + */ |
|
| 282 | + public function print_table_footer() { |
|
| 283 | + |
|
| 284 | + ?> |
|
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
| 296 | 296 | </table> |
| 297 | 297 | <?php |
| 298 | 298 | |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Displays the navigation. |
|
| 303 | - * |
|
| 304 | - * @param int $total |
|
| 305 | - */ |
|
| 306 | - public function print_navigation( $total ) { |
|
| 301 | + /** |
|
| 302 | + * Displays the navigation. |
|
| 303 | + * |
|
| 304 | + * @param int $total |
|
| 305 | + */ |
|
| 306 | + public function print_navigation( $total ) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ( $total < 1 ) { |
|
| 309 | 309 | |
| 310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | - $args = array( |
|
| 312 | - 'customer_in' => get_current_user_id(), |
|
| 313 | - 'fields' => 'id', |
|
| 314 | - ); |
|
| 310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | + $args = array( |
|
| 312 | + 'customer_in' => get_current_user_id(), |
|
| 313 | + 'fields' => 'id', |
|
| 314 | + ); |
|
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | - $total = $count_query->get_total(); |
|
| 318 | - } |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | + $total = $count_query->get_total(); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Abort if we do not have pages. |
|
| 321 | - if ( 2 > $total ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // Abort if we do not have pages. |
|
| 321 | + if ( 2 > $total ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - ?> |
|
| 325 | + ?> |
|
| 326 | 326 | |
| 327 | 327 | <div class="getpaid-subscriptions-pagination"> |
| 328 | 328 | <?php |
| 329 | - $big = 999999; |
|
| 330 | - |
|
| 331 | - echo wp_kses_post( |
|
| 332 | - getpaid_paginate_links( |
|
| 333 | - array( |
|
| 334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | - 'format' => '?paged=%#%', |
|
| 336 | - 'total' => (int) ceil( $total / 10 ), |
|
| 337 | - ) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 340 | - ?> |
|
| 329 | + $big = 999999; |
|
| 330 | + |
|
| 331 | + echo wp_kses_post( |
|
| 332 | + getpaid_paginate_links( |
|
| 333 | + array( |
|
| 334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | + 'format' => '?paged=%#%', |
|
| 336 | + 'total' => (int) ceil( $total / 10 ), |
|
| 337 | + ) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | + ?> |
|
| 341 | 341 | </div> |
| 342 | 342 | |
| 343 | 343 | <?php |
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Returns a single subscription's columns. |
|
| 348 | - * |
|
| 349 | - * @param WPInv_Subscription $subscription |
|
| 350 | - * |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function get_single_subscription_columns( $subscription ) { |
|
| 354 | - |
|
| 355 | - // Prepare subscription detail columns. |
|
| 356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | - $fields = apply_filters( |
|
| 359 | - 'getpaid_single_subscription_details_fields', |
|
| 360 | - array( |
|
| 361 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | - 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | - ), |
|
| 369 | - $subscription, |
|
| 370 | - $items_count |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | - |
|
| 375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | - unset( $fields['expiry_date'] ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | - unset( $fields['start_date'] ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | - unset( $fields['initial_amount'] ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $fields; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Displays a single subscription. |
|
| 397 | - * |
|
| 398 | - * @param string $subscription |
|
| 399 | - * |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function display_single_subscription( $subscription ) { |
|
| 403 | - |
|
| 404 | - // Fetch the subscription. |
|
| 405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | - |
|
| 407 | - if ( ! $subscription->exists() ) { |
|
| 408 | - |
|
| 409 | - return aui()->alert( |
|
| 410 | - array( |
|
| 411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | - 'type' => 'error', |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Ensure that the user owns this subscription key. |
|
| 419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | - |
|
| 421 | - return aui()->alert( |
|
| 422 | - array( |
|
| 423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | - 'type' => 'error', |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return wpinv_get_template_html( |
|
| 431 | - 'subscriptions/subscription-details.php', |
|
| 432 | - array( |
|
| 433 | - 'subscription' => $subscription, |
|
| 434 | - 'widget' => $this, |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Returns a single subscription's columns. |
|
| 348 | + * |
|
| 349 | + * @param WPInv_Subscription $subscription |
|
| 350 | + * |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function get_single_subscription_columns( $subscription ) { |
|
| 354 | + |
|
| 355 | + // Prepare subscription detail columns. |
|
| 356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | + $fields = apply_filters( |
|
| 359 | + 'getpaid_single_subscription_details_fields', |
|
| 360 | + array( |
|
| 361 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | + 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | + ), |
|
| 369 | + $subscription, |
|
| 370 | + $items_count |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | + |
|
| 375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | + unset( $fields['expiry_date'] ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | + unset( $fields['start_date'] ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | + unset( $fields['initial_amount'] ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $fields; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Displays a single subscription. |
|
| 397 | + * |
|
| 398 | + * @param string $subscription |
|
| 399 | + * |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function display_single_subscription( $subscription ) { |
|
| 403 | + |
|
| 404 | + // Fetch the subscription. |
|
| 405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | + |
|
| 407 | + if ( ! $subscription->exists() ) { |
|
| 408 | + |
|
| 409 | + return aui()->alert( |
|
| 410 | + array( |
|
| 411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | + 'type' => 'error', |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Ensure that the user owns this subscription key. |
|
| 419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | + |
|
| 421 | + return aui()->alert( |
|
| 422 | + array( |
|
| 423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | + 'type' => 'error', |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return wpinv_get_template_html( |
|
| 431 | + 'subscriptions/subscription-details.php', |
|
| 432 | + array( |
|
| 433 | + 'subscription' => $subscription, |
|
| 434 | + 'widget' => $this, |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @version 1.0.0 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
| 28 | 28 | 'class_name' => __CLASS__, |
| 29 | 29 | 'base_id' => 'wpinv_subscriptions', |
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
| 31 | 31 | 'widget_ops' => array( |
| 32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
| 34 | 34 | ), |
| 35 | 35 | 'arguments' => array( |
| 36 | 36 | 'title' => array( |
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 37 | + 'title' => __('Widget title', 'invoicing'), |
|
| 38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 39 | 39 | 'type' => 'text', |
| 40 | 40 | 'desc_tip' => true, |
| 41 | 41 | 'default' => '', |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - parent::__construct( $options ); |
|
| 48 | + parent::__construct($options); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | public function get_subscriptions() { |
| 57 | 57 | |
| 58 | 58 | // Prepare license args. |
| 59 | - $args = array( |
|
| 59 | + $args = array( |
|
| 60 | 60 | 'customer_in' => get_current_user_id(), |
| 61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 61 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 64 | + return new GetPaid_Subscriptions_Query($args); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return mixed|string|bool |
| 76 | 76 | */ |
| 77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 77 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 78 | 78 | |
| 79 | 79 | // Ensure that the user is logged in. |
| 80 | - if ( ! is_user_logged_in() ) { |
|
| 80 | + if (!is_user_logged_in()) { |
|
| 81 | 81 | |
| 82 | 82 | return aui()->alert( |
| 83 | 83 | array( |
| 84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 84 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
| 85 | 85 | 'type' => 'error', |
| 86 | 86 | ) |
| 87 | 87 | ); |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Are we displaying a single subscription? |
| 92 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 92 | + if (isset($_GET['subscription'])) { |
|
| 93 | + return $this->display_single_subscription(intval($_GET['subscription'])); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Retrieve the user's subscriptions. |
@@ -100,27 +100,27 @@ discard block |
||
| 100 | 100 | ob_start(); |
| 101 | 101 | |
| 102 | 102 | // Backwards compatibility. |
| 103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 103 | + do_action('wpinv_before_user_subscriptions'); |
|
| 104 | 104 | |
| 105 | 105 | // Display errors and notices. |
| 106 | 106 | wpinv_print_errors(); |
| 107 | 107 | |
| 108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 108 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
| 109 | 109 | |
| 110 | 110 | // Print the table header. |
| 111 | 111 | $this->print_table_header(); |
| 112 | 112 | |
| 113 | 113 | // Print table body. |
| 114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 114 | + $this->print_table_body($subscriptions->get_results()); |
|
| 115 | 115 | |
| 116 | 116 | // Print table footer. |
| 117 | 117 | $this->print_table_footer(); |
| 118 | 118 | |
| 119 | 119 | // Print the navigation. |
| 120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 120 | + $this->print_navigation($subscriptions->get_total()); |
|
| 121 | 121 | |
| 122 | 122 | // Backwards compatibility. |
| 123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 123 | + do_action('wpinv_after_user_subscriptions'); |
|
| 124 | 124 | |
| 125 | 125 | // Return the output. |
| 126 | 126 | return ob_get_clean(); |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | public function get_subscriptions_table_columns() { |
| 136 | 136 | |
| 137 | 137 | $columns = array( |
| 138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 138 | + 'subscription' => __('Subscription', 'invoicing'), |
|
| 139 | + 'amount' => __('Amount', 'invoicing'), |
|
| 140 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
| 141 | + 'status' => __('Status', 'invoicing'), |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 144 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | <thead> |
| 158 | 158 | <tr> |
| 159 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
| 160 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr( $key ); ?>"> |
|
| 161 | - <?php echo esc_html( $label ); ?> |
|
| 159 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
| 160 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr($key); ?>"> |
|
| 161 | + <?php echo esc_html($label); ?> |
|
| 162 | 162 | </th> |
| 163 | 163 | <?php endforeach; ?> |
| 164 | 164 | </tr> |
@@ -173,12 +173,12 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param WPInv_Subscription[] $subscriptions |
| 175 | 175 | */ |
| 176 | - public function print_table_body( $subscriptions ) { |
|
| 176 | + public function print_table_body($subscriptions) { |
|
| 177 | 177 | |
| 178 | - if ( empty( $subscriptions ) ) { |
|
| 178 | + if (empty($subscriptions)) { |
|
| 179 | 179 | $this->print_table_body_no_subscriptions(); |
| 180 | 180 | } else { |
| 181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 181 | + $this->print_table_body_subscriptions($subscriptions); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | <tbody> |
| 194 | 194 | |
| 195 | 195 | <tr> |
| 196 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
| 196 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
| 197 | 197 | |
| 198 | 198 | <?php |
| 199 | 199 | aui()->alert( |
| 200 | 200 | array( |
| 201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 201 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
| 202 | 202 | 'type' => 'warning', |
| 203 | 203 | ), |
| 204 | 204 | true |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @param WPInv_Subscription[] $subscriptions |
| 219 | 219 | */ |
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 220 | + public function print_table_body_subscriptions($subscriptions) { |
|
| 221 | 221 | |
| 222 | 222 | ?> |
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
| 225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | 228 | wpinv_get_template( |
@@ -248,28 +248,28 @@ discard block |
||
| 248 | 248 | * @since 1.0.0 |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 251 | + public function add_row_actions($content, $subscription) { |
|
| 252 | 252 | |
| 253 | 253 | // Prepare row actions. |
| 254 | 254 | $actions = array(); |
| 255 | 255 | |
| 256 | 256 | // View subscription action. |
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 257 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 258 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
| 260 | 260 | |
| 261 | 261 | // Filter the actions. |
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 262 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
| 263 | 263 | |
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ($actions as $key => $action) { |
|
| 266 | + $key = sanitize_html_class($key); |
|
| 267 | + $action = wp_kses_post($action); |
|
| 268 | 268 | $sanitized[] = "<span class='$key'>$action</span>"; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 272 | + $row_actions .= implode(' | ', $sanitized); |
|
| 273 | 273 | $row_actions .= '</small>'; |
| 274 | 274 | |
| 275 | 275 | return $content . $row_actions; |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
| 288 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
| 289 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr( $key ); ?>"> |
|
| 290 | - <?php echo esc_html( $label ); ?> |
|
| 288 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
| 289 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr($key); ?>"> |
|
| 290 | + <?php echo esc_html($label); ?> |
|
| 291 | 291 | </th> |
| 292 | 292 | <?php endforeach; ?> |
| 293 | 293 | </tr> |
@@ -303,22 +303,22 @@ discard block |
||
| 303 | 303 | * |
| 304 | 304 | * @param int $total |
| 305 | 305 | */ |
| 306 | - public function print_navigation( $total ) { |
|
| 306 | + public function print_navigation($total) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ($total < 1) { |
|
| 309 | 309 | |
| 310 | 310 | // Out-of-bounds, run the query again without LIMIT for total count. |
| 311 | - $args = array( |
|
| 311 | + $args = array( |
|
| 312 | 312 | 'customer_in' => get_current_user_id(), |
| 313 | 313 | 'fields' => 'id', |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
| 317 | 317 | $total = $count_query->get_total(); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // Abort if we do not have pages. |
| 321 | - if ( 2 > $total ) { |
|
| 321 | + if (2 > $total) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | echo wp_kses_post( |
| 332 | 332 | getpaid_paginate_links( |
| 333 | 333 | array( |
| 334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 334 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 335 | 335 | 'format' => '?paged=%#%', |
| 336 | - 'total' => (int) ceil( $total / 10 ), |
|
| 336 | + 'total' => (int) ceil($total / 10), |
|
| 337 | 337 | ) |
| 338 | 338 | ) |
| 339 | 339 | ); |
@@ -350,43 +350,43 @@ discard block |
||
| 350 | 350 | * |
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | - public function get_single_subscription_columns( $subscription ) { |
|
| 353 | + public function get_single_subscription_columns($subscription) { |
|
| 354 | 354 | |
| 355 | 355 | // Prepare subscription detail columns. |
| 356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 356 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
| 357 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
| 358 | 358 | $fields = apply_filters( |
| 359 | 359 | 'getpaid_single_subscription_details_fields', |
| 360 | 360 | array( |
| 361 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | - 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 361 | + 'status' => __('Status', 'invoicing'), |
|
| 362 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
| 363 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
| 364 | + 'start_date' => __('Start date', 'invoicing'), |
|
| 365 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
| 366 | + 'payments' => __('Payments', 'invoicing'), |
|
| 367 | + 'item' => $items_count > 1 ? __('Items', $items_count, 'invoicing') : __('Item', 'invoicing') |
|
| 368 | 368 | ), |
| 369 | 369 | $subscription, |
| 370 | 370 | $items_count |
| 371 | 371 | ); |
| 372 | 372 | |
| 373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
| 373 | + if (isset($fields['expiry_date'])) { |
|
| 374 | 374 | |
| 375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 375 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
| 376 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | - unset( $fields['expiry_date'] ); |
|
| 379 | + if ('pending' === $subscription->get_status()) { |
|
| 380 | + unset($fields['expiry_date']); |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | - unset( $fields['start_date'] ); |
|
| 384 | + if (isset($fields['start_date']) && 'pending' === $subscription->get_status()) { |
|
| 385 | + unset($fields['start_date']); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | - unset( $fields['initial_amount'] ); |
|
| 388 | + if ($subscription->get_initial_amount() === $subscription->get_recurring_amount()) { |
|
| 389 | + unset($fields['initial_amount']); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | return $fields; |
@@ -399,16 +399,16 @@ discard block |
||
| 399 | 399 | * |
| 400 | 400 | * @return string |
| 401 | 401 | */ |
| 402 | - public function display_single_subscription( $subscription ) { |
|
| 402 | + public function display_single_subscription($subscription) { |
|
| 403 | 403 | |
| 404 | 404 | // Fetch the subscription. |
| 405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 405 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
| 406 | 406 | |
| 407 | - if ( ! $subscription->exists() ) { |
|
| 407 | + if (!$subscription->exists()) { |
|
| 408 | 408 | |
| 409 | 409 | return aui()->alert( |
| 410 | 410 | array( |
| 411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 411 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
| 412 | 412 | 'type' => 'error', |
| 413 | 413 | ) |
| 414 | 414 | ); |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Ensure that the user owns this subscription key. |
| 419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 419 | + if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) { |
|
| 420 | 420 | |
| 421 | 421 | return aui()->alert( |
| 422 | 422 | array( |
| 423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 423 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
| 424 | 424 | 'type' => 'error', |
| 425 | 425 | ) |
| 426 | 426 | ); |
@@ -21,20 +21,20 @@ |
||
| 21 | 21 | |
| 22 | 22 | foreach ( $file_types as $file_type ) { |
| 23 | 23 | |
| 24 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | - $types[] = $all_types[ $file_type ]; |
|
| 26 | - $file_type = explode( '|', $file_type ); |
|
| 24 | + if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | + $types[] = $all_types[ $file_type ]; |
|
| 26 | + $file_type = explode( '|', $file_type ); |
|
| 27 | 27 | |
| 28 | - foreach ( $file_type as $type ) { |
|
| 29 | - $type = trim( $type ); |
|
| 30 | - $types[] = ".$type"; |
|
| 31 | - $_types[] = $type; |
|
| 32 | - } |
|
| 28 | + foreach ( $file_type as $type ) { |
|
| 29 | + $type = trim( $type ); |
|
| 30 | + $types[] = ".$type"; |
|
| 31 | + $_types[] = $type; |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ( ! empty( $required ) ) { |
| 37 | - $label .= "<span class='text-danger'> *</span>"; |
|
| 37 | + $label .= "<span class='text-danger'> *</span>"; |
|
| 38 | 38 | } |
| 39 | 39 | ?> |
| 40 | 40 | <label><span v-html="form_element.label"></span></label> |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | /** |
| 3 | 3 | * Displays a file_upload input in a payment form |
| 4 | 4 | * |
@@ -7,36 +7,36 @@ discard block |
||
| 7 | 7 | * @version 2.8.9 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | + defined( 'ABSPATH' ) || exit; |
|
| 11 | 11 | |
| 12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
| 13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
| 14 | -$id = esc_attr( $id ); |
|
| 15 | -$_id = $id . uniqid( '_' ); |
|
| 16 | -$max_file_num = empty( $max_file_num ) ? 1 : absint( $max_file_num ); |
|
| 17 | -$file_types = empty( $file_types ) ? array( 'jpg|jpeg|jpe', 'gif', 'png' ) : $file_types; |
|
| 18 | -$all_types = getpaid_get_allowed_mime_types(); |
|
| 19 | -$types = array(); |
|
| 20 | -$_types = array(); |
|
| 12 | + $label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
| 13 | + $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
| 14 | + $id = esc_attr( $id ); |
|
| 15 | + $_id = $id . uniqid( '_' ); |
|
| 16 | + $max_file_num = empty( $max_file_num ) ? 1 : absint( $max_file_num ); |
|
| 17 | + $file_types = empty( $file_types ) ? array( 'jpg|jpeg|jpe', 'gif', 'png' ) : $file_types; |
|
| 18 | + $all_types = getpaid_get_allowed_mime_types(); |
|
| 19 | + $types = array(); |
|
| 20 | + $_types = array(); |
|
| 21 | 21 | |
| 22 | -foreach ( $file_types as $file_type ) { |
|
| 22 | + foreach ( $file_types as $file_type ) { |
|
| 23 | 23 | |
| 24 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | - $types[] = $all_types[ $file_type ]; |
|
| 26 | - $file_type = explode( '|', $file_type ); |
|
| 24 | + if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | + $types[] = $all_types[ $file_type ]; |
|
| 26 | + $file_type = explode( '|', $file_type ); |
|
| 27 | 27 | |
| 28 | - foreach ( $file_type as $type ) { |
|
| 29 | - $type = trim( $type ); |
|
| 30 | - $types[] = ".$type"; |
|
| 31 | - $_types[] = $type; |
|
| 32 | - } |
|
| 28 | + foreach ( $file_type as $type ) { |
|
| 29 | + $type = trim( $type ); |
|
| 30 | + $types[] = ".$type"; |
|
| 31 | + $_types[] = $type; |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -if ( ! empty( $required ) ) { |
|
| 37 | - $label .= "<span class='text-danger'> *</span>"; |
|
| 36 | + if ( ! empty( $required ) ) { |
|
| 37 | + $label .= "<span class='text-danger'> *</span>"; |
|
| 38 | 38 | } |
| 39 | -?> |
|
| 39 | + ?> |
|
| 40 | 40 | <label><span v-html="form_element.label"></span></label> |
| 41 | 41 | <div class="form-group mb-3 <?php echo esc_attr( $label_class ); ?>" data-name="<?php echo esc_attr( $id ); ?>" data-max="<?php echo esc_attr( $max_file_num ); ?>"> |
| 42 | 42 | <label for="<?php echo esc_attr( $id ); ?>"><?php echo wp_kses_post( $label ); ?></label> |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | <label for="<?php echo esc_attr( $id ); ?>" class="getpaid-file-upload-element d-flex w-100 flex-column align-items-center justify-content-center p-2 mb-2"> |
| 45 | 45 | <div class="h5 text-dark"> |
| 46 | 46 | <?php echo esc_html( ( $max_file_num > 1 ? __( 'Drag files to this area or click to upload', 'invoicing' ) : __( 'Drag your file to this area or click to upload', 'invoicing' ) ) ); ?> |
| 47 | - </div> |
|
| 47 | + </div> |
|
| 48 | 48 | <?php if ( ! empty( $description ) ) : ?> |
| 49 | - <small class="form-text text-muted"><?php echo wp_kses_post( $description ); ?></small> |
|
| 49 | + <small class="form-text text-muted"><?php echo wp_kses_post( $description ); ?></small> |
|
| 50 | 50 | <?php endif; ?> |
| 51 | 51 | </label> |
| 52 | 52 | <div class="getpaid-uploaded-files"></div> |
@@ -7,52 +7,52 @@ |
||
| 7 | 7 | * @version 2.8.9 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
| 13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
| 14 | -$id = esc_attr( $id ); |
|
| 15 | -$_id = $id . uniqid( '_' ); |
|
| 16 | -$max_file_num = empty( $max_file_num ) ? 1 : absint( $max_file_num ); |
|
| 17 | -$file_types = empty( $file_types ) ? array( 'jpg|jpeg|jpe', 'gif', 'png' ) : $file_types; |
|
| 12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
| 13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
| 14 | +$id = esc_attr($id); |
|
| 15 | +$_id = $id . uniqid('_'); |
|
| 16 | +$max_file_num = empty($max_file_num) ? 1 : absint($max_file_num); |
|
| 17 | +$file_types = empty($file_types) ? array('jpg|jpeg|jpe', 'gif', 'png') : $file_types; |
|
| 18 | 18 | $all_types = getpaid_get_allowed_mime_types(); |
| 19 | 19 | $types = array(); |
| 20 | 20 | $_types = array(); |
| 21 | 21 | |
| 22 | -foreach ( $file_types as $file_type ) { |
|
| 22 | +foreach ($file_types as $file_type) { |
|
| 23 | 23 | |
| 24 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | - $types[] = $all_types[ $file_type ]; |
|
| 26 | - $file_type = explode( '|', $file_type ); |
|
| 24 | + if (isset($all_types[$file_type])) { |
|
| 25 | + $types[] = $all_types[$file_type]; |
|
| 26 | + $file_type = explode('|', $file_type); |
|
| 27 | 27 | |
| 28 | - foreach ( $file_type as $type ) { |
|
| 29 | - $type = trim( $type ); |
|
| 28 | + foreach ($file_type as $type) { |
|
| 29 | + $type = trim($type); |
|
| 30 | 30 | $types[] = ".$type"; |
| 31 | 31 | $_types[] = $type; |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -if ( ! empty( $required ) ) { |
|
| 36 | +if (!empty($required)) { |
|
| 37 | 37 | $label .= "<span class='text-danger'> *</span>"; |
| 38 | 38 | } |
| 39 | 39 | ?> |
| 40 | 40 | <label><span v-html="form_element.label"></span></label> |
| 41 | -<div class="form-group mb-3 <?php echo esc_attr( $label_class ); ?>" data-name="<?php echo esc_attr( $id ); ?>" data-max="<?php echo esc_attr( $max_file_num ); ?>"> |
|
| 42 | - <label for="<?php echo esc_attr( $id ); ?>"><?php echo wp_kses_post( $label ); ?></label> |
|
| 43 | - <input type="file" class="sr-only getpaid-files-input" id="<?php echo esc_attr( $id ); ?>" accept="<?php echo esc_attr( implode( ', ', $types ) ); ?>" data-extensions="<?php echo esc_attr( wp_json_encode( $_types ) ); ?>" <?php echo $max_file_num == 1 ? '' : 'multiple="multiple"'; ?>> |
|
| 44 | - <label for="<?php echo esc_attr( $id ); ?>" class="getpaid-file-upload-element d-flex w-100 flex-column align-items-center justify-content-center p-2 mb-2"> |
|
| 41 | +<div class="form-group mb-3 <?php echo esc_attr($label_class); ?>" data-name="<?php echo esc_attr($id); ?>" data-max="<?php echo esc_attr($max_file_num); ?>"> |
|
| 42 | + <label for="<?php echo esc_attr($id); ?>"><?php echo wp_kses_post($label); ?></label> |
|
| 43 | + <input type="file" class="sr-only getpaid-files-input" id="<?php echo esc_attr($id); ?>" accept="<?php echo esc_attr(implode(', ', $types)); ?>" data-extensions="<?php echo esc_attr(wp_json_encode($_types)); ?>" <?php echo $max_file_num == 1 ? '' : 'multiple="multiple"'; ?>> |
|
| 44 | + <label for="<?php echo esc_attr($id); ?>" class="getpaid-file-upload-element d-flex w-100 flex-column align-items-center justify-content-center p-2 mb-2"> |
|
| 45 | 45 | <div class="h5 text-dark"> |
| 46 | - <?php echo esc_html( ( $max_file_num > 1 ? __( 'Drag files to this area or click to upload', 'invoicing' ) : __( 'Drag your file to this area or click to upload', 'invoicing' ) ) ); ?> |
|
| 46 | + <?php echo esc_html(($max_file_num > 1 ? __('Drag files to this area or click to upload', 'invoicing') : __('Drag your file to this area or click to upload', 'invoicing'))); ?> |
|
| 47 | 47 | </div> |
| 48 | - <?php if ( ! empty( $description ) ) : ?> |
|
| 49 | - <small class="form-text text-muted"><?php echo wp_kses_post( $description ); ?></small> |
|
| 48 | + <?php if (!empty($description)) : ?> |
|
| 49 | + <small class="form-text text-muted"><?php echo wp_kses_post($description); ?></small> |
|
| 50 | 50 | <?php endif; ?> |
| 51 | 51 | </label> |
| 52 | 52 | <div class="getpaid-uploaded-files"></div> |
| 53 | 53 | <div class="form-row row mb-3 d-none getpaid-progress-template"> |
| 54 | 54 | <div class="overflow-hidden text-nowrap col-7 col-sm-4"> |
| 55 | - <a href="" class="close float-none" title="<?php esc_attr_e( 'Remove File', 'invoicing' ); ?>">×<span class="sr-only"><?php esc_html_e( 'Close', 'invoicing' ); ?></span></a> |
|
| 55 | + <a href="" class="close float-none" title="<?php esc_attr_e('Remove File', 'invoicing'); ?>">×<span class="sr-only"><?php esc_html_e('Close', 'invoicing'); ?></span></a> |
|
| 56 | 56 | <i class="fa fa-file" aria-hidden="true"></i> <span class="getpaid-progress-file-name"></span> |
| 57 | 57 | </div> |
| 58 | 58 | <div class="col-5 col-sm-8 getpaid-progress"> |