@@ -7,40 +7,40 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( ! defined( 'WPINC' ) ) { |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_is_checkout() { |
| 15 | 15 | global $wp_query; |
| 16 | 16 | |
| 17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
| 18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
| 19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
| 20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
| 17 | + $is_object_set = isset($wp_query->queried_object); |
|
| 18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
| 19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
| 20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
| 21 | 21 | |
| 22 | - if ( ! $is_object_set ) { |
|
| 23 | - unset( $wp_query->queried_object ); |
|
| 22 | + if (!$is_object_set) { |
|
| 23 | + unset($wp_query->queried_object); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if ( ! $is_object_id_set ) { |
|
| 27 | - unset( $wp_query->queried_object_id ); |
|
| 26 | + if (!$is_object_id_set) { |
|
| 27 | + unset($wp_query->queried_object_id); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
| 30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function wpinv_can_checkout() { |
| 34 | 34 | $can_checkout = true; // Always true for now |
| 35 | 35 | |
| 36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function wpinv_get_success_page_uri() { |
| 40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 41 | - $page_id = absint( $page_id ); |
|
| 40 | + $page_id = wpinv_get_option('success_page', 0); |
|
| 41 | + $page_id = absint($page_id); |
|
| 42 | 42 | |
| 43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -49,143 +49,143 @@ discard block |
||
| 49 | 49 | * @param string $post_type The post type or invoice type. |
| 50 | 50 | * @return string The history page URL. |
| 51 | 51 | */ |
| 52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
| 53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
| 54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
| 55 | - $page_id = absint( $page_id ); |
|
| 56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
| 52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
| 53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
| 54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
| 55 | + $page_id = absint($page_id); |
|
| 56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_success_page() { |
| 60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
| 61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
| 62 | 62 | |
| 63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function wpinv_is_invoice_history_page() { |
| 67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 68 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
| 68 | + $ret = $ret ? is_page($ret) : false; |
|
| 69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function wpinv_is_subscriptions_history_page() { |
| 73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 74 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
| 73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
| 74 | + $ret = $ret ? is_page($ret) : false; |
|
| 75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Redirects a user the success page. |
| 80 | 80 | */ |
| 81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
| 81 | +function wpinv_send_to_success_page($args = array()) { |
|
| 82 | 82 | |
| 83 | 83 | $redirect = add_query_arg( |
| 84 | - wp_parse_args( $args ), |
|
| 84 | + wp_parse_args($args), |
|
| 85 | 85 | wpinv_get_success_page_uri() |
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args ); |
|
| 88 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args); |
|
| 89 | 89 | |
| 90 | - wp_redirect( $redirect ); |
|
| 90 | + wp_redirect($redirect); |
|
| 91 | 91 | exit; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | -function wpinv_send_to_failed_page( $args = null ) { |
|
| 94 | +function wpinv_send_to_failed_page($args = null) { |
|
| 95 | 95 | $redirect = wpinv_get_failed_transaction_uri(); |
| 96 | 96 | |
| 97 | - if ( ! empty( $args ) ) { |
|
| 97 | + if (!empty($args)) { |
|
| 98 | 98 | // Check for backward compatibility |
| 99 | - if ( is_string( $args ) ) { |
|
| 100 | - $args = str_replace( '?', '', $args ); |
|
| 99 | + if (is_string($args)) { |
|
| 100 | + $args = str_replace('?', '', $args); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $args = wp_parse_args( $args ); |
|
| 103 | + $args = wp_parse_args($args); |
|
| 104 | 104 | |
| 105 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 105 | + $redirect = add_query_arg($args, $redirect); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 108 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 109 | 109 | |
| 110 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
| 111 | - wp_redirect( $redirect ); |
|
| 110 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
| 111 | + wp_redirect($redirect); |
|
| 112 | 112 | exit; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
| 116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
| 115 | +function wpinv_get_checkout_uri($args = array()) { |
|
| 116 | + $uri = wpinv_get_option('checkout_page', false); |
|
| 117 | + $uri = isset($uri) ? get_permalink($uri) : null; |
|
| 118 | 118 | |
| 119 | - if ( ! empty( $args ) ) { |
|
| 119 | + if (!empty($args)) { |
|
| 120 | 120 | // Check for backward compatibility |
| 121 | - if ( is_string( $args ) ) { |
|
| 122 | - $args = str_replace( '?', '', $args ); |
|
| 121 | + if (is_string($args)) { |
|
| 122 | + $args = str_replace('?', '', $args); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $args = wp_parse_args( $args ); |
|
| 125 | + $args = wp_parse_args($args); |
|
| 126 | 126 | |
| 127 | - $uri = add_query_arg( $args, $uri ); |
|
| 127 | + $uri = add_query_arg($args, $uri); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 130 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 131 | 131 | |
| 132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 132 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
| 133 | 133 | |
| 134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 134 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
| 135 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 138 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
| 142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 143 | - $success_page = get_permalink( $success_page ); |
|
| 141 | +function wpinv_get_success_page_url($query_string = null) { |
|
| 142 | + $success_page = wpinv_get_option('success_page', 0); |
|
| 143 | + $success_page = get_permalink($success_page); |
|
| 144 | 144 | |
| 145 | - if ( $query_string ) { |
|
| 145 | + if ($query_string) { |
|
| 146 | 146 | $success_page .= $query_string; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 149 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
| 153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 152 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
| 153 | + $uri = wpinv_get_option('failure_page', ''); |
|
| 154 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
| 155 | 155 | |
| 156 | - if ( $extras ) { |
|
| 156 | + if ($extras) { |
|
| 157 | 157 | $uri .= $extras; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 160 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function wpinv_is_failed_transaction_page() { |
| 164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 164 | + $ret = wpinv_get_option('failure_page', false); |
|
| 165 | + $ret = isset($ret) ? is_page($ret) : false; |
|
| 166 | 166 | |
| 167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 167 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | -function wpinv_transaction_query( $type = 'start' ) { |
|
| 170 | +function wpinv_transaction_query($type = 'start') { |
|
| 171 | 171 | global $wpdb; |
| 172 | 172 | |
| 173 | 173 | $wpdb->hide_errors(); |
| 174 | 174 | |
| 175 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
| 176 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
| 175 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
| 176 | + define('WPINV_USE_TRANSACTIONS', true); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
| 180 | - switch ( $type ) { |
|
| 179 | + if (WPINV_USE_TRANSACTIONS) { |
|
| 180 | + switch ($type) { |
|
| 181 | 181 | case 'commit': |
| 182 | - $wpdb->query( 'COMMIT' ); |
|
| 182 | + $wpdb->query('COMMIT'); |
|
| 183 | 183 | break; |
| 184 | 184 | case 'rollback': |
| 185 | - $wpdb->query( 'ROLLBACK' ); |
|
| 185 | + $wpdb->query('ROLLBACK'); |
|
| 186 | 186 | break; |
| 187 | 187 | default: |
| 188 | - $wpdb->query( 'START TRANSACTION' ); |
|
| 188 | + $wpdb->query('START TRANSACTION'); |
|
| 189 | 189 | break; |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -194,146 +194,146 @@ discard block |
||
| 194 | 194 | function wpinv_get_prefix() { |
| 195 | 195 | $invoice_prefix = 'INV-'; |
| 196 | 196 | |
| 197 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
| 197 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | function wpinv_get_business_logo() { |
| 201 | - $business_logo = wpinv_get_option( 'logo' ); |
|
| 202 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
| 201 | + $business_logo = wpinv_get_option('logo'); |
|
| 202 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function wpinv_get_business_name() { |
| 206 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
| 206 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
| 207 | 207 | |
| 208 | - if ( empty( $name ) ) { |
|
| 208 | + if (empty($name)) { |
|
| 209 | 209 | $name = wpinv_get_blogname(); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
| 212 | + return apply_filters('wpinv_get_business_name', $name); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | function wpinv_get_blogname() { |
| 216 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
| 216 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | function wpinv_get_admin_email() { |
| 220 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
| 221 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
| 220 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
| 221 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | function wpinv_get_business_website() { |
| 225 | - $business_website = home_url( '/' ); |
|
| 226 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
| 225 | + $business_website = home_url('/'); |
|
| 226 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
| 229 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
| 230 | 230 | $terms_text = ''; |
| 231 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
| 231 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | function wpinv_get_business_footer() { |
| 235 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
| 236 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
| 237 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
| 235 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
| 236 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
| 237 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | function wpinv_checkout_required_fields() { |
| 241 | 241 | $required_fields = array(); |
| 242 | 242 | |
| 243 | 243 | // Let payment gateways and other extensions determine if address fields should be required |
| 244 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
| 244 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
| 245 | 245 | |
| 246 | - if ( $require_billing_details ) { |
|
| 247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
| 246 | + if ($require_billing_details) { |
|
| 247 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
| 248 | 248 | $required_fields['first_name'] = array( |
| 249 | 249 | 'error_id' => 'invalid_first_name', |
| 250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
| 250 | + 'error_message' => __('Please enter your first name', 'invoicing'), |
|
| 251 | 251 | ); |
| 252 | 252 | } |
| 253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
| 253 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
| 254 | 254 | $required_fields['address'] = array( |
| 255 | 255 | 'error_id' => 'invalid_address', |
| 256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
| 256 | + 'error_message' => __('Please enter your address', 'invoicing'), |
|
| 257 | 257 | ); |
| 258 | 258 | } |
| 259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
| 259 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
| 260 | 260 | $required_fields['city'] = array( |
| 261 | 261 | 'error_id' => 'invalid_city', |
| 262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
| 262 | + 'error_message' => __('Please enter your billing city', 'invoicing'), |
|
| 263 | 263 | ); |
| 264 | 264 | } |
| 265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
| 265 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
| 266 | 266 | $required_fields['state'] = array( |
| 267 | 267 | 'error_id' => 'invalid_state', |
| 268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
| 268 | + 'error_message' => __('Please enter billing state / province', 'invoicing'), |
|
| 269 | 269 | ); |
| 270 | 270 | } |
| 271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
| 271 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
| 272 | 272 | $required_fields['country'] = array( |
| 273 | 273 | 'error_id' => 'invalid_country', |
| 274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
| 274 | + 'error_message' => __('Please select your billing country', 'invoicing'), |
|
| 275 | 275 | ); |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
| 279 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | function wpinv_is_ssl_enforced() { |
| 283 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
| 284 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
| 283 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
| 284 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | function wpinv_schedule_event_twicedaily() { |
| 288 | 288 | wpinv_email_payment_reminders(); |
| 289 | 289 | } |
| 290 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
| 290 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
| 291 | 291 | |
| 292 | 292 | function wpinv_require_login_to_checkout() { |
| 293 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
| 294 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
| 293 | + $return = wpinv_get_option('login_to_checkout', false); |
|
| 294 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_sequential_number_active( $type = '' ) { |
|
| 298 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
| 299 | - if ( null !== $check ) { |
|
| 297 | +function wpinv_sequential_number_active($type = '') { |
|
| 298 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
| 299 | + if (null !== $check) { |
|
| 300 | 300 | return $check; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
| 303 | + return wpinv_get_option('sequential_invoice_number'); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | -function wpinv_switch_to_locale( $locale = null ) { |
|
| 306 | +function wpinv_switch_to_locale($locale = null) { |
|
| 307 | 307 | global $invoicing, $wpi_switch_locale; |
| 308 | 308 | |
| 309 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
| 310 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
| 309 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
| 310 | + $locale = empty($locale) ? get_locale() : $locale; |
|
| 311 | 311 | |
| 312 | - switch_to_locale( $locale ); |
|
| 312 | + switch_to_locale($locale); |
|
| 313 | 313 | |
| 314 | 314 | $wpi_switch_locale = $locale; |
| 315 | 315 | |
| 316 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
| 316 | + add_filter('plugin_locale', 'get_locale'); |
|
| 317 | 317 | |
| 318 | 318 | $invoicing->load_textdomain(); |
| 319 | 319 | |
| 320 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
| 320 | + do_action('wpinv_switch_to_locale', $locale); |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | function wpinv_restore_locale() { |
| 325 | 325 | global $invoicing, $wpi_switch_locale; |
| 326 | 326 | |
| 327 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
| 327 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
| 328 | 328 | restore_previous_locale(); |
| 329 | 329 | |
| 330 | 330 | $wpi_switch_locale = null; |
| 331 | 331 | |
| 332 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
| 332 | + remove_filter('plugin_locale', 'get_locale'); |
|
| 333 | 333 | |
| 334 | 334 | $invoicing->load_textdomain(); |
| 335 | 335 | |
| 336 | - do_action( 'wpinv_restore_locale' ); |
|
| 336 | + do_action('wpinv_restore_locale'); |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
@@ -341,26 +341,26 @@ discard block |
||
| 341 | 341 | * Returns the default form's id. |
| 342 | 342 | */ |
| 343 | 343 | function wpinv_get_default_payment_form() { |
| 344 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
| 344 | + $form = get_option('wpinv_default_payment_form'); |
|
| 345 | 345 | |
| 346 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
| 346 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
| 347 | 347 | $form = wp_insert_post( |
| 348 | 348 | array( |
| 349 | 349 | 'post_type' => 'wpi_payment_form', |
| 350 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
| 350 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
| 351 | 351 | 'post_status' => 'publish', |
| 352 | 352 | 'meta_input' => array( |
| 353 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
| 353 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
| 354 | 354 | 'wpinv_form_items' => array(), |
| 355 | 355 | ), |
| 356 | 356 | ) |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | - update_option( 'wpinv_default_payment_form', $form ); |
|
| 359 | + update_option('wpinv_default_payment_form', $form); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // WPML support. |
| 363 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', true ); |
|
| 363 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', true); |
|
| 364 | 364 | return (int) $form; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -369,19 +369,19 @@ discard block |
||
| 369 | 369 | * |
| 370 | 370 | * @param int $payment_form |
| 371 | 371 | */ |
| 372 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
| 372 | +function getpaid_get_payment_form_elements($payment_form) { |
|
| 373 | 373 | |
| 374 | - if ( empty( $payment_form ) ) { |
|
| 375 | - return wpinv_get_data( 'sample-payment-form' ); |
|
| 374 | + if (empty($payment_form)) { |
|
| 375 | + return wpinv_get_data('sample-payment-form'); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
| 378 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
| 379 | 379 | |
| 380 | - if ( is_array( $form_elements ) ) { |
|
| 380 | + if (is_array($form_elements)) { |
|
| 381 | 381 | return $form_elements; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - return wpinv_get_data( 'sample-payment-form' ); |
|
| 384 | + return wpinv_get_data('sample-payment-form'); |
|
| 385 | 385 | |
| 386 | 386 | } |
| 387 | 387 | |
@@ -390,65 +390,65 @@ discard block |
||
| 390 | 390 | * |
| 391 | 391 | * @param int $payment_form |
| 392 | 392 | */ |
| 393 | -function gepaid_get_form_items( $id ) { |
|
| 394 | - $form = new GetPaid_Payment_Form( $id ); |
|
| 393 | +function gepaid_get_form_items($id) { |
|
| 394 | + $form = new GetPaid_Payment_Form($id); |
|
| 395 | 395 | |
| 396 | 396 | // Is this a default form? |
| 397 | - if ( $form->is_default() ) { |
|
| 397 | + if ($form->is_default()) { |
|
| 398 | 398 | return array(); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - return $form->get_items( 'view', 'arrays' ); |
|
| 401 | + return $form->get_items('view', 'arrays'); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | 405 | * Trims each line in a paragraph. |
| 406 | 406 | * |
| 407 | 407 | */ |
| 408 | -function gepaid_trim_lines( $content ) { |
|
| 409 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
| 408 | +function gepaid_trim_lines($content) { |
|
| 409 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
| 413 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
| 413 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
| 414 | 414 | $elements_manager->add_category( |
| 415 | 415 | 'getpaid', |
| 416 | 416 | array( |
| 417 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
| 417 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
| 418 | 418 | 'icon' => 'fa fa-plug', |
| 419 | 419 | ) |
| 420 | 420 | ); |
| 421 | 421 | } |
| 422 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
| 422 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
| 423 | 423 | |
| 424 | -function wpinv_alter_elementor_widget_config( $config ) { |
|
| 424 | +function wpinv_alter_elementor_widget_config($config) { |
|
| 425 | 425 | |
| 426 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
| 427 | - foreach ( $config['initial_document']['widgets'] as $key => $widget ) { |
|
| 428 | - if ( substr( $key, 0, 16 ) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid' ) { |
|
| 429 | - $config['initial_document']['widgets'][ $key ]['categories'][] = 'getpaid'; |
|
| 430 | - $config['initial_document']['widgets'][ $key ]['hide_on_search'] = false; |
|
| 431 | - $config['initial_document']['widgets'][ $key ]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
| 426 | + if (!empty($config['initial_document']['widgets'])) { |
|
| 427 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
| 428 | + if (substr($key, 0, 16) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid') { |
|
| 429 | + $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
|
| 430 | + $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
|
| 431 | + $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | return $config; |
| 437 | 437 | } |
| 438 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
| 438 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
| 439 | 439 | |
| 440 | 440 | function wpinv_get_report_graphs() { |
| 441 | 441 | |
| 442 | 442 | return apply_filters( |
| 443 | 443 | 'getpaid_report_graphs', |
| 444 | 444 | array( |
| 445 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
| 446 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
| 447 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
| 448 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
| 449 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
| 450 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 451 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
| 445 | + 'sales' => __('Earnings', 'invoicing'), |
|
| 446 | + 'refunds' => __('Refunds', 'invoicing'), |
|
| 447 | + 'tax' => __('Taxes', 'invoicing'), |
|
| 448 | + 'fees' => __('Fees', 'invoicing'), |
|
| 449 | + 'discount' => __('Discounts', 'invoicing'), |
|
| 450 | + 'invoices' => __('Invoices', 'invoicing'), |
|
| 451 | + 'items' => __('Purchased Items', 'invoicing'), |
|
| 452 | 452 | ) |
| 453 | 453 | ); |
| 454 | 454 | |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class GetPaid_Meta_Box_Description { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Output the metabox. |
|
| 18 | - * |
|
| 19 | - * @param WP_Post $post Post object. |
|
| 20 | - */ |
|
| 21 | - public static function output( $post ) { |
|
| 16 | + /** |
|
| 17 | + * Output the metabox. |
|
| 18 | + * |
|
| 19 | + * @param WP_Post $post Post object. |
|
| 20 | + */ |
|
| 21 | + public static function output( $post ) { |
|
| 22 | 22 | |
| 23 | - $settings = array( |
|
| 24 | - 'textarea_name' => 'excerpt', |
|
| 25 | - 'quicktags' => array( 'buttons' => 'em,strong,link' ), |
|
| 26 | - 'teeny' => true, |
|
| 27 | - 'media_buttons' => false, |
|
| 28 | - 'tinymce' => array( |
|
| 29 | - 'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator', |
|
| 30 | - 'theme_advanced_buttons2' => '', |
|
| 31 | - ), |
|
| 32 | - 'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>', |
|
| 33 | - ); |
|
| 23 | + $settings = array( |
|
| 24 | + 'textarea_name' => 'excerpt', |
|
| 25 | + 'quicktags' => array( 'buttons' => 'em,strong,link' ), |
|
| 26 | + 'teeny' => true, |
|
| 27 | + 'media_buttons' => false, |
|
| 28 | + 'tinymce' => array( |
|
| 29 | + 'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator', |
|
| 30 | + 'theme_advanced_buttons2' => '', |
|
| 31 | + ), |
|
| 32 | + 'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>', |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - wp_editor( htmlspecialchars_decode( $post->post_excerpt, ENT_QUOTES ), 'excerpt', apply_filters( 'getpaid_description_editor_settings', $settings ) ); |
|
| 36 | - } |
|
| 35 | + wp_editor( htmlspecialchars_decode( $post->post_excerpt, ENT_QUOTES ), 'excerpt', apply_filters( 'getpaid_description_editor_settings', $settings ) ); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * GetPaid_Meta_Box_Description Class. |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param WP_Post $post Post object. |
| 20 | 20 | */ |
| 21 | - public static function output( $post ) { |
|
| 21 | + public static function output($post) { |
|
| 22 | 22 | |
| 23 | 23 | $settings = array( |
| 24 | 24 | 'textarea_name' => 'excerpt', |
| 25 | - 'quicktags' => array( 'buttons' => 'em,strong,link' ), |
|
| 25 | + 'quicktags' => array('buttons' => 'em,strong,link'), |
|
| 26 | 26 | 'teeny' => true, |
| 27 | 27 | 'media_buttons' => false, |
| 28 | 28 | 'tinymce' => array( |
@@ -32,6 +32,6 @@ discard block |
||
| 32 | 32 | 'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>', |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - wp_editor( htmlspecialchars_decode( $post->post_excerpt, ENT_QUOTES ), 'excerpt', apply_filters( 'getpaid_description_editor_settings', $settings ) ); |
|
| 35 | + wp_editor(htmlspecialchars_decode($post->post_excerpt, ENT_QUOTES), 'excerpt', apply_filters('getpaid_description_editor_settings', $settings)); |
|
| 36 | 36 | } |
| 37 | 37 | } |
@@ -12,280 +12,280 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Metaboxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Only save metaboxes once. |
|
| 17 | - * |
|
| 18 | - * @var boolean |
|
| 19 | - */ |
|
| 20 | - private static $saved_meta_boxes = false; |
|
| 15 | + /** |
|
| 16 | + * Only save metaboxes once. |
|
| 17 | + * |
|
| 18 | + * @var boolean |
|
| 19 | + */ |
|
| 20 | + private static $saved_meta_boxes = false; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Hook in methods. |
|
| 24 | - */ |
|
| 25 | - public static function init() { |
|
| 23 | + * Hook in methods. |
|
| 24 | + */ |
|
| 25 | + public static function init() { |
|
| 26 | 26 | |
| 27 | - // Register metaboxes. |
|
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 ); |
|
| 27 | + // Register metaboxes. |
|
| 28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 ); |
|
| 29 | 29 | |
| 30 | - // Remove metaboxes. |
|
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 30 | + // Remove metaboxes. |
|
| 31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 32 | 32 | |
| 33 | - // Rename metaboxes. |
|
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 33 | + // Rename metaboxes. |
|
| 34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 35 | 35 | |
| 36 | - // Save metaboxes. |
|
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | - } |
|
| 36 | + // Save metaboxes. |
|
| 37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Register core metaboxes. |
|
| 42 | - */ |
|
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 40 | + /** |
|
| 41 | + * Register core metaboxes. |
|
| 42 | + */ |
|
| 43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
| 44 | 44 | |
| 45 | - // For invoices. |
|
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 45 | + // For invoices. |
|
| 46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 47 | 47 | |
| 48 | - // For payment forms. |
|
| 49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 48 | + // For payment forms. |
|
| 49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 50 | 50 | |
| 51 | - // For invoice items. |
|
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 51 | + // For invoice items. |
|
| 52 | + self::add_item_meta_boxes( $post_type ); |
|
| 53 | 53 | |
| 54 | - // For invoice discounts. |
|
| 55 | - if ( 'wpi_discount' === $post_type ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | - } |
|
| 54 | + // For invoice discounts. |
|
| 55 | + if ( 'wpi_discount' === $post_type ) { |
|
| 56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Register core metaboxes. |
|
| 63 | - */ |
|
| 64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 61 | + /** |
|
| 62 | + * Register core metaboxes. |
|
| 63 | + */ |
|
| 64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 65 | 65 | |
| 66 | - // For payment forms. |
|
| 67 | - if ( 'wpi_payment_form' === $post_type ) { |
|
| 66 | + // For payment forms. |
|
| 67 | + if ( 'wpi_payment_form' === $post_type ) { |
|
| 68 | 68 | |
| 69 | - // Design payment form. |
|
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 69 | + // Design payment form. |
|
| 70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 71 | 71 | |
| 72 | - // Payment form information. |
|
| 73 | - if ( wpinv_get_default_payment_form() !== $post->ID ) { |
|
| 74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 75 | - } |
|
| 72 | + // Payment form information. |
|
| 73 | + if ( wpinv_get_default_payment_form() !== $post->ID ) { |
|
| 74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 75 | + } |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Register core metaboxes. |
|
| 82 | - */ |
|
| 83 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 78 | + } |
|
| 84 | 79 | |
| 85 | - if ( 'wpi_item' === $post_type ) { |
|
| 86 | - |
|
| 87 | - // Item details. |
|
| 88 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 89 | - |
|
| 90 | - // If taxes are enabled, register the tax metabox. |
|
| 91 | - if ( wpinv_use_taxes() ) { |
|
| 92 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * Register core metaboxes. |
|
| 82 | + */ |
|
| 83 | + protected static function add_item_meta_boxes( $post_type ) { |
|
| 94 | 84 | |
| 95 | - // Item info. |
|
| 96 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 85 | + if ( 'wpi_item' === $post_type ) { |
|
| 97 | 86 | |
| 98 | - // Item description. |
|
| 99 | - add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' ); |
|
| 100 | - } |
|
| 87 | + // Item details. |
|
| 88 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 101 | 89 | |
| 102 | - } |
|
| 90 | + // If taxes are enabled, register the tax metabox. |
|
| 91 | + if ( wpinv_use_taxes() ) { |
|
| 92 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 93 | + } |
|
| 103 | 94 | |
| 104 | - /** |
|
| 105 | - * Register invoice metaboxes. |
|
| 106 | - */ |
|
| 107 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 95 | + // Item info. |
|
| 96 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 108 | 97 | |
| 109 | - // For invoices... |
|
| 110 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 111 | - $invoice = new WPInv_Invoice( $post ); |
|
| 98 | + // Item description. |
|
| 99 | + add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' ); |
|
| 100 | + } |
|
| 112 | 101 | |
| 113 | - // Resend invoice. |
|
| 114 | - if ( ! $invoice->is_draft() ) { |
|
| 102 | + } |
|
| 115 | 103 | |
| 116 | - add_meta_box( |
|
| 117 | - 'wpinv-mb-resend-invoice', |
|
| 118 | - sprintf( |
|
| 119 | - // translators: %s is the invoice type. |
|
| 120 | - __( 'Resend %s', 'invoicing' ), |
|
| 121 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 122 | - ), |
|
| 123 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 124 | - $post_type, |
|
| 125 | - 'side', |
|
| 126 | - 'low' |
|
| 127 | - ); |
|
| 104 | + /** |
|
| 105 | + * Register invoice metaboxes. |
|
| 106 | + */ |
|
| 107 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 108 | + |
|
| 109 | + // For invoices... |
|
| 110 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 111 | + $invoice = new WPInv_Invoice( $post ); |
|
| 112 | + |
|
| 113 | + // Resend invoice. |
|
| 114 | + if ( ! $invoice->is_draft() ) { |
|
| 115 | + |
|
| 116 | + add_meta_box( |
|
| 117 | + 'wpinv-mb-resend-invoice', |
|
| 118 | + sprintf( |
|
| 119 | + // translators: %s is the invoice type. |
|
| 120 | + __( 'Resend %s', 'invoicing' ), |
|
| 121 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 122 | + ), |
|
| 123 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 124 | + $post_type, |
|
| 125 | + 'side', |
|
| 126 | + 'low' |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Subscriptions. |
|
| 132 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 133 | + if ( ! empty( $subscriptions ) ) { |
|
| 134 | + |
|
| 135 | + if ( is_array( $subscriptions ) ) { |
|
| 136 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 137 | + } else { |
|
| 138 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 142 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 143 | + } |
|
| 144 | +} |
|
| 128 | 145 | |
| 129 | - } |
|
| 146 | + // Invoice details. |
|
| 147 | + add_meta_box( |
|
| 148 | + 'wpinv-details', |
|
| 149 | + sprintf( |
|
| 150 | + // translators: %s is the invoice type. |
|
| 151 | + __( '%s Details', 'invoicing' ), |
|
| 152 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 153 | + ), |
|
| 154 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 155 | + $post_type, |
|
| 156 | + 'side' |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + // Payment details. |
|
| 160 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 161 | + |
|
| 162 | + // Billing details. |
|
| 163 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 164 | + |
|
| 165 | + // Invoice items. |
|
| 166 | + add_meta_box( |
|
| 167 | + 'wpinv-items', |
|
| 168 | + sprintf( |
|
| 169 | + // translators: %s is the invoice type. |
|
| 170 | + __( '%s Items', 'invoicing' ), |
|
| 171 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 172 | + ), |
|
| 173 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 174 | + $post_type, |
|
| 175 | + 'normal', |
|
| 176 | + 'high' |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + // Invoice notes. |
|
| 180 | + add_meta_box( |
|
| 181 | + 'wpinv-notes', |
|
| 182 | + sprintf( |
|
| 183 | + // translators: %s is the invoice type. |
|
| 184 | + __( '%s Notes', 'invoicing' ), |
|
| 185 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 186 | + ), |
|
| 187 | + 'WPInv_Meta_Box_Notes::output', |
|
| 188 | + $post_type, |
|
| 189 | + 'side', |
|
| 190 | + 'low' |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + // Shipping Address. |
|
| 194 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 195 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // Payment form information. |
|
| 199 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 200 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 201 | + } |
|
| 202 | +} |
|
| 130 | 203 | |
| 131 | - // Subscriptions. |
|
| 132 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 133 | - if ( ! empty( $subscriptions ) ) { |
|
| 204 | + } |
|
| 134 | 205 | |
| 135 | - if ( is_array( $subscriptions ) ) { |
|
| 136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 137 | - } else { |
|
| 138 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 139 | - } |
|
| 206 | + /** |
|
| 207 | + * Remove some metaboxes. |
|
| 208 | + */ |
|
| 209 | + public static function remove_meta_boxes() { |
|
| 210 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 211 | + remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' ); |
|
| 212 | + } |
|
| 140 | 213 | |
| 141 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 142 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 143 | - } |
|
| 144 | -} |
|
| 214 | + /** |
|
| 215 | + * Rename other metaboxes. |
|
| 216 | + */ |
|
| 217 | + public static function rename_meta_boxes() { |
|
| 145 | 218 | |
| 146 | - // Invoice details. |
|
| 147 | - add_meta_box( |
|
| 148 | - 'wpinv-details', |
|
| 149 | - sprintf( |
|
| 150 | - // translators: %s is the invoice type. |
|
| 151 | - __( '%s Details', 'invoicing' ), |
|
| 152 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 153 | - ), |
|
| 154 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 155 | - $post_type, |
|
| 156 | - 'side' |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - // Payment details. |
|
| 160 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 161 | - |
|
| 162 | - // Billing details. |
|
| 163 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 164 | - |
|
| 165 | - // Invoice items. |
|
| 166 | - add_meta_box( |
|
| 167 | - 'wpinv-items', |
|
| 168 | - sprintf( |
|
| 169 | - // translators: %s is the invoice type. |
|
| 170 | - __( '%s Items', 'invoicing' ), |
|
| 171 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 172 | - ), |
|
| 173 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 174 | - $post_type, |
|
| 175 | - 'normal', |
|
| 176 | - 'high' |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - // Invoice notes. |
|
| 180 | - add_meta_box( |
|
| 181 | - 'wpinv-notes', |
|
| 182 | - sprintf( |
|
| 183 | - // translators: %s is the invoice type. |
|
| 184 | - __( '%s Notes', 'invoicing' ), |
|
| 185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 186 | - ), |
|
| 187 | - 'WPInv_Meta_Box_Notes::output', |
|
| 188 | - $post_type, |
|
| 189 | - 'side', |
|
| 190 | - 'low' |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - // Shipping Address. |
|
| 194 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 195 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // Payment form information. |
|
| 199 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 200 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 201 | - } |
|
| 202 | -} |
|
| 219 | + } |
|
| 203 | 220 | |
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Remove some metaboxes. |
|
| 208 | - */ |
|
| 209 | - public static function remove_meta_boxes() { |
|
| 210 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 211 | - remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' ); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Rename other metaboxes. |
|
| 216 | - */ |
|
| 217 | - public static function rename_meta_boxes() { |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Check if we're saving, then trigger an action based on the post type. |
|
| 223 | - * |
|
| 224 | - * @param int $post_id Post ID. |
|
| 225 | - * @param object $post Post object. |
|
| 226 | - */ |
|
| 227 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 228 | - $post_id = absint( $post_id ); |
|
| 229 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 230 | - |
|
| 231 | - // Do not save for ajax requests. |
|
| 232 | - if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 233 | - return; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // $post_id and $post are required |
|
| 237 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 238 | - return; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Dont' save meta boxes for revisions or autosaves. |
|
| 242 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 243 | - return; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // Check the nonce. |
|
| 247 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 248 | - return; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 252 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Check user has permission to edit. |
|
| 257 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 258 | - return; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 262 | - |
|
| 263 | - // We need this save event to run once to avoid potential endless loops. |
|
| 264 | - self::$saved_meta_boxes = true; |
|
| 265 | - |
|
| 266 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 267 | - |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Ensure this is our post type. |
|
| 271 | - $post_types_map = array( |
|
| 272 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 273 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 274 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 275 | - ); |
|
| 276 | - |
|
| 277 | - // Is this our post type? |
|
| 278 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 279 | - return; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // We need this save event to run once to avoid potential endless loops. |
|
| 283 | - self::$saved_meta_boxes = true; |
|
| 284 | - |
|
| 285 | - // Save the post. |
|
| 286 | - $class = $post_types_map[ $post->post_type ]; |
|
| 287 | - $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
| 288 | - |
|
| 289 | - } |
|
| 221 | + /** |
|
| 222 | + * Check if we're saving, then trigger an action based on the post type. |
|
| 223 | + * |
|
| 224 | + * @param int $post_id Post ID. |
|
| 225 | + * @param object $post Post object. |
|
| 226 | + */ |
|
| 227 | + public static function save_meta_boxes( $post_id, $post ) { |
|
| 228 | + $post_id = absint( $post_id ); |
|
| 229 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 230 | + |
|
| 231 | + // Do not save for ajax requests. |
|
| 232 | + if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // $post_id and $post are required |
|
| 237 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 238 | + return; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Dont' save meta boxes for revisions or autosaves. |
|
| 242 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 243 | + return; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // Check the nonce. |
|
| 247 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 248 | + return; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 252 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Check user has permission to edit. |
|
| 257 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 262 | + |
|
| 263 | + // We need this save event to run once to avoid potential endless loops. |
|
| 264 | + self::$saved_meta_boxes = true; |
|
| 265 | + |
|
| 266 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 267 | + |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Ensure this is our post type. |
|
| 271 | + $post_types_map = array( |
|
| 272 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 273 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 274 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 275 | + ); |
|
| 276 | + |
|
| 277 | + // Is this our post type? |
|
| 278 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 279 | + return; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // We need this save event to run once to avoid potential endless loops. |
|
| 283 | + self::$saved_meta_boxes = true; |
|
| 284 | + |
|
| 285 | + // Save the post. |
|
| 286 | + $class = $post_types_map[ $post->post_type ]; |
|
| 287 | + $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
| 25 | 25 | public static function init() { |
| 26 | 26 | |
| 27 | 27 | // Register metaboxes. |
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 ); |
|
| 28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2); |
|
| 29 | 29 | |
| 30 | 30 | // Remove metaboxes. |
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
| 32 | 32 | |
| 33 | 33 | // Rename metaboxes. |
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
| 35 | 35 | |
| 36 | 36 | // Save metaboxes. |
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Register core metaboxes. |
| 42 | 42 | */ |
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 43 | + public static function add_meta_boxes($post_type, $post) { |
|
| 44 | 44 | |
| 45 | 45 | // For invoices. |
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
| 47 | 47 | |
| 48 | 48 | // For payment forms. |
| 49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 49 | + self::add_payment_form_meta_boxes($post_type, $post); |
|
| 50 | 50 | |
| 51 | 51 | // For invoice items. |
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 52 | + self::add_item_meta_boxes($post_type); |
|
| 53 | 53 | |
| 54 | 54 | // For invoice discounts. |
| 55 | - if ( 'wpi_discount' === $post_type ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 55 | + if ('wpi_discount' === $post_type) { |
|
| 56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * Register core metaboxes. |
| 63 | 63 | */ |
| 64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 64 | + protected static function add_payment_form_meta_boxes($post_type, $post) { |
|
| 65 | 65 | |
| 66 | 66 | // For payment forms. |
| 67 | - if ( 'wpi_payment_form' === $post_type ) { |
|
| 67 | + if ('wpi_payment_form' === $post_type) { |
|
| 68 | 68 | |
| 69 | 69 | // Design payment form. |
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
| 71 | 71 | |
| 72 | 72 | // Payment form information. |
| 73 | - if ( wpinv_get_default_payment_form() !== $post->ID ) { |
|
| 74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 73 | + if (wpinv_get_default_payment_form() !== $post->ID) { |
|
| 74 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
@@ -80,23 +80,23 @@ discard block |
||
| 80 | 80 | /** |
| 81 | 81 | * Register core metaboxes. |
| 82 | 82 | */ |
| 83 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 83 | + protected static function add_item_meta_boxes($post_type) { |
|
| 84 | 84 | |
| 85 | - if ( 'wpi_item' === $post_type ) { |
|
| 85 | + if ('wpi_item' === $post_type) { |
|
| 86 | 86 | |
| 87 | 87 | // Item details. |
| 88 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 88 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
| 89 | 89 | |
| 90 | 90 | // If taxes are enabled, register the tax metabox. |
| 91 | - if ( wpinv_use_taxes() ) { |
|
| 92 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 91 | + if (wpinv_use_taxes()) { |
|
| 92 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Item info. |
| 96 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 96 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
| 97 | 97 | |
| 98 | 98 | // Item description. |
| 99 | - add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' ); |
|
| 99 | + add_meta_box('postexcerpt', __('Item Description', 'invoicing'), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | } |
@@ -104,21 +104,21 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * Register invoice metaboxes. |
| 106 | 106 | */ |
| 107 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 107 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
| 108 | 108 | |
| 109 | 109 | // For invoices... |
| 110 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 111 | - $invoice = new WPInv_Invoice( $post ); |
|
| 110 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
| 111 | + $invoice = new WPInv_Invoice($post); |
|
| 112 | 112 | |
| 113 | 113 | // Resend invoice. |
| 114 | - if ( ! $invoice->is_draft() ) { |
|
| 114 | + if (!$invoice->is_draft()) { |
|
| 115 | 115 | |
| 116 | 116 | add_meta_box( |
| 117 | 117 | 'wpinv-mb-resend-invoice', |
| 118 | 118 | sprintf( |
| 119 | 119 | // translators: %s is the invoice type. |
| 120 | - __( 'Resend %s', 'invoicing' ), |
|
| 121 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 120 | + __('Resend %s', 'invoicing'), |
|
| 121 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 122 | 122 | ), |
| 123 | 123 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
| 124 | 124 | $post_type, |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Subscriptions. |
| 132 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 133 | - if ( ! empty( $subscriptions ) ) { |
|
| 132 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 133 | + if (!empty($subscriptions)) { |
|
| 134 | 134 | |
| 135 | - if ( is_array( $subscriptions ) ) { |
|
| 136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 135 | + if (is_array($subscriptions)) { |
|
| 136 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
| 137 | 137 | } else { |
| 138 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 138 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 142 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 141 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
| 142 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | 'wpinv-details', |
| 149 | 149 | sprintf( |
| 150 | 150 | // translators: %s is the invoice type. |
| 151 | - __( '%s Details', 'invoicing' ), |
|
| 152 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 151 | + __('%s Details', 'invoicing'), |
|
| 152 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 153 | 153 | ), |
| 154 | 154 | 'GetPaid_Meta_Box_Invoice_Details::output', |
| 155 | 155 | $post_type, |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | ); |
| 158 | 158 | |
| 159 | 159 | // Payment details. |
| 160 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 160 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
| 161 | 161 | |
| 162 | 162 | // Billing details. |
| 163 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 163 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
| 164 | 164 | |
| 165 | 165 | // Invoice items. |
| 166 | 166 | add_meta_box( |
| 167 | 167 | 'wpinv-items', |
| 168 | 168 | sprintf( |
| 169 | 169 | // translators: %s is the invoice type. |
| 170 | - __( '%s Items', 'invoicing' ), |
|
| 171 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 170 | + __('%s Items', 'invoicing'), |
|
| 171 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 172 | 172 | ), |
| 173 | 173 | 'GetPaid_Meta_Box_Invoice_Items::output', |
| 174 | 174 | $post_type, |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | 'wpinv-notes', |
| 182 | 182 | sprintf( |
| 183 | 183 | // translators: %s is the invoice type. |
| 184 | - __( '%s Notes', 'invoicing' ), |
|
| 185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 184 | + __('%s Notes', 'invoicing'), |
|
| 185 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 186 | 186 | ), |
| 187 | 187 | 'WPInv_Meta_Box_Notes::output', |
| 188 | 188 | $post_type, |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | 193 | // Shipping Address. |
| 194 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 195 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 194 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
| 195 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Payment form information. |
| 199 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 200 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 199 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
| 200 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | * Remove some metaboxes. |
| 208 | 208 | */ |
| 209 | 209 | public static function remove_meta_boxes() { |
| 210 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 211 | - remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' ); |
|
| 210 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
| 211 | + remove_meta_box('postexcerpt', 'wpi_item', 'normal'); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -224,46 +224,46 @@ discard block |
||
| 224 | 224 | * @param int $post_id Post ID. |
| 225 | 225 | * @param object $post Post object. |
| 226 | 226 | */ |
| 227 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 228 | - $post_id = absint( $post_id ); |
|
| 229 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 227 | + public static function save_meta_boxes($post_id, $post) { |
|
| 228 | + $post_id = absint($post_id); |
|
| 229 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 230 | 230 | |
| 231 | 231 | // Do not save for ajax requests. |
| 232 | - if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 232 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
| 233 | 233 | return; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // $post_id and $post are required |
| 237 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 237 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
| 238 | 238 | return; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Dont' save meta boxes for revisions or autosaves. |
| 242 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 242 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
| 243 | 243 | return; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Check the nonce. |
| 247 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 247 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
| 252 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 252 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Check user has permission to edit. |
| 257 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 257 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 258 | 258 | return; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 261 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
| 262 | 262 | |
| 263 | 263 | // We need this save event to run once to avoid potential endless loops. |
| 264 | 264 | self::$saved_meta_boxes = true; |
| 265 | 265 | |
| 266 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 266 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | ); |
| 276 | 276 | |
| 277 | 277 | // Is this our post type? |
| 278 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 278 | + if (!isset($post_types_map[$post->post_type])) { |
|
| 279 | 279 | return; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | self::$saved_meta_boxes = true; |
| 284 | 284 | |
| 285 | 285 | // Save the post. |
| 286 | - $class = $post_types_map[ $post->post_type ]; |
|
| 287 | - $class::save( $post_id, wp_kses_post_deep( $_POST ), $post ); |
|
| 286 | + $class = $post_types_map[$post->post_type]; |
|
| 287 | + $class::save($post_id, wp_kses_post_deep($_POST), $post); |
|
| 288 | 288 | |
| 289 | 289 | } |
| 290 | 290 | |