| |
| <?php
|
| add_action( 'wp_ajax_validate_vanity_code', 'send_vanity_coupon_request_notification', 9 );
|
|
|
| function send_vanity_coupon_request_notification() {
|
| if ( ! isset( $_REQUEST['vccNonce'] ) || ! wp_verify_nonce( $_REQUEST['vccNonce'], 'request_vanity_coupon_code' ) ) {
|
| return;
|
| }
|
|
|
| $affiliate_id = isset( $_REQUEST['affiliateID'] ) ? sanitize_text_field( $_REQUEST['affiliateID'] ) : false;
|
| $coupon_id = isset( $_REQUEST['couponID'] ) ? sanitize_text_field( $_REQUEST['couponID'] ) : false;
|
| $old_code = isset( $_REQUEST['oldCode'] ) ? sanitize_text_field( $_REQUEST['oldCode'] ) : false;
|
| $new_code = isset( $_REQUEST['newCode'] ) ? sanitize_text_field( $_REQUEST['newCode'] ) : false;
|
| $integration = isset( $_REQUEST['integration'] ) ? sanitize_text_field( $_REQUEST['integration'] ) : false;
|
| $type = isset( $_REQUEST['type'] ) ? sanitize_text_field( $_REQUEST['type'] ) : false;
|
|
|
|
|
| if ( ! $affiliate_id || ! $coupon_id || ! $old_code || ! $new_code || ! $integration || ! $type ) {
|
| return;
|
| }
|
|
|
| if ( affiliatewp_vanity_coupon_codes()->db->is_pending( $coupon_id ) ) {
|
| return;
|
| }
|
|
|
| $sanitized_new_code = affiliatewp_vanity_coupon_codes()->db->sanitize_vanity_code( $new_code );
|
| if ( strtoupper( $new_code ) !== $sanitized_new_code || empty( $sanitized_new_code ) ) {
|
| return;
|
| }
|
|
|
| if ( ! affiliatewp_vanity_coupon_codes()->db->is_unique( $sanitized_new_code, $integration ) ) {
|
| return;
|
| }
|
|
|
| $affiliate = affwp_get_affiliate( $affiliate_id );
|
| if ( ! $affiliate ) {
|
| return;
|
| }
|
|
|
| $user = get_userdata( affwp_get_affiliate_user_id( $affiliate->affiliate_id ) );
|
| if ( ! $user ) {
|
| return;
|
| }
|
|
|
| $admin_email = get_option( 'admin_email' );
|
| $subject = sprintf( '[%s] New Vanity Coupon Code Request', get_bloginfo( 'name' ) );
|
| $message = sprintf(
|
| 'Affiliate: %s' . "\n\n" .
|
| 'Affiliate ID: %d' . "\n\n" .
|
| 'Current Code: %s' . "\n\n" .
|
| 'Requested Code: %s' . "\n\n" .
|
| 'To review this request, please visit: %s',
|
| $user->display_name,
|
| $affiliate->affiliate_id,
|
| $old_code,
|
| $sanitized_new_code,
|
| admin_url( 'admin.php?page=affiliate-wp-vanity-coupon-codes' )
|
| );
|
| $headers = array(
|
| 'Content-Type: text/plain; charset=UTF-8',
|
| 'From: ' . get_bloginfo( 'name' ) . ' <' . $admin_email . '>',
|
| );
|
|
|
| wp_mail( $admin_email, $subject, $message, $headers );
|
| }
|
|
|
| |
| |
Comments