|
@@ 27-38 (lines=12) @@
|
| 24 |
|
return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
function wpinv_delete_discount( $data ) { |
| 28 |
|
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
| 29 |
|
wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
if( ! current_user_can( 'manage_options' ) ) { |
| 33 |
|
wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
$discount_id = $data['discount']; |
| 37 |
|
wpinv_remove_discount( $discount_id ); |
| 38 |
|
} |
| 39 |
|
add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
| 40 |
|
|
| 41 |
|
function wpinv_activate_discount( $data ) { |
|
@@ 41-52 (lines=12) @@
|
| 38 |
|
} |
| 39 |
|
add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
| 40 |
|
|
| 41 |
|
function wpinv_activate_discount( $data ) { |
| 42 |
|
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
| 43 |
|
wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
if( ! current_user_can( 'manage_options' ) ) { |
| 47 |
|
wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
$id = absint( $data['discount'] ); |
| 51 |
|
wpinv_update_discount_status( $id, 'publish' ); |
| 52 |
|
} |
| 53 |
|
add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
| 54 |
|
|
| 55 |
|
function wpinv_deactivate_discount( $data ) { |
|
@@ 55-66 (lines=12) @@
|
| 52 |
|
} |
| 53 |
|
add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
| 54 |
|
|
| 55 |
|
function wpinv_deactivate_discount( $data ) { |
| 56 |
|
if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
| 57 |
|
wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
if( ! current_user_can( 'manage_options' ) ) { |
| 61 |
|
wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
$id = absint( $data['discount'] ); |
| 65 |
|
wpinv_update_discount_status( $id, 'pending' ); |
| 66 |
|
} |
| 67 |
|
add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
| 68 |
|
|
| 69 |
|
function wpinv_get_discounts( $args = array() ) { |