deleteMe() ) { $pmpro_msg = sprintf( __( 'Order %s deleted successfully.', 'paid-memberships-pro' ), $dorder_code ); $pmpro_msgt = 'success'; } else { $pmpro_msg = __( 'Error deleting order.', 'paid-memberships-pro' ); $pmpro_msgt = 'error'; } } // Refund this order if ( ! empty( $_REQUEST['refund'] ) ) { // Check nonce for refunding. $nonceokay = true; if ( empty( $_REQUEST['pmpro_orders_nonce'] ) || ! check_admin_referer( 'refund_order', 'pmpro_orders_nonce' ) ) { $nonceokay = false; } $rorder = new MemberOrder( (int) $_REQUEST['refund'] ); if ( $nonceokay && !empty( $rorder ) && pmpro_allowed_refunds( $rorder ) ) { if( pmpro_refund_order( $rorder ) ) { $pmpro_msg = __( 'Order refunded successfully.', 'paid-memberships-pro' ); $pmpro_msgt = 'success'; } else { $pmpro_msg = __( 'Error refunding order. Please check the order notes for more information.', 'paid-memberships-pro' ); $pmpro_msgt = 'error'; } } else { $pmpro_msg = __( 'Error refunding order. Please check the order notes for more information.', 'paid-memberships-pro' ); $pmpro_msgt = 'error'; } } $thisyear = date( 'Y', $now ); // this array stores fields that should be read only $read_only_fields = apply_filters( 'pmpro_orders_read_only_fields', array( 'code', 'payment_transaction_id', 'subscription_transaction_id', ) ); // if this is a new order or copy of one, let's make all fields editable // Checking orderby as order could be the order ID or whether the List Table should be sorted ascending or descending. if ( ( ! empty( $_REQUEST['order'] ) && $_REQUEST['order'] < 0 ) && ! isset( $_REQUEST['orderby'] ) ) { $read_only_fields = array(); } // saving? if ( ! empty( $_REQUEST['save'] ) ) { // start with old order if applicable $order_id = intval( $_REQUEST['order'] ); if ( $order_id > 0 ) { $order = new MemberOrder( $order_id ); } else { $order = new MemberOrder(); $order->billing = new stdClass(); } // update values if ( ! in_array( 'code', $read_only_fields ) && isset( $_POST['code'] ) ) { $order->code = sanitize_text_field( $_POST['code'] ); } if ( ! in_array( 'user_id', $read_only_fields ) && isset( $_POST['user_id'] ) ) { $order->user_id = intval( $_POST['user_id'] ); } if ( ! in_array( 'membership_id', $read_only_fields ) && isset( $_POST['membership_id'] ) ) { $order->membership_id = intval( $_POST['membership_id'] ); } if ( ! in_array( 'billing_name', $read_only_fields ) && isset( $_POST['billing_name'] ) ) { $order->billing->name = sanitize_text_field( wp_unslash( $_POST['billing_name'] ) ); } if ( ! in_array( 'billing_street', $read_only_fields ) && isset( $_POST['billing_street'] ) ) { $order->billing->street = sanitize_text_field( wp_unslash( $_POST['billing_street'] ) ); } if ( ! in_array( 'billing_city', $read_only_fields ) && isset( $_POST['billing_city'] ) ) { $order->billing->city = sanitize_text_field( wp_unslash( $_POST['billing_city'] ) ); } if ( ! in_array( 'billing_state', $read_only_fields ) && isset( $_POST['billing_state'] ) ) { $order->billing->state = sanitize_text_field( wp_unslash( $_POST['billing_state'] ) ); } if ( ! in_array( 'billing_zip', $read_only_fields ) && isset( $_POST['billing_zip'] ) ) { $order->billing->zip = sanitize_text_field( $_POST['billing_zip'] ); } if ( ! in_array( 'billing_country', $read_only_fields ) && isset( $_POST['billing_country'] ) ) { $order->billing->country = sanitize_text_field( wp_unslash( $_POST['billing_country'] ) ); } if ( ! in_array( 'billing_phone', $read_only_fields ) && isset( $_POST['billing_phone'] ) ) { $order->billing->phone = sanitize_text_field( $_POST['billing_phone'] ); } if ( ! in_array( 'subtotal', $read_only_fields ) && isset( $_POST['subtotal'] ) ) { $order->subtotal = sanitize_text_field( $_POST['subtotal'] ); } if ( ! in_array( 'tax', $read_only_fields ) && isset( $_POST['tax'] ) ) { $order->tax = sanitize_text_field( $_POST['tax'] ); } if ( ! in_array( 'total', $read_only_fields ) && isset( $_POST['total'] ) ) { $order->total = sanitize_text_field( $_POST['total'] ); } if ( ! in_array( 'payment_type', $read_only_fields ) && isset( $_POST['payment_type'] ) ) { $order->payment_type = sanitize_text_field( $_POST['payment_type'] ); } if ( ! in_array( 'cardtype', $read_only_fields ) && isset( $_POST['cardtype'] ) ) { $order->cardtype = sanitize_text_field( $_POST['cardtype'] ); } if ( ! in_array( 'accountnumber', $read_only_fields ) && isset( $_POST['accountnumber'] ) ) { $order->accountnumber = sanitize_text_field( $_POST['accountnumber'] ); } if ( ! in_array( 'expirationmonth', $read_only_fields ) && isset( $_POST['expirationmonth'] ) ) { $order->expirationmonth = sanitize_text_field( $_POST['expirationmonth'] ); } if ( ! in_array( 'expirationyear', $read_only_fields ) && isset( $_POST['expirationyear'] ) ) { $order->expirationyear = sanitize_text_field( $_POST['expirationyear'] ); } if ( ! in_array( 'status', $read_only_fields ) && isset( $_POST['status'] ) ) { $order->status = pmpro_sanitize_with_safelist( $_POST['status'], pmpro_getOrderStatuses() ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized } if ( ! in_array( 'gateway', $read_only_fields ) && isset( $_POST['gateway'] ) ) { $order->gateway = sanitize_text_field( $_POST['gateway'] ); } if ( ! in_array( 'gateway_environment', $read_only_fields ) && isset( $_POST['gateway_environment'] ) ) { $order->gateway_environment = sanitize_text_field( $_POST['gateway_environment'] ); } if ( ! in_array( 'payment_transaction_id', $read_only_fields ) && isset( $_POST['payment_transaction_id'] ) ) { $order->payment_transaction_id = sanitize_text_field( $_POST['payment_transaction_id'] ); } if ( ! in_array( 'subscription_transaction_id', $read_only_fields ) && isset( $_POST['subscription_transaction_id'] ) ) { $order->subscription_transaction_id = sanitize_text_field( $_POST['subscription_transaction_id'] ); } if ( ! in_array( 'notes', $read_only_fields ) && isset( $_POST['notes'] ) ) { global $allowedposttags; $order->notes = wp_kses( wp_unslash( $_REQUEST['notes'] ), $allowedposttags ); } if ( ! in_array( 'timestamp', $read_only_fields ) && isset( $_POST['ts_year'] ) && isset( $_POST['ts_month'] ) && isset( $_POST['ts_day'] ) && isset( $_POST['ts_hour'] ) && isset( $_POST['ts_minute'] ) ) { $year = intval( $_POST['ts_year'] ); $month = intval( $_POST['ts_month'] ); $day = intval( $_POST['ts_day'] ); $hour = intval( $_POST['ts_hour'] ); $minute = intval( $_POST['ts_minute'] ); $date = get_gmt_from_date( $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':00' , 'U' ); $order->timestamp = $date; // Passed 'U' to get_gmt_from_date() so that we get a Unix timestamp. } // affiliate stuff $affiliates = apply_filters( 'pmpro_orders_show_affiliate_ids', false ); if ( ! empty( $affiliates ) ) { if ( ! in_array( 'affiliate_id', $read_only_fields ) ) { $order->affiliate_id = sanitize_text_field( $_POST['affiliate_id'] ); } if ( ! in_array( 'affiliate_subid', $read_only_fields ) ) { $order->affiliate_subid = sanitize_text_field( $_POST['affiliate_subid'] ); } } // check nonce for saving $nonceokay = true; if ( empty( $_REQUEST['pmpro_orders_nonce'] ) || ! check_admin_referer( 'save', 'pmpro_orders_nonce' ) ) { $nonceokay = false; } // save if ( $nonceokay && false !== $order->saveOrder() ) { $order_id = $order->id; $pmpro_msg = __( 'Order saved successfully.', 'paid-memberships-pro' ); $pmpro_msgt = 'success'; } else { $pmpro_msg = __( 'Error saving order.', 'paid-memberships-pro' ); $pmpro_msgt = 'error'; } // also update the discount code if needed if( isset( $_REQUEST['discount_code_id'] ) ) { $order->updateDiscountCode( intval( $_REQUEST['discount_code_id'] ) ); } } else { // order passed? // Checking orderby as order could be the order ID or whether the List Table should be sorted ascending or descending. if ( ! empty( $_REQUEST['order'] ) && ! isset( $_REQUEST['orderby'] ) ) { $order_id = intval( $_REQUEST['order'] ); if ( $order_id > 0 ) { $order = new MemberOrder( $order_id ); } elseif ( ! empty( $_REQUEST['copy'] ) ) { $order = new MemberOrder( intval( $_REQUEST['copy'] ) ); // new id $order->id = null; // new code $order->code = $order->getRandomCode(); } else { $order = new MemberOrder(); // new order // defaults $order->code = $order->getRandomCode(); $order->user_id = ''; $order->membership_id = ''; $order->billing = new stdClass(); $order->billing->name = ''; $order->billing->street = ''; $order->billing->city = ''; $order->billing->state = ''; $order->billing->zip = ''; $order->billing->country = ''; $order->billing->phone = ''; $order->discount_code = ''; $order->subtotal = ''; $order->tax = ''; $order->total = ''; $order->payment_type = ''; $order->cardtype = ''; $order->accountnumber = ''; $order->expirationmonth = ''; $order->expirationyear = ''; $order->status = 'success'; $order->gateway = get_option( 'pmpro_gateway' ); $order->gateway_environment = get_option( 'pmpro_gateway_environment' ); $order->payment_transaction_id = ''; $order->subscription_transaction_id = ''; $order->affiliate_id = ''; $order->affiliate_subid = ''; $order->notes = ''; } } } require_once( dirname( __FILE__ ) . '/admin_header.php' ); ?>