@@ -18,179 +18,179 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GetPaid_REST_Report_Top_Sellers_Controller extends GetPaid_REST_Report_Sales_Controller { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Route base. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $rest_base = 'reports/top_sellers'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Get top sellers report. |
|
| 30 | - * |
|
| 31 | - * @param WP_REST_Request $request |
|
| 32 | - * @return array|WP_Error |
|
| 33 | - */ |
|
| 34 | - public function get_items( $request ) { |
|
| 35 | - |
|
| 36 | - // Prepare items. |
|
| 37 | - $this->report_range = $this->get_date_range( $request ); |
|
| 38 | - $report_data = $this->get_report_data(); |
|
| 39 | - |
|
| 40 | - $top_sellers = array(); |
|
| 41 | - |
|
| 42 | - foreach ( $report_data as $item ) { |
|
| 43 | - |
|
| 44 | - $item_obj = new WPInv_Item( $item ); |
|
| 45 | - $item_name = $item->invoice_item_name; |
|
| 46 | - $item_qty = floatval( $item->invoice_item_qty ); |
|
| 47 | - $item_id = absint( $item->invoice_item_id ); |
|
| 48 | - $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
| 49 | - |
|
| 50 | - $item_obj = new WPInv_Item( $item_id ); |
|
| 51 | - |
|
| 52 | - if ( $item_obj->exists() ) { |
|
| 53 | - $item_name = $item_obj->get_name(); |
|
| 54 | - } else { |
|
| 55 | - $item_id = 0; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $top_sellers[] = array( |
|
| 59 | - 'name' =>sanitize_text_field( $item_name ), |
|
| 60 | - 'item_id' => $item_id, |
|
| 61 | - 'quantity' => $item_qty, |
|
| 62 | - 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
| 63 | - 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $data = array(); |
|
| 69 | - foreach ( $top_sellers as $top_seller ) { |
|
| 70 | - $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
| 71 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return rest_ensure_response( $data ); |
|
| 75 | - |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Prepare a report sales object for serialization. |
|
| 80 | - * |
|
| 81 | - * @param stdClass $top_seller |
|
| 82 | - * @param WP_REST_Request $request Request object. |
|
| 83 | - * @return WP_REST_Response $response Response data. |
|
| 84 | - */ |
|
| 85 | - public function prepare_item_for_response( $top_seller, $request ) { |
|
| 86 | - $data = (array) $top_seller; |
|
| 87 | - |
|
| 88 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 89 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 90 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 91 | - |
|
| 92 | - // Wrap the data in a response object. |
|
| 93 | - $response = rest_ensure_response( $data ); |
|
| 94 | - $links = array( |
|
| 95 | - 'about' => array( |
|
| 96 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 97 | - ), |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - if ( ! empty( $top_seller->item_id ) ) { |
|
| 101 | - $links['item'] = array( |
|
| 102 | - 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
| 103 | - 'embeddable' => true, |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $response->add_links( $links ); |
|
| 108 | - return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Get all data needed for this report and store in the class. |
|
| 113 | - */ |
|
| 114 | - protected function query_report_data() { |
|
| 115 | - |
|
| 116 | - $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 117 | - array( |
|
| 118 | - 'data' => array( |
|
| 119 | - 'quantity' => array( |
|
| 120 | - 'type' => 'invoice_item', |
|
| 121 | - 'function' => 'SUM', |
|
| 122 | - 'name' => 'invoice_item_qty', |
|
| 123 | - ), |
|
| 124 | - 'item_id' => array( |
|
| 125 | - 'type' => 'invoice_item', |
|
| 126 | - 'function' => '', |
|
| 127 | - 'name' => 'invoice_item_id', |
|
| 128 | - ), |
|
| 129 | - 'item_name' => array( |
|
| 130 | - 'type' => 'invoice_item', |
|
| 131 | - 'function' => '', |
|
| 132 | - 'name' => 'invoice_item_name', |
|
| 133 | - ), |
|
| 134 | - 'price' => array( |
|
| 135 | - 'type' => 'invoice_item', |
|
| 136 | - 'function' => 'SUM', |
|
| 137 | - 'name' => 'invoice_item_price', |
|
| 138 | - ), |
|
| 139 | - ), |
|
| 140 | - 'group_by' => 'invoice_item_id', |
|
| 141 | - 'order_by' => 'invoice_item_qty DESC', |
|
| 142 | - 'query_type' => 'get_results', |
|
| 143 | - 'limit' => 10, |
|
| 144 | - 'filter_range' => $this->report_range, |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Get the Report's schema, conforming to JSON Schema. |
|
| 152 | - * |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function get_item_schema() { |
|
| 156 | - $schema = array( |
|
| 157 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 158 | - 'title' => $this->rest_base, |
|
| 159 | - 'type' => 'object', |
|
| 160 | - 'properties' => array( |
|
| 161 | - 'name' => array( |
|
| 162 | - 'description' => __( 'Item name.', 'invoicing' ), |
|
| 163 | - 'type' => 'string', |
|
| 164 | - 'context' => array( 'view' ), |
|
| 165 | - 'readonly' => true, |
|
| 166 | - ), |
|
| 167 | - 'item_id' => array( |
|
| 168 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 169 | - 'type' => 'integer', |
|
| 170 | - 'context' => array( 'view' ), |
|
| 171 | - 'readonly' => true, |
|
| 172 | - ), |
|
| 173 | - 'quantity' => array( |
|
| 174 | - 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
| 175 | - 'type' => 'number', |
|
| 176 | - 'context' => array( 'view' ), |
|
| 177 | - 'readonly' => true, |
|
| 178 | - ), |
|
| 179 | - 'earnings' => array( |
|
| 180 | - 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
| 181 | - 'type' => 'number', |
|
| 182 | - 'context' => array( 'view' ), |
|
| 183 | - 'readonly' => true, |
|
| 184 | - ), |
|
| 185 | - 'earnings_formatted"' => array( |
|
| 186 | - 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
| 187 | - 'type' => 'string', |
|
| 188 | - 'context' => array( 'view' ), |
|
| 189 | - 'readonly' => true, |
|
| 190 | - ), |
|
| 191 | - ), |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - return $this->add_additional_fields_schema( $schema ); |
|
| 195 | - } |
|
| 21 | + /** |
|
| 22 | + * Route base. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $rest_base = 'reports/top_sellers'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Get top sellers report. |
|
| 30 | + * |
|
| 31 | + * @param WP_REST_Request $request |
|
| 32 | + * @return array|WP_Error |
|
| 33 | + */ |
|
| 34 | + public function get_items( $request ) { |
|
| 35 | + |
|
| 36 | + // Prepare items. |
|
| 37 | + $this->report_range = $this->get_date_range( $request ); |
|
| 38 | + $report_data = $this->get_report_data(); |
|
| 39 | + |
|
| 40 | + $top_sellers = array(); |
|
| 41 | + |
|
| 42 | + foreach ( $report_data as $item ) { |
|
| 43 | + |
|
| 44 | + $item_obj = new WPInv_Item( $item ); |
|
| 45 | + $item_name = $item->invoice_item_name; |
|
| 46 | + $item_qty = floatval( $item->invoice_item_qty ); |
|
| 47 | + $item_id = absint( $item->invoice_item_id ); |
|
| 48 | + $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
| 49 | + |
|
| 50 | + $item_obj = new WPInv_Item( $item_id ); |
|
| 51 | + |
|
| 52 | + if ( $item_obj->exists() ) { |
|
| 53 | + $item_name = $item_obj->get_name(); |
|
| 54 | + } else { |
|
| 55 | + $item_id = 0; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $top_sellers[] = array( |
|
| 59 | + 'name' =>sanitize_text_field( $item_name ), |
|
| 60 | + 'item_id' => $item_id, |
|
| 61 | + 'quantity' => $item_qty, |
|
| 62 | + 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
| 63 | + 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $data = array(); |
|
| 69 | + foreach ( $top_sellers as $top_seller ) { |
|
| 70 | + $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
| 71 | + $data[] = $this->prepare_response_for_collection( $item ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return rest_ensure_response( $data ); |
|
| 75 | + |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Prepare a report sales object for serialization. |
|
| 80 | + * |
|
| 81 | + * @param stdClass $top_seller |
|
| 82 | + * @param WP_REST_Request $request Request object. |
|
| 83 | + * @return WP_REST_Response $response Response data. |
|
| 84 | + */ |
|
| 85 | + public function prepare_item_for_response( $top_seller, $request ) { |
|
| 86 | + $data = (array) $top_seller; |
|
| 87 | + |
|
| 88 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 89 | + $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 90 | + $data = $this->filter_response_by_context( $data, $context ); |
|
| 91 | + |
|
| 92 | + // Wrap the data in a response object. |
|
| 93 | + $response = rest_ensure_response( $data ); |
|
| 94 | + $links = array( |
|
| 95 | + 'about' => array( |
|
| 96 | + 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 97 | + ), |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + if ( ! empty( $top_seller->item_id ) ) { |
|
| 101 | + $links['item'] = array( |
|
| 102 | + 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
| 103 | + 'embeddable' => true, |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $response->add_links( $links ); |
|
| 108 | + return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Get all data needed for this report and store in the class. |
|
| 113 | + */ |
|
| 114 | + protected function query_report_data() { |
|
| 115 | + |
|
| 116 | + $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data( |
|
| 117 | + array( |
|
| 118 | + 'data' => array( |
|
| 119 | + 'quantity' => array( |
|
| 120 | + 'type' => 'invoice_item', |
|
| 121 | + 'function' => 'SUM', |
|
| 122 | + 'name' => 'invoice_item_qty', |
|
| 123 | + ), |
|
| 124 | + 'item_id' => array( |
|
| 125 | + 'type' => 'invoice_item', |
|
| 126 | + 'function' => '', |
|
| 127 | + 'name' => 'invoice_item_id', |
|
| 128 | + ), |
|
| 129 | + 'item_name' => array( |
|
| 130 | + 'type' => 'invoice_item', |
|
| 131 | + 'function' => '', |
|
| 132 | + 'name' => 'invoice_item_name', |
|
| 133 | + ), |
|
| 134 | + 'price' => array( |
|
| 135 | + 'type' => 'invoice_item', |
|
| 136 | + 'function' => 'SUM', |
|
| 137 | + 'name' => 'invoice_item_price', |
|
| 138 | + ), |
|
| 139 | + ), |
|
| 140 | + 'group_by' => 'invoice_item_id', |
|
| 141 | + 'order_by' => 'invoice_item_qty DESC', |
|
| 142 | + 'query_type' => 'get_results', |
|
| 143 | + 'limit' => 10, |
|
| 144 | + 'filter_range' => $this->report_range, |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Get the Report's schema, conforming to JSON Schema. |
|
| 152 | + * |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function get_item_schema() { |
|
| 156 | + $schema = array( |
|
| 157 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
| 158 | + 'title' => $this->rest_base, |
|
| 159 | + 'type' => 'object', |
|
| 160 | + 'properties' => array( |
|
| 161 | + 'name' => array( |
|
| 162 | + 'description' => __( 'Item name.', 'invoicing' ), |
|
| 163 | + 'type' => 'string', |
|
| 164 | + 'context' => array( 'view' ), |
|
| 165 | + 'readonly' => true, |
|
| 166 | + ), |
|
| 167 | + 'item_id' => array( |
|
| 168 | + 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 169 | + 'type' => 'integer', |
|
| 170 | + 'context' => array( 'view' ), |
|
| 171 | + 'readonly' => true, |
|
| 172 | + ), |
|
| 173 | + 'quantity' => array( |
|
| 174 | + 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
| 175 | + 'type' => 'number', |
|
| 176 | + 'context' => array( 'view' ), |
|
| 177 | + 'readonly' => true, |
|
| 178 | + ), |
|
| 179 | + 'earnings' => array( |
|
| 180 | + 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
| 181 | + 'type' => 'number', |
|
| 182 | + 'context' => array( 'view' ), |
|
| 183 | + 'readonly' => true, |
|
| 184 | + ), |
|
| 185 | + 'earnings_formatted"' => array( |
|
| 186 | + 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
| 187 | + 'type' => 'string', |
|
| 188 | + 'context' => array( 'view' ), |
|
| 189 | + 'readonly' => true, |
|
| 190 | + ), |
|
| 191 | + ), |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + return $this->add_additional_fields_schema( $schema ); |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @since 2.0.0 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * GetPaid REST top sellers controller class. |
@@ -31,47 +31,47 @@ discard block |
||
| 31 | 31 | * @param WP_REST_Request $request |
| 32 | 32 | * @return array|WP_Error |
| 33 | 33 | */ |
| 34 | - public function get_items( $request ) { |
|
| 34 | + public function get_items($request) { |
|
| 35 | 35 | |
| 36 | 36 | // Prepare items. |
| 37 | - $this->report_range = $this->get_date_range( $request ); |
|
| 37 | + $this->report_range = $this->get_date_range($request); |
|
| 38 | 38 | $report_data = $this->get_report_data(); |
| 39 | 39 | |
| 40 | 40 | $top_sellers = array(); |
| 41 | 41 | |
| 42 | - foreach ( $report_data as $item ) { |
|
| 42 | + foreach ($report_data as $item) { |
|
| 43 | 43 | |
| 44 | - $item_obj = new WPInv_Item( $item ); |
|
| 44 | + $item_obj = new WPInv_Item($item); |
|
| 45 | 45 | $item_name = $item->invoice_item_name; |
| 46 | - $item_qty = floatval( $item->invoice_item_qty ); |
|
| 47 | - $item_id = absint( $item->invoice_item_id ); |
|
| 48 | - $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
| 46 | + $item_qty = floatval($item->invoice_item_qty); |
|
| 47 | + $item_id = absint($item->invoice_item_id); |
|
| 48 | + $price = sanitize_text_field(wpinv_price($item->invoice_item_price)); |
|
| 49 | 49 | |
| 50 | - $item_obj = new WPInv_Item( $item_id ); |
|
| 50 | + $item_obj = new WPInv_Item($item_id); |
|
| 51 | 51 | |
| 52 | - if ( $item_obj->exists() ) { |
|
| 52 | + if ($item_obj->exists()) { |
|
| 53 | 53 | $item_name = $item_obj->get_name(); |
| 54 | 54 | } else { |
| 55 | 55 | $item_id = 0; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $top_sellers[] = array( |
| 59 | - 'name' =>sanitize_text_field( $item_name ), |
|
| 59 | + 'name' =>sanitize_text_field($item_name), |
|
| 60 | 60 | 'item_id' => $item_id, |
| 61 | 61 | 'quantity' => $item_qty, |
| 62 | - 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
| 63 | - 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
| 62 | + 'earnings' => wpinv_round_amount($item->invoice_item_price), |
|
| 63 | + 'earnings_formatted' => sanitize_text_field(wpinv_price($price)), |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $data = array(); |
| 69 | - foreach ( $top_sellers as $top_seller ) { |
|
| 70 | - $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
| 71 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
| 69 | + foreach ($top_sellers as $top_seller) { |
|
| 70 | + $item = $this->prepare_item_for_response((object) $top_seller, $request); |
|
| 71 | + $data[] = $this->prepare_response_for_collection($item); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return rest_ensure_response( $data ); |
|
| 74 | + return rest_ensure_response($data); |
|
| 75 | 75 | |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | * @param WP_REST_Request $request Request object. |
| 83 | 83 | * @return WP_REST_Response $response Response data. |
| 84 | 84 | */ |
| 85 | - public function prepare_item_for_response( $top_seller, $request ) { |
|
| 85 | + public function prepare_item_for_response($top_seller, $request) { |
|
| 86 | 86 | $data = (array) $top_seller; |
| 87 | 87 | |
| 88 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
| 89 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
| 90 | - $data = $this->filter_response_by_context( $data, $context ); |
|
| 88 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
| 89 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
| 90 | + $data = $this->filter_response_by_context($data, $context); |
|
| 91 | 91 | |
| 92 | 92 | // Wrap the data in a response object. |
| 93 | - $response = rest_ensure_response( $data ); |
|
| 93 | + $response = rest_ensure_response($data); |
|
| 94 | 94 | $links = array( |
| 95 | 95 | 'about' => array( |
| 96 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
| 96 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
| 97 | 97 | ), |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - if ( ! empty( $top_seller->item_id ) ) { |
|
| 101 | - $links['item'] = array( |
|
| 102 | - 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
| 100 | + if (!empty($top_seller->item_id)) { |
|
| 101 | + $links['item'] = array( |
|
| 102 | + 'href' => rest_url(sprintf('/%s/items/%s', $this->namespace, $top_seller->item_id)), |
|
| 103 | 103 | 'embeddable' => true, |
| 104 | 104 | ); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $response->add_links( $links ); |
|
| 108 | - return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
| 107 | + $response->add_links($links); |
|
| 108 | + return apply_filters('getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -159,38 +159,38 @@ discard block |
||
| 159 | 159 | 'type' => 'object', |
| 160 | 160 | 'properties' => array( |
| 161 | 161 | 'name' => array( |
| 162 | - 'description' => __( 'Item name.', 'invoicing' ), |
|
| 162 | + 'description' => __('Item name.', 'invoicing'), |
|
| 163 | 163 | 'type' => 'string', |
| 164 | - 'context' => array( 'view' ), |
|
| 164 | + 'context' => array('view'), |
|
| 165 | 165 | 'readonly' => true, |
| 166 | 166 | ), |
| 167 | 167 | 'item_id' => array( |
| 168 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 168 | + 'description' => __('Item ID.', 'invoicing'), |
|
| 169 | 169 | 'type' => 'integer', |
| 170 | - 'context' => array( 'view' ), |
|
| 170 | + 'context' => array('view'), |
|
| 171 | 171 | 'readonly' => true, |
| 172 | 172 | ), |
| 173 | 173 | 'quantity' => array( |
| 174 | - 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
| 174 | + 'description' => __('Total number of purchases.', 'invoicing'), |
|
| 175 | 175 | 'type' => 'number', |
| 176 | - 'context' => array( 'view' ), |
|
| 176 | + 'context' => array('view'), |
|
| 177 | 177 | 'readonly' => true, |
| 178 | 178 | ), |
| 179 | 179 | 'earnings' => array( |
| 180 | - 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
| 180 | + 'description' => __('Total earnings for the item.', 'invoicing'), |
|
| 181 | 181 | 'type' => 'number', |
| 182 | - 'context' => array( 'view' ), |
|
| 182 | + 'context' => array('view'), |
|
| 183 | 183 | 'readonly' => true, |
| 184 | 184 | ), |
| 185 | 185 | 'earnings_formatted"' => array( |
| 186 | - 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
| 186 | + 'description' => __('Total earnings (formatted) for the item.', 'invoicing'), |
|
| 187 | 187 | 'type' => 'string', |
| 188 | - 'context' => array( 'view' ), |
|
| 188 | + 'context' => array('view'), |
|
| 189 | 189 | 'readonly' => true, |
| 190 | 190 | ), |
| 191 | 191 | ), |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - return $this->add_additional_fields_schema( $schema ); |
|
| 194 | + return $this->add_additional_fields_schema($schema); |
|
| 195 | 195 | } |
| 196 | 196 | } |
@@ -12,79 +12,79 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 20 | - |
|
| 21 | 15 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 30 | - |
|
| 31 | - // Prepare the selected items. |
|
| 32 | - $selected_items = array(); |
|
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // For default forms, ensure that an item has been set. |
|
| 38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
| 41 | - } |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 42 | 20 | |
| 43 | - // Process each individual item. |
|
| 44 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 45 | - $this->process_item( $item, $selected_items ); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - } |
|
| 21 | + /** |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | + |
|
| 31 | + // Prepare the selected items. |
|
| 32 | + $selected_items = array(); |
|
| 33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // For default forms, ensure that an item has been set. |
|
| 38 | + if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // Process each individual item. |
|
| 44 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 45 | + $this->process_item( $item, $selected_items ); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Process a single item. |
|
| 52 | - * |
|
| 53 | - * @param GetPaid_Form_Item $item |
|
| 54 | - * @param array $selected_items |
|
| 55 | - */ |
|
| 56 | - public function process_item( $item, $selected_items ) { |
|
| 50 | + /** |
|
| 51 | + * Process a single item. |
|
| 52 | + * |
|
| 53 | + * @param GetPaid_Form_Item $item |
|
| 54 | + * @param array $selected_items |
|
| 55 | + */ |
|
| 56 | + public function process_item( $item, $selected_items ) { |
|
| 57 | 57 | |
| 58 | - // Abort if this is an optional item and it has not been selected. |
|
| 59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 58 | + // Abort if this is an optional item and it has not been selected. |
|
| 59 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // (maybe) let customers change the quantities and prices. |
|
| 64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 63 | + // (maybe) let customers change the quantities and prices. |
|
| 64 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 65 | 65 | |
| 66 | - // Maybe change the quantities. |
|
| 67 | - if ( $item->allows_quantities() ) { |
|
| 68 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 69 | - } |
|
| 66 | + // Maybe change the quantities. |
|
| 67 | + if ( $item->allows_quantities() ) { |
|
| 68 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // Maybe change the price. |
|
| 72 | - if ( $item->user_can_set_their_price() ) { |
|
| 73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 71 | + // Maybe change the price. |
|
| 72 | + if ( $item->user_can_set_their_price() ) { |
|
| 73 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 74 | 74 | |
| 75 | - if ( $item->get_minimum_price() > $price ) { |
|
| 76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
| 77 | - } |
|
| 75 | + if ( $item->get_minimum_price() > $price ) { |
|
| 76 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $item->set_price( $price ); |
|
| 79 | + $item->set_price( $price ); |
|
| 80 | 80 | |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Save the item. |
|
| 86 | - $this->items[] = $item; |
|
| 85 | + // Save the item. |
|
| 86 | + $this->items[] = $item; |
|
| 87 | 87 | |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | } |
@@ -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 | * Payment form submission itemss class |
@@ -23,26 +23,26 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
| 25 | 25 | */ |
| 26 | - public function __construct( $submission ) { |
|
| 26 | + public function __construct($submission) { |
|
| 27 | 27 | |
| 28 | 28 | $data = $submission->get_data(); |
| 29 | 29 | $payment_form = $submission->get_payment_form(); |
| 30 | 30 | |
| 31 | 31 | // Prepare the selected items. |
| 32 | 32 | $selected_items = array(); |
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 33 | + if (!empty($data['getpaid-items'])) { |
|
| 34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // For default forms, ensure that an item has been set. |
| 38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
| 39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
| 38 | + if ($payment_form->is_default() && !$submission->has_invoice() && isset($data['getpaid-form-items'])) { |
|
| 39 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
| 40 | + $payment_form->set_items(getpaid_convert_items_to_array($form_items)); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Process each individual item. |
| 44 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 45 | - $this->process_item( $item, $selected_items ); |
|
| 44 | + foreach ($payment_form->get_items() as $item) { |
|
| 45 | + $this->process_item($item, $selected_items); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | } |
@@ -53,30 +53,30 @@ discard block |
||
| 53 | 53 | * @param GetPaid_Form_Item $item |
| 54 | 54 | * @param array $selected_items |
| 55 | 55 | */ |
| 56 | - public function process_item( $item, $selected_items ) { |
|
| 56 | + public function process_item($item, $selected_items) { |
|
| 57 | 57 | |
| 58 | 58 | // Abort if this is an optional item and it has not been selected. |
| 59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 59 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // (maybe) let customers change the quantities and prices. |
| 64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 64 | + if (isset($selected_items[$item->get_id()])) { |
|
| 65 | 65 | |
| 66 | 66 | // Maybe change the quantities. |
| 67 | - if ( $item->allows_quantities() ) { |
|
| 68 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 67 | + if ($item->allows_quantities()) { |
|
| 68 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Maybe change the price. |
| 72 | - if ( $item->user_can_set_their_price() ) { |
|
| 73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 72 | + if ($item->user_can_set_their_price()) { |
|
| 73 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
| 74 | 74 | |
| 75 | - if ( $item->get_minimum_price() > $price ) { |
|
| 76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
| 75 | + if ($item->get_minimum_price() > $price) { |
|
| 76 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), wpinv_sanitize_amount($item->get_minimum_price()))); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $item->set_price( $price ); |
|
| 79 | + $item->set_price($price); |
|
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | |
@@ -13,629 +13,629 @@ |
||
| 13 | 13 | |
| 14 | 14 | return array( |
| 15 | 15 | |
| 16 | - 'id' => array( |
|
| 17 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
| 18 | - 'type' => 'integer', |
|
| 19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | - 'readonly' => true, |
|
| 21 | - ), |
|
| 22 | - |
|
| 23 | - 'parent_id' => array( |
|
| 24 | - 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
| 25 | - 'type' => 'integer', |
|
| 26 | - 'minimum' => 0, |
|
| 27 | - 'default' => 0, |
|
| 28 | - 'context' => array( 'view', 'edit' ), |
|
| 29 | - ), |
|
| 30 | - |
|
| 31 | - 'key' => array( |
|
| 32 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
| 33 | - 'type' => 'string', |
|
| 34 | - 'context' => array( 'view', 'edit' ), |
|
| 35 | - 'readonly' => true, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'number' => array( |
|
| 39 | - 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
| 40 | - 'type' => 'string', |
|
| 41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | - ), |
|
| 43 | - |
|
| 44 | - 'type' => array( |
|
| 45 | - 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
| 46 | - 'type' => 'string', |
|
| 47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | - 'readonly' => true, |
|
| 49 | - ), |
|
| 50 | - |
|
| 51 | - 'post_type' => array( |
|
| 52 | - 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
| 53 | - 'type' => 'string', |
|
| 54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | - 'readonly' => true, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - 'version' => array( |
|
| 59 | - 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
| 60 | - 'type' => 'integer', |
|
| 61 | - 'context' => array( 'view', 'edit' ), |
|
| 62 | - 'readonly' => true, |
|
| 63 | - ), |
|
| 64 | - |
|
| 65 | - 'template' => array( |
|
| 66 | - 'description' => __( 'The invoice template.', 'invoicing' ), |
|
| 67 | - 'type' => 'string', |
|
| 68 | - 'default' => 'quantity', |
|
| 69 | - 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
| 70 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 71 | - ), |
|
| 72 | - |
|
| 73 | - 'status' => array( |
|
| 74 | - 'description' => __( 'Invoice status.', 'invoicing' ), |
|
| 75 | - 'type' => 'string', |
|
| 76 | - 'default' => 'wpi-pending', |
|
| 77 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
| 78 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 79 | - ), |
|
| 80 | - |
|
| 81 | - 'status_nicename' => array( |
|
| 82 | - 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
| 83 | - 'type' => 'string', |
|
| 84 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 85 | - 'readonly' => true, |
|
| 86 | - ), |
|
| 87 | - |
|
| 88 | - 'currency' => array( |
|
| 89 | - 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
| 90 | - 'type' => 'string', |
|
| 91 | - 'default' => wpinv_get_currency(), |
|
| 92 | - 'enum' => array_keys( wpinv_get_currencies() ), |
|
| 93 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 94 | - ), |
|
| 95 | - |
|
| 96 | - 'date_created' => array( |
|
| 97 | - 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
| 98 | - 'type' => 'string', |
|
| 99 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 100 | - ), |
|
| 101 | - |
|
| 102 | - 'date_created_gmt' => array( |
|
| 103 | - 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
| 104 | - 'type' => 'string', |
|
| 105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 106 | - 'readonly' => true, |
|
| 107 | - ), |
|
| 108 | - |
|
| 109 | - 'date_modified' => array( |
|
| 110 | - 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
| 111 | - 'type' => 'string', |
|
| 112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 113 | - 'readonly' => true, |
|
| 114 | - ), |
|
| 115 | - |
|
| 116 | - 'date_modified_gmt' => array( |
|
| 117 | - 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
| 118 | - 'type' => 'string', |
|
| 119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 120 | - 'readonly' => true, |
|
| 121 | - ), |
|
| 122 | - |
|
| 123 | - 'due_date' => array( |
|
| 124 | - 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
| 125 | - 'type' => 'string', |
|
| 126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 127 | - ), |
|
| 128 | - |
|
| 129 | - 'due_date_gmt' => array( |
|
| 130 | - 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
| 131 | - 'type' => 'string', |
|
| 132 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 133 | - 'readonly' => true, |
|
| 134 | - ), |
|
| 135 | - |
|
| 136 | - 'completed_date' => array( |
|
| 137 | - 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
| 138 | - 'type' => 'string', |
|
| 139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 140 | - 'readonly' => true, |
|
| 141 | - ), |
|
| 142 | - |
|
| 143 | - 'completed_date_gmt' => array( |
|
| 144 | - 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
| 145 | - 'type' => 'string', |
|
| 146 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 147 | - 'readonly' => true, |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - 'total_discount' => array( |
|
| 151 | - 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
| 152 | - 'type' => 'number', |
|
| 153 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 154 | - 'readonly' => true, |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - 'total_tax' => array( |
|
| 158 | - 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
| 159 | - 'type' => 'number', |
|
| 160 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 161 | - 'readonly' => true, |
|
| 162 | - ), |
|
| 163 | - |
|
| 164 | - 'total_fees' => array( |
|
| 165 | - 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
| 166 | - 'type' => 'number', |
|
| 167 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 168 | - 'readonly' => true, |
|
| 169 | - ), |
|
| 170 | - |
|
| 171 | - 'subtotal' => array( |
|
| 172 | - 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
| 173 | - 'type' => 'number', |
|
| 174 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 175 | - 'readonly' => true, |
|
| 176 | - ), |
|
| 177 | - |
|
| 178 | - 'total' => array( |
|
| 179 | - 'description' => __( 'Grand total.', 'invoicing' ), |
|
| 180 | - 'type' => 'number', |
|
| 181 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 182 | - 'readonly' => true, |
|
| 183 | - ), |
|
| 184 | - |
|
| 185 | - 'initial_total' => array( |
|
| 186 | - 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
| 187 | - 'type' => 'number', |
|
| 188 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 189 | - 'readonly' => true, |
|
| 190 | - ), |
|
| 191 | - |
|
| 192 | - 'recurring_total' => array( |
|
| 193 | - 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
| 194 | - 'type' => 'number', |
|
| 195 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 196 | - 'readonly' => true, |
|
| 197 | - ), |
|
| 198 | - |
|
| 199 | - 'totals' => array( |
|
| 200 | - 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
| 201 | - 'type' => 'object', |
|
| 202 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 203 | - 'readonly' => true, |
|
| 204 | - ), |
|
| 205 | - |
|
| 206 | - 'fees' => array( |
|
| 207 | - 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
| 208 | - 'type' => 'object', |
|
| 209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 210 | - 'items' => array( |
|
| 211 | - 'type' => 'object', |
|
| 212 | - 'required' => array( 'amount' ), |
|
| 213 | - 'properties' => array( |
|
| 214 | - 'amount' => array( |
|
| 215 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 216 | - 'type' => 'string', |
|
| 217 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 218 | - ), |
|
| 219 | - 'recurring' => array( |
|
| 220 | - 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
| 221 | - 'type' => array( 'boolean', 'integer' ), |
|
| 222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - ), |
|
| 226 | - ), |
|
| 227 | - |
|
| 228 | - 'discounts' => array( |
|
| 229 | - 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
| 230 | - 'type' => 'object', |
|
| 231 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 232 | - 'items' => array( |
|
| 233 | - 'type' => 'object', |
|
| 234 | - 'required' => array( 'amount' ), |
|
| 235 | - 'properties' => array( |
|
| 236 | - 'amount' => array( |
|
| 237 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 238 | - 'type' => 'string', |
|
| 239 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 240 | - ), |
|
| 241 | - 'recurring' => array( |
|
| 242 | - 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
| 243 | - 'type' => array( 'boolean', 'integer' ), |
|
| 244 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 245 | - ), |
|
| 246 | - ), |
|
| 247 | - ), |
|
| 248 | - ), |
|
| 249 | - |
|
| 250 | - 'taxes' => array( |
|
| 251 | - 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
| 252 | - 'type' => 'object', |
|
| 253 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 254 | - 'items' => array( |
|
| 255 | - 'type' => 'object', |
|
| 256 | - 'required' => array( 'amount' ), |
|
| 257 | - 'properties' => array( |
|
| 258 | - 'amount' => array( |
|
| 259 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 260 | - 'type' => 'string', |
|
| 261 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 262 | - ), |
|
| 263 | - 'recurring' => array( |
|
| 264 | - 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
| 265 | - 'type' => array( 'boolean', 'integer' ), |
|
| 266 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 267 | - ), |
|
| 268 | - ), |
|
| 269 | - ), |
|
| 270 | - ), |
|
| 271 | - |
|
| 272 | - 'items' => array( |
|
| 273 | - 'description' => __( 'Invoice items.', 'invoicing' ), |
|
| 274 | - 'type' => 'array', |
|
| 275 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 276 | - 'items' => array( |
|
| 277 | - 'type' => 'object', |
|
| 278 | - 'required' => array( 'item_id' ), |
|
| 279 | - 'properties' => array( |
|
| 280 | - 'item_id' => array( |
|
| 281 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 282 | - 'type' => 'integer', |
|
| 283 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 284 | - ), |
|
| 285 | - 'item_name' => array( |
|
| 286 | - 'description' => __( 'Item Name.', 'invoicing' ), |
|
| 287 | - 'type' => 'string', |
|
| 288 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 289 | - ), |
|
| 290 | - 'item_description' => array( |
|
| 291 | - 'description' => __( 'Item Description.', 'invoicing' ), |
|
| 292 | - 'type' => 'string', |
|
| 293 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 294 | - ), |
|
| 295 | - 'item_price' => array( |
|
| 296 | - 'description' => __( 'Item Price.', 'invoicing' ), |
|
| 297 | - 'type' => 'number', |
|
| 298 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 299 | - ), |
|
| 300 | - 'quantity' => array( |
|
| 301 | - 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
| 302 | - 'type' => 'number', |
|
| 303 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 304 | - ), |
|
| 305 | - 'subtotal' => array( |
|
| 306 | - 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
| 307 | - 'type' => 'number', |
|
| 308 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 309 | - 'readonly' => true, |
|
| 310 | - ), |
|
| 311 | - 'meta' => array( |
|
| 312 | - 'description' => __( 'Item Meta.', 'invoicing' ), |
|
| 313 | - 'type' => 'object', |
|
| 314 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 315 | - ), |
|
| 316 | - ), |
|
| 317 | - ), |
|
| 318 | - ), |
|
| 319 | - |
|
| 320 | - 'mode' => array( |
|
| 321 | - 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
| 322 | - 'type' => 'string', |
|
| 323 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 324 | - 'enum' => array( 'live', 'test' ), |
|
| 325 | - 'readonly' => true, |
|
| 326 | - ), |
|
| 16 | + 'id' => array( |
|
| 17 | + 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
| 18 | + 'type' => 'integer', |
|
| 19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 20 | + 'readonly' => true, |
|
| 21 | + ), |
|
| 22 | + |
|
| 23 | + 'parent_id' => array( |
|
| 24 | + 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
| 25 | + 'type' => 'integer', |
|
| 26 | + 'minimum' => 0, |
|
| 27 | + 'default' => 0, |
|
| 28 | + 'context' => array( 'view', 'edit' ), |
|
| 29 | + ), |
|
| 30 | + |
|
| 31 | + 'key' => array( |
|
| 32 | + 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
| 33 | + 'type' => 'string', |
|
| 34 | + 'context' => array( 'view', 'edit' ), |
|
| 35 | + 'readonly' => true, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'number' => array( |
|
| 39 | + 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
| 40 | + 'type' => 'string', |
|
| 41 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 42 | + ), |
|
| 43 | + |
|
| 44 | + 'type' => array( |
|
| 45 | + 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
| 46 | + 'type' => 'string', |
|
| 47 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 48 | + 'readonly' => true, |
|
| 49 | + ), |
|
| 50 | + |
|
| 51 | + 'post_type' => array( |
|
| 52 | + 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
| 53 | + 'type' => 'string', |
|
| 54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 55 | + 'readonly' => true, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + 'version' => array( |
|
| 59 | + 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
| 60 | + 'type' => 'integer', |
|
| 61 | + 'context' => array( 'view', 'edit' ), |
|
| 62 | + 'readonly' => true, |
|
| 63 | + ), |
|
| 64 | + |
|
| 65 | + 'template' => array( |
|
| 66 | + 'description' => __( 'The invoice template.', 'invoicing' ), |
|
| 67 | + 'type' => 'string', |
|
| 68 | + 'default' => 'quantity', |
|
| 69 | + 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
| 70 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 71 | + ), |
|
| 72 | + |
|
| 73 | + 'status' => array( |
|
| 74 | + 'description' => __( 'Invoice status.', 'invoicing' ), |
|
| 75 | + 'type' => 'string', |
|
| 76 | + 'default' => 'wpi-pending', |
|
| 77 | + 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
| 78 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 79 | + ), |
|
| 80 | + |
|
| 81 | + 'status_nicename' => array( |
|
| 82 | + 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
| 83 | + 'type' => 'string', |
|
| 84 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 85 | + 'readonly' => true, |
|
| 86 | + ), |
|
| 87 | + |
|
| 88 | + 'currency' => array( |
|
| 89 | + 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
| 90 | + 'type' => 'string', |
|
| 91 | + 'default' => wpinv_get_currency(), |
|
| 92 | + 'enum' => array_keys( wpinv_get_currencies() ), |
|
| 93 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 94 | + ), |
|
| 95 | + |
|
| 96 | + 'date_created' => array( |
|
| 97 | + 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
| 98 | + 'type' => 'string', |
|
| 99 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 100 | + ), |
|
| 101 | + |
|
| 102 | + 'date_created_gmt' => array( |
|
| 103 | + 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
| 104 | + 'type' => 'string', |
|
| 105 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 106 | + 'readonly' => true, |
|
| 107 | + ), |
|
| 108 | + |
|
| 109 | + 'date_modified' => array( |
|
| 110 | + 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
| 111 | + 'type' => 'string', |
|
| 112 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 113 | + 'readonly' => true, |
|
| 114 | + ), |
|
| 115 | + |
|
| 116 | + 'date_modified_gmt' => array( |
|
| 117 | + 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
| 118 | + 'type' => 'string', |
|
| 119 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 120 | + 'readonly' => true, |
|
| 121 | + ), |
|
| 122 | + |
|
| 123 | + 'due_date' => array( |
|
| 124 | + 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
| 125 | + 'type' => 'string', |
|
| 126 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 127 | + ), |
|
| 128 | + |
|
| 129 | + 'due_date_gmt' => array( |
|
| 130 | + 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
| 131 | + 'type' => 'string', |
|
| 132 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 133 | + 'readonly' => true, |
|
| 134 | + ), |
|
| 135 | + |
|
| 136 | + 'completed_date' => array( |
|
| 137 | + 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
| 138 | + 'type' => 'string', |
|
| 139 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 140 | + 'readonly' => true, |
|
| 141 | + ), |
|
| 142 | + |
|
| 143 | + 'completed_date_gmt' => array( |
|
| 144 | + 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
| 145 | + 'type' => 'string', |
|
| 146 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 147 | + 'readonly' => true, |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + 'total_discount' => array( |
|
| 151 | + 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
| 152 | + 'type' => 'number', |
|
| 153 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 154 | + 'readonly' => true, |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + 'total_tax' => array( |
|
| 158 | + 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
| 159 | + 'type' => 'number', |
|
| 160 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 161 | + 'readonly' => true, |
|
| 162 | + ), |
|
| 163 | + |
|
| 164 | + 'total_fees' => array( |
|
| 165 | + 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
| 166 | + 'type' => 'number', |
|
| 167 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 168 | + 'readonly' => true, |
|
| 169 | + ), |
|
| 170 | + |
|
| 171 | + 'subtotal' => array( |
|
| 172 | + 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
| 173 | + 'type' => 'number', |
|
| 174 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 175 | + 'readonly' => true, |
|
| 176 | + ), |
|
| 177 | + |
|
| 178 | + 'total' => array( |
|
| 179 | + 'description' => __( 'Grand total.', 'invoicing' ), |
|
| 180 | + 'type' => 'number', |
|
| 181 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 182 | + 'readonly' => true, |
|
| 183 | + ), |
|
| 184 | + |
|
| 185 | + 'initial_total' => array( |
|
| 186 | + 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
| 187 | + 'type' => 'number', |
|
| 188 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 189 | + 'readonly' => true, |
|
| 190 | + ), |
|
| 191 | + |
|
| 192 | + 'recurring_total' => array( |
|
| 193 | + 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
| 194 | + 'type' => 'number', |
|
| 195 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 196 | + 'readonly' => true, |
|
| 197 | + ), |
|
| 198 | + |
|
| 199 | + 'totals' => array( |
|
| 200 | + 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
| 201 | + 'type' => 'object', |
|
| 202 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 203 | + 'readonly' => true, |
|
| 204 | + ), |
|
| 205 | + |
|
| 206 | + 'fees' => array( |
|
| 207 | + 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
| 208 | + 'type' => 'object', |
|
| 209 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 210 | + 'items' => array( |
|
| 211 | + 'type' => 'object', |
|
| 212 | + 'required' => array( 'amount' ), |
|
| 213 | + 'properties' => array( |
|
| 214 | + 'amount' => array( |
|
| 215 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 216 | + 'type' => 'string', |
|
| 217 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 218 | + ), |
|
| 219 | + 'recurring' => array( |
|
| 220 | + 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
| 221 | + 'type' => array( 'boolean', 'integer' ), |
|
| 222 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + ), |
|
| 226 | + ), |
|
| 227 | + |
|
| 228 | + 'discounts' => array( |
|
| 229 | + 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
| 230 | + 'type' => 'object', |
|
| 231 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 232 | + 'items' => array( |
|
| 233 | + 'type' => 'object', |
|
| 234 | + 'required' => array( 'amount' ), |
|
| 235 | + 'properties' => array( |
|
| 236 | + 'amount' => array( |
|
| 237 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 238 | + 'type' => 'string', |
|
| 239 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 240 | + ), |
|
| 241 | + 'recurring' => array( |
|
| 242 | + 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
| 243 | + 'type' => array( 'boolean', 'integer' ), |
|
| 244 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 245 | + ), |
|
| 246 | + ), |
|
| 247 | + ), |
|
| 248 | + ), |
|
| 249 | + |
|
| 250 | + 'taxes' => array( |
|
| 251 | + 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
| 252 | + 'type' => 'object', |
|
| 253 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 254 | + 'items' => array( |
|
| 255 | + 'type' => 'object', |
|
| 256 | + 'required' => array( 'amount' ), |
|
| 257 | + 'properties' => array( |
|
| 258 | + 'amount' => array( |
|
| 259 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 260 | + 'type' => 'string', |
|
| 261 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 262 | + ), |
|
| 263 | + 'recurring' => array( |
|
| 264 | + 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
| 265 | + 'type' => array( 'boolean', 'integer' ), |
|
| 266 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 267 | + ), |
|
| 268 | + ), |
|
| 269 | + ), |
|
| 270 | + ), |
|
| 271 | + |
|
| 272 | + 'items' => array( |
|
| 273 | + 'description' => __( 'Invoice items.', 'invoicing' ), |
|
| 274 | + 'type' => 'array', |
|
| 275 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 276 | + 'items' => array( |
|
| 277 | + 'type' => 'object', |
|
| 278 | + 'required' => array( 'item_id' ), |
|
| 279 | + 'properties' => array( |
|
| 280 | + 'item_id' => array( |
|
| 281 | + 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 282 | + 'type' => 'integer', |
|
| 283 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 284 | + ), |
|
| 285 | + 'item_name' => array( |
|
| 286 | + 'description' => __( 'Item Name.', 'invoicing' ), |
|
| 287 | + 'type' => 'string', |
|
| 288 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 289 | + ), |
|
| 290 | + 'item_description' => array( |
|
| 291 | + 'description' => __( 'Item Description.', 'invoicing' ), |
|
| 292 | + 'type' => 'string', |
|
| 293 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 294 | + ), |
|
| 295 | + 'item_price' => array( |
|
| 296 | + 'description' => __( 'Item Price.', 'invoicing' ), |
|
| 297 | + 'type' => 'number', |
|
| 298 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 299 | + ), |
|
| 300 | + 'quantity' => array( |
|
| 301 | + 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
| 302 | + 'type' => 'number', |
|
| 303 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 304 | + ), |
|
| 305 | + 'subtotal' => array( |
|
| 306 | + 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
| 307 | + 'type' => 'number', |
|
| 308 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 309 | + 'readonly' => true, |
|
| 310 | + ), |
|
| 311 | + 'meta' => array( |
|
| 312 | + 'description' => __( 'Item Meta.', 'invoicing' ), |
|
| 313 | + 'type' => 'object', |
|
| 314 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 315 | + ), |
|
| 316 | + ), |
|
| 317 | + ), |
|
| 318 | + ), |
|
| 319 | + |
|
| 320 | + 'mode' => array( |
|
| 321 | + 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
| 322 | + 'type' => 'string', |
|
| 323 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 324 | + 'enum' => array( 'live', 'test' ), |
|
| 325 | + 'readonly' => true, |
|
| 326 | + ), |
|
| 327 | 327 | |
| 328 | - 'discount_code' => array( |
|
| 329 | - 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
| 330 | - 'type' => 'string', |
|
| 331 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 332 | - ), |
|
| 333 | - |
|
| 334 | - 'gateway' => array( |
|
| 335 | - 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
| 336 | - 'type' => 'string', |
|
| 337 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 338 | - ), |
|
| 339 | - |
|
| 340 | - 'gateway_title' => array( |
|
| 341 | - 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
| 342 | - 'type' => 'string', |
|
| 343 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 344 | - 'readonly' => true, |
|
| 345 | - ), |
|
| 346 | - |
|
| 347 | - 'transaction_id' => array( |
|
| 348 | - 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
| 349 | - 'type' => 'string', |
|
| 350 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 351 | - ), |
|
| 328 | + 'discount_code' => array( |
|
| 329 | + 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
| 330 | + 'type' => 'string', |
|
| 331 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 332 | + ), |
|
| 333 | + |
|
| 334 | + 'gateway' => array( |
|
| 335 | + 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
| 336 | + 'type' => 'string', |
|
| 337 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 338 | + ), |
|
| 339 | + |
|
| 340 | + 'gateway_title' => array( |
|
| 341 | + 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
| 342 | + 'type' => 'string', |
|
| 343 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 344 | + 'readonly' => true, |
|
| 345 | + ), |
|
| 346 | + |
|
| 347 | + 'transaction_id' => array( |
|
| 348 | + 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
| 349 | + 'type' => 'string', |
|
| 350 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 351 | + ), |
|
| 352 | 352 | |
| 353 | - 'disable_taxes' => array( |
|
| 354 | - 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
| 355 | - 'type' => 'boolean ', |
|
| 356 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 357 | - ), |
|
| 358 | - |
|
| 359 | - 'is_viewed' => array( |
|
| 360 | - 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
| 361 | - 'type' => 'boolean ', |
|
| 362 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 363 | - 'readonly' => true, |
|
| 364 | - ), |
|
| 365 | - |
|
| 366 | - 'email_cc' => array( |
|
| 367 | - 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
| 368 | - 'type' => 'string ', |
|
| 369 | - 'context' => array( 'view', 'edit' ), |
|
| 370 | - ), |
|
| 371 | - |
|
| 372 | - 'subscription_id' => array( |
|
| 373 | - 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
| 374 | - 'type' => 'string ', |
|
| 375 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 376 | - 'readonly' => true, |
|
| 377 | - ), |
|
| 378 | - |
|
| 379 | - 'subscription_name' => array( |
|
| 380 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 381 | - 'type' => 'string ', |
|
| 382 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 383 | - 'readonly' => true, |
|
| 384 | - ), |
|
| 385 | - |
|
| 386 | - 'subscription_name' => array( |
|
| 387 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 388 | - 'type' => 'string ', |
|
| 389 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 390 | - 'readonly' => true, |
|
| 391 | - ), |
|
| 392 | - |
|
| 393 | - 'is_parent' => array( |
|
| 394 | - 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
| 395 | - 'type' => 'boolean', |
|
| 396 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 397 | - 'readonly' => true, |
|
| 398 | - ), |
|
| 399 | - |
|
| 400 | - 'is_renewal' => array( |
|
| 401 | - 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
| 402 | - 'type' => 'boolean', |
|
| 403 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 404 | - 'readonly' => true, |
|
| 405 | - ), |
|
| 406 | - |
|
| 407 | - 'is_recurring' => array( |
|
| 408 | - 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
| 409 | - 'type' => 'boolean', |
|
| 410 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 411 | - 'readonly' => true, |
|
| 412 | - ), |
|
| 413 | - |
|
| 414 | - 'is_free' => array( |
|
| 415 | - 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
| 416 | - 'type' => 'boolean', |
|
| 417 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 418 | - 'readonly' => true, |
|
| 419 | - ), |
|
| 420 | - |
|
| 421 | - 'is_paid' => array( |
|
| 422 | - 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
| 423 | - 'type' => 'boolean', |
|
| 424 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 425 | - 'readonly' => true, |
|
| 426 | - ), |
|
| 427 | - |
|
| 428 | - 'needs_payment' => array( |
|
| 429 | - 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
| 430 | - 'type' => 'boolean', |
|
| 431 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 432 | - 'readonly' => true, |
|
| 433 | - ), |
|
| 434 | - |
|
| 435 | - 'is_refunded' => array( |
|
| 436 | - 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
| 437 | - 'type' => 'boolean', |
|
| 438 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 439 | - 'readonly' => true, |
|
| 440 | - ), |
|
| 441 | - |
|
| 442 | - 'is_due' => array( |
|
| 443 | - 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
| 444 | - 'type' => 'boolean', |
|
| 445 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 446 | - 'readonly' => true, |
|
| 447 | - ), |
|
| 448 | - |
|
| 449 | - 'is_held' => array( |
|
| 450 | - 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
| 451 | - 'type' => 'boolean', |
|
| 452 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 453 | - 'readonly' => true, |
|
| 454 | - ), |
|
| 455 | - |
|
| 456 | - 'is_draft' => array( |
|
| 457 | - 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
| 458 | - 'type' => 'boolean', |
|
| 459 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 460 | - 'readonly' => true, |
|
| 461 | - ), |
|
| 462 | - |
|
| 463 | - 'path' => array( |
|
| 464 | - 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
| 465 | - 'type' => 'string', |
|
| 466 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 467 | - 'readonly' => true, |
|
| 468 | - ), |
|
| 469 | - |
|
| 470 | - 'description' => array( |
|
| 471 | - 'description' => __( 'The invoice description.', 'invoicing' ), |
|
| 472 | - 'type' => 'string', |
|
| 473 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 474 | - ), |
|
| 475 | - |
|
| 476 | - 'payment_form' => array( |
|
| 477 | - 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
| 478 | - 'type' => 'integer', |
|
| 479 | - 'context' => array( 'view', 'edit' ), |
|
| 480 | - 'readonly' => true, |
|
| 481 | - ), |
|
| 482 | - |
|
| 483 | - 'submission_id' => array( |
|
| 484 | - 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
| 485 | - 'type' => 'string', |
|
| 486 | - 'context' => array( 'view', 'edit' ), |
|
| 487 | - 'readonly' => true, |
|
| 488 | - ), |
|
| 489 | - |
|
| 490 | - 'customer_id' => array( |
|
| 491 | - 'description' => __( 'The customer id.', 'invoicing' ), |
|
| 492 | - 'type' => 'integer', |
|
| 493 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 494 | - ), |
|
| 495 | - |
|
| 496 | - 'customer_ip' => array( |
|
| 497 | - 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
| 498 | - 'type' => 'string', |
|
| 499 | - 'format' => 'ip', |
|
| 500 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 501 | - ), |
|
| 502 | - |
|
| 503 | - 'first_name' => array( |
|
| 504 | - 'description' => __( "The customer's first name.", 'invoicing' ), |
|
| 505 | - 'type' => 'string', |
|
| 506 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 507 | - ), |
|
| 508 | - |
|
| 509 | - 'last_name' => array( |
|
| 510 | - 'description' => __( "The customer's last name.", 'invoicing' ), |
|
| 511 | - 'type' => 'string', |
|
| 512 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 513 | - ), |
|
| 353 | + 'disable_taxes' => array( |
|
| 354 | + 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
| 355 | + 'type' => 'boolean ', |
|
| 356 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 357 | + ), |
|
| 358 | + |
|
| 359 | + 'is_viewed' => array( |
|
| 360 | + 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
| 361 | + 'type' => 'boolean ', |
|
| 362 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 363 | + 'readonly' => true, |
|
| 364 | + ), |
|
| 365 | + |
|
| 366 | + 'email_cc' => array( |
|
| 367 | + 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
| 368 | + 'type' => 'string ', |
|
| 369 | + 'context' => array( 'view', 'edit' ), |
|
| 370 | + ), |
|
| 371 | + |
|
| 372 | + 'subscription_id' => array( |
|
| 373 | + 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
| 374 | + 'type' => 'string ', |
|
| 375 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 376 | + 'readonly' => true, |
|
| 377 | + ), |
|
| 378 | + |
|
| 379 | + 'subscription_name' => array( |
|
| 380 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 381 | + 'type' => 'string ', |
|
| 382 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 383 | + 'readonly' => true, |
|
| 384 | + ), |
|
| 385 | + |
|
| 386 | + 'subscription_name' => array( |
|
| 387 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 388 | + 'type' => 'string ', |
|
| 389 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 390 | + 'readonly' => true, |
|
| 391 | + ), |
|
| 392 | + |
|
| 393 | + 'is_parent' => array( |
|
| 394 | + 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
| 395 | + 'type' => 'boolean', |
|
| 396 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 397 | + 'readonly' => true, |
|
| 398 | + ), |
|
| 399 | + |
|
| 400 | + 'is_renewal' => array( |
|
| 401 | + 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
| 402 | + 'type' => 'boolean', |
|
| 403 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 404 | + 'readonly' => true, |
|
| 405 | + ), |
|
| 406 | + |
|
| 407 | + 'is_recurring' => array( |
|
| 408 | + 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
| 409 | + 'type' => 'boolean', |
|
| 410 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 411 | + 'readonly' => true, |
|
| 412 | + ), |
|
| 413 | + |
|
| 414 | + 'is_free' => array( |
|
| 415 | + 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
| 416 | + 'type' => 'boolean', |
|
| 417 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 418 | + 'readonly' => true, |
|
| 419 | + ), |
|
| 420 | + |
|
| 421 | + 'is_paid' => array( |
|
| 422 | + 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
| 423 | + 'type' => 'boolean', |
|
| 424 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 425 | + 'readonly' => true, |
|
| 426 | + ), |
|
| 427 | + |
|
| 428 | + 'needs_payment' => array( |
|
| 429 | + 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
| 430 | + 'type' => 'boolean', |
|
| 431 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 432 | + 'readonly' => true, |
|
| 433 | + ), |
|
| 434 | + |
|
| 435 | + 'is_refunded' => array( |
|
| 436 | + 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
| 437 | + 'type' => 'boolean', |
|
| 438 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 439 | + 'readonly' => true, |
|
| 440 | + ), |
|
| 441 | + |
|
| 442 | + 'is_due' => array( |
|
| 443 | + 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
| 444 | + 'type' => 'boolean', |
|
| 445 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 446 | + 'readonly' => true, |
|
| 447 | + ), |
|
| 448 | + |
|
| 449 | + 'is_held' => array( |
|
| 450 | + 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
| 451 | + 'type' => 'boolean', |
|
| 452 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 453 | + 'readonly' => true, |
|
| 454 | + ), |
|
| 455 | + |
|
| 456 | + 'is_draft' => array( |
|
| 457 | + 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
| 458 | + 'type' => 'boolean', |
|
| 459 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 460 | + 'readonly' => true, |
|
| 461 | + ), |
|
| 462 | + |
|
| 463 | + 'path' => array( |
|
| 464 | + 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
| 465 | + 'type' => 'string', |
|
| 466 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 467 | + 'readonly' => true, |
|
| 468 | + ), |
|
| 469 | + |
|
| 470 | + 'description' => array( |
|
| 471 | + 'description' => __( 'The invoice description.', 'invoicing' ), |
|
| 472 | + 'type' => 'string', |
|
| 473 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 474 | + ), |
|
| 475 | + |
|
| 476 | + 'payment_form' => array( |
|
| 477 | + 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
| 478 | + 'type' => 'integer', |
|
| 479 | + 'context' => array( 'view', 'edit' ), |
|
| 480 | + 'readonly' => true, |
|
| 481 | + ), |
|
| 482 | + |
|
| 483 | + 'submission_id' => array( |
|
| 484 | + 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
| 485 | + 'type' => 'string', |
|
| 486 | + 'context' => array( 'view', 'edit' ), |
|
| 487 | + 'readonly' => true, |
|
| 488 | + ), |
|
| 489 | + |
|
| 490 | + 'customer_id' => array( |
|
| 491 | + 'description' => __( 'The customer id.', 'invoicing' ), |
|
| 492 | + 'type' => 'integer', |
|
| 493 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 494 | + ), |
|
| 495 | + |
|
| 496 | + 'customer_ip' => array( |
|
| 497 | + 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
| 498 | + 'type' => 'string', |
|
| 499 | + 'format' => 'ip', |
|
| 500 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 501 | + ), |
|
| 502 | + |
|
| 503 | + 'first_name' => array( |
|
| 504 | + 'description' => __( "The customer's first name.", 'invoicing' ), |
|
| 505 | + 'type' => 'string', |
|
| 506 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 507 | + ), |
|
| 508 | + |
|
| 509 | + 'last_name' => array( |
|
| 510 | + 'description' => __( "The customer's last name.", 'invoicing' ), |
|
| 511 | + 'type' => 'string', |
|
| 512 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 513 | + ), |
|
| 514 | 514 | |
| 515 | - 'full_name' => array( |
|
| 516 | - 'description' => __( "The customer's full name.", 'invoicing' ), |
|
| 517 | - 'type' => 'string', |
|
| 518 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 519 | - 'readonly' => true, |
|
| 520 | - ), |
|
| 521 | - |
|
| 522 | - 'phone_number' => array( |
|
| 523 | - 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
| 524 | - 'type' => 'string', |
|
| 525 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 526 | - ), |
|
| 527 | - |
|
| 528 | - 'email_address' => array( |
|
| 529 | - 'description' => __( "The customer's email address.", 'invoicing' ), |
|
| 530 | - 'type' => 'string', |
|
| 531 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 532 | - 'readonly' => true, |
|
| 533 | - ), |
|
| 534 | - |
|
| 535 | - 'customer_country' => array( |
|
| 536 | - 'description' => __( "The customer's country.", 'invoicing' ), |
|
| 537 | - 'type' => 'string', |
|
| 538 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 539 | - 'default' => wpinv_get_default_country(), |
|
| 540 | - ), |
|
| 541 | - |
|
| 542 | - 'customer_state' => array( |
|
| 543 | - 'description' => __( "The customer's state.", 'invoicing' ), |
|
| 544 | - 'type' => 'string', |
|
| 545 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 546 | - ), |
|
| 547 | - |
|
| 548 | - 'customer_city' => array( |
|
| 549 | - 'description' => __( "The customer's city.", 'invoicing' ), |
|
| 550 | - 'type' => 'string', |
|
| 551 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 552 | - ), |
|
| 553 | - |
|
| 554 | - 'customer_zip' => array( |
|
| 555 | - 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
| 556 | - 'type' => 'string', |
|
| 557 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 558 | - ), |
|
| 559 | - |
|
| 560 | - 'customer_company' => array( |
|
| 561 | - 'description' => __( "The customer's company name.", 'invoicing' ), |
|
| 562 | - 'type' => 'string', |
|
| 563 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 564 | - ), |
|
| 565 | - |
|
| 566 | - 'vat_number' => array( |
|
| 567 | - 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
| 568 | - 'type' => 'string', |
|
| 569 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 570 | - ), |
|
| 571 | - |
|
| 572 | - 'vat_rate' => array( |
|
| 573 | - 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
| 574 | - 'type' => 'number', |
|
| 575 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 576 | - 'readonly' => true, |
|
| 577 | - ), |
|
| 578 | - |
|
| 579 | - 'customer_address' => array( |
|
| 580 | - 'description' => __( "The customer's address.", 'invoicing' ), |
|
| 581 | - 'type' => 'string', |
|
| 582 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 583 | - ), |
|
| 584 | - |
|
| 585 | - 'address_confirmed' => array( |
|
| 586 | - 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
| 587 | - 'type' => 'boolean', |
|
| 588 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 589 | - ), |
|
| 590 | - |
|
| 591 | - 'meta_data' => array( |
|
| 592 | - 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
| 593 | - 'type' => 'array', |
|
| 594 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 595 | - 'items' => array( |
|
| 596 | - 'type' => 'object', |
|
| 597 | - 'properties' => array( |
|
| 598 | - 'id' => array( |
|
| 599 | - 'description' => __( 'Meta ID.', 'invoicing' ), |
|
| 600 | - 'type' => 'string', |
|
| 601 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 602 | - ), |
|
| 603 | - 'key' => array( |
|
| 604 | - 'description' => __( 'Meta key.', 'invoicing' ), |
|
| 605 | - 'type' => 'string', |
|
| 606 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 607 | - ), |
|
| 608 | - 'value' => array( |
|
| 609 | - 'description' => __( 'Meta Value.', 'invoicing' ), |
|
| 610 | - 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
| 611 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 612 | - ), |
|
| 613 | - ), |
|
| 614 | - ), |
|
| 615 | - ), |
|
| 616 | - |
|
| 617 | - 'view_url' => array( |
|
| 618 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
| 619 | - 'type' => 'string', |
|
| 620 | - 'format' => 'uri', |
|
| 621 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 622 | - 'readonly' => true, |
|
| 623 | - ), |
|
| 624 | - |
|
| 625 | - 'checkout_payment_url' => array( |
|
| 626 | - 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
| 627 | - 'type' => 'string', |
|
| 628 | - 'format' => 'uri', |
|
| 629 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 630 | - 'readonly' => true, |
|
| 631 | - ), |
|
| 632 | - |
|
| 633 | - 'receipt_url' => array( |
|
| 634 | - 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
| 635 | - 'type' => 'string', |
|
| 636 | - 'format' => 'uri', |
|
| 637 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 638 | - 'readonly' => true, |
|
| 639 | - ), |
|
| 515 | + 'full_name' => array( |
|
| 516 | + 'description' => __( "The customer's full name.", 'invoicing' ), |
|
| 517 | + 'type' => 'string', |
|
| 518 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 519 | + 'readonly' => true, |
|
| 520 | + ), |
|
| 521 | + |
|
| 522 | + 'phone_number' => array( |
|
| 523 | + 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
| 524 | + 'type' => 'string', |
|
| 525 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 526 | + ), |
|
| 527 | + |
|
| 528 | + 'email_address' => array( |
|
| 529 | + 'description' => __( "The customer's email address.", 'invoicing' ), |
|
| 530 | + 'type' => 'string', |
|
| 531 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 532 | + 'readonly' => true, |
|
| 533 | + ), |
|
| 534 | + |
|
| 535 | + 'customer_country' => array( |
|
| 536 | + 'description' => __( "The customer's country.", 'invoicing' ), |
|
| 537 | + 'type' => 'string', |
|
| 538 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 539 | + 'default' => wpinv_get_default_country(), |
|
| 540 | + ), |
|
| 541 | + |
|
| 542 | + 'customer_state' => array( |
|
| 543 | + 'description' => __( "The customer's state.", 'invoicing' ), |
|
| 544 | + 'type' => 'string', |
|
| 545 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 546 | + ), |
|
| 547 | + |
|
| 548 | + 'customer_city' => array( |
|
| 549 | + 'description' => __( "The customer's city.", 'invoicing' ), |
|
| 550 | + 'type' => 'string', |
|
| 551 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 552 | + ), |
|
| 553 | + |
|
| 554 | + 'customer_zip' => array( |
|
| 555 | + 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
| 556 | + 'type' => 'string', |
|
| 557 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 558 | + ), |
|
| 559 | + |
|
| 560 | + 'customer_company' => array( |
|
| 561 | + 'description' => __( "The customer's company name.", 'invoicing' ), |
|
| 562 | + 'type' => 'string', |
|
| 563 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 564 | + ), |
|
| 565 | + |
|
| 566 | + 'vat_number' => array( |
|
| 567 | + 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
| 568 | + 'type' => 'string', |
|
| 569 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 570 | + ), |
|
| 571 | + |
|
| 572 | + 'vat_rate' => array( |
|
| 573 | + 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
| 574 | + 'type' => 'number', |
|
| 575 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 576 | + 'readonly' => true, |
|
| 577 | + ), |
|
| 578 | + |
|
| 579 | + 'customer_address' => array( |
|
| 580 | + 'description' => __( "The customer's address.", 'invoicing' ), |
|
| 581 | + 'type' => 'string', |
|
| 582 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 583 | + ), |
|
| 584 | + |
|
| 585 | + 'address_confirmed' => array( |
|
| 586 | + 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
| 587 | + 'type' => 'boolean', |
|
| 588 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 589 | + ), |
|
| 590 | + |
|
| 591 | + 'meta_data' => array( |
|
| 592 | + 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
| 593 | + 'type' => 'array', |
|
| 594 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 595 | + 'items' => array( |
|
| 596 | + 'type' => 'object', |
|
| 597 | + 'properties' => array( |
|
| 598 | + 'id' => array( |
|
| 599 | + 'description' => __( 'Meta ID.', 'invoicing' ), |
|
| 600 | + 'type' => 'string', |
|
| 601 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 602 | + ), |
|
| 603 | + 'key' => array( |
|
| 604 | + 'description' => __( 'Meta key.', 'invoicing' ), |
|
| 605 | + 'type' => 'string', |
|
| 606 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 607 | + ), |
|
| 608 | + 'value' => array( |
|
| 609 | + 'description' => __( 'Meta Value.', 'invoicing' ), |
|
| 610 | + 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
| 611 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 612 | + ), |
|
| 613 | + ), |
|
| 614 | + ), |
|
| 615 | + ), |
|
| 616 | + |
|
| 617 | + 'view_url' => array( |
|
| 618 | + 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
| 619 | + 'type' => 'string', |
|
| 620 | + 'format' => 'uri', |
|
| 621 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 622 | + 'readonly' => true, |
|
| 623 | + ), |
|
| 624 | + |
|
| 625 | + 'checkout_payment_url' => array( |
|
| 626 | + 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
| 627 | + 'type' => 'string', |
|
| 628 | + 'format' => 'uri', |
|
| 629 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 630 | + 'readonly' => true, |
|
| 631 | + ), |
|
| 632 | + |
|
| 633 | + 'receipt_url' => array( |
|
| 634 | + 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
| 635 | + 'type' => 'string', |
|
| 636 | + 'format' => 'uri', |
|
| 637 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
| 638 | + 'readonly' => true, |
|
| 639 | + ), |
|
| 640 | 640 | |
| 641 | 641 | ); |
@@ -9,632 +9,632 @@ |
||
| 9 | 9 | * @version 1.0.19 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | return array( |
| 15 | 15 | |
| 16 | 16 | 'id' => array( |
| 17 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
| 17 | + 'description' => __('Unique identifier for the invoice.', 'invoicing'), |
|
| 18 | 18 | 'type' => 'integer', |
| 19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 19 | + 'context' => array('view', 'edit', 'embed'), |
|
| 20 | 20 | 'readonly' => true, |
| 21 | 21 | ), |
| 22 | 22 | |
| 23 | 23 | 'parent_id' => array( |
| 24 | - 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
| 24 | + 'description' => __('Parent invoice ID.', 'invoicing'), |
|
| 25 | 25 | 'type' => 'integer', |
| 26 | 26 | 'minimum' => 0, |
| 27 | 27 | 'default' => 0, |
| 28 | - 'context' => array( 'view', 'edit' ), |
|
| 28 | + 'context' => array('view', 'edit'), |
|
| 29 | 29 | ), |
| 30 | 30 | |
| 31 | 31 | 'key' => array( |
| 32 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
| 32 | + 'description' => __('A unique key for the invoice.', 'invoicing'), |
|
| 33 | 33 | 'type' => 'string', |
| 34 | - 'context' => array( 'view', 'edit' ), |
|
| 34 | + 'context' => array('view', 'edit'), |
|
| 35 | 35 | 'readonly' => true, |
| 36 | 36 | ), |
| 37 | 37 | |
| 38 | 38 | 'number' => array( |
| 39 | - 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
| 39 | + 'description' => __('A unique number for the invoice.', 'invoicing'), |
|
| 40 | 40 | 'type' => 'string', |
| 41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 41 | + 'context' => array('view', 'edit', 'embed'), |
|
| 42 | 42 | ), |
| 43 | 43 | |
| 44 | 44 | 'type' => array( |
| 45 | - 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
| 45 | + 'description' => __('Get the invoice type (e.g invoice, quote etc).', 'invoicing'), |
|
| 46 | 46 | 'type' => 'string', |
| 47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 47 | + 'context' => array('view', 'edit', 'embed'), |
|
| 48 | 48 | 'readonly' => true, |
| 49 | 49 | ), |
| 50 | 50 | |
| 51 | 51 | 'post_type' => array( |
| 52 | - 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
| 52 | + 'description' => __('Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing'), |
|
| 53 | 53 | 'type' => 'string', |
| 54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 54 | + 'context' => array('view', 'edit', 'embed'), |
|
| 55 | 55 | 'readonly' => true, |
| 56 | 56 | ), |
| 57 | 57 | |
| 58 | 58 | 'version' => array( |
| 59 | - 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
| 59 | + 'description' => __('Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing'), |
|
| 60 | 60 | 'type' => 'integer', |
| 61 | - 'context' => array( 'view', 'edit' ), |
|
| 61 | + 'context' => array('view', 'edit'), |
|
| 62 | 62 | 'readonly' => true, |
| 63 | 63 | ), |
| 64 | 64 | |
| 65 | 65 | 'template' => array( |
| 66 | - 'description' => __( 'The invoice template.', 'invoicing' ), |
|
| 66 | + 'description' => __('The invoice template.', 'invoicing'), |
|
| 67 | 67 | 'type' => 'string', |
| 68 | 68 | 'default' => 'quantity', |
| 69 | - 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
| 70 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 69 | + 'enum' => array('quantity', 'hours', 'amount'), |
|
| 70 | + 'context' => array('view', 'edit', 'embed'), |
|
| 71 | 71 | ), |
| 72 | 72 | |
| 73 | 73 | 'status' => array( |
| 74 | - 'description' => __( 'Invoice status.', 'invoicing' ), |
|
| 74 | + 'description' => __('Invoice status.', 'invoicing'), |
|
| 75 | 75 | 'type' => 'string', |
| 76 | 76 | 'default' => 'wpi-pending', |
| 77 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
| 78 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 77 | + 'enum' => array_keys(wpinv_get_invoice_statuses(true)), |
|
| 78 | + 'context' => array('view', 'edit', 'embed'), |
|
| 79 | 79 | ), |
| 80 | 80 | |
| 81 | 81 | 'status_nicename' => array( |
| 82 | - 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
| 82 | + 'description' => __('A human readable name for the invoice status.', 'invoicing'), |
|
| 83 | 83 | 'type' => 'string', |
| 84 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 84 | + 'context' => array('view', 'edit', 'embed'), |
|
| 85 | 85 | 'readonly' => true, |
| 86 | 86 | ), |
| 87 | 87 | |
| 88 | 88 | 'currency' => array( |
| 89 | - 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
| 89 | + 'description' => __('The invoice currency in ISO format.', 'invoicing'), |
|
| 90 | 90 | 'type' => 'string', |
| 91 | 91 | 'default' => wpinv_get_currency(), |
| 92 | - 'enum' => array_keys( wpinv_get_currencies() ), |
|
| 93 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 92 | + 'enum' => array_keys(wpinv_get_currencies()), |
|
| 93 | + 'context' => array('view', 'edit', 'embed'), |
|
| 94 | 94 | ), |
| 95 | 95 | |
| 96 | 96 | 'date_created' => array( |
| 97 | - 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
| 97 | + 'description' => __("The date the invoice was created, in the site's timezone.", 'invoicing'), |
|
| 98 | 98 | 'type' => 'string', |
| 99 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 99 | + 'context' => array('view', 'edit', 'embed'), |
|
| 100 | 100 | ), |
| 101 | 101 | |
| 102 | 102 | 'date_created_gmt' => array( |
| 103 | - 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
| 103 | + 'description' => __('The GMT date the invoice was created.', 'invoicing'), |
|
| 104 | 104 | 'type' => 'string', |
| 105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 105 | + 'context' => array('view', 'edit', 'embed'), |
|
| 106 | 106 | 'readonly' => true, |
| 107 | 107 | ), |
| 108 | 108 | |
| 109 | 109 | 'date_modified' => array( |
| 110 | - 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
| 110 | + 'description' => __("The date the invoice was last modified, in the site's timezone.", 'invoicing'), |
|
| 111 | 111 | 'type' => 'string', |
| 112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 112 | + 'context' => array('view', 'edit', 'embed'), |
|
| 113 | 113 | 'readonly' => true, |
| 114 | 114 | ), |
| 115 | 115 | |
| 116 | 116 | 'date_modified_gmt' => array( |
| 117 | - 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
| 117 | + 'description' => __('The GMT date the invoice was last modified.', 'invoicing'), |
|
| 118 | 118 | 'type' => 'string', |
| 119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 119 | + 'context' => array('view', 'edit', 'embed'), |
|
| 120 | 120 | 'readonly' => true, |
| 121 | 121 | ), |
| 122 | 122 | |
| 123 | 123 | 'due_date' => array( |
| 124 | - 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
| 124 | + 'description' => __("The invoice's due date, in the site's timezone.", 'invoicing'), |
|
| 125 | 125 | 'type' => 'string', |
| 126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 126 | + 'context' => array('view', 'edit', 'embed'), |
|
| 127 | 127 | ), |
| 128 | 128 | |
| 129 | 129 | 'due_date_gmt' => array( |
| 130 | - 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
| 130 | + 'description' => __('The GMT date the invoice is/was due.', 'invoicing'), |
|
| 131 | 131 | 'type' => 'string', |
| 132 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 132 | + 'context' => array('view', 'edit', 'embed'), |
|
| 133 | 133 | 'readonly' => true, |
| 134 | 134 | ), |
| 135 | 135 | |
| 136 | 136 | 'completed_date' => array( |
| 137 | - 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
| 137 | + 'description' => __("The date the invoice was paid, in the site's timezone.", 'invoicing'), |
|
| 138 | 138 | 'type' => 'string', |
| 139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 139 | + 'context' => array('view', 'edit', 'embed'), |
|
| 140 | 140 | 'readonly' => true, |
| 141 | 141 | ), |
| 142 | 142 | |
| 143 | 143 | 'completed_date_gmt' => array( |
| 144 | - 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
| 144 | + 'description' => __('The GMT date the invoice was paid.', 'invoicing'), |
|
| 145 | 145 | 'type' => 'string', |
| 146 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 146 | + 'context' => array('view', 'edit', 'embed'), |
|
| 147 | 147 | 'readonly' => true, |
| 148 | 148 | ), |
| 149 | 149 | |
| 150 | 150 | 'total_discount' => array( |
| 151 | - 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
| 151 | + 'description' => __('Total discount amount for the invoice.', 'invoicing'), |
|
| 152 | 152 | 'type' => 'number', |
| 153 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 153 | + 'context' => array('view', 'edit', 'embed'), |
|
| 154 | 154 | 'readonly' => true, |
| 155 | 155 | ), |
| 156 | 156 | |
| 157 | 157 | 'total_tax' => array( |
| 158 | - 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
| 158 | + 'description' => __('Total tax amount for the invoice.', 'invoicing'), |
|
| 159 | 159 | 'type' => 'number', |
| 160 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 160 | + 'context' => array('view', 'edit', 'embed'), |
|
| 161 | 161 | 'readonly' => true, |
| 162 | 162 | ), |
| 163 | 163 | |
| 164 | 164 | 'total_fees' => array( |
| 165 | - 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
| 165 | + 'description' => __('Total fees amount for the invoice.', 'invoicing'), |
|
| 166 | 166 | 'type' => 'number', |
| 167 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 167 | + 'context' => array('view', 'edit', 'embed'), |
|
| 168 | 168 | 'readonly' => true, |
| 169 | 169 | ), |
| 170 | 170 | |
| 171 | 171 | 'subtotal' => array( |
| 172 | - 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
| 172 | + 'description' => __('Invoice subtotal.', 'invoicing'), |
|
| 173 | 173 | 'type' => 'number', |
| 174 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 174 | + 'context' => array('view', 'edit', 'embed'), |
|
| 175 | 175 | 'readonly' => true, |
| 176 | 176 | ), |
| 177 | 177 | |
| 178 | 178 | 'total' => array( |
| 179 | - 'description' => __( 'Grand total.', 'invoicing' ), |
|
| 179 | + 'description' => __('Grand total.', 'invoicing'), |
|
| 180 | 180 | 'type' => 'number', |
| 181 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 181 | + 'context' => array('view', 'edit', 'embed'), |
|
| 182 | 182 | 'readonly' => true, |
| 183 | 183 | ), |
| 184 | 184 | |
| 185 | 185 | 'initial_total' => array( |
| 186 | - 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
| 186 | + 'description' => __('Initial total (for recurring invoices).', 'invoicing'), |
|
| 187 | 187 | 'type' => 'number', |
| 188 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 188 | + 'context' => array('view', 'edit', 'embed'), |
|
| 189 | 189 | 'readonly' => true, |
| 190 | 190 | ), |
| 191 | 191 | |
| 192 | 192 | 'recurring_total' => array( |
| 193 | - 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
| 193 | + 'description' => __('Recurring total (for recurring invoices).', 'invoicing'), |
|
| 194 | 194 | 'type' => 'number', |
| 195 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 195 | + 'context' => array('view', 'edit', 'embed'), |
|
| 196 | 196 | 'readonly' => true, |
| 197 | 197 | ), |
| 198 | 198 | |
| 199 | 199 | 'totals' => array( |
| 200 | - 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
| 200 | + 'description' => __('Invoice totals.', 'invoicing'), |
|
| 201 | 201 | 'type' => 'object', |
| 202 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 202 | + 'context' => array('view', 'edit', 'embed'), |
|
| 203 | 203 | 'readonly' => true, |
| 204 | 204 | ), |
| 205 | 205 | |
| 206 | 206 | 'fees' => array( |
| 207 | - 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
| 207 | + 'description' => __('Invoice fees (Name => properties).', 'invoicing'), |
|
| 208 | 208 | 'type' => 'object', |
| 209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 209 | + 'context' => array('view', 'edit', 'embed'), |
|
| 210 | 210 | 'items' => array( |
| 211 | 211 | 'type' => 'object', |
| 212 | - 'required' => array( 'amount' ), |
|
| 212 | + 'required' => array('amount'), |
|
| 213 | 213 | 'properties' => array( |
| 214 | 214 | 'amount' => array( |
| 215 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 215 | + 'description' => __('Fee amount.', 'invoicing'), |
|
| 216 | 216 | 'type' => 'string', |
| 217 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 217 | + 'context' => array('view', 'edit', 'embed'), |
|
| 218 | 218 | ), |
| 219 | 219 | 'recurring' => array( |
| 220 | - 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
| 221 | - 'type' => array( 'boolean', 'integer' ), |
|
| 222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 220 | + 'description' => __('Whether this is a recurring or one-time fee.', 'invoicing'), |
|
| 221 | + 'type' => array('boolean', 'integer'), |
|
| 222 | + 'context' => array('view', 'edit', 'embed'), |
|
| 223 | 223 | ), |
| 224 | 224 | ), |
| 225 | 225 | ), |
| 226 | 226 | ), |
| 227 | 227 | |
| 228 | 228 | 'discounts' => array( |
| 229 | - 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
| 229 | + 'description' => __('Invoice discounts (Name => properties).', 'invoicing'), |
|
| 230 | 230 | 'type' => 'object', |
| 231 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 231 | + 'context' => array('view', 'edit', 'embed'), |
|
| 232 | 232 | 'items' => array( |
| 233 | 233 | 'type' => 'object', |
| 234 | - 'required' => array( 'amount' ), |
|
| 234 | + 'required' => array('amount'), |
|
| 235 | 235 | 'properties' => array( |
| 236 | 236 | 'amount' => array( |
| 237 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 237 | + 'description' => __('Fee amount.', 'invoicing'), |
|
| 238 | 238 | 'type' => 'string', |
| 239 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 239 | + 'context' => array('view', 'edit', 'embed'), |
|
| 240 | 240 | ), |
| 241 | 241 | 'recurring' => array( |
| 242 | - 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
| 243 | - 'type' => array( 'boolean', 'integer' ), |
|
| 244 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 242 | + 'description' => __('Whether this is a recurring or one-time discount.', 'invoicing'), |
|
| 243 | + 'type' => array('boolean', 'integer'), |
|
| 244 | + 'context' => array('view', 'edit', 'embed'), |
|
| 245 | 245 | ), |
| 246 | 246 | ), |
| 247 | 247 | ), |
| 248 | 248 | ), |
| 249 | 249 | |
| 250 | 250 | 'taxes' => array( |
| 251 | - 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
| 251 | + 'description' => __('Invoice taxes (Name => properties).', 'invoicing'), |
|
| 252 | 252 | 'type' => 'object', |
| 253 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 253 | + 'context' => array('view', 'edit', 'embed'), |
|
| 254 | 254 | 'items' => array( |
| 255 | 255 | 'type' => 'object', |
| 256 | - 'required' => array( 'amount' ), |
|
| 256 | + 'required' => array('amount'), |
|
| 257 | 257 | 'properties' => array( |
| 258 | 258 | 'amount' => array( |
| 259 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
| 259 | + 'description' => __('Fee amount.', 'invoicing'), |
|
| 260 | 260 | 'type' => 'string', |
| 261 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 261 | + 'context' => array('view', 'edit', 'embed'), |
|
| 262 | 262 | ), |
| 263 | 263 | 'recurring' => array( |
| 264 | - 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
| 265 | - 'type' => array( 'boolean', 'integer' ), |
|
| 266 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 264 | + 'description' => __('Whether this is a recurring or one-time tax.', 'invoicing'), |
|
| 265 | + 'type' => array('boolean', 'integer'), |
|
| 266 | + 'context' => array('view', 'edit', 'embed'), |
|
| 267 | 267 | ), |
| 268 | 268 | ), |
| 269 | 269 | ), |
| 270 | 270 | ), |
| 271 | 271 | |
| 272 | 272 | 'items' => array( |
| 273 | - 'description' => __( 'Invoice items.', 'invoicing' ), |
|
| 273 | + 'description' => __('Invoice items.', 'invoicing'), |
|
| 274 | 274 | 'type' => 'array', |
| 275 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 275 | + 'context' => array('view', 'edit', 'embed'), |
|
| 276 | 276 | 'items' => array( |
| 277 | 277 | 'type' => 'object', |
| 278 | - 'required' => array( 'item_id' ), |
|
| 278 | + 'required' => array('item_id'), |
|
| 279 | 279 | 'properties' => array( |
| 280 | 280 | 'item_id' => array( |
| 281 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
| 281 | + 'description' => __('Item ID.', 'invoicing'), |
|
| 282 | 282 | 'type' => 'integer', |
| 283 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 283 | + 'context' => array('view', 'edit', 'embed'), |
|
| 284 | 284 | ), |
| 285 | 285 | 'item_name' => array( |
| 286 | - 'description' => __( 'Item Name.', 'invoicing' ), |
|
| 286 | + 'description' => __('Item Name.', 'invoicing'), |
|
| 287 | 287 | 'type' => 'string', |
| 288 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 288 | + 'context' => array('view', 'edit', 'embed'), |
|
| 289 | 289 | ), |
| 290 | 290 | 'item_description' => array( |
| 291 | - 'description' => __( 'Item Description.', 'invoicing' ), |
|
| 291 | + 'description' => __('Item Description.', 'invoicing'), |
|
| 292 | 292 | 'type' => 'string', |
| 293 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 293 | + 'context' => array('view', 'edit', 'embed'), |
|
| 294 | 294 | ), |
| 295 | 295 | 'item_price' => array( |
| 296 | - 'description' => __( 'Item Price.', 'invoicing' ), |
|
| 296 | + 'description' => __('Item Price.', 'invoicing'), |
|
| 297 | 297 | 'type' => 'number', |
| 298 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 298 | + 'context' => array('view', 'edit', 'embed'), |
|
| 299 | 299 | ), |
| 300 | 300 | 'quantity' => array( |
| 301 | - 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
| 301 | + 'description' => __('Item Quantity.', 'invoicing'), |
|
| 302 | 302 | 'type' => 'number', |
| 303 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 303 | + 'context' => array('view', 'edit', 'embed'), |
|
| 304 | 304 | ), |
| 305 | 305 | 'subtotal' => array( |
| 306 | - 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
| 306 | + 'description' => __('Item Subtotal.', 'invoicing'), |
|
| 307 | 307 | 'type' => 'number', |
| 308 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 308 | + 'context' => array('view', 'edit', 'embed'), |
|
| 309 | 309 | 'readonly' => true, |
| 310 | 310 | ), |
| 311 | 311 | 'meta' => array( |
| 312 | - 'description' => __( 'Item Meta.', 'invoicing' ), |
|
| 312 | + 'description' => __('Item Meta.', 'invoicing'), |
|
| 313 | 313 | 'type' => 'object', |
| 314 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 314 | + 'context' => array('view', 'edit', 'embed'), |
|
| 315 | 315 | ), |
| 316 | 316 | ), |
| 317 | 317 | ), |
| 318 | 318 | ), |
| 319 | 319 | |
| 320 | 320 | 'mode' => array( |
| 321 | - 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
| 321 | + 'description' => __('The invoice transaction mode.', 'invoicing'), |
|
| 322 | 322 | 'type' => 'string', |
| 323 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 324 | - 'enum' => array( 'live', 'test' ), |
|
| 323 | + 'context' => array('view', 'edit', 'embed'), |
|
| 324 | + 'enum' => array('live', 'test'), |
|
| 325 | 325 | 'readonly' => true, |
| 326 | 326 | ), |
| 327 | 327 | |
| 328 | 328 | 'discount_code' => array( |
| 329 | - 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
| 329 | + 'description' => __('The discount code used on this invoice.', 'invoicing'), |
|
| 330 | 330 | 'type' => 'string', |
| 331 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 331 | + 'context' => array('view', 'edit', 'embed'), |
|
| 332 | 332 | ), |
| 333 | 333 | |
| 334 | 334 | 'gateway' => array( |
| 335 | - 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
| 335 | + 'description' => __('The gateway used to pay this invoice.', 'invoicing'), |
|
| 336 | 336 | 'type' => 'string', |
| 337 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 337 | + 'context' => array('view', 'edit', 'embed'), |
|
| 338 | 338 | ), |
| 339 | 339 | |
| 340 | 340 | 'gateway_title' => array( |
| 341 | - 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
| 341 | + 'description' => __('The title of the gateway used to pay this invoice.', 'invoicing'), |
|
| 342 | 342 | 'type' => 'string', |
| 343 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 343 | + 'context' => array('view', 'edit', 'embed'), |
|
| 344 | 344 | 'readonly' => true, |
| 345 | 345 | ), |
| 346 | 346 | |
| 347 | 347 | 'transaction_id' => array( |
| 348 | - 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
| 348 | + 'description' => __('The transaction id for this invoice.', 'invoicing'), |
|
| 349 | 349 | 'type' => 'string', |
| 350 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 350 | + 'context' => array('view', 'edit', 'embed'), |
|
| 351 | 351 | ), |
| 352 | 352 | |
| 353 | 353 | 'disable_taxes' => array( |
| 354 | - 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
| 354 | + 'description' => __('Whether or not taxes should be disabled for this invoice.', 'invoicing'), |
|
| 355 | 355 | 'type' => 'boolean ', |
| 356 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 356 | + 'context' => array('view', 'edit', 'embed'), |
|
| 357 | 357 | ), |
| 358 | 358 | |
| 359 | 359 | 'is_viewed' => array( |
| 360 | - 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
| 360 | + 'description' => __('Whether or not this invoice has been viewed by the user.', 'invoicing'), |
|
| 361 | 361 | 'type' => 'boolean ', |
| 362 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 362 | + 'context' => array('view', 'edit', 'embed'), |
|
| 363 | 363 | 'readonly' => true, |
| 364 | 364 | ), |
| 365 | 365 | |
| 366 | 366 | 'email_cc' => array( |
| 367 | - 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
| 367 | + 'description' => __('A comma separated list of other emails that should receive communications for this invoice.', 'invoicing'), |
|
| 368 | 368 | 'type' => 'string ', |
| 369 | - 'context' => array( 'view', 'edit' ), |
|
| 369 | + 'context' => array('view', 'edit'), |
|
| 370 | 370 | ), |
| 371 | 371 | |
| 372 | 372 | 'subscription_id' => array( |
| 373 | - 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
| 373 | + 'description' => __('The ID of the subscription associated with this invoice.', 'invoicing'), |
|
| 374 | 374 | 'type' => 'string ', |
| 375 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 375 | + 'context' => array('view', 'edit', 'embed'), |
|
| 376 | 376 | 'readonly' => true, |
| 377 | 377 | ), |
| 378 | 378 | |
| 379 | 379 | 'subscription_name' => array( |
| 380 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 380 | + 'description' => __('The name of the subscription associated with this invoice.', 'invoicing'), |
|
| 381 | 381 | 'type' => 'string ', |
| 382 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 382 | + 'context' => array('view', 'edit', 'embed'), |
|
| 383 | 383 | 'readonly' => true, |
| 384 | 384 | ), |
| 385 | 385 | |
| 386 | 386 | 'subscription_name' => array( |
| 387 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
| 387 | + 'description' => __('The name of the subscription associated with this invoice.', 'invoicing'), |
|
| 388 | 388 | 'type' => 'string ', |
| 389 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 389 | + 'context' => array('view', 'edit', 'embed'), |
|
| 390 | 390 | 'readonly' => true, |
| 391 | 391 | ), |
| 392 | 392 | |
| 393 | 393 | 'is_parent' => array( |
| 394 | - 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
| 394 | + 'description' => __('Whether or not this is a parent invoice.', 'invoicing'), |
|
| 395 | 395 | 'type' => 'boolean', |
| 396 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 396 | + 'context' => array('view', 'edit', 'embed'), |
|
| 397 | 397 | 'readonly' => true, |
| 398 | 398 | ), |
| 399 | 399 | |
| 400 | 400 | 'is_renewal' => array( |
| 401 | - 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
| 401 | + 'description' => __('Whether or not this is a renewal invoice.', 'invoicing'), |
|
| 402 | 402 | 'type' => 'boolean', |
| 403 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 403 | + 'context' => array('view', 'edit', 'embed'), |
|
| 404 | 404 | 'readonly' => true, |
| 405 | 405 | ), |
| 406 | 406 | |
| 407 | 407 | 'is_recurring' => array( |
| 408 | - 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
| 408 | + 'description' => __('Whether or not this is a recurring invoice.', 'invoicing'), |
|
| 409 | 409 | 'type' => 'boolean', |
| 410 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 410 | + 'context' => array('view', 'edit', 'embed'), |
|
| 411 | 411 | 'readonly' => true, |
| 412 | 412 | ), |
| 413 | 413 | |
| 414 | 414 | 'is_free' => array( |
| 415 | - 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
| 415 | + 'description' => __('Whether or not this invoice is free.', 'invoicing'), |
|
| 416 | 416 | 'type' => 'boolean', |
| 417 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 417 | + 'context' => array('view', 'edit', 'embed'), |
|
| 418 | 418 | 'readonly' => true, |
| 419 | 419 | ), |
| 420 | 420 | |
| 421 | 421 | 'is_paid' => array( |
| 422 | - 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
| 422 | + 'description' => __('Whether or not this invoice has been paid.', 'invoicing'), |
|
| 423 | 423 | 'type' => 'boolean', |
| 424 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 424 | + 'context' => array('view', 'edit', 'embed'), |
|
| 425 | 425 | 'readonly' => true, |
| 426 | 426 | ), |
| 427 | 427 | |
| 428 | 428 | 'needs_payment' => array( |
| 429 | - 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
| 429 | + 'description' => __('Whether or not this invoice needs payment.', 'invoicing'), |
|
| 430 | 430 | 'type' => 'boolean', |
| 431 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 431 | + 'context' => array('view', 'edit', 'embed'), |
|
| 432 | 432 | 'readonly' => true, |
| 433 | 433 | ), |
| 434 | 434 | |
| 435 | 435 | 'is_refunded' => array( |
| 436 | - 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
| 436 | + 'description' => __('Whether or not this invoice was refunded.', 'invoicing'), |
|
| 437 | 437 | 'type' => 'boolean', |
| 438 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 438 | + 'context' => array('view', 'edit', 'embed'), |
|
| 439 | 439 | 'readonly' => true, |
| 440 | 440 | ), |
| 441 | 441 | |
| 442 | 442 | 'is_due' => array( |
| 443 | - 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
| 443 | + 'description' => __('Whether or not this invoice is due.', 'invoicing'), |
|
| 444 | 444 | 'type' => 'boolean', |
| 445 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 445 | + 'context' => array('view', 'edit', 'embed'), |
|
| 446 | 446 | 'readonly' => true, |
| 447 | 447 | ), |
| 448 | 448 | |
| 449 | 449 | 'is_held' => array( |
| 450 | - 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
| 450 | + 'description' => __('Whether or not this invoice has been held for payment confirmation.', 'invoicing'), |
|
| 451 | 451 | 'type' => 'boolean', |
| 452 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 452 | + 'context' => array('view', 'edit', 'embed'), |
|
| 453 | 453 | 'readonly' => true, |
| 454 | 454 | ), |
| 455 | 455 | |
| 456 | 456 | 'is_draft' => array( |
| 457 | - 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
| 457 | + 'description' => __('Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing'), |
|
| 458 | 458 | 'type' => 'boolean', |
| 459 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 459 | + 'context' => array('view', 'edit', 'embed'), |
|
| 460 | 460 | 'readonly' => true, |
| 461 | 461 | ), |
| 462 | 462 | |
| 463 | 463 | 'path' => array( |
| 464 | - 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
| 464 | + 'description' => __('The invoice path/slug/name.', 'invoicing'), |
|
| 465 | 465 | 'type' => 'string', |
| 466 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 466 | + 'context' => array('view', 'edit', 'embed'), |
|
| 467 | 467 | 'readonly' => true, |
| 468 | 468 | ), |
| 469 | 469 | |
| 470 | 470 | 'description' => array( |
| 471 | - 'description' => __( 'The invoice description.', 'invoicing' ), |
|
| 471 | + 'description' => __('The invoice description.', 'invoicing'), |
|
| 472 | 472 | 'type' => 'string', |
| 473 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 473 | + 'context' => array('view', 'edit', 'embed'), |
|
| 474 | 474 | ), |
| 475 | 475 | |
| 476 | 476 | 'payment_form' => array( |
| 477 | - 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
| 477 | + 'description' => __('The id of the payment form used to pay for this invoice.', 'invoicing'), |
|
| 478 | 478 | 'type' => 'integer', |
| 479 | - 'context' => array( 'view', 'edit' ), |
|
| 479 | + 'context' => array('view', 'edit'), |
|
| 480 | 480 | 'readonly' => true, |
| 481 | 481 | ), |
| 482 | 482 | |
| 483 | 483 | 'submission_id' => array( |
| 484 | - 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
| 484 | + 'description' => __('A uniques ID of the submission details used to pay for this invoice.', 'invoicing'), |
|
| 485 | 485 | 'type' => 'string', |
| 486 | - 'context' => array( 'view', 'edit' ), |
|
| 486 | + 'context' => array('view', 'edit'), |
|
| 487 | 487 | 'readonly' => true, |
| 488 | 488 | ), |
| 489 | 489 | |
| 490 | 490 | 'customer_id' => array( |
| 491 | - 'description' => __( 'The customer id.', 'invoicing' ), |
|
| 491 | + 'description' => __('The customer id.', 'invoicing'), |
|
| 492 | 492 | 'type' => 'integer', |
| 493 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 493 | + 'context' => array('view', 'edit', 'embed'), |
|
| 494 | 494 | ), |
| 495 | 495 | |
| 496 | 496 | 'customer_ip' => array( |
| 497 | - 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
| 497 | + 'description' => __("The customer's ip address.", 'invoicing'), |
|
| 498 | 498 | 'type' => 'string', |
| 499 | 499 | 'format' => 'ip', |
| 500 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 500 | + 'context' => array('view', 'edit', 'embed'), |
|
| 501 | 501 | ), |
| 502 | 502 | |
| 503 | 503 | 'first_name' => array( |
| 504 | - 'description' => __( "The customer's first name.", 'invoicing' ), |
|
| 504 | + 'description' => __("The customer's first name.", 'invoicing'), |
|
| 505 | 505 | 'type' => 'string', |
| 506 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 506 | + 'context' => array('view', 'edit', 'embed'), |
|
| 507 | 507 | ), |
| 508 | 508 | |
| 509 | 509 | 'last_name' => array( |
| 510 | - 'description' => __( "The customer's last name.", 'invoicing' ), |
|
| 510 | + 'description' => __("The customer's last name.", 'invoicing'), |
|
| 511 | 511 | 'type' => 'string', |
| 512 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 512 | + 'context' => array('view', 'edit', 'embed'), |
|
| 513 | 513 | ), |
| 514 | 514 | |
| 515 | 515 | 'full_name' => array( |
| 516 | - 'description' => __( "The customer's full name.", 'invoicing' ), |
|
| 516 | + 'description' => __("The customer's full name.", 'invoicing'), |
|
| 517 | 517 | 'type' => 'string', |
| 518 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 518 | + 'context' => array('view', 'edit', 'embed'), |
|
| 519 | 519 | 'readonly' => true, |
| 520 | 520 | ), |
| 521 | 521 | |
| 522 | 522 | 'phone_number' => array( |
| 523 | - 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
| 523 | + 'description' => __("The customer's phone number.", 'invoicing'), |
|
| 524 | 524 | 'type' => 'string', |
| 525 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 525 | + 'context' => array('view', 'edit', 'embed'), |
|
| 526 | 526 | ), |
| 527 | 527 | |
| 528 | 528 | 'email_address' => array( |
| 529 | - 'description' => __( "The customer's email address.", 'invoicing' ), |
|
| 529 | + 'description' => __("The customer's email address.", 'invoicing'), |
|
| 530 | 530 | 'type' => 'string', |
| 531 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 531 | + 'context' => array('view', 'edit', 'embed'), |
|
| 532 | 532 | 'readonly' => true, |
| 533 | 533 | ), |
| 534 | 534 | |
| 535 | 535 | 'customer_country' => array( |
| 536 | - 'description' => __( "The customer's country.", 'invoicing' ), |
|
| 536 | + 'description' => __("The customer's country.", 'invoicing'), |
|
| 537 | 537 | 'type' => 'string', |
| 538 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 538 | + 'context' => array('view', 'edit', 'embed'), |
|
| 539 | 539 | 'default' => wpinv_get_default_country(), |
| 540 | 540 | ), |
| 541 | 541 | |
| 542 | 542 | 'customer_state' => array( |
| 543 | - 'description' => __( "The customer's state.", 'invoicing' ), |
|
| 543 | + 'description' => __("The customer's state.", 'invoicing'), |
|
| 544 | 544 | 'type' => 'string', |
| 545 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 545 | + 'context' => array('view', 'edit', 'embed'), |
|
| 546 | 546 | ), |
| 547 | 547 | |
| 548 | 548 | 'customer_city' => array( |
| 549 | - 'description' => __( "The customer's city.", 'invoicing' ), |
|
| 549 | + 'description' => __("The customer's city.", 'invoicing'), |
|
| 550 | 550 | 'type' => 'string', |
| 551 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 551 | + 'context' => array('view', 'edit', 'embed'), |
|
| 552 | 552 | ), |
| 553 | 553 | |
| 554 | 554 | 'customer_zip' => array( |
| 555 | - 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
| 555 | + 'description' => __("The customer's zip/postal code.", 'invoicing'), |
|
| 556 | 556 | 'type' => 'string', |
| 557 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 557 | + 'context' => array('view', 'edit', 'embed'), |
|
| 558 | 558 | ), |
| 559 | 559 | |
| 560 | 560 | 'customer_company' => array( |
| 561 | - 'description' => __( "The customer's company name.", 'invoicing' ), |
|
| 561 | + 'description' => __("The customer's company name.", 'invoicing'), |
|
| 562 | 562 | 'type' => 'string', |
| 563 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 563 | + 'context' => array('view', 'edit', 'embed'), |
|
| 564 | 564 | ), |
| 565 | 565 | |
| 566 | 566 | 'vat_number' => array( |
| 567 | - 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
| 567 | + 'description' => __("The customer's VAT number.", 'invoicing'), |
|
| 568 | 568 | 'type' => 'string', |
| 569 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 569 | + 'context' => array('view', 'edit', 'embed'), |
|
| 570 | 570 | ), |
| 571 | 571 | |
| 572 | 572 | 'vat_rate' => array( |
| 573 | - 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
| 573 | + 'description' => __("The customer's VAT rate.", 'invoicing'), |
|
| 574 | 574 | 'type' => 'number', |
| 575 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 575 | + 'context' => array('view', 'edit', 'embed'), |
|
| 576 | 576 | 'readonly' => true, |
| 577 | 577 | ), |
| 578 | 578 | |
| 579 | 579 | 'customer_address' => array( |
| 580 | - 'description' => __( "The customer's address.", 'invoicing' ), |
|
| 580 | + 'description' => __("The customer's address.", 'invoicing'), |
|
| 581 | 581 | 'type' => 'string', |
| 582 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 582 | + 'context' => array('view', 'edit', 'embed'), |
|
| 583 | 583 | ), |
| 584 | 584 | |
| 585 | 585 | 'address_confirmed' => array( |
| 586 | - 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
| 586 | + 'description' => __("Whether or not the customer's address is confirmed.", 'invoicing'), |
|
| 587 | 587 | 'type' => 'boolean', |
| 588 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 588 | + 'context' => array('view', 'edit', 'embed'), |
|
| 589 | 589 | ), |
| 590 | 590 | |
| 591 | 591 | 'meta_data' => array( |
| 592 | - 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
| 592 | + 'description' => __('Invoice meta data.', 'invoicing'), |
|
| 593 | 593 | 'type' => 'array', |
| 594 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 594 | + 'context' => array('view', 'edit', 'embed'), |
|
| 595 | 595 | 'items' => array( |
| 596 | 596 | 'type' => 'object', |
| 597 | 597 | 'properties' => array( |
| 598 | 598 | 'id' => array( |
| 599 | - 'description' => __( 'Meta ID.', 'invoicing' ), |
|
| 599 | + 'description' => __('Meta ID.', 'invoicing'), |
|
| 600 | 600 | 'type' => 'string', |
| 601 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 601 | + 'context' => array('view', 'edit', 'embed'), |
|
| 602 | 602 | ), |
| 603 | 603 | 'key' => array( |
| 604 | - 'description' => __( 'Meta key.', 'invoicing' ), |
|
| 604 | + 'description' => __('Meta key.', 'invoicing'), |
|
| 605 | 605 | 'type' => 'string', |
| 606 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 606 | + 'context' => array('view', 'edit', 'embed'), |
|
| 607 | 607 | ), |
| 608 | 608 | 'value' => array( |
| 609 | - 'description' => __( 'Meta Value.', 'invoicing' ), |
|
| 610 | - 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
| 611 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 609 | + 'description' => __('Meta Value.', 'invoicing'), |
|
| 610 | + 'type' => array('string', 'array', 'object', 'integer', 'null'), |
|
| 611 | + 'context' => array('view', 'edit', 'embed'), |
|
| 612 | 612 | ), |
| 613 | 613 | ), |
| 614 | 614 | ), |
| 615 | 615 | ), |
| 616 | 616 | |
| 617 | 617 | 'view_url' => array( |
| 618 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
| 618 | + 'description' => __('URL to the invoice.', 'invoicing'), |
|
| 619 | 619 | 'type' => 'string', |
| 620 | 620 | 'format' => 'uri', |
| 621 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 621 | + 'context' => array('view', 'edit', 'embed'), |
|
| 622 | 622 | 'readonly' => true, |
| 623 | 623 | ), |
| 624 | 624 | |
| 625 | 625 | 'checkout_payment_url' => array( |
| 626 | - 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
| 626 | + 'description' => __('URL to the invoice checkout page.', 'invoicing'), |
|
| 627 | 627 | 'type' => 'string', |
| 628 | 628 | 'format' => 'uri', |
| 629 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 629 | + 'context' => array('view', 'edit', 'embed'), |
|
| 630 | 630 | 'readonly' => true, |
| 631 | 631 | ), |
| 632 | 632 | |
| 633 | 633 | 'receipt_url' => array( |
| 634 | - 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
| 634 | + 'description' => __('URL to the invoice receipt page.', 'invoicing'), |
|
| 635 | 635 | 'type' => 'string', |
| 636 | 636 | 'format' => 'uri', |
| 637 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
| 637 | + 'context' => array('view', 'edit', 'embed'), |
|
| 638 | 638 | 'readonly' => true, |
| 639 | 639 | ), |
| 640 | 640 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
| 10 | 10 | class WPInv_Item extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'item'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'item'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'item'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'parent_id' => 0, |
|
| 34 | - 'status' => 'draft', |
|
| 35 | - 'version' => '', |
|
| 36 | - 'date_created' => null, |
|
| 27 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'parent_id' => 0, |
|
| 34 | + 'status' => 'draft', |
|
| 35 | + 'version' => '', |
|
| 36 | + 'date_created' => null, |
|
| 37 | 37 | 'date_modified' => null, |
| 38 | 38 | 'name' => '', |
| 39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Stores meta in cache for future reads. |
|
| 62 | - * |
|
| 63 | - * A group must be set to to enable caching. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $cache_group = 'getpaid_items'; |
|
| 61 | + * Stores meta in cache for future reads. |
|
| 62 | + * |
|
| 63 | + * A group must be set to to enable caching. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $cache_group = 'getpaid_items'; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
| 74 | 74 | protected $post = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | - * |
|
| 79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | - */ |
|
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 94 | - } else { |
|
| 95 | - $this->set_object_read( true ); |
|
| 96 | - } |
|
| 77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | + * |
|
| 79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | + */ |
|
| 81 | + public function __construct( $item = 0 ) { |
|
| 82 | + parent::__construct( $item ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | + $this->set_id( $item ); |
|
| 86 | + } elseif ( $item instanceof self ) { |
|
| 87 | + $this->set_id( $item->get_id() ); |
|
| 88 | + } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | + $this->set_id( $item->ID ); |
|
| 90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | + $this->set_id( $item_id ); |
|
| 92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | + $this->set_id( $item_id ); |
|
| 94 | + } else { |
|
| 95 | + $this->set_object_read( true ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 101 | + if ( $this->get_id() > 0 ) { |
|
| 102 | 102 | $this->post = get_post( $this->get_id() ); |
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read( $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Get parent item ID. |
|
| 126 | - * |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @param string $context View or edit context. |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 125 | + * Get parent item ID. |
|
| 126 | + * |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @param string $context View or edit context. |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function get_parent_id( $context = 'view' ) { |
|
| 132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | - * Get item status. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @param string $context View or edit context. |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 136 | + * Get item status. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @param string $context View or edit context. |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_status( $context = 'view' ) { |
|
| 143 | + return $this->get_prop( 'status', $context ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Get plugin version when the item was created. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * @param string $context View or edit context. |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 147 | + * Get plugin version when the item was created. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * @param string $context View or edit context. |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_version( $context = 'view' ) { |
|
| 154 | + return $this->get_prop( 'version', $context ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get date when the item was created. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.19 |
|
| 161 | - * @param string $context View or edit context. |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 158 | + * Get date when the item was created. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.19 |
|
| 161 | + * @param string $context View or edit context. |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_date_created( $context = 'view' ) { |
|
| 165 | + return $this->get_prop( 'date_created', $context ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Get GMT date when the item was created. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * @param string $context View or edit context. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 169 | + * Get GMT date when the item was created. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * @param string $context View or edit context. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | 176 | $date = $this->get_date_created( $context ); |
| 177 | 177 | |
| 178 | 178 | if ( $date ) { |
| 179 | 179 | $date = get_gmt_from_date( $date ); |
| 180 | 180 | } |
| 181 | - return $date; |
|
| 181 | + return $date; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Get date when the item was last modified. |
|
| 186 | - * |
|
| 187 | - * @since 1.0.19 |
|
| 188 | - * @param string $context View or edit context. |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 185 | + * Get date when the item was last modified. |
|
| 186 | + * |
|
| 187 | + * @since 1.0.19 |
|
| 188 | + * @param string $context View or edit context. |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function get_date_modified( $context = 'view' ) { |
|
| 192 | + return $this->get_prop( 'date_modified', $context ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Get GMT date when the item was last modified. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 196 | + * Get GMT date when the item was last modified. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | 203 | $date = $this->get_date_modified( $context ); |
| 204 | 204 | |
| 205 | 205 | if ( $date ) { |
| 206 | 206 | $date = get_gmt_from_date( $date ); |
| 207 | 207 | } |
| 208 | - return $date; |
|
| 208 | + return $date; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get the item name. |
|
| 213 | - * |
|
| 214 | - * @since 1.0.19 |
|
| 215 | - * @param string $context View or edit context. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 212 | + * Get the item name. |
|
| 213 | + * |
|
| 214 | + * @since 1.0.19 |
|
| 215 | + * @param string $context View or edit context. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function get_name( $context = 'view' ) { |
|
| 219 | + return $this->get_prop( 'name', $context ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Alias of self::get_name(). |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @param string $context View or edit context. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 223 | + * Alias of self::get_name(). |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @param string $context View or edit context. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function get_title( $context = 'view' ) { |
|
| 230 | + return $this->get_name( $context ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * Get the item description. |
|
| 235 | - * |
|
| 236 | - * @since 1.0.19 |
|
| 237 | - * @param string $context View or edit context. |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 234 | + * Get the item description. |
|
| 235 | + * |
|
| 236 | + * @since 1.0.19 |
|
| 237 | + * @param string $context View or edit context. |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_description( $context = 'view' ) { |
|
| 241 | + return $this->get_prop( 'description', $context ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Alias of self::get_description(). |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 245 | + * Alias of self::get_description(). |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_excerpt( $context = 'view' ) { |
|
| 252 | + return $this->get_description( $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Alias of self::get_description(). |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 256 | + * Alias of self::get_description(). |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_summary( $context = 'view' ) { |
|
| 263 | + return $this->get_description( $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get the owner of the item. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @param string $context View or edit context. |
|
| 271 | - * @return int |
|
| 272 | - */ |
|
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 275 | - } |
|
| 267 | + * Get the owner of the item. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @param string $context View or edit context. |
|
| 271 | + * @return int |
|
| 272 | + */ |
|
| 273 | + public function get_author( $context = 'view' ) { |
|
| 274 | + return (int) $this->get_prop( 'author', $context ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * Alias of self::get_author(). |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @param string $context View or edit context. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Get the price of the item. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return float |
|
| 294 | - */ |
|
| 295 | - public function get_price( $context = 'view' ) { |
|
| 277 | + /** |
|
| 278 | + * Alias of self::get_author(). |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @param string $context View or edit context. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + public function get_owner( $context = 'view' ) { |
|
| 285 | + return $this->get_author( $context ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Get the price of the item. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return float |
|
| 294 | + */ |
|
| 295 | + public function get_price( $context = 'view' ) { |
|
| 296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
| 297 | - } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Get the inital price of the item. |
|
| 301 | - * |
|
| 302 | - * @since 1.0.19 |
|
| 303 | - * @param string $context View or edit context. |
|
| 304 | - * @return float |
|
| 305 | - */ |
|
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 299 | + /** |
|
| 300 | + * Get the inital price of the item. |
|
| 301 | + * |
|
| 302 | + * @since 1.0.19 |
|
| 303 | + * @param string $context View or edit context. |
|
| 304 | + * @return float |
|
| 305 | + */ |
|
| 306 | + public function get_initial_price( $context = 'view' ) { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price( $context ); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 311 | - $price = 0; |
|
| 312 | - } |
|
| 310 | + if ( $this->has_free_trial() ) { |
|
| 311 | + $price = 0; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | - * Returns a formated price. |
|
| 319 | - * |
|
| 320 | - * @since 1.0.19 |
|
| 321 | - * @param string $context View or edit context. |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 318 | + * Returns a formated price. |
|
| 319 | + * |
|
| 320 | + * @since 1.0.19 |
|
| 321 | + * @param string $context View or edit context. |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | 324 | public function get_the_price() { |
| 325 | 325 | return wpinv_price( $this->get_price() ); |
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Returns the formated initial price. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param string $context View or edit context. |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Returns the formated initial price. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param string $context View or edit context. |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | 335 | public function get_the_initial_price() { |
| 336 | 336 | return wpinv_price( $this->get_initial_price() ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | - * Get the VAT rule of the item. |
|
| 341 | - * |
|
| 342 | - * @since 1.0.19 |
|
| 343 | - * @param string $context View or edit context. |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 340 | + * Get the VAT rule of the item. |
|
| 341 | + * |
|
| 342 | + * @since 1.0.19 |
|
| 343 | + * @param string $context View or edit context. |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function get_vat_rule( $context = 'view' ) { |
|
| 347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | - * Get the VAT class of the item. |
|
| 352 | - * |
|
| 353 | - * @since 1.0.19 |
|
| 354 | - * @param string $context View or edit context. |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 351 | + * Get the VAT class of the item. |
|
| 352 | + * |
|
| 353 | + * @since 1.0.19 |
|
| 354 | + * @param string $context View or edit context. |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + public function get_vat_class( $context = 'view' ) { |
|
| 358 | 358 | return $this->get_prop( 'vat_class', $context ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Get the type of the item. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param string $context View or edit context. |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_type( $context = 'view' ) { |
|
| 362 | + * Get the type of the item. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param string $context View or edit context. |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_type( $context = 'view' ) { |
|
| 369 | 369 | return $this->get_prop( 'type', $context ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Get the custom id of the item. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 373 | + * Get the custom id of the item. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_custom_id( $context = 'view' ) { |
|
| 380 | 380 | return $this->get_prop( 'custom_id', $context ); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | - * Get the custom name of the item. |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 384 | + * Get the custom name of the item. |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_custom_name( $context = 'view' ) { |
|
| 391 | 391 | return $this->get_prop( 'custom_name', $context ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Get the custom singular name of the item. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 395 | + * Get the custom singular name of the item. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Checks if an item is editable.. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - * @param string $context View or edit context. |
|
| 410 | - * @return int |
|
| 411 | - */ |
|
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 406 | + * Checks if an item is editable.. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + * @param string $context View or edit context. |
|
| 410 | + * @return int |
|
| 411 | + */ |
|
| 412 | + public function get_is_editable( $context = 'view' ) { |
|
| 413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | - * Alias of self::get_is_editable(). |
|
| 418 | - * |
|
| 419 | - * @since 1.0.19 |
|
| 420 | - * @param string $context View or edit context. |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 417 | + * Alias of self::get_is_editable(). |
|
| 418 | + * |
|
| 419 | + * @since 1.0.19 |
|
| 420 | + * @param string $context View or edit context. |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + public function get_editable( $context = 'view' ) { |
|
| 424 | + return $this->get_is_editable( $context ); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Checks if dynamic pricing is enabled. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return int |
|
| 433 | - */ |
|
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 428 | + * Checks if dynamic pricing is enabled. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return int |
|
| 433 | + */ |
|
| 434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return float |
|
| 444 | - */ |
|
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return float |
|
| 444 | + */ |
|
| 445 | + public function get_minimum_price( $context = 'view' ) { |
|
| 446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Checks if this is a recurring item. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return int |
|
| 455 | - */ |
|
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 450 | + * Checks if this is a recurring item. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return int |
|
| 455 | + */ |
|
| 456 | + public function get_is_recurring( $context = 'view' ) { |
|
| 457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - /** |
|
| 461 | - * Get the recurring price of the item. |
|
| 462 | - * |
|
| 463 | - * @since 1.0.19 |
|
| 464 | - * @param string $context View or edit context. |
|
| 465 | - * @return float |
|
| 466 | - */ |
|
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 460 | + /** |
|
| 461 | + * Get the recurring price of the item. |
|
| 462 | + * |
|
| 463 | + * @since 1.0.19 |
|
| 464 | + * @param string $context View or edit context. |
|
| 465 | + * @return float |
|
| 466 | + */ |
|
| 467 | + public function get_recurring_price( $context = 'view' ) { |
|
| 468 | + $price = $this->get_price( $context ); |
|
| 469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Get the formatted recurring price of the item. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - * @param string $context View or edit context. |
|
| 477 | - * @return string |
|
| 478 | - */ |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Get the formatted recurring price of the item. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + * @param string $context View or edit context. |
|
| 477 | + * @return string |
|
| 478 | + */ |
|
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | 480 | return wpinv_price( $this->get_recurring_price() ); |
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get the first renewal date (in timestamps) of the item. |
|
| 485 | - * |
|
| 486 | - * @since 1.0.19 |
|
| 487 | - * @return int |
|
| 488 | - */ |
|
| 489 | - public function get_first_renewal_date() { |
|
| 490 | - |
|
| 491 | - $periods = array( |
|
| 492 | - 'D' => 'days', |
|
| 493 | - 'W' => 'weeks', |
|
| 494 | - 'M' => 'months', |
|
| 495 | - 'Y' => 'years', |
|
| 496 | - ); |
|
| 497 | - |
|
| 498 | - $period = $this->get_recurring_period(); |
|
| 499 | - $interval = $this->get_recurring_interval(); |
|
| 500 | - |
|
| 501 | - if ( $this->has_free_trial() ) { |
|
| 502 | - $period = $this->get_trial_period(); |
|
| 503 | - $interval = $this->get_trial_interval(); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get the first renewal date (in timestamps) of the item. |
|
| 485 | + * |
|
| 486 | + * @since 1.0.19 |
|
| 487 | + * @return int |
|
| 488 | + */ |
|
| 489 | + public function get_first_renewal_date() { |
|
| 490 | + |
|
| 491 | + $periods = array( |
|
| 492 | + 'D' => 'days', |
|
| 493 | + 'W' => 'weeks', |
|
| 494 | + 'M' => 'months', |
|
| 495 | + 'Y' => 'years', |
|
| 496 | + ); |
|
| 497 | + |
|
| 498 | + $period = $this->get_recurring_period(); |
|
| 499 | + $interval = $this->get_recurring_interval(); |
|
| 500 | + |
|
| 501 | + if ( $this->has_free_trial() ) { |
|
| 502 | + $period = $this->get_trial_period(); |
|
| 503 | + $interval = $this->get_trial_interval(); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $period = $periods[ $period ]; |
|
| 507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
| 513 | - * Get the recurring period. |
|
| 514 | - * |
|
| 515 | - * @since 1.0.19 |
|
| 516 | - * @param bool $full Return abbreviation or in full. |
|
| 517 | - * @return string |
|
| 518 | - */ |
|
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 513 | + * Get the recurring period. |
|
| 514 | + * |
|
| 515 | + * @since 1.0.19 |
|
| 516 | + * @param bool $full Return abbreviation or in full. |
|
| 517 | + * @return string |
|
| 518 | + */ |
|
| 519 | + public function get_recurring_period( $full = false ) { |
|
| 520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
| 521 | 521 | |
| 522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
| 530 | - * Get the recurring interval. |
|
| 531 | - * |
|
| 532 | - * @since 1.0.19 |
|
| 533 | - * @param string $context View or edit context. |
|
| 534 | - * @return int |
|
| 535 | - */ |
|
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 530 | + * Get the recurring interval. |
|
| 531 | + * |
|
| 532 | + * @since 1.0.19 |
|
| 533 | + * @param string $context View or edit context. |
|
| 534 | + * @return int |
|
| 535 | + */ |
|
| 536 | + public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 538 | 538 | |
| 539 | - if ( $interval < 1 ) { |
|
| 540 | - $interval = 1; |
|
| 541 | - } |
|
| 539 | + if ( $interval < 1 ) { |
|
| 540 | + $interval = 1; |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | 543 | return $interval; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Get the recurring limit. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param string $context View or edit context. |
|
| 551 | - * @return int |
|
| 552 | - */ |
|
| 553 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 547 | + * Get the recurring limit. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param string $context View or edit context. |
|
| 551 | + * @return int |
|
| 552 | + */ |
|
| 553 | + public function get_recurring_limit( $context = 'view' ) { |
|
| 554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
| 558 | - * Checks if we have a free trial. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param string $context View or edit context. |
|
| 562 | - * @return int |
|
| 563 | - */ |
|
| 564 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 558 | + * Checks if we have a free trial. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param string $context View or edit context. |
|
| 562 | + * @return int |
|
| 563 | + */ |
|
| 564 | + public function get_is_free_trial( $context = 'view' ) { |
|
| 565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
| 569 | - * Alias for self::get_is_free_trial(). |
|
| 570 | - * |
|
| 571 | - * @since 1.0.19 |
|
| 572 | - * @param string $context View or edit context. |
|
| 573 | - * @return int |
|
| 574 | - */ |
|
| 575 | - public function get_free_trial( $context = 'view' ) { |
|
| 569 | + * Alias for self::get_is_free_trial(). |
|
| 570 | + * |
|
| 571 | + * @since 1.0.19 |
|
| 572 | + * @param string $context View or edit context. |
|
| 573 | + * @return int |
|
| 574 | + */ |
|
| 575 | + public function get_free_trial( $context = 'view' ) { |
|
| 576 | 576 | return $this->get_is_free_trial( $context ); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | - * Get the trial period. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - * @param bool $full Return abbreviation or in full. |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function get_trial_period( $full = false ) { |
|
| 580 | + * Get the trial period. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + * @param bool $full Return abbreviation or in full. |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function get_trial_period( $full = false ) { |
|
| 587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
| 588 | 588 | |
| 589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
| 597 | - * Get the trial interval. |
|
| 598 | - * |
|
| 599 | - * @since 1.0.19 |
|
| 600 | - * @param string $context View or edit context. |
|
| 601 | - * @return int |
|
| 602 | - */ |
|
| 603 | - public function get_trial_interval( $context = 'view' ) { |
|
| 597 | + * Get the trial interval. |
|
| 598 | + * |
|
| 599 | + * @since 1.0.19 |
|
| 600 | + * @param string $context View or edit context. |
|
| 601 | + * @return int |
|
| 602 | + */ |
|
| 603 | + public function get_trial_interval( $context = 'view' ) { |
|
| 604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
| 605 | - } |
|
| 605 | + } |
|
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * Get the item's edit url. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @return string |
|
| 612 | - */ |
|
| 613 | - public function get_edit_url() { |
|
| 607 | + /** |
|
| 608 | + * Get the item's edit url. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @return string |
|
| 612 | + */ |
|
| 613 | + public function get_edit_url() { |
|
| 614 | 614 | return get_edit_post_link( $this->get_id() ); |
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Given an item's name/custom id, it returns its id. |
|
| 619 | - * |
|
| 620 | - * |
|
| 621 | - * @static |
|
| 622 | - * @param string $value The item name or custom id. |
|
| 623 | - * @param string $field Either name or custom_id. |
|
| 624 | - * @param string $type in case you need to search for a given type. |
|
| 625 | - * @since 1.0.15 |
|
| 626 | - * @return int |
|
| 627 | - */ |
|
| 628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 629 | - |
|
| 630 | - // Trim the value. |
|
| 631 | - $value = sanitize_text_field( $value ); |
|
| 632 | - if ( empty( $value ) ) { |
|
| 633 | - return 0; |
|
| 634 | - } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Given an item's name/custom id, it returns its id. |
|
| 619 | + * |
|
| 620 | + * |
|
| 621 | + * @static |
|
| 622 | + * @param string $value The item name or custom id. |
|
| 623 | + * @param string $field Either name or custom_id. |
|
| 624 | + * @param string $type in case you need to search for a given type. |
|
| 625 | + * @since 1.0.15 |
|
| 626 | + * @return int |
|
| 627 | + */ |
|
| 628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 629 | + |
|
| 630 | + // Trim the value. |
|
| 631 | + $value = sanitize_text_field( $value ); |
|
| 632 | + if ( empty( $value ) ) { |
|
| 633 | + return 0; |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | 636 | // Valid fields. |
| 637 | 637 | $fields = array( 'custom_id', 'name', 'slug' ); |
| 638 | 638 | |
| 639 | - // Ensure a field has been passed. |
|
| 640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 641 | - return 0; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ( $field == 'name' ) { |
|
| 645 | - $field = 'slug'; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // Maybe retrieve from the cache. |
|
| 649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 650 | - if ( ! empty( $item_id ) ) { |
|
| 651 | - return $item_id; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - // Fetch from the db. |
|
| 655 | - $items = array(); |
|
| 656 | - if ( $field == 'slug' ) { |
|
| 657 | - $items = get_posts( |
|
| 658 | - array( |
|
| 659 | - 'post_type' => 'wpi_item', |
|
| 660 | - 'name' => $value, |
|
| 661 | - 'posts_per_page' => 1, |
|
| 662 | - 'post_status' => 'any', |
|
| 663 | - ) |
|
| 664 | - ); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - if ( $field =='custom_id' ) { |
|
| 668 | - $items = get_posts( |
|
| 669 | - array( |
|
| 670 | - 'post_type' => 'wpi_item', |
|
| 671 | - 'posts_per_page' => 1, |
|
| 672 | - 'post_status' => 'any', |
|
| 673 | - 'meta_query' => array( |
|
| 674 | - array( |
|
| 675 | - 'key' => '_wpinv_type', |
|
| 676 | - 'value' => $type, |
|
| 677 | - ), |
|
| 678 | - array( |
|
| 679 | - 'key' => '_wpinv_custom_id', |
|
| 680 | - 'value' => $value, |
|
| 681 | - ) |
|
| 682 | - ) |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if ( empty( $items ) ) { |
|
| 688 | - return 0; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - // Update the cache with our data |
|
| 692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 693 | - |
|
| 694 | - return $items[0]->ID; |
|
| 639 | + // Ensure a field has been passed. |
|
| 640 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 641 | + return 0; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ( $field == 'name' ) { |
|
| 645 | + $field = 'slug'; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + // Maybe retrieve from the cache. |
|
| 649 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 650 | + if ( ! empty( $item_id ) ) { |
|
| 651 | + return $item_id; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + // Fetch from the db. |
|
| 655 | + $items = array(); |
|
| 656 | + if ( $field == 'slug' ) { |
|
| 657 | + $items = get_posts( |
|
| 658 | + array( |
|
| 659 | + 'post_type' => 'wpi_item', |
|
| 660 | + 'name' => $value, |
|
| 661 | + 'posts_per_page' => 1, |
|
| 662 | + 'post_status' => 'any', |
|
| 663 | + ) |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + if ( $field =='custom_id' ) { |
|
| 668 | + $items = get_posts( |
|
| 669 | + array( |
|
| 670 | + 'post_type' => 'wpi_item', |
|
| 671 | + 'posts_per_page' => 1, |
|
| 672 | + 'post_status' => 'any', |
|
| 673 | + 'meta_query' => array( |
|
| 674 | + array( |
|
| 675 | + 'key' => '_wpinv_type', |
|
| 676 | + 'value' => $type, |
|
| 677 | + ), |
|
| 678 | + array( |
|
| 679 | + 'key' => '_wpinv_custom_id', |
|
| 680 | + 'value' => $value, |
|
| 681 | + ) |
|
| 682 | + ) |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if ( empty( $items ) ) { |
|
| 688 | + return 0; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + // Update the cache with our data |
|
| 692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 693 | + |
|
| 694 | + return $items[0]->ID; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
| 724 | 724 | */ |
| 725 | 725 | |
| 726 | 726 | /** |
| 727 | - * Set parent order ID. |
|
| 728 | - * |
|
| 729 | - * @since 1.0.19 |
|
| 730 | - */ |
|
| 731 | - public function set_parent_id( $value ) { |
|
| 732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 733 | - return; |
|
| 734 | - } |
|
| 735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Sets item status. |
|
| 740 | - * |
|
| 741 | - * @since 1.0.19 |
|
| 742 | - * @param string $status New status. |
|
| 743 | - * @return array details of change. |
|
| 744 | - */ |
|
| 745 | - public function set_status( $status ) { |
|
| 727 | + * Set parent order ID. |
|
| 728 | + * |
|
| 729 | + * @since 1.0.19 |
|
| 730 | + */ |
|
| 731 | + public function set_parent_id( $value ) { |
|
| 732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 733 | + return; |
|
| 734 | + } |
|
| 735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Sets item status. |
|
| 740 | + * |
|
| 741 | + * @since 1.0.19 |
|
| 742 | + * @param string $status New status. |
|
| 743 | + * @return array details of change. |
|
| 744 | + */ |
|
| 745 | + public function set_status( $status ) { |
|
| 746 | 746 | $old_status = $this->get_status(); |
| 747 | 747 | |
| 748 | 748 | $this->set_prop( 'status', $status ); |
| 749 | 749 | |
| 750 | - return array( |
|
| 751 | - 'from' => $old_status, |
|
| 752 | - 'to' => $status, |
|
| 753 | - ); |
|
| 750 | + return array( |
|
| 751 | + 'from' => $old_status, |
|
| 752 | + 'to' => $status, |
|
| 753 | + ); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
| 757 | - * Set plugin version when the item was created. |
|
| 758 | - * |
|
| 759 | - * @since 1.0.19 |
|
| 760 | - */ |
|
| 761 | - public function set_version( $value ) { |
|
| 762 | - $this->set_prop( 'version', $value ); |
|
| 757 | + * Set plugin version when the item was created. |
|
| 758 | + * |
|
| 759 | + * @since 1.0.19 |
|
| 760 | + */ |
|
| 761 | + public function set_version( $value ) { |
|
| 762 | + $this->set_prop( 'version', $value ); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
| 766 | - * Set date when the item was created. |
|
| 767 | - * |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - * @param string $value Value to set. |
|
| 766 | + * Set date when the item was created. |
|
| 767 | + * |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + * @param string $value Value to set. |
|
| 770 | 770 | * @return bool Whether or not the date was set. |
| 771 | - */ |
|
| 772 | - public function set_date_created( $value ) { |
|
| 771 | + */ |
|
| 772 | + public function set_date_created( $value ) { |
|
| 773 | 773 | $date = strtotime( $value ); |
| 774 | 774 | |
| 775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | - * Set date when the item was last modified. |
|
| 786 | - * |
|
| 787 | - * @since 1.0.19 |
|
| 788 | - * @param string $value Value to set. |
|
| 785 | + * Set date when the item was last modified. |
|
| 786 | + * |
|
| 787 | + * @since 1.0.19 |
|
| 788 | + * @param string $value Value to set. |
|
| 789 | 789 | * @return bool Whether or not the date was set. |
| 790 | - */ |
|
| 791 | - public function set_date_modified( $value ) { |
|
| 790 | + */ |
|
| 791 | + public function set_date_modified( $value ) { |
|
| 792 | 792 | $date = strtotime( $value ); |
| 793 | 793 | |
| 794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | - * Set the item name. |
|
| 805 | - * |
|
| 806 | - * @since 1.0.19 |
|
| 807 | - * @param string $value New name. |
|
| 808 | - */ |
|
| 809 | - public function set_name( $value ) { |
|
| 804 | + * Set the item name. |
|
| 805 | + * |
|
| 806 | + * @since 1.0.19 |
|
| 807 | + * @param string $value New name. |
|
| 808 | + */ |
|
| 809 | + public function set_name( $value ) { |
|
| 810 | 810 | $name = sanitize_text_field( $value ); |
| 811 | - $this->set_prop( 'name', $name ); |
|
| 811 | + $this->set_prop( 'name', $name ); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
| 815 | - * Alias of self::set_name(). |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - * @param string $value New name. |
|
| 819 | - */ |
|
| 820 | - public function set_title( $value ) { |
|
| 821 | - $this->set_name( $value ); |
|
| 815 | + * Alias of self::set_name(). |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + * @param string $value New name. |
|
| 819 | + */ |
|
| 820 | + public function set_title( $value ) { |
|
| 821 | + $this->set_name( $value ); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
| 825 | - * Set the item description. |
|
| 826 | - * |
|
| 827 | - * @since 1.0.19 |
|
| 828 | - * @param string $value New description. |
|
| 829 | - */ |
|
| 830 | - public function set_description( $value ) { |
|
| 831 | - $description = wp_kses_post( $value ); |
|
| 832 | - return $this->set_prop( 'description', $description ); |
|
| 825 | + * Set the item description. |
|
| 826 | + * |
|
| 827 | + * @since 1.0.19 |
|
| 828 | + * @param string $value New description. |
|
| 829 | + */ |
|
| 830 | + public function set_description( $value ) { |
|
| 831 | + $description = wp_kses_post( $value ); |
|
| 832 | + return $this->set_prop( 'description', $description ); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
| 836 | - * Alias of self::set_description(). |
|
| 837 | - * |
|
| 838 | - * @since 1.0.19 |
|
| 839 | - * @param string $value New description. |
|
| 840 | - */ |
|
| 841 | - public function set_excerpt( $value ) { |
|
| 842 | - $this->set_description( $value ); |
|
| 836 | + * Alias of self::set_description(). |
|
| 837 | + * |
|
| 838 | + * @since 1.0.19 |
|
| 839 | + * @param string $value New description. |
|
| 840 | + */ |
|
| 841 | + public function set_excerpt( $value ) { |
|
| 842 | + $this->set_description( $value ); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
| 846 | - * Alias of self::set_description(). |
|
| 847 | - * |
|
| 848 | - * @since 1.0.19 |
|
| 849 | - * @param string $value New description. |
|
| 850 | - */ |
|
| 851 | - public function set_summary( $value ) { |
|
| 852 | - $this->set_description( $value ); |
|
| 846 | + * Alias of self::set_description(). |
|
| 847 | + * |
|
| 848 | + * @since 1.0.19 |
|
| 849 | + * @param string $value New description. |
|
| 850 | + */ |
|
| 851 | + public function set_summary( $value ) { |
|
| 852 | + $this->set_description( $value ); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
| 856 | - * Set the owner of the item. |
|
| 857 | - * |
|
| 858 | - * @since 1.0.19 |
|
| 859 | - * @param int $value New author. |
|
| 860 | - */ |
|
| 861 | - public function set_author( $value ) { |
|
| 862 | - $this->set_prop( 'author', (int) $value ); |
|
| 863 | - } |
|
| 856 | + * Set the owner of the item. |
|
| 857 | + * |
|
| 858 | + * @since 1.0.19 |
|
| 859 | + * @param int $value New author. |
|
| 860 | + */ |
|
| 861 | + public function set_author( $value ) { |
|
| 862 | + $this->set_prop( 'author', (int) $value ); |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - /** |
|
| 866 | - * Alias of self::set_author(). |
|
| 867 | - * |
|
| 868 | - * @since 1.0.19 |
|
| 869 | - * @param int $value New author. |
|
| 870 | - */ |
|
| 871 | - public function set_owner( $value ) { |
|
| 872 | - $this->set_author( $value ); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Set the price of the item. |
|
| 877 | - * |
|
| 878 | - * @since 1.0.19 |
|
| 879 | - * @param float $value New price. |
|
| 880 | - */ |
|
| 881 | - public function set_price( $value ) { |
|
| 865 | + /** |
|
| 866 | + * Alias of self::set_author(). |
|
| 867 | + * |
|
| 868 | + * @since 1.0.19 |
|
| 869 | + * @param int $value New author. |
|
| 870 | + */ |
|
| 871 | + public function set_owner( $value ) { |
|
| 872 | + $this->set_author( $value ); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Set the price of the item. |
|
| 877 | + * |
|
| 878 | + * @since 1.0.19 |
|
| 879 | + * @param float $value New price. |
|
| 880 | + */ |
|
| 881 | + public function set_price( $value ) { |
|
| 882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /** |
| 886 | - * Set the VAT rule of the item. |
|
| 887 | - * |
|
| 888 | - * @since 1.0.19 |
|
| 889 | - * @param string $value new rule. |
|
| 890 | - */ |
|
| 891 | - public function set_vat_rule( $value ) { |
|
| 886 | + * Set the VAT rule of the item. |
|
| 887 | + * |
|
| 888 | + * @since 1.0.19 |
|
| 889 | + * @param string $value new rule. |
|
| 890 | + */ |
|
| 891 | + public function set_vat_rule( $value ) { |
|
| 892 | 892 | $this->set_prop( 'vat_rule', $value ); |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
| 896 | - * Set the VAT class of the item. |
|
| 897 | - * |
|
| 898 | - * @since 1.0.19 |
|
| 899 | - * @param string $value new class. |
|
| 900 | - */ |
|
| 901 | - public function set_vat_class( $value ) { |
|
| 896 | + * Set the VAT class of the item. |
|
| 897 | + * |
|
| 898 | + * @since 1.0.19 |
|
| 899 | + * @param string $value new class. |
|
| 900 | + */ |
|
| 901 | + public function set_vat_class( $value ) { |
|
| 902 | 902 | $this->set_prop( 'vat_class', $value ); |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
| 906 | - * Set the type of the item. |
|
| 907 | - * |
|
| 908 | - * @since 1.0.19 |
|
| 909 | - * @param string $value new item type. |
|
| 910 | - * @return string |
|
| 911 | - */ |
|
| 912 | - public function set_type( $value ) { |
|
| 906 | + * Set the type of the item. |
|
| 907 | + * |
|
| 908 | + * @since 1.0.19 |
|
| 909 | + * @param string $value new item type. |
|
| 910 | + * @return string |
|
| 911 | + */ |
|
| 912 | + public function set_type( $value ) { |
|
| 913 | 913 | |
| 914 | 914 | if ( empty( $value ) ) { |
| 915 | 915 | $value = 'custom'; |
@@ -919,132 +919,132 @@ discard block |
||
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /** |
| 922 | - * Set the custom id of the item. |
|
| 923 | - * |
|
| 924 | - * @since 1.0.19 |
|
| 925 | - * @param string $value new custom id. |
|
| 926 | - */ |
|
| 927 | - public function set_custom_id( $value ) { |
|
| 922 | + * Set the custom id of the item. |
|
| 923 | + * |
|
| 924 | + * @since 1.0.19 |
|
| 925 | + * @param string $value new custom id. |
|
| 926 | + */ |
|
| 927 | + public function set_custom_id( $value ) { |
|
| 928 | 928 | $this->set_prop( 'custom_id', $value ); |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | - * Set the custom name of the item. |
|
| 933 | - * |
|
| 934 | - * @since 1.0.19 |
|
| 935 | - * @param string $value new custom name. |
|
| 936 | - */ |
|
| 937 | - public function set_custom_name( $value ) { |
|
| 932 | + * Set the custom name of the item. |
|
| 933 | + * |
|
| 934 | + * @since 1.0.19 |
|
| 935 | + * @param string $value new custom name. |
|
| 936 | + */ |
|
| 937 | + public function set_custom_name( $value ) { |
|
| 938 | 938 | $this->set_prop( 'custom_name', $value ); |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * Set the custom singular name of the item. |
|
| 943 | - * |
|
| 944 | - * @since 1.0.19 |
|
| 945 | - * @param string $value new custom singular name. |
|
| 946 | - */ |
|
| 947 | - public function set_custom_singular_name( $value ) { |
|
| 942 | + * Set the custom singular name of the item. |
|
| 943 | + * |
|
| 944 | + * @since 1.0.19 |
|
| 945 | + * @param string $value new custom singular name. |
|
| 946 | + */ |
|
| 947 | + public function set_custom_singular_name( $value ) { |
|
| 948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
| 952 | - * Sets if an item is editable.. |
|
| 953 | - * |
|
| 954 | - * @since 1.0.19 |
|
| 955 | - * @param int|bool $value whether or not the item is editable. |
|
| 956 | - */ |
|
| 957 | - public function set_is_editable( $value ) { |
|
| 958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 952 | + * Sets if an item is editable.. |
|
| 953 | + * |
|
| 954 | + * @since 1.0.19 |
|
| 955 | + * @param int|bool $value whether or not the item is editable. |
|
| 956 | + */ |
|
| 957 | + public function set_is_editable( $value ) { |
|
| 958 | + $this->set_prop( 'is_editable', (int) $value ); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
| 962 | - * Sets if dynamic pricing is enabled. |
|
| 963 | - * |
|
| 964 | - * @since 1.0.19 |
|
| 965 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 966 | - */ |
|
| 967 | - public function set_is_dynamic_pricing( $value ) { |
|
| 962 | + * Sets if dynamic pricing is enabled. |
|
| 963 | + * |
|
| 964 | + * @since 1.0.19 |
|
| 965 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 966 | + */ |
|
| 967 | + public function set_is_dynamic_pricing( $value ) { |
|
| 968 | 968 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
| 972 | - * Sets the minimum price if dynamic pricing is enabled. |
|
| 973 | - * |
|
| 974 | - * @since 1.0.19 |
|
| 975 | - * @param float $value minimum price. |
|
| 976 | - */ |
|
| 977 | - public function set_minimum_price( $value ) { |
|
| 972 | + * Sets the minimum price if dynamic pricing is enabled. |
|
| 973 | + * |
|
| 974 | + * @since 1.0.19 |
|
| 975 | + * @param float $value minimum price. |
|
| 976 | + */ |
|
| 977 | + public function set_minimum_price( $value ) { |
|
| 978 | 978 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
| 982 | - * Sets if this is a recurring item. |
|
| 983 | - * |
|
| 984 | - * @since 1.0.19 |
|
| 985 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 986 | - */ |
|
| 987 | - public function set_is_recurring( $value ) { |
|
| 982 | + * Sets if this is a recurring item. |
|
| 983 | + * |
|
| 984 | + * @since 1.0.19 |
|
| 985 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 986 | + */ |
|
| 987 | + public function set_is_recurring( $value ) { |
|
| 988 | 988 | $this->set_prop( 'is_recurring', (int) $value ); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
| 992 | - * Set the recurring period. |
|
| 993 | - * |
|
| 994 | - * @since 1.0.19 |
|
| 995 | - * @param string $value new period. |
|
| 996 | - */ |
|
| 997 | - public function set_recurring_period( $value ) { |
|
| 992 | + * Set the recurring period. |
|
| 993 | + * |
|
| 994 | + * @since 1.0.19 |
|
| 995 | + * @param string $value new period. |
|
| 996 | + */ |
|
| 997 | + public function set_recurring_period( $value ) { |
|
| 998 | 998 | $this->set_prop( 'recurring_period', $value ); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
| 1002 | - * Set the recurring interval. |
|
| 1003 | - * |
|
| 1004 | - * @since 1.0.19 |
|
| 1005 | - * @param int $value recurring interval. |
|
| 1006 | - */ |
|
| 1007 | - public function set_recurring_interval( $value ) { |
|
| 1002 | + * Set the recurring interval. |
|
| 1003 | + * |
|
| 1004 | + * @since 1.0.19 |
|
| 1005 | + * @param int $value recurring interval. |
|
| 1006 | + */ |
|
| 1007 | + public function set_recurring_interval( $value ) { |
|
| 1008 | 1008 | return $this->set_prop( 'recurring_interval', (int) $value ); |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
| 1012 | - * Get the recurring limit. |
|
| 1013 | - * @since 1.0.19 |
|
| 1014 | - * @param int $value The recurring limit. |
|
| 1015 | - * @return int |
|
| 1016 | - */ |
|
| 1017 | - public function set_recurring_limit( $value ) { |
|
| 1012 | + * Get the recurring limit. |
|
| 1013 | + * @since 1.0.19 |
|
| 1014 | + * @param int $value The recurring limit. |
|
| 1015 | + * @return int |
|
| 1016 | + */ |
|
| 1017 | + public function set_recurring_limit( $value ) { |
|
| 1018 | 1018 | $this->set_prop( 'recurring_limit', (int) $value ); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
| 1022 | - * Checks if we have a free trial. |
|
| 1023 | - * |
|
| 1024 | - * @since 1.0.19 |
|
| 1025 | - * @param int|bool $value whether or not it has a free trial. |
|
| 1026 | - */ |
|
| 1027 | - public function set_is_free_trial( $value ) { |
|
| 1022 | + * Checks if we have a free trial. |
|
| 1023 | + * |
|
| 1024 | + * @since 1.0.19 |
|
| 1025 | + * @param int|bool $value whether or not it has a free trial. |
|
| 1026 | + */ |
|
| 1027 | + public function set_is_free_trial( $value ) { |
|
| 1028 | 1028 | $this->set_prop( 'is_free_trial', (int) $value ); |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
| 1032 | - * Set the trial period. |
|
| 1033 | - * |
|
| 1034 | - * @since 1.0.19 |
|
| 1035 | - * @param string $value trial period. |
|
| 1036 | - */ |
|
| 1037 | - public function set_trial_period( $value ) { |
|
| 1032 | + * Set the trial period. |
|
| 1033 | + * |
|
| 1034 | + * @since 1.0.19 |
|
| 1035 | + * @param string $value trial period. |
|
| 1036 | + */ |
|
| 1037 | + public function set_trial_period( $value ) { |
|
| 1038 | 1038 | $this->set_prop( 'trial_period', $value ); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
| 1042 | - * Set the trial interval. |
|
| 1043 | - * |
|
| 1044 | - * @since 1.0.19 |
|
| 1045 | - * @param int $value trial interval. |
|
| 1046 | - */ |
|
| 1047 | - public function set_trial_interval( $value ) { |
|
| 1042 | + * Set the trial interval. |
|
| 1043 | + * |
|
| 1044 | + * @since 1.0.19 |
|
| 1045 | + * @param int $value trial interval. |
|
| 1046 | + */ |
|
| 1047 | + public function set_trial_interval( $value ) { |
|
| 1048 | 1048 | $this->set_prop( 'trial_interval', $value ); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1052,17 +1052,17 @@ discard block |
||
| 1052 | 1052 | * Create an item. For backwards compatibilty. |
| 1053 | 1053 | * |
| 1054 | 1054 | * @deprecated |
| 1055 | - * @return int item id |
|
| 1055 | + * @return int item id |
|
| 1056 | 1056 | */ |
| 1057 | 1057 | public function create( $data = array() ) { |
| 1058 | 1058 | |
| 1059 | - // Set the properties. |
|
| 1060 | - if ( is_array( $data ) ) { |
|
| 1061 | - $this->set_props( $data ); |
|
| 1062 | - } |
|
| 1059 | + // Set the properties. |
|
| 1060 | + if ( is_array( $data ) ) { |
|
| 1061 | + $this->set_props( $data ); |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - // Save the item. |
|
| 1065 | - return $this->save(); |
|
| 1064 | + // Save the item. |
|
| 1065 | + return $this->save(); |
|
| 1066 | 1066 | |
| 1067 | 1067 | } |
| 1068 | 1068 | |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | * Updates an item. For backwards compatibilty. |
| 1071 | 1071 | * |
| 1072 | 1072 | * @deprecated |
| 1073 | - * @return int item id |
|
| 1073 | + * @return int item id |
|
| 1074 | 1074 | */ |
| 1075 | 1075 | public function update( $data = array() ) { |
| 1076 | 1076 | return $this->create( $data ); |
@@ -1086,93 +1086,93 @@ discard block |
||
| 1086 | 1086 | */ |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
| 1089 | - * Checks whether the item has enabled dynamic pricing. |
|
| 1090 | - * |
|
| 1091 | - * @since 1.0.19 |
|
| 1092 | - * @return bool |
|
| 1093 | - */ |
|
| 1094 | - public function user_can_set_their_price() { |
|
| 1089 | + * Checks whether the item has enabled dynamic pricing. |
|
| 1090 | + * |
|
| 1091 | + * @since 1.0.19 |
|
| 1092 | + * @return bool |
|
| 1093 | + */ |
|
| 1094 | + public function user_can_set_their_price() { |
|
| 1095 | 1095 | return (bool) $this->get_is_dynamic_pricing(); |
| 1096 | - } |
|
| 1096 | + } |
|
| 1097 | 1097 | |
| 1098 | - /** |
|
| 1099 | - * Checks whether the item is recurring. |
|
| 1100 | - * |
|
| 1101 | - * @since 1.0.19 |
|
| 1102 | - * @return bool |
|
| 1103 | - */ |
|
| 1104 | - public function is_recurring() { |
|
| 1098 | + /** |
|
| 1099 | + * Checks whether the item is recurring. |
|
| 1100 | + * |
|
| 1101 | + * @since 1.0.19 |
|
| 1102 | + * @return bool |
|
| 1103 | + */ |
|
| 1104 | + public function is_recurring() { |
|
| 1105 | 1105 | return (bool) $this->get_is_recurring(); |
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
| 1109 | - * Checks whether the item has a free trial. |
|
| 1110 | - * |
|
| 1111 | - * @since 1.0.19 |
|
| 1112 | - * @return bool |
|
| 1113 | - */ |
|
| 1109 | + * Checks whether the item has a free trial. |
|
| 1110 | + * |
|
| 1111 | + * @since 1.0.19 |
|
| 1112 | + * @return bool |
|
| 1113 | + */ |
|
| 1114 | 1114 | public function has_free_trial() { |
| 1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1116 | 1116 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
| 1120 | - * Checks whether the item is free. |
|
| 1121 | - * |
|
| 1122 | - * @since 1.0.19 |
|
| 1123 | - * @return bool |
|
| 1124 | - */ |
|
| 1120 | + * Checks whether the item is free. |
|
| 1121 | + * |
|
| 1122 | + * @since 1.0.19 |
|
| 1123 | + * @return bool |
|
| 1124 | + */ |
|
| 1125 | 1125 | public function is_free() { |
| 1126 | 1126 | $is_free = $this->get_price() == 0; |
| 1127 | 1127 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | /** |
| 1131 | - * Checks the item status against a passed in status. |
|
| 1132 | - * |
|
| 1133 | - * @param array|string $status Status to check. |
|
| 1134 | - * @return bool |
|
| 1135 | - */ |
|
| 1136 | - public function has_status( $status ) { |
|
| 1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1131 | + * Checks the item status against a passed in status. |
|
| 1132 | + * |
|
| 1133 | + * @param array|string $status Status to check. |
|
| 1134 | + * @return bool |
|
| 1135 | + */ |
|
| 1136 | + public function has_status( $status ) { |
|
| 1137 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1138 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** |
| 1142 | - * Checks the item type against a passed in types. |
|
| 1143 | - * |
|
| 1144 | - * @param array|string $type Type to check. |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public function is_type( $type ) { |
|
| 1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1150 | - } |
|
| 1142 | + * Checks the item type against a passed in types. |
|
| 1143 | + * |
|
| 1144 | + * @param array|string $type Type to check. |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public function is_type( $type ) { |
|
| 1148 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1149 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1150 | + } |
|
| 1151 | 1151 | |
| 1152 | 1152 | /** |
| 1153 | - * Checks whether the item is editable. |
|
| 1154 | - * |
|
| 1155 | - * @since 1.0.19 |
|
| 1156 | - * @return bool |
|
| 1157 | - */ |
|
| 1153 | + * Checks whether the item is editable. |
|
| 1154 | + * |
|
| 1155 | + * @since 1.0.19 |
|
| 1156 | + * @return bool |
|
| 1157 | + */ |
|
| 1158 | 1158 | public function is_editable() { |
| 1159 | 1159 | $is_editable = $this->get_is_editable(); |
| 1160 | 1160 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
| 1161 | - } |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1164 | - * Returns an array of cart fees. |
|
| 1165 | - */ |
|
| 1166 | - public function get_fees() { |
|
| 1163 | + /** |
|
| 1164 | + * Returns an array of cart fees. |
|
| 1165 | + */ |
|
| 1166 | + public function get_fees() { |
|
| 1167 | 1167 | return array(); |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | /** |
| 1171 | - * Checks whether the item is purchasable. |
|
| 1172 | - * |
|
| 1173 | - * @since 1.0.19 |
|
| 1174 | - * @return bool |
|
| 1175 | - */ |
|
| 1171 | + * Checks whether the item is purchasable. |
|
| 1172 | + * |
|
| 1173 | + * @since 1.0.19 |
|
| 1174 | + * @return bool |
|
| 1175 | + */ |
|
| 1176 | 1176 | public function can_purchase() { |
| 1177 | 1177 | $can_purchase = $this->exists(); |
| 1178 | 1178 | |
@@ -1184,11 +1184,11 @@ discard block |
||
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | 1186 | /** |
| 1187 | - * Checks whether the item supports dynamic pricing. |
|
| 1188 | - * |
|
| 1189 | - * @since 1.0.19 |
|
| 1190 | - * @return bool |
|
| 1191 | - */ |
|
| 1187 | + * Checks whether the item supports dynamic pricing. |
|
| 1188 | + * |
|
| 1189 | + * @since 1.0.19 |
|
| 1190 | + * @return bool |
|
| 1191 | + */ |
|
| 1192 | 1192 | public function supports_dynamic_pricing() { |
| 1193 | 1193 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
| 1194 | 1194 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
| 80 | 80 | */ |
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 81 | + public function __construct($item = 0) { |
|
| 82 | + parent::__construct($item); |
|
| 83 | + |
|
| 84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
| 85 | + $this->set_id($item); |
|
| 86 | + } elseif ($item instanceof self) { |
|
| 87 | + $this->set_id($item->get_id()); |
|
| 88 | + } elseif (!empty($item->ID)) { |
|
| 89 | + $this->set_id($item->ID); |
|
| 90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
| 91 | + $this->set_id($item_id); |
|
| 92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
| 93 | + $this->set_id($item_id); |
|
| 94 | 94 | } else { |
| 95 | - $this->set_object_read( true ); |
|
| 95 | + $this->set_object_read(true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 102 | - $this->post = get_post( $this->get_id() ); |
|
| 101 | + if ($this->get_id() > 0) { |
|
| 102 | + $this->post = get_post($this->get_id()); |
|
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read($this); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * @param string $context View or edit context. |
| 129 | 129 | * @return int |
| 130 | 130 | */ |
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 131 | + public function get_parent_id($context = 'view') { |
|
| 132 | + return (int) $this->get_prop('parent_id', $context); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $context View or edit context. |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 142 | + public function get_status($context = 'view') { |
|
| 143 | + return $this->get_prop('status', $context); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * @param string $context View or edit context. |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 153 | + public function get_version($context = 'view') { |
|
| 154 | + return $this->get_prop('version', $context); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | * @param string $context View or edit context. |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 164 | + public function get_date_created($context = 'view') { |
|
| 165 | + return $this->get_prop('date_created', $context); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | * @param string $context View or edit context. |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | - $date = $this->get_date_created( $context ); |
|
| 175 | + public function get_date_created_gmt($context = 'view') { |
|
| 176 | + $date = $this->get_date_created($context); |
|
| 177 | 177 | |
| 178 | - if ( $date ) { |
|
| 179 | - $date = get_gmt_from_date( $date ); |
|
| 178 | + if ($date) { |
|
| 179 | + $date = get_gmt_from_date($date); |
|
| 180 | 180 | } |
| 181 | 181 | return $date; |
| 182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param string $context View or edit context. |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 191 | + public function get_date_modified($context = 'view') { |
|
| 192 | + return $this->get_prop('date_modified', $context); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @param string $context View or edit context. |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | - $date = $this->get_date_modified( $context ); |
|
| 202 | + public function get_date_modified_gmt($context = 'view') { |
|
| 203 | + $date = $this->get_date_modified($context); |
|
| 204 | 204 | |
| 205 | - if ( $date ) { |
|
| 206 | - $date = get_gmt_from_date( $date ); |
|
| 205 | + if ($date) { |
|
| 206 | + $date = get_gmt_from_date($date); |
|
| 207 | 207 | } |
| 208 | 208 | return $date; |
| 209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * @param string $context View or edit context. |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 218 | + public function get_name($context = 'view') { |
|
| 219 | + return $this->get_prop('name', $context); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | * @param string $context View or edit context. |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 229 | + public function get_title($context = 'view') { |
|
| 230 | + return $this->get_name($context); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | * @param string $context View or edit context. |
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 240 | + public function get_description($context = 'view') { |
|
| 241 | + return $this->get_prop('description', $context); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | * @param string $context View or edit context. |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 251 | + public function get_excerpt($context = 'view') { |
|
| 252 | + return $this->get_description($context); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string $context View or edit context. |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 262 | + public function get_summary($context = 'view') { |
|
| 263 | + return $this->get_description($context); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param string $context View or edit context. |
| 271 | 271 | * @return int |
| 272 | 272 | */ |
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 273 | + public function get_author($context = 'view') { |
|
| 274 | + return (int) $this->get_prop('author', $context); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * @param string $context View or edit context. |
| 282 | 282 | * @return int |
| 283 | 283 | */ |
| 284 | - public function get_owner( $context = 'view' ) { |
|
| 285 | - return $this->get_author( $context ); |
|
| 284 | + public function get_owner($context = 'view') { |
|
| 285 | + return $this->get_author($context); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | * @param string $context View or edit context. |
| 293 | 293 | * @return float |
| 294 | 294 | */ |
| 295 | - public function get_price( $context = 'view' ) { |
|
| 296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
| 295 | + public function get_price($context = 'view') { |
|
| 296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
| 303 | 303 | * @param string $context View or edit context. |
| 304 | 304 | * @return float |
| 305 | 305 | */ |
| 306 | - public function get_initial_price( $context = 'view' ) { |
|
| 306 | + public function get_initial_price($context = 'view') { |
|
| 307 | 307 | |
| 308 | - $price = (float) $this->get_price( $context ); |
|
| 308 | + $price = (float) $this->get_price($context); |
|
| 309 | 309 | |
| 310 | - if ( $this->has_free_trial() ) { |
|
| 310 | + if ($this->has_free_trial()) { |
|
| 311 | 311 | $price = 0; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
| 314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | 324 | public function get_the_price() { |
| 325 | - return wpinv_price( $this->get_price() ); |
|
| 325 | + return wpinv_price($this->get_price()); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | public function get_the_initial_price() { |
| 336 | - return wpinv_price( $this->get_initial_price() ); |
|
| 336 | + return wpinv_price($this->get_initial_price()); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | * @param string $context View or edit context. |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function get_vat_rule( $context = 'view' ) { |
|
| 347 | - return $this->get_prop( 'vat_rule', $context ); |
|
| 346 | + public function get_vat_rule($context = 'view') { |
|
| 347 | + return $this->get_prop('vat_rule', $context); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | * @param string $context View or edit context. |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - public function get_vat_class( $context = 'view' ) { |
|
| 358 | - return $this->get_prop( 'vat_class', $context ); |
|
| 357 | + public function get_vat_class($context = 'view') { |
|
| 358 | + return $this->get_prop('vat_class', $context); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string $context View or edit context. |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function get_type( $context = 'view' ) { |
|
| 369 | - return $this->get_prop( 'type', $context ); |
|
| 368 | + public function get_type($context = 'view') { |
|
| 369 | + return $this->get_prop('type', $context); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param string $context View or edit context. |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function get_custom_id( $context = 'view' ) { |
|
| 380 | - return $this->get_prop( 'custom_id', $context ); |
|
| 379 | + public function get_custom_id($context = 'view') { |
|
| 380 | + return $this->get_prop('custom_id', $context); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | * @param string $context View or edit context. |
| 388 | 388 | * @return string |
| 389 | 389 | */ |
| 390 | - public function get_custom_name( $context = 'view' ) { |
|
| 391 | - return $this->get_prop( 'custom_name', $context ); |
|
| 390 | + public function get_custom_name($context = 'view') { |
|
| 391 | + return $this->get_prop('custom_name', $context); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param string $context View or edit context. |
| 399 | 399 | * @return string |
| 400 | 400 | */ |
| 401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
| 401 | + public function get_custom_singular_name($context = 'view') { |
|
| 402 | + return $this->get_prop('custom_singular_name', $context); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * @param string $context View or edit context. |
| 410 | 410 | * @return int |
| 411 | 411 | */ |
| 412 | - public function get_is_editable( $context = 'view' ) { |
|
| 413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
| 412 | + public function get_is_editable($context = 'view') { |
|
| 413 | + return (int) $this->get_prop('is_editable', $context); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @param string $context View or edit context. |
| 421 | 421 | * @return int |
| 422 | 422 | */ |
| 423 | - public function get_editable( $context = 'view' ) { |
|
| 424 | - return $this->get_is_editable( $context ); |
|
| 423 | + public function get_editable($context = 'view') { |
|
| 424 | + return $this->get_is_editable($context); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @param string $context View or edit context. |
| 432 | 432 | * @return int |
| 433 | 433 | */ |
| 434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
| 434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
| 435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | * @param string $context View or edit context. |
| 443 | 443 | * @return float |
| 444 | 444 | */ |
| 445 | - public function get_minimum_price( $context = 'view' ) { |
|
| 446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
| 445 | + public function get_minimum_price($context = 'view') { |
|
| 446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * @param string $context View or edit context. |
| 454 | 454 | * @return int |
| 455 | 455 | */ |
| 456 | - public function get_is_recurring( $context = 'view' ) { |
|
| 457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
| 456 | + public function get_is_recurring($context = 'view') { |
|
| 457 | + return (int) $this->get_prop('is_recurring', $context); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
| 464 | 464 | * @param string $context View or edit context. |
| 465 | 465 | * @return float |
| 466 | 466 | */ |
| 467 | - public function get_recurring_price( $context = 'view' ) { |
|
| 468 | - $price = $this->get_price( $context ); |
|
| 469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
| 467 | + public function get_recurring_price($context = 'view') { |
|
| 468 | + $price = $this->get_price($context); |
|
| 469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @return string |
| 478 | 478 | */ |
| 479 | 479 | public function get_the_recurring_price() { |
| 480 | - return wpinv_price( $this->get_recurring_price() ); |
|
| 480 | + return wpinv_price($this->get_recurring_price()); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
| 498 | 498 | $period = $this->get_recurring_period(); |
| 499 | 499 | $interval = $this->get_recurring_interval(); |
| 500 | 500 | |
| 501 | - if ( $this->has_free_trial() ) { |
|
| 501 | + if ($this->has_free_trial()) { |
|
| 502 | 502 | $period = $this->get_trial_period(); |
| 503 | 503 | $interval = $this->get_trial_interval(); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $period = $periods[ $period ]; |
|
| 507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
| 506 | + $period = $periods[$period]; |
|
| 507 | + $interval = empty($interval) ? 1 : $interval; |
|
| 508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
| 509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
| 516 | 516 | * @param bool $full Return abbreviation or in full. |
| 517 | 517 | * @return string |
| 518 | 518 | */ |
| 519 | - public function get_recurring_period( $full = false ) { |
|
| 520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
| 519 | + public function get_recurring_period($full = false) { |
|
| 520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
| 521 | 521 | |
| 522 | - if ( $full && ! is_bool( $full ) ) { |
|
| 522 | + if ($full && !is_bool($full)) { |
|
| 523 | 523 | $full = false; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -533,10 +533,10 @@ discard block |
||
| 533 | 533 | * @param string $context View or edit context. |
| 534 | 534 | * @return int |
| 535 | 535 | */ |
| 536 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 536 | + public function get_recurring_interval($context = 'view') { |
|
| 537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
| 538 | 538 | |
| 539 | - if ( $interval < 1 ) { |
|
| 539 | + if ($interval < 1) { |
|
| 540 | 540 | $interval = 1; |
| 541 | 541 | } |
| 542 | 542 | |
@@ -550,8 +550,8 @@ discard block |
||
| 550 | 550 | * @param string $context View or edit context. |
| 551 | 551 | * @return int |
| 552 | 552 | */ |
| 553 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 554 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
| 553 | + public function get_recurring_limit($context = 'view') { |
|
| 554 | + return (int) $this->get_prop('recurring_limit', $context); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | * @param string $context View or edit context. |
| 562 | 562 | * @return int |
| 563 | 563 | */ |
| 564 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 565 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
| 564 | + public function get_is_free_trial($context = 'view') { |
|
| 565 | + return (int) $this->get_prop('is_free_trial', $context); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
| 572 | 572 | * @param string $context View or edit context. |
| 573 | 573 | * @return int |
| 574 | 574 | */ |
| 575 | - public function get_free_trial( $context = 'view' ) { |
|
| 576 | - return $this->get_is_free_trial( $context ); |
|
| 575 | + public function get_free_trial($context = 'view') { |
|
| 576 | + return $this->get_is_free_trial($context); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,14 +583,14 @@ discard block |
||
| 583 | 583 | * @param bool $full Return abbreviation or in full. |
| 584 | 584 | * @return string |
| 585 | 585 | */ |
| 586 | - public function get_trial_period( $full = false ) { |
|
| 587 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
| 586 | + public function get_trial_period($full = false) { |
|
| 587 | + $period = $this->get_prop('trial_period', 'view'); |
|
| 588 | 588 | |
| 589 | - if ( $full && ! is_bool( $full ) ) { |
|
| 589 | + if ($full && !is_bool($full)) { |
|
| 590 | 590 | $full = false; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 593 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @param string $context View or edit context. |
| 601 | 601 | * @return int |
| 602 | 602 | */ |
| 603 | - public function get_trial_interval( $context = 'view' ) { |
|
| 604 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
| 603 | + public function get_trial_interval($context = 'view') { |
|
| 604 | + return (int) $this->get_prop('trial_interval', $context); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return string |
| 612 | 612 | */ |
| 613 | 613 | public function get_edit_url() { |
| 614 | - return get_edit_post_link( $this->get_id() ); |
|
| 614 | + return get_edit_post_link($this->get_id()); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -625,35 +625,35 @@ discard block |
||
| 625 | 625 | * @since 1.0.15 |
| 626 | 626 | * @return int |
| 627 | 627 | */ |
| 628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 628 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
| 629 | 629 | |
| 630 | 630 | // Trim the value. |
| 631 | - $value = sanitize_text_field( $value ); |
|
| 632 | - if ( empty( $value ) ) { |
|
| 631 | + $value = sanitize_text_field($value); |
|
| 632 | + if (empty($value)) { |
|
| 633 | 633 | return 0; |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | // Valid fields. |
| 637 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
| 637 | + $fields = array('custom_id', 'name', 'slug'); |
|
| 638 | 638 | |
| 639 | 639 | // Ensure a field has been passed. |
| 640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 640 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 641 | 641 | return 0; |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - if ( $field == 'name' ) { |
|
| 644 | + if ($field == 'name') { |
|
| 645 | 645 | $field = 'slug'; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | // Maybe retrieve from the cache. |
| 649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 650 | - if ( ! empty( $item_id ) ) { |
|
| 649 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 650 | + if (!empty($item_id)) { |
|
| 651 | 651 | return $item_id; |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | // Fetch from the db. |
| 655 | 655 | $items = array(); |
| 656 | - if ( $field == 'slug' ) { |
|
| 656 | + if ($field == 'slug') { |
|
| 657 | 657 | $items = get_posts( |
| 658 | 658 | array( |
| 659 | 659 | 'post_type' => 'wpi_item', |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | ); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - if ( $field =='custom_id' ) { |
|
| 667 | + if ($field == 'custom_id') { |
|
| 668 | 668 | $items = get_posts( |
| 669 | 669 | array( |
| 670 | 670 | 'post_type' => 'wpi_item', |
@@ -684,12 +684,12 @@ discard block |
||
| 684 | 684 | ); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if ( empty( $items ) ) { |
|
| 687 | + if (empty($items)) { |
|
| 688 | 688 | return 0; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | // Update the cache with our data |
| 692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 692 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 693 | 693 | |
| 694 | 694 | return $items[0]->ID; |
| 695 | 695 | } |
@@ -697,19 +697,19 @@ discard block |
||
| 697 | 697 | /** |
| 698 | 698 | * Margic method for retrieving a property. |
| 699 | 699 | */ |
| 700 | - public function __get( $key ) { |
|
| 700 | + public function __get($key) { |
|
| 701 | 701 | |
| 702 | 702 | // Check if we have a helper method for that. |
| 703 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 704 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 703 | + if (method_exists($this, 'get_' . $key)) { |
|
| 704 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | // Check if the key is in the associated $post object. |
| 708 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
| 708 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
| 709 | 709 | return $this->post->$key; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - return $this->get_prop( $key ); |
|
| 712 | + return $this->get_prop($key); |
|
| 713 | 713 | |
| 714 | 714 | } |
| 715 | 715 | |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * |
| 729 | 729 | * @since 1.0.19 |
| 730 | 730 | */ |
| 731 | - public function set_parent_id( $value ) { |
|
| 732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 731 | + public function set_parent_id($value) { |
|
| 732 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
| 733 | 733 | return; |
| 734 | 734 | } |
| 735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 735 | + $this->set_prop('parent_id', absint($value)); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -742,10 +742,10 @@ discard block |
||
| 742 | 742 | * @param string $status New status. |
| 743 | 743 | * @return array details of change. |
| 744 | 744 | */ |
| 745 | - public function set_status( $status ) { |
|
| 745 | + public function set_status($status) { |
|
| 746 | 746 | $old_status = $this->get_status(); |
| 747 | 747 | |
| 748 | - $this->set_prop( 'status', $status ); |
|
| 748 | + $this->set_prop('status', $status); |
|
| 749 | 749 | |
| 750 | 750 | return array( |
| 751 | 751 | 'from' => $old_status, |
@@ -758,8 +758,8 @@ discard block |
||
| 758 | 758 | * |
| 759 | 759 | * @since 1.0.19 |
| 760 | 760 | */ |
| 761 | - public function set_version( $value ) { |
|
| 762 | - $this->set_prop( 'version', $value ); |
|
| 761 | + public function set_version($value) { |
|
| 762 | + $this->set_prop('version', $value); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * @param string $value Value to set. |
| 770 | 770 | * @return bool Whether or not the date was set. |
| 771 | 771 | */ |
| 772 | - public function set_date_created( $value ) { |
|
| 773 | - $date = strtotime( $value ); |
|
| 772 | + public function set_date_created($value) { |
|
| 773 | + $date = strtotime($value); |
|
| 774 | 774 | |
| 775 | - if ( $date ) { |
|
| 776 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 775 | + if ($date) { |
|
| 776 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 777 | 777 | return true; |
| 778 | 778 | } |
| 779 | 779 | |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * @param string $value Value to set. |
| 789 | 789 | * @return bool Whether or not the date was set. |
| 790 | 790 | */ |
| 791 | - public function set_date_modified( $value ) { |
|
| 792 | - $date = strtotime( $value ); |
|
| 791 | + public function set_date_modified($value) { |
|
| 792 | + $date = strtotime($value); |
|
| 793 | 793 | |
| 794 | - if ( $date ) { |
|
| 795 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 794 | + if ($date) { |
|
| 795 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 796 | 796 | return true; |
| 797 | 797 | } |
| 798 | 798 | |
@@ -806,9 +806,9 @@ discard block |
||
| 806 | 806 | * @since 1.0.19 |
| 807 | 807 | * @param string $value New name. |
| 808 | 808 | */ |
| 809 | - public function set_name( $value ) { |
|
| 810 | - $name = sanitize_text_field( $value ); |
|
| 811 | - $this->set_prop( 'name', $name ); |
|
| 809 | + public function set_name($value) { |
|
| 810 | + $name = sanitize_text_field($value); |
|
| 811 | + $this->set_prop('name', $name); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -817,8 +817,8 @@ discard block |
||
| 817 | 817 | * @since 1.0.19 |
| 818 | 818 | * @param string $value New name. |
| 819 | 819 | */ |
| 820 | - public function set_title( $value ) { |
|
| 821 | - $this->set_name( $value ); |
|
| 820 | + public function set_title($value) { |
|
| 821 | + $this->set_name($value); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -827,9 +827,9 @@ discard block |
||
| 827 | 827 | * @since 1.0.19 |
| 828 | 828 | * @param string $value New description. |
| 829 | 829 | */ |
| 830 | - public function set_description( $value ) { |
|
| 831 | - $description = wp_kses_post( $value ); |
|
| 832 | - return $this->set_prop( 'description', $description ); |
|
| 830 | + public function set_description($value) { |
|
| 831 | + $description = wp_kses_post($value); |
|
| 832 | + return $this->set_prop('description', $description); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -838,8 +838,8 @@ discard block |
||
| 838 | 838 | * @since 1.0.19 |
| 839 | 839 | * @param string $value New description. |
| 840 | 840 | */ |
| 841 | - public function set_excerpt( $value ) { |
|
| 842 | - $this->set_description( $value ); |
|
| 841 | + public function set_excerpt($value) { |
|
| 842 | + $this->set_description($value); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
@@ -848,8 +848,8 @@ discard block |
||
| 848 | 848 | * @since 1.0.19 |
| 849 | 849 | * @param string $value New description. |
| 850 | 850 | */ |
| 851 | - public function set_summary( $value ) { |
|
| 852 | - $this->set_description( $value ); |
|
| 851 | + public function set_summary($value) { |
|
| 852 | + $this->set_description($value); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
@@ -858,8 +858,8 @@ discard block |
||
| 858 | 858 | * @since 1.0.19 |
| 859 | 859 | * @param int $value New author. |
| 860 | 860 | */ |
| 861 | - public function set_author( $value ) { |
|
| 862 | - $this->set_prop( 'author', (int) $value ); |
|
| 861 | + public function set_author($value) { |
|
| 862 | + $this->set_prop('author', (int) $value); |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | /** |
@@ -868,8 +868,8 @@ discard block |
||
| 868 | 868 | * @since 1.0.19 |
| 869 | 869 | * @param int $value New author. |
| 870 | 870 | */ |
| 871 | - public function set_owner( $value ) { |
|
| 872 | - $this->set_author( $value ); |
|
| 871 | + public function set_owner($value) { |
|
| 872 | + $this->set_author($value); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | /** |
@@ -878,8 +878,8 @@ discard block |
||
| 878 | 878 | * @since 1.0.19 |
| 879 | 879 | * @param float $value New price. |
| 880 | 880 | */ |
| 881 | - public function set_price( $value ) { |
|
| 882 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 881 | + public function set_price($value) { |
|
| 882 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /** |
@@ -888,8 +888,8 @@ discard block |
||
| 888 | 888 | * @since 1.0.19 |
| 889 | 889 | * @param string $value new rule. |
| 890 | 890 | */ |
| 891 | - public function set_vat_rule( $value ) { |
|
| 892 | - $this->set_prop( 'vat_rule', $value ); |
|
| 891 | + public function set_vat_rule($value) { |
|
| 892 | + $this->set_prop('vat_rule', $value); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -898,8 +898,8 @@ discard block |
||
| 898 | 898 | * @since 1.0.19 |
| 899 | 899 | * @param string $value new class. |
| 900 | 900 | */ |
| 901 | - public function set_vat_class( $value ) { |
|
| 902 | - $this->set_prop( 'vat_class', $value ); |
|
| 901 | + public function set_vat_class($value) { |
|
| 902 | + $this->set_prop('vat_class', $value); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -909,13 +909,13 @@ discard block |
||
| 909 | 909 | * @param string $value new item type. |
| 910 | 910 | * @return string |
| 911 | 911 | */ |
| 912 | - public function set_type( $value ) { |
|
| 912 | + public function set_type($value) { |
|
| 913 | 913 | |
| 914 | - if ( empty( $value ) ) { |
|
| 914 | + if (empty($value)) { |
|
| 915 | 915 | $value = 'custom'; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - $this->set_prop( 'type', $value ); |
|
| 918 | + $this->set_prop('type', $value); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | /** |
@@ -924,8 +924,8 @@ discard block |
||
| 924 | 924 | * @since 1.0.19 |
| 925 | 925 | * @param string $value new custom id. |
| 926 | 926 | */ |
| 927 | - public function set_custom_id( $value ) { |
|
| 928 | - $this->set_prop( 'custom_id', $value ); |
|
| 927 | + public function set_custom_id($value) { |
|
| 928 | + $this->set_prop('custom_id', $value); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | * @since 1.0.19 |
| 935 | 935 | * @param string $value new custom name. |
| 936 | 936 | */ |
| 937 | - public function set_custom_name( $value ) { |
|
| 938 | - $this->set_prop( 'custom_name', $value ); |
|
| 937 | + public function set_custom_name($value) { |
|
| 938 | + $this->set_prop('custom_name', $value); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -944,8 +944,8 @@ discard block |
||
| 944 | 944 | * @since 1.0.19 |
| 945 | 945 | * @param string $value new custom singular name. |
| 946 | 946 | */ |
| 947 | - public function set_custom_singular_name( $value ) { |
|
| 948 | - $this->set_prop( 'custom_singular_name', $value ); |
|
| 947 | + public function set_custom_singular_name($value) { |
|
| 948 | + $this->set_prop('custom_singular_name', $value); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | * @since 1.0.19 |
| 955 | 955 | * @param int|bool $value whether or not the item is editable. |
| 956 | 956 | */ |
| 957 | - public function set_is_editable( $value ) { |
|
| 958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 957 | + public function set_is_editable($value) { |
|
| 958 | + $this->set_prop('is_editable', (int) $value); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -964,8 +964,8 @@ discard block |
||
| 964 | 964 | * @since 1.0.19 |
| 965 | 965 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 966 | 966 | */ |
| 967 | - public function set_is_dynamic_pricing( $value ) { |
|
| 968 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
| 967 | + public function set_is_dynamic_pricing($value) { |
|
| 968 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -974,8 +974,8 @@ discard block |
||
| 974 | 974 | * @since 1.0.19 |
| 975 | 975 | * @param float $value minimum price. |
| 976 | 976 | */ |
| 977 | - public function set_minimum_price( $value ) { |
|
| 978 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 977 | + public function set_minimum_price($value) { |
|
| 978 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
@@ -984,8 +984,8 @@ discard block |
||
| 984 | 984 | * @since 1.0.19 |
| 985 | 985 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 986 | 986 | */ |
| 987 | - public function set_is_recurring( $value ) { |
|
| 988 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
| 987 | + public function set_is_recurring($value) { |
|
| 988 | + $this->set_prop('is_recurring', (int) $value); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -994,8 +994,8 @@ discard block |
||
| 994 | 994 | * @since 1.0.19 |
| 995 | 995 | * @param string $value new period. |
| 996 | 996 | */ |
| 997 | - public function set_recurring_period( $value ) { |
|
| 998 | - $this->set_prop( 'recurring_period', $value ); |
|
| 997 | + public function set_recurring_period($value) { |
|
| 998 | + $this->set_prop('recurring_period', $value); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
@@ -1004,8 +1004,8 @@ discard block |
||
| 1004 | 1004 | * @since 1.0.19 |
| 1005 | 1005 | * @param int $value recurring interval. |
| 1006 | 1006 | */ |
| 1007 | - public function set_recurring_interval( $value ) { |
|
| 1008 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
| 1007 | + public function set_recurring_interval($value) { |
|
| 1008 | + return $this->set_prop('recurring_interval', (int) $value); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
@@ -1014,8 +1014,8 @@ discard block |
||
| 1014 | 1014 | * @param int $value The recurring limit. |
| 1015 | 1015 | * @return int |
| 1016 | 1016 | */ |
| 1017 | - public function set_recurring_limit( $value ) { |
|
| 1018 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
| 1017 | + public function set_recurring_limit($value) { |
|
| 1018 | + $this->set_prop('recurring_limit', (int) $value); |
|
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
@@ -1024,8 +1024,8 @@ discard block |
||
| 1024 | 1024 | * @since 1.0.19 |
| 1025 | 1025 | * @param int|bool $value whether or not it has a free trial. |
| 1026 | 1026 | */ |
| 1027 | - public function set_is_free_trial( $value ) { |
|
| 1028 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
| 1027 | + public function set_is_free_trial($value) { |
|
| 1028 | + $this->set_prop('is_free_trial', (int) $value); |
|
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | /** |
@@ -1034,8 +1034,8 @@ discard block |
||
| 1034 | 1034 | * @since 1.0.19 |
| 1035 | 1035 | * @param string $value trial period. |
| 1036 | 1036 | */ |
| 1037 | - public function set_trial_period( $value ) { |
|
| 1038 | - $this->set_prop( 'trial_period', $value ); |
|
| 1037 | + public function set_trial_period($value) { |
|
| 1038 | + $this->set_prop('trial_period', $value); |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1044,8 +1044,8 @@ discard block |
||
| 1044 | 1044 | * @since 1.0.19 |
| 1045 | 1045 | * @param int $value trial interval. |
| 1046 | 1046 | */ |
| 1047 | - public function set_trial_interval( $value ) { |
|
| 1048 | - $this->set_prop( 'trial_interval', $value ); |
|
| 1047 | + public function set_trial_interval($value) { |
|
| 1048 | + $this->set_prop('trial_interval', $value); |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1054,11 +1054,11 @@ discard block |
||
| 1054 | 1054 | * @deprecated |
| 1055 | 1055 | * @return int item id |
| 1056 | 1056 | */ |
| 1057 | - public function create( $data = array() ) { |
|
| 1057 | + public function create($data = array()) { |
|
| 1058 | 1058 | |
| 1059 | 1059 | // Set the properties. |
| 1060 | - if ( is_array( $data ) ) { |
|
| 1061 | - $this->set_props( $data ); |
|
| 1060 | + if (is_array($data)) { |
|
| 1061 | + $this->set_props($data); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | // Save the item. |
@@ -1072,8 +1072,8 @@ discard block |
||
| 1072 | 1072 | * @deprecated |
| 1073 | 1073 | * @return int item id |
| 1074 | 1074 | */ |
| 1075 | - public function update( $data = array() ) { |
|
| 1076 | - return $this->create( $data ); |
|
| 1075 | + public function update($data = array()) { |
|
| 1076 | + return $this->create($data); |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | /* |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | */ |
| 1114 | 1114 | public function has_free_trial() { |
| 1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1116 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
| 1116 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | /** |
@@ -1123,8 +1123,8 @@ discard block |
||
| 1123 | 1123 | * @return bool |
| 1124 | 1124 | */ |
| 1125 | 1125 | public function is_free() { |
| 1126 | - $is_free = $this->get_price() == 0; |
|
| 1127 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
| 1126 | + $is_free = $this->get_price() == 0; |
|
| 1127 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | /** |
@@ -1133,9 +1133,9 @@ discard block |
||
| 1133 | 1133 | * @param array|string $status Status to check. |
| 1134 | 1134 | * @return bool |
| 1135 | 1135 | */ |
| 1136 | - public function has_status( $status ) { |
|
| 1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1136 | + public function has_status($status) { |
|
| 1137 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
| 1138 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** |
@@ -1144,9 +1144,9 @@ discard block |
||
| 1144 | 1144 | * @param array|string $type Type to check. |
| 1145 | 1145 | * @return bool |
| 1146 | 1146 | */ |
| 1147 | - public function is_type( $type ) { |
|
| 1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1147 | + public function is_type($type) { |
|
| 1148 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
| 1149 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | */ |
| 1158 | 1158 | public function is_editable() { |
| 1159 | 1159 | $is_editable = $this->get_is_editable(); |
| 1160 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
| 1160 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | /** |
@@ -1176,11 +1176,11 @@ discard block |
||
| 1176 | 1176 | public function can_purchase() { |
| 1177 | 1177 | $can_purchase = $this->exists(); |
| 1178 | 1178 | |
| 1179 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 1179 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 1180 | 1180 | $can_purchase = false; |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 1183 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | 1186 | /** |
@@ -1190,6 +1190,6 @@ discard block |
||
| 1190 | 1190 | * @return bool |
| 1191 | 1191 | */ |
| 1192 | 1192 | public function supports_dynamic_pricing() { |
| 1193 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
| 1193 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
| 1194 | 1194 | } |
| 1195 | 1195 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | - exit; |
|
| 7 | + exit; |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
| 19 | - * |
|
| 20 | - * @since 1.0.19 |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $internal_meta_keys = array( |
|
| 24 | - '_wpinv_price', |
|
| 25 | - '_wpinv_vat_rule', |
|
| 26 | - '_wpinv_vat_class', |
|
| 27 | - '_wpinv_type', |
|
| 28 | - '_wpinv_custom_id', |
|
| 29 | - '_wpinv_custom_name', |
|
| 30 | - '_wpinv_custom_singular_name', |
|
| 31 | - '_wpinv_editable', |
|
| 32 | - '_wpinv_dynamic_pricing', |
|
| 33 | - '_minimum_price', |
|
| 34 | - '_wpinv_is_recurring', |
|
| 35 | - '_wpinv_recurring_period', |
|
| 36 | - '_wpinv_recurring_interval', |
|
| 37 | - '_wpinv_recurring_limit', |
|
| 38 | - '_wpinv_free_trial', |
|
| 39 | - '_wpinv_trial_period', |
|
| 40 | - '_wpinv_trial_interval' |
|
| 41 | - ); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * A map of meta keys to data props. |
|
| 45 | - * |
|
| 46 | - * @since 1.0.19 |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $meta_key_to_props = array( |
|
| 51 | - '_wpinv_price' => 'price', |
|
| 52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
| 53 | - '_wpinv_vat_class' => 'vat_class', |
|
| 54 | - '_wpinv_type' => 'type', |
|
| 55 | - '_wpinv_custom_id' => 'custom_id', |
|
| 56 | - '_wpinv_custom_name' => 'custom_name', |
|
| 57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
| 58 | - '_wpinv_editable' => 'is_editable', |
|
| 59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
| 60 | - '_minimum_price' => 'minimum_price', |
|
| 61 | - '_wpinv_custom_name' => 'custom_name', |
|
| 62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
| 63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
| 64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
| 65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
| 66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
| 67 | - '_wpinv_trial_period' => 'trial_period', |
|
| 68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
| 69 | - '_wpinv_version' => 'version', |
|
| 70 | - ); |
|
| 71 | - |
|
| 72 | - /* |
|
| 17 | + /** |
|
| 18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
| 19 | + * |
|
| 20 | + * @since 1.0.19 |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $internal_meta_keys = array( |
|
| 24 | + '_wpinv_price', |
|
| 25 | + '_wpinv_vat_rule', |
|
| 26 | + '_wpinv_vat_class', |
|
| 27 | + '_wpinv_type', |
|
| 28 | + '_wpinv_custom_id', |
|
| 29 | + '_wpinv_custom_name', |
|
| 30 | + '_wpinv_custom_singular_name', |
|
| 31 | + '_wpinv_editable', |
|
| 32 | + '_wpinv_dynamic_pricing', |
|
| 33 | + '_minimum_price', |
|
| 34 | + '_wpinv_is_recurring', |
|
| 35 | + '_wpinv_recurring_period', |
|
| 36 | + '_wpinv_recurring_interval', |
|
| 37 | + '_wpinv_recurring_limit', |
|
| 38 | + '_wpinv_free_trial', |
|
| 39 | + '_wpinv_trial_period', |
|
| 40 | + '_wpinv_trial_interval' |
|
| 41 | + ); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * A map of meta keys to data props. |
|
| 45 | + * |
|
| 46 | + * @since 1.0.19 |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $meta_key_to_props = array( |
|
| 51 | + '_wpinv_price' => 'price', |
|
| 52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
| 53 | + '_wpinv_vat_class' => 'vat_class', |
|
| 54 | + '_wpinv_type' => 'type', |
|
| 55 | + '_wpinv_custom_id' => 'custom_id', |
|
| 56 | + '_wpinv_custom_name' => 'custom_name', |
|
| 57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
| 58 | + '_wpinv_editable' => 'is_editable', |
|
| 59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
| 60 | + '_minimum_price' => 'minimum_price', |
|
| 61 | + '_wpinv_custom_name' => 'custom_name', |
|
| 62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
| 63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
| 64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
| 65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
| 66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
| 67 | + '_wpinv_trial_period' => 'trial_period', |
|
| 68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
| 69 | + '_wpinv_version' => 'version', |
|
| 70 | + ); |
|
| 71 | + |
|
| 72 | + /* |
|
| 73 | 73 | |-------------------------------------------------------------------------- |
| 74 | 74 | | CRUD Methods |
| 75 | 75 | |-------------------------------------------------------------------------- |
| 76 | 76 | */ |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Method to create a new item in the database. |
|
| 80 | - * |
|
| 81 | - * @param WPInv_Item $item Item object. |
|
| 82 | - */ |
|
| 83 | - public function create( &$item ) { |
|
| 84 | - $item->set_version( WPINV_VERSION ); |
|
| 85 | - $item->set_date_created( current_time('mysql') ); |
|
| 86 | - |
|
| 87 | - // Create a new post. |
|
| 88 | - $id = wp_insert_post( |
|
| 89 | - apply_filters( |
|
| 90 | - 'getpaid_new_item_data', |
|
| 91 | - array( |
|
| 92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
| 93 | - 'post_type' => 'wpi_item', |
|
| 94 | - 'post_status' => $this->get_post_status( $item ), |
|
| 95 | - 'ping_status' => 'closed', |
|
| 96 | - 'post_author' => $item->get_author( 'edit' ), |
|
| 97 | - 'post_title' => $item->get_name( 'edit' ), |
|
| 98 | - 'post_parent' => 0, |
|
| 99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 100 | - ) |
|
| 101 | - ), |
|
| 102 | - true |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
| 106 | - $item->set_id( $id ); |
|
| 107 | - $this->update_post_meta( $item ); |
|
| 108 | - $item->save_meta_data(); |
|
| 109 | - $item->apply_changes(); |
|
| 110 | - $this->clear_caches( $item ); |
|
| 111 | - do_action( 'getpaid_new_item', $item ); |
|
| 112 | - return true; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( is_wp_error( $id ) ) { |
|
| 116 | - $item->last_error = $id->get_error_message(); |
|
| 117 | - } |
|
| 78 | + /** |
|
| 79 | + * Method to create a new item in the database. |
|
| 80 | + * |
|
| 81 | + * @param WPInv_Item $item Item object. |
|
| 82 | + */ |
|
| 83 | + public function create( &$item ) { |
|
| 84 | + $item->set_version( WPINV_VERSION ); |
|
| 85 | + $item->set_date_created( current_time('mysql') ); |
|
| 86 | + |
|
| 87 | + // Create a new post. |
|
| 88 | + $id = wp_insert_post( |
|
| 89 | + apply_filters( |
|
| 90 | + 'getpaid_new_item_data', |
|
| 91 | + array( |
|
| 92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
| 93 | + 'post_type' => 'wpi_item', |
|
| 94 | + 'post_status' => $this->get_post_status( $item ), |
|
| 95 | + 'ping_status' => 'closed', |
|
| 96 | + 'post_author' => $item->get_author( 'edit' ), |
|
| 97 | + 'post_title' => $item->get_name( 'edit' ), |
|
| 98 | + 'post_parent' => 0, |
|
| 99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 100 | + ) |
|
| 101 | + ), |
|
| 102 | + true |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
| 106 | + $item->set_id( $id ); |
|
| 107 | + $this->update_post_meta( $item ); |
|
| 108 | + $item->save_meta_data(); |
|
| 109 | + $item->apply_changes(); |
|
| 110 | + $this->clear_caches( $item ); |
|
| 111 | + do_action( 'getpaid_new_item', $item ); |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( is_wp_error( $id ) ) { |
|
| 116 | + $item->last_error = $id->get_error_message(); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Method to read an item from the database. |
|
| 124 | - * |
|
| 125 | - * @param WPInv_Item $item Item object. |
|
| 126 | - * |
|
| 127 | - */ |
|
| 128 | - public function read( &$item ) { |
|
| 129 | - |
|
| 130 | - $item->set_defaults(); |
|
| 131 | - $item_object = get_post( $item->get_id() ); |
|
| 132 | - |
|
| 133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
| 134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
| 135 | - $item->set_id( 0 ); |
|
| 136 | - return false; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $item->set_props( |
|
| 140 | - array( |
|
| 141 | - 'parent_id' => $item_object->post_parent, |
|
| 142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
| 143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
| 144 | - 'status' => $item_object->post_status, |
|
| 145 | - 'name' => $item_object->post_title, |
|
| 146 | - 'description' => $item_object->post_excerpt, |
|
| 147 | - 'author' => $item_object->post_author, |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - $this->read_object_data( $item, $item_object ); |
|
| 152 | - $item->read_meta_data(); |
|
| 153 | - $item->set_object_read( true ); |
|
| 154 | - do_action( 'getpaid_read_item', $item ); |
|
| 155 | - |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Method to update an item in the database. |
|
| 160 | - * |
|
| 161 | - * @param WPInv_Item $item Item object. |
|
| 162 | - */ |
|
| 163 | - public function update( &$item ) { |
|
| 164 | - $item->save_meta_data(); |
|
| 165 | - $item->set_version( WPINV_VERSION ); |
|
| 166 | - |
|
| 167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
| 168 | - $item->set_date_created( current_time('mysql') ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Grab the current status so we can compare. |
|
| 172 | - $previous_status = get_post_status( $item->get_id() ); |
|
| 173 | - |
|
| 174 | - $changes = $item->get_changes(); |
|
| 175 | - |
|
| 176 | - // Only update the post when the post data changes. |
|
| 177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
| 178 | - $post_data = array( |
|
| 179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
| 180 | - 'post_status' => $item->get_status( 'edit' ), |
|
| 181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
| 182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
| 184 | - 'post_title' => $item->get_name( 'edit' ), |
|
| 185 | - 'post_author' => $item->get_author( 'edit' ), |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
| 190 | - * to update data, since wp_update_post spawns more calls to the |
|
| 191 | - * save_post action. |
|
| 192 | - * |
|
| 193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
| 194 | - * or an update purely from CRUD. |
|
| 195 | - */ |
|
| 196 | - if ( doing_action( 'save_post' ) ) { |
|
| 197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
| 198 | - clean_post_cache( $item->get_id() ); |
|
| 199 | - } else { |
|
| 200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
| 201 | - } |
|
| 202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 203 | - } |
|
| 204 | - $this->update_post_meta( $item ); |
|
| 205 | - $item->apply_changes(); |
|
| 206 | - $this->clear_caches( $item ); |
|
| 207 | - |
|
| 208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
| 209 | - $new_status = $item->get_status( 'edit' ); |
|
| 210 | - |
|
| 211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 212 | - do_action( 'getpaid_new_item', $item ); |
|
| 213 | - } else { |
|
| 214 | - do_action( 'getpaid_update_item', $item ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /* |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Method to read an item from the database. |
|
| 124 | + * |
|
| 125 | + * @param WPInv_Item $item Item object. |
|
| 126 | + * |
|
| 127 | + */ |
|
| 128 | + public function read( &$item ) { |
|
| 129 | + |
|
| 130 | + $item->set_defaults(); |
|
| 131 | + $item_object = get_post( $item->get_id() ); |
|
| 132 | + |
|
| 133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
| 134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
| 135 | + $item->set_id( 0 ); |
|
| 136 | + return false; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $item->set_props( |
|
| 140 | + array( |
|
| 141 | + 'parent_id' => $item_object->post_parent, |
|
| 142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
| 143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
| 144 | + 'status' => $item_object->post_status, |
|
| 145 | + 'name' => $item_object->post_title, |
|
| 146 | + 'description' => $item_object->post_excerpt, |
|
| 147 | + 'author' => $item_object->post_author, |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + $this->read_object_data( $item, $item_object ); |
|
| 152 | + $item->read_meta_data(); |
|
| 153 | + $item->set_object_read( true ); |
|
| 154 | + do_action( 'getpaid_read_item', $item ); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Method to update an item in the database. |
|
| 160 | + * |
|
| 161 | + * @param WPInv_Item $item Item object. |
|
| 162 | + */ |
|
| 163 | + public function update( &$item ) { |
|
| 164 | + $item->save_meta_data(); |
|
| 165 | + $item->set_version( WPINV_VERSION ); |
|
| 166 | + |
|
| 167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
| 168 | + $item->set_date_created( current_time('mysql') ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Grab the current status so we can compare. |
|
| 172 | + $previous_status = get_post_status( $item->get_id() ); |
|
| 173 | + |
|
| 174 | + $changes = $item->get_changes(); |
|
| 175 | + |
|
| 176 | + // Only update the post when the post data changes. |
|
| 177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
| 178 | + $post_data = array( |
|
| 179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
| 180 | + 'post_status' => $item->get_status( 'edit' ), |
|
| 181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
| 182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
| 184 | + 'post_title' => $item->get_name( 'edit' ), |
|
| 185 | + 'post_author' => $item->get_author( 'edit' ), |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
| 190 | + * to update data, since wp_update_post spawns more calls to the |
|
| 191 | + * save_post action. |
|
| 192 | + * |
|
| 193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
| 194 | + * or an update purely from CRUD. |
|
| 195 | + */ |
|
| 196 | + if ( doing_action( 'save_post' ) ) { |
|
| 197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
| 198 | + clean_post_cache( $item->get_id() ); |
|
| 199 | + } else { |
|
| 200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
| 201 | + } |
|
| 202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 203 | + } |
|
| 204 | + $this->update_post_meta( $item ); |
|
| 205 | + $item->apply_changes(); |
|
| 206 | + $this->clear_caches( $item ); |
|
| 207 | + |
|
| 208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
| 209 | + $new_status = $item->get_status( 'edit' ); |
|
| 210 | + |
|
| 211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 212 | + do_action( 'getpaid_new_item', $item ); |
|
| 213 | + } else { |
|
| 214 | + do_action( 'getpaid_update_item', $item ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /* |
|
| 220 | 220 | |-------------------------------------------------------------------------- |
| 221 | 221 | | Additional Methods |
| 222 | 222 | |-------------------------------------------------------------------------- |
| 223 | 223 | */ |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
| 227 | - * |
|
| 228 | - * @param WPInv_Item $item WPInv_Item object. |
|
| 229 | - * @since 1.0.19 |
|
| 230 | - */ |
|
| 231 | - protected function update_post_meta( &$item ) { |
|
| 225 | + /** |
|
| 226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
| 227 | + * |
|
| 228 | + * @param WPInv_Item $item WPInv_Item object. |
|
| 229 | + * @since 1.0.19 |
|
| 230 | + */ |
|
| 231 | + protected function update_post_meta( &$item ) { |
|
| 232 | 232 | |
| 233 | - // Ensure that we have a custom id. |
|
| 233 | + // Ensure that we have a custom id. |
|
| 234 | 234 | if ( ! $item->get_custom_id() ) { |
| 235 | 235 | $item->set_custom_id( $item->get_id() ); |
| 236 | - } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - parent::update_post_meta( $item ); |
|
| 239 | - } |
|
| 238 | + parent::update_post_meta( $item ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * GetPaid_Item_Data_Store class file. |
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -80,39 +80,39 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @param WPInv_Item $item Item object. |
| 82 | 82 | */ |
| 83 | - public function create( &$item ) { |
|
| 84 | - $item->set_version( WPINV_VERSION ); |
|
| 85 | - $item->set_date_created( current_time('mysql') ); |
|
| 83 | + public function create(&$item) { |
|
| 84 | + $item->set_version(WPINV_VERSION); |
|
| 85 | + $item->set_date_created(current_time('mysql')); |
|
| 86 | 86 | |
| 87 | 87 | // Create a new post. |
| 88 | 88 | $id = wp_insert_post( |
| 89 | 89 | apply_filters( |
| 90 | 90 | 'getpaid_new_item_data', |
| 91 | 91 | array( |
| 92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
| 92 | + 'post_date' => $item->get_date_created('edit'), |
|
| 93 | 93 | 'post_type' => 'wpi_item', |
| 94 | - 'post_status' => $this->get_post_status( $item ), |
|
| 94 | + 'post_status' => $this->get_post_status($item), |
|
| 95 | 95 | 'ping_status' => 'closed', |
| 96 | - 'post_author' => $item->get_author( 'edit' ), |
|
| 97 | - 'post_title' => $item->get_name( 'edit' ), |
|
| 96 | + 'post_author' => $item->get_author('edit'), |
|
| 97 | + 'post_title' => $item->get_name('edit'), |
|
| 98 | 98 | 'post_parent' => 0, |
| 99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 99 | + 'post_excerpt' => $item->get_description('edit'), |
|
| 100 | 100 | ) |
| 101 | 101 | ), |
| 102 | 102 | true |
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
| 106 | - $item->set_id( $id ); |
|
| 107 | - $this->update_post_meta( $item ); |
|
| 105 | + if ($id && !is_wp_error($id)) { |
|
| 106 | + $item->set_id($id); |
|
| 107 | + $this->update_post_meta($item); |
|
| 108 | 108 | $item->save_meta_data(); |
| 109 | 109 | $item->apply_changes(); |
| 110 | - $this->clear_caches( $item ); |
|
| 111 | - do_action( 'getpaid_new_item', $item ); |
|
| 110 | + $this->clear_caches($item); |
|
| 111 | + do_action('getpaid_new_item', $item); |
|
| 112 | 112 | return true; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( is_wp_error( $id ) ) { |
|
| 115 | + if (is_wp_error($id)) { |
|
| 116 | 116 | $item->last_error = $id->get_error_message(); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | * @param WPInv_Item $item Item object. |
| 126 | 126 | * |
| 127 | 127 | */ |
| 128 | - public function read( &$item ) { |
|
| 128 | + public function read(&$item) { |
|
| 129 | 129 | |
| 130 | 130 | $item->set_defaults(); |
| 131 | - $item_object = get_post( $item->get_id() ); |
|
| 131 | + $item_object = get_post($item->get_id()); |
|
| 132 | 132 | |
| 133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
| 134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
| 135 | - $item->set_id( 0 ); |
|
| 133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
| 134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
| 135 | + $item->set_id(0); |
|
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | ) |
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - $this->read_object_data( $item, $item_object ); |
|
| 151 | + $this->read_object_data($item, $item_object); |
|
| 152 | 152 | $item->read_meta_data(); |
| 153 | - $item->set_object_read( true ); |
|
| 154 | - do_action( 'getpaid_read_item', $item ); |
|
| 153 | + $item->set_object_read(true); |
|
| 154 | + do_action('getpaid_read_item', $item); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @param WPInv_Item $item Item object. |
| 162 | 162 | */ |
| 163 | - public function update( &$item ) { |
|
| 163 | + public function update(&$item) { |
|
| 164 | 164 | $item->save_meta_data(); |
| 165 | - $item->set_version( WPINV_VERSION ); |
|
| 165 | + $item->set_version(WPINV_VERSION); |
|
| 166 | 166 | |
| 167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
| 168 | - $item->set_date_created( current_time('mysql') ); |
|
| 167 | + if (null === $item->get_date_created('edit')) { |
|
| 168 | + $item->set_date_created(current_time('mysql')); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Grab the current status so we can compare. |
| 172 | - $previous_status = get_post_status( $item->get_id() ); |
|
| 172 | + $previous_status = get_post_status($item->get_id()); |
|
| 173 | 173 | |
| 174 | 174 | $changes = $item->get_changes(); |
| 175 | 175 | |
| 176 | 176 | // Only update the post when the post data changes. |
| 177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
| 177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author'), array_keys($changes))) { |
|
| 178 | 178 | $post_data = array( |
| 179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
| 180 | - 'post_status' => $item->get_status( 'edit' ), |
|
| 181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
| 182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
| 183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
| 184 | - 'post_title' => $item->get_name( 'edit' ), |
|
| 185 | - 'post_author' => $item->get_author( 'edit' ), |
|
| 179 | + 'post_date' => $item->get_date_created('edit'), |
|
| 180 | + 'post_status' => $item->get_status('edit'), |
|
| 181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
| 182 | + 'post_excerpt' => $item->get_description('edit'), |
|
| 183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
| 184 | + 'post_title' => $item->get_name('edit'), |
|
| 185 | + 'post_author' => $item->get_author('edit'), |
|
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
| 193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
| 194 | 194 | * or an update purely from CRUD. |
| 195 | 195 | */ |
| 196 | - if ( doing_action( 'save_post' ) ) { |
|
| 197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
| 198 | - clean_post_cache( $item->get_id() ); |
|
| 196 | + if (doing_action('save_post')) { |
|
| 197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
| 198 | + clean_post_cache($item->get_id()); |
|
| 199 | 199 | } else { |
| 200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
| 200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
| 201 | 201 | } |
| 202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
| 203 | 203 | } |
| 204 | - $this->update_post_meta( $item ); |
|
| 204 | + $this->update_post_meta($item); |
|
| 205 | 205 | $item->apply_changes(); |
| 206 | - $this->clear_caches( $item ); |
|
| 206 | + $this->clear_caches($item); |
|
| 207 | 207 | |
| 208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
| 209 | - $new_status = $item->get_status( 'edit' ); |
|
| 209 | + $new_status = $item->get_status('edit'); |
|
| 210 | 210 | |
| 211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
| 212 | - do_action( 'getpaid_new_item', $item ); |
|
| 211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
| 212 | + do_action('getpaid_new_item', $item); |
|
| 213 | 213 | } else { |
| 214 | - do_action( 'getpaid_update_item', $item ); |
|
| 214 | + do_action('getpaid_update_item', $item); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
| 229 | 229 | * @since 1.0.19 |
| 230 | 230 | */ |
| 231 | - protected function update_post_meta( &$item ) { |
|
| 231 | + protected function update_post_meta(&$item) { |
|
| 232 | 232 | |
| 233 | 233 | // Ensure that we have a custom id. |
| 234 | - if ( ! $item->get_custom_id() ) { |
|
| 235 | - $item->set_custom_id( $item->get_id() ); |
|
| 234 | + if (!$item->get_custom_id()) { |
|
| 235 | + $item->set_custom_id($item->get_id()); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - parent::update_post_meta( $item ); |
|
| 238 | + parent::update_post_meta($item); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'payment_form'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'payment_form'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'payment_form'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'status' => 'draft', |
|
| 34 | - 'version' => '', |
|
| 35 | - 'date_created' => null, |
|
| 27 | + * Form Data array. This is the core form data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'status' => 'draft', |
|
| 34 | + 'version' => '', |
|
| 35 | + 'date_created' => null, |
|
| 36 | 36 | 'date_modified' => null, |
| 37 | 37 | 'name' => '', |
| 38 | 38 | 'author' => 1, |
| 39 | 39 | 'elements' => null, |
| 40 | - 'items' => null, |
|
| 41 | - 'earned' => 0, |
|
| 42 | - 'refunded' => 0, |
|
| 43 | - 'cancelled' => 0, |
|
| 44 | - 'failed' => 0, |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Stores meta in cache for future reads. |
|
| 49 | - * |
|
| 50 | - * A group must be set to to enable caching. |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $cache_group = 'getpaid_forms'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | - * |
|
| 59 | - * @var WPInv_Invoice |
|
| 60 | - */ |
|
| 61 | - public $invoice = 0; |
|
| 40 | + 'items' => null, |
|
| 41 | + 'earned' => 0, |
|
| 42 | + 'refunded' => 0, |
|
| 43 | + 'cancelled' => 0, |
|
| 44 | + 'failed' => 0, |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Stores meta in cache for future reads. |
|
| 49 | + * |
|
| 50 | + * A group must be set to to enable caching. |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $cache_group = 'getpaid_forms'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
| 58 | + * |
|
| 59 | + * @var WPInv_Invoice |
|
| 60 | + */ |
|
| 61 | + public $invoice = 0; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
| 68 | 68 | protected $post = null; |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | - * |
|
| 73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | - */ |
|
| 75 | - public function __construct( $form = 0 ) { |
|
| 76 | - parent::__construct( $form ); |
|
| 71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
| 72 | + * |
|
| 73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
| 74 | + */ |
|
| 75 | + public function __construct( $form = 0 ) { |
|
| 76 | + parent::__construct( $form ); |
|
| 77 | 77 | |
| 78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | - $this->set_id( $form ); |
|
| 80 | - } elseif ( $form instanceof self ) { |
|
| 78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | + $this->set_id( $form ); |
|
| 80 | + } elseif ( $form instanceof self ) { |
|
| 81 | 81 | |
| 82 | - $this->set_id( $form->get_id() ); |
|
| 83 | - $this->invoice = $form->invoice; |
|
| 82 | + $this->set_id( $form->get_id() ); |
|
| 83 | + $this->invoice = $form->invoice; |
|
| 84 | 84 | |
| 85 | - } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | - $this->set_id( $form->ID ); |
|
| 87 | - } else { |
|
| 88 | - $this->set_object_read( true ); |
|
| 89 | - } |
|
| 85 | + } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | + $this->set_id( $form->ID ); |
|
| 87 | + } else { |
|
| 88 | + $this->set_object_read( true ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | // Load the datastore. |
| 92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 93 | 93 | |
| 94 | - if ( $this->get_id() > 0 ) { |
|
| 94 | + if ( $this->get_id() > 0 ) { |
|
| 95 | 95 | $this->post = get_post( $this->get_id() ); |
| 96 | - $this->data_store->read( $this ); |
|
| 96 | + $this->data_store->read( $this ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | /* |
| 102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,358 +114,358 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | - * Get plugin version when the form was created. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * @param string $context View or edit context. |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function get_version( $context = 'view' ) { |
|
| 124 | - return $this->get_prop( 'version', $context ); |
|
| 117 | + * Get plugin version when the form was created. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * @param string $context View or edit context. |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function get_version( $context = 'view' ) { |
|
| 124 | + return $this->get_prop( 'version', $context ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | - * Get date when the form was created. |
|
| 129 | - * |
|
| 130 | - * @since 1.0.19 |
|
| 131 | - * @param string $context View or edit context. |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function get_date_created( $context = 'view' ) { |
|
| 135 | - return $this->get_prop( 'date_created', $context ); |
|
| 128 | + * Get date when the form was created. |
|
| 129 | + * |
|
| 130 | + * @since 1.0.19 |
|
| 131 | + * @param string $context View or edit context. |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function get_date_created( $context = 'view' ) { |
|
| 135 | + return $this->get_prop( 'date_created', $context ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * Get GMT date when the form was created. |
|
| 140 | - * |
|
| 141 | - * @since 1.0.19 |
|
| 142 | - * @param string $context View or edit context. |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 139 | + * Get GMT date when the form was created. |
|
| 140 | + * |
|
| 141 | + * @since 1.0.19 |
|
| 142 | + * @param string $context View or edit context. |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 146 | 146 | $date = $this->get_date_created( $context ); |
| 147 | 147 | |
| 148 | 148 | if ( $date ) { |
| 149 | 149 | $date = get_gmt_from_date( $date ); |
| 150 | 150 | } |
| 151 | - return $date; |
|
| 151 | + return $date; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * Get date when the form was last modified. |
|
| 156 | - * |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @param string $context View or edit context. |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - public function get_date_modified( $context = 'view' ) { |
|
| 162 | - return $this->get_prop( 'date_modified', $context ); |
|
| 155 | + * Get date when the form was last modified. |
|
| 156 | + * |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @param string $context View or edit context. |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + public function get_date_modified( $context = 'view' ) { |
|
| 162 | + return $this->get_prop( 'date_modified', $context ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * Get GMT date when the form was last modified. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @param string $context View or edit context. |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 166 | + * Get GMT date when the form was last modified. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @param string $context View or edit context. |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 173 | 173 | $date = $this->get_date_modified( $context ); |
| 174 | 174 | |
| 175 | 175 | if ( $date ) { |
| 176 | 176 | $date = get_gmt_from_date( $date ); |
| 177 | 177 | } |
| 178 | - return $date; |
|
| 178 | + return $date; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | - * Get the form name. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function get_name( $context = 'view' ) { |
|
| 189 | - return $this->get_prop( 'name', $context ); |
|
| 182 | + * Get the form name. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function get_name( $context = 'view' ) { |
|
| 189 | + return $this->get_prop( 'name', $context ); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | - * Alias of self::get_name(). |
|
| 194 | - * |
|
| 195 | - * @since 1.0.19 |
|
| 196 | - * @param string $context View or edit context. |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function get_title( $context = 'view' ) { |
|
| 200 | - return $this->get_name( $context ); |
|
| 201 | - } |
|
| 193 | + * Alias of self::get_name(). |
|
| 194 | + * |
|
| 195 | + * @since 1.0.19 |
|
| 196 | + * @param string $context View or edit context. |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function get_title( $context = 'view' ) { |
|
| 200 | + return $this->get_name( $context ); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * Get the owner of the form. |
|
| 205 | - * |
|
| 206 | - * @since 1.0.19 |
|
| 207 | - * @param string $context View or edit context. |
|
| 208 | - * @return int |
|
| 209 | - */ |
|
| 210 | - public function get_author( $context = 'view' ) { |
|
| 211 | - return (int) $this->get_prop( 'author', $context ); |
|
| 204 | + * Get the owner of the form. |
|
| 205 | + * |
|
| 206 | + * @since 1.0.19 |
|
| 207 | + * @param string $context View or edit context. |
|
| 208 | + * @return int |
|
| 209 | + */ |
|
| 210 | + public function get_author( $context = 'view' ) { |
|
| 211 | + return (int) $this->get_prop( 'author', $context ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * Get the elements that make up the form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - * @param string $context View or edit context. |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - public function get_elements( $context = 'view' ) { |
|
| 222 | - $elements = $this->get_prop( 'elements', $context ); |
|
| 215 | + * Get the elements that make up the form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + * @param string $context View or edit context. |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + public function get_elements( $context = 'view' ) { |
|
| 222 | + $elements = $this->get_prop( 'elements', $context ); |
|
| 223 | 223 | |
| 224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - // Ensure that all required elements exist. |
|
| 229 | - $_elements = array(); |
|
| 230 | - foreach ( $elements as $element ) { |
|
| 228 | + // Ensure that all required elements exist. |
|
| 229 | + $_elements = array(); |
|
| 230 | + foreach ( $elements as $element ) { |
|
| 231 | 231 | |
| 232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 233 | 233 | |
| 234 | - $_elements[] = array( |
|
| 235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | - 'id' => 'gtscicd', |
|
| 237 | - 'name' => 'gtscicd', |
|
| 238 | - 'type' => 'gateway_select', |
|
| 239 | - 'premade' => true |
|
| 234 | + $_elements[] = array( |
|
| 235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 236 | + 'id' => 'gtscicd', |
|
| 237 | + 'name' => 'gtscicd', |
|
| 238 | + 'type' => 'gateway_select', |
|
| 239 | + 'premade' => true |
|
| 240 | 240 | |
| 241 | - ); |
|
| 241 | + ); |
|
| 242 | 242 | |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $_elements[] = $element; |
|
| 245 | + $_elements[] = $element; |
|
| 246 | 246 | |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | return $_elements; |
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Get the items sold via the form. |
|
| 254 | - * |
|
| 255 | - * @since 1.0.19 |
|
| 256 | - * @param string $context View or edit context. |
|
| 257 | - * @param string $return objects or arrays. |
|
| 258 | - * @return GetPaid_Form_Item[] |
|
| 259 | - */ |
|
| 260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | - $items = $this->get_prop( 'items', $context ); |
|
| 262 | - |
|
| 263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Get the items sold via the form. |
|
| 254 | + * |
|
| 255 | + * @since 1.0.19 |
|
| 256 | + * @param string $context View or edit context. |
|
| 257 | + * @param string $return objects or arrays. |
|
| 258 | + * @return GetPaid_Form_Item[] |
|
| 259 | + */ |
|
| 260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | + $items = $this->get_prop( 'items', $context ); |
|
| 262 | + |
|
| 263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
| 265 | - } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // Convert the items. |
|
| 268 | + $prepared = array(); |
|
| 266 | 269 | |
| 267 | - // Convert the items. |
|
| 268 | - $prepared = array(); |
|
| 270 | + foreach ( $items as $key => $value ) { |
|
| 269 | 271 | |
| 270 | - foreach ( $items as $key => $value ) { |
|
| 272 | + // Form items. |
|
| 273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
| 271 | 274 | |
| 272 | - // Form items. |
|
| 273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
| 275 | + if ( $value->can_purchase() ) { |
|
| 276 | + $prepared[] = $value; |
|
| 277 | + } |
|
| 274 | 278 | |
| 275 | - if ( $value->can_purchase() ) { |
|
| 276 | - $prepared[] = $value; |
|
| 277 | - } |
|
| 279 | + continue; |
|
| 278 | 280 | |
| 279 | - continue; |
|
| 281 | + } |
|
| 280 | 282 | |
| 281 | - } |
|
| 283 | + // $item_id => $quantity (buy buttons) |
|
| 284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | + $item = new GetPaid_Form_Item( $key ); |
|
| 282 | 286 | |
| 283 | - // $item_id => $quantity (buy buttons) |
|
| 284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | - $item = new GetPaid_Form_Item( $key ); |
|
| 287 | + if ( $item->can_purchase() ) { |
|
| 286 | 288 | |
| 287 | - if ( $item->can_purchase() ) { |
|
| 289 | + $value = (float) $value; |
|
| 290 | + $item->set_quantity( $value ); |
|
| 291 | + if ( 0 == $value ) { |
|
| 292 | + $item->set_quantity( 1 ); |
|
| 293 | + $item->set_allow_quantities( true ); |
|
| 294 | + } |
|
| 288 | 295 | |
| 289 | - $value = (float) $value; |
|
| 290 | - $item->set_quantity( $value ); |
|
| 291 | - if ( 0 == $value ) { |
|
| 292 | - $item->set_quantity( 1 ); |
|
| 293 | - $item->set_allow_quantities( true ); |
|
| 294 | - } |
|
| 296 | + $prepared[] = $item; |
|
| 297 | + } |
|
| 295 | 298 | |
| 296 | - $prepared[] = $item; |
|
| 297 | - } |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 298 | 301 | |
| 299 | - continue; |
|
| 300 | - } |
|
| 302 | + // Items saved via payment forms editor. |
|
| 303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 301 | 304 | |
| 302 | - // Items saved via payment forms editor. |
|
| 303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 304 | 306 | |
| 305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 307 | + if ( ! $item->can_purchase() ) { |
|
| 308 | + continue; |
|
| 309 | + } |
|
| 306 | 310 | |
| 307 | - if ( ! $item->can_purchase() ) { |
|
| 308 | - continue; |
|
| 309 | - } |
|
| 311 | + // Sub-total (Cart items). |
|
| 312 | + if ( isset( $value['subtotal'] ) ) { |
|
| 313 | + $item->set_price( $value['subtotal'] ); |
|
| 314 | + } |
|
| 310 | 315 | |
| 311 | - // Sub-total (Cart items). |
|
| 312 | - if ( isset( $value['subtotal'] ) ) { |
|
| 313 | - $item->set_price( $value['subtotal'] ); |
|
| 314 | - } |
|
| 316 | + if ( isset( $value['quantity'] ) ) { |
|
| 317 | + $item->set_quantity( $value['quantity'] ); |
|
| 318 | + } |
|
| 315 | 319 | |
| 316 | - if ( isset( $value['quantity'] ) ) { |
|
| 317 | - $item->set_quantity( $value['quantity'] ); |
|
| 318 | - } |
|
| 320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | + } |
|
| 319 | 323 | |
| 320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 322 | - } |
|
| 324 | + if ( isset( $value['required'] ) ) { |
|
| 325 | + $item->set_is_required( $value['required'] ); |
|
| 326 | + } |
|
| 323 | 327 | |
| 324 | - if ( isset( $value['required'] ) ) { |
|
| 325 | - $item->set_is_required( $value['required'] ); |
|
| 326 | - } |
|
| 328 | + if ( isset( $value['description'] ) ) { |
|
| 329 | + $item->set_custom_description( $value['description'] ); |
|
| 330 | + } |
|
| 327 | 331 | |
| 328 | - if ( isset( $value['description'] ) ) { |
|
| 329 | - $item->set_custom_description( $value['description'] ); |
|
| 330 | - } |
|
| 332 | + $prepared[] = $item; |
|
| 333 | + continue; |
|
| 331 | 334 | |
| 332 | - $prepared[] = $item; |
|
| 333 | - continue; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | + $item = new GetPaid_Form_Item( $key ); |
|
| 340 | + |
|
| 341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | + $item->set_price( $value['price'] ); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( $item->can_purchase() ) { |
|
| 346 | + $prepared[] = $item; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + continue; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
| 355 | + return $prepared; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $items = array(); |
|
| 359 | + foreach ( $prepared as $item ) { |
|
| 360 | + $items[] = $item->prepare_data_for_use(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $items; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Get a single item belonging to the form. |
|
| 368 | + * |
|
| 369 | + * @since 1.0.19 |
|
| 370 | + * @param int $item_id The item id to return. |
|
| 371 | + * @return GetPaid_Form_Item|bool |
|
| 372 | + */ |
|
| 373 | + public function get_item( $item_id ) { |
|
| 374 | + |
|
| 375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + foreach( $this->get_items() as $item ) { |
|
| 380 | + if ( $item->get_id() == (int) $item_id ) { |
|
| 381 | + return $item; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return false; |
|
| 386 | + |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Gets a single element. |
|
| 391 | + * |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + * @param string $element_type The element type to return. |
|
| 394 | + * @return array|bool |
|
| 395 | + */ |
|
| 396 | + public function get_element_type( $element_type ) { |
|
| 397 | + |
|
| 398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 403 | + |
|
| 404 | + if ( $element['type'] == $element_type ) { |
|
| 405 | + return $element; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return false; |
|
| 411 | + |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Get the total amount earned via this form. |
|
| 416 | + * |
|
| 417 | + * @since 1.0.19 |
|
| 418 | + * @param string $context View or edit context. |
|
| 419 | + * @return float |
|
| 420 | + */ |
|
| 421 | + public function get_earned( $context = 'view' ) { |
|
| 422 | + return $this->get_prop( 'earned', $context ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Get the total amount refunded via this form. |
|
| 427 | + * |
|
| 428 | + * @since 1.0.19 |
|
| 429 | + * @param string $context View or edit context. |
|
| 430 | + * @return float |
|
| 431 | + */ |
|
| 432 | + public function get_refunded( $context = 'view' ) { |
|
| 433 | + return $this->get_prop( 'refunded', $context ); |
|
| 434 | + } |
|
| 334 | 435 | |
| 335 | - } |
|
| 436 | + /** |
|
| 437 | + * Get the total amount cancelled via this form. |
|
| 438 | + * |
|
| 439 | + * @since 1.0.19 |
|
| 440 | + * @param string $context View or edit context. |
|
| 441 | + * @return float |
|
| 442 | + */ |
|
| 443 | + public function get_cancelled( $context = 'view' ) { |
|
| 444 | + return $this->get_prop( 'cancelled', $context ); |
|
| 445 | + } |
|
| 336 | 446 | |
| 337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
| 338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | - $item = new GetPaid_Form_Item( $key ); |
|
| 447 | + /** |
|
| 448 | + * Get the total amount failed via this form. |
|
| 449 | + * |
|
| 450 | + * @since 1.0.19 |
|
| 451 | + * @param string $context View or edit context. |
|
| 452 | + * @return float |
|
| 453 | + */ |
|
| 454 | + public function get_failed( $context = 'view' ) { |
|
| 455 | + return $this->get_prop( 'failed', $context ); |
|
| 456 | + } |
|
| 340 | 457 | |
| 341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | - $item->set_price( $value['price'] ); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( $item->can_purchase() ) { |
|
| 346 | - $prepared[] = $item; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - continue; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
| 355 | - return $prepared; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $items = array(); |
|
| 359 | - foreach ( $prepared as $item ) { |
|
| 360 | - $items[] = $item->prepare_data_for_use(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $items; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Get a single item belonging to the form. |
|
| 368 | - * |
|
| 369 | - * @since 1.0.19 |
|
| 370 | - * @param int $item_id The item id to return. |
|
| 371 | - * @return GetPaid_Form_Item|bool |
|
| 372 | - */ |
|
| 373 | - public function get_item( $item_id ) { |
|
| 374 | - |
|
| 375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - foreach( $this->get_items() as $item ) { |
|
| 380 | - if ( $item->get_id() == (int) $item_id ) { |
|
| 381 | - return $item; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return false; |
|
| 386 | - |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Gets a single element. |
|
| 391 | - * |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - * @param string $element_type The element type to return. |
|
| 394 | - * @return array|bool |
|
| 395 | - */ |
|
| 396 | - public function get_element_type( $element_type ) { |
|
| 397 | - |
|
| 398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 399 | - return false; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 403 | - |
|
| 404 | - if ( $element['type'] == $element_type ) { |
|
| 405 | - return $element; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return false; |
|
| 411 | - |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Get the total amount earned via this form. |
|
| 416 | - * |
|
| 417 | - * @since 1.0.19 |
|
| 418 | - * @param string $context View or edit context. |
|
| 419 | - * @return float |
|
| 420 | - */ |
|
| 421 | - public function get_earned( $context = 'view' ) { |
|
| 422 | - return $this->get_prop( 'earned', $context ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Get the total amount refunded via this form. |
|
| 427 | - * |
|
| 428 | - * @since 1.0.19 |
|
| 429 | - * @param string $context View or edit context. |
|
| 430 | - * @return float |
|
| 431 | - */ |
|
| 432 | - public function get_refunded( $context = 'view' ) { |
|
| 433 | - return $this->get_prop( 'refunded', $context ); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Get the total amount cancelled via this form. |
|
| 438 | - * |
|
| 439 | - * @since 1.0.19 |
|
| 440 | - * @param string $context View or edit context. |
|
| 441 | - * @return float |
|
| 442 | - */ |
|
| 443 | - public function get_cancelled( $context = 'view' ) { |
|
| 444 | - return $this->get_prop( 'cancelled', $context ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Get the total amount failed via this form. |
|
| 449 | - * |
|
| 450 | - * @since 1.0.19 |
|
| 451 | - * @param string $context View or edit context. |
|
| 452 | - * @return float |
|
| 453 | - */ |
|
| 454 | - public function get_failed( $context = 'view' ) { |
|
| 455 | - return $this->get_prop( 'failed', $context ); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Get the currency. |
|
| 460 | - * |
|
| 461 | - * @since 1.0.19 |
|
| 462 | - * @param string $context View or edit context. |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function get_currency() { |
|
| 466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 468 | - } |
|
| 458 | + /** |
|
| 459 | + * Get the currency. |
|
| 460 | + * |
|
| 461 | + * @since 1.0.19 |
|
| 462 | + * @param string $context View or edit context. |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function get_currency() { |
|
| 466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 468 | + } |
|
| 469 | 469 | |
| 470 | 470 | /* |
| 471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
| 478 | 478 | */ |
| 479 | 479 | |
| 480 | 480 | /** |
| 481 | - * Set plugin version when the item was created. |
|
| 482 | - * |
|
| 483 | - * @since 1.0.19 |
|
| 484 | - */ |
|
| 485 | - public function set_version( $value ) { |
|
| 486 | - $this->set_prop( 'version', $value ); |
|
| 481 | + * Set plugin version when the item was created. |
|
| 482 | + * |
|
| 483 | + * @since 1.0.19 |
|
| 484 | + */ |
|
| 485 | + public function set_version( $value ) { |
|
| 486 | + $this->set_prop( 'version', $value ); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
| 490 | - * Set date when the item was created. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $value Value to set. |
|
| 490 | + * Set date when the item was created. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $value Value to set. |
|
| 494 | 494 | * @return bool Whether or not the date was set. |
| 495 | - */ |
|
| 496 | - public function set_date_created( $value ) { |
|
| 495 | + */ |
|
| 496 | + public function set_date_created( $value ) { |
|
| 497 | 497 | $date = strtotime( $value ); |
| 498 | 498 | |
| 499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
| 509 | - * Set date when the item was last modified. |
|
| 510 | - * |
|
| 511 | - * @since 1.0.19 |
|
| 512 | - * @param string $value Value to set. |
|
| 509 | + * Set date when the item was last modified. |
|
| 510 | + * |
|
| 511 | + * @since 1.0.19 |
|
| 512 | + * @param string $value Value to set. |
|
| 513 | 513 | * @return bool Whether or not the date was set. |
| 514 | - */ |
|
| 515 | - public function set_date_modified( $value ) { |
|
| 514 | + */ |
|
| 515 | + public function set_date_modified( $value ) { |
|
| 516 | 516 | $date = strtotime( $value ); |
| 517 | 517 | |
| 518 | 518 | if ( $date ) { |
@@ -525,118 +525,118 @@ discard block |
||
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
| 528 | - * Set the item name. |
|
| 529 | - * |
|
| 530 | - * @since 1.0.19 |
|
| 531 | - * @param string $value New name. |
|
| 532 | - */ |
|
| 533 | - public function set_name( $value ) { |
|
| 534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Alias of self::set_name(). |
|
| 539 | - * |
|
| 540 | - * @since 1.0.19 |
|
| 541 | - * @param string $value New name. |
|
| 542 | - */ |
|
| 543 | - public function set_title( $value ) { |
|
| 544 | - $this->set_name( $value ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Set the owner of the item. |
|
| 549 | - * |
|
| 550 | - * @since 1.0.19 |
|
| 551 | - * @param int $value New author. |
|
| 552 | - */ |
|
| 553 | - public function set_author( $value ) { |
|
| 554 | - $this->set_prop( 'author', (int) $value ); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Set the form elements. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param array $value Form elements. |
|
| 562 | - */ |
|
| 563 | - public function set_elements( $value ) { |
|
| 564 | - if ( is_array( $value ) ) { |
|
| 565 | - $this->set_prop( 'elements', $value ); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Set the form items. |
|
| 571 | - * |
|
| 572 | - * @since 1.0.19 |
|
| 573 | - * @param array $value Form elements. |
|
| 574 | - */ |
|
| 575 | - public function set_items( $value ) { |
|
| 576 | - if ( is_array( $value ) ) { |
|
| 577 | - $this->set_prop( 'items', $value ); |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Set the total amount earned via this form. |
|
| 583 | - * |
|
| 584 | - * @since 1.0.19 |
|
| 585 | - * @param float $value Amount earned. |
|
| 586 | - */ |
|
| 587 | - public function set_earned( $value ) { |
|
| 588 | - $value = max( (float) $value, 0 ); |
|
| 589 | - $this->set_prop( 'earned', $value ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Set the total amount refunded via this form. |
|
| 594 | - * |
|
| 595 | - * @since 1.0.19 |
|
| 596 | - * @param float $value Amount refunded. |
|
| 597 | - */ |
|
| 598 | - public function set_refunded( $value ) { |
|
| 599 | - $value = max( (float) $value, 0 ); |
|
| 600 | - $this->set_prop( 'refunded', $value ); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Set the total amount cancelled via this form. |
|
| 605 | - * |
|
| 606 | - * @since 1.0.19 |
|
| 607 | - * @param float $value Amount cancelled. |
|
| 608 | - */ |
|
| 609 | - public function set_cancelled( $value ) { |
|
| 610 | - $value = max( (float) $value, 0 ); |
|
| 611 | - $this->set_prop( 'cancelled', $value ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Set the total amount failed via this form. |
|
| 616 | - * |
|
| 617 | - * @since 1.0.19 |
|
| 618 | - * @param float $value Amount cancelled. |
|
| 619 | - */ |
|
| 620 | - public function set_failed( $value ) { |
|
| 621 | - $value = max( (float) $value, 0 ); |
|
| 622 | - $this->set_prop( 'failed', $value ); |
|
| 623 | - } |
|
| 528 | + * Set the item name. |
|
| 529 | + * |
|
| 530 | + * @since 1.0.19 |
|
| 531 | + * @param string $value New name. |
|
| 532 | + */ |
|
| 533 | + public function set_name( $value ) { |
|
| 534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Alias of self::set_name(). |
|
| 539 | + * |
|
| 540 | + * @since 1.0.19 |
|
| 541 | + * @param string $value New name. |
|
| 542 | + */ |
|
| 543 | + public function set_title( $value ) { |
|
| 544 | + $this->set_name( $value ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Set the owner of the item. |
|
| 549 | + * |
|
| 550 | + * @since 1.0.19 |
|
| 551 | + * @param int $value New author. |
|
| 552 | + */ |
|
| 553 | + public function set_author( $value ) { |
|
| 554 | + $this->set_prop( 'author', (int) $value ); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Set the form elements. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param array $value Form elements. |
|
| 562 | + */ |
|
| 563 | + public function set_elements( $value ) { |
|
| 564 | + if ( is_array( $value ) ) { |
|
| 565 | + $this->set_prop( 'elements', $value ); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Set the form items. |
|
| 571 | + * |
|
| 572 | + * @since 1.0.19 |
|
| 573 | + * @param array $value Form elements. |
|
| 574 | + */ |
|
| 575 | + public function set_items( $value ) { |
|
| 576 | + if ( is_array( $value ) ) { |
|
| 577 | + $this->set_prop( 'items', $value ); |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Set the total amount earned via this form. |
|
| 583 | + * |
|
| 584 | + * @since 1.0.19 |
|
| 585 | + * @param float $value Amount earned. |
|
| 586 | + */ |
|
| 587 | + public function set_earned( $value ) { |
|
| 588 | + $value = max( (float) $value, 0 ); |
|
| 589 | + $this->set_prop( 'earned', $value ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Set the total amount refunded via this form. |
|
| 594 | + * |
|
| 595 | + * @since 1.0.19 |
|
| 596 | + * @param float $value Amount refunded. |
|
| 597 | + */ |
|
| 598 | + public function set_refunded( $value ) { |
|
| 599 | + $value = max( (float) $value, 0 ); |
|
| 600 | + $this->set_prop( 'refunded', $value ); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Set the total amount cancelled via this form. |
|
| 605 | + * |
|
| 606 | + * @since 1.0.19 |
|
| 607 | + * @param float $value Amount cancelled. |
|
| 608 | + */ |
|
| 609 | + public function set_cancelled( $value ) { |
|
| 610 | + $value = max( (float) $value, 0 ); |
|
| 611 | + $this->set_prop( 'cancelled', $value ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Set the total amount failed via this form. |
|
| 616 | + * |
|
| 617 | + * @since 1.0.19 |
|
| 618 | + * @param float $value Amount cancelled. |
|
| 619 | + */ |
|
| 620 | + public function set_failed( $value ) { |
|
| 621 | + $value = max( (float) $value, 0 ); |
|
| 622 | + $this->set_prop( 'failed', $value ); |
|
| 623 | + } |
|
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | 626 | * Create an item. For backwards compatibilty. |
| 627 | 627 | * |
| 628 | 628 | * @deprecated |
| 629 | - * @return int item id |
|
| 629 | + * @return int item id |
|
| 630 | 630 | */ |
| 631 | 631 | public function create( $data = array() ) { |
| 632 | 632 | |
| 633 | - // Set the properties. |
|
| 634 | - if ( is_array( $data ) ) { |
|
| 635 | - $this->set_props( $data ); |
|
| 636 | - } |
|
| 633 | + // Set the properties. |
|
| 634 | + if ( is_array( $data ) ) { |
|
| 635 | + $this->set_props( $data ); |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - // Save the item. |
|
| 639 | - return $this->save(); |
|
| 638 | + // Save the item. |
|
| 639 | + return $this->save(); |
|
| 640 | 640 | |
| 641 | 641 | } |
| 642 | 642 | |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | * Updates an item. For backwards compatibilty. |
| 645 | 645 | * |
| 646 | 646 | * @deprecated |
| 647 | - * @return int item id |
|
| 647 | + * @return int item id |
|
| 648 | 648 | */ |
| 649 | 649 | public function update( $data = array() ) { |
| 650 | 650 | return $this->create( $data ); |
@@ -660,22 +660,22 @@ discard block |
||
| 660 | 660 | */ |
| 661 | 661 | |
| 662 | 662 | /** |
| 663 | - * Checks whether this is the default payment form. |
|
| 664 | - * |
|
| 665 | - * @since 1.0.19 |
|
| 666 | - * @return bool |
|
| 667 | - */ |
|
| 663 | + * Checks whether this is the default payment form. |
|
| 664 | + * |
|
| 665 | + * @since 1.0.19 |
|
| 666 | + * @return bool |
|
| 667 | + */ |
|
| 668 | 668 | public function is_default() { |
| 669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
| 670 | 670 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
| 671 | - } |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | /** |
| 674 | - * Checks whether the form is active. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @return bool |
|
| 678 | - */ |
|
| 674 | + * Checks whether the form is active. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @return bool |
|
| 678 | + */ |
|
| 679 | 679 | public function is_active() { |
| 680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
| 681 | 681 | |
@@ -684,76 +684,76 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Checks whether the form has a given item. |
|
| 691 | - * |
|
| 692 | - * @since 1.0.19 |
|
| 693 | - * @return bool |
|
| 694 | - */ |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Checks whether the form has a given item. |
|
| 691 | + * |
|
| 692 | + * @since 1.0.19 |
|
| 693 | + * @return bool |
|
| 694 | + */ |
|
| 695 | 695 | public function has_item( $item_id ) { |
| 696 | 696 | return false !== $this->get_item( $item_id ); |
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Checks whether the form has a given element. |
|
| 701 | - * |
|
| 702 | - * @since 1.0.19 |
|
| 703 | - * @return bool |
|
| 704 | - */ |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Checks whether the form has a given element. |
|
| 701 | + * |
|
| 702 | + * @since 1.0.19 |
|
| 703 | + * @return bool |
|
| 704 | + */ |
|
| 705 | 705 | public function has_element_type( $element_type ) { |
| 706 | 706 | return false !== $this->get_element_type( $element_type ); |
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Checks whether this form is recurring or not. |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - * @return bool |
|
| 714 | - */ |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Checks whether this form is recurring or not. |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + * @return bool |
|
| 714 | + */ |
|
| 715 | 715 | public function is_recurring() { |
| 716 | 716 | |
| 717 | - if ( ! empty( $this->invoice ) ) { |
|
| 718 | - return $this->invoice->is_recurring(); |
|
| 719 | - } |
|
| 717 | + if ( ! empty( $this->invoice ) ) { |
|
| 718 | + return $this->invoice->is_recurring(); |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - foreach ( $this->get_items() as $item ) { |
|
| 721 | + foreach ( $this->get_items() as $item ) { |
|
| 722 | 722 | |
| 723 | - if ( $item->is_recurring() ) { |
|
| 724 | - return true; |
|
| 725 | - } |
|
| 723 | + if ( $item->is_recurring() ) { |
|
| 724 | + return true; |
|
| 725 | + } |
|
| 726 | 726 | |
| 727 | - } |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | 729 | return false; |
| 730 | - } |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Retrieves the form's html. |
|
| 734 | - * |
|
| 735 | - * @since 1.0.19 |
|
| 736 | - */ |
|
| 732 | + /** |
|
| 733 | + * Retrieves the form's html. |
|
| 734 | + * |
|
| 735 | + * @since 1.0.19 |
|
| 736 | + */ |
|
| 737 | 737 | public function get_html( $extra_markup = '' ) { |
| 738 | 738 | |
| 739 | - // Return the HTML. |
|
| 740 | - return wpinv_get_template_html( |
|
| 741 | - 'payment-forms/form.php', |
|
| 742 | - array( |
|
| 743 | - 'form' => $this, |
|
| 744 | - 'extra_markup' => $extra_markup, |
|
| 745 | - ) |
|
| 746 | - ); |
|
| 747 | - |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Displays the payment form. |
|
| 752 | - * |
|
| 753 | - * @since 1.0.19 |
|
| 754 | - */ |
|
| 739 | + // Return the HTML. |
|
| 740 | + return wpinv_get_template_html( |
|
| 741 | + 'payment-forms/form.php', |
|
| 742 | + array( |
|
| 743 | + 'form' => $this, |
|
| 744 | + 'extra_markup' => $extra_markup, |
|
| 745 | + ) |
|
| 746 | + ); |
|
| 747 | + |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Displays the payment form. |
|
| 752 | + * |
|
| 753 | + * @since 1.0.19 |
|
| 754 | + */ |
|
| 755 | 755 | public function display( $extra_markup = '' ) { |
| 756 | - echo $this->get_html( $extra_markup ); |
|
| 756 | + echo $this->get_html( $extra_markup ); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
| 74 | 74 | */ |
| 75 | - public function __construct( $form = 0 ) { |
|
| 76 | - parent::__construct( $form ); |
|
| 75 | + public function __construct($form = 0) { |
|
| 76 | + parent::__construct($form); |
|
| 77 | 77 | |
| 78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
| 79 | - $this->set_id( $form ); |
|
| 80 | - } elseif ( $form instanceof self ) { |
|
| 78 | + if (is_numeric($form) && $form > 0) { |
|
| 79 | + $this->set_id($form); |
|
| 80 | + } elseif ($form instanceof self) { |
|
| 81 | 81 | |
| 82 | - $this->set_id( $form->get_id() ); |
|
| 82 | + $this->set_id($form->get_id()); |
|
| 83 | 83 | $this->invoice = $form->invoice; |
| 84 | 84 | |
| 85 | - } elseif ( ! empty( $form->ID ) ) { |
|
| 86 | - $this->set_id( $form->ID ); |
|
| 85 | + } elseif (!empty($form->ID)) { |
|
| 86 | + $this->set_id($form->ID); |
|
| 87 | 87 | } else { |
| 88 | - $this->set_object_read( true ); |
|
| 88 | + $this->set_object_read(true); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Load the datastore. |
| 92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 93 | 93 | |
| 94 | - if ( $this->get_id() > 0 ) { |
|
| 95 | - $this->post = get_post( $this->get_id() ); |
|
| 96 | - $this->data_store->read( $this ); |
|
| 94 | + if ($this->get_id() > 0) { |
|
| 95 | + $this->post = get_post($this->get_id()); |
|
| 96 | + $this->data_store->read($this); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * @param string $context View or edit context. |
| 121 | 121 | * @return string |
| 122 | 122 | */ |
| 123 | - public function get_version( $context = 'view' ) { |
|
| 124 | - return $this->get_prop( 'version', $context ); |
|
| 123 | + public function get_version($context = 'view') { |
|
| 124 | + return $this->get_prop('version', $context); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | * @param string $context View or edit context. |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function get_date_created( $context = 'view' ) { |
|
| 135 | - return $this->get_prop( 'date_created', $context ); |
|
| 134 | + public function get_date_created($context = 'view') { |
|
| 135 | + return $this->get_prop('date_created', $context); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | * @param string $context View or edit context. |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 146 | - $date = $this->get_date_created( $context ); |
|
| 145 | + public function get_date_created_gmt($context = 'view') { |
|
| 146 | + $date = $this->get_date_created($context); |
|
| 147 | 147 | |
| 148 | - if ( $date ) { |
|
| 149 | - $date = get_gmt_from_date( $date ); |
|
| 148 | + if ($date) { |
|
| 149 | + $date = get_gmt_from_date($date); |
|
| 150 | 150 | } |
| 151 | 151 | return $date; |
| 152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | * @param string $context View or edit context. |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - public function get_date_modified( $context = 'view' ) { |
|
| 162 | - return $this->get_prop( 'date_modified', $context ); |
|
| 161 | + public function get_date_modified($context = 'view') { |
|
| 162 | + return $this->get_prop('date_modified', $context); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
| 169 | 169 | * @param string $context View or edit context. |
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 173 | - $date = $this->get_date_modified( $context ); |
|
| 172 | + public function get_date_modified_gmt($context = 'view') { |
|
| 173 | + $date = $this->get_date_modified($context); |
|
| 174 | 174 | |
| 175 | - if ( $date ) { |
|
| 176 | - $date = get_gmt_from_date( $date ); |
|
| 175 | + if ($date) { |
|
| 176 | + $date = get_gmt_from_date($date); |
|
| 177 | 177 | } |
| 178 | 178 | return $date; |
| 179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | * @param string $context View or edit context. |
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | - public function get_name( $context = 'view' ) { |
|
| 189 | - return $this->get_prop( 'name', $context ); |
|
| 188 | + public function get_name($context = 'view') { |
|
| 189 | + return $this->get_prop('name', $context); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | * @param string $context View or edit context. |
| 197 | 197 | * @return string |
| 198 | 198 | */ |
| 199 | - public function get_title( $context = 'view' ) { |
|
| 200 | - return $this->get_name( $context ); |
|
| 199 | + public function get_title($context = 'view') { |
|
| 200 | + return $this->get_name($context); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | * @param string $context View or edit context. |
| 208 | 208 | * @return int |
| 209 | 209 | */ |
| 210 | - public function get_author( $context = 'view' ) { |
|
| 211 | - return (int) $this->get_prop( 'author', $context ); |
|
| 210 | + public function get_author($context = 'view') { |
|
| 211 | + return (int) $this->get_prop('author', $context); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
| 218 | 218 | * @param string $context View or edit context. |
| 219 | 219 | * @return array |
| 220 | 220 | */ |
| 221 | - public function get_elements( $context = 'view' ) { |
|
| 222 | - $elements = $this->get_prop( 'elements', $context ); |
|
| 221 | + public function get_elements($context = 'view') { |
|
| 222 | + $elements = $this->get_prop('elements', $context); |
|
| 223 | 223 | |
| 224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
| 225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
| 224 | + if (empty($elements) || !is_array($elements)) { |
|
| 225 | + return wpinv_get_data('sample-payment-form'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Ensure that all required elements exist. |
| 229 | 229 | $_elements = array(); |
| 230 | - foreach ( $elements as $element ) { |
|
| 230 | + foreach ($elements as $element) { |
|
| 231 | 231 | |
| 232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
| 232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
| 233 | 233 | |
| 234 | 234 | $_elements[] = array( |
| 235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
| 236 | 236 | 'id' => 'gtscicd', |
| 237 | 237 | 'name' => 'gtscicd', |
| 238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
| 257 | 257 | * @param string $return objects or arrays. |
| 258 | 258 | * @return GetPaid_Form_Item[] |
| 259 | 259 | */ |
| 260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
| 261 | - $items = $this->get_prop( 'items', $context ); |
|
| 260 | + public function get_items($context = 'view', $return = 'objects') { |
|
| 261 | + $items = $this->get_prop('items', $context); |
|
| 262 | 262 | |
| 263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
| 264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
| 263 | + if (empty($items) || !is_array($items)) { |
|
| 264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Convert the items. |
| 268 | 268 | $prepared = array(); |
| 269 | 269 | |
| 270 | - foreach ( $items as $key => $value ) { |
|
| 270 | + foreach ($items as $key => $value) { |
|
| 271 | 271 | |
| 272 | 272 | // Form items. |
| 273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
| 273 | + if ($value instanceof GetPaid_Form_Item) { |
|
| 274 | 274 | |
| 275 | - if ( $value->can_purchase() ) { |
|
| 275 | + if ($value->can_purchase()) { |
|
| 276 | 276 | $prepared[] = $value; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // $item_id => $quantity (buy buttons) |
| 284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
| 285 | - $item = new GetPaid_Form_Item( $key ); |
|
| 284 | + if (is_numeric($key) && is_numeric($value)) { |
|
| 285 | + $item = new GetPaid_Form_Item($key); |
|
| 286 | 286 | |
| 287 | - if ( $item->can_purchase() ) { |
|
| 287 | + if ($item->can_purchase()) { |
|
| 288 | 288 | |
| 289 | 289 | $value = (float) $value; |
| 290 | - $item->set_quantity( $value ); |
|
| 291 | - if ( 0 == $value ) { |
|
| 292 | - $item->set_quantity( 1 ); |
|
| 293 | - $item->set_allow_quantities( true ); |
|
| 290 | + $item->set_quantity($value); |
|
| 291 | + if (0 == $value) { |
|
| 292 | + $item->set_quantity(1); |
|
| 293 | + $item->set_allow_quantities(true); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Items saved via payment forms editor. |
| 303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
| 303 | + if (is_array($value) && isset($value['id'])) { |
|
| 304 | 304 | |
| 305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
| 305 | + $item = new GetPaid_Form_Item($value['id']); |
|
| 306 | 306 | |
| 307 | - if ( ! $item->can_purchase() ) { |
|
| 307 | + if (!$item->can_purchase()) { |
|
| 308 | 308 | continue; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Sub-total (Cart items). |
| 312 | - if ( isset( $value['subtotal'] ) ) { |
|
| 313 | - $item->set_price( $value['subtotal'] ); |
|
| 312 | + if (isset($value['subtotal'])) { |
|
| 313 | + $item->set_price($value['subtotal']); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if ( isset( $value['quantity'] ) ) { |
|
| 317 | - $item->set_quantity( $value['quantity'] ); |
|
| 316 | + if (isset($value['quantity'])) { |
|
| 317 | + $item->set_quantity($value['quantity']); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
| 321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
| 320 | + if (isset($value['allow_quantities'])) { |
|
| 321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( isset( $value['required'] ) ) { |
|
| 325 | - $item->set_is_required( $value['required'] ); |
|
| 324 | + if (isset($value['required'])) { |
|
| 325 | + $item->set_is_required($value['required']); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if ( isset( $value['description'] ) ) { |
|
| 329 | - $item->set_custom_description( $value['description'] ); |
|
| 328 | + if (isset($value['description'])) { |
|
| 329 | + $item->set_custom_description($value['description']); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
| 338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
| 339 | - $item = new GetPaid_Form_Item( $key ); |
|
| 338 | + if (is_numeric($key) && is_array($value)) { |
|
| 339 | + $item = new GetPaid_Form_Item($key); |
|
| 340 | 340 | |
| 341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
| 342 | - $item->set_price( $value['price'] ); |
|
| 341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
| 342 | + $item->set_price($value['price']); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if ( $item->can_purchase() ) { |
|
| 345 | + if ($item->can_purchase()) { |
|
| 346 | 346 | $prepared[] = $item; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -351,12 +351,12 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
| 354 | + if ('objects' == $return && 'view' == $context) { |
|
| 355 | 355 | return $prepared; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $items = array(); |
| 359 | - foreach ( $prepared as $item ) { |
|
| 359 | + foreach ($prepared as $item) { |
|
| 360 | 360 | $items[] = $item->prepare_data_for_use(); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -370,14 +370,14 @@ discard block |
||
| 370 | 370 | * @param int $item_id The item id to return. |
| 371 | 371 | * @return GetPaid_Form_Item|bool |
| 372 | 372 | */ |
| 373 | - public function get_item( $item_id ) { |
|
| 373 | + public function get_item($item_id) { |
|
| 374 | 374 | |
| 375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
| 375 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
| 376 | 376 | return false; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - foreach( $this->get_items() as $item ) { |
|
| 380 | - if ( $item->get_id() == (int) $item_id ) { |
|
| 379 | + foreach ($this->get_items() as $item) { |
|
| 380 | + if ($item->get_id() == (int) $item_id) { |
|
| 381 | 381 | return $item; |
| 382 | 382 | } |
| 383 | 383 | } |
@@ -393,15 +393,15 @@ discard block |
||
| 393 | 393 | * @param string $element_type The element type to return. |
| 394 | 394 | * @return array|bool |
| 395 | 395 | */ |
| 396 | - public function get_element_type( $element_type ) { |
|
| 396 | + public function get_element_type($element_type) { |
|
| 397 | 397 | |
| 398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
| 398 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
| 399 | 399 | return false; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
| 402 | + foreach ($this->get_prop('elements') as $element) { |
|
| 403 | 403 | |
| 404 | - if ( $element['type'] == $element_type ) { |
|
| 404 | + if ($element['type'] == $element_type) { |
|
| 405 | 405 | return $element; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | * @param string $context View or edit context. |
| 419 | 419 | * @return float |
| 420 | 420 | */ |
| 421 | - public function get_earned( $context = 'view' ) { |
|
| 422 | - return $this->get_prop( 'earned', $context ); |
|
| 421 | + public function get_earned($context = 'view') { |
|
| 422 | + return $this->get_prop('earned', $context); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * @param string $context View or edit context. |
| 430 | 430 | * @return float |
| 431 | 431 | */ |
| 432 | - public function get_refunded( $context = 'view' ) { |
|
| 433 | - return $this->get_prop( 'refunded', $context ); |
|
| 432 | + public function get_refunded($context = 'view') { |
|
| 433 | + return $this->get_prop('refunded', $context); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @param string $context View or edit context. |
| 441 | 441 | * @return float |
| 442 | 442 | */ |
| 443 | - public function get_cancelled( $context = 'view' ) { |
|
| 444 | - return $this->get_prop( 'cancelled', $context ); |
|
| 443 | + public function get_cancelled($context = 'view') { |
|
| 444 | + return $this->get_prop('cancelled', $context); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
| 451 | 451 | * @param string $context View or edit context. |
| 452 | 452 | * @return float |
| 453 | 453 | */ |
| 454 | - public function get_failed( $context = 'view' ) { |
|
| 455 | - return $this->get_prop( 'failed', $context ); |
|
| 454 | + public function get_failed($context = 'view') { |
|
| 455 | + return $this->get_prop('failed', $context); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -463,8 +463,8 @@ discard block |
||
| 463 | 463 | * @return string |
| 464 | 464 | */ |
| 465 | 465 | public function get_currency() { |
| 466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
| 466 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
| 467 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /* |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * |
| 483 | 483 | * @since 1.0.19 |
| 484 | 484 | */ |
| 485 | - public function set_version( $value ) { |
|
| 486 | - $this->set_prop( 'version', $value ); |
|
| 485 | + public function set_version($value) { |
|
| 486 | + $this->set_prop('version', $value); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,11 +493,11 @@ discard block |
||
| 493 | 493 | * @param string $value Value to set. |
| 494 | 494 | * @return bool Whether or not the date was set. |
| 495 | 495 | */ |
| 496 | - public function set_date_created( $value ) { |
|
| 497 | - $date = strtotime( $value ); |
|
| 496 | + public function set_date_created($value) { |
|
| 497 | + $date = strtotime($value); |
|
| 498 | 498 | |
| 499 | - if ( $date ) { |
|
| 500 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 499 | + if ($date) { |
|
| 500 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 501 | 501 | return true; |
| 502 | 502 | } |
| 503 | 503 | |
@@ -512,11 +512,11 @@ discard block |
||
| 512 | 512 | * @param string $value Value to set. |
| 513 | 513 | * @return bool Whether or not the date was set. |
| 514 | 514 | */ |
| 515 | - public function set_date_modified( $value ) { |
|
| 516 | - $date = strtotime( $value ); |
|
| 515 | + public function set_date_modified($value) { |
|
| 516 | + $date = strtotime($value); |
|
| 517 | 517 | |
| 518 | - if ( $date ) { |
|
| 519 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 518 | + if ($date) { |
|
| 519 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 520 | 520 | return true; |
| 521 | 521 | } |
| 522 | 522 | |
@@ -530,8 +530,8 @@ discard block |
||
| 530 | 530 | * @since 1.0.19 |
| 531 | 531 | * @param string $value New name. |
| 532 | 532 | */ |
| 533 | - public function set_name( $value ) { |
|
| 534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
| 533 | + public function set_name($value) { |
|
| 534 | + $this->set_prop('name', sanitize_text_field($value)); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | * @since 1.0.19 |
| 541 | 541 | * @param string $value New name. |
| 542 | 542 | */ |
| 543 | - public function set_title( $value ) { |
|
| 544 | - $this->set_name( $value ); |
|
| 543 | + public function set_title($value) { |
|
| 544 | + $this->set_name($value); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -550,8 +550,8 @@ discard block |
||
| 550 | 550 | * @since 1.0.19 |
| 551 | 551 | * @param int $value New author. |
| 552 | 552 | */ |
| 553 | - public function set_author( $value ) { |
|
| 554 | - $this->set_prop( 'author', (int) $value ); |
|
| 553 | + public function set_author($value) { |
|
| 554 | + $this->set_prop('author', (int) $value); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -560,9 +560,9 @@ discard block |
||
| 560 | 560 | * @since 1.0.19 |
| 561 | 561 | * @param array $value Form elements. |
| 562 | 562 | */ |
| 563 | - public function set_elements( $value ) { |
|
| 564 | - if ( is_array( $value ) ) { |
|
| 565 | - $this->set_prop( 'elements', $value ); |
|
| 563 | + public function set_elements($value) { |
|
| 564 | + if (is_array($value)) { |
|
| 565 | + $this->set_prop('elements', $value); |
|
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
@@ -572,9 +572,9 @@ discard block |
||
| 572 | 572 | * @since 1.0.19 |
| 573 | 573 | * @param array $value Form elements. |
| 574 | 574 | */ |
| 575 | - public function set_items( $value ) { |
|
| 576 | - if ( is_array( $value ) ) { |
|
| 577 | - $this->set_prop( 'items', $value ); |
|
| 575 | + public function set_items($value) { |
|
| 576 | + if (is_array($value)) { |
|
| 577 | + $this->set_prop('items', $value); |
|
| 578 | 578 | } |
| 579 | 579 | } |
| 580 | 580 | |
@@ -584,9 +584,9 @@ discard block |
||
| 584 | 584 | * @since 1.0.19 |
| 585 | 585 | * @param float $value Amount earned. |
| 586 | 586 | */ |
| 587 | - public function set_earned( $value ) { |
|
| 588 | - $value = max( (float) $value, 0 ); |
|
| 589 | - $this->set_prop( 'earned', $value ); |
|
| 587 | + public function set_earned($value) { |
|
| 588 | + $value = max((float) $value, 0); |
|
| 589 | + $this->set_prop('earned', $value); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -595,9 +595,9 @@ discard block |
||
| 595 | 595 | * @since 1.0.19 |
| 596 | 596 | * @param float $value Amount refunded. |
| 597 | 597 | */ |
| 598 | - public function set_refunded( $value ) { |
|
| 599 | - $value = max( (float) $value, 0 ); |
|
| 600 | - $this->set_prop( 'refunded', $value ); |
|
| 598 | + public function set_refunded($value) { |
|
| 599 | + $value = max((float) $value, 0); |
|
| 600 | + $this->set_prop('refunded', $value); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -606,9 +606,9 @@ discard block |
||
| 606 | 606 | * @since 1.0.19 |
| 607 | 607 | * @param float $value Amount cancelled. |
| 608 | 608 | */ |
| 609 | - public function set_cancelled( $value ) { |
|
| 610 | - $value = max( (float) $value, 0 ); |
|
| 611 | - $this->set_prop( 'cancelled', $value ); |
|
| 609 | + public function set_cancelled($value) { |
|
| 610 | + $value = max((float) $value, 0); |
|
| 611 | + $this->set_prop('cancelled', $value); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -617,9 +617,9 @@ discard block |
||
| 617 | 617 | * @since 1.0.19 |
| 618 | 618 | * @param float $value Amount cancelled. |
| 619 | 619 | */ |
| 620 | - public function set_failed( $value ) { |
|
| 621 | - $value = max( (float) $value, 0 ); |
|
| 622 | - $this->set_prop( 'failed', $value ); |
|
| 620 | + public function set_failed($value) { |
|
| 621 | + $value = max((float) $value, 0); |
|
| 622 | + $this->set_prop('failed', $value); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -628,11 +628,11 @@ discard block |
||
| 628 | 628 | * @deprecated |
| 629 | 629 | * @return int item id |
| 630 | 630 | */ |
| 631 | - public function create( $data = array() ) { |
|
| 631 | + public function create($data = array()) { |
|
| 632 | 632 | |
| 633 | 633 | // Set the properties. |
| 634 | - if ( is_array( $data ) ) { |
|
| 635 | - $this->set_props( $data ); |
|
| 634 | + if (is_array($data)) { |
|
| 635 | + $this->set_props($data); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Save the item. |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | * @deprecated |
| 647 | 647 | * @return int item id |
| 648 | 648 | */ |
| 649 | - public function update( $data = array() ) { |
|
| 650 | - return $this->create( $data ); |
|
| 649 | + public function update($data = array()) { |
|
| 650 | + return $this->create($data); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /* |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | */ |
| 668 | 668 | public function is_default() { |
| 669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
| 670 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
| 670 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -679,11 +679,11 @@ discard block |
||
| 679 | 679 | public function is_active() { |
| 680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
| 681 | 681 | |
| 682 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
| 682 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
| 683 | 683 | $is_active = false; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
| 686 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -692,8 +692,8 @@ discard block |
||
| 692 | 692 | * @since 1.0.19 |
| 693 | 693 | * @return bool |
| 694 | 694 | */ |
| 695 | - public function has_item( $item_id ) { |
|
| 696 | - return false !== $this->get_item( $item_id ); |
|
| 695 | + public function has_item($item_id) { |
|
| 696 | + return false !== $this->get_item($item_id); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | * @since 1.0.19 |
| 703 | 703 | * @return bool |
| 704 | 704 | */ |
| 705 | - public function has_element_type( $element_type ) { |
|
| 706 | - return false !== $this->get_element_type( $element_type ); |
|
| 705 | + public function has_element_type($element_type) { |
|
| 706 | + return false !== $this->get_element_type($element_type); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -714,13 +714,13 @@ discard block |
||
| 714 | 714 | */ |
| 715 | 715 | public function is_recurring() { |
| 716 | 716 | |
| 717 | - if ( ! empty( $this->invoice ) ) { |
|
| 717 | + if (!empty($this->invoice)) { |
|
| 718 | 718 | return $this->invoice->is_recurring(); |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - foreach ( $this->get_items() as $item ) { |
|
| 721 | + foreach ($this->get_items() as $item) { |
|
| 722 | 722 | |
| 723 | - if ( $item->is_recurring() ) { |
|
| 723 | + if ($item->is_recurring()) { |
|
| 724 | 724 | return true; |
| 725 | 725 | } |
| 726 | 726 | |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * |
| 735 | 735 | * @since 1.0.19 |
| 736 | 736 | */ |
| 737 | - public function get_html( $extra_markup = '' ) { |
|
| 737 | + public function get_html($extra_markup = '') { |
|
| 738 | 738 | |
| 739 | 739 | // Return the HTML. |
| 740 | 740 | return wpinv_get_template_html( |
@@ -752,8 +752,8 @@ discard block |
||
| 752 | 752 | * |
| 753 | 753 | * @since 1.0.19 |
| 754 | 754 | */ |
| 755 | - public function display( $extra_markup = '' ) { |
|
| 756 | - echo $this->get_html( $extra_markup ); |
|
| 755 | + public function display($extra_markup = '') { |
|
| 756 | + echo $this->get_html($extra_markup); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | * @param string $context View or edit context. |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function get_name( $context = 'view' ) { |
|
| 91 | - $name = parent::get_name( $context ); |
|
| 92 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 90 | + public function get_name($context = 'view') { |
|
| 91 | + $name = parent::get_name($context); |
|
| 92 | + return $name . wpinv_get_item_suffix($this); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @param string $context View or edit context. |
| 100 | 100 | * @return string |
| 101 | 101 | */ |
| 102 | - public function get_raw_name( $context = 'view' ) { |
|
| 103 | - return parent::get_name( $context ); |
|
| 102 | + public function get_raw_name($context = 'view') { |
|
| 103 | + return parent::get_name($context); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | * @param string $context View or edit context. |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function get_description( $context = 'view' ) { |
|
| 113 | + public function get_description($context = 'view') { |
|
| 114 | 114 | |
| 115 | - if ( isset( $this->custom_description ) ) { |
|
| 115 | + if (isset($this->custom_description)) { |
|
| 116 | 116 | return $this->custom_description; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return parent::get_description( $context ); |
|
| 119 | + return parent::get_description($context); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param string $context View or edit context. |
| 127 | 127 | * @return float |
| 128 | 128 | */ |
| 129 | - public function get_sub_total( $context = 'view' ) { |
|
| 130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 129 | + public function get_sub_total($context = 'view') { |
|
| 130 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -137,10 +137,10 @@ discard block |
||
| 137 | 137 | * @param string $context View or edit context. |
| 138 | 138 | * @return float |
| 139 | 139 | */ |
| 140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 140 | + public function get_recurring_sub_total($context = 'view') { |
|
| 141 | 141 | |
| 142 | - if ( $this->is_recurring() ) { |
|
| 143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 142 | + if ($this->is_recurring()) { |
|
| 143 | + return $this->get_quantity($context) * $this->get_price($context); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | return 0; |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | /** |
| 150 | 150 | * @deprecated |
| 151 | 151 | */ |
| 152 | - public function get_qantity( $context = 'view' ) { |
|
| 153 | - return $this->get_quantity( $context ); |
|
| 152 | + public function get_qantity($context = 'view') { |
|
| 153 | + return $this->get_quantity($context); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,15 +160,15 @@ discard block |
||
| 160 | 160 | * @param string $context View or edit context. |
| 161 | 161 | * @return float |
| 162 | 162 | */ |
| 163 | - public function get_quantity( $context = 'view' ) { |
|
| 163 | + public function get_quantity($context = 'view') { |
|
| 164 | 164 | $quantity = (float) $this->quantity; |
| 165 | 165 | |
| 166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
| 166 | + if (empty($quantity) || 1 > $quantity) { |
|
| 167 | 167 | $quantity = 1; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( 'view' == $context ) { |
|
| 171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 170 | + if ('view' == $context) { |
|
| 171 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return $quantity; |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | * @param string $context View or edit context. |
| 183 | 183 | * @return meta |
| 184 | 184 | */ |
| 185 | - public function get_item_meta( $context = 'view' ) { |
|
| 185 | + public function get_item_meta($context = 'view') { |
|
| 186 | 186 | $meta = $this->meta; |
| 187 | 187 | |
| 188 | - if ( 'view' == $context ) { |
|
| 189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 188 | + if ('view' == $context) { |
|
| 189 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | return $meta; |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @param string $context View or edit context. |
| 201 | 201 | * @return bool |
| 202 | 202 | */ |
| 203 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 203 | + public function get_allow_quantities($context = 'view') { |
|
| 204 | 204 | $allow_quantities = (bool) $this->allow_quantities; |
| 205 | 205 | |
| 206 | - if ( 'view' == $context ) { |
|
| 207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 206 | + if ('view' == $context) { |
|
| 207 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | return $allow_quantities; |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | * @param string $context View or edit context. |
| 219 | 219 | * @return bool |
| 220 | 220 | */ |
| 221 | - public function get_is_required( $context = 'view' ) { |
|
| 221 | + public function get_is_required($context = 'view') { |
|
| 222 | 222 | $is_required = (bool) $this->is_required; |
| 223 | 223 | |
| 224 | - if ( 'view' == $context ) { |
|
| 225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 224 | + if ('view' == $context) { |
|
| 225 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | return $is_required; |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | * @since 1.0.19 |
| 236 | 236 | * @return array |
| 237 | 237 | */ |
| 238 | - public function prepare_data_for_use( $required = null ) { |
|
| 238 | + public function prepare_data_for_use($required = null) { |
|
| 239 | 239 | |
| 240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 240 | + $required = is_null($required) ? $this->is_required() : $required; |
|
| 241 | 241 | return array( |
| 242 | - 'title' => strip_tags( $this->get_name() ), |
|
| 242 | + 'title' => strip_tags($this->get_name()), |
|
| 243 | 243 | 'id' => $this->get_id(), |
| 244 | 244 | 'price' => $this->get_price(), |
| 245 | 245 | 'recurring' => $this->is_recurring(), |
@@ -256,30 +256,30 @@ discard block |
||
| 256 | 256 | * @since 1.0.19 |
| 257 | 257 | * @return array |
| 258 | 258 | */ |
| 259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 259 | + public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) { |
|
| 260 | 260 | |
| 261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 261 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
| 262 | 262 | |
| 263 | - if ( $description ) { |
|
| 263 | + if ($description) { |
|
| 264 | 264 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 268 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 267 | + $price = !$is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 268 | + $subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 269 | 269 | return array( |
| 270 | 270 | 'id' => $this->get_id(), |
| 271 | 271 | 'texts' => array( |
| 272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 273 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 274 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 275 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 276 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 272 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 273 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
| 274 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 275 | + 'item-price' => wpinv_price($price, $currency), |
|
| 276 | + 'item-total' => wpinv_price($subtotal, $currency), |
|
| 277 | 277 | ), |
| 278 | 278 | 'inputs' => array( |
| 279 | 279 | 'item-id' => $this->get_id(), |
| 280 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 281 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 282 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 280 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 281 | + 'item-description' => wp_kses_post($this->get_description()), |
|
| 282 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 283 | 283 | 'item-price' => $price, |
| 284 | 284 | ) |
| 285 | 285 | ); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | return array( |
| 298 | 298 | 'post_id' => $this->invoice_id, |
| 299 | 299 | 'item_id' => $this->get_id(), |
| 300 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
| 300 | + 'item_name' => sanitize_text_field($this->get_raw_name()), |
|
| 301 | 301 | 'item_description' => $this->get_description(), |
| 302 | 302 | 'tax' => $this->item_tax, |
| 303 | 303 | 'item_price' => $this->get_price(), |
@@ -326,9 +326,9 @@ discard block |
||
| 326 | 326 | * @since 1.0.19 |
| 327 | 327 | * @param float $quantity The item quantity. |
| 328 | 328 | */ |
| 329 | - public function set_quantity( $quantity ) { |
|
| 329 | + public function set_quantity($quantity) { |
|
| 330 | 330 | |
| 331 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
| 331 | + if (empty($quantity) || !is_numeric($quantity)) { |
|
| 332 | 332 | $quantity = 1; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -342,8 +342,8 @@ discard block |
||
| 342 | 342 | * @since 1.0.19 |
| 343 | 343 | * @param array $meta The item meta data. |
| 344 | 344 | */ |
| 345 | - public function set_item_meta( $meta ) { |
|
| 346 | - $this->meta = maybe_unserialize( $meta ); |
|
| 345 | + public function set_item_meta($meta) { |
|
| 346 | + $this->meta = maybe_unserialize($meta); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @since 1.0.19 |
| 353 | 353 | * @param bool $allow_quantities |
| 354 | 354 | */ |
| 355 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 355 | + public function set_allow_quantities($allow_quantities) { |
|
| 356 | 356 | $this->allow_quantities = (bool) $allow_quantities; |
| 357 | 357 | } |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @since 1.0.19 |
| 363 | 363 | * @param bool $is_required |
| 364 | 364 | */ |
| 365 | - public function set_is_required( $is_required ) { |
|
| 365 | + public function set_is_required($is_required) { |
|
| 366 | 366 | $this->is_required = (bool) $is_required; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * @since 1.0.19 |
| 373 | 373 | * @param string $description |
| 374 | 374 | */ |
| 375 | - public function set_custom_description( $description ) { |
|
| 375 | + public function set_custom_description($description) { |
|
| 376 | 376 | $this->custom_description = $description; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @return int item id |
| 383 | 383 | */ |
| 384 | - public function save( $data = array() ) { |
|
| 384 | + public function save($data = array()) { |
|
| 385 | 385 | return $this->get_id(); |
| 386 | 386 | } |
| 387 | 387 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,67 +10,67 @@ discard block |
||
| 10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Stores a custom description for the item. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $custom_description = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Stores the item quantity. |
|
| 21 | - * |
|
| 22 | - * @var float |
|
| 23 | - */ |
|
| 24 | - protected $quantity = 1; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Stores the item meta. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $meta = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Is this item required? |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $is_required = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Are quantities allowed? |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $allow_quantities = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Associated invoice. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - public $invoice_id = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Item discount. |
|
| 56 | - * |
|
| 57 | - * @var float |
|
| 58 | - */ |
|
| 59 | - public $item_discount = 0; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Recurring item discount. |
|
| 63 | - * |
|
| 64 | - * @var float |
|
| 65 | - */ |
|
| 66 | - public $recurring_item_discount = 0; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Item tax. |
|
| 70 | - * |
|
| 71 | - * @var float |
|
| 72 | - */ |
|
| 73 | - public $item_tax = 0; |
|
| 13 | + * Stores a custom description for the item. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $custom_description = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Stores the item quantity. |
|
| 21 | + * |
|
| 22 | + * @var float |
|
| 23 | + */ |
|
| 24 | + protected $quantity = 1; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Stores the item meta. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $meta = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Is this item required? |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $is_required = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Are quantities allowed? |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $allow_quantities = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Associated invoice. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + public $invoice_id = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Item discount. |
|
| 56 | + * |
|
| 57 | + * @var float |
|
| 58 | + */ |
|
| 59 | + public $item_discount = 0; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Recurring item discount. |
|
| 63 | + * |
|
| 64 | + * @var float |
|
| 65 | + */ |
|
| 66 | + public $recurring_item_discount = 0; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Item tax. |
|
| 70 | + * |
|
| 71 | + * @var float |
|
| 72 | + */ |
|
| 73 | + public $item_tax = 0; |
|
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,234 +88,234 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * Get the item name. |
|
| 92 | - * |
|
| 93 | - * @since 1.0.19 |
|
| 94 | - * @param string $context View or edit context. |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get the item name without a suffix. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @param string $context View or edit context. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the item description. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @param string $context View or edit context. |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function get_description( $context = 'view' ) { |
|
| 121 | - |
|
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 123 | - return $this->custom_description; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return parent::get_description( $context ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Returns the sub total. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @param string $context View or edit context. |
|
| 134 | - * @return float |
|
| 135 | - */ |
|
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns the recurring sub total. |
|
| 142 | - * |
|
| 143 | - * @since 1.0.19 |
|
| 144 | - * @param string $context View or edit context. |
|
| 145 | - * @return float |
|
| 146 | - */ |
|
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | - |
|
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @deprecated |
|
| 158 | - */ |
|
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get the item quantity. |
|
| 165 | - * |
|
| 166 | - * @since 1.0.19 |
|
| 167 | - * @param string $context View or edit context. |
|
| 168 | - * @return float |
|
| 169 | - */ |
|
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 171 | - $quantity = (float) $this->quantity; |
|
| 172 | - |
|
| 173 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
| 174 | - $quantity = 1; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ( 'view' == $context ) { |
|
| 178 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $quantity; |
|
| 182 | - |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Get the item meta data. |
|
| 187 | - * |
|
| 188 | - * @since 1.0.19 |
|
| 189 | - * @param string $context View or edit context. |
|
| 190 | - * @return meta |
|
| 191 | - */ |
|
| 192 | - public function get_item_meta( $context = 'view' ) { |
|
| 193 | - $meta = $this->meta; |
|
| 194 | - |
|
| 195 | - if ( 'view' == $context ) { |
|
| 196 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $meta; |
|
| 200 | - |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Returns whether or not customers can update the item quantity. |
|
| 205 | - * |
|
| 206 | - * @since 1.0.19 |
|
| 207 | - * @param string $context View or edit context. |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 211 | - $allow_quantities = (bool) $this->allow_quantities; |
|
| 212 | - |
|
| 213 | - if ( 'view' == $context ) { |
|
| 214 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $allow_quantities; |
|
| 218 | - |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Returns whether or not the item is required. |
|
| 223 | - * |
|
| 224 | - * @since 1.0.19 |
|
| 225 | - * @param string $context View or edit context. |
|
| 226 | - * @return bool |
|
| 227 | - */ |
|
| 228 | - public function get_is_required( $context = 'view' ) { |
|
| 229 | - $is_required = (bool) $this->is_required; |
|
| 230 | - |
|
| 231 | - if ( 'view' == $context ) { |
|
| 232 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $is_required; |
|
| 236 | - |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Prepares form data for use. |
|
| 241 | - * |
|
| 242 | - * @since 1.0.19 |
|
| 243 | - * @return array |
|
| 244 | - */ |
|
| 245 | - public function prepare_data_for_use( $required = null ) { |
|
| 246 | - |
|
| 247 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 248 | - return array( |
|
| 249 | - 'title' => strip_tags( $this->get_name() ), |
|
| 250 | - 'id' => $this->get_id(), |
|
| 251 | - 'price' => $this->get_price(), |
|
| 252 | - 'recurring' => $this->is_recurring(), |
|
| 253 | - 'description' => $this->get_description(), |
|
| 254 | - 'allow_quantities' => $this->allows_quantities(), |
|
| 255 | - 'required' => $required, |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Prepares form data for ajax use. |
|
| 262 | - * |
|
| 263 | - * @since 1.0.19 |
|
| 264 | - * @return array |
|
| 265 | - */ |
|
| 266 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 267 | - |
|
| 268 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 269 | - |
|
| 270 | - if ( $description ) { |
|
| 271 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 275 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 276 | - return array( |
|
| 277 | - 'id' => $this->get_id(), |
|
| 278 | - 'texts' => array( |
|
| 279 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 280 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 281 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 282 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 283 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 284 | - ), |
|
| 285 | - 'inputs' => array( |
|
| 286 | - 'item-id' => $this->get_id(), |
|
| 287 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 288 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 289 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 290 | - 'item-price' => $price, |
|
| 291 | - ) |
|
| 292 | - ); |
|
| 293 | - |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Prepares form data for saving (cart_details). |
|
| 298 | - * |
|
| 299 | - * @since 1.0.19 |
|
| 300 | - * @return array |
|
| 301 | - */ |
|
| 302 | - public function prepare_data_for_saving() { |
|
| 303 | - |
|
| 304 | - return array( |
|
| 305 | - 'post_id' => $this->invoice_id, |
|
| 306 | - 'item_id' => $this->get_id(), |
|
| 307 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
| 308 | - 'item_description' => $this->get_description(), |
|
| 309 | - 'tax' => $this->item_tax, |
|
| 310 | - 'item_price' => $this->get_price(), |
|
| 311 | - 'quantity' => (float) $this->get_quantity(), |
|
| 312 | - 'discount' => $this->item_discount, |
|
| 313 | - 'subtotal' => $this->get_sub_total(), |
|
| 314 | - 'price' => $this->get_sub_total() + $this->item_tax - $this->item_discount, |
|
| 315 | - 'meta' => $this->get_item_meta(), |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - } |
|
| 91 | + * Get the item name. |
|
| 92 | + * |
|
| 93 | + * @since 1.0.19 |
|
| 94 | + * @param string $context View or edit context. |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function get_name( $context = 'view' ) { |
|
| 98 | + $name = parent::get_name( $context ); |
|
| 99 | + return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get the item name without a suffix. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @param string $context View or edit context. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function get_raw_name( $context = 'view' ) { |
|
| 110 | + return parent::get_name( $context ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the item description. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @param string $context View or edit context. |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function get_description( $context = 'view' ) { |
|
| 121 | + |
|
| 122 | + if ( isset( $this->custom_description ) ) { |
|
| 123 | + return $this->custom_description; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return parent::get_description( $context ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Returns the sub total. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @param string $context View or edit context. |
|
| 134 | + * @return float |
|
| 135 | + */ |
|
| 136 | + public function get_sub_total( $context = 'view' ) { |
|
| 137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns the recurring sub total. |
|
| 142 | + * |
|
| 143 | + * @since 1.0.19 |
|
| 144 | + * @param string $context View or edit context. |
|
| 145 | + * @return float |
|
| 146 | + */ |
|
| 147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | + |
|
| 149 | + if ( $this->is_recurring() ) { |
|
| 150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @deprecated |
|
| 158 | + */ |
|
| 159 | + public function get_qantity( $context = 'view' ) { |
|
| 160 | + return $this->get_quantity( $context ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get the item quantity. |
|
| 165 | + * |
|
| 166 | + * @since 1.0.19 |
|
| 167 | + * @param string $context View or edit context. |
|
| 168 | + * @return float |
|
| 169 | + */ |
|
| 170 | + public function get_quantity( $context = 'view' ) { |
|
| 171 | + $quantity = (float) $this->quantity; |
|
| 172 | + |
|
| 173 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
| 174 | + $quantity = 1; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ( 'view' == $context ) { |
|
| 178 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $quantity; |
|
| 182 | + |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Get the item meta data. |
|
| 187 | + * |
|
| 188 | + * @since 1.0.19 |
|
| 189 | + * @param string $context View or edit context. |
|
| 190 | + * @return meta |
|
| 191 | + */ |
|
| 192 | + public function get_item_meta( $context = 'view' ) { |
|
| 193 | + $meta = $this->meta; |
|
| 194 | + |
|
| 195 | + if ( 'view' == $context ) { |
|
| 196 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $meta; |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Returns whether or not customers can update the item quantity. |
|
| 205 | + * |
|
| 206 | + * @since 1.0.19 |
|
| 207 | + * @param string $context View or edit context. |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + public function get_allow_quantities( $context = 'view' ) { |
|
| 211 | + $allow_quantities = (bool) $this->allow_quantities; |
|
| 212 | + |
|
| 213 | + if ( 'view' == $context ) { |
|
| 214 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $allow_quantities; |
|
| 218 | + |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Returns whether or not the item is required. |
|
| 223 | + * |
|
| 224 | + * @since 1.0.19 |
|
| 225 | + * @param string $context View or edit context. |
|
| 226 | + * @return bool |
|
| 227 | + */ |
|
| 228 | + public function get_is_required( $context = 'view' ) { |
|
| 229 | + $is_required = (bool) $this->is_required; |
|
| 230 | + |
|
| 231 | + if ( 'view' == $context ) { |
|
| 232 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $is_required; |
|
| 236 | + |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Prepares form data for use. |
|
| 241 | + * |
|
| 242 | + * @since 1.0.19 |
|
| 243 | + * @return array |
|
| 244 | + */ |
|
| 245 | + public function prepare_data_for_use( $required = null ) { |
|
| 246 | + |
|
| 247 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 248 | + return array( |
|
| 249 | + 'title' => strip_tags( $this->get_name() ), |
|
| 250 | + 'id' => $this->get_id(), |
|
| 251 | + 'price' => $this->get_price(), |
|
| 252 | + 'recurring' => $this->is_recurring(), |
|
| 253 | + 'description' => $this->get_description(), |
|
| 254 | + 'allow_quantities' => $this->allows_quantities(), |
|
| 255 | + 'required' => $required, |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Prepares form data for ajax use. |
|
| 262 | + * |
|
| 263 | + * @since 1.0.19 |
|
| 264 | + * @return array |
|
| 265 | + */ |
|
| 266 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 267 | + |
|
| 268 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 269 | + |
|
| 270 | + if ( $description ) { |
|
| 271 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 275 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 276 | + return array( |
|
| 277 | + 'id' => $this->get_id(), |
|
| 278 | + 'texts' => array( |
|
| 279 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 280 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 281 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 282 | + 'item-price' => wpinv_price( $price, $currency ), |
|
| 283 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 284 | + ), |
|
| 285 | + 'inputs' => array( |
|
| 286 | + 'item-id' => $this->get_id(), |
|
| 287 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 288 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 289 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 290 | + 'item-price' => $price, |
|
| 291 | + ) |
|
| 292 | + ); |
|
| 293 | + |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Prepares form data for saving (cart_details). |
|
| 298 | + * |
|
| 299 | + * @since 1.0.19 |
|
| 300 | + * @return array |
|
| 301 | + */ |
|
| 302 | + public function prepare_data_for_saving() { |
|
| 303 | + |
|
| 304 | + return array( |
|
| 305 | + 'post_id' => $this->invoice_id, |
|
| 306 | + 'item_id' => $this->get_id(), |
|
| 307 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
| 308 | + 'item_description' => $this->get_description(), |
|
| 309 | + 'tax' => $this->item_tax, |
|
| 310 | + 'item_price' => $this->get_price(), |
|
| 311 | + 'quantity' => (float) $this->get_quantity(), |
|
| 312 | + 'discount' => $this->item_discount, |
|
| 313 | + 'subtotal' => $this->get_sub_total(), |
|
| 314 | + 'price' => $this->get_sub_total() + $this->item_tax - $this->item_discount, |
|
| 315 | + 'meta' => $this->get_item_meta(), |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | 320 | /* |
| 321 | 321 | |-------------------------------------------------------------------------- |
@@ -327,70 +327,70 @@ discard block |
||
| 327 | 327 | | object. |
| 328 | 328 | */ |
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Set the item qantity. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param float $quantity The item quantity. |
|
| 335 | - */ |
|
| 336 | - public function set_quantity( $quantity ) { |
|
| 337 | - |
|
| 338 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
| 339 | - $quantity = 1; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $this->quantity = (float) $quantity; |
|
| 343 | - |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Set the item meta data. |
|
| 348 | - * |
|
| 349 | - * @since 1.0.19 |
|
| 350 | - * @param array $meta The item meta data. |
|
| 351 | - */ |
|
| 352 | - public function set_item_meta( $meta ) { |
|
| 353 | - $this->meta = maybe_unserialize( $meta ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Set whether or not the quantities are allowed. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - * @param bool $allow_quantities |
|
| 361 | - */ |
|
| 362 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 363 | - $this->allow_quantities = (bool) $allow_quantities; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Set whether or not the item is required. |
|
| 368 | - * |
|
| 369 | - * @since 1.0.19 |
|
| 370 | - * @param bool $is_required |
|
| 371 | - */ |
|
| 372 | - public function set_is_required( $is_required ) { |
|
| 373 | - $this->is_required = (bool) $is_required; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Sets the custom item description. |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - * @param string $description |
|
| 381 | - */ |
|
| 382 | - public function set_custom_description( $description ) { |
|
| 383 | - $this->custom_description = $description; |
|
| 384 | - } |
|
| 330 | + /** |
|
| 331 | + * Set the item qantity. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param float $quantity The item quantity. |
|
| 335 | + */ |
|
| 336 | + public function set_quantity( $quantity ) { |
|
| 337 | + |
|
| 338 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
| 339 | + $quantity = 1; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $this->quantity = (float) $quantity; |
|
| 343 | + |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Set the item meta data. |
|
| 348 | + * |
|
| 349 | + * @since 1.0.19 |
|
| 350 | + * @param array $meta The item meta data. |
|
| 351 | + */ |
|
| 352 | + public function set_item_meta( $meta ) { |
|
| 353 | + $this->meta = maybe_unserialize( $meta ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Set whether or not the quantities are allowed. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + * @param bool $allow_quantities |
|
| 361 | + */ |
|
| 362 | + public function set_allow_quantities( $allow_quantities ) { |
|
| 363 | + $this->allow_quantities = (bool) $allow_quantities; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Set whether or not the item is required. |
|
| 368 | + * |
|
| 369 | + * @since 1.0.19 |
|
| 370 | + * @param bool $is_required |
|
| 371 | + */ |
|
| 372 | + public function set_is_required( $is_required ) { |
|
| 373 | + $this->is_required = (bool) $is_required; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Sets the custom item description. |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + * @param string $description |
|
| 381 | + */ |
|
| 382 | + public function set_custom_description( $description ) { |
|
| 383 | + $this->custom_description = $description; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | 386 | /** |
| 387 | 387 | * We do not want to save items to the database. |
| 388 | 388 | * |
| 389 | - * @return int item id |
|
| 389 | + * @return int item id |
|
| 390 | 390 | */ |
| 391 | 391 | public function save( $data = array() ) { |
| 392 | 392 | return $this->get_id(); |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | /* |
| 396 | 396 | |-------------------------------------------------------------------------- |
@@ -402,23 +402,23 @@ discard block |
||
| 402 | 402 | */ |
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | - * Checks whether the item has enabled dynamic pricing. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - * @return bool |
|
| 409 | - */ |
|
| 410 | - public function is_required() { |
|
| 405 | + * Checks whether the item has enabled dynamic pricing. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + * @return bool |
|
| 409 | + */ |
|
| 410 | + public function is_required() { |
|
| 411 | 411 | return (bool) $this->get_is_required(); |
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Checks whether users can edit the quantities. |
|
| 416 | - * |
|
| 417 | - * @since 1.0.19 |
|
| 418 | - * @return bool |
|
| 419 | - */ |
|
| 420 | - public function allows_quantities() { |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Checks whether users can edit the quantities. |
|
| 416 | + * |
|
| 417 | + * @since 1.0.19 |
|
| 418 | + * @return bool |
|
| 419 | + */ |
|
| 420 | + public function allows_quantities() { |
|
| 421 | 421 | return (bool) $this->get_allow_quantities(); |
| 422 | - } |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | } |
@@ -12,180 +12,180 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Checkout { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Payment_Form_Submission |
|
| 17 | - */ |
|
| 18 | - protected $payment_form_submission; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | - */ |
|
| 25 | - public function __construct( $submission ) { |
|
| 26 | - $this->payment_form_submission = $submission; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Processes the checkout. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function process_checkout() { |
|
| 34 | - |
|
| 35 | - // Validate the submission. |
|
| 36 | - $this->validate_submission(); |
|
| 37 | - |
|
| 38 | - // Prepare the invoice. |
|
| 39 | - $items = $this->get_submission_items(); |
|
| 40 | - $invoice = $this->get_submission_invoice(); |
|
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | - |
|
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 45 | - |
|
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | - |
|
| 48 | - // Save the invoice. |
|
| 49 | - $invoice->set_is_viewed( true ); |
|
| 50 | - $invoice->recalculate_total(); |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Payment_Form_Submission |
|
| 17 | + */ |
|
| 18 | + protected $payment_form_submission; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | + */ |
|
| 25 | + public function __construct( $submission ) { |
|
| 26 | + $this->payment_form_submission = $submission; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Processes the checkout. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function process_checkout() { |
|
| 34 | + |
|
| 35 | + // Validate the submission. |
|
| 36 | + $this->validate_submission(); |
|
| 37 | + |
|
| 38 | + // Prepare the invoice. |
|
| 39 | + $items = $this->get_submission_items(); |
|
| 40 | + $invoice = $this->get_submission_invoice(); |
|
| 41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | + |
|
| 44 | + $this->prepare_billing_info( $invoice ); |
|
| 45 | + |
|
| 46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | + |
|
| 48 | + // Save the invoice. |
|
| 49 | + $invoice->set_is_viewed( true ); |
|
| 50 | + $invoice->recalculate_total(); |
|
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 54 | 54 | |
| 55 | - // Send to the gateway. |
|
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | - } |
|
| 55 | + // Send to the gateway. |
|
| 56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Validates the submission. |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - protected function validate_submission() { |
|
| 59 | + /** |
|
| 60 | + * Validates the submission. |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + protected function validate_submission() { |
|
| 64 | 64 | |
| 65 | - $submission = $this->payment_form_submission; |
|
| 66 | - $data = $submission->get_data(); |
|
| 65 | + $submission = $this->payment_form_submission; |
|
| 66 | + $data = $submission->get_data(); |
|
| 67 | 67 | |
| 68 | - // Do we have an error? |
|
| 68 | + // Do we have an error? |
|
| 69 | 69 | if ( ! empty( $submission->last_error ) ) { |
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 70 | + wp_send_json_error( $submission->last_error ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - // We need a billing email. |
|
| 73 | + // We need a billing email. |
|
| 74 | 74 | if ( ! $submission->has_billing_email() ) { |
| 75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | - } |
|
| 78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // Ensure the gateway is active. |
|
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | - } |
|
| 83 | + // Ensure the gateway is active. |
|
| 84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Clear any existing errors. |
|
| 89 | - wpinv_clear_errors(); |
|
| 88 | + // Clear any existing errors. |
|
| 89 | + wpinv_clear_errors(); |
|
| 90 | 90 | |
| 91 | - // Allow themes and plugins to hook to errors |
|
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 91 | + // Allow themes and plugins to hook to errors |
|
| 92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 93 | 93 | |
| 94 | - // Do we have any errors? |
|
| 94 | + // Do we have any errors? |
|
| 95 | 95 | if ( wpinv_get_errors() ) { |
| 96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieves submission items. |
|
| 103 | - * |
|
| 104 | - * @return GetPaid_Form_Item[] |
|
| 105 | - */ |
|
| 106 | - protected function get_submission_items() { |
|
| 101 | + /** |
|
| 102 | + * Retrieves submission items. |
|
| 103 | + * |
|
| 104 | + * @return GetPaid_Form_Item[] |
|
| 105 | + */ |
|
| 106 | + protected function get_submission_items() { |
|
| 107 | 107 | |
| 108 | - $items = $this->payment_form_submission->get_items(); |
|
| 108 | + $items = $this->payment_form_submission->get_items(); |
|
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $items; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Retrieves submission invoice. |
|
| 120 | - * |
|
| 121 | - * @return WPInv_Invoice |
|
| 122 | - */ |
|
| 123 | - protected function get_submission_invoice() { |
|
| 124 | - $submission = $this->payment_form_submission; |
|
| 125 | - |
|
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 127 | - $invoice = new WPInv_Invoice(); |
|
| 128 | - $invoice->created_via( 'payment_form' ); |
|
| 129 | - return $invoice; |
|
| 130 | 113 | } |
| 131 | 114 | |
| 132 | - $invoice = $submission->get_invoice(); |
|
| 115 | + return $items; |
|
| 116 | + } |
|
| 133 | 117 | |
| 134 | - // Make sure that it is neither paid or refunded. |
|
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | - } |
|
| 118 | + /** |
|
| 119 | + * Retrieves submission invoice. |
|
| 120 | + * |
|
| 121 | + * @return WPInv_Invoice |
|
| 122 | + */ |
|
| 123 | + protected function get_submission_invoice() { |
|
| 124 | + $submission = $this->payment_form_submission; |
|
| 138 | 125 | |
| 139 | - return $invoice; |
|
| 140 | - } |
|
| 126 | + if ( ! $submission->has_invoice() ) { |
|
| 127 | + $invoice = new WPInv_Invoice(); |
|
| 128 | + $invoice->created_via( 'payment_form' ); |
|
| 129 | + return $invoice; |
|
| 130 | + } |
|
| 141 | 131 | |
| 142 | - /** |
|
| 143 | - * Processes the submission invoice. |
|
| 144 | - * |
|
| 145 | - * @param WPInv_Invoice $invoice |
|
| 146 | - * @param GetPaid_Form_Item[] $items |
|
| 147 | - * @return WPInv_Invoice |
|
| 148 | - */ |
|
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 132 | + $invoice = $submission->get_invoice(); |
|
| 150 | 133 | |
| 151 | - $submission = $this->payment_form_submission; |
|
| 152 | - $data = $submission->get_data(); |
|
| 134 | + // Make sure that it is neither paid or refunded. |
|
| 135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $invoice; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Processes the submission invoice. |
|
| 144 | + * |
|
| 145 | + * @param WPInv_Invoice $invoice |
|
| 146 | + * @param GetPaid_Form_Item[] $items |
|
| 147 | + * @return WPInv_Invoice |
|
| 148 | + */ |
|
| 149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 153 | 150 | |
| 154 | - // Set-up the invoice details. |
|
| 155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 151 | + $submission = $this->payment_form_submission; |
|
| 152 | + $data = $submission->get_data(); |
|
| 153 | + |
|
| 154 | + // Set-up the invoice details. |
|
| 155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 158 | 158 | $invoice->set_items( $items ); |
| 159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
| 160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
| 161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 163 | 163 | |
| 164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 166 | 166 | |
| 167 | - if ( $submission->has_discount_code() ) { |
|
| 167 | + if ( $submission->has_discount_code() ) { |
|
| 168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 169 | - } |
|
| 170 | - |
|
| 171 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 172 | - return $invoice; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Retrieves the submission's customer. |
|
| 177 | - * |
|
| 178 | - * @return int The customer id. |
|
| 179 | - */ |
|
| 180 | - protected function get_submission_customer() { |
|
| 181 | - $submission = $this->payment_form_submission; |
|
| 182 | - |
|
| 183 | - // If this is an existing invoice... |
|
| 184 | - if ( $submission->has_invoice() ) { |
|
| 185 | - return $submission->get_invoice()->get_user_id(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // (Maybe) create the user. |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 172 | + return $invoice; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Retrieves the submission's customer. |
|
| 177 | + * |
|
| 178 | + * @return int The customer id. |
|
| 179 | + */ |
|
| 180 | + protected function get_submission_customer() { |
|
| 181 | + $submission = $this->payment_form_submission; |
|
| 182 | + |
|
| 183 | + // If this is an existing invoice... |
|
| 184 | + if ( $submission->has_invoice() ) { |
|
| 185 | + return $submission->get_invoice()->get_user_id(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // (Maybe) create the user. |
|
| 189 | 189 | $user = get_current_user_id(); |
| 190 | 190 | |
| 191 | 191 | if ( empty( $user ) ) { |
@@ -202,31 +202,31 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | if ( is_numeric( $user ) ) { |
| 204 | 204 | return $user; |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $user->ID; |
|
| 207 | + return $user->ID; |
|
| 208 | 208 | |
| 209 | - } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 211 | + /** |
|
| 212 | 212 | * Prepares submission data for saving to the database. |
| 213 | 213 | * |
| 214 | - * @return array |
|
| 214 | + * @return array |
|
| 215 | 215 | */ |
| 216 | 216 | public function prepare_submission_data_for_saving() { |
| 217 | 217 | |
| 218 | - $submission = $this->payment_form_submission; |
|
| 218 | + $submission = $this->payment_form_submission; |
|
| 219 | 219 | |
| 220 | - // Prepared submission details. |
|
| 220 | + // Prepared submission details. |
|
| 221 | 221 | $prepared = array(); |
| 222 | 222 | |
| 223 | 223 | // Raw submission details. |
| 224 | - $data = $submission->get_data(); |
|
| 224 | + $data = $submission->get_data(); |
|
| 225 | 225 | |
| 226 | - // Loop through the submitted details. |
|
| 226 | + // Loop through the submitted details. |
|
| 227 | 227 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 228 | 228 | |
| 229 | - // Skip premade fields. |
|
| 229 | + // Skip premade fields. |
|
| 230 | 230 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
| 231 | 231 | continue; |
| 232 | 232 | } |
@@ -244,176 +244,176 @@ discard block |
||
| 244 | 244 | $label = $field['label']; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
| 247 | + $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - } |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - return $prepared; |
|
| 253 | + return $prepared; |
|
| 254 | 254 | |
| 255 | - } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 257 | + /** |
|
| 258 | 258 | * Retrieves address details. |
| 259 | 259 | * |
| 260 | - * @return array |
|
| 261 | - * @param WPInv_Invoice $invoice |
|
| 262 | - * @param string $type |
|
| 260 | + * @return array |
|
| 261 | + * @param WPInv_Invoice $invoice |
|
| 262 | + * @param string $type |
|
| 263 | 263 | */ |
| 264 | 264 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
| 265 | 265 | |
| 266 | - $data = $this->payment_form_submission->get_data(); |
|
| 267 | - $type = sanitize_key( $type ); |
|
| 268 | - $address = array(); |
|
| 269 | - $prepared = array(); |
|
| 266 | + $data = $this->payment_form_submission->get_data(); |
|
| 267 | + $type = sanitize_key( $type ); |
|
| 268 | + $address = array(); |
|
| 269 | + $prepared = array(); |
|
| 270 | 270 | |
| 271 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 272 | - $address = $data[ $type ]; |
|
| 273 | - } |
|
| 271 | + if ( ! empty( $data[ $type ] ) ) { |
|
| 272 | + $address = $data[ $type ]; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - // Clean address details. |
|
| 276 | - foreach ( $address as $key => $value ) { |
|
| 277 | - $key = sanitize_key( $key ); |
|
| 278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 279 | - $value = wpinv_clean( $value ); |
|
| 280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 281 | - } |
|
| 275 | + // Clean address details. |
|
| 276 | + foreach ( $address as $key => $value ) { |
|
| 277 | + $key = sanitize_key( $key ); |
|
| 278 | + $key = str_replace( 'wpinv_', '', $key ); |
|
| 279 | + $value = wpinv_clean( $value ); |
|
| 280 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - // Filter address details. |
|
| 284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 283 | + // Filter address details. |
|
| 284 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 285 | 285 | |
| 286 | - // Remove non-whitelisted values. |
|
| 287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 286 | + // Remove non-whitelisted values. |
|
| 287 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 288 | 288 | |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 291 | + /** |
|
| 292 | 292 | * Prepares the billing details. |
| 293 | 293 | * |
| 294 | - * @return array |
|
| 295 | - * @param WPInv_Invoice $invoice |
|
| 294 | + * @return array |
|
| 295 | + * @param WPInv_Invoice $invoice |
|
| 296 | 296 | */ |
| 297 | 297 | protected function prepare_billing_info( &$invoice ) { |
| 298 | 298 | |
| 299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 299 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 300 | 300 | |
| 301 | - // Update the invoice with the billing details. |
|
| 302 | - $invoice->set_props( $billing_address ); |
|
| 301 | + // Update the invoice with the billing details. |
|
| 302 | + $invoice->set_props( $billing_address ); |
|
| 303 | 303 | |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 306 | + /** |
|
| 307 | 307 | * Prepares the shipping details. |
| 308 | 308 | * |
| 309 | - * @return array |
|
| 310 | - * @param WPInv_Invoice $invoice |
|
| 309 | + * @return array |
|
| 310 | + * @param WPInv_Invoice $invoice |
|
| 311 | 311 | */ |
| 312 | 312 | protected function prepare_shipping_info( $invoice ) { |
| 313 | 313 | |
| 314 | - $data = $this->payment_form_submission->get_data(); |
|
| 314 | + $data = $this->payment_form_submission->get_data(); |
|
| 315 | 315 | |
| 316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 318 | - } |
|
| 316 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
| 317 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 320 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 321 | 321 | |
| 322 | - } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Confirms the submission is valid and send users to the gateway. |
|
| 326 | - * |
|
| 327 | - * @param WPInv_Invoice $invoice |
|
| 328 | - * @param array $prepared_payment_form_data |
|
| 329 | - * @param array $shipping |
|
| 330 | - */ |
|
| 331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 324 | + /** |
|
| 325 | + * Confirms the submission is valid and send users to the gateway. |
|
| 326 | + * |
|
| 327 | + * @param WPInv_Invoice $invoice |
|
| 328 | + * @param array $prepared_payment_form_data |
|
| 329 | + * @param array $shipping |
|
| 330 | + */ |
|
| 331 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 332 | 332 | |
| 333 | - // Ensure the invoice exists. |
|
| 333 | + // Ensure the invoice exists. |
|
| 334 | 334 | if ( ! $invoice->exists() ) { |
| 335 | 335 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - // Save payment form data. |
|
| 339 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 338 | + // Save payment form data. |
|
| 339 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 340 | 340 | if ( ! empty( $prepared_payment_form_data ) ) { |
| 341 | 341 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
| 342 | - } |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - // Save payment form data. |
|
| 344 | + // Save payment form data. |
|
| 345 | 345 | if ( ! empty( $shipping ) ) { |
| 346 | 346 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
| 347 | - } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - // Backwards compatibility. |
|
| 349 | + // Backwards compatibility. |
|
| 350 | 350 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 351 | 351 | |
| 352 | - $this->process_payment( $invoice ); |
|
| 352 | + $this->process_payment( $invoice ); |
|
| 353 | 353 | |
| 354 | 354 | // If we are here, there was an error. |
| 355 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 355 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 356 | 356 | |
| 357 | - } |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Processes the actual payment. |
|
| 361 | - * |
|
| 362 | - * @param WPInv_Invoice $invoice |
|
| 363 | - */ |
|
| 364 | - protected function process_payment( $invoice ) { |
|
| 359 | + /** |
|
| 360 | + * Processes the actual payment. |
|
| 361 | + * |
|
| 362 | + * @param WPInv_Invoice $invoice |
|
| 363 | + */ |
|
| 364 | + protected function process_payment( $invoice ) { |
|
| 365 | 365 | |
| 366 | - // Clear any checkout errors. |
|
| 367 | - wpinv_clear_errors(); |
|
| 366 | + // Clear any checkout errors. |
|
| 367 | + wpinv_clear_errors(); |
|
| 368 | 368 | |
| 369 | - // No need to send free invoices to the gateway. |
|
| 370 | - if ( $invoice->is_free() ) { |
|
| 371 | - $this->process_free_payment( $invoice ); |
|
| 372 | - } |
|
| 369 | + // No need to send free invoices to the gateway. |
|
| 370 | + if ( $invoice->is_free() ) { |
|
| 371 | + $this->process_free_payment( $invoice ); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $submission = $this->payment_form_submission; |
|
| 374 | + $submission = $this->payment_form_submission; |
|
| 375 | 375 | |
| 376 | - // Fires before sending to the gateway. |
|
| 377 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 376 | + // Fires before sending to the gateway. |
|
| 377 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 378 | 378 | |
| 379 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 380 | - $submission_data = $submission->get_data(); |
|
| 381 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 382 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 379 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 380 | + $submission_data = $submission->get_data(); |
|
| 381 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 382 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 383 | 383 | |
| 384 | - // Validate the currency. |
|
| 385 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 386 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 387 | - } |
|
| 384 | + // Validate the currency. |
|
| 385 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 386 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - // Check to see if we have any errors. |
|
| 390 | - if ( wpinv_get_errors() ) { |
|
| 391 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 392 | - } |
|
| 389 | + // Check to see if we have any errors. |
|
| 390 | + if ( wpinv_get_errors() ) { |
|
| 391 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - // Send info to the gateway for payment processing |
|
| 395 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 394 | + // Send info to the gateway for payment processing |
|
| 395 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 396 | 396 | |
| 397 | - // Backwards compatibility. |
|
| 398 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 397 | + // Backwards compatibility. |
|
| 398 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 399 | 399 | |
| 400 | - } |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * Marks the invoice as paid in case the checkout is free. |
|
| 404 | - * |
|
| 405 | - * @param WPInv_Invoice $invoice |
|
| 406 | - */ |
|
| 407 | - protected function process_free_payment( $invoice ) { |
|
| 402 | + /** |
|
| 403 | + * Marks the invoice as paid in case the checkout is free. |
|
| 404 | + * |
|
| 405 | + * @param WPInv_Invoice $invoice |
|
| 406 | + */ |
|
| 407 | + protected function process_free_payment( $invoice ) { |
|
| 408 | 408 | |
| 409 | - $invoice->set_gateway( 'none' ); |
|
| 410 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 411 | - $invoice->mark_paid(); |
|
| 412 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 409 | + $invoice->set_gateway( 'none' ); |
|
| 410 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 411 | + $invoice->mark_paid(); |
|
| 412 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 413 | 413 | |
| 414 | - } |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - /** |
|
| 416 | + /** |
|
| 417 | 417 | * Sends a redrect response to payment details. |
| 418 | 418 | * |
| 419 | 419 | */ |
@@ -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 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
| 24 | 24 | */ |
| 25 | - public function __construct( $submission ) { |
|
| 25 | + public function __construct($submission) { |
|
| 26 | 26 | $this->payment_form_submission = $submission; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | // Prepare the invoice. |
| 39 | 39 | $items = $this->get_submission_items(); |
| 40 | 40 | $invoice = $this->get_submission_invoice(); |
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
| 42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
| 43 | 43 | |
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 44 | + $this->prepare_billing_info($invoice); |
|
| 45 | 45 | |
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
| 47 | 47 | |
| 48 | 48 | // Save the invoice. |
| 49 | - $invoice->set_is_viewed( true ); |
|
| 49 | + $invoice->set_is_viewed(true); |
|
| 50 | 50 | $invoice->recalculate_total(); |
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
| 54 | 54 | |
| 55 | 55 | // Send to the gateway. |
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
| 66 | 66 | $data = $submission->get_data(); |
| 67 | 67 | |
| 68 | 68 | // Do we have an error? |
| 69 | - if ( ! empty( $submission->last_error ) ) { |
|
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 69 | + if (!empty($submission->last_error)) { |
|
| 70 | + wp_send_json_error($submission->last_error); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // We need a billing email. |
| 74 | - if ( ! $submission->has_billing_email() ) { |
|
| 75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
| 74 | + if (!$submission->has_billing_email()) { |
|
| 75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
| 80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // Ensure the gateway is active. |
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
| 85 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Clear any existing errors. |
| 89 | 89 | wpinv_clear_errors(); |
| 90 | 90 | |
| 91 | 91 | // Allow themes and plugins to hook to errors |
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
| 93 | 93 | |
| 94 | 94 | // Do we have any errors? |
| 95 | - if ( wpinv_get_errors() ) { |
|
| 96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
| 95 | + if (wpinv_get_errors()) { |
|
| 96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | $items = $this->payment_form_submission->get_items(); |
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
| 112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
| 111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
| 112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | protected function get_submission_invoice() { |
| 124 | 124 | $submission = $this->payment_form_submission; |
| 125 | 125 | |
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 126 | + if (!$submission->has_invoice()) { |
|
| 127 | 127 | $invoice = new WPInv_Invoice(); |
| 128 | - $invoice->created_via( 'payment_form' ); |
|
| 128 | + $invoice->created_via('payment_form'); |
|
| 129 | 129 | return $invoice; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $invoice = $submission->get_invoice(); |
| 133 | 133 | |
| 134 | 134 | // Make sure that it is neither paid or refunded. |
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $invoice; |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | * @param GetPaid_Form_Item[] $items |
| 147 | 147 | * @return WPInv_Invoice |
| 148 | 148 | */ |
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 149 | + protected function process_submission_invoice($invoice, $items) { |
|
| 150 | 150 | |
| 151 | 151 | $submission = $this->payment_form_submission; |
| 152 | 152 | $data = $submission->get_data(); |
| 153 | 153 | |
| 154 | 154 | // Set-up the invoice details. |
| 155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 158 | - $invoice->set_items( $items ); |
|
| 159 | - $invoice->set_fees( $submission->get_fees() ); |
|
| 160 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
| 161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 163 | - |
|
| 164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 166 | - |
|
| 167 | - if ( $submission->has_discount_code() ) { |
|
| 168 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
| 155 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
| 156 | + $invoice->set_user_id($this->get_submission_customer()); |
|
| 157 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
| 158 | + $invoice->set_items($items); |
|
| 159 | + $invoice->set_fees($submission->get_fees()); |
|
| 160 | + $invoice->set_taxes($submission->get_taxes()); |
|
| 161 | + $invoice->set_discounts($submission->get_discounts()); |
|
| 162 | + $invoice->set_gateway($data['wpi-gateway']); |
|
| 163 | + |
|
| 164 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
| 165 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
| 166 | + |
|
| 167 | + if ($submission->has_discount_code()) { |
|
| 168 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 171 | + getpaid_maybe_add_default_address($invoice); |
|
| 172 | 172 | return $invoice; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -181,26 +181,26 @@ discard block |
||
| 181 | 181 | $submission = $this->payment_form_submission; |
| 182 | 182 | |
| 183 | 183 | // If this is an existing invoice... |
| 184 | - if ( $submission->has_invoice() ) { |
|
| 184 | + if ($submission->has_invoice()) { |
|
| 185 | 185 | return $submission->get_invoice()->get_user_id(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // (Maybe) create the user. |
| 189 | 189 | $user = get_current_user_id(); |
| 190 | 190 | |
| 191 | - if ( empty( $user ) ) { |
|
| 192 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
| 191 | + if (empty($user)) { |
|
| 192 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ( empty( $user ) ) { |
|
| 196 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
| 195 | + if (empty($user)) { |
|
| 196 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( is_wp_error( $user ) ) { |
|
| 200 | - wp_send_json_error( $user->get_error_message() ); |
|
| 199 | + if (is_wp_error($user)) { |
|
| 200 | + wp_send_json_error($user->get_error_message()); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( is_numeric( $user ) ) { |
|
| 203 | + if (is_numeric($user)) { |
|
| 204 | 204 | return $user; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -221,30 +221,30 @@ discard block |
||
| 221 | 221 | $prepared = array(); |
| 222 | 222 | |
| 223 | 223 | // Raw submission details. |
| 224 | - $data = $submission->get_data(); |
|
| 224 | + $data = $submission->get_data(); |
|
| 225 | 225 | |
| 226 | 226 | // Loop through the submitted details. |
| 227 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
| 227 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
| 228 | 228 | |
| 229 | 229 | // Skip premade fields. |
| 230 | - if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
|
| 230 | + if (!empty($field['premade']) || $field['type'] == 'address') { |
|
| 231 | 231 | continue; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // If it is required and not set, abort. |
| 235 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
| 236 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 235 | + if (!$submission->is_required_field_set($field)) { |
|
| 236 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Handle misc fields. |
| 240 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
| 240 | + if (isset($data[$field['id']])) { |
|
| 241 | 241 | $label = $field['id']; |
| 242 | 242 | |
| 243 | - if ( isset( $field['label'] ) ) { |
|
| 243 | + if (isset($field['label'])) { |
|
| 244 | 244 | $label = $field['label']; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
| 247 | + $prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]); |
|
| 248 | 248 | |
| 249 | 249 | } |
| 250 | 250 | |
@@ -261,30 +261,30 @@ discard block |
||
| 261 | 261 | * @param WPInv_Invoice $invoice |
| 262 | 262 | * @param string $type |
| 263 | 263 | */ |
| 264 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
| 264 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
| 265 | 265 | |
| 266 | 266 | $data = $this->payment_form_submission->get_data(); |
| 267 | - $type = sanitize_key( $type ); |
|
| 267 | + $type = sanitize_key($type); |
|
| 268 | 268 | $address = array(); |
| 269 | 269 | $prepared = array(); |
| 270 | 270 | |
| 271 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 272 | - $address = $data[ $type ]; |
|
| 271 | + if (!empty($data[$type])) { |
|
| 272 | + $address = $data[$type]; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Clean address details. |
| 276 | - foreach ( $address as $key => $value ) { |
|
| 277 | - $key = sanitize_key( $key ); |
|
| 278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 279 | - $value = wpinv_clean( $value ); |
|
| 280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 276 | + foreach ($address as $key => $value) { |
|
| 277 | + $key = sanitize_key($key); |
|
| 278 | + $key = str_replace('wpinv_', '', $key); |
|
| 279 | + $value = wpinv_clean($value); |
|
| 280 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Filter address details. |
| 284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 284 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
| 285 | 285 | |
| 286 | 286 | // Remove non-whitelisted values. |
| 287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 287 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
| 288 | 288 | |
| 289 | 289 | } |
| 290 | 290 | |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | * @return array |
| 295 | 295 | * @param WPInv_Invoice $invoice |
| 296 | 296 | */ |
| 297 | - protected function prepare_billing_info( &$invoice ) { |
|
| 297 | + protected function prepare_billing_info(&$invoice) { |
|
| 298 | 298 | |
| 299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 299 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
| 300 | 300 | |
| 301 | 301 | // Update the invoice with the billing details. |
| 302 | - $invoice->set_props( $billing_address ); |
|
| 302 | + $invoice->set_props($billing_address); |
|
| 303 | 303 | |
| 304 | 304 | } |
| 305 | 305 | |
@@ -309,15 +309,15 @@ discard block |
||
| 309 | 309 | * @return array |
| 310 | 310 | * @param WPInv_Invoice $invoice |
| 311 | 311 | */ |
| 312 | - protected function prepare_shipping_info( $invoice ) { |
|
| 312 | + protected function prepare_shipping_info($invoice) { |
|
| 313 | 313 | |
| 314 | 314 | $data = $this->payment_form_submission->get_data(); |
| 315 | 315 | |
| 316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 316 | + if (empty($data['same-shipping-address'])) { |
|
| 317 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 320 | + return $this->prepare_address_details($invoice, 'billing'); |
|
| 321 | 321 | |
| 322 | 322 | } |
| 323 | 323 | |
@@ -328,31 +328,31 @@ discard block |
||
| 328 | 328 | * @param array $prepared_payment_form_data |
| 329 | 329 | * @param array $shipping |
| 330 | 330 | */ |
| 331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 331 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
| 332 | 332 | |
| 333 | 333 | // Ensure the invoice exists. |
| 334 | - if ( ! $invoice->exists() ) { |
|
| 335 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
| 334 | + if (!$invoice->exists()) { |
|
| 335 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Save payment form data. |
| 339 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 340 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 341 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
| 339 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
| 340 | + if (!empty($prepared_payment_form_data)) { |
|
| 341 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Save payment form data. |
| 345 | - if ( ! empty( $shipping ) ) { |
|
| 346 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
| 345 | + if (!empty($shipping)) { |
|
| 346 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Backwards compatibility. |
| 350 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
| 350 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
| 351 | 351 | |
| 352 | - $this->process_payment( $invoice ); |
|
| 352 | + $this->process_payment($invoice); |
|
| 353 | 353 | |
| 354 | 354 | // If we are here, there was an error. |
| 355 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 355 | + wpinv_send_back_to_checkout($invoice); |
|
| 356 | 356 | |
| 357 | 357 | } |
| 358 | 358 | |
@@ -361,41 +361,41 @@ discard block |
||
| 361 | 361 | * |
| 362 | 362 | * @param WPInv_Invoice $invoice |
| 363 | 363 | */ |
| 364 | - protected function process_payment( $invoice ) { |
|
| 364 | + protected function process_payment($invoice) { |
|
| 365 | 365 | |
| 366 | 366 | // Clear any checkout errors. |
| 367 | 367 | wpinv_clear_errors(); |
| 368 | 368 | |
| 369 | 369 | // No need to send free invoices to the gateway. |
| 370 | - if ( $invoice->is_free() ) { |
|
| 371 | - $this->process_free_payment( $invoice ); |
|
| 370 | + if ($invoice->is_free()) { |
|
| 371 | + $this->process_free_payment($invoice); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $submission = $this->payment_form_submission; |
| 375 | 375 | |
| 376 | 376 | // Fires before sending to the gateway. |
| 377 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 377 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
| 378 | 378 | |
| 379 | 379 | // Allow the sumission data to be modified before it is sent to the gateway. |
| 380 | 380 | $submission_data = $submission->get_data(); |
| 381 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 382 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 381 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
| 382 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
| 383 | 383 | |
| 384 | 384 | // Validate the currency. |
| 385 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 386 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 385 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
| 386 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Check to see if we have any errors. |
| 390 | - if ( wpinv_get_errors() ) { |
|
| 391 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 390 | + if (wpinv_get_errors()) { |
|
| 391 | + wpinv_send_back_to_checkout($invoice); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // Send info to the gateway for payment processing |
| 395 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 395 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
| 396 | 396 | |
| 397 | 397 | // Backwards compatibility. |
| 398 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 398 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
| 399 | 399 | |
| 400 | 400 | } |
| 401 | 401 | |
@@ -404,12 +404,12 @@ discard block |
||
| 404 | 404 | * |
| 405 | 405 | * @param WPInv_Invoice $invoice |
| 406 | 406 | */ |
| 407 | - protected function process_free_payment( $invoice ) { |
|
| 407 | + protected function process_free_payment($invoice) { |
|
| 408 | 408 | |
| 409 | - $invoice->set_gateway( 'none' ); |
|
| 410 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 409 | + $invoice->set_gateway('none'); |
|
| 410 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
| 411 | 411 | $invoice->mark_paid(); |
| 412 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 412 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 413 | 413 | |
| 414 | 414 | } |
| 415 | 415 | |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * Sends a redrect response to payment details. |
| 418 | 418 | * |
| 419 | 419 | */ |
| 420 | - public function send_redirect_response( $url ) { |
|
| 421 | - $url = urlencode( $url ); |
|
| 422 | - wp_send_json_success( $url ); |
|
| 420 | + public function send_redirect_response($url) { |
|
| 421 | + $url = urlencode($url); |
|
| 422 | + wp_send_json_success($url); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $installPath = $this->getPackageBasePath($package); |
| 167 | 167 | $io = $this->io; |
| 168 | - $outputStatus = function () use ($io, $installPath) { |
|
| 168 | + $outputStatus = function() use ($io, $installPath) { |
|
| 169 | 169 | $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); |
| 170 | 170 | }; |
| 171 | 171 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return $pattern ? : '(\w+)'; |
|
| 238 | + return $pattern ?: '(\w+)'; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |