コード例 #1
0
/**
 * Saves an edited discount
 *
 * @since 1.0
 * @param array $data Discount code data
 * @return void
 */
function edd_edit_discount($data)
{
    if (isset($data['edd-discount-nonce']) && wp_verify_nonce($data['edd-discount-nonce'], 'edd_discount_nonce')) {
        // Setup the discount code details
        $discount = array();
        foreach ($data as $key => $value) {
            if ($key != 'edd-discount-nonce' && $key != 'edd-action' && $key != 'discount-id' && $key != 'edd-redirect') {
                if (is_string($value) || is_int($value)) {
                    $discount[$key] = strip_tags(addslashes($value));
                } elseif (is_array($value)) {
                    $discount[$key] = array_map('absint', $value);
                }
            }
        }
        $old_discount = edd_get_discount_by('code', $data['code']);
        $discount['uses'] = edd_get_discount_uses($old_discount->ID);
        if (edd_store_discount($discount, $data['discount-id'])) {
            wp_redirect(add_query_arg('edd-message', 'discount_updated', $data['edd-redirect']));
            edd_die();
        } else {
            wp_redirect(add_query_arg('edd-message', 'discount_update_failed', $data['edd-redirect']));
            edd_die();
        }
    }
}
コード例 #2
0
/**
 * Saves an edited receipt
 *
 * @since 1.0
 * @param array $data Receipt data
 * @return void
 */
function edd_ppe_edit_receipt($data)
{
    if (isset($data['edd-receipt-nonce']) && wp_verify_nonce($data['edd-receipt-nonce'], 'edd_receipt_nonce')) {
        // Setup the receipt details
        $receipt = array();
        foreach ($data as $key => $value) {
            if ($key != 'edd-receipt-nonce' && $key != 'edd-action' && $key != 'receipt-id' && $key != 'edd-receipt') {
                if ('email' == $key) {
                    $receipt[$key] = $value;
                } elseif (is_string($value) || is_int($value)) {
                    $receipt[$key] = strip_tags(addslashes($value));
                } elseif (is_array($value)) {
                    $receipt[$key] = array_map('absint', $value);
                }
            }
        }
        if (edd_ppe_store_receipt($receipt, $data['receipt-id'])) {
            wp_redirect(add_query_arg('edd-message', 'receipt_updated', $data['edd-receipt']));
            edd_die();
        } else {
            wp_redirect(add_query_arg('edd-message', 'receipt_update_failed', $data['edd-receipt']));
            edd_die();
        }
    }
}
コード例 #3
0
/**
 * Check for download price variations
 *
 * @since       2.0
 * @return      void
 */
function edd_cr_check_for_download_price_variations()
{
    if (!current_user_can('edit_products')) {
        die('-1');
    }
    $download_id = absint($_POST['download_id']);
    $key = isset($_POST['key']) ? absint($_POST['key']) : 0;
    $download = get_post($download_id);
    if ('download' != $download->post_type) {
        die('-2');
    }
    if (edd_has_variable_prices($download_id)) {
        $variable_prices = edd_get_variable_prices($download_id);
        if ($variable_prices) {
            $ajax_response = '<select class="edd_price_options_select edd-select edd-select edd_cr_download" name="edd_cr_download[' . $key . '][price_id]">';
            $ajax_response .= '<option value="all">' . esc_html(__('All prices', 'edd-cr')) . '</option>';
            foreach ($variable_prices as $price_id => $price) {
                $ajax_response .= '<option value="' . esc_attr($price_id) . '">' . esc_html($price['name']) . '</option>';
            }
            $ajax_response .= '</select>';
            echo $ajax_response;
        }
    }
    edd_die();
}
コード例 #4
0
ファイル: ajax-functions.php プロジェクト: companyjuice/theme
/**
 * Sharing message
*/
function affwp_share_thanks()
{
    // check nonce
    check_ajax_referer('affwp_ajax_nonce', 'nonce');
    //	EDD()->session->set( 'affwp_shared', true );
    $return = array('msg' => 'valid', 'success_title' => 'Thanks for sharing!');
    echo json_encode($return);
    edd_die();
}
コード例 #5
0
/**
 * Sets up and saves a product update email when added or edited.
 *
 * @since 0.9.3
 * @param array $data email data
 * @return void
 */
function edd_pup_create_email($data)
{
    if (isset($data['edd_pup_nonce']) && wp_verify_nonce($data['edd_pup_nonce'], 'edd_pup_nonce')) {
        $post = edd_pup_sanitize_save($data);
        if (0 != $post) {
            if ($data['edd-action'] == 'add_pup_email') {
                wp_redirect(esc_url_raw(add_query_arg(array('view' => 'edit_pup_email', 'id' => $post, 'edd_pup_notice' => 2))));
            } else {
                wp_redirect(esc_url_raw(add_query_arg('edd_pup_notice', 1)));
            }
            edd_die();
        } else {
            wp_redirect(esc_url_raw(add_query_arg('edd_pup_notice', 3)));
            edd_die();
        }
    }
}
コード例 #6
0
ファイル: actions.php プロジェクト: nguyenthai2010/ngocshop
/**
 * Performs redirect actions
 *
 * @since  	1.0
 * @uses  	edd_wl_is_private_list()
 * @uses 	edd_wl_get_wish_list_uri()
 * @return 	void
 */
function edd_wl_redirects()
{
    // Prevent private lists from being viewed. Also only allows users to access edit slugs with own list ID
    if (edd_wl_is_private_list() || !edd_wl_is_users_list(get_query_var('edit')) && get_query_var('edit')) {
        // Don't redirect if we're on single download page.
        // Extra check to fix compatibility with crowdfunding extension or any other extension that uses an edit query var on the single download page
        if (!is_singular('download')) {
            $redirect = apply_filters('edd_wl_private_redirect', edd_wl_get_wish_list_uri());
            wp_redirect($redirect);
            edd_die();
        }
    }
    // redirect if edit or view page is accessed but edit/view query_var does not exist
    if (edd_wl_is_page('view') && !get_query_var('view') || edd_wl_is_page('edit') && !get_query_var('edit')) {
        wp_redirect(edd_wl_get_wish_list_uri());
        edd_die();
    }
}
コード例 #7
0
function edd_wallet_process_incentive()
{
    if ($_REQUEST['gateway'] == 'wallet') {
        EDD()->session->set('wallet_has_incentives', '1');
    } else {
        EDD()->session->set('wallet_has_incentives', null);
    }
    // Refresh the cart
    if (empty($_POST['billing_country'])) {
        $_POST['billing_country'] = edd_get_shop_country();
    }
    ob_start();
    edd_checkout_cart();
    $cart = ob_get_clean();
    $response = array('html' => $cart, 'tax_raw' => edd_get_cart_tax(), 'tax' => html_entity_decode(edd_cart_tax(false), ENT_COMPAT, 'UTF-8'), 'tax_rate_raw' => edd_get_tax_rate(), 'tax_rate' => html_entity_decode(edd_get_formatted_tax_rate(), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_cart_total(false), ENT_COMPAT, 'UTF-8'), 'total_raw' => edd_get_cart_total());
    echo json_encode($response);
    edd_die();
}
コード例 #8
0
/**
 * Process deposit
 *
 * @since       1.0.0
 * @return      void
 */
function edd_wallet_process_deposit()
{
    // Verify the nonce
    if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edd-wallet-deposit-nonce')) {
        wp_die(__('Nonce verification failed', 'edd-wallet'), __('Error', 'edd-wallet'), array('response' => 403));
    }
    // Make sure the cart is empty
    edd_empty_cart();
    $value = $_POST['edd_wallet_deposit_amount'];
    if ($value == 'custom') {
        $value = $_POST['edd_wallet_custom_deposit'];
    }
    // Setup the fee label
    $label = edd_get_option('edd_wallet_deposit_description', __('Deposit to wallet', 'edd-wallet'));
    $label = str_replace('{val}', edd_currency_filter(edd_format_amount($value)), $label);
    // Setup the fee (product) for the deposit
    $fee = array('amount' => $value, 'label' => $label, 'type' => 'item', 'no_tax' => true, 'id' => 'edd-wallet-deposit');
    EDD()->fees->add_fee($fee);
    // Redirect to checkout
    wp_redirect(edd_get_checkout_uri(), 303);
    edd_die();
}
コード例 #9
0
/**
 * Trigger a Purchase Deletion
 *
 * @since 1.3.4
 * @param $data Arguments passed
 * @return void
 */
function edd_trigger_purchase_delete($data)
{
    if (wp_verify_nonce($data['_wpnonce'], 'edd_payment_nonce')) {
        $payment_id = absint($data['purchase_id']);
        if (!current_user_can('edit_shop_payments', $payment_id)) {
            wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
        }
        edd_delete_purchase($payment_id);
        wp_redirect(admin_url('/edit.php?post_type=download&page=edd-payment-history&edd-message=payment_deleted'));
        edd_die();
    }
}
コード例 #10
0
/**
 * Processes a remove discount from cart request
 *
 * @since 1.4.1
 * @return void
 */
