ID : 0; $atts = shortcode_atts( array( 'id' => $post_id, 'price_id' => isset( $atts['price_id'] ) ? $atts['price_id'] : false, 'sku' => '', 'price' => '1', 'direct' => '0', 'text' => '', 'style' => edd_get_option( 'button_style', 'button' ), 'color' => edd_get_button_color_class(), 'class' => 'edd-submit', 'form_id' => '', ), $atts, 'purchase_link' ); // Override text only if not provided / empty if ( ! $atts['text'] ) { if( $atts['direct'] == '1' || $atts['direct'] == 'true' ) { $atts['text'] = edd_get_option( 'buy_now_text', __( 'Buy Now', 'easy-digital-downloads' ) ); } else { $atts['text'] = edd_get_option( 'add_to_cart_text', __( 'Purchase', 'easy-digital-downloads' ) ); } } if( ! empty( $atts['sku'] ) ) { $download = edd_get_download_by( 'sku', $atts['sku'] ); if ( $download ) { $atts['download_id'] = $download->ID; } } elseif( isset( $atts['id'] ) ) { // Edd_get_purchase_link() expects the ID to be download_id since v1.3 $atts['download_id'] = $atts['id']; $download = edd_get_download( $atts['download_id'] ); } if ( $download ) { return edd_get_purchase_link( $atts ); } } add_shortcode( 'purchase_link', 'edd_download_shortcode' ); /** * Download History Shortcode * * Displays a user's download history. * * @since 1.0 * @return string */ function edd_download_history() { if ( is_user_logged_in() ) { ob_start(); if( ! edd_user_pending_verification() ) { edd_get_template_part( 'history', 'downloads' ); } else { edd_get_template_part( 'account', 'pending' ); } return ob_get_clean(); } } add_shortcode( 'download_history', 'edd_download_history' ); /** * Purchase History Shortcode * * Displays a user's purchase history. * * @since 1.0 * @return string */ function edd_purchase_history() { ob_start(); if( ! edd_user_pending_verification() ) { edd_get_template_part( 'history', 'purchases' ); } else { edd_get_template_part( 'account', 'pending' ); } return ob_get_clean(); } add_shortcode( 'purchase_history', 'edd_purchase_history' ); /** * Checkout Form Shortcode * * Show the checkout form. * * @since 1.0 * @param array $atts Shortcode attributes * @param string $content * @return string */ function edd_checkout_form_shortcode( $atts, $content = null ) { return edd_checkout_form(); } add_shortcode( 'download_checkout', 'edd_checkout_form_shortcode' ); /** * Download Cart Shortcode * * Show the shopping cart. * * @since 1.0 * @param array $atts Shortcode attributes * @param string $content * @return string */ function edd_cart_shortcode( $atts, $content = null ) { return edd_shopping_cart(); } add_shortcode( 'download_cart', 'edd_cart_shortcode' ); /** * Login Shortcode * * Shows a login form allowing users to users to log in. This function simply * calls the edd_login_form function to display the login form. * * @since 1.0 * @param array $atts Shortcode attributes * @param string $content * @uses edd_login_form() * @return string */ function edd_login_form_shortcode( $atts, $content = null ) { $redirect = ''; extract( shortcode_atts( array( 'redirect' => $redirect ), $atts, 'edd_login' ) ); if ( empty( $redirect ) ) { $login_redirect_page = edd_get_option( 'login_redirect_page', '' ); if ( ! empty( $login_redirect_page ) ) { $redirect = get_permalink( $login_redirect_page ); } } if ( empty( $redirect ) ) { $purchase_history = edd_get_option( 'purchase_history_page', 0 ); if ( ! empty( $purchase_history ) ) { $redirect = get_permalink( $purchase_history ); } } if ( empty( $redirect ) ) { $redirect = home_url(); } return edd_login_form( $redirect ); } add_shortcode( 'edd_login', 'edd_login_form_shortcode' ); /** * Register Shortcode * * Shows a registration form allowing users to users to register for the site * * @since 2.0 * @param array $atts Shortcode attributes * @param string $content * @uses edd_register_form() * @return string */ function edd_register_form_shortcode( $atts, $content = null ) { $redirect = home_url(); $purchase_history = edd_get_option( 'purchase_history_page', 0 ); if ( ! empty( $purchase_history ) ) { $redirect = get_permalink( $purchase_history ); } extract( shortcode_atts( array( 'redirect' => $redirect ), $atts, 'edd_register' ) ); return edd_register_form( $redirect ); } add_shortcode( 'edd_register', 'edd_register_form_shortcode' ); /** * Discounts shortcode * * Displays a list of all the active discounts. The active discounts can be configured * from the Discount Codes admin screen. * * @since 1.0.8.2 * @param array $atts Shortcode attributes * @param string $content * @uses edd_get_discounts() * @return string $discounts_lists List of all the active discount codes */ function edd_discounts_shortcode( $atts, $content = null ) { $discounts = edd_get_discounts(); $discounts_list = '
' . $edd_receipt_args['error'] . '
'; } $order = edd_get_order_by( 'payment_key', $payment_key ); $user_can_view = edd_can_view_receipt( $payment_key ); // Key was provided, but user is logged out. Offer them the ability to login and view the receipt if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! edd_is_guest_payment( $order->id ) ) { global $edd_login_redirect; $edd_login_redirect = edd_get_receipt_page_uri( $order->id ); ob_start(); echo '' . __( 'You must be logged in to view this payment receipt.', 'easy-digital-downloads' ) . '
'; edd_get_template_part( 'shortcode', 'login' ); $login_form = ob_get_clean(); return $login_form; } $user_can_view = apply_filters( 'edd_user_can_view_receipt', $user_can_view, $edd_receipt_args ); // If this was a guest checkout and the purchase session is empty, output a relevant error message if ( empty( $session ) && ! is_user_logged_in() && ! $user_can_view ) { return '' . apply_filters( 'edd_receipt_guest_error_message', __( 'Receipt could not be retrieved, your purchase session has expired.', 'easy-digital-downloads' ) ) . '
'; } /* * Check if the user has permission to view the receipt * * If user is logged in, user ID is compared to user ID of ID stored in payment meta * * Or if user is logged out and purchase was made as a guest, the purchase session is checked for * * Or if user is logged in and the user can view sensitive shop data */ if ( ! $user_can_view ) { return '' . $edd_receipt_args['error'] . '
'; } ob_start(); edd_get_template_part( 'shortcode', 'receipt' ); $display = ob_get_clean(); return $display; } add_shortcode( 'edd_receipt', 'edd_receipt_shortcode' ); /** * Render the profile editor shortcode. * * @since 1.4 * * @param null $atts Unused parameter. * @param null $content Unused parameter. * * @return string Shortcode template. */ function edd_profile_editor_shortcode( $atts = null, $content = null ) { ob_start(); if ( ! edd_user_pending_verification() ) { edd_get_template_part( 'shortcode', 'profile-editor' ); } else { edd_get_template_part( 'account', 'pending' ); } $display = ob_get_clean(); return $display; } add_shortcode( 'edd_profile_editor', 'edd_profile_editor_shortcode' ); /** * Process profile updates. * * @since 1.4 * @since 3.0 Updated to use new custom tables. * * @param array $data Data sent from the profile editor. * @return bool False on error. */ function edd_process_profile_editor_updates( $data ) { // Profile field change request. if ( empty( $_POST['edd_profile_editor_submit'] ) && ! is_user_logged_in() ) { return false; } // Pending users can't edit their profile. if ( edd_user_pending_verification() ) { return false; } // Verify nonce. if ( ! wp_verify_nonce( $data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce' ) ) { return false; } $user_id = get_current_user_id(); $old_user_data = get_userdata( $user_id ); // Fetch customer record. $customer = edd_get_customer_by( 'user_id', $user_id ); $display_name = isset( $data['edd_display_name'] ) ? sanitize_text_field( $data['edd_display_name'] ) : $old_user_data->display_name; $first_name = isset( $data['edd_first_name'] ) ? sanitize_text_field( $data['edd_first_name'] ) : $old_user_data->first_name; $last_name = isset( $data['edd_last_name'] ) ? sanitize_text_field( $data['edd_last_name'] ) : $old_user_data->last_name; $email = isset( $data['edd_email'] ) ? sanitize_email( $data['edd_email'] ) : $old_user_data->user_email; $line1 = isset( $data['edd_address_line1'] ) ? sanitize_text_field( $data['edd_address_line1'] ) : ''; $line2 = isset( $data['edd_address_line2'] ) ? sanitize_text_field( $data['edd_address_line2'] ) : ''; $city = isset( $data['edd_address_city'] ) ? sanitize_text_field( $data['edd_address_city'] ) : ''; $state = isset( $data['edd_address_state'] ) ? sanitize_text_field( $data['edd_address_state'] ) : ''; $zip = isset( $data['edd_address_zip'] ) ? sanitize_text_field( $data['edd_address_zip'] ) : ''; $country = isset( $data['edd_address_country'] ) ? sanitize_text_field( $data['edd_address_country'] ) : ''; $userdata = array( 'ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email ); $address = array( 'line1' => $line1, 'line2' => $line2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country ); do_action( 'edd_pre_update_user_profile', $user_id, $userdata ); // New password if ( ! empty( $data['edd_new_user_pass1'] ) ) { if ( $data['edd_new_user_pass1'] !== $data['edd_new_user_pass2'] ) { edd_set_error( 'password_mismatch', __( 'The passwords you entered do not match. Please try again.', 'easy-digital-downloads' ) ); } else { $userdata['user_pass'] = $data['edd_new_user_pass1']; } } // Make sure the new email doesn't belong to another user. if ( $email !== $old_user_data->user_email ) { // Make sure the new email is valid. if ( ! is_email( $email ) ) { edd_set_error( 'email_invalid', __( 'The email you entered is invalid. Please enter a valid email.', 'easy-digital-downloads' ) ); } // Make sure the new email doesn't belong to another user. if ( email_exists( $email ) ) { edd_set_error( 'email_exists', __( 'The email you entered belongs to another user. Please use another.', 'easy-digital-downloads' ) ); } } // Check for errors. $errors = edd_get_errors(); // Send back to the profile editor if there are errors. if ( ! empty( $errors ) ) { edd_redirect( $data['edd_redirect'] ); } // Update user. $updated = wp_update_user( $userdata ); // If the current user does not have an associated customer record, create one. if ( ! $customer && $updated ) { $customer_id = edd_add_customer( array( 'user_id' => $updated, 'email' => $email, ) ); $customer = edd_get_customer_by( 'id', $customer_id ); } // Try to update customer data. if ( $customer ) { // Update the primary address. $customer_address_id = edd_get_customer_addresses( array( 'customer_id' => $customer->id, 'type' => 'billing', 'is_primary' => 1, 'number' => 1, 'fields' => 'ids' ) ); // Try updating the address if it exists. if ( ! empty( $customer_address_id ) ) { $customer_address_id = $customer_address_id[0]; edd_update_customer_address( $customer_address_id, array( 'name' => stripslashes( $first_name . ' ' . $last_name ), 'address' => $address['line1'], 'address2' => $address['line2'], 'city' => $address['city'], 'country' => $address['country'], 'region' => $address['state'], 'postal_code' => $address['zip'], 'country' => $address['country'] ) ); // Add a customer address. } else { edd_maybe_add_customer_address( $customer->id, array( 'name' => stripslashes( $first_name . ' ' . $last_name ), 'type' => 'billing', 'address' => $address['line1'], 'address2' => $address['line2'], 'city' => $address['city'], 'country' => $address['country'], 'region' => $address['state'], 'postal_code' => $address['zip'], 'country' => $address['country'], 'is_primary' => true, ) ); } if ( $customer->email === $email || ( is_array( $customer->emails ) && in_array( $email, $customer->emails ) ) ) { $customer->set_primary_email( $email ); } $update_args = array( 'name' => stripslashes( $first_name . ' ' . $last_name ), ); $customer->update( $update_args ); } if ( $updated ) { do_action( 'edd_user_profile_updated', $user_id, $userdata ); edd_redirect( add_query_arg( 'updated', 'true', $data['edd_redirect'] ) ); } } add_action( 'edd_edit_user_profile', 'edd_process_profile_editor_updates' ); /** * Process the 'remove' URL on the profile editor when customers wish to remove an email address * * @since 2.6 * @return void */ function edd_process_profile_editor_remove_email() { if ( ! is_user_logged_in() ) { return false; } // Pending users can't edit their profile if ( edd_user_pending_verification() ) { return false; } // Nonce security if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'edd-remove-customer-email' ) ) { return false; } if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) { return false; } $customer = new EDD_Customer( get_current_user_id(), true ); if ( $customer->remove_email( $_GET['email'] ) ) { $url = add_query_arg( 'updated', true, $_GET['redirect'] ); $user = wp_get_current_user(); $user_login = ! empty( $user->user_login ) ? $user->user_login : edd_get_bot_name(); $customer_note = sprintf( __( 'Email address %s removed by %s', 'easy-digital-downloads' ), sanitize_email( $_GET['email'] ), $user_login ); $customer->add_note( $customer_note ); } else { edd_set_error( 'profile-remove-email-failure', __( 'Error removing email address from profile. Please try again later.', 'easy-digital-downloads' ) ); $url = $_GET['redirect']; } edd_redirect( $url ); } add_action( 'edd_profile-remove-email', 'edd_process_profile_editor_remove_email' );