@@ -13,731 +13,731 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | - |
|
| 30 | - // Invoice table columns. |
|
| 31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | - |
|
| 36 | - // Items table columns. |
|
| 37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | - |
|
| 44 | - // Payment forms columns. |
|
| 45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | - |
|
| 49 | - // Discount table columns. |
|
| 50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | - |
|
| 53 | - // Deleting posts. |
|
| 54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | - |
|
| 57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Post updated messages. |
|
| 62 | - */ |
|
| 63 | - public static function post_updated_messages( $messages ) { |
|
| 64 | - global $post; |
|
| 65 | - |
|
| 66 | - $messages['wpi_discount'] = array( |
|
| 67 | - 0 => '', |
|
| 68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $messages['wpi_payment_form'] = array( |
|
| 81 | - 0 => '', |
|
| 82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - return $messages; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Post row actions. |
|
| 100 | - */ |
|
| 101 | - public static function post_row_actions( $actions, $post ) { |
|
| 102 | - |
|
| 103 | - $post = get_post( $post ); |
|
| 104 | - |
|
| 105 | - // We do not want to edit the default payment form. |
|
| 106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | - |
|
| 108 | - if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
| 109 | - unset( $actions['trash'] ); |
|
| 110 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $actions['duplicate'] = sprintf( |
|
| 114 | - '<a href="%1$s">%2$s</a>', |
|
| 115 | - esc_url( |
|
| 116 | - wp_nonce_url( |
|
| 117 | - add_query_arg( |
|
| 118 | - array( |
|
| 119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | - 'form_id' => $post->ID |
|
| 121 | - ) |
|
| 122 | - ), |
|
| 123 | - 'getpaid-nonce', |
|
| 124 | - 'getpaid-nonce' |
|
| 125 | - ) |
|
| 126 | - ), |
|
| 127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Link to item payment form. |
|
| 133 | - if ( 'wpi_item' == $post->post_type && get_post_meta( $post->ID, '_wpinv_type', true ) == 'custom' ) { |
|
| 134 | - |
|
| 135 | - $actions['buy'] = sprintf( |
|
| 136 | - '<a href="%1$s">%2$s</a>', |
|
| 137 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 138 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 139 | - ); |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $actions; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 19 | + |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 22 | + |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | + |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | + |
|
| 30 | + // Invoice table columns. |
|
| 31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | + |
|
| 36 | + // Items table columns. |
|
| 37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | + |
|
| 44 | + // Payment forms columns. |
|
| 45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | + |
|
| 49 | + // Discount table columns. |
|
| 50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | + |
|
| 53 | + // Deleting posts. |
|
| 54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | + |
|
| 57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Post updated messages. |
|
| 62 | + */ |
|
| 63 | + public static function post_updated_messages( $messages ) { |
|
| 64 | + global $post; |
|
| 65 | + |
|
| 66 | + $messages['wpi_discount'] = array( |
|
| 67 | + 0 => '', |
|
| 68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $messages['wpi_payment_form'] = array( |
|
| 81 | + 0 => '', |
|
| 82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + return $messages; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Post row actions. |
|
| 100 | + */ |
|
| 101 | + public static function post_row_actions( $actions, $post ) { |
|
| 102 | + |
|
| 103 | + $post = get_post( $post ); |
|
| 104 | + |
|
| 105 | + // We do not want to edit the default payment form. |
|
| 106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | + |
|
| 108 | + if ( $post->ID == wpinv_get_default_payment_form() ) { |
|
| 109 | + unset( $actions['trash'] ); |
|
| 110 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $actions['duplicate'] = sprintf( |
|
| 114 | + '<a href="%1$s">%2$s</a>', |
|
| 115 | + esc_url( |
|
| 116 | + wp_nonce_url( |
|
| 117 | + add_query_arg( |
|
| 118 | + array( |
|
| 119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | + 'form_id' => $post->ID |
|
| 121 | + ) |
|
| 122 | + ), |
|
| 123 | + 'getpaid-nonce', |
|
| 124 | + 'getpaid-nonce' |
|
| 125 | + ) |
|
| 126 | + ), |
|
| 127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Link to item payment form. |
|
| 133 | + if ( 'wpi_item' == $post->post_type && get_post_meta( $post->ID, '_wpinv_type', true ) == 'custom' ) { |
|
| 134 | + |
|
| 135 | + $actions['buy'] = sprintf( |
|
| 136 | + '<a href="%1$s">%2$s</a>', |
|
| 137 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 138 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 139 | + ); |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $actions; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | 147 | * Remove bulk edit option from admin side quote listing |
| 148 | 148 | * |
| 149 | 149 | * @since 1.0.0 |
| 150 | 150 | * @param array $actions post actions |
| 151 | - * @param WP_Post $post |
|
| 151 | + * @param WP_Post $post |
|
| 152 | 152 | * @return array $actions actions without edit option |
| 153 | 153 | */ |
| 154 | 154 | public static function filter_invoice_row_actions( $actions, $post ) { |
| 155 | 155 | |
| 156 | 156 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
| 157 | 157 | |
| 158 | - $actions = array(); |
|
| 159 | - $invoice = new WPInv_Invoice( $post ); |
|
| 160 | - |
|
| 161 | - $actions['edit'] = sprintf( |
|
| 162 | - '<a href="%1$s">%2$s</a>', |
|
| 163 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 164 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 165 | - ); |
|
| 166 | - |
|
| 167 | - if ( ! $invoice->is_draft() ) { |
|
| 168 | - |
|
| 169 | - $actions['view'] = sprintf( |
|
| 170 | - '<a href="%1$s">%2$s</a>', |
|
| 171 | - esc_url( $invoice->get_view_url() ), |
|
| 172 | - sprintf( |
|
| 173 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
| 174 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 175 | - ) |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - $actions['send'] = sprintf( |
|
| 179 | - '<a href="%1$s">%2$s</a>', |
|
| 180 | - esc_url( |
|
| 181 | - wp_nonce_url( |
|
| 182 | - add_query_arg( |
|
| 183 | - array( |
|
| 184 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 185 | - 'invoice_id' => $invoice->get_id() |
|
| 186 | - ) |
|
| 187 | - ), |
|
| 188 | - 'getpaid-nonce', |
|
| 189 | - 'getpaid-nonce' |
|
| 190 | - ) |
|
| 191 | - ), |
|
| 192 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $actions['duplicate'] = sprintf( |
|
| 198 | - '<a href="%1$s">%2$s</a>', |
|
| 199 | - esc_url( |
|
| 200 | - wp_nonce_url( |
|
| 201 | - add_query_arg( |
|
| 202 | - array( |
|
| 203 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 204 | - 'invoice_id' => $post->ID |
|
| 205 | - ) |
|
| 206 | - ), |
|
| 207 | - 'getpaid-nonce', |
|
| 208 | - 'getpaid-nonce' |
|
| 209 | - ) |
|
| 210 | - ), |
|
| 211 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 212 | - ); |
|
| 158 | + $actions = array(); |
|
| 159 | + $invoice = new WPInv_Invoice( $post ); |
|
| 160 | + |
|
| 161 | + $actions['edit'] = sprintf( |
|
| 162 | + '<a href="%1$s">%2$s</a>', |
|
| 163 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 164 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 165 | + ); |
|
| 166 | + |
|
| 167 | + if ( ! $invoice->is_draft() ) { |
|
| 168 | + |
|
| 169 | + $actions['view'] = sprintf( |
|
| 170 | + '<a href="%1$s">%2$s</a>', |
|
| 171 | + esc_url( $invoice->get_view_url() ), |
|
| 172 | + sprintf( |
|
| 173 | + esc_html( __( 'View %s', 'invoicing' ) ), |
|
| 174 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 175 | + ) |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + $actions['send'] = sprintf( |
|
| 179 | + '<a href="%1$s">%2$s</a>', |
|
| 180 | + esc_url( |
|
| 181 | + wp_nonce_url( |
|
| 182 | + add_query_arg( |
|
| 183 | + array( |
|
| 184 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 185 | + 'invoice_id' => $invoice->get_id() |
|
| 186 | + ) |
|
| 187 | + ), |
|
| 188 | + 'getpaid-nonce', |
|
| 189 | + 'getpaid-nonce' |
|
| 190 | + ) |
|
| 191 | + ), |
|
| 192 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $actions['duplicate'] = sprintf( |
|
| 198 | + '<a href="%1$s">%2$s</a>', |
|
| 199 | + esc_url( |
|
| 200 | + wp_nonce_url( |
|
| 201 | + add_query_arg( |
|
| 202 | + array( |
|
| 203 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 204 | + 'invoice_id' => $post->ID |
|
| 205 | + ) |
|
| 206 | + ), |
|
| 207 | + 'getpaid-nonce', |
|
| 208 | + 'getpaid-nonce' |
|
| 209 | + ) |
|
| 210 | + ), |
|
| 211 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 212 | + ); |
|
| 213 | 213 | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | return $actions; |
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Returns an array of invoice table columns. |
|
| 221 | - */ |
|
| 222 | - public static function invoice_columns( $columns ) { |
|
| 223 | - |
|
| 224 | - $columns = array( |
|
| 225 | - 'cb' => $columns['cb'], |
|
| 226 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 227 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 228 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 229 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 230 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 231 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 232 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Displays invoice table columns. |
|
| 240 | - */ |
|
| 241 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 242 | - |
|
| 243 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 244 | - |
|
| 245 | - switch ( $column_name ) { |
|
| 246 | - |
|
| 247 | - case 'invoice_date' : |
|
| 248 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 249 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 250 | - echo "<span title='$date_time'>$date</span>"; |
|
| 251 | - break; |
|
| 252 | - |
|
| 253 | - case 'payment_date' : |
|
| 254 | - |
|
| 255 | - if ( $invoice->is_paid() ) { |
|
| 256 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 257 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 258 | - echo "<span title='$date_time'>$date</span>"; |
|
| 259 | - } else { |
|
| 260 | - echo "—"; |
|
| 261 | - } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Returns an array of invoice table columns. |
|
| 221 | + */ |
|
| 222 | + public static function invoice_columns( $columns ) { |
|
| 223 | + |
|
| 224 | + $columns = array( |
|
| 225 | + 'cb' => $columns['cb'], |
|
| 226 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 227 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 228 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 229 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 230 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 231 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 232 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Displays invoice table columns. |
|
| 240 | + */ |
|
| 241 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 242 | + |
|
| 243 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 244 | + |
|
| 245 | + switch ( $column_name ) { |
|
| 246 | + |
|
| 247 | + case 'invoice_date' : |
|
| 248 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 249 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 250 | + echo "<span title='$date_time'>$date</span>"; |
|
| 251 | + break; |
|
| 252 | + |
|
| 253 | + case 'payment_date' : |
|
| 254 | + |
|
| 255 | + if ( $invoice->is_paid() ) { |
|
| 256 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 257 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
| 258 | + echo "<span title='$date_time'>$date</span>"; |
|
| 259 | + } else { |
|
| 260 | + echo "—"; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - break; |
|
| 263 | + break; |
|
| 264 | 264 | |
| 265 | - case 'amount' : |
|
| 265 | + case 'amount' : |
|
| 266 | 266 | |
| 267 | - $amount = $invoice->get_total(); |
|
| 268 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
| 267 | + $amount = $invoice->get_total(); |
|
| 268 | + $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
| 269 | 269 | |
| 270 | - if ( $invoice->is_refunded() ) { |
|
| 271 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 272 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 273 | - } else { |
|
| 270 | + if ( $invoice->is_refunded() ) { |
|
| 271 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 272 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 273 | + } else { |
|
| 274 | 274 | |
| 275 | - $discount = $invoice->get_total_discount(); |
|
| 275 | + $discount = $invoice->get_total_discount(); |
|
| 276 | 276 | |
| 277 | - if ( ! empty( $discount ) ) { |
|
| 278 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 279 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 280 | - } else { |
|
| 281 | - echo $formated_amount; |
|
| 282 | - } |
|
| 277 | + if ( ! empty( $discount ) ) { |
|
| 278 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 279 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 280 | + } else { |
|
| 281 | + echo $formated_amount; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - break; |
|
| 286 | + break; |
|
| 287 | 287 | |
| 288 | - case 'status' : |
|
| 289 | - $status = esc_html( $invoice->get_status() ); |
|
| 290 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 288 | + case 'status' : |
|
| 289 | + $status = esc_html( $invoice->get_status() ); |
|
| 290 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 291 | 291 | |
| 292 | - // If it is paid, show the gateway title. |
|
| 293 | - if ( $invoice->is_paid() ) { |
|
| 294 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 295 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 292 | + // If it is paid, show the gateway title. |
|
| 293 | + if ( $invoice->is_paid() ) { |
|
| 294 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 295 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 296 | 296 | |
| 297 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 298 | - } else { |
|
| 299 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 300 | - } |
|
| 297 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 298 | + } else { |
|
| 299 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - // If it is not paid, display the overdue and view status. |
|
| 303 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 302 | + // If it is not paid, display the overdue and view status. |
|
| 303 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 304 | 304 | |
| 305 | - // Invoice view status. |
|
| 306 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 307 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 308 | - } else { |
|
| 309 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 310 | - } |
|
| 305 | + // Invoice view status. |
|
| 306 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 307 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 308 | + } else { |
|
| 309 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - // Display the overview status. |
|
| 313 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 314 | - $due_date = $invoice->get_due_date(); |
|
| 315 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 312 | + // Display the overview status. |
|
| 313 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 314 | + $due_date = $invoice->get_due_date(); |
|
| 315 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 316 | 316 | |
| 317 | - if ( ! empty( $fomatted ) ) { |
|
| 318 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 319 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 320 | - } |
|
| 321 | - } |
|
| 317 | + if ( ! empty( $fomatted ) ) { |
|
| 318 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 319 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - } |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - break; |
|
| 325 | + break; |
|
| 326 | 326 | |
| 327 | - case 'recurring': |
|
| 327 | + case 'recurring': |
|
| 328 | 328 | |
| 329 | - if ( $invoice->is_recurring() ) { |
|
| 330 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 331 | - } else { |
|
| 332 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 333 | - } |
|
| 334 | - break; |
|
| 329 | + if ( $invoice->is_recurring() ) { |
|
| 330 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 331 | + } else { |
|
| 332 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 333 | + } |
|
| 334 | + break; |
|
| 335 | 335 | |
| 336 | - case 'number' : |
|
| 336 | + case 'number' : |
|
| 337 | 337 | |
| 338 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 339 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
| 340 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 338 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 339 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
| 340 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 341 | 341 | |
| 342 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 342 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 343 | 343 | |
| 344 | - break; |
|
| 344 | + break; |
|
| 345 | 345 | |
| 346 | - case 'customer' : |
|
| 346 | + case 'customer' : |
|
| 347 | 347 | |
| 348 | - $customer_name = $invoice->get_user_full_name(); |
|
| 348 | + $customer_name = $invoice->get_user_full_name(); |
|
| 349 | 349 | |
| 350 | - if ( empty( $customer_name ) ) { |
|
| 351 | - $customer_name = $invoice->get_email(); |
|
| 352 | - } |
|
| 350 | + if ( empty( $customer_name ) ) { |
|
| 351 | + $customer_name = $invoice->get_email(); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - if ( ! empty( $customer_name ) ) { |
|
| 355 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 356 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 357 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 358 | - } else { |
|
| 359 | - echo '<div>—</div>'; |
|
| 360 | - } |
|
| 354 | + if ( ! empty( $customer_name ) ) { |
|
| 355 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 356 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 357 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 358 | + } else { |
|
| 359 | + echo '<div>—</div>'; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - break; |
|
| 362 | + break; |
|
| 363 | 363 | |
| 364 | - } |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - /** |
|
| 369 | - * Displays invoice bulk actions. |
|
| 370 | - */ |
|
| 371 | - public static function invoice_bulk_actions( $actions ) { |
|
| 372 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 373 | - return $actions; |
|
| 374 | - } |
|
| 368 | + /** |
|
| 369 | + * Displays invoice bulk actions. |
|
| 370 | + */ |
|
| 371 | + public static function invoice_bulk_actions( $actions ) { |
|
| 372 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 373 | + return $actions; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - /** |
|
| 377 | - * Processes invoice bulk actions. |
|
| 378 | - */ |
|
| 379 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 376 | + /** |
|
| 377 | + * Processes invoice bulk actions. |
|
| 378 | + */ |
|
| 379 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 380 | 380 | |
| 381 | - if ( $action == 'resend-invoice' ) { |
|
| 381 | + if ( $action == 'resend-invoice' ) { |
|
| 382 | 382 | |
| 383 | - $success = false; |
|
| 384 | - foreach ( $post_ids as $post_id ) { |
|
| 385 | - $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 386 | - } |
|
| 383 | + $success = false; |
|
| 384 | + foreach ( $post_ids as $post_id ) { |
|
| 385 | + $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - if ( $success ) { |
|
| 389 | - getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
| 390 | - } else { |
|
| 391 | - getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
| 392 | - } |
|
| 388 | + if ( $success ) { |
|
| 389 | + getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) ); |
|
| 390 | + } else { |
|
| 391 | + getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) ); |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - } |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - return $redirect_url; |
|
| 396 | + return $redirect_url; |
|
| 397 | 397 | |
| 398 | - } |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * Returns an array of payment forms table columns. |
|
| 402 | - */ |
|
| 403 | - public static function payment_form_columns( $columns ) { |
|
| 400 | + /** |
|
| 401 | + * Returns an array of payment forms table columns. |
|
| 402 | + */ |
|
| 403 | + public static function payment_form_columns( $columns ) { |
|
| 404 | 404 | |
| 405 | - $columns = array( |
|
| 406 | - 'cb' => $columns['cb'], |
|
| 407 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 408 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 409 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 410 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 411 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 412 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 413 | - ); |
|
| 405 | + $columns = array( |
|
| 406 | + 'cb' => $columns['cb'], |
|
| 407 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 408 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 409 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 410 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 411 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 412 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 413 | + ); |
|
| 414 | 414 | |
| 415 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 415 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 416 | 416 | |
| 417 | - } |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | - /** |
|
| 420 | - * Displays payment form table columns. |
|
| 421 | - */ |
|
| 422 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 419 | + /** |
|
| 420 | + * Displays payment form table columns. |
|
| 421 | + */ |
|
| 422 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 423 | 423 | |
| 424 | - // Retrieve the payment form. |
|
| 425 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 424 | + // Retrieve the payment form. |
|
| 425 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 426 | 426 | |
| 427 | - switch ( $column_name ) { |
|
| 427 | + switch ( $column_name ) { |
|
| 428 | 428 | |
| 429 | - case 'earnings' : |
|
| 430 | - echo wpinv_price( $form->get_earned() ); |
|
| 431 | - break; |
|
| 429 | + case 'earnings' : |
|
| 430 | + echo wpinv_price( $form->get_earned() ); |
|
| 431 | + break; |
|
| 432 | 432 | |
| 433 | - case 'refunds' : |
|
| 434 | - echo wpinv_price( $form->get_refunded() ); |
|
| 435 | - break; |
|
| 433 | + case 'refunds' : |
|
| 434 | + echo wpinv_price( $form->get_refunded() ); |
|
| 435 | + break; |
|
| 436 | 436 | |
| 437 | - case 'refunds' : |
|
| 438 | - echo wpinv_price( $form->get_refunded() ); |
|
| 439 | - break; |
|
| 437 | + case 'refunds' : |
|
| 438 | + echo wpinv_price( $form->get_refunded() ); |
|
| 439 | + break; |
|
| 440 | 440 | |
| 441 | - case 'shortcode' : |
|
| 441 | + case 'shortcode' : |
|
| 442 | 442 | |
| 443 | - if ( $form->is_default() ) { |
|
| 444 | - echo '—'; |
|
| 445 | - } else { |
|
| 446 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 447 | - } |
|
| 443 | + if ( $form->is_default() ) { |
|
| 444 | + echo '—'; |
|
| 445 | + } else { |
|
| 446 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - break; |
|
| 449 | + break; |
|
| 450 | 450 | |
| 451 | - case 'items' : |
|
| 451 | + case 'items' : |
|
| 452 | 452 | |
| 453 | - $items = $form->get_items(); |
|
| 453 | + $items = $form->get_items(); |
|
| 454 | 454 | |
| 455 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 456 | - echo '—'; |
|
| 457 | - return; |
|
| 458 | - } |
|
| 455 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 456 | + echo '—'; |
|
| 457 | + return; |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - $_items = array(); |
|
| 460 | + $_items = array(); |
|
| 461 | 461 | |
| 462 | - foreach ( $items as $item ) { |
|
| 463 | - $url = $item->get_edit_url(); |
|
| 462 | + foreach ( $items as $item ) { |
|
| 463 | + $url = $item->get_edit_url(); |
|
| 464 | 464 | |
| 465 | - if ( empty( $url ) ) { |
|
| 466 | - $_items[] = esc_html( $item->get_name() ); |
|
| 467 | - } else { |
|
| 468 | - $_items[] = sprintf( |
|
| 469 | - '<a href="%s">%s</a>', |
|
| 470 | - esc_url( $url ), |
|
| 471 | - esc_html( $item->get_name() ) |
|
| 472 | - ); |
|
| 473 | - } |
|
| 465 | + if ( empty( $url ) ) { |
|
| 466 | + $_items[] = esc_html( $item->get_name() ); |
|
| 467 | + } else { |
|
| 468 | + $_items[] = sprintf( |
|
| 469 | + '<a href="%s">%s</a>', |
|
| 470 | + esc_url( $url ), |
|
| 471 | + esc_html( $item->get_name() ) |
|
| 472 | + ); |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - } |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - echo implode( '<br>', $_items ); |
|
| 477 | + echo implode( '<br>', $_items ); |
|
| 478 | 478 | |
| 479 | - break; |
|
| 479 | + break; |
|
| 480 | 480 | |
| 481 | - } |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - /** |
|
| 486 | - * Filters post states. |
|
| 487 | - */ |
|
| 488 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 485 | + /** |
|
| 486 | + * Filters post states. |
|
| 487 | + */ |
|
| 488 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 489 | 489 | |
| 490 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 491 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 492 | - } |
|
| 490 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 491 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - return $post_states; |
|
| 495 | - |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Returns an array of coupon table columns. |
|
| 500 | - */ |
|
| 501 | - public static function discount_columns( $columns ) { |
|
| 502 | - |
|
| 503 | - $columns = array( |
|
| 504 | - 'cb' => $columns['cb'], |
|
| 505 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 506 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 507 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 508 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 509 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 510 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 511 | - ); |
|
| 512 | - |
|
| 513 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Filters post states. |
|
| 518 | - */ |
|
| 519 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 520 | - |
|
| 521 | - if ( 'wpi_discount' == $post->post_type ) { |
|
| 522 | - |
|
| 523 | - $discount = new WPInv_Discount( $post ); |
|
| 524 | - |
|
| 525 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 526 | - |
|
| 527 | - if ( $status != 'publish' ) { |
|
| 528 | - return array( |
|
| 529 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 530 | - ); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return array(); |
|
| 534 | - |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return $post_states; |
|
| 538 | - |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Returns an array of items table columns. |
|
| 543 | - */ |
|
| 544 | - public static function item_columns( $columns ) { |
|
| 545 | - |
|
| 546 | - $columns = array( |
|
| 547 | - 'cb' => $columns['cb'], |
|
| 548 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 549 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 550 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 551 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 552 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 553 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 554 | - ); |
|
| 555 | - |
|
| 556 | - if ( ! wpinv_use_taxes() ) { |
|
| 557 | - unset( $columns['vat_rule'] ); |
|
| 558 | - unset( $columns['vat_class'] ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Returns an array of sortable items table columns. |
|
| 566 | - */ |
|
| 567 | - public static function sortable_item_columns( $columns ) { |
|
| 568 | - |
|
| 569 | - return array_merge( |
|
| 570 | - $columns, |
|
| 571 | - array( |
|
| 572 | - 'price' => 'price', |
|
| 573 | - 'vat_rule' => 'vat_rule', |
|
| 574 | - 'vat_class' => 'vat_class', |
|
| 575 | - 'type' => 'type', |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Displays items table columns. |
|
| 583 | - */ |
|
| 584 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 494 | + return $post_states; |
|
| 495 | + |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Returns an array of coupon table columns. |
|
| 500 | + */ |
|
| 501 | + public static function discount_columns( $columns ) { |
|
| 502 | + |
|
| 503 | + $columns = array( |
|
| 504 | + 'cb' => $columns['cb'], |
|
| 505 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 506 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 507 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 508 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 509 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 510 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 511 | + ); |
|
| 512 | + |
|
| 513 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Filters post states. |
|
| 518 | + */ |
|
| 519 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 520 | + |
|
| 521 | + if ( 'wpi_discount' == $post->post_type ) { |
|
| 522 | + |
|
| 523 | + $discount = new WPInv_Discount( $post ); |
|
| 524 | + |
|
| 525 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 526 | + |
|
| 527 | + if ( $status != 'publish' ) { |
|
| 528 | + return array( |
|
| 529 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 530 | + ); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return array(); |
|
| 534 | + |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return $post_states; |
|
| 538 | + |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Returns an array of items table columns. |
|
| 543 | + */ |
|
| 544 | + public static function item_columns( $columns ) { |
|
| 545 | + |
|
| 546 | + $columns = array( |
|
| 547 | + 'cb' => $columns['cb'], |
|
| 548 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 549 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 550 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 551 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 552 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 553 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 554 | + ); |
|
| 555 | + |
|
| 556 | + if ( ! wpinv_use_taxes() ) { |
|
| 557 | + unset( $columns['vat_rule'] ); |
|
| 558 | + unset( $columns['vat_class'] ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Returns an array of sortable items table columns. |
|
| 566 | + */ |
|
| 567 | + public static function sortable_item_columns( $columns ) { |
|
| 568 | + |
|
| 569 | + return array_merge( |
|
| 570 | + $columns, |
|
| 571 | + array( |
|
| 572 | + 'price' => 'price', |
|
| 573 | + 'vat_rule' => 'vat_rule', |
|
| 574 | + 'vat_class' => 'vat_class', |
|
| 575 | + 'type' => 'type', |
|
| 576 | + ) |
|
| 577 | + ); |
|
| 578 | + |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Displays items table columns. |
|
| 583 | + */ |
|
| 584 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 585 | 585 | |
| 586 | - $item = new WPInv_Item( $post_id ); |
|
| 586 | + $item = new WPInv_Item( $post_id ); |
|
| 587 | 587 | |
| 588 | - switch ( $column_name ) { |
|
| 588 | + switch ( $column_name ) { |
|
| 589 | 589 | |
| 590 | - case 'price' : |
|
| 590 | + case 'price' : |
|
| 591 | 591 | |
| 592 | - if ( ! $item->is_recurring() ) { |
|
| 593 | - echo $item->get_the_price(); |
|
| 594 | - break; |
|
| 595 | - } |
|
| 592 | + if ( ! $item->is_recurring() ) { |
|
| 593 | + echo $item->get_the_price(); |
|
| 594 | + break; |
|
| 595 | + } |
|
| 596 | 596 | |
| 597 | - $price = wp_sprintf( |
|
| 598 | - __( '%s / %s', 'invoicing' ), |
|
| 599 | - $item->get_the_price(), |
|
| 600 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 601 | - ); |
|
| 597 | + $price = wp_sprintf( |
|
| 598 | + __( '%s / %s', 'invoicing' ), |
|
| 599 | + $item->get_the_price(), |
|
| 600 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 601 | + ); |
|
| 602 | 602 | |
| 603 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 604 | - echo $price; |
|
| 605 | - break; |
|
| 606 | - } |
|
| 603 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 604 | + echo $price; |
|
| 605 | + break; |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | - echo $item->get_the_initial_price(); |
|
| 608 | + echo $item->get_the_initial_price(); |
|
| 609 | 609 | |
| 610 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 611 | - break; |
|
| 610 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 611 | + break; |
|
| 612 | 612 | |
| 613 | - case 'vat_rule' : |
|
| 614 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
| 615 | - break; |
|
| 613 | + case 'vat_rule' : |
|
| 614 | + echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
| 615 | + break; |
|
| 616 | 616 | |
| 617 | - case 'vat_class' : |
|
| 618 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
| 619 | - break; |
|
| 617 | + case 'vat_class' : |
|
| 618 | + echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
| 619 | + break; |
|
| 620 | 620 | |
| 621 | - case 'shortcode' : |
|
| 622 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 623 | - break; |
|
| 621 | + case 'shortcode' : |
|
| 622 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 623 | + break; |
|
| 624 | 624 | |
| 625 | - case 'type' : |
|
| 626 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 627 | - break; |
|
| 625 | + case 'type' : |
|
| 626 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 627 | + break; |
|
| 628 | 628 | |
| 629 | - } |
|
| 629 | + } |
|
| 630 | 630 | |
| 631 | - } |
|
| 631 | + } |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Lets users filter items using taxes. |
|
| 635 | - */ |
|
| 636 | - public static function add_item_filters( $post_type ) { |
|
| 633 | + /** |
|
| 634 | + * Lets users filter items using taxes. |
|
| 635 | + */ |
|
| 636 | + public static function add_item_filters( $post_type ) { |
|
| 637 | 637 | |
| 638 | - // Abort if we're not dealing with items. |
|
| 639 | - if ( $post_type != 'wpi_item' ) { |
|
| 640 | - return; |
|
| 641 | - } |
|
| 638 | + // Abort if we're not dealing with items. |
|
| 639 | + if ( $post_type != 'wpi_item' ) { |
|
| 640 | + return; |
|
| 641 | + } |
|
| 642 | 642 | |
| 643 | - // Filter by vat rules. |
|
| 644 | - if ( wpinv_use_taxes() ) { |
|
| 643 | + // Filter by vat rules. |
|
| 644 | + if ( wpinv_use_taxes() ) { |
|
| 645 | 645 | |
| 646 | - // Sanitize selected vat rule. |
|
| 647 | - $vat_rule = ''; |
|
| 648 | - $vat_rules = getpaid_get_tax_rules(); |
|
| 649 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
| 650 | - $vat_rule = $_GET['vat_rule']; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - // Filter by VAT rule. |
|
| 654 | - echo wpinv_html_select( |
|
| 655 | - array( |
|
| 656 | - 'options' => array_merge( |
|
| 657 | - array( |
|
| 658 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
| 659 | - ), |
|
| 660 | - $vat_rules |
|
| 661 | - ), |
|
| 662 | - 'name' => 'vat_rule', |
|
| 663 | - 'id' => 'vat_rule', |
|
| 664 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 665 | - 'show_option_all' => false, |
|
| 666 | - 'show_option_none' => false, |
|
| 667 | - ) |
|
| 668 | - ); |
|
| 669 | - |
|
| 670 | - // Filter by VAT class. |
|
| 646 | + // Sanitize selected vat rule. |
|
| 647 | + $vat_rule = ''; |
|
| 648 | + $vat_rules = getpaid_get_tax_rules(); |
|
| 649 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
| 650 | + $vat_rule = $_GET['vat_rule']; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + // Filter by VAT rule. |
|
| 654 | + echo wpinv_html_select( |
|
| 655 | + array( |
|
| 656 | + 'options' => array_merge( |
|
| 657 | + array( |
|
| 658 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
| 659 | + ), |
|
| 660 | + $vat_rules |
|
| 661 | + ), |
|
| 662 | + 'name' => 'vat_rule', |
|
| 663 | + 'id' => 'vat_rule', |
|
| 664 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 665 | + 'show_option_all' => false, |
|
| 666 | + 'show_option_none' => false, |
|
| 667 | + ) |
|
| 668 | + ); |
|
| 669 | + |
|
| 670 | + // Filter by VAT class. |
|
| 671 | 671 | |
| 672 | - // Sanitize selected vat rule. |
|
| 673 | - $vat_class = ''; |
|
| 674 | - $vat_classes = getpaid_get_tax_classes(); |
|
| 675 | - if ( isset( $_GET['vat_class'] ) ) { |
|
| 676 | - $vat_class = $_GET['vat_class']; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - echo wpinv_html_select( |
|
| 680 | - array( |
|
| 681 | - 'options' => array_merge( |
|
| 682 | - array( |
|
| 683 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
| 684 | - ), |
|
| 685 | - $vat_classes |
|
| 686 | - ), |
|
| 687 | - 'name' => 'vat_class', |
|
| 688 | - 'id' => 'vat_class', |
|
| 689 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 690 | - 'show_option_all' => false, |
|
| 691 | - 'show_option_none' => false, |
|
| 692 | - ) |
|
| 693 | - ); |
|
| 694 | - |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - // Filter by item type. |
|
| 698 | - $type = ''; |
|
| 699 | - if ( isset( $_GET['type'] ) ) { |
|
| 700 | - $type = $_GET['type']; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - echo wpinv_html_select( |
|
| 704 | - array( |
|
| 705 | - 'options' => array_merge( |
|
| 706 | - array( |
|
| 707 | - '' => __( 'All item types', 'invoicing' ) |
|
| 708 | - ), |
|
| 709 | - wpinv_get_item_types() |
|
| 710 | - ), |
|
| 711 | - 'name' => 'type', |
|
| 712 | - 'id' => 'type', |
|
| 713 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 714 | - 'show_option_all' => false, |
|
| 715 | - 'show_option_none' => false, |
|
| 716 | - ) |
|
| 717 | - ); |
|
| 718 | - |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Filters the item query. |
|
| 723 | - */ |
|
| 724 | - public static function filter_item_query( $query ) { |
|
| 725 | - |
|
| 726 | - // modify the query only if it admin and main query. |
|
| 727 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 728 | - return $query; |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - // we want to modify the query for our items. |
|
| 732 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
| 733 | - return $query; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 737 | - $query->query_vars['meta_query'] = array(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - // Filter vat rule type |
|
| 672 | + // Sanitize selected vat rule. |
|
| 673 | + $vat_class = ''; |
|
| 674 | + $vat_classes = getpaid_get_tax_classes(); |
|
| 675 | + if ( isset( $_GET['vat_class'] ) ) { |
|
| 676 | + $vat_class = $_GET['vat_class']; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + echo wpinv_html_select( |
|
| 680 | + array( |
|
| 681 | + 'options' => array_merge( |
|
| 682 | + array( |
|
| 683 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
| 684 | + ), |
|
| 685 | + $vat_classes |
|
| 686 | + ), |
|
| 687 | + 'name' => 'vat_class', |
|
| 688 | + 'id' => 'vat_class', |
|
| 689 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 690 | + 'show_option_all' => false, |
|
| 691 | + 'show_option_none' => false, |
|
| 692 | + ) |
|
| 693 | + ); |
|
| 694 | + |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + // Filter by item type. |
|
| 698 | + $type = ''; |
|
| 699 | + if ( isset( $_GET['type'] ) ) { |
|
| 700 | + $type = $_GET['type']; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + echo wpinv_html_select( |
|
| 704 | + array( |
|
| 705 | + 'options' => array_merge( |
|
| 706 | + array( |
|
| 707 | + '' => __( 'All item types', 'invoicing' ) |
|
| 708 | + ), |
|
| 709 | + wpinv_get_item_types() |
|
| 710 | + ), |
|
| 711 | + 'name' => 'type', |
|
| 712 | + 'id' => 'type', |
|
| 713 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 714 | + 'show_option_all' => false, |
|
| 715 | + 'show_option_none' => false, |
|
| 716 | + ) |
|
| 717 | + ); |
|
| 718 | + |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Filters the item query. |
|
| 723 | + */ |
|
| 724 | + public static function filter_item_query( $query ) { |
|
| 725 | + |
|
| 726 | + // modify the query only if it admin and main query. |
|
| 727 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 728 | + return $query; |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + // we want to modify the query for our items. |
|
| 732 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
| 733 | + return $query; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 737 | + $query->query_vars['meta_query'] = array(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + // Filter vat rule type |
|
| 741 | 741 | if ( ! empty( $_GET['vat_rule'] ) ) { |
| 742 | 742 | $query->query_vars['meta_query'][] = array( |
| 743 | 743 | 'key' => '_wpinv_vat_rule', |
@@ -762,97 +762,97 @@ discard block |
||
| 762 | 762 | 'value' => sanitize_text_field( $_GET['type'] ), |
| 763 | 763 | 'compare' => '=' |
| 764 | 764 | ); |
| 765 | - } |
|
| 766 | - |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Reorders items. |
|
| 771 | - */ |
|
| 772 | - public static function reorder_items( $vars ) { |
|
| 773 | - global $typenow; |
|
| 774 | - |
|
| 775 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 776 | - return $vars; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - // By item type. |
|
| 780 | - if ( 'type' == $vars['orderby'] ) { |
|
| 781 | - return array_merge( |
|
| 782 | - $vars, |
|
| 783 | - array( |
|
| 784 | - 'meta_key' => '_wpinv_type', |
|
| 785 | - 'orderby' => 'meta_value' |
|
| 786 | - ) |
|
| 787 | - ); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - // By vat class. |
|
| 791 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
| 792 | - return array_merge( |
|
| 793 | - $vars, |
|
| 794 | - array( |
|
| 795 | - 'meta_key' => '_wpinv_vat_class', |
|
| 796 | - 'orderby' => 'meta_value' |
|
| 797 | - ) |
|
| 798 | - ); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // By vat rule. |
|
| 802 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 803 | - return array_merge( |
|
| 804 | - $vars, |
|
| 805 | - array( |
|
| 806 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 807 | - 'orderby' => 'meta_value' |
|
| 808 | - ) |
|
| 809 | - ); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - // By price. |
|
| 813 | - if ( 'price' == $vars['orderby'] ) { |
|
| 814 | - return array_merge( |
|
| 815 | - $vars, |
|
| 816 | - array( |
|
| 817 | - 'meta_key' => '_wpinv_price', |
|
| 818 | - 'orderby' => 'meta_value_num' |
|
| 819 | - ) |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - return $vars; |
|
| 824 | - |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Fired when deleting a post. |
|
| 829 | - */ |
|
| 830 | - public static function delete_post( $post_id ) { |
|
| 831 | - |
|
| 832 | - switch ( get_post_type( $post_id ) ) { |
|
| 833 | - |
|
| 834 | - case 'wpi_item' : |
|
| 835 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 836 | - break; |
|
| 837 | - |
|
| 838 | - case 'wpi_payment_form' : |
|
| 839 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 840 | - break; |
|
| 841 | - |
|
| 842 | - case 'wpi_discount' : |
|
| 843 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 844 | - break; |
|
| 845 | - |
|
| 846 | - case 'wpi_invoice' : |
|
| 847 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 848 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 849 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 850 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 851 | - break; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - /** |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Reorders items. |
|
| 771 | + */ |
|
| 772 | + public static function reorder_items( $vars ) { |
|
| 773 | + global $typenow; |
|
| 774 | + |
|
| 775 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 776 | + return $vars; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + // By item type. |
|
| 780 | + if ( 'type' == $vars['orderby'] ) { |
|
| 781 | + return array_merge( |
|
| 782 | + $vars, |
|
| 783 | + array( |
|
| 784 | + 'meta_key' => '_wpinv_type', |
|
| 785 | + 'orderby' => 'meta_value' |
|
| 786 | + ) |
|
| 787 | + ); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + // By vat class. |
|
| 791 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
| 792 | + return array_merge( |
|
| 793 | + $vars, |
|
| 794 | + array( |
|
| 795 | + 'meta_key' => '_wpinv_vat_class', |
|
| 796 | + 'orderby' => 'meta_value' |
|
| 797 | + ) |
|
| 798 | + ); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // By vat rule. |
|
| 802 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 803 | + return array_merge( |
|
| 804 | + $vars, |
|
| 805 | + array( |
|
| 806 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 807 | + 'orderby' => 'meta_value' |
|
| 808 | + ) |
|
| 809 | + ); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + // By price. |
|
| 813 | + if ( 'price' == $vars['orderby'] ) { |
|
| 814 | + return array_merge( |
|
| 815 | + $vars, |
|
| 816 | + array( |
|
| 817 | + 'meta_key' => '_wpinv_price', |
|
| 818 | + 'orderby' => 'meta_value_num' |
|
| 819 | + ) |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + return $vars; |
|
| 824 | + |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Fired when deleting a post. |
|
| 829 | + */ |
|
| 830 | + public static function delete_post( $post_id ) { |
|
| 831 | + |
|
| 832 | + switch ( get_post_type( $post_id ) ) { |
|
| 833 | + |
|
| 834 | + case 'wpi_item' : |
|
| 835 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 836 | + break; |
|
| 837 | + |
|
| 838 | + case 'wpi_payment_form' : |
|
| 839 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 840 | + break; |
|
| 841 | + |
|
| 842 | + case 'wpi_discount' : |
|
| 843 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 844 | + break; |
|
| 845 | + |
|
| 846 | + case 'wpi_invoice' : |
|
| 847 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 848 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 849 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 850 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 851 | + break; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | 856 | * Add a post display state for special GetPaid pages in the page list table. |
| 857 | 857 | * |
| 858 | 858 | * @param array $post_states An array of post display states. |
@@ -866,22 +866,22 @@ discard block |
||
| 866 | 866 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 869 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 870 | 870 | |
| 871 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 872 | - $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
| 873 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 874 | - $label |
|
| 875 | - ); |
|
| 876 | - } |
|
| 871 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 872 | + $post_states["getpaid_{$post_type}_history_page"] = sprintf( |
|
| 873 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 874 | + $label |
|
| 875 | + ); |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | - } |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 880 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 881 | 881 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 884 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 885 | 885 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
| 886 | 886 | } |
| 887 | 887 | |