function edd_remove_cart_discount()
{
    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
        return;
    }
    do_action('edd_pre_remove_cart_discount', absint($_GET['discount_id']));
    edd_unset_cart_discount(urldecode($_GET['discount_code']));
    do_action('edd_post_remove_cart_discount', absint($_GET['discount_id']));
    wp_redirect(edd_get_checkout_uri());
    edd_die();
}
コード例 #11
0
/**
 * Check for Download Price Variations via AJAX (this function can only be used
 * in WordPress Admin). This function is used for the Edit Payment screen when downloads
 * are added to the purchase. When each download is chosen, an AJAX call is fired
 * to this function which will check if variable prices exist for that download.
 * If they do, it will output a dropdown of all the variable prices available for
 * that download.
 *
 * @author Sunny Ratilal
 * @since 1.5
 * @return void
 */
function edd_check_for_download_price_variations()
{
    if (!current_user_can('edit_products')) {
        die('-1');
    }
    $download_id = intval($_POST['download_id']);
    $download = get_post($download_id);
    if ('download' != $download->post_type) {
        die('-2');
    }
    if (edd_has_variable_prices($download_id)) {
        $variable_prices = edd_get_variable_prices($download_id);
        if ($variable_prices) {
            $ajax_response = '<select class="edd_price_options_select edd-select edd-select" name="edd_price_option">';
            if (isset($_POST['all_prices'])) {
                $ajax_response .= '<option value="">' . __('All Prices', 'easy-digital-downloads') . '</option>';
            }
            foreach ($variable_prices as $key => $price) {
                $ajax_response .= '<option value="' . esc_attr($key) . '">' . esc_html($price['name']) . '</option>';
            }
            $ajax_response .= '</select>';
            echo $ajax_response;
        }
    }
    edd_die();
}
コード例 #12
0
 /**
  * Generates the System Info Download File
  *
  * @since 1.4
  * @return void
  */
 function edd_generate_fes_sysinfo_download()
 {
     nocache_headers();
     header("Content-type: text/plain");
     header('Content-Disposition: attachment; filename="fes-system-info.txt"');
     echo wp_strip_all_tags($_POST['fes-sysinfo']);
     edd_die();
 }
コード例 #13
0
/**
 * Share via email
 *
 * @since 1.0
*/
function edd_wl_share_via_email()
{
    check_ajax_referer('edd_wl_ajax_nonce', 'nonce');
    global $edd_options;
    if (!isset($_POST['post_id'])) {
        return;
    }
    // referrer
    $referrer = $_POST['referrer'] ? $_POST['referrer'] : '';
    // sender details
    $sender_name = isset($_POST['from_name']) ? $_POST['from_name'] : '';
    $sender_email = isset($_POST['from_email']) ? $_POST['from_email'] : '';
    $emails = isset($_POST['emails']) ? $_POST['emails'] : '';
    $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
    $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
    $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
    $message = isset($_POST['message']) ? $_POST['message'] : '';
    // validation
    if (!($sender_name || $sender_email || !edd_wl_validate_share_emails($emails))) {
        $has_error = true;
    }
    if (!isset($has_error)) {
        $shortlink = wp_get_shortlink($post_id);
        // shortlink
        $subject = edd_wl_share_via_email_subject($sender_name, $referrer);
        $message = edd_wl_share_via_email_message($shortlink, $sender_name, $sender_email, $message, $referrer);
        $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
        $headers .= "Reply-To: " . $sender_email . "\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        $headers = apply_filters('edd_wl_share_via_email_headers', $headers);
        // send email
        wp_mail($emails, $subject, $message, $headers);
    }
    $return['success'] = edd_wl_modal_share_via_email_success();
    echo json_encode($return);
    edd_die();
}
コード例 #14
0
 /**
  * Grabs the submitted front end tickets form and adds the products to the cart.
  */
 public function process_front_end_tickets_form()
 {
     // We're only interested in EDD Tickets submissions
     if (!isset($_GET['eddtickets_process']) || empty($_POST['product_id'])) {
         return;
     }
     // Add each ticket product to the cart
     foreach ((array) $_POST['product_id'] as $product_id) {
         $quantity = isset($_POST['quantity_' . $product_id]) ? (int) $_POST['quantity_' . $product_id] : 0;
         if ($quantity > 0) {
             $this->add_ticket_to_cart($product_id, $quantity);
         }
     }
     // To minimize accidental re-submissions, redirect back to self
     wp_redirect(edd_get_checkout_uri());
     edd_die();
 }
コード例 #15
0
 /**
  * Output Query in either JSON/XML. The query data is outputted as JSON
  * by default
  *
  * @author Daniel J Griffiths
  * @since 1.5
  * @global $wp_query
  *
  * @param int $status_code
  */
 public function output($status_code = 200)
 {
     global $wp_query;
     $format = $this->get_output_format();
     status_header($status_code);
     do_action('edd_api_output_before', $this->data, $this, $format);
     switch ($format) {
         case 'xml':
             require_once EDD_PLUGIN_DIR . 'includes/libraries/array2xml.php';
             $xml = Array2XML::createXML('edd', $this->data);
             echo $xml->saveXML();
             break;
         case 'json':
             header('Content-Type: application/json');
             if (!empty($this->pretty_print)) {
                 echo json_encode($this->data, $this->pretty_print);
             } else {
                 echo json_encode($this->data);
             }
             break;
         default:
             // Allow other formats to be added via extensions
             do_action('edd_api_output_' . $format, $this->data, $this);
             break;
     }
     do_action('edd_api_output_after', $this->data, $this, $format);
     edd_die();
 }
コード例 #16
0
function wppb_check_edd_login_form($auth_cookie, $expire, $expiration, $user_id, $scheme)
{
    $wppb_generalSettings = get_option('wppb_general_settings', 'not_found');
    if ($wppb_generalSettings != 'not_found') {
        if (!empty($wppb_generalSettings['adminApproval']) && $wppb_generalSettings['adminApproval'] == 'yes') {
            if (isset($_REQUEST['edd_login_nonce'])) {
                if (wp_get_object_terms($user_id, 'user_status')) {
                    if (isset($_REQUEST['edd_redirect'])) {
                        wp_redirect($_REQUEST['edd_redirect']);
                        edd_set_error('user_unapproved', __('Your account has to be confirmed by an administrator before you can log in.', 'profile-builder'));
                        edd_get_errors();
                        edd_die();
                    }
                }
            }
        }
    }
}
コード例 #17
0
/**
 * Process Download
 *
 * Handles the file download process.
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function edd_process_download()
{
    if (!isset($_GET['download_id']) && isset($_GET['download'])) {
        $_GET['download_id'] = $_GET['download'];
    }
    $args = apply_filters('edd_process_download_args', array('download' => isset($_GET['download_id']) ? (int) $_GET['download_id'] : '', 'email' => isset($_GET['email']) ? rawurldecode($_GET['email']) : '', 'expire' => isset($_GET['expire']) ? rawurldecode($_GET['expire']) : '', 'file_key' => isset($_GET['file']) ? (int) $_GET['file'] : '', 'price_id' => isset($_GET['price_id']) ? (int) $_GET['price_id'] : false, 'key' => isset($_GET['download_key']) ? $_GET['download_key'] : '', 'eddfile' => isset($_GET['eddfile']) ? $_GET['eddfile'] : '', 'ttl' => isset($_GET['ttl']) ? $_GET['ttl'] : '', 'token' => isset($_GET['token']) ? $_GET['token'] : ''));
    if (!empty($args['eddfile']) && !empty($args['ttl']) && !empty($args['token'])) {
        // Validate a signed URL that edd_process_signed_download_urlcontains a token
        $args = edd_process_signed_download_url($args);
        // Backfill some legacy super globals for backwards compatibility
        $_GET['download_id'] = $args['download'];
        $_GET['email'] = $args['email'];
        $_GET['expire'] = $args['expire'];
        $_GET['download_key'] = $args['key'];
        $_GET['price_id'] = $args['price_id'];
    } elseif (!empty($args['download']) && !empty($args['key']) && !empty($args['email']) && !empty($args['expire']) && isset($args['file_key'])) {
        // Validate a legacy URL without a token
        $args = edd_process_legacy_download_url($args);
    } else {
        return;
    }
    $args['has_access'] = apply_filters('edd_file_download_has_access', $args['has_access'], $args['payment'], $args);
    //$args['has_access'] = ( edd_logged_in_only() && is_user_logged_in() ) || !edd_logged_in_only() ? true : false;
    if ($args['payment'] && $args['has_access']) {
        do_action('edd_process_verified_download', $args['download'], $args['email'], $args['payment'], $args);
        // Determine the download method set in settings
        $method = edd_get_file_download_method();
        // Payment has been verified, setup the download
        $download_files = edd_get_download_files($args['download']);
        $attachment_id = !empty($download_files[$args['file_key']]['attachment_id']) ? absint($download_files[$args['file_key']]['attachment_id']) : false;
        /*
         * If we have an attachment ID stored, use get_attached_file() to retrieve absolute URL
         * If this fails or returns a relative path, we fail back to our own absolute URL detection
         */
        if ($attachment_id && 'attachment' == get_post_type($attachment_id)) {
            if ('redirect' == $method) {
                $attached_file = wp_get_attachment_url($attachment_id);
            } else {
                $attached_file = get_attached_file($attachment_id, false);
                // Confirm the file exists
                if (!file_exists($attached_file)) {
                    $attached_file = false;
                }
            }
            if ($attached_file) {
                $requested_file = $attached_file;
            }
        }
        // If we didn't find a file from the attachment, grab the given URL
        if (!isset($requested_file)) {
            $requested_file = isset($download_files[$args['file_key']]['file']) ? $download_files[$args['file_key']]['file'] : '';
        }
        // Allow the file to be altered before any headers are sent
        $requested_file = apply_filters('edd_requested_file', $requested_file, $download_files, $args['file_key']);
        if ('x_sendfile' == $method && (!function_exists('apache_get_modules') || !in_array('mod_xsendfile', apache_get_modules()))) {
            // If X-Sendfile is selected but is not supported, fallback to Direct
            $method = 'direct';
        }
        $file_details = parse_url($requested_file);
        $schemes = array('http', 'https');
        // Direct URL schemes
        if ((!isset($file_details['scheme']) || !in_array($file_details['scheme'], $schemes)) && isset($file_details['path']) && file_exists($requested_file)) {
            /**
             * Download method is seto to Redirect in settings but an absolute path was provided
             * We need to switch to a direct download in order for the file to download properly
             */
            $method = 'direct';
        }
        /**
         * Allow extensions to run actions prior to recording the file download log entry
         *
         * @since 2.6.14
         */
        do_action('edd_process_download_pre_record_log', $requested_file, $args, $method);
        // Record this file download in the log
        $user_info = array();
        $user_info['email'] = $args['email'];
        if (is_user_logged_in()) {
            $user_data = get_userdata(get_current_user_id());
            $user_info['id'] = get_current_user_id();
            $user_info['name'] = $user_data->display_name;
        }
        edd_record_download_in_log($args['download'], $args['file_key'], $user_info, edd_get_ip(), $args['payment'], $args['price_id']);
        $file_extension = edd_get_file_extension($requested_file);
        $ctype = edd_get_file_ctype($file_extension);
        if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
            @set_time_limit(0);
        }
        if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime() && version_compare(phpversion(), '5.4', '<')) {
            set_magic_quotes_runtime(0);
        }
        @session_write_close();
        if (function_exists('apache_setenv')) {
            @apache_setenv('no-gzip', 1);
        }
        @ini_set('zlib.output_compression', 'Off');
        do_action('edd_process_download_headers', $requested_file, $args['download'], $args['email'], $args['payment']);
        nocache_headers();
        header("Robots: none");
        header("Content-Type: " . $ctype . "");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=\"" . apply_filters('edd_requested_file_name', basename($requested_file)) . "\"");
        header("Content-Transfer-Encoding: binary");
        // If the file isn't locally hosted, process the redirect
        if (filter_var($requested_file, FILTER_VALIDATE_URL) && !edd_is_local_file($requested_file)) {
            edd_deliver_download($requested_file, true);
            exit;
        }
        switch ($method) {
            case 'redirect':
                // Redirect straight to the file
                edd_deliver_download($requested_file, true);
                break;
            case 'direct':
            default:
                $direct = false;
                $file_path = $requested_file;
                if ((!isset($file_details['scheme']) || !in_array($file_details['scheme'], $schemes)) && isset($file_details['path']) && file_exists($requested_file)) {
                    /** This is an absolute path */
                    $direct = true;
                    $file_path = $requested_file;
                } else {
                    if (defined('UPLOADS') && strpos($requested_file, UPLOADS) !== false) {
                        /**
                         * This is a local file given by URL so we need to figure out the path
                         * UPLOADS is always relative to ABSPATH
                         * site_url() is the URL to where WordPress is installed
                         */
                        $file_path = str_replace(site_url(), '', $requested_file);
                        $file_path = realpath(ABSPATH . $file_path);
                        $direct = true;
                    } else {
                        if (strpos($requested_file, content_url()) !== false) {
                            /** This is a local file given by URL so we need to figure out the path */
                            $file_path = str_replace(content_url(), WP_CONTENT_DIR, $requested_file);
                            $file_path = realpath($file_path);
                            $direct = true;
                        } else {
                            if (strpos($requested_file, set_url_scheme(content_url(), 'https')) !== false) {
                                /** This is a local file given by an HTTPS URL so we need to figure out the path */
                                $file_path = str_replace(set_url_scheme(content_url(), 'https'), WP_CONTENT_DIR, $requested_file);
                                $file_path = realpath($file_path);
                                $direct = true;
                            }
                        }
                    }
                }
                // Set the file size header
                header("Content-Length: " . @filesize($file_path));
                // Now deliver the file based on the kind of software the server is running / has enabled
                if (stristr(getenv('SERVER_SOFTWARE'), 'lighttpd')) {
                    header("X-LIGHTTPD-send-file: {$file_path}");
                } elseif ($direct && (stristr(getenv('SERVER_SOFTWARE'), 'nginx') || stristr(getenv('SERVER_SOFTWARE'), 'cherokee'))) {
                    // We need a path relative to the domain
                    $file_path = str_ireplace(realpath($_SERVER['DOCUMENT_ROOT']), '', $file_path);
                    header("X-Accel-Redirect: /{$file_path}");
                }
                if ($direct) {
                    edd_deliver_download($file_path);
                } else {
                    // The file supplied does not have a discoverable absolute path
                    edd_deliver_download($requested_file, true);
                }
                break;
        }
        edd_die();
    } else {
        $error_message = __('You do not have permission to download this file', 'easy-digital-downloads');
        wp_die(apply_filters('edd_deny_download_message', $error_message, __('Purchase Verification Failed', 'easy-digital-downloads')), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    exit;
}
コード例 #18
0
/**
 * Saves an edited discount
 *
 * @since 1.0
 * @param array $data Discount code data
 * @return void
 */
function edd_edit_discount($data)
{
    if (!isset($data['edd-discount-nonce']) || !wp_verify_nonce($data['edd-discount-nonce'], 'edd_discount_nonce')) {
        return;
    }
    if (!current_user_can('manage_shop_discounts')) {
        wp_die(__('You do not have permission to edit discount codes', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    // Setup the discount code details
    $discount = array();
    foreach ($data as $key => $value) {
        if ($key != 'edd-discount-nonce' && $key != 'edd-action' && $key != 'discount-id' && $key != 'edd-redirect') {
            if (is_string($value) || is_int($value)) {
                $discount[$key] = strip_tags(addslashes($value));
            } elseif (is_array($value)) {
                $discount[$key] = array_map('absint', $value);
            }
        }
    }
    $old_discount = edd_get_discount_by('code', $data['code']);
    $discount['uses'] = edd_get_discount_uses($old_discount->ID);
    if (edd_store_discount($discount, $data['discount-id'])) {
        wp_redirect(add_query_arg('edd-message', 'discount_updated', $data['edd-redirect']));
        edd_die();
    } else {
        wp_redirect(add_query_arg('edd-message', 'discount_update_failed', $data['edd-redirect']));
        edd_die();
    }
}
コード例 #19
0
/**
 * Generates a System Info download file
 *
 * @since       2.0
 * @return      void
 */
function edd_tools_sysinfo_download()
{
    nocache_headers();
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment; filename="edd-system-info.txt"');
    echo wp_strip_all_tags($_POST['edd-sysinfo']);
    edd_die();
}
コード例 #20
0
/**
 * Generates a System Info download file
 *
 * @since       2.0
 * @return      void
 */
function edd_tools_sysinfo_download()
{
    if (!current_user_can('manage_shop_settings')) {
        return;
    }
    nocache_headers();
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment; filename="edd-system-info.txt"');
    echo wp_strip_all_tags($_POST['edd-sysinfo']);
    edd_die();
}
コード例 #21
0
/**
 * Process Profile Updater Form
 *
 * Processes the profile updater form by updating the necessary fields
 *
 * @since 1.4
 * @author Sunny Ratilal
 * @param array $data Data sent from the profile editor
 * @return void
 */
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;
    }
    // Nonce security
    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);
    $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();
    if ($errors) {
        // Send back to the profile editor if there are errors
        wp_redirect($data['edd_redirect']);
        edd_die();
    }
    // Update the user
    $meta = update_user_meta($user_id, '_edd_user_address', $address);
    $updated = wp_update_user($userdata);
    if ($updated) {
        do_action('edd_user_profile_updated', $user_id, $userdata);
        wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect']));
        edd_die();
    }
}
コード例 #22
0
 function checkout_check_for_download_price_variations()
 {
     if (!current_user_can('edit_products')) {
         die('-1');
     }
     $download_id = intval($_POST['download_id']);
     $download = get_post($download_id);
     if ('download' != $download->post_type) {
         die('-2');
     }
     if (edd_has_variable_prices($download_id)) {
         $variable_prices = edd_get_variable_prices($download_id);
         $ajax_response = '<select class="checkout_price_options_select" name="' . esc_attr($this->get_field_name('price_variation')) . '">';
         $ajax_response .= '<option value="none">' . __('None', 'checkout') . '</option>';
         if ($variable_prices) {
             foreach ($variable_prices as $key => $price) {
                 $ajax_response .= '<option value="' . esc_attr($key) . '">' . esc_html($price['name']) . '</option>';
             }
             $ajax_response .= '</select>';
             echo $ajax_response;
         }
     }
     edd_die();
 }
コード例 #23
0
/**
 * Process the Collection Purchase request
 *
 * @since 1.0
 *
 * @param $data
 */
function edd_process_collection_purchase($data)
{
    $taxonomy = urldecode($data['taxonomy']);
    $terms = urldecode($data['terms']);
    $cart_items = edd_add_collection_to_cart($taxonomy, $terms);
    wp_redirect(add_query_arg('added', '1', remove_query_arg(array('edd_action', 'taxonomy', 'terms'))));
    edd_die();
}
コード例 #24
0
/**
 * Grabs all of the selected date info and then redirects appropriately
 *
 * @since 1.3
 *
 * @param $data
 */
function edd_parse_report_dates($data)
{
    $dates = edd_get_report_dates();
    $view = edd_get_reporting_view();
    $id = isset($_GET['download-id']) ? $_GET['download-id'] : null;
    $exclude_taxes = isset($_GET['exclude_taxes']) ? $_GET['exclude_taxes'] : null;
    wp_redirect(add_query_arg($dates, admin_url('edit.php?post_type=download&page=edd-reports&view=' . esc_attr($view) . '&download-id=' . absint($id) . '&exclude_taxes=' . absint($exclude_taxes))));
    edd_die();
}
コード例 #25
0
/**
 * Process Profile Updater Form
 *
 * Processes the profile updater form by updating the necessary fields
 *
 * @since 1.4
 * @author Sunny Ratilal
 * @param array $data Data sent from the profile editor
 * @return void
 */
function edd_process_profile_editor_updates($data)
{
    // Profile field change request
    if (empty($_POST['edd_profile_editor_submit']) && !is_user_logged_in()) {
        return false;
    }
    // Nonce security
    if (!wp_verify_nonce($data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce')) {
        return false;
    }
    $user_id = get_current_user_id();
    $display_name = sanitize_text_field($data['edd_display_name']);
    $first_name = sanitize_text_field($data['edd_first_name']);
    $last_name = sanitize_text_field($data['edd_last_name']);
    $email = sanitize_email($data['edd_email']);
    $userdata = array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email);
    // 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.', 'edd'));
        } else {
            $userdata['user_pass'] = $data['edd_new_user_pass1'];
        }
    }
    // Update the user
    $updated = wp_update_user($userdata);
    if ($updated) {
        do_action('edd_user_profile_updated', $user_id, $userdata);
        wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect']));
        edd_die();
    }
}
コード例 #26
0
/**
 * Process the checkout login form
 *
 * @access      private
 * @since       1.8
 * @return      void
 */
function edd_process_purchase_login()
{
    $is_ajax = isset($_POST['edd_ajax']);
    $user_data = edd_purchase_form_validate_user_login();
    if (edd_get_errors() || $user_data['user_id'] < 1) {
        if ($is_ajax) {
            do_action('edd_ajax_checkout_errors');
            edd_die();
        } else {
            wp_redirect($_SERVER['HTTP_REFERER']);
            exit;
        }
    }
    edd_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']);
    if ($is_ajax) {
        echo 'success';
        edd_die();
    } else {
        wp_redirect(edd_get_checkout_uri($_SERVER['QUERY_STRING']));
    }
}
コード例 #27
0
/**
 * Process Register Form
 *
 * @since 2.0
 * @param array $data Data sent from the register form
 * @return void
*/
function edd_process_register_form($data)
{
    if (is_user_logged_in()) {
        return;
    }
    if (empty($_POST['edd_register_submit'])) {
        return;
    }
    do_action('edd_pre_process_register_form');
    if (empty($data['edd_user_login'])) {
        edd_set_error('empty_username', __('Invalid username', 'edd'));
    }
    if (username_exists($data['edd_user_login'])) {
        edd_set_error('username_unavailable', __('Username already taken', 'edd'));
    }
    if (!validate_username($data['edd_user_login'])) {
        edd_set_error('username_invalid', __('Invalid username', 'edd'));
    }
    if (email_exists($data['edd_user_email'])) {
        edd_set_error('email_unavailable', __('Email address already taken', 'edd'));
    }
    if (empty($data['edd_user_email']) || !is_email($data['edd_user_email'])) {
        edd_set_error('email_invalid', __('Invalid email', 'edd'));
    }
    if (!empty($data['edd_payment_email']) && $data['edd_payment_email'] != $data['edd_user_email'] && !is_email($data['edd_payment_email'])) {
        edd_set_error('payment_email_invalid', __('Invalid payment email', 'edd'));
    }
    if (empty($_POST['edd_user_pass'])) {
        edd_set_error('empty_password', __('Please enter a password', 'edd'));
    }
    if (!empty($_POST['edd_user_pass']) && empty($_POST['edd_user_pass2']) || $_POST['edd_user_pass'] !== $_POST['edd_user_pass2']) {
        edd_set_error('password_mismatch', __('Passwords do not match', 'edd'));
    }
    do_action('edd_process_register_form');
    // Check for errors and redirect if none present
    $errors = edd_get_errors();
    if (empty($errors)) {
        $redirect = apply_filters('edd_register_redirect', $data['edd_redirect']);
        edd_register_and_login_new_user(array('user_login' => $data['edd_user_login'], 'user_pass' => $data['edd_user_pass'], 'user_email' => $data['edd_user_email'], 'user_registered' => date('Y-m-d H:i:s'), 'role' => get_option('default_role')));
        wp_redirect($redirect);
        edd_die();
    }
}
コード例 #28
0
/**
 * Trigger a Purchase Deletion
 *
 * @since 1.3.4
 * @param $data Arguments passed
 * @return void
 */
function edd_trigger_purchase_delete($data)
{
    if (wp_verify_nonce($data['_wpnonce'], 'edd_payment_nonce')) {
        $payment_id = absint($data['purchase_id']);
        edd_delete_purchase($payment_id);
        wp_redirect(admin_url('/edit.php?post_type=download&page=edd-payment-history&edd-message=payment_deleted'));
        edd_die();
    }
}
 /**
  * Perform the export
  *
  * @access public
  * @since 2.5
  * @return void
  */
 public function export()
 {
     // Set headers
     $this->headers();
     edd_die();
 }
コード例 #30
0
/**
 * Check for Download Price Variations via AJAX (this function can only be used
 * in WordPress Admin). This function isused for the Edit Payment screen when downloads
 * are added to the purchase. When each download is chosen, an AJAX call is fired
 * to this function which will check if variable prices exist for that download.
 * If they do, it will output a dropdown of all the variable prices available for
 * that download.
 *
 * @author Sunny Ratilal
 * @since 1.5
 * @return void
 */
function edd_check_for_download_price_variations()
{
    if (!check_ajax_referer('edd_add_downloads_to_purchase_nonce', 'nonce')) {
        return false;
    }
    $download_id = intval($_POST['download_id']);
    if (edd_has_variable_prices($download_id)) {
        $variable_prices = get_post_meta($download_id, 'edd_variable_prices', true);
        if ($variable_prices) {
            $ajax_response = '<select name="downloads[' . intval($_POST['array_key']) . '][options][price_id]" class="edd-variable-prices-select">';
            foreach ($variable_prices as $key => $price) {
                $ajax_response .= '<option value="' . $key . '">' . $price['name'] . '</option>';
            }
            $ajax_response .= '</select>';
        }
        echo $ajax_response;
    }
    edd_die();
}