@@ -512,7 +512,7 @@ |
||
| 512 | 512 | |
| 513 | 513 | $response['success'] = true; |
| 514 | 514 | $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
| 515 | - } else { |
|
| 515 | + } else { |
|
| 516 | 516 | $errors = wpinv_get_errors(); |
| 517 | 517 | if ( !empty( $errors['wpinv-discount-error'] ) ) { |
| 518 | 518 | $response['msg'] = $errors['wpinv-discount-error']; |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | /** |
| 6 | 8 | * The Subscriptions DB Class |
@@ -5,237 +5,237 @@ |
||
| 5 | 5 | |
| 6 | 6 | abstract class Wpinv_DB { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * The name of our database table |
|
| 10 | - * |
|
| 11 | - * @access public |
|
| 12 | - * @since 1.0.0 |
|
| 13 | - */ |
|
| 14 | - public $table_name; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * The version of our database table |
|
| 18 | - * |
|
| 19 | - * @access public |
|
| 20 | - * @since 1.0.0 |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * The name of the primary column |
|
| 26 | - * |
|
| 27 | - * @access public |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - */ |
|
| 30 | - public $primary_key; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Get things started |
|
| 34 | - * |
|
| 35 | - * @access public |
|
| 36 | - * @since 1.0.0 |
|
| 37 | - */ |
|
| 38 | - public function __construct() {} |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Whitelist of columns |
|
| 42 | - * |
|
| 43 | - * @access public |
|
| 44 | - * @since 1.0.0 |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function get_columns() { |
|
| 48 | - return array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Default column values |
|
| 53 | - * |
|
| 54 | - * @access public |
|
| 55 | - * @since 1.0.0 |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - public function get_column_defaults() { |
|
| 59 | - return array(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Retrieve a row by the primary key |
|
| 64 | - * |
|
| 65 | - * @access public |
|
| 66 | - * @since 1.0.0 |
|
| 67 | - * @return object |
|
| 68 | - */ |
|
| 69 | - public function get( $row_id ) { |
|
| 70 | - global $wpdb; |
|
| 71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Retrieve a row by a specific column / value |
|
| 76 | - * |
|
| 77 | - * @access public |
|
| 78 | - * @since 1.0.0 |
|
| 79 | - * @return object |
|
| 80 | - */ |
|
| 81 | - public function get_by( $column, $row_id ) { |
|
| 82 | - global $wpdb; |
|
| 83 | - $column = esc_sql( $column ); |
|
| 84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Retrieve a specific column's value by the primary key |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @since 1.0.0 |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function get_column( $column, $row_id ) { |
|
| 95 | - global $wpdb; |
|
| 96 | - $column = esc_sql( $column ); |
|
| 97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Retrieve a specific column's value by the the specified column / value |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @since 1.0.0 |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 107 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
| 108 | - global $wpdb; |
|
| 109 | - $column_where = esc_sql( $column_where ); |
|
| 110 | - $column = esc_sql( $column ); |
|
| 111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Insert a new row |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @since 1.0.0 |
|
| 119 | - * @return int |
|
| 120 | - */ |
|
| 121 | - public function insert( $data, $type = '' ) { |
|
| 122 | - global $wpdb; |
|
| 123 | - |
|
| 124 | - // Set default values |
|
| 125 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
| 126 | - |
|
| 127 | - do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
| 128 | - |
|
| 129 | - // Initialise column format array |
|
| 130 | - $column_formats = $this->get_columns(); |
|
| 131 | - |
|
| 132 | - // Force fields to lower case |
|
| 133 | - $data = array_change_key_case( $data ); |
|
| 134 | - |
|
| 135 | - // White list columns |
|
| 136 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 137 | - |
|
| 138 | - // Reorder $column_formats to match the order of columns given in $data |
|
| 139 | - $data_keys = array_keys( $data ); |
|
| 140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 141 | - |
|
| 142 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
| 143 | - $wpdb_insert_id = $wpdb->insert_id; |
|
| 144 | - |
|
| 145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
| 146 | - |
|
| 147 | - return $wpdb_insert_id; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Update a row |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @since 1.0.0 |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
| 158 | - |
|
| 159 | - global $wpdb; |
|
| 160 | - |
|
| 161 | - // Row ID must be positive integer |
|
| 162 | - $row_id = absint( $row_id ); |
|
| 163 | - |
|
| 164 | - if( empty( $row_id ) ) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if( empty( $where ) ) { |
|
| 169 | - $where = $this->primary_key; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // Initialise column format array |
|
| 173 | - $column_formats = $this->get_columns(); |
|
| 174 | - |
|
| 175 | - // Force fields to lower case |
|
| 176 | - $data = array_change_key_case( $data ); |
|
| 177 | - |
|
| 178 | - // White list columns |
|
| 179 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 180 | - |
|
| 181 | - // Reorder $column_formats to match the order of columns given in $data |
|
| 182 | - $data_keys = array_keys( $data ); |
|
| 183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 184 | - |
|
| 185 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
| 186 | - return false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Delete a row identified by the primary key |
|
| 194 | - * |
|
| 195 | - * @access public |
|
| 196 | - * @since 1.0.0 |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function delete( $row_id = 0 ) { |
|
| 200 | - |
|
| 201 | - global $wpdb; |
|
| 202 | - |
|
| 203 | - // Row ID must be positive integer |
|
| 204 | - $row_id = absint( $row_id ); |
|
| 205 | - |
|
| 206 | - if( empty( $row_id ) ) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Check if the given table exists |
|
| 219 | - * |
|
| 220 | - * @since 2.4 |
|
| 221 | - * @param string $table The table name |
|
| 222 | - * @return bool If the table name exists |
|
| 223 | - */ |
|
| 224 | - public function table_exists( $table ) { |
|
| 225 | - global $wpdb; |
|
| 226 | - $table = sanitize_text_field( $table ); |
|
| 227 | - |
|
| 228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Check if the table was ever installed |
|
| 233 | - * |
|
| 234 | - * @since 2.4 |
|
| 235 | - * @return bool Returns if the customers table was installed and upgrade routine run |
|
| 236 | - */ |
|
| 237 | - public function installed() { |
|
| 238 | - return $this->table_exists( $this->table_name ); |
|
| 239 | - } |
|
| 8 | + /** |
|
| 9 | + * The name of our database table |
|
| 10 | + * |
|
| 11 | + * @access public |
|
| 12 | + * @since 1.0.0 |
|
| 13 | + */ |
|
| 14 | + public $table_name; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * The version of our database table |
|
| 18 | + * |
|
| 19 | + * @access public |
|
| 20 | + * @since 1.0.0 |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * The name of the primary column |
|
| 26 | + * |
|
| 27 | + * @access public |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + */ |
|
| 30 | + public $primary_key; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Get things started |
|
| 34 | + * |
|
| 35 | + * @access public |
|
| 36 | + * @since 1.0.0 |
|
| 37 | + */ |
|
| 38 | + public function __construct() {} |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Whitelist of columns |
|
| 42 | + * |
|
| 43 | + * @access public |
|
| 44 | + * @since 1.0.0 |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function get_columns() { |
|
| 48 | + return array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Default column values |
|
| 53 | + * |
|
| 54 | + * @access public |
|
| 55 | + * @since 1.0.0 |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + public function get_column_defaults() { |
|
| 59 | + return array(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Retrieve a row by the primary key |
|
| 64 | + * |
|
| 65 | + * @access public |
|
| 66 | + * @since 1.0.0 |
|
| 67 | + * @return object |
|
| 68 | + */ |
|
| 69 | + public function get( $row_id ) { |
|
| 70 | + global $wpdb; |
|
| 71 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Retrieve a row by a specific column / value |
|
| 76 | + * |
|
| 77 | + * @access public |
|
| 78 | + * @since 1.0.0 |
|
| 79 | + * @return object |
|
| 80 | + */ |
|
| 81 | + public function get_by( $column, $row_id ) { |
|
| 82 | + global $wpdb; |
|
| 83 | + $column = esc_sql( $column ); |
|
| 84 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Retrieve a specific column's value by the primary key |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @since 1.0.0 |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function get_column( $column, $row_id ) { |
|
| 95 | + global $wpdb; |
|
| 96 | + $column = esc_sql( $column ); |
|
| 97 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Retrieve a specific column's value by the the specified column / value |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @since 1.0.0 |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | + public function get_column_by( $column, $column_where, $column_value ) { |
|
| 108 | + global $wpdb; |
|
| 109 | + $column_where = esc_sql( $column_where ); |
|
| 110 | + $column = esc_sql( $column ); |
|
| 111 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Insert a new row |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @since 1.0.0 |
|
| 119 | + * @return int |
|
| 120 | + */ |
|
| 121 | + public function insert( $data, $type = '' ) { |
|
| 122 | + global $wpdb; |
|
| 123 | + |
|
| 124 | + // Set default values |
|
| 125 | + $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
| 126 | + |
|
| 127 | + do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
| 128 | + |
|
| 129 | + // Initialise column format array |
|
| 130 | + $column_formats = $this->get_columns(); |
|
| 131 | + |
|
| 132 | + // Force fields to lower case |
|
| 133 | + $data = array_change_key_case( $data ); |
|
| 134 | + |
|
| 135 | + // White list columns |
|
| 136 | + $data = array_intersect_key( $data, $column_formats ); |
|
| 137 | + |
|
| 138 | + // Reorder $column_formats to match the order of columns given in $data |
|
| 139 | + $data_keys = array_keys( $data ); |
|
| 140 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 141 | + |
|
| 142 | + $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
| 143 | + $wpdb_insert_id = $wpdb->insert_id; |
|
| 144 | + |
|
| 145 | + do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
| 146 | + |
|
| 147 | + return $wpdb_insert_id; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Update a row |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @since 1.0.0 |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function update( $row_id, $data = array(), $where = '' ) { |
|
| 158 | + |
|
| 159 | + global $wpdb; |
|
| 160 | + |
|
| 161 | + // Row ID must be positive integer |
|
| 162 | + $row_id = absint( $row_id ); |
|
| 163 | + |
|
| 164 | + if( empty( $row_id ) ) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if( empty( $where ) ) { |
|
| 169 | + $where = $this->primary_key; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // Initialise column format array |
|
| 173 | + $column_formats = $this->get_columns(); |
|
| 174 | + |
|
| 175 | + // Force fields to lower case |
|
| 176 | + $data = array_change_key_case( $data ); |
|
| 177 | + |
|
| 178 | + // White list columns |
|
| 179 | + $data = array_intersect_key( $data, $column_formats ); |
|
| 180 | + |
|
| 181 | + // Reorder $column_formats to match the order of columns given in $data |
|
| 182 | + $data_keys = array_keys( $data ); |
|
| 183 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 184 | + |
|
| 185 | + if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
| 186 | + return false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Delete a row identified by the primary key |
|
| 194 | + * |
|
| 195 | + * @access public |
|
| 196 | + * @since 1.0.0 |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function delete( $row_id = 0 ) { |
|
| 200 | + |
|
| 201 | + global $wpdb; |
|
| 202 | + |
|
| 203 | + // Row ID must be positive integer |
|
| 204 | + $row_id = absint( $row_id ); |
|
| 205 | + |
|
| 206 | + if( empty( $row_id ) ) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Check if the given table exists |
|
| 219 | + * |
|
| 220 | + * @since 2.4 |
|
| 221 | + * @param string $table The table name |
|
| 222 | + * @return bool If the table name exists |
|
| 223 | + */ |
|
| 224 | + public function table_exists( $table ) { |
|
| 225 | + global $wpdb; |
|
| 226 | + $table = sanitize_text_field( $table ); |
|
| 227 | + |
|
| 228 | + return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Check if the table was ever installed |
|
| 233 | + * |
|
| 234 | + * @since 2.4 |
|
| 235 | + * @return bool Returns if the customers table was installed and upgrade routine run |
|
| 236 | + */ |
|
| 237 | + public function installed() { |
|
| 238 | + return $this->table_exists( $this->table_name ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | } |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | abstract class Wpinv_DB { |
| 7 | 9 | |
@@ -8,7 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | + exit; |
|
| 13 | +} |
|
| 12 | 14 | |
| 13 | 15 | |
| 14 | 16 | // Load WP_List_Table if not loaded |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded |
| 15 | 15 | if( ! class_exists( 'WP_List_Table' ) ) { |
| 16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,102 +23,102 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class WPInv_Subscription_Reports_Table extends WP_List_Table { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Number of results to show per page |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - */ |
|
| 31 | - |
|
| 32 | - public $per_page = 20; |
|
| 33 | - public $total_count = 0; |
|
| 34 | - public $active_count = 0; |
|
| 35 | - public $pending_count = 0; |
|
| 36 | - public $expired_count = 0; |
|
| 37 | - public $completed_count = 0; |
|
| 38 | - public $trialling_count = 0; |
|
| 39 | - public $cancelled_count = 0; |
|
| 40 | - public $failing_count = 0; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Get things started |
|
| 44 | - * |
|
| 45 | - * @access private |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function __construct(){ |
|
| 50 | - global $status, $page; |
|
| 51 | - |
|
| 52 | - // Set parent defaults |
|
| 53 | - parent::__construct( array( |
|
| 54 | - 'singular' => 'subscription', |
|
| 55 | - 'plural' => 'subscriptions', |
|
| 56 | - 'ajax' => false |
|
| 57 | - ) ); |
|
| 58 | - |
|
| 59 | - $this->get_subscription_counts(); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieve the view types |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @since 1.0.0 |
|
| 68 | - * @return array $views All the views available |
|
| 69 | - */ |
|
| 70 | - public function get_views() { |
|
| 71 | - |
|
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | - $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | - $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | - $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | - |
|
| 82 | - $views = array( |
|
| 83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Show the search field |
|
| 98 | - * |
|
| 99 | - * @since 2.5 |
|
| 100 | - * @access public |
|
| 101 | - * |
|
| 102 | - * @param string $text Label for the search box |
|
| 103 | - * @param string $input_id ID of the search box |
|
| 104 | - * |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function search_box( $text, $input_id ) { |
|
| 108 | - |
|
| 109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $input_id = $input_id . '-search-input'; |
|
| 114 | - |
|
| 115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | - } |
|
| 26 | + /** |
|
| 27 | + * Number of results to show per page |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + */ |
|
| 31 | + |
|
| 32 | + public $per_page = 20; |
|
| 33 | + public $total_count = 0; |
|
| 34 | + public $active_count = 0; |
|
| 35 | + public $pending_count = 0; |
|
| 36 | + public $expired_count = 0; |
|
| 37 | + public $completed_count = 0; |
|
| 38 | + public $trialling_count = 0; |
|
| 39 | + public $cancelled_count = 0; |
|
| 40 | + public $failing_count = 0; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Get things started |
|
| 44 | + * |
|
| 45 | + * @access private |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function __construct(){ |
|
| 50 | + global $status, $page; |
|
| 51 | + |
|
| 52 | + // Set parent defaults |
|
| 53 | + parent::__construct( array( |
|
| 54 | + 'singular' => 'subscription', |
|
| 55 | + 'plural' => 'subscriptions', |
|
| 56 | + 'ajax' => false |
|
| 57 | + ) ); |
|
| 58 | + |
|
| 59 | + $this->get_subscription_counts(); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieve the view types |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @since 1.0.0 |
|
| 68 | + * @return array $views All the views available |
|
| 69 | + */ |
|
| 70 | + public function get_views() { |
|
| 71 | + |
|
| 72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | + $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | + $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | + $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | + |
|
| 82 | + $views = array( |
|
| 83 | + 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | + 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | + 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | + 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | + 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | + 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | + 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | + 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Show the search field |
|
| 98 | + * |
|
| 99 | + * @since 2.5 |
|
| 100 | + * @access public |
|
| 101 | + * |
|
| 102 | + * @param string $text Label for the search box |
|
| 103 | + * @param string $input_id ID of the search box |
|
| 104 | + * |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function search_box( $text, $input_id ) { |
|
| 108 | + |
|
| 109 | + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $input_id = $input_id . '-search-input'; |
|
| 114 | + |
|
| 115 | + if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | + } |
|
| 122 | 122 | ?> |
| 123 | 123 | <p class="search-box"> |
| 124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
| 128 | 128 | </p> |
| 129 | 129 | <?php |
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Render most columns |
|
| 134 | - * |
|
| 135 | - * @access private |
|
| 136 | - * @since 1.0.0 |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - function column_default( $item, $column_name ) { |
|
| 140 | - return $item->$column_name; |
|
| 141 | - } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Render most columns |
|
| 134 | + * |
|
| 135 | + * @access private |
|
| 136 | + * @since 1.0.0 |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + function column_default( $item, $column_name ) { |
|
| 140 | + return $item->$column_name; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * Subscription id column |
@@ -151,244 +151,244 @@ discard block |
||
| 151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Customer column |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @since 1.0.0 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - function column_customer_id( $item ) { |
|
| 162 | - $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | - |
|
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Status column |
|
| 170 | - * |
|
| 171 | - * @access private |
|
| 172 | - * @since 1.0.0 |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - function column_status( $item ) { |
|
| 176 | - return $item->get_status_label(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Period column |
|
| 181 | - * |
|
| 182 | - * @access private |
|
| 183 | - * @since 1.0.0 |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - function column_period( $item ) { |
|
| 187 | - |
|
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | - |
|
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Billing Times column |
|
| 195 | - * |
|
| 196 | - * @access private |
|
| 197 | - * @since 1.0.0 |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - function column_bill_times( $item ) { |
|
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Initial Amount column |
|
| 206 | - * |
|
| 207 | - * @access private |
|
| 208 | - * @since 1.0.0 |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - function column_initial_amount( $item ) { |
|
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Renewal date column |
|
| 217 | - * |
|
| 218 | - * @access private |
|
| 219 | - * @since 1.0.0 |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - function column_renewal_date( $item ) { |
|
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Payment column |
|
| 228 | - * |
|
| 229 | - * @access private |
|
| 230 | - * @since 1.0.0 |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - function column_parent_payment_id( $item ) { |
|
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Product ID column |
|
| 239 | - * |
|
| 240 | - * @access private |
|
| 241 | - * @since 1.0.0 |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - function column_product_id( $item ) { |
|
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Render the edit column |
|
| 250 | - * |
|
| 251 | - * @access private |
|
| 252 | - * @since 2.0 |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - function column_actions( $item ) { |
|
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Retrieve the table columns |
|
| 262 | - * |
|
| 263 | - * @access private |
|
| 264 | - * @since 1.0.0 |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 267 | - |
|
| 268 | - function get_columns(){ |
|
| 269 | - $columns = array( |
|
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Retrieve the current page number |
|
| 287 | - * |
|
| 288 | - * @access private |
|
| 289 | - * @since 1.0.0 |
|
| 290 | - * @return int |
|
| 291 | - */ |
|
| 292 | - function get_paged() { |
|
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Retrieve the subscription counts |
|
| 298 | - * |
|
| 299 | - * @access public |
|
| 300 | - * @since 1.4 |
|
| 301 | - * @return void |
|
| 302 | - */ |
|
| 303 | - public function get_subscription_counts() { |
|
| 304 | - |
|
| 305 | - global $wp_query; |
|
| 306 | - |
|
| 307 | - $db = new WPInv_Subscriptions_DB; |
|
| 308 | - |
|
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | - |
|
| 311 | - $this->total_count = $db->count(); |
|
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | - |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Setup the final data for the table |
|
| 324 | - * |
|
| 325 | - * @access private |
|
| 326 | - * @since 1.0.0 |
|
| 327 | - * @uses $this->_column_headers |
|
| 328 | - * @uses $this->items |
|
| 329 | - * @uses $this->get_columns() |
|
| 330 | - * @uses $this->get_sortable_columns() |
|
| 331 | - * @uses $this->get_pagenum() |
|
| 332 | - * @uses $this->set_pagination_args() |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - function prepare_items() { |
|
| 336 | - |
|
| 337 | - $columns = $this->get_columns(); |
|
| 338 | - $hidden = array(); // No hidden columns |
|
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | - $sortable = $this->get_sortable_columns(); |
|
| 341 | - |
|
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | - |
|
| 344 | - $current_page = $this->get_pagenum(); |
|
| 345 | - |
|
| 346 | - $db = new WPInv_Subscriptions_DB; |
|
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | - $args = array( |
|
| 349 | - 'number' => $this->per_page, |
|
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | - 'search' => $search |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - if ( 'any' !== $status ) { |
|
| 355 | - $args['status'] = $status; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $this->items = $db->get_subscriptions( $args ); |
|
| 359 | - |
|
| 360 | - switch ( $status ) { |
|
| 361 | - case 'active': |
|
| 362 | - $total_items = $this->active_count; |
|
| 363 | - break; |
|
| 364 | - case 'pending': |
|
| 365 | - $total_items = $this->pending_count; |
|
| 366 | - break; |
|
| 367 | - case 'expired': |
|
| 368 | - $total_items = $this->expired_count; |
|
| 369 | - break; |
|
| 370 | - case 'cancelled': |
|
| 371 | - $total_items = $this->cancelled_count; |
|
| 372 | - break; |
|
| 373 | - case 'failing': |
|
| 374 | - $total_items = $this->failing_count; |
|
| 375 | - break; |
|
| 376 | - case 'trialling': |
|
| 377 | - $total_items = $this->trialling_count; |
|
| 378 | - break; |
|
| 379 | - case 'completed': |
|
| 380 | - $total_items = $this->completed_count; |
|
| 381 | - break; |
|
| 382 | - case 'any': |
|
| 383 | - default: |
|
| 384 | - $total_items = $this->total_count; |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $this->set_pagination_args( array( |
|
| 389 | - 'total_items' => $total_items, |
|
| 390 | - 'per_page' => $this->per_page, |
|
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | - ) ); |
|
| 393 | - } |
|
| 154 | + /** |
|
| 155 | + * Customer column |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @since 1.0.0 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + function column_customer_id( $item ) { |
|
| 162 | + $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | + |
|
| 165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Status column |
|
| 170 | + * |
|
| 171 | + * @access private |
|
| 172 | + * @since 1.0.0 |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + function column_status( $item ) { |
|
| 176 | + return $item->get_status_label(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Period column |
|
| 181 | + * |
|
| 182 | + * @access private |
|
| 183 | + * @since 1.0.0 |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + function column_period( $item ) { |
|
| 187 | + |
|
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | + |
|
| 190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Billing Times column |
|
| 195 | + * |
|
| 196 | + * @access private |
|
| 197 | + * @since 1.0.0 |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + function column_bill_times( $item ) { |
|
| 201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Initial Amount column |
|
| 206 | + * |
|
| 207 | + * @access private |
|
| 208 | + * @since 1.0.0 |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + function column_initial_amount( $item ) { |
|
| 212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Renewal date column |
|
| 217 | + * |
|
| 218 | + * @access private |
|
| 219 | + * @since 1.0.0 |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + function column_renewal_date( $item ) { |
|
| 223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Payment column |
|
| 228 | + * |
|
| 229 | + * @access private |
|
| 230 | + * @since 1.0.0 |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + function column_parent_payment_id( $item ) { |
|
| 234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Product ID column |
|
| 239 | + * |
|
| 240 | + * @access private |
|
| 241 | + * @since 1.0.0 |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + function column_product_id( $item ) { |
|
| 245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Render the edit column |
|
| 250 | + * |
|
| 251 | + * @access private |
|
| 252 | + * @since 2.0 |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + function column_actions( $item ) { |
|
| 256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Retrieve the table columns |
|
| 262 | + * |
|
| 263 | + * @access private |
|
| 264 | + * @since 1.0.0 |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | + |
|
| 268 | + function get_columns(){ |
|
| 269 | + $columns = array( |
|
| 270 | + 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | + 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | + 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | + 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | + 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Retrieve the current page number |
|
| 287 | + * |
|
| 288 | + * @access private |
|
| 289 | + * @since 1.0.0 |
|
| 290 | + * @return int |
|
| 291 | + */ |
|
| 292 | + function get_paged() { |
|
| 293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Retrieve the subscription counts |
|
| 298 | + * |
|
| 299 | + * @access public |
|
| 300 | + * @since 1.4 |
|
| 301 | + * @return void |
|
| 302 | + */ |
|
| 303 | + public function get_subscription_counts() { |
|
| 304 | + |
|
| 305 | + global $wp_query; |
|
| 306 | + |
|
| 307 | + $db = new WPInv_Subscriptions_DB; |
|
| 308 | + |
|
| 309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | + |
|
| 311 | + $this->total_count = $db->count(); |
|
| 312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | + |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Setup the final data for the table |
|
| 324 | + * |
|
| 325 | + * @access private |
|
| 326 | + * @since 1.0.0 |
|
| 327 | + * @uses $this->_column_headers |
|
| 328 | + * @uses $this->items |
|
| 329 | + * @uses $this->get_columns() |
|
| 330 | + * @uses $this->get_sortable_columns() |
|
| 331 | + * @uses $this->get_pagenum() |
|
| 332 | + * @uses $this->set_pagination_args() |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + function prepare_items() { |
|
| 336 | + |
|
| 337 | + $columns = $this->get_columns(); |
|
| 338 | + $hidden = array(); // No hidden columns |
|
| 339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | + $sortable = $this->get_sortable_columns(); |
|
| 341 | + |
|
| 342 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | + |
|
| 344 | + $current_page = $this->get_pagenum(); |
|
| 345 | + |
|
| 346 | + $db = new WPInv_Subscriptions_DB; |
|
| 347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | + $args = array( |
|
| 349 | + 'number' => $this->per_page, |
|
| 350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | + 'search' => $search |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + if ( 'any' !== $status ) { |
|
| 355 | + $args['status'] = $status; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $this->items = $db->get_subscriptions( $args ); |
|
| 359 | + |
|
| 360 | + switch ( $status ) { |
|
| 361 | + case 'active': |
|
| 362 | + $total_items = $this->active_count; |
|
| 363 | + break; |
|
| 364 | + case 'pending': |
|
| 365 | + $total_items = $this->pending_count; |
|
| 366 | + break; |
|
| 367 | + case 'expired': |
|
| 368 | + $total_items = $this->expired_count; |
|
| 369 | + break; |
|
| 370 | + case 'cancelled': |
|
| 371 | + $total_items = $this->cancelled_count; |
|
| 372 | + break; |
|
| 373 | + case 'failing': |
|
| 374 | + $total_items = $this->failing_count; |
|
| 375 | + break; |
|
| 376 | + case 'trialling': |
|
| 377 | + $total_items = $this->trialling_count; |
|
| 378 | + break; |
|
| 379 | + case 'completed': |
|
| 380 | + $total_items = $this->completed_count; |
|
| 381 | + break; |
|
| 382 | + case 'any': |
|
| 383 | + default: |
|
| 384 | + $total_items = $this->total_count; |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $this->set_pagination_args( array( |
|
| 389 | + 'total_items' => $total_items, |
|
| 390 | + 'per_page' => $this->per_page, |
|
| 391 | + 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | + ) ); |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | function wpinv_subscription_init() { |
| 6 | 8 | return WPInv_Subscriptions::instance(); |
@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function wpinv_can_checkout() { |
| 33 | - $can_checkout = true; // Always true for now |
|
| 33 | + $can_checkout = true; // Always true for now |
|
| 34 | 34 | |
| 35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 35 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function wpinv_get_success_page_uri() { |
| 39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | - $page_id = absint( $page_id ); |
|
| 39 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | + $page_id = absint( $page_id ); |
|
| 41 | 41 | |
| 42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 42 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function wpinv_get_history_page_uri() { |
| 46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | - $page_id = absint( $page_id ); |
|
| 46 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | + $page_id = absint( $page_id ); |
|
| 48 | 48 | |
| 49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 49 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function wpinv_is_success_page() { |
| 53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 53 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | + $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 55 | 55 | |
| 56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 56 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_invoice_history_page() { |
| 60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 60 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | + $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function wpinv_is_subscriptions_history_page() { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function wpinv_send_to_success_page( $args = null ) { |
| 72 | - $redirect = wpinv_get_success_page_uri(); |
|
| 72 | + $redirect = wpinv_get_success_page_uri(); |
|
| 73 | 73 | |
| 74 | 74 | if ( !empty( $args ) ) { |
| 75 | 75 | // Check for backward compatibility |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
| 92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
| 92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
| 93 | 93 | |
| 94 | 94 | if ( !empty( $args ) ) { |
| 95 | 95 | // Check for backward compatibility |
@@ -109,72 +109,72 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
| 112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 114 | 114 | |
| 115 | - if ( !empty( $args ) ) { |
|
| 116 | - // Check for backward compatibility |
|
| 117 | - if ( is_string( $args ) ) |
|
| 118 | - $args = str_replace( '?', '', $args ); |
|
| 115 | + if ( !empty( $args ) ) { |
|
| 116 | + // Check for backward compatibility |
|
| 117 | + if ( is_string( $args ) ) |
|
| 118 | + $args = str_replace( '?', '', $args ); |
|
| 119 | 119 | |
| 120 | - $args = wp_parse_args( $args ); |
|
| 120 | + $args = wp_parse_args( $args ); |
|
| 121 | 121 | |
| 122 | - $uri = add_query_arg( $args, $uri ); |
|
| 123 | - } |
|
| 122 | + $uri = add_query_arg( $args, $uri ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 126 | 126 | |
| 127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 128 | 128 | |
| 129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 131 | - } |
|
| 129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | function wpinv_send_back_to_checkout( $args = array() ) { |
| 137 | - $redirect = wpinv_get_checkout_uri(); |
|
| 137 | + $redirect = wpinv_get_checkout_uri(); |
|
| 138 | 138 | |
| 139 | - if ( ! empty( $args ) ) { |
|
| 140 | - // Check for backward compatibility |
|
| 141 | - if ( is_string( $args ) ) |
|
| 142 | - $args = str_replace( '?', '', $args ); |
|
| 139 | + if ( ! empty( $args ) ) { |
|
| 140 | + // Check for backward compatibility |
|
| 141 | + if ( is_string( $args ) ) |
|
| 142 | + $args = str_replace( '?', '', $args ); |
|
| 143 | 143 | |
| 144 | - $args = wp_parse_args( $args ); |
|
| 144 | + $args = wp_parse_args( $args ); |
|
| 145 | 145 | |
| 146 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 147 | - } |
|
| 146 | + $redirect = add_query_arg( $args, $redirect ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 150 | - exit; |
|
| 149 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 150 | + exit; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | function wpinv_get_success_page_url( $query_string = null ) { |
| 154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 155 | - $success_page = get_permalink( $success_page ); |
|
| 154 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 155 | + $success_page = get_permalink( $success_page ); |
|
| 156 | 156 | |
| 157 | - if ( $query_string ) |
|
| 158 | - $success_page .= $query_string; |
|
| 157 | + if ( $query_string ) |
|
| 158 | + $success_page .= $query_string; |
|
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 160 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
| 164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 164 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 165 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 166 | 166 | |
| 167 | - if ( $extras ) |
|
| 168 | - $uri .= $extras; |
|
| 167 | + if ( $extras ) |
|
| 168 | + $uri .= $extras; |
|
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 170 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function wpinv_is_failed_transaction_page() { |
| 174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 174 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
| 175 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 176 | 176 | |
| 177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 177 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -1010,10 +1010,11 @@ discard block |
||
| 1010 | 1010 | |
| 1011 | 1011 | $checked = false; |
| 1012 | 1012 | |
| 1013 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 1014 | - $checked = true; |
|
| 1015 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 1016 | - $checked = true; |
|
| 1013 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) { |
|
| 1014 | + $checked = true; |
|
| 1015 | + } elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1016 | + $checked = true; |
|
| 1017 | + } |
|
| 1017 | 1018 | |
| 1018 | 1019 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
| 1019 | 1020 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
@@ -1030,10 +1031,11 @@ discard block |
||
| 1030 | 1031 | foreach ( $args['options'] as $key => $option ) : |
| 1031 | 1032 | $sanitize_key = wpinv_sanitize_key( $key ); |
| 1032 | 1033 | |
| 1033 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
| 1034 | - $enabled = '1'; |
|
| 1035 | - else |
|
| 1036 | - $enabled = null; |
|
| 1034 | + if ( isset( $wpinv_options['gateways'][ $key ] ) ) { |
|
| 1035 | + $enabled = '1'; |
|
| 1036 | + } else { |
|
| 1037 | + $enabled = null; |
|
| 1038 | + } |
|
| 1037 | 1039 | |
| 1038 | 1040 | echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
| 1039 | 1041 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
@@ -1393,7 +1395,8 @@ discard block |
||
| 1393 | 1395 | <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
| 1394 | 1396 | </tr> |
| 1395 | 1397 | <?php endforeach; ?> |
| 1396 | - <?php else : ?> |
|
| 1398 | + <?php else { |
|
| 1399 | + : ?> |
|
| 1397 | 1400 | <tr> |
| 1398 | 1401 | <td class="wpinv_tax_country"> |
| 1399 | 1402 | <?php |
@@ -1404,7 +1407,9 @@ discard block |
||
| 1404 | 1407 | 'show_option_none' => false, |
| 1405 | 1408 | 'class' => 'wpinv-tax-country', |
| 1406 | 1409 | 'placeholder' => __( 'Choose a country', 'invoicing' ) |
| 1407 | - ) ); ?> |
|
| 1410 | + ) ); |
|
| 1411 | +} |
|
| 1412 | +?> |
|
| 1408 | 1413 | </td> |
| 1409 | 1414 | <td class="wpinv_tax_state"> |
| 1410 | 1415 | <?php echo wpinv_html_text( array( |
@@ -876,322 +876,322 @@ discard block |
||
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
| 879 | - $pages_options = array(); |
|
| 879 | + $pages_options = array(); |
|
| 880 | 880 | |
| 881 | - if( $default_label !== NULL && $default_label !== false ) { |
|
| 882 | - $pages_options = array( '' => $default_label ); // Blank option |
|
| 883 | - } |
|
| 881 | + if( $default_label !== NULL && $default_label !== false ) { |
|
| 882 | + $pages_options = array( '' => $default_label ); // Blank option |
|
| 883 | + } |
|
| 884 | 884 | |
| 885 | - $pages = get_pages(); |
|
| 886 | - if ( $pages ) { |
|
| 887 | - foreach ( $pages as $page ) { |
|
| 888 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 885 | + $pages = get_pages(); |
|
| 886 | + if ( $pages ) { |
|
| 887 | + foreach ( $pages as $page ) { |
|
| 888 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 889 | 889 | $pages_options[ $page->ID ] = $title; |
| 890 | - } |
|
| 891 | - } |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | - return $pages_options; |
|
| 893 | + return $pages_options; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | function wpinv_header_callback( $args ) { |
| 897 | - if ( !empty( $args['desc'] ) ) { |
|
| 897 | + if ( !empty( $args['desc'] ) ) { |
|
| 898 | 898 | echo $args['desc']; |
| 899 | 899 | } |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | function wpinv_hidden_callback( $args ) { |
| 903 | - global $wpinv_options; |
|
| 904 | - |
|
| 905 | - if ( isset( $args['set_value'] ) ) { |
|
| 906 | - $value = $args['set_value']; |
|
| 907 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 908 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 909 | - } else { |
|
| 910 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 914 | - $args['readonly'] = true; |
|
| 915 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 916 | - $name = ''; |
|
| 917 | - } else { |
|
| 918 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 903 | + global $wpinv_options; |
|
| 904 | + |
|
| 905 | + if ( isset( $args['set_value'] ) ) { |
|
| 906 | + $value = $args['set_value']; |
|
| 907 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 908 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 909 | + } else { |
|
| 910 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 914 | + $args['readonly'] = true; |
|
| 915 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 916 | + $name = ''; |
|
| 917 | + } else { |
|
| 918 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 922 | 922 | |
| 923 | - echo $html; |
|
| 923 | + echo $html; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | function wpinv_checkbox_callback( $args ) { |
| 927 | - global $wpinv_options; |
|
| 927 | + global $wpinv_options; |
|
| 928 | 928 | |
| 929 | 929 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 930 | 930 | |
| 931 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 932 | - $name = ''; |
|
| 933 | - } else { |
|
| 934 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
| 935 | - } |
|
| 931 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 932 | + $name = ''; |
|
| 933 | + } else { |
|
| 934 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
| 935 | + } |
|
| 936 | 936 | |
| 937 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
| 938 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
| 939 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 937 | + $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
| 938 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
| 939 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 940 | 940 | |
| 941 | - echo $html; |
|
| 941 | + echo $html; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | function wpinv_multicheck_callback( $args ) { |
| 945 | - global $wpinv_options; |
|
| 945 | + global $wpinv_options; |
|
| 946 | 946 | |
| 947 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 947 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 948 | 948 | |
| 949 | - if ( ! empty( $args['options'] ) ) { |
|
| 950 | - foreach( $args['options'] as $key => $option ): |
|
| 951 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 952 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
| 953 | - $enabled = $sanitize_key; |
|
| 954 | - } else { |
|
| 955 | - $enabled = NULL; |
|
| 956 | - } |
|
| 957 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 958 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
| 959 | - endforeach; |
|
| 960 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 961 | - } |
|
| 949 | + if ( ! empty( $args['options'] ) ) { |
|
| 950 | + foreach( $args['options'] as $key => $option ): |
|
| 951 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 952 | + if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
| 953 | + $enabled = $sanitize_key; |
|
| 954 | + } else { |
|
| 955 | + $enabled = NULL; |
|
| 956 | + } |
|
| 957 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 958 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
| 959 | + endforeach; |
|
| 960 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
| 961 | + } |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | function wpinv_payment_icons_callback( $args ) { |
| 965 | - global $wpinv_options; |
|
| 965 | + global $wpinv_options; |
|
| 966 | 966 | |
| 967 | 967 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 968 | 968 | |
| 969 | - if ( ! empty( $args['options'] ) ) { |
|
| 970 | - foreach( $args['options'] as $key => $option ) { |
|
| 969 | + if ( ! empty( $args['options'] ) ) { |
|
| 970 | + foreach( $args['options'] as $key => $option ) { |
|
| 971 | 971 | $sanitize_key = wpinv_sanitize_key( $key ); |
| 972 | 972 | |
| 973 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 974 | - $enabled = $option; |
|
| 975 | - } else { |
|
| 976 | - $enabled = NULL; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 980 | - |
|
| 981 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 982 | - |
|
| 983 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
| 984 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 985 | - } else { |
|
| 986 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 987 | - |
|
| 988 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 989 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 990 | - } else { |
|
| 991 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 992 | - $content_dir = WP_CONTENT_DIR; |
|
| 993 | - |
|
| 994 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 995 | - // Replaces backslashes with forward slashes for Windows systems |
|
| 996 | - $image = wp_normalize_path( $image ); |
|
| 997 | - $content_dir = wp_normalize_path( $content_dir ); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1004 | - } |
|
| 1005 | - echo $option . '</label>'; |
|
| 1006 | - } |
|
| 1007 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1008 | - } |
|
| 973 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
| 974 | + $enabled = $option; |
|
| 975 | + } else { |
|
| 976 | + $enabled = NULL; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 980 | + |
|
| 981 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 982 | + |
|
| 983 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
| 984 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 985 | + } else { |
|
| 986 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 987 | + |
|
| 988 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 989 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 990 | + } else { |
|
| 991 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 992 | + $content_dir = WP_CONTENT_DIR; |
|
| 993 | + |
|
| 994 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 995 | + // Replaces backslashes with forward slashes for Windows systems |
|
| 996 | + $image = wp_normalize_path( $image ); |
|
| 997 | + $content_dir = wp_normalize_path( $content_dir ); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 1004 | + } |
|
| 1005 | + echo $option . '</label>'; |
|
| 1006 | + } |
|
| 1007 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1008 | + } |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | function wpinv_radio_callback( $args ) { |
| 1012 | - global $wpinv_options; |
|
| 1012 | + global $wpinv_options; |
|
| 1013 | 1013 | |
| 1014 | 1014 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1015 | 1015 | |
| 1016 | 1016 | foreach ( $args['options'] as $key => $option ) : |
| 1017 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1017 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1018 | 1018 | |
| 1019 | 1019 | $checked = false; |
| 1020 | 1020 | |
| 1021 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 1022 | - $checked = true; |
|
| 1023 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 1024 | - $checked = true; |
|
| 1021 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
| 1022 | + $checked = true; |
|
| 1023 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
| 1024 | + $checked = true; |
|
| 1025 | 1025 | |
| 1026 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
| 1027 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
| 1028 | - endforeach; |
|
| 1026 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
| 1027 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
| 1028 | + endforeach; |
|
| 1029 | 1029 | |
| 1030 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1030 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | function wpinv_gateways_callback( $args ) { |
| 1034 | - global $wpinv_options; |
|
| 1034 | + global $wpinv_options; |
|
| 1035 | 1035 | |
| 1036 | 1036 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1037 | 1037 | |
| 1038 | - foreach ( $args['options'] as $key => $option ) : |
|
| 1039 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1038 | + foreach ( $args['options'] as $key => $option ) : |
|
| 1039 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
| 1040 | 1040 | |
| 1041 | 1041 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
| 1042 | - $enabled = '1'; |
|
| 1043 | - else |
|
| 1044 | - $enabled = null; |
|
| 1042 | + $enabled = '1'; |
|
| 1043 | + else |
|
| 1044 | + $enabled = null; |
|
| 1045 | 1045 | |
| 1046 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 1047 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 1048 | - endforeach; |
|
| 1046 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
| 1047 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
| 1048 | + endforeach; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | function wpinv_gateway_select_callback($args) { |
| 1052 | - global $wpinv_options; |
|
| 1052 | + global $wpinv_options; |
|
| 1053 | 1053 | |
| 1054 | 1054 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1055 | 1055 | |
| 1056 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
|
| 1056 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
|
| 1057 | 1057 | |
| 1058 | - foreach ( $args['options'] as $key => $option ) : |
|
| 1059 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 1058 | + foreach ( $args['options'] as $key => $option ) : |
|
| 1059 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 1060 | 1060 | $selected = selected( $key, $args['selected'], false ); |
| 1061 | 1061 | } else { |
| 1062 | 1062 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
| 1063 | 1063 | } |
| 1064 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 1065 | - endforeach; |
|
| 1064 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 1065 | + endforeach; |
|
| 1066 | 1066 | |
| 1067 | - echo '</select>'; |
|
| 1068 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1067 | + echo '</select>'; |
|
| 1068 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | function wpinv_text_callback( $args ) { |
| 1072 | - global $wpinv_options; |
|
| 1072 | + global $wpinv_options; |
|
| 1073 | 1073 | |
| 1074 | 1074 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1075 | 1075 | |
| 1076 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1077 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1078 | - } else { |
|
| 1079 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1083 | - $args['readonly'] = true; |
|
| 1084 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1085 | - $name = ''; |
|
| 1086 | - } else { |
|
| 1087 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1088 | - } |
|
| 1089 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1090 | - |
|
| 1091 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
| 1092 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1093 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
| 1094 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1095 | - |
|
| 1096 | - echo $html; |
|
| 1076 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1077 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1078 | + } else { |
|
| 1079 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1083 | + $args['readonly'] = true; |
|
| 1084 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1085 | + $name = ''; |
|
| 1086 | + } else { |
|
| 1087 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1088 | + } |
|
| 1089 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1090 | + |
|
| 1091 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
| 1092 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1093 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
| 1094 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1095 | + |
|
| 1096 | + echo $html; |
|
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | 1099 | function wpinv_number_callback( $args ) { |
| 1100 | - global $wpinv_options; |
|
| 1100 | + global $wpinv_options; |
|
| 1101 | 1101 | |
| 1102 | 1102 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1103 | 1103 | |
| 1104 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1105 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1106 | - } else { |
|
| 1107 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1111 | - $args['readonly'] = true; |
|
| 1112 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1113 | - $name = ''; |
|
| 1114 | - } else { |
|
| 1115 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
| 1119 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
| 1120 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
| 1121 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1122 | - |
|
| 1123 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1124 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1125 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1126 | - |
|
| 1127 | - echo $html; |
|
| 1104 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1105 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1106 | + } else { |
|
| 1107 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 1111 | + $args['readonly'] = true; |
|
| 1112 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1113 | + $name = ''; |
|
| 1114 | + } else { |
|
| 1115 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
| 1119 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
| 1120 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
| 1121 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
| 1122 | + |
|
| 1123 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1124 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1125 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1126 | + |
|
| 1127 | + echo $html; |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | function wpinv_textarea_callback( $args ) { |
| 1131 | - global $wpinv_options; |
|
| 1131 | + global $wpinv_options; |
|
| 1132 | 1132 | |
| 1133 | 1133 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1134 | 1134 | |
| 1135 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1136 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1137 | - } else { |
|
| 1138 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1139 | - } |
|
| 1135 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1136 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1137 | + } else { |
|
| 1138 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | 1141 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 1142 | 1142 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
| 1143 | 1143 | |
| 1144 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1145 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1144 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1145 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1146 | 1146 | |
| 1147 | - echo $html; |
|
| 1147 | + echo $html; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | function wpinv_password_callback( $args ) { |
| 1151 | - global $wpinv_options; |
|
| 1151 | + global $wpinv_options; |
|
| 1152 | 1152 | |
| 1153 | 1153 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1154 | 1154 | |
| 1155 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1156 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1157 | - } else { |
|
| 1158 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1159 | - } |
|
| 1155 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1156 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1157 | + } else { |
|
| 1158 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1159 | + } |
|
| 1160 | 1160 | |
| 1161 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1162 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 1163 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1161 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1162 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 1163 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1164 | 1164 | |
| 1165 | - echo $html; |
|
| 1165 | + echo $html; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | function wpinv_missing_callback($args) { |
| 1169 | - printf( |
|
| 1170 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 1171 | - '<strong>' . $args['id'] . '</strong>' |
|
| 1172 | - ); |
|
| 1169 | + printf( |
|
| 1170 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 1171 | + '<strong>' . $args['id'] . '</strong>' |
|
| 1172 | + ); |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | function wpinv_select_callback($args) { |
| 1176 | - global $wpinv_options; |
|
| 1176 | + global $wpinv_options; |
|
| 1177 | 1177 | |
| 1178 | 1178 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1179 | 1179 | |
| 1180 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1181 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1182 | - } else { |
|
| 1183 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1184 | - } |
|
| 1180 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1181 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1182 | + } else { |
|
| 1183 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | 1186 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
| 1187 | 1187 | $value = $args['selected']; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | - if ( isset( $args['placeholder'] ) ) { |
|
| 1191 | - $placeholder = $args['placeholder']; |
|
| 1192 | - } else { |
|
| 1193 | - $placeholder = ''; |
|
| 1194 | - } |
|
| 1190 | + if ( isset( $args['placeholder'] ) ) { |
|
| 1191 | + $placeholder = $args['placeholder']; |
|
| 1192 | + } else { |
|
| 1193 | + $placeholder = ''; |
|
| 1194 | + } |
|
| 1195 | 1195 | |
| 1196 | 1196 | if( !empty( $args['onchange'] ) ) { |
| 1197 | 1197 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -1199,142 +1199,142 @@ discard block |
||
| 1199 | 1199 | $onchange = ''; |
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
| 1202 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
| 1203 | 1203 | |
| 1204 | - foreach ( $args['options'] as $option => $name ) { |
|
| 1205 | - $selected = selected( $option, $value, false ); |
|
| 1206 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1207 | - } |
|
| 1204 | + foreach ( $args['options'] as $option => $name ) { |
|
| 1205 | + $selected = selected( $option, $value, false ); |
|
| 1206 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1207 | + } |
|
| 1208 | 1208 | |
| 1209 | - $html .= '</select>'; |
|
| 1210 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1209 | + $html .= '</select>'; |
|
| 1210 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1211 | 1211 | |
| 1212 | - echo $html; |
|
| 1212 | + echo $html; |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | function wpinv_color_select_callback( $args ) { |
| 1216 | - global $wpinv_options; |
|
| 1216 | + global $wpinv_options; |
|
| 1217 | 1217 | |
| 1218 | 1218 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1219 | 1219 | |
| 1220 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1221 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1222 | - } else { |
|
| 1223 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1224 | - } |
|
| 1220 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1221 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1222 | + } else { |
|
| 1223 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1224 | + } |
|
| 1225 | 1225 | |
| 1226 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 1226 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 1227 | 1227 | |
| 1228 | - foreach ( $args['options'] as $option => $color ) { |
|
| 1229 | - $selected = selected( $option, $value, false ); |
|
| 1230 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 1231 | - } |
|
| 1228 | + foreach ( $args['options'] as $option => $color ) { |
|
| 1229 | + $selected = selected( $option, $value, false ); |
|
| 1230 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 1231 | + } |
|
| 1232 | 1232 | |
| 1233 | - $html .= '</select>'; |
|
| 1234 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1233 | + $html .= '</select>'; |
|
| 1234 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1235 | 1235 | |
| 1236 | - echo $html; |
|
| 1236 | + echo $html; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | function wpinv_rich_editor_callback( $args ) { |
| 1240 | - global $wpinv_options, $wp_version; |
|
| 1240 | + global $wpinv_options, $wp_version; |
|
| 1241 | 1241 | |
| 1242 | 1242 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1243 | 1243 | |
| 1244 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1245 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1244 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1245 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1246 | 1246 | |
| 1247 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 1248 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1249 | - } |
|
| 1250 | - } else { |
|
| 1251 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1252 | - } |
|
| 1247 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 1248 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1249 | + } |
|
| 1250 | + } else { |
|
| 1251 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1252 | + } |
|
| 1253 | 1253 | |
| 1254 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 1254 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 1255 | 1255 | |
| 1256 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 1257 | - ob_start(); |
|
| 1258 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 1259 | - $html = ob_get_clean(); |
|
| 1260 | - } else { |
|
| 1261 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1262 | - } |
|
| 1256 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 1257 | + ob_start(); |
|
| 1258 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
| 1259 | + $html = ob_get_clean(); |
|
| 1260 | + } else { |
|
| 1261 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 1262 | + } |
|
| 1263 | 1263 | |
| 1264 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1264 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1265 | 1265 | |
| 1266 | - echo $html; |
|
| 1266 | + echo $html; |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | 1269 | function wpinv_upload_callback( $args ) { |
| 1270 | - global $wpinv_options; |
|
| 1270 | + global $wpinv_options; |
|
| 1271 | 1271 | |
| 1272 | 1272 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1273 | 1273 | |
| 1274 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1275 | - $value = $wpinv_options[$args['id']]; |
|
| 1276 | - } else { |
|
| 1277 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1278 | - } |
|
| 1274 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1275 | + $value = $wpinv_options[$args['id']]; |
|
| 1276 | + } else { |
|
| 1277 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
| 1278 | + } |
|
| 1279 | 1279 | |
| 1280 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1281 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1282 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 1283 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1280 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 1281 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 1282 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 1283 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1284 | 1284 | |
| 1285 | - echo $html; |
|
| 1285 | + echo $html; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | function wpinv_color_callback( $args ) { |
| 1289 | - global $wpinv_options; |
|
| 1289 | + global $wpinv_options; |
|
| 1290 | 1290 | |
| 1291 | 1291 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1292 | 1292 | |
| 1293 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1294 | - $value = $wpinv_options[ $args['id'] ]; |
|
| 1295 | - } else { |
|
| 1296 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1297 | - } |
|
| 1293 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
| 1294 | + $value = $wpinv_options[ $args['id'] ]; |
|
| 1295 | + } else { |
|
| 1296 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1297 | + } |
|
| 1298 | 1298 | |
| 1299 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1299 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 1300 | 1300 | |
| 1301 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 1302 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1301 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
| 1302 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1303 | 1303 | |
| 1304 | - echo $html; |
|
| 1304 | + echo $html; |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | 1307 | function wpinv_country_states_callback($args) { |
| 1308 | - global $wpinv_options; |
|
| 1308 | + global $wpinv_options; |
|
| 1309 | 1309 | |
| 1310 | 1310 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 1311 | 1311 | |
| 1312 | - if ( isset( $args['placeholder'] ) ) { |
|
| 1313 | - $placeholder = $args['placeholder']; |
|
| 1314 | - } else { |
|
| 1315 | - $placeholder = ''; |
|
| 1316 | - } |
|
| 1312 | + if ( isset( $args['placeholder'] ) ) { |
|
| 1313 | + $placeholder = $args['placeholder']; |
|
| 1314 | + } else { |
|
| 1315 | + $placeholder = ''; |
|
| 1316 | + } |
|
| 1317 | 1317 | |
| 1318 | - $states = wpinv_get_country_states(); |
|
| 1318 | + $states = wpinv_get_country_states(); |
|
| 1319 | 1319 | |
| 1320 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ''; |
|
| 1321 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 1320 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ''; |
|
| 1321 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 1322 | 1322 | |
| 1323 | - foreach ( $states as $option => $name ) { |
|
| 1324 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 1325 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1326 | - } |
|
| 1323 | + foreach ( $states as $option => $name ) { |
|
| 1324 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
| 1325 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
| 1326 | + } |
|
| 1327 | 1327 | |
| 1328 | - $html .= '</select>'; |
|
| 1329 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1328 | + $html .= '</select>'; |
|
| 1329 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 1330 | 1330 | |
| 1331 | - echo $html; |
|
| 1331 | + echo $html; |
|
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | function wpinv_tax_rates_callback($args) { |
| 1335 | - global $wpinv_options; |
|
| 1336 | - $rates = wpinv_get_tax_rates(); |
|
| 1337 | - ob_start(); ?> |
|
| 1335 | + global $wpinv_options; |
|
| 1336 | + $rates = wpinv_get_tax_rates(); |
|
| 1337 | + ob_start(); ?> |
|
| 1338 | 1338 | </td><tr> |
| 1339 | 1339 | <td colspan="2" class="wpinv_tax_tdbox"> |
| 1340 | 1340 | <p><?php echo $args['desc']; ?></p> |
@@ -1358,39 +1358,39 @@ discard block |
||
| 1358 | 1358 | <tr> |
| 1359 | 1359 | <td class="wpinv_tax_country"> |
| 1360 | 1360 | <?php |
| 1361 | - echo wpinv_html_select( array( |
|
| 1362 | - 'options' => wpinv_get_country_list( true ), |
|
| 1363 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
| 1361 | + echo wpinv_html_select( array( |
|
| 1362 | + 'options' => wpinv_get_country_list( true ), |
|
| 1363 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
| 1364 | 1364 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
| 1365 | - 'selected' => $rate['country'], |
|
| 1366 | - 'show_option_all' => false, |
|
| 1367 | - 'show_option_none' => false, |
|
| 1368 | - 'class' => 'wpinv-tax-country', |
|
| 1369 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1370 | - ) ); |
|
| 1371 | - ?> |
|
| 1365 | + 'selected' => $rate['country'], |
|
| 1366 | + 'show_option_all' => false, |
|
| 1367 | + 'show_option_none' => false, |
|
| 1368 | + 'class' => 'wpinv-tax-country', |
|
| 1369 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1370 | + ) ); |
|
| 1371 | + ?> |
|
| 1372 | 1372 | </td> |
| 1373 | 1373 | <td class="wpinv_tax_state"> |
| 1374 | 1374 | <?php |
| 1375 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
| 1376 | - if( !empty( $states ) ) { |
|
| 1377 | - echo wpinv_html_select( array( |
|
| 1378 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 1379 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
| 1375 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
| 1376 | + if( !empty( $states ) ) { |
|
| 1377 | + echo wpinv_html_select( array( |
|
| 1378 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
| 1379 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
| 1380 | 1380 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 1381 | - 'selected' => $rate['state'], |
|
| 1382 | - 'show_option_all' => false, |
|
| 1383 | - 'show_option_none' => false, |
|
| 1384 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
| 1385 | - ) ); |
|
| 1386 | - } else { |
|
| 1387 | - echo wpinv_html_text( array( |
|
| 1388 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
| 1389 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
| 1381 | + 'selected' => $rate['state'], |
|
| 1382 | + 'show_option_all' => false, |
|
| 1383 | + 'show_option_none' => false, |
|
| 1384 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
| 1385 | + ) ); |
|
| 1386 | + } else { |
|
| 1387 | + echo wpinv_html_text( array( |
|
| 1388 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
| 1389 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
| 1390 | 1390 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
| 1391 | - ) ); |
|
| 1392 | - } |
|
| 1393 | - ?> |
|
| 1391 | + ) ); |
|
| 1392 | + } |
|
| 1393 | + ?> |
|
| 1394 | 1394 | </td> |
| 1395 | 1395 | <td class="wpinv_tax_global"> |
| 1396 | 1396 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -1405,19 +1405,19 @@ discard block |
||
| 1405 | 1405 | <tr> |
| 1406 | 1406 | <td class="wpinv_tax_country"> |
| 1407 | 1407 | <?php |
| 1408 | - echo wpinv_html_select( array( |
|
| 1409 | - 'options' => wpinv_get_country_list( true ), |
|
| 1410 | - 'name' => 'tax_rates[0][country]', |
|
| 1411 | - 'show_option_all' => false, |
|
| 1412 | - 'show_option_none' => false, |
|
| 1413 | - 'class' => 'wpinv-tax-country', |
|
| 1414 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1415 | - ) ); ?> |
|
| 1408 | + echo wpinv_html_select( array( |
|
| 1409 | + 'options' => wpinv_get_country_list( true ), |
|
| 1410 | + 'name' => 'tax_rates[0][country]', |
|
| 1411 | + 'show_option_all' => false, |
|
| 1412 | + 'show_option_none' => false, |
|
| 1413 | + 'class' => 'wpinv-tax-country', |
|
| 1414 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
| 1415 | + ) ); ?> |
|
| 1416 | 1416 | </td> |
| 1417 | 1417 | <td class="wpinv_tax_state"> |
| 1418 | 1418 | <?php echo wpinv_html_text( array( |
| 1419 | - 'name' => 'tax_rates[0][state]' |
|
| 1420 | - ) ); ?> |
|
| 1419 | + 'name' => 'tax_rates[0][state]' |
|
| 1420 | + ) ); ?> |
|
| 1421 | 1421 | </td> |
| 1422 | 1422 | <td class="wpinv_tax_global"> |
| 1423 | 1423 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
| 1433 | 1433 | </table> |
| 1434 | 1434 | <?php |
| 1435 | - echo ob_get_clean(); |
|
| 1435 | + echo ob_get_clean(); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | function wpinv_tools_callback($args) { |
@@ -1460,15 +1460,15 @@ discard block |
||
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | function wpinv_descriptive_text_callback( $args ) { |
| 1463 | - echo wp_kses_post( $args['desc'] ); |
|
| 1463 | + echo wp_kses_post( $args['desc'] ); |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | function wpinv_hook_callback( $args ) { |
| 1467 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1467 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | function wpinv_set_settings_cap() { |
| 1471 | - return 'manage_options'; |
|
| 1471 | + return 'manage_options'; |
|
| 1472 | 1472 | } |
| 1473 | 1473 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
| 1474 | 1474 | |
@@ -1,6 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) { |
| 6 | 8 | if ( empty( $user ) ) { |
@@ -218,262 +218,262 @@ discard block |
||
| 218 | 218 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
| 219 | 219 | |
| 220 | 220 | function wpinv_process_paypal_ipn() { |
| 221 | - // Check the request method is POST |
|
| 222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | - return; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Set initial post data to empty string |
|
| 227 | - $post_data = ''; |
|
| 228 | - |
|
| 229 | - // Fallback just in case post_max_size is lower than needed |
|
| 230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 231 | - $post_data = file_get_contents( 'php://input' ); |
|
| 232 | - } else { |
|
| 233 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 234 | - ini_set( 'post_max_size', '12M' ); |
|
| 235 | - } |
|
| 236 | - // Start the encoded data collection with notification command |
|
| 237 | - $encoded_data = 'cmd=_notify-validate'; |
|
| 238 | - |
|
| 239 | - // Get current arg separator |
|
| 240 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 241 | - |
|
| 242 | - // Verify there is a post_data |
|
| 243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | - // Append the data |
|
| 245 | - $encoded_data .= $arg_separator.$post_data; |
|
| 246 | - } else { |
|
| 247 | - // Check if POST is empty |
|
| 248 | - if ( empty( $_POST ) ) { |
|
| 249 | - // Nothing to do |
|
| 250 | - return; |
|
| 251 | - } else { |
|
| 252 | - // Loop through each POST |
|
| 253 | - foreach ( $_POST as $key => $value ) { |
|
| 254 | - // Encode the value and append the data |
|
| 255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // Convert collected post data to an array |
|
| 261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | - |
|
| 263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 265 | - $new_key = str_replace( '&', '&', $key ); |
|
| 266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 267 | - |
|
| 268 | - unset( $encoded_data_array[ $key ] ); |
|
| 269 | - $encoded_data_array[ $new_key ] = $value; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Get the PayPal redirect uri |
|
| 274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | - |
|
| 276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | - // Validate the IPN |
|
| 278 | - |
|
| 279 | - $remote_post_vars = array( |
|
| 280 | - 'method' => 'POST', |
|
| 281 | - 'timeout' => 45, |
|
| 282 | - 'redirection' => 5, |
|
| 283 | - 'httpversion' => '1.1', |
|
| 284 | - 'blocking' => true, |
|
| 285 | - 'headers' => array( |
|
| 286 | - 'host' => 'www.paypal.com', |
|
| 287 | - 'connection' => 'close', |
|
| 288 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
| 289 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 290 | - |
|
| 291 | - ), |
|
| 292 | - 'sslverify' => false, |
|
| 293 | - 'body' => $encoded_data_array |
|
| 294 | - ); |
|
| 295 | - |
|
| 296 | - // Get response |
|
| 297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | - |
|
| 299 | - if ( is_wp_error( $api_response ) ) { |
|
| 300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 301 | - return; // Something went wrong |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 306 | - return; // Response not okay |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Check if $post_data_array has been populated |
|
| 311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | - return; |
|
| 313 | - |
|
| 314 | - $defaults = array( |
|
| 315 | - 'txn_type' => '', |
|
| 316 | - 'payment_status' => '' |
|
| 317 | - ); |
|
| 318 | - |
|
| 319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | - |
|
| 321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 221 | + // Check the request method is POST |
|
| 222 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 223 | + return; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Set initial post data to empty string |
|
| 227 | + $post_data = ''; |
|
| 228 | + |
|
| 229 | + // Fallback just in case post_max_size is lower than needed |
|
| 230 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 231 | + $post_data = file_get_contents( 'php://input' ); |
|
| 232 | + } else { |
|
| 233 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 234 | + ini_set( 'post_max_size', '12M' ); |
|
| 235 | + } |
|
| 236 | + // Start the encoded data collection with notification command |
|
| 237 | + $encoded_data = 'cmd=_notify-validate'; |
|
| 238 | + |
|
| 239 | + // Get current arg separator |
|
| 240 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 241 | + |
|
| 242 | + // Verify there is a post_data |
|
| 243 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 244 | + // Append the data |
|
| 245 | + $encoded_data .= $arg_separator.$post_data; |
|
| 246 | + } else { |
|
| 247 | + // Check if POST is empty |
|
| 248 | + if ( empty( $_POST ) ) { |
|
| 249 | + // Nothing to do |
|
| 250 | + return; |
|
| 251 | + } else { |
|
| 252 | + // Loop through each POST |
|
| 253 | + foreach ( $_POST as $key => $value ) { |
|
| 254 | + // Encode the value and append the data |
|
| 255 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // Convert collected post data to an array |
|
| 261 | + parse_str( $encoded_data, $encoded_data_array ); |
|
| 262 | + |
|
| 263 | + foreach ( $encoded_data_array as $key => $value ) { |
|
| 264 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 265 | + $new_key = str_replace( '&', '&', $key ); |
|
| 266 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 267 | + |
|
| 268 | + unset( $encoded_data_array[ $key ] ); |
|
| 269 | + $encoded_data_array[ $new_key ] = $value; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Get the PayPal redirect uri |
|
| 274 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 275 | + |
|
| 276 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 277 | + // Validate the IPN |
|
| 278 | + |
|
| 279 | + $remote_post_vars = array( |
|
| 280 | + 'method' => 'POST', |
|
| 281 | + 'timeout' => 45, |
|
| 282 | + 'redirection' => 5, |
|
| 283 | + 'httpversion' => '1.1', |
|
| 284 | + 'blocking' => true, |
|
| 285 | + 'headers' => array( |
|
| 286 | + 'host' => 'www.paypal.com', |
|
| 287 | + 'connection' => 'close', |
|
| 288 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
| 289 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 290 | + |
|
| 291 | + ), |
|
| 292 | + 'sslverify' => false, |
|
| 293 | + 'body' => $encoded_data_array |
|
| 294 | + ); |
|
| 295 | + |
|
| 296 | + // Get response |
|
| 297 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 298 | + |
|
| 299 | + if ( is_wp_error( $api_response ) ) { |
|
| 300 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 301 | + return; // Something went wrong |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 305 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 306 | + return; // Response not okay |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Check if $post_data_array has been populated |
|
| 311 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 312 | + return; |
|
| 313 | + |
|
| 314 | + $defaults = array( |
|
| 315 | + 'txn_type' => '', |
|
| 316 | + 'payment_status' => '' |
|
| 317 | + ); |
|
| 318 | + |
|
| 319 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 320 | + |
|
| 321 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 322 | 322 | |
| 323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 324 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
| 325 | - |
|
| 326 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | - // Allow PayPal IPN types to be processed separately |
|
| 328 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | - } else { |
|
| 330 | - // Fallback to web accept just in case the txn_type isn't present |
|
| 331 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | - } |
|
| 333 | - exit; |
|
| 323 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 324 | + wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
| 325 | + |
|
| 326 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 327 | + // Allow PayPal IPN types to be processed separately |
|
| 328 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 329 | + } else { |
|
| 330 | + // Fallback to web accept just in case the txn_type isn't present |
|
| 331 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 332 | + } |
|
| 333 | + exit; |
|
| 334 | 334 | } |
| 335 | 335 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
| 336 | 336 | |
| 337 | 337 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
| 338 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 339 | - return; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if( empty( $invoice_id ) ) { |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Collect payment details |
|
| 347 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | - $paypal_amount = $data['mc_gross']; |
|
| 349 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 350 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 351 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 352 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 353 | - |
|
| 354 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | - return; // this isn't a PayPal standard IPN |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Verify payment recipient |
|
| 359 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 360 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 361 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 362 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Verify payment currency |
|
| 367 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 368 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 369 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 370 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 371 | - return; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 376 | - // No email associated with purchase, so store from PayPal |
|
| 377 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | - |
|
| 379 | - // Setup and store the customer's details |
|
| 380 | - $user_info = array( |
|
| 381 | - 'user_id' => '-1', |
|
| 382 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 383 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 384 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 385 | - 'discount' => '', |
|
| 386 | - ); |
|
| 387 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 388 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 389 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 390 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 391 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 392 | - |
|
| 393 | - $payment_meta['user_info'] = $user_info; |
|
| 394 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | - // Process a refund |
|
| 399 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | - } else { |
|
| 401 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | - return; // Only paid payments once |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - // Retrieve the total purchase amount (before PayPal) |
|
| 406 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | - |
|
| 408 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | - // The prices don't match |
|
| 410 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 411 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 412 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 413 | - return; |
|
| 414 | - } |
|
| 415 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | - // Purchase keys don't match |
|
| 417 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 418 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 419 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 420 | - return; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 424 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 425 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 426 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 427 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 428 | - // Look for possible pending reasons, such as an echeck |
|
| 429 | - $note = ''; |
|
| 430 | - |
|
| 431 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | - case 'echeck' : |
|
| 433 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | - break; |
|
| 338 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if( empty( $invoice_id ) ) { |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Collect payment details |
|
| 347 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 348 | + $paypal_amount = $data['mc_gross']; |
|
| 349 | + $payment_status = strtolower( $data['payment_status'] ); |
|
| 350 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
| 351 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 352 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 353 | + |
|
| 354 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 355 | + return; // this isn't a PayPal standard IPN |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Verify payment recipient |
|
| 359 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 360 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 361 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 362 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Verify payment currency |
|
| 367 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 368 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 369 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 370 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 371 | + return; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 375 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 376 | + // No email associated with purchase, so store from PayPal |
|
| 377 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 378 | + |
|
| 379 | + // Setup and store the customer's details |
|
| 380 | + $user_info = array( |
|
| 381 | + 'user_id' => '-1', |
|
| 382 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 383 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 384 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 385 | + 'discount' => '', |
|
| 386 | + ); |
|
| 387 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 388 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 389 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 390 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 391 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 392 | + |
|
| 393 | + $payment_meta['user_info'] = $user_info; |
|
| 394 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 398 | + // Process a refund |
|
| 399 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 400 | + } else { |
|
| 401 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 402 | + return; // Only paid payments once |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // Retrieve the total purchase amount (before PayPal) |
|
| 406 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 407 | + |
|
| 408 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 409 | + // The prices don't match |
|
| 410 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 411 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 412 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 413 | + return; |
|
| 414 | + } |
|
| 415 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 416 | + // Purchase keys don't match |
|
| 417 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 418 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 419 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
| 420 | + return; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 424 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
| 425 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 426 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 427 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 428 | + // Look for possible pending reasons, such as an echeck |
|
| 429 | + $note = ''; |
|
| 430 | + |
|
| 431 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
| 432 | + case 'echeck' : |
|
| 433 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 434 | + break; |
|
| 435 | 435 | |
| 436 | 436 | case 'address' : |
| 437 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | - break; |
|
| 437 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 438 | + break; |
|
| 439 | 439 | |
| 440 | 440 | case 'intl' : |
| 441 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | - break; |
|
| 441 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 442 | + break; |
|
| 443 | 443 | |
| 444 | 444 | case 'multi-currency' : |
| 445 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | - break; |
|
| 445 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 446 | + break; |
|
| 447 | 447 | |
| 448 | 448 | case 'paymentreview' : |
| 449 | 449 | case 'regulatory_review' : |
| 450 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | - break; |
|
| 450 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 451 | + break; |
|
| 452 | 452 | |
| 453 | 453 | case 'unilateral' : |
| 454 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | - break; |
|
| 454 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 455 | + break; |
|
| 456 | 456 | |
| 457 | 457 | case 'upgrade' : |
| 458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | - break; |
|
| 458 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 459 | + break; |
|
| 460 | 460 | |
| 461 | 461 | case 'verify' : |
| 462 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | - break; |
|
| 464 | - |
|
| 465 | - case 'other' : |
|
| 466 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | - break; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - if ( ! empty( $note ) ) { |
|
| 471 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | - } |
|
| 476 | - } |
|
| 462 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 463 | + break; |
|
| 464 | + |
|
| 465 | + case 'other' : |
|
| 466 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 467 | + break; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + if ( ! empty( $note ) ) { |
|
| 471 | + wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
| 479 | 479 | |
@@ -661,34 +661,34 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
| 664 | - // Collect payment details |
|
| 664 | + // Collect payment details |
|
| 665 | 665 | |
| 666 | - if( empty( $invoice_id ) ) { |
|
| 667 | - return; |
|
| 668 | - } |
|
| 666 | + if( empty( $invoice_id ) ) { |
|
| 667 | + return; |
|
| 668 | + } |
|
| 669 | 669 | |
| 670 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 671 | - return; // Only refund payments once |
|
| 672 | - } |
|
| 670 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 671 | + return; // Only refund payments once |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 675 | - $refund_amount = $data['mc_gross'] * -1; |
|
| 674 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 675 | + $refund_amount = $data['mc_gross'] * -1; |
|
| 676 | 676 | |
| 677 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 677 | + do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
| 678 | 678 | |
| 679 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 680 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 679 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 680 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 681 | 681 | |
| 682 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 682 | + do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
| 683 | 683 | |
| 684 | - return; // This is a partial refund |
|
| 685 | - } |
|
| 684 | + return; // This is a partial refund |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 688 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 689 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 687 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
| 688 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
| 689 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 690 | 690 | |
| 691 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 691 | + do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |