@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,354 +21,354 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var int Number of items per page |
|
| 26 | - * @since 1.0.19 |
|
| 27 | - */ |
|
| 28 | - public $per_page = 10; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int Number of items |
|
| 32 | - * @since 1.0.19 |
|
| 33 | - */ |
|
| 34 | - public $total = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get things started |
|
| 38 | - * |
|
| 39 | - * @since 1.0.19 |
|
| 40 | - * @see WP_List_Table::__construct() |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - // Set parent defaults |
|
| 45 | - parent::__construct( array( |
|
| 46 | - 'singular' => 'id', |
|
| 47 | - 'plural' => 'ids', |
|
| 48 | - 'ajax' => false, |
|
| 49 | - ) ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Gets the name of the primary column. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.19 |
|
| 57 | - * @access protected |
|
| 58 | - * |
|
| 59 | - * @return string Name of the primary column. |
|
| 60 | - */ |
|
| 61 | - protected function get_primary_column_name() { |
|
| 62 | - return 'name'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * This function renders most of the columns in the list table. |
|
| 67 | - * |
|
| 68 | - * @since 1.0.19 |
|
| 69 | - * |
|
| 70 | - * @param WP_User $item |
|
| 71 | - * @param string $column_name The name of the column |
|
| 72 | - * |
|
| 73 | - * @return string Column Name |
|
| 74 | - */ |
|
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Displays the country column. |
|
| 82 | - * |
|
| 83 | - * @since 1.0.19 |
|
| 84 | - * |
|
| 85 | - * @param WP_User $user |
|
| 86 | - * |
|
| 87 | - * @return string Column Name |
|
| 88 | - */ |
|
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 93 | - } |
|
| 94 | - return sanitize_text_field( $country ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Displays the state column. |
|
| 99 | - * |
|
| 100 | - * @since 1.0.19 |
|
| 101 | - * |
|
| 102 | - * @param WP_User $user |
|
| 103 | - * |
|
| 104 | - * @return string Column Name |
|
| 105 | - */ |
|
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | - $state = $user->_wpinv_state; |
|
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return sanitize_text_field( $state ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Displays the signup column. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * |
|
| 121 | - * @param WP_User $user |
|
| 122 | - * |
|
| 123 | - * @return string Column Name |
|
| 124 | - */ |
|
| 125 | - public function column_signup( $user ) { |
|
| 126 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Displays the total spent column. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * |
|
| 134 | - * @param WP_User $user |
|
| 135 | - * |
|
| 136 | - * @return string Column Name |
|
| 137 | - */ |
|
| 138 | - public function column_total( $user ) { |
|
| 139 | - |
|
| 140 | - $args = array( |
|
| 141 | - 'data' => array( |
|
| 142 | - |
|
| 143 | - 'total' => array( |
|
| 144 | - 'type' => 'invoice_data', |
|
| 145 | - 'function' => 'SUM', |
|
| 146 | - 'name' => 'total_sales', |
|
| 147 | - ) |
|
| 148 | - |
|
| 149 | - ), |
|
| 150 | - 'where' => array( |
|
| 151 | - |
|
| 152 | - 'author' => array( |
|
| 153 | - 'type' => 'post_data', |
|
| 154 | - 'value' => absint( $user->ID ), |
|
| 155 | - 'key' => 'posts.post_author', |
|
| 156 | - 'operator' => '=', |
|
| 157 | - ), |
|
| 158 | - |
|
| 159 | - ), |
|
| 160 | - 'query_type' => 'get_var', |
|
| 161 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 165 | - |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Displays the total spent column. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * |
|
| 173 | - * @param WP_User $user |
|
| 174 | - * |
|
| 175 | - * @return string Column Name |
|
| 176 | - */ |
|
| 177 | - public function column_invoices( $user ) { |
|
| 178 | - |
|
| 179 | - $args = array( |
|
| 180 | - 'data' => array( |
|
| 181 | - |
|
| 182 | - 'ID' => array( |
|
| 183 | - 'type' => 'post_data', |
|
| 184 | - 'function' => 'COUNT', |
|
| 185 | - 'name' => 'count', |
|
| 186 | - 'distinct' => true, |
|
| 187 | - ), |
|
| 188 | - |
|
| 189 | - ), |
|
| 190 | - 'where' => array( |
|
| 191 | - |
|
| 192 | - 'author' => array( |
|
| 193 | - 'type' => 'post_data', |
|
| 194 | - 'value' => absint( $user->ID ), |
|
| 195 | - 'key' => 'posts.post_author', |
|
| 196 | - 'operator' => '=', |
|
| 197 | - ), |
|
| 198 | - |
|
| 199 | - ), |
|
| 200 | - 'query_type' => 'get_var', |
|
| 201 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 202 | - ); |
|
| 203 | - |
|
| 204 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 205 | - |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Generates content for a single row of the table |
|
| 210 | - * @since 1.0.19 |
|
| 211 | - * |
|
| 212 | - * @param int $item The user id. |
|
| 213 | - */ |
|
| 214 | - public function single_row( $item ) { |
|
| 215 | - $item = get_user_by( 'id', $item ); |
|
| 216 | - |
|
| 217 | - if ( empty( $item ) ) { |
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - echo '<tr>'; |
|
| 222 | - $this->single_row_columns( $item ); |
|
| 223 | - echo '</tr>'; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Displays the customers name |
|
| 228 | - * |
|
| 229 | - * @param WP_User $customer customer. |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - public function column_name( $customer ) { |
|
| 233 | - |
|
| 234 | - // Customer view URL. |
|
| 235 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 236 | - $row_actions = $this->row_actions( |
|
| 237 | - array( |
|
| 238 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - // Get user's address. |
|
| 243 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 244 | - |
|
| 245 | - // Customer email address. |
|
| 246 | - $email = sanitize_email( $customer->user_email ); |
|
| 247 | - |
|
| 248 | - // Customer's avatar. |
|
| 249 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 250 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 251 | - |
|
| 252 | - // Customer's name. |
|
| 253 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 254 | - |
|
| 255 | - if ( ! empty( $name ) ) { |
|
| 256 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 260 | - |
|
| 261 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 262 | - |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Retrieve the table columns |
|
| 267 | - * |
|
| 268 | - * @since 1.0.19 |
|
| 269 | - * @return array $columns Array of all the list table columns |
|
| 270 | - */ |
|
| 271 | - public function get_columns() { |
|
| 272 | - |
|
| 273 | - $columns = array( |
|
| 274 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 275 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 276 | - 'state' => __( 'State', 'invoicing' ), |
|
| 277 | - 'city' => __( 'City', 'invoicing' ), |
|
| 278 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 279 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 280 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 281 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 282 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 283 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 284 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 285 | - ); |
|
| 286 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 287 | - |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Retrieve the current page number |
|
| 292 | - * |
|
| 293 | - * @since 1.0.19 |
|
| 294 | - * @return int Current page number |
|
| 295 | - */ |
|
| 296 | - public function get_paged() { |
|
| 297 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Returns bulk actions. |
|
| 302 | - * |
|
| 303 | - * @since 1.0.19 |
|
| 304 | - * @return void |
|
| 305 | - */ |
|
| 306 | - public function bulk_actions( $which = '' ) { |
|
| 307 | - return array(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Prepares the display query |
|
| 312 | - */ |
|
| 313 | - public function prepare_query() { |
|
| 314 | - global $wpdb; |
|
| 315 | - |
|
| 316 | - $post_types = ''; |
|
| 317 | - |
|
| 318 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 319 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 323 | - |
|
| 324 | - // Maybe search. |
|
| 325 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 326 | - $users = get_users( |
|
| 327 | - array( |
|
| 328 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 329 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 330 | - 'fields' => 'ID', |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - $users = implode( ', ', $users ); |
|
| 335 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // Users with invoices. |
|
| 339 | - $customers = $wpdb->get_col( |
|
| 340 | - $wpdb->prepare( |
|
| 341 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 342 | - $this->get_paged() * 10 - 10, |
|
| 343 | - $this->per_page |
|
| 344 | - ) |
|
| 345 | - ); |
|
| 346 | - |
|
| 347 | - $this->items = $customers; |
|
| 348 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 349 | - |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Setup the final data for the table |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @return void |
|
| 357 | - */ |
|
| 358 | - public function prepare_items() { |
|
| 359 | - $columns = $this->get_columns(); |
|
| 360 | - $hidden = array(); // No hidden columns |
|
| 361 | - $sortable = $this->get_sortable_columns(); |
|
| 362 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 363 | - $this->prepare_query(); |
|
| 364 | - |
|
| 365 | - $this->set_pagination_args( |
|
| 366 | - array( |
|
| 367 | - 'total_items' => $this->total, |
|
| 368 | - 'per_page' => $this->per_page, |
|
| 369 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - } |
|
| 24 | + /** |
|
| 25 | + * @var int Number of items per page |
|
| 26 | + * @since 1.0.19 |
|
| 27 | + */ |
|
| 28 | + public $per_page = 10; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int Number of items |
|
| 32 | + * @since 1.0.19 |
|
| 33 | + */ |
|
| 34 | + public $total = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get things started |
|
| 38 | + * |
|
| 39 | + * @since 1.0.19 |
|
| 40 | + * @see WP_List_Table::__construct() |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + // Set parent defaults |
|
| 45 | + parent::__construct( array( |
|
| 46 | + 'singular' => 'id', |
|
| 47 | + 'plural' => 'ids', |
|
| 48 | + 'ajax' => false, |
|
| 49 | + ) ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Gets the name of the primary column. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.19 |
|
| 57 | + * @access protected |
|
| 58 | + * |
|
| 59 | + * @return string Name of the primary column. |
|
| 60 | + */ |
|
| 61 | + protected function get_primary_column_name() { |
|
| 62 | + return 'name'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * This function renders most of the columns in the list table. |
|
| 67 | + * |
|
| 68 | + * @since 1.0.19 |
|
| 69 | + * |
|
| 70 | + * @param WP_User $item |
|
| 71 | + * @param string $column_name The name of the column |
|
| 72 | + * |
|
| 73 | + * @return string Column Name |
|
| 74 | + */ |
|
| 75 | + public function column_default( $item, $column_name ) { |
|
| 76 | + $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Displays the country column. |
|
| 82 | + * |
|
| 83 | + * @since 1.0.19 |
|
| 84 | + * |
|
| 85 | + * @param WP_User $user |
|
| 86 | + * |
|
| 87 | + * @return string Column Name |
|
| 88 | + */ |
|
| 89 | + public function column_country( $user ) { |
|
| 90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | + if ( $country ) { |
|
| 92 | + $country = wpinv_country_name( $country ); |
|
| 93 | + } |
|
| 94 | + return sanitize_text_field( $country ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Displays the state column. |
|
| 99 | + * |
|
| 100 | + * @since 1.0.19 |
|
| 101 | + * |
|
| 102 | + * @param WP_User $user |
|
| 103 | + * |
|
| 104 | + * @return string Column Name |
|
| 105 | + */ |
|
| 106 | + public function column_state( $user ) { |
|
| 107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | + $state = $user->_wpinv_state; |
|
| 109 | + if ( $state ) { |
|
| 110 | + $state = wpinv_state_name( $state, $country ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return sanitize_text_field( $state ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Displays the signup column. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * |
|
| 121 | + * @param WP_User $user |
|
| 122 | + * |
|
| 123 | + * @return string Column Name |
|
| 124 | + */ |
|
| 125 | + public function column_signup( $user ) { |
|
| 126 | + return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Displays the total spent column. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * |
|
| 134 | + * @param WP_User $user |
|
| 135 | + * |
|
| 136 | + * @return string Column Name |
|
| 137 | + */ |
|
| 138 | + public function column_total( $user ) { |
|
| 139 | + |
|
| 140 | + $args = array( |
|
| 141 | + 'data' => array( |
|
| 142 | + |
|
| 143 | + 'total' => array( |
|
| 144 | + 'type' => 'invoice_data', |
|
| 145 | + 'function' => 'SUM', |
|
| 146 | + 'name' => 'total_sales', |
|
| 147 | + ) |
|
| 148 | + |
|
| 149 | + ), |
|
| 150 | + 'where' => array( |
|
| 151 | + |
|
| 152 | + 'author' => array( |
|
| 153 | + 'type' => 'post_data', |
|
| 154 | + 'value' => absint( $user->ID ), |
|
| 155 | + 'key' => 'posts.post_author', |
|
| 156 | + 'operator' => '=', |
|
| 157 | + ), |
|
| 158 | + |
|
| 159 | + ), |
|
| 160 | + 'query_type' => 'get_var', |
|
| 161 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 165 | + |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Displays the total spent column. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * |
|
| 173 | + * @param WP_User $user |
|
| 174 | + * |
|
| 175 | + * @return string Column Name |
|
| 176 | + */ |
|
| 177 | + public function column_invoices( $user ) { |
|
| 178 | + |
|
| 179 | + $args = array( |
|
| 180 | + 'data' => array( |
|
| 181 | + |
|
| 182 | + 'ID' => array( |
|
| 183 | + 'type' => 'post_data', |
|
| 184 | + 'function' => 'COUNT', |
|
| 185 | + 'name' => 'count', |
|
| 186 | + 'distinct' => true, |
|
| 187 | + ), |
|
| 188 | + |
|
| 189 | + ), |
|
| 190 | + 'where' => array( |
|
| 191 | + |
|
| 192 | + 'author' => array( |
|
| 193 | + 'type' => 'post_data', |
|
| 194 | + 'value' => absint( $user->ID ), |
|
| 195 | + 'key' => 'posts.post_author', |
|
| 196 | + 'operator' => '=', |
|
| 197 | + ), |
|
| 198 | + |
|
| 199 | + ), |
|
| 200 | + 'query_type' => 'get_var', |
|
| 201 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 202 | + ); |
|
| 203 | + |
|
| 204 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 205 | + |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Generates content for a single row of the table |
|
| 210 | + * @since 1.0.19 |
|
| 211 | + * |
|
| 212 | + * @param int $item The user id. |
|
| 213 | + */ |
|
| 214 | + public function single_row( $item ) { |
|
| 215 | + $item = get_user_by( 'id', $item ); |
|
| 216 | + |
|
| 217 | + if ( empty( $item ) ) { |
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + echo '<tr>'; |
|
| 222 | + $this->single_row_columns( $item ); |
|
| 223 | + echo '</tr>'; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Displays the customers name |
|
| 228 | + * |
|
| 229 | + * @param WP_User $customer customer. |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + public function column_name( $customer ) { |
|
| 233 | + |
|
| 234 | + // Customer view URL. |
|
| 235 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 236 | + $row_actions = $this->row_actions( |
|
| 237 | + array( |
|
| 238 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + // Get user's address. |
|
| 243 | + $address = wpinv_get_user_address( $customer->ID ); |
|
| 244 | + |
|
| 245 | + // Customer email address. |
|
| 246 | + $email = sanitize_email( $customer->user_email ); |
|
| 247 | + |
|
| 248 | + // Customer's avatar. |
|
| 249 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 250 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 251 | + |
|
| 252 | + // Customer's name. |
|
| 253 | + $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 254 | + |
|
| 255 | + if ( ! empty( $name ) ) { |
|
| 256 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 260 | + |
|
| 261 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 262 | + |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Retrieve the table columns |
|
| 267 | + * |
|
| 268 | + * @since 1.0.19 |
|
| 269 | + * @return array $columns Array of all the list table columns |
|
| 270 | + */ |
|
| 271 | + public function get_columns() { |
|
| 272 | + |
|
| 273 | + $columns = array( |
|
| 274 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 275 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 276 | + 'state' => __( 'State', 'invoicing' ), |
|
| 277 | + 'city' => __( 'City', 'invoicing' ), |
|
| 278 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 279 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 280 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 281 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 282 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 283 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 284 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 285 | + ); |
|
| 286 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 287 | + |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Retrieve the current page number |
|
| 292 | + * |
|
| 293 | + * @since 1.0.19 |
|
| 294 | + * @return int Current page number |
|
| 295 | + */ |
|
| 296 | + public function get_paged() { |
|
| 297 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Returns bulk actions. |
|
| 302 | + * |
|
| 303 | + * @since 1.0.19 |
|
| 304 | + * @return void |
|
| 305 | + */ |
|
| 306 | + public function bulk_actions( $which = '' ) { |
|
| 307 | + return array(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Prepares the display query |
|
| 312 | + */ |
|
| 313 | + public function prepare_query() { |
|
| 314 | + global $wpdb; |
|
| 315 | + |
|
| 316 | + $post_types = ''; |
|
| 317 | + |
|
| 318 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 319 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 323 | + |
|
| 324 | + // Maybe search. |
|
| 325 | + if ( ! empty( $_POST['s'] ) ) { |
|
| 326 | + $users = get_users( |
|
| 327 | + array( |
|
| 328 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 329 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 330 | + 'fields' => 'ID', |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + $users = implode( ', ', $users ); |
|
| 335 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // Users with invoices. |
|
| 339 | + $customers = $wpdb->get_col( |
|
| 340 | + $wpdb->prepare( |
|
| 341 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 342 | + $this->get_paged() * 10 - 10, |
|
| 343 | + $this->per_page |
|
| 344 | + ) |
|
| 345 | + ); |
|
| 346 | + |
|
| 347 | + $this->items = $customers; |
|
| 348 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 349 | + |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Setup the final data for the table |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @return void |
|
| 357 | + */ |
|
| 358 | + public function prepare_items() { |
|
| 359 | + $columns = $this->get_columns(); |
|
| 360 | + $hidden = array(); // No hidden columns |
|
| 361 | + $sortable = $this->get_sortable_columns(); |
|
| 362 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 363 | + $this->prepare_query(); |
|
| 364 | + |
|
| 365 | + $this->set_pagination_args( |
|
| 366 | + array( |
|
| 367 | + 'total_items' => $this->total, |
|
| 368 | + 'per_page' => $this->per_page, |
|
| 369 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | 374 | } |
@@ -5,10 +5,10 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | // Exit if accessed directly |
| 8 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 8 | +if (!defined('ABSPATH')) exit; |
|
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 11 | +if (!class_exists('WP_List_Table')) { |
|
| 12 | 12 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 13 | 13 | } |
| 14 | 14 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | public function __construct() { |
| 43 | 43 | |
| 44 | 44 | // Set parent defaults |
| 45 | - parent::__construct( array( |
|
| 45 | + parent::__construct(array( |
|
| 46 | 46 | 'singular' => 'id', |
| 47 | 47 | 'plural' => 'ids', |
| 48 | 48 | 'ajax' => false, |
| 49 | - ) ); |
|
| 49 | + )); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return string Column Name |
| 74 | 74 | */ |
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 75 | + public function column_default($item, $column_name) { |
|
| 76 | + $value = sanitize_text_field(get_user_meta($item->ID, '_wpinv_' . $column_name, true)); |
|
| 77 | + return apply_filters('wpinv_customers_table_column' . $column_name, $value, $item); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return string Column Name |
| 88 | 88 | */ |
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 89 | + public function column_country($user) { |
|
| 90 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 91 | + if ($country) { |
|
| 92 | + $country = wpinv_country_name($country); |
|
| 93 | 93 | } |
| 94 | - return sanitize_text_field( $country ); |
|
| 94 | + return sanitize_text_field($country); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return string Column Name |
| 105 | 105 | */ |
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 106 | + public function column_state($user) { |
|
| 107 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
| 108 | 108 | $state = $user->_wpinv_state; |
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 109 | + if ($state) { |
|
| 110 | + $state = wpinv_state_name($state, $country); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - return sanitize_text_field( $state ); |
|
| 113 | + return sanitize_text_field($state); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return string Column Name |
| 124 | 124 | */ |
| 125 | - public function column_signup( $user ) { |
|
| 126 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 125 | + public function column_signup($user) { |
|
| 126 | + return getpaid_format_date_value($user->user_registered); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @return string Column Name |
| 137 | 137 | */ |
| 138 | - public function column_total( $user ) { |
|
| 138 | + public function column_total($user) { |
|
| 139 | 139 | |
| 140 | 140 | $args = array( |
| 141 | 141 | 'data' => array( |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | 'author' => array( |
| 153 | 153 | 'type' => 'post_data', |
| 154 | - 'value' => absint( $user->ID ), |
|
| 154 | + 'value' => absint($user->ID), |
|
| 155 | 155 | 'key' => 'posts.post_author', |
| 156 | 156 | 'operator' => '=', |
| 157 | 157 | ), |
| 158 | 158 | |
| 159 | 159 | ), |
| 160 | 160 | 'query_type' => 'get_var', |
| 161 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 161 | + 'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'), |
|
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 164 | + return wpinv_price((float) GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 165 | 165 | |
| 166 | 166 | } |
| 167 | 167 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return string Column Name |
| 176 | 176 | */ |
| 177 | - public function column_invoices( $user ) { |
|
| 177 | + public function column_invoices($user) { |
|
| 178 | 178 | |
| 179 | 179 | $args = array( |
| 180 | 180 | 'data' => array( |
@@ -191,17 +191,17 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | 'author' => array( |
| 193 | 193 | 'type' => 'post_data', |
| 194 | - 'value' => absint( $user->ID ), |
|
| 194 | + 'value' => absint($user->ID), |
|
| 195 | 195 | 'key' => 'posts.post_author', |
| 196 | 196 | 'operator' => '=', |
| 197 | 197 | ), |
| 198 | 198 | |
| 199 | 199 | ), |
| 200 | 200 | 'query_type' => 'get_var', |
| 201 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 201 | + 'invoice_status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 202 | 202 | ); |
| 203 | 203 | |
| 204 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 204 | + return absint(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
| 205 | 205 | |
| 206 | 206 | } |
| 207 | 207 | |
@@ -211,15 +211,15 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @param int $item The user id. |
| 213 | 213 | */ |
| 214 | - public function single_row( $item ) { |
|
| 215 | - $item = get_user_by( 'id', $item ); |
|
| 214 | + public function single_row($item) { |
|
| 215 | + $item = get_user_by('id', $item); |
|
| 216 | 216 | |
| 217 | - if ( empty( $item ) ) { |
|
| 217 | + if (empty($item)) { |
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | echo '<tr>'; |
| 222 | - $this->single_row_columns( $item ); |
|
| 222 | + $this->single_row_columns($item); |
|
| 223 | 223 | echo '</tr>'; |
| 224 | 224 | } |
| 225 | 225 | |
@@ -229,30 +229,30 @@ discard block |
||
| 229 | 229 | * @param WP_User $customer customer. |
| 230 | 230 | * @return string |
| 231 | 231 | */ |
| 232 | - public function column_name( $customer ) { |
|
| 232 | + public function column_name($customer) { |
|
| 233 | 233 | |
| 234 | 234 | // Customer view URL. |
| 235 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 235 | + $view_url = esc_url(add_query_arg('user_id', $customer->ID, admin_url('user-edit.php'))); |
|
| 236 | 236 | $row_actions = $this->row_actions( |
| 237 | 237 | array( |
| 238 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 238 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>', |
|
| 239 | 239 | ) |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | 242 | // Get user's address. |
| 243 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 243 | + $address = wpinv_get_user_address($customer->ID); |
|
| 244 | 244 | |
| 245 | 245 | // Customer email address. |
| 246 | - $email = sanitize_email( $customer->user_email ); |
|
| 246 | + $email = sanitize_email($customer->user_email); |
|
| 247 | 247 | |
| 248 | 248 | // Customer's avatar. |
| 249 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 249 | + $avatar = esc_url(get_avatar_url($email)); |
|
| 250 | 250 | $avatar = "<img src='$avatar' height='32' width='32'/>"; |
| 251 | 251 | |
| 252 | 252 | // Customer's name. |
| 253 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 253 | + $name = sanitize_text_field("{$address['first_name']} {$address['last_name']}"); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $name ) ) { |
|
| 255 | + if (!empty($name)) { |
|
| 256 | 256 | $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -271,19 +271,19 @@ discard block |
||
| 271 | 271 | public function get_columns() { |
| 272 | 272 | |
| 273 | 273 | $columns = array( |
| 274 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 275 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 276 | - 'state' => __( 'State', 'invoicing' ), |
|
| 277 | - 'city' => __( 'City', 'invoicing' ), |
|
| 278 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 279 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 280 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 281 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 282 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 283 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 284 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 274 | + 'name' => __('Name', 'invoicing'), |
|
| 275 | + 'country' => __('Country', 'invoicing'), |
|
| 276 | + 'state' => __('State', 'invoicing'), |
|
| 277 | + 'city' => __('City', 'invoicing'), |
|
| 278 | + 'zip' => __('ZIP', 'invoicing'), |
|
| 279 | + 'address' => __('Address', 'invoicing'), |
|
| 280 | + 'phone' => __('Phone', 'invoicing'), |
|
| 281 | + 'company' => __('Company', 'invoicing'), |
|
| 282 | + 'invoices' => __('Invoices', 'invoicing'), |
|
| 283 | + 'total' => __('Total Spend', 'invoicing'), |
|
| 284 | + 'signup' => __('Date created', 'invoicing'), |
|
| 285 | 285 | ); |
| 286 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 286 | + return apply_filters('wpinv_customers_table_columns', $columns); |
|
| 287 | 287 | |
| 288 | 288 | } |
| 289 | 289 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * @return int Current page number |
| 295 | 295 | */ |
| 296 | 296 | public function get_paged() { |
| 297 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 297 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @since 1.0.19 |
| 304 | 304 | * @return void |
| 305 | 305 | */ |
| 306 | - public function bulk_actions( $which = '' ) { |
|
| 306 | + public function bulk_actions($which = '') { |
|
| 307 | 307 | return array(); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -315,23 +315,23 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $post_types = ''; |
| 317 | 317 | |
| 318 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 319 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 318 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
| 319 | + $post_types .= $wpdb->prepare("post_type=%s OR ", $post_type); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 322 | + $post_types = rtrim($post_types, ' OR'); |
|
| 323 | 323 | |
| 324 | 324 | // Maybe search. |
| 325 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 325 | + if (!empty($_POST['s'])) { |
|
| 326 | 326 | $users = get_users( |
| 327 | 327 | array( |
| 328 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
| 329 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 328 | + 'search' => '*' . sanitize_text_field(urldecode($_POST['s'])) . '*', |
|
| 329 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
| 330 | 330 | 'fields' => 'ID', |
| 331 | 331 | ) |
| 332 | 332 | ); |
| 333 | 333 | |
| 334 | - $users = implode( ', ', $users ); |
|
| 334 | + $users = implode(', ', $users); |
|
| 335 | 335 | $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | ); |
| 346 | 346 | |
| 347 | 347 | $this->items = $customers; |
| 348 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 348 | + $this->total = (int) $wpdb->get_var("SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types"); |
|
| 349 | 349 | |
| 350 | 350 | } |
| 351 | 351 | |
@@ -359,14 +359,14 @@ discard block |
||
| 359 | 359 | $columns = $this->get_columns(); |
| 360 | 360 | $hidden = array(); // No hidden columns |
| 361 | 361 | $sortable = $this->get_sortable_columns(); |
| 362 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 362 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 363 | 363 | $this->prepare_query(); |
| 364 | 364 | |
| 365 | 365 | $this->set_pagination_args( |
| 366 | 366 | array( |
| 367 | 367 | 'total_items' => $this->total, |
| 368 | 368 | 'per_page' => $this->per_page, |
| 369 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 369 | + 'total_pages' => ceil($this->total / $this->per_page) |
|
| 370 | 370 | ) |
| 371 | 371 | ); |
| 372 | 372 | |
@@ -14,77 +14,77 @@ discard block |
||
| 14 | 14 | class GetPaid_Admin { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Local path to this plugins admin directory |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $admin_path; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Web path to this plugins admin directory |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - public $admin_url; |
|
| 17 | + * Local path to this plugins admin directory |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $admin_path; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Web path to this plugins admin directory |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + public $admin_url; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 30 | + /** |
|
| 31 | + * Reports components. |
|
| 32 | + * |
|
| 33 | + * @var GetPaid_Reports |
|
| 34 | + */ |
|
| 35 | 35 | public $reports; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Class constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct(){ |
|
| 38 | + * Class constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct(){ |
|
| 41 | 41 | |
| 42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | - $this->reports = new GetPaid_Reports(); |
|
| 43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | + $this->reports = new GetPaid_Reports(); |
|
| 45 | 45 | |
| 46 | 46 | if ( is_admin() ) { |
| 47 | - $this->init_admin_hooks(); |
|
| 47 | + $this->init_admin_hooks(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Init action and filter hooks |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - private function init_admin_hooks() { |
|
| 53 | + * Init action and filter hooks |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + private function init_admin_hooks() { |
|
| 57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
| 58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
| 61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 66 | 66 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 71 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 72 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 71 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 72 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Register admin scripts |
|
| 78 | - * |
|
| 79 | - */ |
|
| 80 | - public function enqeue_scripts() { |
|
| 77 | + * Register admin scripts |
|
| 78 | + * |
|
| 79 | + */ |
|
| 80 | + public function enqeue_scripts() { |
|
| 81 | 81 | global $current_screen, $pagenow; |
| 82 | 82 | |
| 83 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 84 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 83 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 84 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 85 | 85 | |
| 86 | 86 | if ( ! empty( $current_screen->post_type ) ) { |
| 87 | - $page = $current_screen->post_type; |
|
| 87 | + $page = $current_screen->post_type; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // General styles. |
@@ -105,54 +105,54 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Payment form scripts. |
| 108 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 108 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 109 | 109 | $this->load_payment_form_scripts(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 113 | - wp_enqueue_script( 'postbox' ); |
|
| 114 | - } |
|
| 112 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 113 | + wp_enqueue_script( 'postbox' ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
| 119 | - * Returns admin js translations. |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - protected function get_admin_i18() { |
|
| 119 | + * Returns admin js translations. |
|
| 120 | + * |
|
| 121 | + */ |
|
| 122 | + protected function get_admin_i18() { |
|
| 123 | 123 | global $post; |
| 124 | 124 | |
| 125 | - $date_range = array( |
|
| 126 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 127 | - ); |
|
| 125 | + $date_range = array( |
|
| 126 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 127 | + ); |
|
| 128 | 128 | |
| 129 | - if ( $date_range['period'] == 'custom' ) { |
|
| 129 | + if ( $date_range['period'] == 'custom' ) { |
|
| 130 | 130 | |
| 131 | - if ( isset( $_GET['from'] ) ) { |
|
| 132 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 133 | - } |
|
| 131 | + if ( isset( $_GET['from'] ) ) { |
|
| 132 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if ( isset( $_GET['to'] ) ) { |
|
| 136 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 137 | - } |
|
| 135 | + if ( isset( $_GET['to'] ) ) { |
|
| 136 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | $i18n = array( |
| 142 | 142 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 143 | 143 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 144 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 145 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 146 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 147 | - 'date_range' => $date_range, |
|
| 144 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 145 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 146 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 147 | + 'date_range' => $date_range, |
|
| 148 | 148 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 149 | 149 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 150 | 150 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 151 | 151 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 152 | 152 | 'tax' => wpinv_tax_amount(), |
| 153 | 153 | 'discount' => 0, |
| 154 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 155 | - 'currency' => wpinv_get_currency(), |
|
| 154 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 155 | + 'currency' => wpinv_get_currency(), |
|
| 156 | 156 | 'currency_pos' => wpinv_currency_position(), |
| 157 | 157 | 'thousand_sep' => wpinv_thousands_separator(), |
| 158 | 158 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -172,117 +172,117 @@ discard block |
||
| 172 | 172 | 'item_description' => __( 'Item Description', 'invoicing' ), |
| 173 | 173 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
| 174 | 174 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
| 175 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 176 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 177 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 175 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
| 176 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 177 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 180 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 181 | 181 | |
| 182 | - $invoice = new WPInv_Invoice( $post ); |
|
| 183 | - $i18n['save_invoice'] = sprintf( |
|
| 184 | - __( 'Save %s', 'invoicing' ), |
|
| 185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 186 | - ); |
|
| 182 | + $invoice = new WPInv_Invoice( $post ); |
|
| 183 | + $i18n['save_invoice'] = sprintf( |
|
| 184 | + __( 'Save %s', 'invoicing' ), |
|
| 185 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 186 | + ); |
|
| 187 | 187 | |
| 188 | - $i18n['invoice_description'] = sprintf( |
|
| 189 | - __( '%s Description', 'invoicing' ), |
|
| 190 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 191 | - ); |
|
| 188 | + $i18n['invoice_description'] = sprintf( |
|
| 189 | + __( '%s Description', 'invoicing' ), |
|
| 190 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 191 | + ); |
|
| 192 | 192 | |
| 193 | - } |
|
| 194 | - return $i18n; |
|
| 195 | - } |
|
| 193 | + } |
|
| 194 | + return $i18n; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Change the admin footer text on GetPaid admin pages. |
|
| 199 | - * |
|
| 200 | - * @since 2.0.0 |
|
| 201 | - * @param string $footer_text |
|
| 202 | - * @return string |
|
| 203 | - */ |
|
| 204 | - public function admin_footer_text( $footer_text ) { |
|
| 205 | - global $current_screen; |
|
| 197 | + /** |
|
| 198 | + * Change the admin footer text on GetPaid admin pages. |
|
| 199 | + * |
|
| 200 | + * @since 2.0.0 |
|
| 201 | + * @param string $footer_text |
|
| 202 | + * @return string |
|
| 203 | + */ |
|
| 204 | + public function admin_footer_text( $footer_text ) { |
|
| 205 | + global $current_screen; |
|
| 206 | 206 | |
| 207 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 207 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 208 | 208 | |
| 209 | 209 | if ( ! empty( $current_screen->post_type ) ) { |
| 210 | - $page = $current_screen->post_type; |
|
| 210 | + $page = $current_screen->post_type; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // General styles. |
| 214 | 214 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 215 | 215 | |
| 216 | - // Change the footer text |
|
| 217 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 218 | - |
|
| 219 | - $rating_url = esc_url( |
|
| 220 | - wp_nonce_url( |
|
| 221 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 222 | - 'getpaid-nonce', |
|
| 223 | - 'getpaid-nonce' |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 226 | - |
|
| 227 | - $footer_text = sprintf( |
|
| 228 | - /* translators: %s: five stars */ |
|
| 229 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 230 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 231 | - ); |
|
| 232 | - |
|
| 233 | - } else { |
|
| 234 | - |
|
| 235 | - $footer_text = sprintf( |
|
| 236 | - /* translators: %s: GetPaid */ |
|
| 237 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 238 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $footer_text; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Redirects to wp.org to rate the plugin. |
|
| 250 | - * |
|
| 251 | - * @since 2.0.0 |
|
| 252 | - */ |
|
| 253 | - public function redirect_to_wordpress_rating_page() { |
|
| 254 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 255 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 256 | - exit; |
|
| 257 | - } |
|
| 216 | + // Change the footer text |
|
| 217 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 218 | + |
|
| 219 | + $rating_url = esc_url( |
|
| 220 | + wp_nonce_url( |
|
| 221 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 222 | + 'getpaid-nonce', |
|
| 223 | + 'getpaid-nonce' |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | + |
|
| 227 | + $footer_text = sprintf( |
|
| 228 | + /* translators: %s: five stars */ |
|
| 229 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 230 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 231 | + ); |
|
| 232 | + |
|
| 233 | + } else { |
|
| 234 | + |
|
| 235 | + $footer_text = sprintf( |
|
| 236 | + /* translators: %s: GetPaid */ |
|
| 237 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 238 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $footer_text; |
|
| 246 | + } |
|
| 258 | 247 | |
| 259 | 248 | /** |
| 260 | - * Loads payment form js. |
|
| 261 | - * |
|
| 262 | - */ |
|
| 263 | - protected function load_payment_form_scripts() { |
|
| 249 | + * Redirects to wp.org to rate the plugin. |
|
| 250 | + * |
|
| 251 | + * @since 2.0.0 |
|
| 252 | + */ |
|
| 253 | + public function redirect_to_wordpress_rating_page() { |
|
| 254 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 255 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 256 | + exit; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Loads payment form js. |
|
| 261 | + * |
|
| 262 | + */ |
|
| 263 | + protected function load_payment_form_scripts() { |
|
| 264 | 264 | global $post; |
| 265 | 265 | |
| 266 | 266 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
| 267 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 268 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 267 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 268 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 269 | 269 | |
| 270 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 271 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 270 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 271 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 272 | 272 | |
| 273 | - wp_localize_script( |
|
| 273 | + wp_localize_script( |
|
| 274 | 274 | 'wpinv-admin-payment-form-script', |
| 275 | 275 | 'wpinvPaymentFormAdmin', |
| 276 | 276 | array( |
| 277 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 278 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 279 | - 'currency' => wpinv_currency_symbol(), |
|
| 280 | - 'position' => wpinv_currency_position(), |
|
| 281 | - 'decimals' => (int) wpinv_decimals(), |
|
| 282 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 283 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 284 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 285 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 277 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 278 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 279 | + 'currency' => wpinv_currency_symbol(), |
|
| 280 | + 'position' => wpinv_currency_position(), |
|
| 281 | + 'decimals' => (int) wpinv_decimals(), |
|
| 282 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 283 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 284 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 285 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 286 | 286 | ) |
| 287 | 287 | ); |
| 288 | 288 | |
@@ -291,20 +291,20 @@ discard block |
||
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | - * Add our classes to admin pages. |
|
| 294 | + * Add our classes to admin pages. |
|
| 295 | 295 | * |
| 296 | 296 | * @param string $classes |
| 297 | 297 | * @return string |
| 298 | - * |
|
| 299 | - */ |
|
| 298 | + * |
|
| 299 | + */ |
|
| 300 | 300 | public function admin_body_class( $classes ) { |
| 301 | - global $pagenow, $post, $current_screen; |
|
| 301 | + global $pagenow, $post, $current_screen; |
|
| 302 | 302 | |
| 303 | 303 | |
| 304 | 304 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 305 | 305 | |
| 306 | 306 | if ( ! empty( $current_screen->post_type ) ) { |
| 307 | - $page = $current_screen->post_type; |
|
| 307 | + $page = $current_screen->post_type; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -313,59 +313,59 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 315 | 315 | $classes .= ' wpinv-cpt wpinv'; |
| 316 | - } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 318 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 319 | 319 | $classes .= ' getpaid-is-invoice-cpt'; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - return $classes; |
|
| 322 | + return $classes; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
| 326 | - * Maybe show the AyeCode Connect Notice. |
|
| 327 | - */ |
|
| 328 | - public function init_ayecode_connect_helper(){ |
|
| 326 | + * Maybe show the AyeCode Connect Notice. |
|
| 327 | + */ |
|
| 328 | + public function init_ayecode_connect_helper(){ |
|
| 329 | 329 | |
| 330 | 330 | new AyeCode_Connect_Helper( |
| 331 | 331 | array( |
| 332 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 333 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 334 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 335 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 336 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 337 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 338 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 332 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 333 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 334 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 335 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 336 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 337 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 338 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 339 | 339 | ), |
| 340 | 340 | array( 'wpi-addons' ) |
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Redirect users to settings on activation. |
|
| 347 | - * |
|
| 348 | - * @return void |
|
| 349 | - */ |
|
| 350 | - public function activation_redirect() { |
|
| 345 | + /** |
|
| 346 | + * Redirect users to settings on activation. |
|
| 347 | + * |
|
| 348 | + * @return void |
|
| 349 | + */ |
|
| 350 | + public function activation_redirect() { |
|
| 351 | 351 | |
| 352 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 352 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 353 | 353 | |
| 354 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 355 | - return; |
|
| 356 | - } |
|
| 354 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 355 | + return; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - // Bail if activating from network, or bulk |
|
| 359 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 360 | - return; |
|
| 361 | - } |
|
| 358 | + // Bail if activating from network, or bulk |
|
| 359 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 360 | + return; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 363 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 364 | 364 | |
| 365 | 365 | wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
| 366 | 366 | exit; |
| 367 | 367 | |
| 368 | - } |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | 371 | * Fires an admin action after verifying that a user can fire them. |
@@ -379,304 +379,304 @@ discard block |
||
| 379 | 379 | |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - /** |
|
| 382 | + /** |
|
| 383 | 383 | * Sends a payment reminder to a customer. |
| 384 | - * |
|
| 385 | - * @param array $args |
|
| 384 | + * |
|
| 385 | + * @param array $args |
|
| 386 | 386 | */ |
| 387 | 387 | public function send_customer_invoice( $args ) { |
| 388 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 388 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 389 | 389 | |
| 390 | - if ( $sent ) { |
|
| 391 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 392 | - } else { |
|
| 393 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 394 | - } |
|
| 390 | + if ( $sent ) { |
|
| 391 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 392 | + } else { |
|
| 393 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 397 | - exit; |
|
| 398 | - } |
|
| 396 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 397 | + exit; |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - /** |
|
| 400 | + /** |
|
| 401 | 401 | * Sends a payment reminder to a customer. |
| 402 | - * |
|
| 403 | - * @param array $args |
|
| 402 | + * |
|
| 403 | + * @param array $args |
|
| 404 | 404 | */ |
| 405 | 405 | public function send_customer_payment_reminder( $args ) { |
| 406 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 406 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 407 | 407 | |
| 408 | - if ( $sent ) { |
|
| 409 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 410 | - } else { |
|
| 411 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 412 | - } |
|
| 408 | + if ( $sent ) { |
|
| 409 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 410 | + } else { |
|
| 411 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 415 | - exit; |
|
| 416 | - } |
|
| 414 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 415 | + exit; |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - /** |
|
| 418 | + /** |
|
| 419 | 419 | * Resets tax rates. |
| 420 | - * |
|
| 420 | + * |
|
| 421 | 421 | */ |
| 422 | 422 | public function admin_reset_tax_rates() { |
| 423 | 423 | |
| 424 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 425 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 426 | - exit; |
|
| 424 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 425 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 426 | + exit; |
|
| 427 | 427 | |
| 428 | - } |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | - /** |
|
| 430 | + /** |
|
| 431 | 431 | * Resets admin pages. |
| 432 | - * |
|
| 432 | + * |
|
| 433 | 433 | */ |
| 434 | 434 | public function admin_create_missing_pages() { |
| 435 | - $installer = new GetPaid_Installer(); |
|
| 436 | - $installer->create_pages(); |
|
| 437 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 438 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 439 | - exit; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 435 | + $installer = new GetPaid_Installer(); |
|
| 436 | + $installer->create_pages(); |
|
| 437 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 438 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 439 | + exit; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | 443 | * Creates an missing admin tables. |
| 444 | - * |
|
| 444 | + * |
|
| 445 | 445 | */ |
| 446 | 446 | public function admin_create_missing_tables() { |
| 447 | - global $wpdb; |
|
| 448 | - $installer = new GetPaid_Installer(); |
|
| 447 | + global $wpdb; |
|
| 448 | + $installer = new GetPaid_Installer(); |
|
| 449 | 449 | |
| 450 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 451 | - $installer->create_subscriptions_table(); |
|
| 450 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 451 | + $installer->create_subscriptions_table(); |
|
| 452 | 452 | |
| 453 | - if ( $wpdb->last_error !== '' ) { |
|
| 454 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 455 | - } |
|
| 456 | - } |
|
| 453 | + if ( $wpdb->last_error !== '' ) { |
|
| 454 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 459 | - $installer->create_invoices_table(); |
|
| 458 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 459 | + $installer->create_invoices_table(); |
|
| 460 | 460 | |
| 461 | - if ( $wpdb->last_error !== '' ) { |
|
| 462 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 463 | - } |
|
| 464 | - } |
|
| 461 | + if ( $wpdb->last_error !== '' ) { |
|
| 462 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 467 | - $installer->create_invoice_items_table(); |
|
| 466 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 467 | + $installer->create_invoice_items_table(); |
|
| 468 | 468 | |
| 469 | - if ( $wpdb->last_error !== '' ) { |
|
| 470 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 471 | - } |
|
| 472 | - } |
|
| 469 | + if ( $wpdb->last_error !== '' ) { |
|
| 470 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | - if ( ! $this->has_notices() ) { |
|
| 475 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 476 | - } |
|
| 474 | + if ( ! $this->has_notices() ) { |
|
| 475 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 479 | - exit; |
|
| 480 | - } |
|
| 478 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 479 | + exit; |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - /** |
|
| 482 | + /** |
|
| 483 | 483 | * Migrates old invoices to the new database tables. |
| 484 | - * |
|
| 484 | + * |
|
| 485 | 485 | */ |
| 486 | 486 | public function admin_migrate_old_invoices() { |
| 487 | 487 | |
| 488 | - // Migrate the invoices. |
|
| 489 | - $installer = new GetPaid_Installer(); |
|
| 490 | - $installer->migrate_old_invoices(); |
|
| 488 | + // Migrate the invoices. |
|
| 489 | + $installer = new GetPaid_Installer(); |
|
| 490 | + $installer->migrate_old_invoices(); |
|
| 491 | 491 | |
| 492 | - // Show an admin message. |
|
| 493 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 492 | + // Show an admin message. |
|
| 493 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 494 | 494 | |
| 495 | - // Redirect the admin. |
|
| 496 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 497 | - exit; |
|
| 495 | + // Redirect the admin. |
|
| 496 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 497 | + exit; |
|
| 498 | 498 | |
| 499 | - } |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - /** |
|
| 501 | + /** |
|
| 502 | 502 | * Recalculates discounts. |
| 503 | - * |
|
| 503 | + * |
|
| 504 | 504 | */ |
| 505 | 505 | public function admin_recalculate_discounts() { |
| 506 | - global $wpdb; |
|
| 506 | + global $wpdb; |
|
| 507 | 507 | |
| 508 | - // Fetch all invoices that have discount codes. |
|
| 509 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 510 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 508 | + // Fetch all invoices that have discount codes. |
|
| 509 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 510 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 511 | 511 | |
| 512 | - foreach ( $invoices as $invoice ) { |
|
| 512 | + foreach ( $invoices as $invoice ) { |
|
| 513 | 513 | |
| 514 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 514 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 515 | 515 | |
| 516 | - if ( ! $invoice->exists() ) { |
|
| 517 | - continue; |
|
| 518 | - } |
|
| 516 | + if ( ! $invoice->exists() ) { |
|
| 517 | + continue; |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | - // Abort if the discount does not exist or does not apply here. |
|
| 521 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 522 | - if ( ! $discount->exists() ) { |
|
| 523 | - continue; |
|
| 524 | - } |
|
| 520 | + // Abort if the discount does not exist or does not apply here. |
|
| 521 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 522 | + if ( ! $discount->exists() ) { |
|
| 523 | + continue; |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 527 | - $invoice->recalculate_total(); |
|
| 526 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 527 | + $invoice->recalculate_total(); |
|
| 528 | 528 | |
| 529 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 530 | - $invoice->save(); |
|
| 531 | - } |
|
| 529 | + if ( $invoice->get_total_discount() > 0 ) { |
|
| 530 | + $invoice->save(); |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | - } |
|
| 533 | + } |
|
| 534 | 534 | |
| 535 | - // Show an admin message. |
|
| 536 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 535 | + // Show an admin message. |
|
| 536 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 537 | 537 | |
| 538 | - // Redirect the admin. |
|
| 539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 540 | - exit; |
|
| 538 | + // Redirect the admin. |
|
| 539 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 540 | + exit; |
|
| 541 | 541 | |
| 542 | - } |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | 544 | /** |
| 545 | - * Returns an array of admin notices. |
|
| 546 | - * |
|
| 547 | - * @since 1.0.19 |
|
| 545 | + * Returns an array of admin notices. |
|
| 546 | + * |
|
| 547 | + * @since 1.0.19 |
|
| 548 | 548 | * @return array |
| 549 | - */ |
|
| 550 | - public function get_notices() { |
|
| 551 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 549 | + */ |
|
| 550 | + public function get_notices() { |
|
| 551 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 552 | 552 | return is_array( $notices ) ? $notices : array(); |
| 553 | - } |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - /** |
|
| 556 | - * Checks if we have any admin notices. |
|
| 557 | - * |
|
| 558 | - * @since 2.0.4 |
|
| 555 | + /** |
|
| 556 | + * Checks if we have any admin notices. |
|
| 557 | + * |
|
| 558 | + * @since 2.0.4 |
|
| 559 | 559 | * @return array |
| 560 | - */ |
|
| 561 | - public function has_notices() { |
|
| 562 | - return count( $this->get_notices() ) > 0; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Clears all admin notices |
|
| 567 | - * |
|
| 568 | - * @access public |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - */ |
|
| 571 | - public function clear_notices() { |
|
| 572 | - delete_option( 'wpinv_admin_notices' ); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Saves a new admin notice |
|
| 577 | - * |
|
| 578 | - * @access public |
|
| 579 | - * @since 1.0.19 |
|
| 580 | - */ |
|
| 581 | - public function save_notice( $type, $message ) { |
|
| 582 | - $notices = $this->get_notices(); |
|
| 583 | - |
|
| 584 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 585 | - $notices[ $type ] = array(); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - $notices[ $type ][] = $message; |
|
| 589 | - |
|
| 590 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Displays a success notice |
|
| 595 | - * |
|
| 596 | - * @param string $msg The message to qeue. |
|
| 597 | - * @access public |
|
| 598 | - * @since 1.0.19 |
|
| 599 | - */ |
|
| 600 | - public function show_success( $msg ) { |
|
| 601 | - $this->save_notice( 'success', $msg ); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Displays a error notice |
|
| 606 | - * |
|
| 607 | - * @access public |
|
| 608 | - * @param string $msg The message to qeue. |
|
| 609 | - * @since 1.0.19 |
|
| 610 | - */ |
|
| 611 | - public function show_error( $msg ) { |
|
| 612 | - $this->save_notice( 'error', $msg ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Displays a warning notice |
|
| 617 | - * |
|
| 618 | - * @access public |
|
| 619 | - * @param string $msg The message to qeue. |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - */ |
|
| 622 | - public function show_warning( $msg ) { |
|
| 623 | - $this->save_notice( 'warning', $msg ); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Displays a info notice |
|
| 628 | - * |
|
| 629 | - * @access public |
|
| 630 | - * @param string $msg The message to qeue. |
|
| 631 | - * @since 1.0.19 |
|
| 632 | - */ |
|
| 633 | - public function show_info( $msg ) { |
|
| 634 | - $this->save_notice( 'info', $msg ); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Show notices |
|
| 639 | - * |
|
| 640 | - * @access public |
|
| 641 | - * @since 1.0.19 |
|
| 642 | - */ |
|
| 643 | - public function show_notices() { |
|
| 560 | + */ |
|
| 561 | + public function has_notices() { |
|
| 562 | + return count( $this->get_notices() ) > 0; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Clears all admin notices |
|
| 567 | + * |
|
| 568 | + * @access public |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + */ |
|
| 571 | + public function clear_notices() { |
|
| 572 | + delete_option( 'wpinv_admin_notices' ); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Saves a new admin notice |
|
| 577 | + * |
|
| 578 | + * @access public |
|
| 579 | + * @since 1.0.19 |
|
| 580 | + */ |
|
| 581 | + public function save_notice( $type, $message ) { |
|
| 582 | + $notices = $this->get_notices(); |
|
| 583 | + |
|
| 584 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 585 | + $notices[ $type ] = array(); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + $notices[ $type ][] = $message; |
|
| 589 | + |
|
| 590 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Displays a success notice |
|
| 595 | + * |
|
| 596 | + * @param string $msg The message to qeue. |
|
| 597 | + * @access public |
|
| 598 | + * @since 1.0.19 |
|
| 599 | + */ |
|
| 600 | + public function show_success( $msg ) { |
|
| 601 | + $this->save_notice( 'success', $msg ); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Displays a error notice |
|
| 606 | + * |
|
| 607 | + * @access public |
|
| 608 | + * @param string $msg The message to qeue. |
|
| 609 | + * @since 1.0.19 |
|
| 610 | + */ |
|
| 611 | + public function show_error( $msg ) { |
|
| 612 | + $this->save_notice( 'error', $msg ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Displays a warning notice |
|
| 617 | + * |
|
| 618 | + * @access public |
|
| 619 | + * @param string $msg The message to qeue. |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + */ |
|
| 622 | + public function show_warning( $msg ) { |
|
| 623 | + $this->save_notice( 'warning', $msg ); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Displays a info notice |
|
| 628 | + * |
|
| 629 | + * @access public |
|
| 630 | + * @param string $msg The message to qeue. |
|
| 631 | + * @since 1.0.19 |
|
| 632 | + */ |
|
| 633 | + public function show_info( $msg ) { |
|
| 634 | + $this->save_notice( 'info', $msg ); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Show notices |
|
| 639 | + * |
|
| 640 | + * @access public |
|
| 641 | + * @since 1.0.19 |
|
| 642 | + */ |
|
| 643 | + public function show_notices() { |
|
| 644 | 644 | |
| 645 | 645 | $notices = $this->get_notices(); |
| 646 | 646 | $this->clear_notices(); |
| 647 | 647 | |
| 648 | - foreach ( $notices as $type => $messages ) { |
|
| 648 | + foreach ( $notices as $type => $messages ) { |
|
| 649 | 649 | |
| 650 | - if ( ! is_array( $messages ) ) { |
|
| 651 | - continue; |
|
| 652 | - } |
|
| 650 | + if ( ! is_array( $messages ) ) { |
|
| 651 | + continue; |
|
| 652 | + } |
|
| 653 | 653 | |
| 654 | 654 | $type = sanitize_key( $type ); |
| 655 | - foreach ( $messages as $message ) { |
|
| 655 | + foreach ( $messages as $message ) { |
|
| 656 | 656 | $message = wp_kses_post( $message ); |
| 657 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 657 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 663 | + |
|
| 664 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 665 | + $url = esc_url( |
|
| 666 | + wp_nonce_url( |
|
| 667 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 668 | + 'getpaid-nonce', |
|
| 669 | + 'getpaid-nonce' |
|
| 670 | + ) |
|
| 671 | + ); |
|
| 672 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 673 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 674 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 675 | + break; |
|
| 658 | 676 | } |
| 659 | 677 | |
| 660 | 678 | } |
| 661 | 679 | |
| 662 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 663 | - |
|
| 664 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 665 | - $url = esc_url( |
|
| 666 | - wp_nonce_url( |
|
| 667 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 668 | - 'getpaid-nonce', |
|
| 669 | - 'getpaid-nonce' |
|
| 670 | - ) |
|
| 671 | - ); |
|
| 672 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 673 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 674 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
| 675 | - break; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - } |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | 682 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * The main admin class. |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * Class constructor. |
| 39 | 39 | */ |
| 40 | - public function __construct(){ |
|
| 40 | + public function __construct() { |
|
| 41 | 41 | |
| 42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
| 43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
| 44 | 44 | $this->reports = new GetPaid_Reports(); |
| 45 | 45 | |
| 46 | - if ( is_admin() ) { |
|
| 46 | + if (is_admin()) { |
|
| 47 | 47 | $this->init_admin_hooks(); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,22 +54,22 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | */ |
| 56 | 56 | private function init_admin_hooks() { |
| 57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
| 58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
| 59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
| 60 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
| 61 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 66 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
| 67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 70 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 71 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 72 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
| 58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
| 59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
| 60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
| 61 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
| 62 | + add_action('admin_notices', array($this, 'show_notices')); |
|
| 63 | + add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page')); |
|
| 64 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
| 65 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
| 66 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
| 67 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
| 68 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
| 69 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
| 70 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
| 71 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
| 72 | + do_action('getpaid_init_admin_hooks', $this); |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | |
@@ -80,37 +80,37 @@ discard block |
||
| 80 | 80 | public function enqeue_scripts() { |
| 81 | 81 | global $current_screen, $pagenow; |
| 82 | 82 | |
| 83 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 83 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
| 84 | 84 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
| 85 | 85 | |
| 86 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 86 | + if (!empty($current_screen->post_type)) { |
|
| 87 | 87 | $page = $current_screen->post_type; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // General styles. |
| 91 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
| 91 | + if (false !== stripos($page, 'wpi')) { |
|
| 92 | 92 | |
| 93 | 93 | // Styles. |
| 94 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
| 95 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
| 96 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
| 94 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
| 95 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
| 96 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
| 97 | 97 | |
| 98 | 98 | // Scripts. |
| 99 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 99 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
| 100 | 100 | |
| 101 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
| 102 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker' ), $version ); |
|
| 103 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
| 101 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
| 102 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker'), $version); |
|
| 103 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Payment form scripts. |
| 108 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 108 | + if ('wpi_payment_form' == $page && $editing) { |
|
| 109 | 109 | $this->load_payment_form_scripts(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 113 | - wp_enqueue_script( 'postbox' ); |
|
| 112 | + if ($page == 'wpinv-subscriptions') { |
|
| 113 | + wp_enqueue_script('postbox'); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | } |
@@ -123,32 +123,32 @@ discard block |
||
| 123 | 123 | global $post; |
| 124 | 124 | |
| 125 | 125 | $date_range = array( |
| 126 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
| 126 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days' |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | - if ( $date_range['period'] == 'custom' ) { |
|
| 129 | + if ($date_range['period'] == 'custom') { |
|
| 130 | 130 | |
| 131 | - if ( isset( $_GET['from'] ) ) { |
|
| 132 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 131 | + if (isset($_GET['from'])) { |
|
| 132 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( isset( $_GET['to'] ) ) { |
|
| 136 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 135 | + if (isset($_GET['to'])) { |
|
| 136 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $i18n = array( |
| 142 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 143 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
| 144 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 145 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 146 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 142 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 143 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
| 144 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
| 145 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
| 146 | + 'rest_root' => esc_url_raw(rest_url()), |
|
| 147 | 147 | 'date_range' => $date_range, |
| 148 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
| 149 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
| 150 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
| 151 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
| 148 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
| 149 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
| 150 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
| 151 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
| 152 | 152 | 'tax' => wpinv_tax_amount(), |
| 153 | 153 | 'discount' => 0, |
| 154 | 154 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -157,37 +157,37 @@ discard block |
||
| 157 | 157 | 'thousand_sep' => wpinv_thousands_separator(), |
| 158 | 158 | 'decimal_sep' => wpinv_decimal_separator(), |
| 159 | 159 | 'decimals' => wpinv_decimals(), |
| 160 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
| 161 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
| 162 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
| 163 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
| 164 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
| 165 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
| 166 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
| 167 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
| 168 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
| 169 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
| 170 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
| 171 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
| 172 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
| 173 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
| 174 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
| 175 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 176 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 177 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 160 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
| 161 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
| 162 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
| 163 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
| 164 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
| 165 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
| 166 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
| 167 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
| 168 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
| 169 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
| 170 | + 'action_edit' => __('Edit', 'invoicing'), |
|
| 171 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
| 172 | + 'item_description' => __('Item Description', 'invoicing'), |
|
| 173 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
| 174 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
| 175 | + 'searching' => __('Searching', 'invoicing'), |
|
| 176 | + 'loading' => __('Loading...', 'invoicing'), |
|
| 177 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 180 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
| 181 | 181 | |
| 182 | - $invoice = new WPInv_Invoice( $post ); |
|
| 182 | + $invoice = new WPInv_Invoice($post); |
|
| 183 | 183 | $i18n['save_invoice'] = sprintf( |
| 184 | - __( 'Save %s', 'invoicing' ), |
|
| 185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 184 | + __('Save %s', 'invoicing'), |
|
| 185 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | 188 | $i18n['invoice_description'] = sprintf( |
| 189 | - __( '%s Description', 'invoicing' ), |
|
| 190 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 189 | + __('%s Description', 'invoicing'), |
|
| 190 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | 193 | } |
@@ -201,24 +201,24 @@ discard block |
||
| 201 | 201 | * @param string $footer_text |
| 202 | 202 | * @return string |
| 203 | 203 | */ |
| 204 | - public function admin_footer_text( $footer_text ) { |
|
| 204 | + public function admin_footer_text($footer_text) { |
|
| 205 | 205 | global $current_screen; |
| 206 | 206 | |
| 207 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 207 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
| 208 | 208 | |
| 209 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 209 | + if (!empty($current_screen->post_type)) { |
|
| 210 | 210 | $page = $current_screen->post_type; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // General styles. |
| 214 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
| 214 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
| 215 | 215 | |
| 216 | 216 | // Change the footer text |
| 217 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 217 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
| 218 | 218 | |
| 219 | - $rating_url = esc_url( |
|
| 219 | + $rating_url = esc_url( |
|
| 220 | 220 | wp_nonce_url( |
| 221 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 221 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
| 222 | 222 | 'getpaid-nonce', |
| 223 | 223 | 'getpaid-nonce' |
| 224 | 224 | ) |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | $footer_text = sprintf( |
| 228 | 228 | /* translators: %s: five stars */ |
| 229 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 229 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
| 230 | 230 | "<a href='$rating_url'>★★★★★</a>" |
| 231 | 231 | ); |
| 232 | 232 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $footer_text = sprintf( |
| 236 | 236 | /* translators: %s: GetPaid */ |
| 237 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 237 | + __('Thank you for using %s!', 'invoicing'), |
|
| 238 | 238 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
| 239 | 239 | ); |
| 240 | 240 | |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | * @since 2.0.0 |
| 252 | 252 | */ |
| 253 | 253 | public function redirect_to_wordpress_rating_page() { |
| 254 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 255 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 254 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
| 255 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
| 256 | 256 | exit; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -263,30 +263,30 @@ discard block |
||
| 263 | 263 | protected function load_payment_form_scripts() { |
| 264 | 264 | global $post; |
| 265 | 265 | |
| 266 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
| 267 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 268 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 266 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
| 267 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
| 268 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
| 269 | 269 | |
| 270 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 271 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 270 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
| 271 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
| 272 | 272 | |
| 273 | 273 | wp_localize_script( |
| 274 | 274 | 'wpinv-admin-payment-form-script', |
| 275 | 275 | 'wpinvPaymentFormAdmin', |
| 276 | 276 | array( |
| 277 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 278 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 277 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
| 278 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
| 279 | 279 | 'currency' => wpinv_currency_symbol(), |
| 280 | 280 | 'position' => wpinv_currency_position(), |
| 281 | 281 | 'decimals' => (int) wpinv_decimals(), |
| 282 | 282 | 'thousands_sep' => wpinv_thousands_separator(), |
| 283 | 283 | 'decimals_sep' => wpinv_decimal_separator(), |
| 284 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 284 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
| 285 | 285 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
| 286 | 286 | ) |
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
| 289 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
@@ -297,25 +297,25 @@ discard block |
||
| 297 | 297 | * @return string |
| 298 | 298 | * |
| 299 | 299 | */ |
| 300 | - public function admin_body_class( $classes ) { |
|
| 300 | + public function admin_body_class($classes) { |
|
| 301 | 301 | global $pagenow, $post, $current_screen; |
| 302 | 302 | |
| 303 | 303 | |
| 304 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 304 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $current_screen->post_type ) ) { |
|
| 306 | + if (!empty($current_screen->post_type)) { |
|
| 307 | 307 | $page = $current_screen->post_type; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
| 311 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
| 310 | + if (false !== stripos($page, 'wpi')) { |
|
| 311 | + $classes .= ' wpi-' . sanitize_key($page); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
| 314 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
| 315 | 315 | $classes .= ' wpinv-cpt wpinv'; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 318 | + if (getpaid_is_invoice_post_type($page)) { |
|
| 319 | 319 | $classes .= ' getpaid-is-invoice-cpt'; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -325,19 +325,19 @@ discard block |
||
| 325 | 325 | /** |
| 326 | 326 | * Maybe show the AyeCode Connect Notice. |
| 327 | 327 | */ |
| 328 | - public function init_ayecode_connect_helper(){ |
|
| 328 | + public function init_ayecode_connect_helper() { |
|
| 329 | 329 | |
| 330 | 330 | new AyeCode_Connect_Helper( |
| 331 | 331 | array( |
| 332 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 333 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 334 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 335 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 336 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 337 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 338 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 332 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
| 333 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
| 334 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
| 335 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
| 336 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
| 337 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
| 338 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
| 339 | 339 | ), |
| 340 | - array( 'wpi-addons' ) |
|
| 340 | + array('wpi-addons') |
|
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | 343 | } |
@@ -349,20 +349,20 @@ discard block |
||
| 349 | 349 | */ |
| 350 | 350 | public function activation_redirect() { |
| 351 | 351 | |
| 352 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 352 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
| 353 | 353 | |
| 354 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 354 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
| 355 | 355 | return; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Bail if activating from network, or bulk |
| 359 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 359 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 360 | 360 | return; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 363 | + update_option('wpinv_redirected_to_settings', 1); |
|
| 364 | 364 | |
| 365 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 365 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 366 | 366 | exit; |
| 367 | 367 | |
| 368 | 368 | } |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function maybe_do_admin_action() { |
| 374 | 374 | |
| 375 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 376 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
| 377 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
| 375 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
| 376 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
| 377 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | } |
@@ -384,16 +384,16 @@ discard block |
||
| 384 | 384 | * |
| 385 | 385 | * @param array $args |
| 386 | 386 | */ |
| 387 | - public function send_customer_invoice( $args ) { |
|
| 388 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 387 | + public function send_customer_invoice($args) { |
|
| 388 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
| 389 | 389 | |
| 390 | - if ( $sent ) { |
|
| 391 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 390 | + if ($sent) { |
|
| 391 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
| 392 | 392 | } else { |
| 393 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 393 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 396 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
| 397 | 397 | exit; |
| 398 | 398 | } |
| 399 | 399 | |
@@ -402,16 +402,16 @@ discard block |
||
| 402 | 402 | * |
| 403 | 403 | * @param array $args |
| 404 | 404 | */ |
| 405 | - public function send_customer_payment_reminder( $args ) { |
|
| 406 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 405 | + public function send_customer_payment_reminder($args) { |
|
| 406 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
| 407 | 407 | |
| 408 | - if ( $sent ) { |
|
| 409 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 408 | + if ($sent) { |
|
| 409 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
| 410 | 410 | } else { |
| 411 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 411 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 414 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
| 415 | 415 | exit; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | */ |
| 422 | 422 | public function admin_reset_tax_rates() { |
| 423 | 423 | |
| 424 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 425 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 424 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
| 425 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 426 | 426 | exit; |
| 427 | 427 | |
| 428 | 428 | } |
@@ -434,8 +434,8 @@ discard block |
||
| 434 | 434 | public function admin_create_missing_pages() { |
| 435 | 435 | $installer = new GetPaid_Installer(); |
| 436 | 436 | $installer->create_pages(); |
| 437 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 438 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 437 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
| 438 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 439 | 439 | exit; |
| 440 | 440 | } |
| 441 | 441 | |
@@ -447,35 +447,35 @@ discard block |
||
| 447 | 447 | global $wpdb; |
| 448 | 448 | $installer = new GetPaid_Installer(); |
| 449 | 449 | |
| 450 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 450 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
| 451 | 451 | $installer->create_subscriptions_table(); |
| 452 | 452 | |
| 453 | - if ( $wpdb->last_error !== '' ) { |
|
| 454 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 453 | + if ($wpdb->last_error !== '') { |
|
| 454 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 458 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
| 459 | 459 | $installer->create_invoices_table(); |
| 460 | 460 | |
| 461 | - if ( $wpdb->last_error !== '' ) { |
|
| 462 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 461 | + if ($wpdb->last_error !== '') { |
|
| 462 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 466 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
| 467 | 467 | $installer->create_invoice_items_table(); |
| 468 | 468 | |
| 469 | - if ( $wpdb->last_error !== '' ) { |
|
| 470 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 469 | + if ($wpdb->last_error !== '') { |
|
| 470 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if ( ! $this->has_notices() ) { |
|
| 475 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 474 | + if (!$this->has_notices()) { |
|
| 475 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 478 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 479 | 479 | exit; |
| 480 | 480 | } |
| 481 | 481 | |
@@ -490,10 +490,10 @@ discard block |
||
| 490 | 490 | $installer->migrate_old_invoices(); |
| 491 | 491 | |
| 492 | 492 | // Show an admin message. |
| 493 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 493 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
| 494 | 494 | |
| 495 | 495 | // Redirect the admin. |
| 496 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 496 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 497 | 497 | exit; |
| 498 | 498 | |
| 499 | 499 | } |
@@ -507,36 +507,36 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | // Fetch all invoices that have discount codes. |
| 509 | 509 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 510 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 510 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
| 511 | 511 | |
| 512 | - foreach ( $invoices as $invoice ) { |
|
| 512 | + foreach ($invoices as $invoice) { |
|
| 513 | 513 | |
| 514 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 514 | + $invoice = new WPInv_Invoice($invoice); |
|
| 515 | 515 | |
| 516 | - if ( ! $invoice->exists() ) { |
|
| 516 | + if (!$invoice->exists()) { |
|
| 517 | 517 | continue; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Abort if the discount does not exist or does not apply here. |
| 521 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 522 | - if ( ! $discount->exists() ) { |
|
| 521 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 522 | + if (!$discount->exists()) { |
|
| 523 | 523 | continue; |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 526 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 527 | 527 | $invoice->recalculate_total(); |
| 528 | 528 | |
| 529 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 529 | + if ($invoice->get_total_discount() > 0) { |
|
| 530 | 530 | $invoice->save(); |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | // Show an admin message. |
| 536 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 536 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
| 537 | 537 | |
| 538 | 538 | // Redirect the admin. |
| 539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 539 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
| 540 | 540 | exit; |
| 541 | 541 | |
| 542 | 542 | } |
@@ -548,8 +548,8 @@ discard block |
||
| 548 | 548 | * @return array |
| 549 | 549 | */ |
| 550 | 550 | public function get_notices() { |
| 551 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 552 | - return is_array( $notices ) ? $notices : array(); |
|
| 551 | + $notices = get_option('wpinv_admin_notices'); |
|
| 552 | + return is_array($notices) ? $notices : array(); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | * @return array |
| 560 | 560 | */ |
| 561 | 561 | public function has_notices() { |
| 562 | - return count( $this->get_notices() ) > 0; |
|
| 562 | + return count($this->get_notices()) > 0; |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @since 1.0.19 |
| 570 | 570 | */ |
| 571 | 571 | public function clear_notices() { |
| 572 | - delete_option( 'wpinv_admin_notices' ); |
|
| 572 | + delete_option('wpinv_admin_notices'); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -578,16 +578,16 @@ discard block |
||
| 578 | 578 | * @access public |
| 579 | 579 | * @since 1.0.19 |
| 580 | 580 | */ |
| 581 | - public function save_notice( $type, $message ) { |
|
| 581 | + public function save_notice($type, $message) { |
|
| 582 | 582 | $notices = $this->get_notices(); |
| 583 | 583 | |
| 584 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 585 | - $notices[ $type ] = array(); |
|
| 584 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
| 585 | + $notices[$type] = array(); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - $notices[ $type ][] = $message; |
|
| 588 | + $notices[$type][] = $message; |
|
| 589 | 589 | |
| 590 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 590 | + update_option('wpinv_admin_notices', $notices); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * @access public |
| 598 | 598 | * @since 1.0.19 |
| 599 | 599 | */ |
| 600 | - public function show_success( $msg ) { |
|
| 601 | - $this->save_notice( 'success', $msg ); |
|
| 600 | + public function show_success($msg) { |
|
| 601 | + $this->save_notice('success', $msg); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | * @param string $msg The message to qeue. |
| 609 | 609 | * @since 1.0.19 |
| 610 | 610 | */ |
| 611 | - public function show_error( $msg ) { |
|
| 612 | - $this->save_notice( 'error', $msg ); |
|
| 611 | + public function show_error($msg) { |
|
| 612 | + $this->save_notice('error', $msg); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -619,8 +619,8 @@ discard block |
||
| 619 | 619 | * @param string $msg The message to qeue. |
| 620 | 620 | * @since 1.0.19 |
| 621 | 621 | */ |
| 622 | - public function show_warning( $msg ) { |
|
| 623 | - $this->save_notice( 'warning', $msg ); |
|
| 622 | + public function show_warning($msg) { |
|
| 623 | + $this->save_notice('warning', $msg); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -630,8 +630,8 @@ discard block |
||
| 630 | 630 | * @param string $msg The message to qeue. |
| 631 | 631 | * @since 1.0.19 |
| 632 | 632 | */ |
| 633 | - public function show_info( $msg ) { |
|
| 634 | - $this->save_notice( 'info', $msg ); |
|
| 633 | + public function show_info($msg) { |
|
| 634 | + $this->save_notice('info', $msg); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -645,32 +645,32 @@ discard block |
||
| 645 | 645 | $notices = $this->get_notices(); |
| 646 | 646 | $this->clear_notices(); |
| 647 | 647 | |
| 648 | - foreach ( $notices as $type => $messages ) { |
|
| 648 | + foreach ($notices as $type => $messages) { |
|
| 649 | 649 | |
| 650 | - if ( ! is_array( $messages ) ) { |
|
| 650 | + if (!is_array($messages)) { |
|
| 651 | 651 | continue; |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - $type = sanitize_key( $type ); |
|
| 655 | - foreach ( $messages as $message ) { |
|
| 656 | - $message = wp_kses_post( $message ); |
|
| 654 | + $type = sanitize_key($type); |
|
| 655 | + foreach ($messages as $message) { |
|
| 656 | + $message = wp_kses_post($message); |
|
| 657 | 657 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 662 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
| 663 | 663 | |
| 664 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 665 | - $url = esc_url( |
|
| 664 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
| 665 | + $url = esc_url( |
|
| 666 | 666 | wp_nonce_url( |
| 667 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 667 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
| 668 | 668 | 'getpaid-nonce', |
| 669 | 669 | 'getpaid-nonce' |
| 670 | 670 | ) |
| 671 | 671 | ); |
| 672 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 673 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 672 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
| 673 | + $message2 = __('Generate Pages', 'invoicing'); |
|
| 674 | 674 | echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
| 675 | 675 | break; |
| 676 | 676 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | * Hook in ajax handlers. |
| 18 | 18 | */ |
| 19 | 19 | public static function init() { |
| 20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
| 21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
| 20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
| 21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
| 22 | 22 | self::add_ajax_events(); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public static function define_ajax() { |
| 29 | 29 | |
| 30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
| 31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
| 32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
| 33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
| 34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
| 30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
| 32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
| 33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
| 34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
| 35 | 35 | } |
| 36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
| 37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | * @since 1.0.18 |
| 45 | 45 | */ |
| 46 | 46 | private static function wpinv_ajax_headers() { |
| 47 | - if ( ! headers_sent() ) { |
|
| 47 | + if (!headers_sent()) { |
|
| 48 | 48 | send_origin_headers(); |
| 49 | 49 | send_nosniff_header(); |
| 50 | 50 | nocache_headers(); |
| 51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 52 | - header( 'X-Robots-Tag: noindex' ); |
|
| 53 | - status_header( 200 ); |
|
| 51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
| 52 | + header('X-Robots-Tag: noindex'); |
|
| 53 | + status_header(200); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | public static function do_wpinv_ajax() { |
| 61 | 61 | global $wp_query; |
| 62 | 62 | |
| 63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
| 64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
| 63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
| 67 | + $action = $wp_query->get('wpinv-ajax'); |
|
| 68 | 68 | |
| 69 | - if ( $action ) { |
|
| 69 | + if ($action) { |
|
| 70 | 70 | self::wpinv_ajax_headers(); |
| 71 | - $action = sanitize_text_field( $action ); |
|
| 72 | - do_action( 'wpinv_ajax_' . $action ); |
|
| 71 | + $action = sanitize_text_field($action); |
|
| 72 | + do_action('wpinv_ajax_' . $action); |
|
| 73 | 73 | wp_die(); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -102,36 +102,36 @@ discard block |
||
| 102 | 102 | 'payment_form_refresh_prices' => true, |
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
| 106 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 107 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 105 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
| 106 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 107 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 108 | 108 | |
| 109 | - if ( $nopriv ) { |
|
| 110 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 111 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 112 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 109 | + if ($nopriv) { |
|
| 110 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 111 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 112 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | public static function add_note() { |
| 118 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
| 118 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
| 119 | 119 | |
| 120 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 120 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 121 | 121 | die(-1); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $post_id = absint( $_POST['post_id'] ); |
|
| 125 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
| 126 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
| 124 | + $post_id = absint($_POST['post_id']); |
|
| 125 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
| 126 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
| 127 | 127 | |
| 128 | 128 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 129 | 129 | |
| 130 | - if ( $post_id > 0 ) { |
|
| 131 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
| 130 | + if ($post_id > 0) { |
|
| 131 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
| 132 | 132 | |
| 133 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
| 134 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
| 133 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
| 134 | + wpinv_get_invoice_note_line_item($note_id); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -139,16 +139,16 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public static function delete_note() { |
| 142 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
| 142 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
| 143 | 143 | |
| 144 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 144 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 145 | 145 | die(-1); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $note_id = (int)$_POST['note_id']; |
|
| 148 | + $note_id = (int) $_POST['note_id']; |
|
| 149 | 149 | |
| 150 | - if ( $note_id > 0 ) { |
|
| 151 | - wp_delete_comment( $note_id, true ); |
|
| 150 | + if ($note_id > 0) { |
|
| 151 | + wp_delete_comment($note_id, true); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | die(); |
@@ -166,34 +166,34 @@ discard block |
||
| 166 | 166 | public static function get_billing_details() { |
| 167 | 167 | |
| 168 | 168 | // Verify nonce. |
| 169 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 169 | + check_ajax_referer('wpinv-nonce'); |
|
| 170 | 170 | |
| 171 | 171 | // Can the user manage the plugin? |
| 172 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 172 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 173 | 173 | die(-1); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // Do we have a user id? |
| 177 | 177 | $user_id = $_GET['user_id']; |
| 178 | 178 | |
| 179 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
| 179 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
| 180 | 180 | die(-1); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Fetch the billing details. |
| 184 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
| 185 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
| 184 | + $billing_details = wpinv_get_user_address($user_id); |
|
| 185 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
| 186 | 186 | |
| 187 | 187 | // unset the user id and email. |
| 188 | - $to_ignore = array( 'user_id', 'email' ); |
|
| 188 | + $to_ignore = array('user_id', 'email'); |
|
| 189 | 189 | |
| 190 | - foreach ( $to_ignore as $key ) { |
|
| 191 | - if ( isset( $billing_details[ $key ] ) ) { |
|
| 192 | - unset( $billing_details[ $key ] ); |
|
| 190 | + foreach ($to_ignore as $key) { |
|
| 191 | + if (isset($billing_details[$key])) { |
|
| 192 | + unset($billing_details[$key]); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - wp_send_json_success( $billing_details ); |
|
| 196 | + wp_send_json_success($billing_details); |
|
| 197 | 197 | |
| 198 | 198 | } |
| 199 | 199 | |
@@ -203,47 +203,47 @@ discard block |
||
| 203 | 203 | public static function check_new_user_email() { |
| 204 | 204 | |
| 205 | 205 | // Verify nonce. |
| 206 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 206 | + check_ajax_referer('wpinv-nonce'); |
|
| 207 | 207 | |
| 208 | 208 | // Can the user manage the plugin? |
| 209 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 209 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 210 | 210 | die(-1); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // We need an email address. |
| 214 | - if ( empty( $_GET['email'] ) ) { |
|
| 215 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
| 214 | + if (empty($_GET['email'])) { |
|
| 215 | + _e("Provide the new user's email address", 'invoicing'); |
|
| 216 | 216 | exit; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | // Ensure the email is valid. |
| 220 | - $email = sanitize_text_field( $_GET['email'] ); |
|
| 221 | - if ( ! is_email( $email ) ) { |
|
| 222 | - _e( 'Invalid email address', 'invoicing' ); |
|
| 220 | + $email = sanitize_text_field($_GET['email']); |
|
| 221 | + if (!is_email($email)) { |
|
| 222 | + _e('Invalid email address', 'invoicing'); |
|
| 223 | 223 | exit; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // And it does not exist. |
| 227 | - if ( email_exists( $email ) ) { |
|
| 228 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
| 227 | + if (email_exists($email)) { |
|
| 228 | + _e('A user with this email address already exists', 'invoicing'); |
|
| 229 | 229 | exit; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - wp_send_json_success( true ); |
|
| 232 | + wp_send_json_success(true); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public static function run_tool() { |
| 236 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 237 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 236 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 237 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 238 | 238 | die(-1); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
| 241 | + $tool = sanitize_text_field($_POST['tool']); |
|
| 242 | 242 | |
| 243 | - do_action( 'wpinv_run_tool' ); |
|
| 243 | + do_action('wpinv_run_tool'); |
|
| 244 | 244 | |
| 245 | - if ( !empty( $tool ) ) { |
|
| 246 | - do_action( 'wpinv_tool_' . $tool ); |
|
| 245 | + if (!empty($tool)) { |
|
| 246 | + do_action('wpinv_tool_' . $tool); |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
@@ -253,27 +253,27 @@ discard block |
||
| 253 | 253 | public static function get_payment_form() { |
| 254 | 254 | |
| 255 | 255 | // Check nonce. |
| 256 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 256 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 257 | 257 | |
| 258 | 258 | // Is the request set up correctly? |
| 259 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 259 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
| 260 | 260 | echo aui()->alert( |
| 261 | 261 | array( |
| 262 | 262 | 'type' => 'warning', |
| 263 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
| 263 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
| 264 | 264 | ) |
| 265 | 265 | ); |
| 266 | 266 | exit; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Payment form or button? |
| 270 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 271 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
| 272 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
| 273 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
| 270 | + if (!empty($_GET['form'])) { |
|
| 271 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
| 272 | + } else if (!empty($_GET['invoice'])) { |
|
| 273 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
| 274 | 274 | } else { |
| 275 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
| 276 | - getpaid_display_item_payment_form( $items ); |
|
| 275 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
| 276 | + getpaid_display_item_payment_form($items); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | exit; |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | public static function payment_form() { |
| 289 | 289 | |
| 290 | 290 | // Check nonce. |
| 291 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 291 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 292 | 292 | |
| 293 | 293 | // ... form fields... |
| 294 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 295 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
| 294 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
| 295 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
| 296 | 296 | exit; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Process the payment form. |
| 300 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
| 301 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
| 300 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
| 301 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
| 302 | 302 | $checkout->process_checkout(); |
| 303 | 303 | |
| 304 | 304 | exit; |
@@ -311,55 +311,55 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public static function get_payment_form_states_field() { |
| 313 | 313 | |
| 314 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
| 314 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
| 315 | 315 | exit; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
| 318 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
| 319 | 319 | |
| 320 | - if ( empty( $elements ) ) { |
|
| 320 | + if (empty($elements)) { |
|
| 321 | 321 | exit; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | $address_fields = array(); |
| 325 | - foreach ( $elements as $element ) { |
|
| 326 | - if ( 'address' === $element['type'] ) { |
|
| 325 | + foreach ($elements as $element) { |
|
| 326 | + if ('address' === $element['type']) { |
|
| 327 | 327 | $address_fields = $element; |
| 328 | 328 | break; |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if ( empty( $address_fields ) ) { |
|
| 332 | + if (empty($address_fields)) { |
|
| 333 | 333 | exit; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
| 336 | + foreach ($address_fields['fields'] as $address_field) { |
|
| 337 | 337 | |
| 338 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
| 338 | + if ('wpinv_state' == $address_field['name']) { |
|
| 339 | 339 | |
| 340 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
| 341 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
| 342 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
| 343 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
| 344 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
| 345 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
| 340 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
| 341 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
| 342 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
| 343 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
| 344 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
| 345 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
| 346 | 346 | |
| 347 | - if ( ! empty( $address_field['required'] ) ) { |
|
| 347 | + if (!empty($address_field['required'])) { |
|
| 348 | 348 | $label .= "<span class='text-danger'> *</span>"; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $html = getpaid_get_states_select_markup ( |
|
| 352 | - sanitize_text_field( $_GET['country'] ), |
|
| 351 | + $html = getpaid_get_states_select_markup( |
|
| 352 | + sanitize_text_field($_GET['country']), |
|
| 353 | 353 | $value, |
| 354 | 354 | $placeholder, |
| 355 | 355 | $label, |
| 356 | 356 | $description, |
| 357 | - ! empty( $address_field['required'] ), |
|
| 357 | + !empty($address_field['required']), |
|
| 358 | 358 | $wrap_class, |
| 359 | - wpinv_clean( $_GET['name'] ) |
|
| 359 | + wpinv_clean($_GET['name']) |
|
| 360 | 360 | ); |
| 361 | 361 | |
| 362 | - wp_send_json_success( $html ); |
|
| 362 | + wp_send_json_success($html); |
|
| 363 | 363 | exit; |
| 364 | 364 | |
| 365 | 365 | } |
@@ -375,66 +375,66 @@ discard block |
||
| 375 | 375 | public static function recalculate_invoice_totals() { |
| 376 | 376 | |
| 377 | 377 | // Verify nonce. |
| 378 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 378 | + check_ajax_referer('wpinv-nonce'); |
|
| 379 | 379 | |
| 380 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 380 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 381 | 381 | exit; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // We need an invoice. |
| 385 | - if ( empty( $_POST['post_id'] ) ) { |
|
| 385 | + if (empty($_POST['post_id'])) { |
|
| 386 | 386 | exit; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // Fetch the invoice. |
| 390 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
| 390 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
| 391 | 391 | |
| 392 | 392 | // Ensure it exists. |
| 393 | - if ( ! $invoice->get_id() ) { |
|
| 393 | + if (!$invoice->get_id()) { |
|
| 394 | 394 | exit; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Maybe set the country, state, currency. |
| 398 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
| 399 | - if ( isset( $_POST[ $key ] ) ) { |
|
| 398 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
| 399 | + if (isset($_POST[$key])) { |
|
| 400 | 400 | $method = "set_$key"; |
| 401 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
| 401 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Maybe disable taxes. |
| 406 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
| 406 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
| 407 | 407 | |
| 408 | 408 | // Discount code. |
| 409 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 410 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 411 | - if ( $discount->exists() ) { |
|
| 412 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 409 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 410 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 411 | + if ($discount->exists()) { |
|
| 412 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 413 | 413 | } else { |
| 414 | - $invoice->remove_discount( 'discount_code' ); |
|
| 414 | + $invoice->remove_discount('discount_code'); |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Recalculate totals. |
| 419 | 419 | $invoice->recalculate_total(); |
| 420 | 420 | |
| 421 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 421 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
| 422 | 422 | |
| 423 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
| 424 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
| 425 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
| 423 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
| 424 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
| 425 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | $totals = array( |
| 429 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
| 430 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
| 431 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
| 429 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
| 430 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
| 431 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
| 432 | 432 | 'total' => $total, |
| 433 | 433 | ); |
| 434 | 434 | |
| 435 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
| 435 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
| 436 | 436 | |
| 437 | - wp_send_json_success( compact( 'totals' ) ); |
|
| 437 | + wp_send_json_success(compact('totals')); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -443,33 +443,33 @@ discard block |
||
| 443 | 443 | public static function get_invoice_items() { |
| 444 | 444 | |
| 445 | 445 | // Verify nonce. |
| 446 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 446 | + check_ajax_referer('wpinv-nonce'); |
|
| 447 | 447 | |
| 448 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 448 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 449 | 449 | exit; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // We need an invoice and items. |
| 453 | - if ( empty( $_POST['post_id'] ) ) { |
|
| 453 | + if (empty($_POST['post_id'])) { |
|
| 454 | 454 | exit; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // Fetch the invoice. |
| 458 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
| 458 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
| 459 | 459 | |
| 460 | 460 | // Ensure it exists. |
| 461 | - if ( ! $invoice->get_id() ) { |
|
| 461 | + if (!$invoice->get_id()) { |
|
| 462 | 462 | exit; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // Return an array of invoice items. |
| 466 | 466 | $items = array(); |
| 467 | 467 | |
| 468 | - foreach ( $invoice->get_items() as $item ) { |
|
| 469 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
| 468 | + foreach ($invoice->get_items() as $item) { |
|
| 469 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - wp_send_json_success( compact( 'items' ) ); |
|
| 472 | + wp_send_json_success(compact('items')); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
@@ -478,50 +478,50 @@ discard block |
||
| 478 | 478 | public static function edit_invoice_item() { |
| 479 | 479 | |
| 480 | 480 | // Verify nonce. |
| 481 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 481 | + check_ajax_referer('wpinv-nonce'); |
|
| 482 | 482 | |
| 483 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 483 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 484 | 484 | exit; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // We need an invoice and item details. |
| 488 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
| 488 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
| 489 | 489 | exit; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | // Fetch the invoice. |
| 493 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
| 493 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
| 494 | 494 | |
| 495 | 495 | // Ensure it exists and its not been paid for. |
| 496 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 496 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 497 | 497 | exit; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // Format the data. |
| 501 | - $data = wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ); |
|
| 501 | + $data = wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')); |
|
| 502 | 502 | |
| 503 | 503 | // Ensure that we have an item id. |
| 504 | - if ( empty( $data['id'] ) ) { |
|
| 504 | + if (empty($data['id'])) { |
|
| 505 | 505 | exit; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | // Abort if the invoice does not have the specified item. |
| 509 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
| 509 | + $item = $invoice->get_item((int) $data['id']); |
|
| 510 | 510 | |
| 511 | - if ( empty( $item ) ) { |
|
| 511 | + if (empty($item)) { |
|
| 512 | 512 | exit; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // Update the item. |
| 516 | - $item->set_price( floatval( $data['price'] ) ); |
|
| 517 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
| 518 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
| 519 | - $item->set_quantity( intval( $data['quantity'] ) ); |
|
| 516 | + $item->set_price(floatval($data['price'])); |
|
| 517 | + $item->set_name(sanitize_text_field($data['name'])); |
|
| 518 | + $item->set_description(wp_kses_post($data['description'])); |
|
| 519 | + $item->set_quantity(intval($data['quantity'])); |
|
| 520 | 520 | |
| 521 | 521 | // Add it to the invoice. |
| 522 | - $error = $invoice->add_item( $item ); |
|
| 522 | + $error = $invoice->add_item($item); |
|
| 523 | 523 | $alert = false; |
| 524 | - if ( is_wp_error( $error ) ) { |
|
| 524 | + if (is_wp_error($error)) { |
|
| 525 | 525 | $alert = $error->get_error_message(); |
| 526 | 526 | } |
| 527 | 527 | |
@@ -534,11 +534,11 @@ discard block |
||
| 534 | 534 | // Return an array of invoice items. |
| 535 | 535 | $items = array(); |
| 536 | 536 | |
| 537 | - foreach ( $invoice->get_items() as $item ) { |
|
| 538 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 537 | + foreach ($invoice->get_items() as $item) { |
|
| 538 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
| 541 | + wp_send_json_success(compact('items', 'alert')); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -547,33 +547,33 @@ discard block |
||
| 547 | 547 | public static function remove_invoice_item() { |
| 548 | 548 | |
| 549 | 549 | // Verify nonce. |
| 550 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 550 | + check_ajax_referer('wpinv-nonce'); |
|
| 551 | 551 | |
| 552 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 552 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 553 | 553 | exit; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | // We need an invoice and an item. |
| 557 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
| 557 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
| 558 | 558 | exit; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | // Fetch the invoice. |
| 562 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
| 562 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
| 563 | 563 | |
| 564 | 564 | // Ensure it exists and its not been paid for. |
| 565 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 565 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 566 | 566 | exit; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // Abort if the invoice does not have the specified item. |
| 570 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
| 570 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
| 571 | 571 | |
| 572 | - if ( empty( $item ) ) { |
|
| 572 | + if (empty($item)) { |
|
| 573 | 573 | exit; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
| 576 | + $invoice->remove_item((int) $_POST['item_id']); |
|
| 577 | 577 | |
| 578 | 578 | // Update totals. |
| 579 | 579 | $invoice->recalculate_total(); |
@@ -584,11 +584,11 @@ discard block |
||
| 584 | 584 | // Return an array of invoice items. |
| 585 | 585 | $items = array(); |
| 586 | 586 | |
| 587 | - foreach ( $invoice->get_items() as $item ) { |
|
| 588 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 587 | + foreach ($invoice->get_items() as $item) { |
|
| 588 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - wp_send_json_success( compact( 'items' ) ); |
|
| 591 | + wp_send_json_success(compact('items')); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -597,39 +597,39 @@ discard block |
||
| 597 | 597 | public static function add_invoice_items() { |
| 598 | 598 | |
| 599 | 599 | // Verify nonce. |
| 600 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 600 | + check_ajax_referer('wpinv-nonce'); |
|
| 601 | 601 | |
| 602 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 602 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 603 | 603 | exit; |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | // We need an invoice and items. |
| 607 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
| 607 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
| 608 | 608 | exit; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // Fetch the invoice. |
| 612 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
| 612 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
| 613 | 613 | $alert = false; |
| 614 | 614 | |
| 615 | 615 | // Ensure it exists and its not been paid for. |
| 616 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 616 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 617 | 617 | exit; |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // Add the items. |
| 621 | - foreach ( $_POST['items'] as $data ) { |
|
| 621 | + foreach ($_POST['items'] as $data) { |
|
| 622 | 622 | |
| 623 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
| 623 | + $item = new GetPaid_Form_Item($data['id']); |
|
| 624 | 624 | |
| 625 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
| 626 | - $item->set_quantity( $data[ 'qty' ] ); |
|
| 625 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
| 626 | + $item->set_quantity($data['qty']); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if ( $item->get_id() > 0 ) { |
|
| 630 | - $error = $invoice->add_item( $item ); |
|
| 629 | + if ($item->get_id() > 0) { |
|
| 630 | + $error = $invoice->add_item($item); |
|
| 631 | 631 | |
| 632 | - if ( is_wp_error( $error ) ) { |
|
| 632 | + if (is_wp_error($error)) { |
|
| 633 | 633 | $alert = $error->get_error_message(); |
| 634 | 634 | } |
| 635 | 635 | |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | // Return an array of invoice items. |
| 645 | 645 | $items = array(); |
| 646 | 646 | |
| 647 | - foreach ( $invoice->get_items() as $item ) { |
|
| 648 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
| 647 | + foreach ($invoice->get_items() as $item) { |
|
| 648 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
| 651 | + wp_send_json_success(compact('items', 'alert')); |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -657,15 +657,15 @@ discard block |
||
| 657 | 657 | public static function get_invoicing_items() { |
| 658 | 658 | |
| 659 | 659 | // Verify nonce. |
| 660 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 660 | + check_ajax_referer('wpinv-nonce'); |
|
| 661 | 661 | |
| 662 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 662 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 663 | 663 | exit; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | // We need a search term. |
| 667 | - if ( empty( $_GET['search'] ) ) { |
|
| 668 | - wp_send_json_success( array() ); |
|
| 667 | + if (empty($_GET['search'])) { |
|
| 668 | + wp_send_json_success(array()); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | // Retrieve items. |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | 'orderby' => 'title', |
| 675 | 675 | 'order' => 'ASC', |
| 676 | 676 | 'posts_per_page' => -1, |
| 677 | - 'post_status' => array( 'publish' ), |
|
| 678 | - 's' => trim( $_GET['search'] ), |
|
| 677 | + 'post_status' => array('publish'), |
|
| 678 | + 's' => trim($_GET['search']), |
|
| 679 | 679 | 'meta_query' => array( |
| 680 | 680 | array( |
| 681 | 681 | 'key' => '_wpinv_type', |
@@ -685,22 +685,22 @@ discard block |
||
| 685 | 685 | ) |
| 686 | 686 | ); |
| 687 | 687 | |
| 688 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
| 688 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
| 689 | 689 | $data = array(); |
| 690 | 690 | |
| 691 | 691 | |
| 692 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
| 692 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
| 693 | 693 | |
| 694 | - foreach ( $items as $item ) { |
|
| 695 | - $item = new GetPaid_Form_Item( $item ); |
|
| 694 | + foreach ($items as $item) { |
|
| 695 | + $item = new GetPaid_Form_Item($item); |
|
| 696 | 696 | $data[] = array( |
| 697 | 697 | 'id' => (int) $item->get_id(), |
| 698 | - 'text' => strip_tags( $item->get_name() ), |
|
| 699 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
| 698 | + 'text' => strip_tags($item->get_name()), |
|
| 699 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
| 700 | 700 | ); |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - wp_send_json_success( $data ); |
|
| 703 | + wp_send_json_success($data); |
|
| 704 | 704 | |
| 705 | 705 | } |
| 706 | 706 | |
@@ -710,37 +710,37 @@ discard block |
||
| 710 | 710 | public static function get_customers() { |
| 711 | 711 | |
| 712 | 712 | // Verify nonce. |
| 713 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 713 | + check_ajax_referer('wpinv-nonce'); |
|
| 714 | 714 | |
| 715 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 715 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 716 | 716 | exit; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | // We need a search term. |
| 720 | - if ( empty( $_GET['search'] ) ) { |
|
| 721 | - wp_send_json_success( array() ); |
|
| 720 | + if (empty($_GET['search'])) { |
|
| 721 | + wp_send_json_success(array()); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // Retrieve customers. |
| 725 | 725 | |
| 726 | 726 | $customer_args = array( |
| 727 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
| 727 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
| 728 | 728 | 'orderby' => 'display_name', |
| 729 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
| 730 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 729 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
| 730 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
| 731 | 731 | ); |
| 732 | 732 | |
| 733 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
| 733 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
| 734 | 734 | $data = array(); |
| 735 | 735 | |
| 736 | - foreach ( $customers as $customer ) { |
|
| 736 | + foreach ($customers as $customer) { |
|
| 737 | 737 | $data[] = array( |
| 738 | 738 | 'id' => (int) $customer->ID, |
| 739 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
| 739 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
| 740 | 740 | ); |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - wp_send_json_success( $data ); |
|
| 743 | + wp_send_json_success($data); |
|
| 744 | 744 | |
| 745 | 745 | } |
| 746 | 746 | |
@@ -750,28 +750,28 @@ discard block |
||
| 750 | 750 | public static function get_aui_states_field() { |
| 751 | 751 | |
| 752 | 752 | // Verify nonce. |
| 753 | - check_ajax_referer( 'wpinv-nonce' ); |
|
| 753 | + check_ajax_referer('wpinv-nonce'); |
|
| 754 | 754 | |
| 755 | 755 | // We need a country. |
| 756 | - if ( empty( $_GET['country'] ) ) { |
|
| 756 | + if (empty($_GET['country'])) { |
|
| 757 | 757 | exit; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
| 761 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
| 762 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
| 763 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
| 760 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
| 761 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
| 762 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
| 763 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
| 764 | 764 | |
| 765 | - if ( empty( $states ) ) { |
|
| 765 | + if (empty($states)) { |
|
| 766 | 766 | |
| 767 | 767 | $html = aui()->input( |
| 768 | 768 | array( |
| 769 | 769 | 'type' => 'text', |
| 770 | 770 | 'id' => 'wpinv_state', |
| 771 | 771 | 'name' => $name, |
| 772 | - 'label' => __( 'State', 'invoicing' ), |
|
| 772 | + 'label' => __('State', 'invoicing'), |
|
| 773 | 773 | 'label_type' => 'vertical', |
| 774 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
| 774 | + 'placeholder' => __('State', 'invoicing'), |
|
| 775 | 775 | 'class' => $class, |
| 776 | 776 | 'value' => $state, |
| 777 | 777 | ) |
@@ -783,9 +783,9 @@ discard block |
||
| 783 | 783 | array( |
| 784 | 784 | 'id' => 'wpinv_state', |
| 785 | 785 | 'name' => $name, |
| 786 | - 'label' => __( 'State', 'invoicing' ), |
|
| 786 | + 'label' => __('State', 'invoicing'), |
|
| 787 | 787 | 'label_type' => 'vertical', |
| 788 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
| 788 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
| 789 | 789 | 'class' => $class, |
| 790 | 790 | 'value' => $state, |
| 791 | 791 | 'options' => $states, |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | wp_send_json_success( |
| 800 | 800 | array( |
| 801 | 801 | 'html' => $html, |
| 802 | - 'select' => ! empty ( $states ) |
|
| 802 | + 'select' => !empty ($states) |
|
| 803 | 803 | ) |
| 804 | 804 | ); |
| 805 | 805 | |
@@ -813,11 +813,11 @@ discard block |
||
| 813 | 813 | public static function payment_form_refresh_prices() { |
| 814 | 814 | |
| 815 | 815 | // Check nonce. |
| 816 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
| 816 | + check_ajax_referer('getpaid_form_nonce'); |
|
| 817 | 817 | |
| 818 | 818 | // ... form fields... |
| 819 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 820 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
| 819 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
| 820 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
| 821 | 821 | exit; |
| 822 | 822 | } |
| 823 | 823 | |
@@ -825,18 +825,18 @@ discard block |
||
| 825 | 825 | $submission = new GetPaid_Payment_Form_Submission(); |
| 826 | 826 | |
| 827 | 827 | // Do we have an error? |
| 828 | - if ( ! empty( $submission->last_error ) ) { |
|
| 828 | + if (!empty($submission->last_error)) { |
|
| 829 | 829 | echo $submission->last_error; |
| 830 | 830 | exit; |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | // Prepare the response. |
| 834 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
| 834 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
| 835 | 835 | |
| 836 | 836 | // Filter the response. |
| 837 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
| 837 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
| 838 | 838 | |
| 839 | - wp_send_json_success( $response ); |
|
| 839 | + wp_send_json_success($response); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | } |