/**
 * Get Purchase Link
 *
 * Builds a Purchase link for a specified download based on arguments passed.
 * This function is used all over EDD to generate the Purchase or Add to Cart
 * buttons. If no arguments are passed, the function uses the defaults that have
 * been set by the plugin. The Purchase link is built for simple and variable
 * pricing and filters are available throughout the function to override
 * certain elements of the function.
 *
 * $download_id = null, $link_text = null, $style = null, $color = null, $class = null
 *
 * @since 1.0
 * @param array $args Arguments for display
 * @return string $purchase_form
 */
function edd_get_purchase_link($args = array())
{
    global $edd_options, $post;
    if (!isset($edd_options['purchase_page']) || $edd_options['purchase_page'] == 0) {
        edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'edd'), admin_url('edit.php?post_type=download&page=edd-settings')));
        edd_print_errors();
        return false;
    }
    $post_id = is_object($post) ? $post->ID : 0;
    $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'direct' => edd_get_download_button_behavior($post_id) == 'direct' ? true : false, 'text' => !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'), 'style' => isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button', 'color' => isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue', 'class' => 'edd-submit'));
    $args = wp_parse_args($args, $defaults);
    if ('publish' != get_post_field('post_status', $args['download_id']) && !current_user_can('edit_product', $args['download_id'])) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    // Override color if color == inherit
    $args['color'] = $args['color'] == 'inherit' ? '' : $args['color'];
    $variable_pricing = edd_has_variable_prices($args['download_id']);
    $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"';
    $type = edd_single_price_option_mode($args['download_id']) ? 'data-price-mode=multi' : 'data-price-mode=single';
    if ($args['price'] && $args['price'] !== 'no' && !$variable_pricing) {
        $price = edd_get_download_price($args['download_id']);
        $button_text = !empty($args['text']) ? '&nbsp;&ndash;&nbsp;' . $args['text'] : '';
        if (0 == $price) {
            $args['text'] = __('Free', 'edd') . $button_text;
        } else {
            $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text;
        }
    }
    if (edd_item_in_cart($args['download_id']) && !$variable_pricing) {
        $button_display = 'style="display:none;"';
        $checkout_display = '';
    } else {
        $button_display = '';
        $checkout_display = 'style="display:none;"';
    }
    global $edd_displayed_form_ids;
    $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $args['download_id'];
    $args = apply_filters('edd_purchase_link_args', $args);
    ob_start();
    ?>
	<form id="<?php 
    echo $form_id;
    ?>
" class="edd_download_purchase_form" method="post">

		<?php 
    do_action('edd_purchase_link_top', $args['download_id'], $args);
    ?>

		<div class="edd_purchase_submit_wrapper">
			<?php 
    $class = implode(' ', array($args['style'], $args['color'], trim($args['class'])));
    if (!edd_is_ajax_disabled()) {
        echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($args['download_id']) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>';
    }
    echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($args['download_id']) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>';
    echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'edd') . '</a>';
    ?>

			<?php 
    if (!edd_is_ajax_disabled()) {
        ?>
				<span class="edd-cart-ajax-alert">
					<span class="edd-cart-added-alert" style="display: none;">
						<?php 
        printf(__('<i class="edd-icon-ok"></i> Added to cart', 'edd'), '<a href="' . esc_url(edd_get_checkout_uri()) . '" title="' . __('Go to Checkout', 'edd') . '">', '</a>');
        ?>
					</span>
				</span>
			<?php 
    }
    ?>
			<?php 
    if (edd_display_tax_rate() && edd_prices_include_tax()) {
        echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s&#37; tax', 'edd'), edd_get_tax_rate() * 100) . '</span>';
    } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) {
        echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s&#37; tax', 'edd'), edd_get_tax_rate() * 100) . '</span>';
    }
    ?>
		</div><!--end .edd_purchase_submit_wrapper-->

		<input type="hidden" name="download_id" value="<?php 
    echo esc_attr($args['download_id']);
    ?>
">
		<?php 
    if (!empty($args['direct'])) {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway">
		<?php 
    } else {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart">
		<?php 
    }
    ?>

		<?php 
    do_action('edd_purchase_link_end', $args['download_id'], $args);
    ?>

	</form><!--end #<?php 
    echo esc_attr($form_id);
    ?>
-->
<?php 
    $purchase_form = ob_get_clean();
    return apply_filters('edd_purchase_download_form', $purchase_form, $args);
}
 /**
  * Get EDD details
  *
  * ## OPTIONS
  *
  * None. Returns basic info regarding your EDD instance.
  *
  * ## EXAMPLES
  *
  * wp edd details
  *
  * @access		public
  * @param		array $args
  * @param		array $assoc_args
  * @return		void
  */
 public function details($args, $assoc_args)
 {
     $symlink_file_downloads = edd_get_option('symlink_file_downloads', false);
     $purchase_page = edd_get_option('purchase_page', '');
     $success_page = edd_get_option('success_page', '');
     $failure_page = edd_get_option('failure_page', '');
     WP_CLI::line(sprintf(__('You are running EDD version: %s', 'easy-digital-downloads'), EDD_VERSION));
     WP_CLI::line("\n" . sprintf(__('Test mode is: %s', 'easy-digital-downloads'), edd_is_test_mode() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Ajax is: %s', 'easy-digital-downloads'), edd_is_ajax_enabled() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Guest checkouts are: %s', 'easy-digital-downloads'), edd_no_guest_checkout() ? __('Disabled', 'easy-digital-downloads') : __('Enabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Symlinks are: %s', 'easy-digital-downloads'), apply_filters('edd_symlink_file_downloads', isset($symlink_file_downloads)) && function_exists('symlink') ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line("\n" . sprintf(__('Checkout page is: %s', 'easy-digital-downloads'), !edd_get_option('purchase_page', false) ? __('Valid', 'easy-digital-downloads') : __('Invalid', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Checkout URL is: %s', 'easy-digital-downloads'), !empty($purchase_page) ? get_permalink($purchase_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Success URL is: %s', 'easy-digital-downloads'), !empty($success_page) ? get_permalink($success_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Failure URL is: %s', 'easy-digital-downloads'), !empty($failure_page) ? get_permalink($failure_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Downloads slug is: %s', 'easy-digital-downloads'), defined('EDD_SLUG') ? '/' . EDD_SLUG : '/downloads'));
     WP_CLI::line("\n" . sprintf(__('Taxes are: %s', 'easy-digital-downloads'), edd_use_taxes() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Tax rate is: %s', 'easy-digital-downloads'), edd_get_tax_rate() * 100 . '%'));
     $rates = edd_get_tax_rates();
     if (!empty($rates)) {
         foreach ($rates as $rate) {
             WP_CLI::line(sprintf(__('Country: %s, State: %s, Rate: %s', 'easy-digital-downloads'), $rate['country'], $rate['state'], $rate['rate']));
         }
     }
 }
/**
 * Calculate taxed amount
 *
 * @access      public
 * @since       1.3.3
 * @param 		$amount float The original amount to calculate a tax cost
 * @return      float
*/
function edd_calculate_tax($amount)
{
    $rate = edd_get_tax_rate();
    $tax = number_format($amount * $rate, 2);
    // the tax amount
    return apply_filters('edd_taxed_amount', $tax, $rate);
}
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();
}
				<div class="one-seventh small-one-fifth edd_cart_subtotal_amount">
					<?php 
    echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal() - edd_get_cart_discounted_amount())));
    ?>
				</div>
			</div>
		</div>

		<?php 
    if (!edd_prices_show_tax_on_checkout()) {
        ?>
			<div class="row iceberg--small">
				<div class="grid">
					<div class="three-seventh offset-three-seventh small-four-fifth">
						<?php 
        printf(__('VAT (<span class="yst-tax-rate">%s</span>%%)', 'yoastcom'), number_format(edd_get_tax_rate() * 100, 1));
        ?>
					</div>
					<div class="one-seventh small-one-fifth">
						<span class="edd_cart_tax_amount" id="yst_main_tax" data-tax="<?php 
        echo esc_attr(edd_get_cart_tax());
        ?>
">
							<?php 
        echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_tax())));
        ?>
						</span>
					</div>
				</div>
			</div>
		<?php 
/**
 * Get Purchase Link
 *
 * Builds a Purchase link for a specified download based on arguments passed.
 * This function is used all over EDD to generate the Purchase or Add to Cart
 * buttons. If no arguments are passed, the function uses the defaults that have
 * been set by the plugin. The Purchase link is built for simple and variable
 * pricing and filters are available throughout the function to override
 * certain elements of the function.
 *
 * $download_id = null, $link_text = null, $style = null, $color = null, $class = null
 *
 * @since 1.0
 * @param array $args Arguments for display
 * @return string $purchase_form
 */
function edd_get_purchase_link($args = array())
{
    global $post, $edd_displayed_form_ids;
    $purchase_page = edd_get_option('purchase_page', false);
    if (!$purchase_page || $purchase_page == 0) {
        edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'easy-digital-downloads'), admin_url('edit.php?post_type=download&page=edd-settings')));
        edd_print_errors();
        return false;
    }
    $post_id = is_object($post) ? $post->ID : 0;
    $button_behavior = edd_get_download_button_behavior($post_id);
    $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'price_id' => isset($args['price_id']) ? $args['price_id'] : false, 'direct' => $button_behavior == 'direct' ? true : false, 'text' => $button_behavior == 'direct' ? edd_get_option('buy_now_text', __('Buy Now', 'easy-digital-downloads')) : edd_get_option('add_to_cart_text', __('Purchase', 'easy-digital-downloads')), 'style' => edd_get_option('button_style', 'button'), 'color' => edd_get_option('checkout_color', 'blue'), 'class' => 'edd-submit'));
    $args = wp_parse_args($args, $defaults);
    // Override the stright_to_gateway if the shop doesn't support it
    if (!edd_shop_supports_buy_now()) {
        $args['direct'] = false;
    }
    $download = new EDD_Download($args['download_id']);
    if (empty($download->ID)) {
        return false;
    }
    if ('publish' !== $download->post_status && !current_user_can('edit_product', $download->ID)) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    // Override color if color == inherit
    $args['color'] = $args['color'] == 'inherit' ? '' : $args['color'];
    $options = array();
    $variable_pricing = $download->has_variable_prices();
    $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"';
    $type = $download->is_single_price_mode() ? 'data-price-mode=multi' : 'data-price-mode=single';
    $show_price = $args['price'] && $args['price'] !== 'no';
    $data_price_value = 0;
    $price = false;
    if ($variable_pricing && false !== $args['price_id']) {
        $price_id = $args['price_id'];
        $prices = $download->prices;
        $options['price_id'] = $args['price_id'];
        $found_price = isset($prices[$price_id]) ? $prices[$price_id]['amount'] : false;
        $data_price_value = $found_price;
        if ($show_price) {
            $price = $found_price;
        }
    } elseif (!$variable_pricing) {
        $data_price_value = $download->price;
        if ($show_price) {
            $price = $download->price;
        }
    }
    $args['display_price'] = $data_price_value;
    $data_price = 'data-price="' . $data_price_value . '"';
    $button_text = !empty($args['text']) ? '&nbsp;&ndash;&nbsp;' . $args['text'] : '';
    if (false !== $price) {
        if (0 == $price) {
            $args['text'] = __('Free', 'easy-digital-downloads') . $button_text;
        } else {
            $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text;
        }
    }
    if (edd_item_in_cart($download->ID, $options) && (!$variable_pricing || !$download->is_single_price_mode())) {
        $button_display = 'style="display:none;"';
        $checkout_display = '';
    } else {
        $button_display = '';
        $checkout_display = 'style="display:none;"';
    }
    // Collect any form IDs we've displayed already so we can avoid duplicate IDs
    if (isset($edd_displayed_form_ids[$download->ID])) {
        $edd_displayed_form_ids[$download->ID]++;
    } else {
        $edd_displayed_form_ids[$download->ID] = 1;
    }
    $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $download->ID;
    // If we've already generated a form ID for this download ID, apped -#
    if ($edd_displayed_form_ids[$download->ID] > 1) {
        $form_id .= '-' . $edd_displayed_form_ids[$download->ID];
    }
    $args = apply_filters('edd_purchase_link_args', $args);
    ob_start();
    ?>
	<form id="<?php 
    echo $form_id;
    ?>
" class="edd_download_purchase_form edd_purchase_<?php 
    echo absint($download->ID);
    ?>
" method="post">

		<?php 
    do_action('edd_purchase_link_top', $download->ID, $args);
    ?>

		<div class="edd_purchase_submit_wrapper">
			<?php 
    $class = implode(' ', array($args['style'], $args['color'], trim($args['class'])));
    if (!edd_is_ajax_disabled()) {
        echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $data_price . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>';
    }
    echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>';
    echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'easy-digital-downloads') . '</a>';
    ?>

			<?php 
    if (!edd_is_ajax_disabled()) {
        ?>
				<span class="edd-cart-ajax-alert">
					<span class="edd-cart-added-alert" style="display: none;">
						<?php 
        echo '<i class="edd-icon-ok"></i> ' . __('Added to cart', 'easy-digital-downloads');
        ?>
					</span>
				</span>
			<?php 
    }
    ?>
			<?php 
    if (!$download->is_free($args['price_id'])) {
        ?>
				<?php 
        if (edd_display_tax_rate() && edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        }
        ?>
			<?php 
    }
    ?>
		</div><!--end .edd_purchase_submit_wrapper-->

		<input type="hidden" name="download_id" value="<?php 
    echo esc_attr($download->ID);
    ?>
">
		<?php 
    if ($variable_pricing && isset($price_id) && isset($prices[$price_id])) {
        ?>
			<input type="hidden" name="edd_options[price_id][]" id="edd_price_option_<?php 
        echo $download->ID;
        ?>
_1" class="edd_price_option_<?php 
        echo $download->ID;
        ?>
" value="<?php 
        echo $price_id;
        ?>
">
		<?php 
    }
    ?>
		<?php 
    if (!empty($args['direct']) && !$download->is_free($args['price_id'])) {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway">
		<?php 
    } else {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart">
		<?php 
    }
    ?>

		<?php 
    if (apply_filters('edd_download_redirect_to_checkout', edd_straight_to_checkout(), $download->ID, $args)) {
        ?>
			<input type="hidden" name="edd_redirect_to_checkout" id="edd_redirect_to_checkout" value="1">
		<?php 
    }
    ?>

		<?php 
    do_action('edd_purchase_link_end', $download->ID, $args);
    ?>

	</form><!--end #<?php 
    echo esc_attr($form_id);
    ?>
-->
<?php 
    $purchase_form = ob_get_clean();
    return apply_filters('edd_purchase_download_form', $purchase_form, $args);
}
/**
 * Recalculate cart taxes
 *
 * @since 1.6
 * @return void
 */
function edd_ajax_recalculate_taxes()
{
    if (!edd_get_cart_contents()) {
        return false;
    }
    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();
}
/**
 * Calculate the taxed amount
 *
 * @since 1.3.3
 * @param $amount float The original amount to calculate a tax cost
 * @param $country string The country to calculate tax for. Will use default if not passed
 * @param $state string The state to calculate tax for. Will use default if not passed
 * @return float $tax Taxed amount
 */
function edd_calculate_tax($amount = 0, $country = false, $state = false)
{
    global $edd_options;
    $rate = edd_get_tax_rate($country, $state);
    $tax = 0.0;
    if (edd_use_taxes()) {
        if (edd_prices_include_tax()) {
            $pre_tax = $amount / (1 + $rate);
            $tax = $amount - $pre_tax;
        } else {
            $tax = $amount * $rate;
        }
    }
    return apply_filters('edd_taxed_amount', $tax, $rate, $country, $state);
}
/**
 * Calculate the taxed amount
 *
 * @since 1.3.3
 * @param $amount float The original amount to calculate a tax cost
 * @return float $tax Taxed amount
 */
function edd_calculate_tax($amount, $sum = true)
{
    global $edd_options;
    // Not using taxes
    if (!edd_use_taxes()) {
        return $amount;
    }
    $rate = edd_get_tax_rate();
    $tax = 0.0;
    $prices_include_tax = edd_prices_include_tax();
    if ($prices_include_tax) {
        $tax = $amount - $amount / ($rate + 1);
    } else {
        $tax = $amount * $rate;
    }
    if ($sum) {
        if ($prices_include_tax) {
            $tax = $amount - $tax;
        } else {
            $tax = $amount + $tax;
        }
    }
    return apply_filters('edd_taxed_amount', round($tax, 2), $rate);
}
Example #10
0
/**
 * Get system info
 *
 * @since       2.0
 * @access      public
 * @global      object $wpdb Used to query the database using the WordPress Database API
 * @global      array $edd_options Array of all EDD options
 * @return      string $return A string containing the info to output
 */
function edd_tools_sysinfo_get()
{
    global $wpdb, $edd_options;
    if (!class_exists('Browser')) {
        require_once EDD_PLUGIN_DIR . 'includes/libraries/browser.php';
    }
    $browser = new Browser();
    // Get theme info
    if (get_bloginfo('version') < '3.4') {
        $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
        $theme = $theme_data['Name'] . ' ' . $theme_data['Version'];
    } else {
        $theme_data = wp_get_theme();
        $theme = $theme_data->Name . ' ' . $theme_data->Version;
    }
    // Try to identify the hosting provider
    $host = edd_get_host();
    $return = '### Begin System Info ###' . "\n\n";
    // Start with the basics...
    $return .= '-- Site Info' . "\n\n";
    $return .= 'Site URL:                 ' . site_url() . "\n";
    $return .= 'Home URL:                 ' . home_url() . "\n";
    $return .= 'Multisite:                ' . (is_multisite() ? 'Yes' : 'No') . "\n";
    $return = apply_filters('edd_sysinfo_after_site_info', $return);
    // Can we determine the site's host?
    if ($host) {
        $return .= "\n" . '-- Hosting Provider' . "\n\n";
        $return .= 'Host:                     ' . $host . "\n";
        $return = apply_filters('edd_sysinfo_after_host_info', $return);
    }
    // The local users' browser information, handled by the Browser class
    $return .= "\n" . '-- User Browser' . "\n\n";
    $return .= $browser;
    $return = apply_filters('edd_sysinfo_after_user_browser', $return);
    // WordPress configuration
    $return .= "\n" . '-- WordPress Configuration' . "\n\n";
    $return .= 'Version:                  ' . get_bloginfo('version') . "\n";
    $return .= 'Language:                 ' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US') . "\n";
    $return .= 'Permalink Structure:      ' . (get_option('permalink_structure') ? get_option('permalink_structure') : 'Default') . "\n";
    $return .= 'Active Theme:             ' . $theme . "\n";
    $return .= 'Show On Front:            ' . get_option('show_on_front') . "\n";
    // Only show page specs if frontpage is set to 'page'
    if (get_option('show_on_front') == 'page') {
        $front_page_id = get_option('page_on_front');
        $blog_page_id = get_option('page_for_posts');
        $return .= 'Page On Front:            ' . ($front_page_id != 0 ? get_the_title($front_page_id) . ' (#' . $front_page_id . ')' : 'Unset') . "\n";
        $return .= 'Page For Posts:           ' . ($blog_page_id != 0 ? get_the_title($blog_page_id) . ' (#' . $blog_page_id . ')' : 'Unset') . "\n";
    }
    // Make sure wp_remote_post() is working
    $request['cmd'] = '_notify-validate';
    $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'EDD/' . EDD_VERSION, 'body' => $request);
    $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params);
    if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
        $WP_REMOTE_POST = 'wp_remote_post() works';
    } else {
        $WP_REMOTE_POST = 'wp_remote_post() does not work';
    }
    $return .= 'Remote Post:              ' . $WP_REMOTE_POST . "\n";
    $return .= 'Table Prefix:             ' . 'Length: ' . strlen($wpdb->prefix) . '   Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable') . "\n";
    $return .= 'WP_DEBUG:                 ' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set') . "\n";
    $return .= 'Memory Limit:             ' . WP_MEMORY_LIMIT . "\n";
    $return .= 'Registered Post Stati:    ' . implode(', ', get_post_stati()) . "\n";
    $return = apply_filters('edd_sysinfo_after_wordpress_config', $return);
    // EDD configuration
    $return .= "\n" . '-- EDD Configuration' . "\n\n";
    $return .= 'Version:                  ' . EDD_VERSION . "\n";
    $return .= 'Upgraded From:            ' . get_option('edd_version_upgraded_from', 'None') . "\n";
    $return .= 'Test Mode:                ' . (edd_is_test_mode() ? "Enabled\n" : "Disabled\n");
    $return .= 'Ajax:                     ' . (!edd_is_ajax_disabled() ? "Enabled\n" : "Disabled\n");
    $return .= 'Guest Checkout:           ' . (edd_no_guest_checkout() ? "Disabled\n" : "Enabled\n");
    $return .= 'Symlinks:                 ' . (apply_filters('edd_symlink_file_downloads', isset($edd_options['symlink_file_downloads'])) && function_exists('symlink') ? "Enabled\n" : "Disabled\n");
    $return .= 'Download Method:          ' . ucfirst(edd_get_file_download_method()) . "\n";
    $return .= 'Currency Code:            ' . edd_get_currency() . "\n";
    $return .= 'Currency Position:        ' . edd_get_option('currency_position', 'before') . "\n";
    $return .= 'Decimal Separator:        ' . edd_get_option('decimal_separator', '.') . "\n";
    $return .= 'Thousands Separator:      ' . edd_get_option('thousands_separator', ',') . "\n";
    $return = apply_filters('edd_sysinfo_after_edd_config', $return);
    // EDD pages
    $return .= "\n" . '-- EDD Page Configuration' . "\n\n";
    $return .= 'Checkout:                 ' . (!empty($edd_options['purchase_page']) ? "Valid\n" : "Invalid\n");
    $return .= 'Checkout Page:            ' . (!empty($edd_options['purchase_page']) ? get_permalink($edd_options['purchase_page']) . "\n" : "Unset\n");
    $return .= 'Success Page:             ' . (!empty($edd_options['success_page']) ? get_permalink($edd_options['success_page']) . "\n" : "Unset\n");
    $return .= 'Failure Page:             ' . (!empty($edd_options['failure_page']) ? get_permalink($edd_options['failure_page']) . "\n" : "Unset\n");
    $return .= 'Downloads Slug:           ' . (defined('EDD_SLUG') ? '/' . EDD_SLUG . "\n" : "/downloads\n");
    $return = apply_filters('edd_sysinfo_after_edd_pages', $return);
    // EDD gateways
    $return .= "\n" . '-- EDD Gateway Configuration' . "\n\n";
    $active_gateways = edd_get_enabled_payment_gateways();
    if ($active_gateways) {
        $default_gateway_is_active = edd_is_gateway_active(edd_get_default_gateway());
        if ($default_gateway_is_active) {
            $default_gateway = edd_get_default_gateway();
            $default_gateway = $active_gateways[$default_gateway]['admin_label'];
        } else {
            $default_gateway = 'Test Payment';
        }
        $gateways = array();
        foreach ($active_gateways as $gateway) {
            $gateways[] = $gateway['admin_label'];
        }
        $return .= 'Enabled Gateways:         ' . implode(', ', $gateways) . "\n";
        $return .= 'Default Gateway:          ' . $default_gateway . "\n";
    } else {
        $return .= 'Enabled Gateways:         None' . "\n";
    }
    $return = apply_filters('edd_sysinfo_after_edd_gateways', $return);
    // EDD Taxes
    $return .= "\n" . '-- EDD Tax Configuration' . "\n\n";
    $return .= 'Taxes:                    ' . (edd_use_taxes() ? "Enabled\n" : "Disabled\n");
    $return .= 'Tax Rate:                 ' . edd_get_tax_rate() * 100 . "\n";
    $return .= 'Display On Checkout:      ' . (!empty($edd_options['checkout_include_tax']) ? "Displayed\n" : "Not Displayed\n");
    $return .= 'Prices Include Tax:       ' . (edd_prices_include_tax() ? "Yes\n" : "No\n");
    $rates = edd_get_tax_rates();
    if (!empty($rates)) {
        $return .= 'Country / State Rates:    ' . "\n";
        foreach ($rates as $rate) {
            $return .= '                          Country: ' . $rate['country'] . ', State: ' . $rate['state'] . ', Rate: ' . $rate['rate'] . "\n";
        }
    }
    $return = apply_filters('edd_sysinfo_after_edd_taxes', $return);
    // EDD Templates
    $dir = get_stylesheet_directory() . '/edd_templates/*';
    if (is_dir($dir) && count(glob("{$dir}/*")) !== 0) {
        $return .= "\n" . '-- EDD Template Overrides' . "\n\n";
        foreach (glob($dir) as $file) {
            $return .= 'Filename:                 ' . basename($file) . "\n";
        }
        $return = apply_filters('edd_sysinfo_after_edd_templates', $return);
    }
    // WordPress active plugins
    $return .= "\n" . '-- WordPress Active Plugins' . "\n\n";
    $plugins = get_plugins();
    $active_plugins = get_option('active_plugins', array());
    foreach ($plugins as $plugin_path => $plugin) {
        if (!in_array($plugin_path, $active_plugins)) {
            continue;
        }
        $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
    }
    $return = apply_filters('edd_sysinfo_after_wordpress_plugins', $return);
    // WordPress inactive plugins
    $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n";
    foreach ($plugins as $plugin_path => $plugin) {
        if (in_array($plugin_path, $active_plugins)) {
            continue;
        }
        $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
    }
    $return = apply_filters('edd_sysinfo_after_wordpress_plugins_inactive', $return);
    if (is_multisite()) {
        // WordPress Multisite active plugins
        $return .= "\n" . '-- Network Active Plugins' . "\n\n";
        $plugins = wp_get_active_network_plugins();
        $active_plugins = get_site_option('active_sitewide_plugins', array());
        foreach ($plugins as $plugin_path) {
            $plugin_base = plugin_basename($plugin_path);
            if (!array_key_exists($plugin_base, $active_plugins)) {
                continue;
            }
            $plugin = get_plugin_data($plugin_path);
            $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
        }
        $return = apply_filters('edd_sysinfo_after_wordpress_ms_plugins', $return);
    }
    // Server configuration (really just versioning)
    $return .= "\n" . '-- Webserver Configuration' . "\n\n";
    $return .= 'PHP Version:              ' . PHP_VERSION . "\n";
    $return .= 'MySQL Version:            ' . $wpdb->db_version() . "\n";
    $return .= 'Webserver Info:           ' . $_SERVER['SERVER_SOFTWARE'] . "\n";
    $return = apply_filters('edd_sysinfo_after_webserver_config', $return);
    // PHP configs... now we're getting to the important stuff
    $return .= "\n" . '-- PHP Configuration' . "\n\n";
    $return .= 'Safe Mode:                ' . (ini_get('safe_mode') ? 'Enabled' : 'Disabled' . "\n");
    $return .= 'Memory Limit:             ' . ini_get('memory_limit') . "\n";
    $return .= 'Upload Max Size:          ' . ini_get('upload_max_filesize') . "\n";
    $return .= 'Post Max Size:            ' . ini_get('post_max_size') . "\n";
    $return .= 'Upload Max Filesize:      ' . ini_get('upload_max_filesize') . "\n";
    $return .= 'Time Limit:               ' . ini_get('max_execution_time') . "\n";
    $return .= 'Max Input Vars:           ' . ini_get('max_input_vars') . "\n";
    $return .= 'Display Errors:           ' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A') . "\n";
    $return = apply_filters('edd_sysinfo_after_php_config', $return);
    // PHP extensions and such
    $return .= "\n" . '-- PHP Extensions' . "\n\n";
    $return .= 'cURL:                     ' . (function_exists('curl_init') ? 'Supported' : 'Not Supported') . "\n";
    $return .= 'fsockopen:                ' . (function_exists('fsockopen') ? 'Supported' : 'Not Supported') . "\n";
    $return .= 'SOAP Client:              ' . (class_exists('SoapClient') ? 'Installed' : 'Not Installed') . "\n";
    $return .= 'Suhosin:                  ' . (extension_loaded('suhosin') ? 'Installed' : 'Not Installed') . "\n";
    $return = apply_filters('edd_sysinfo_after_php_ext', $return);
    // Session stuff
    $return .= "\n" . '-- Session Configuration' . "\n\n";
    $return .= 'EDD Use Sessions:         ' . (defined('EDD_USE_PHP_SESSIONS') && EDD_USE_PHP_SESSIONS ? 'Enforced' : (EDD()->session->use_php_sessions() ? 'Enabled' : 'Disabled')) . "\n";
    $return .= 'Session:                  ' . (isset($_SESSION) ? 'Enabled' : 'Disabled') . "\n";
    // The rest of this is only relevant is session is enabled
    if (isset($_SESSION)) {
        $return .= 'Session Name:             ' . esc_html(ini_get('session.name')) . "\n";
        $return .= 'Cookie Path:              ' . esc_html(ini_get('session.cookie_path')) . "\n";
        $return .= 'Save Path:                ' . esc_html(ini_get('session.save_path')) . "\n";
        $return .= 'Use Cookies:              ' . (ini_get('session.use_cookies') ? 'On' : 'Off') . "\n";
        $return .= 'Use Only Cookies:         ' . (ini_get('session.use_only_cookies') ? 'On' : 'Off') . "\n";
    }
    $return = apply_filters('edd_sysinfo_after_session_config', $return);
    $return .= "\n" . '### End System Info ###';
    return $return;
}
Example #11
0
/**
 * System info
 *
 * Shows the system info panel which contains version data and debug info.
 * The data for the system info is generated by the Browser class.
 *
 * @since 1.4
 * @global $wpdb
 * @global object $wpdb Used to query the database using the WordPress
 *   Database API
 * @global $edd_options Array of all the EDD Options
 * @author Chris Christoff
 * @return void
 */
function edd_system_info()
{
    global $wpdb, $edd_options;
    if (!class_exists('Browser')) {
        require_once EDD_PLUGIN_DIR . 'includes/libraries/browser.php';
    }
    $browser = new Browser();
    if (get_bloginfo('version') < '3.4') {
        $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
        $theme = $theme_data['Name'] . ' ' . $theme_data['Version'];
    } else {
        $theme_data = wp_get_theme();
        $theme = $theme_data->Name . ' ' . $theme_data->Version;
    }
    // Try to identifty the hosting provider
    $host = false;
    if (defined('WPE_APIKEY')) {
        $host = 'WP Engine';
    } elseif (defined('PAGELYBIN')) {
        $host = 'Pagely';
    }
    ?>
	<div class="wrap">
		<h2><?php 
    _e('System Information', 'edd');
    ?>
</h2><br/>
		<form action="<?php 
    echo esc_url(admin_url('edit.php?post_type=download&page=edd-system-info'));
    ?>
" method="post" dir="ltr">
			<textarea readonly="readonly" onclick="this.focus();this.select()" id="system-info-textarea" name="edd-sysinfo" title="<?php 
    _e('To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'edd');
    ?>
">
### Begin System Info ###

## Please include this information when posting support requests ##

<?php 
    do_action('edd_system_info_before');
    ?>

Multisite:                <?php 
    echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n";
    ?>

SITE_URL:                 <?php 
    echo site_url() . "\n";
    ?>
HOME_URL:                 <?php 
    echo home_url() . "\n";
    ?>

EDD Version:              <?php 
    echo EDD_VERSION . "\n";
    ?>
Upgraded From:            <?php 
    echo get_option('edd_version_upgraded_from', 'None') . "\n";
    ?>
WordPress Version:        <?php 
    echo get_bloginfo('version') . "\n";
    ?>
Permalink Structure:      <?php 
    echo get_option('permalink_structure') . "\n";
    ?>
Active Theme:             <?php 
    echo $theme . "\n";
    if ($host) {
        ?>
Host:                     <?php 
        echo $host . "\n";
    }
    ?>

Test Mode Enabled:        <?php 
    echo edd_is_test_mode() ? "Yes\n" : "No\n";
    ?>
Ajax Enabled:             <?php 
    echo edd_is_ajax_enabled() ? "Yes\n" : "No\n";
    ?>
Guest Checkout Enabled:   <?php 
    echo edd_no_guest_checkout() ? "No\n" : "Yes\n";
    ?>
Symlinks Enabled:         <?php 
    echo apply_filters('edd_symlink_file_downloads', isset($edd_options['symlink_file_downloads'])) && function_exists('symlink') ? "Yes\n" : "No\n";
    ?>

Checkout is:              <?php 
    echo !empty($edd_options['purchase_page']) ? "Valid\n" : "Invalid\n";
    ?>
Checkout Page:            <?php 
    echo !empty($edd_options['purchase_page']) ? get_permalink($edd_options['purchase_page']) . "\n" : "\n";
    ?>
Success Page:             <?php 
    echo !empty($edd_options['success_page']) ? get_permalink($edd_options['success_page']) . "\n" : "\n";
    ?>
Failure Page:             <?php 
    echo !empty($edd_options['failure_page']) ? get_permalink($edd_options['failure_page']) . "\n" : "\n";
    ?>
Downloads slug:           <?php 
    echo defined('EDD_SLUG') ? '/' . EDD_SLUG . "\n" : "/downloads\n";
    ?>

Taxes Enabled:            <?php 
    echo edd_use_taxes() ? "Yes\n" : "No\n";
    ?>
Taxes After Discounts:    <?php 
    echo edd_taxes_after_discounts() ? "Yes\n" : "No\n";
    ?>
Tax Rate:                 <?php 
    echo edd_get_tax_rate() * 100;
    ?>
%
Country / State Rates:    <?php 
    $rates = edd_get_tax_rates();
    if (!empty($rates)) {
        foreach ($rates as $rate) {
            echo 'Country: ' . $rate['country'] . ', State: ' . $rate['state'] . ', Rate: ' . $rate['rate'] . ' | ';
        }
    }
    ?>

Registered Post Stati:    <?php 
    echo implode(', ', get_post_stati()) . "\n\n";
    ?>

<?php 
    echo $browser;
    ?>

PHP Version:              <?php 
    echo PHP_VERSION . "\n";
    ?>
MySQL Version:            <?php 
    echo mysql_get_server_info() . "\n";
    ?>
Web Server Info:          <?php 
    echo $_SERVER['SERVER_SOFTWARE'] . "\n";
    ?>

WordPress Memory Limit:   <?php 
    echo edd_let_to_num(WP_MEMORY_LIMIT) / 1024 . "MB";
    echo "\n";
    ?>
PHP Safe Mode:            <?php 
    echo ini_get('safe_mode') ? "Yes" : "No\n";
    ?>
PHP Memory Limit:         <?php 
    echo ini_get('memory_limit') . "\n";
    ?>
PHP Upload Max Size:      <?php 
    echo ini_get('upload_max_filesize') . "\n";
    ?>
PHP Post Max Size:        <?php 
    echo ini_get('post_max_size') . "\n";
    ?>
PHP Upload Max Filesize:  <?php 
    echo ini_get('upload_max_filesize') . "\n";
    ?>
PHP Time Limit:           <?php 
    echo ini_get('max_execution_time') . "\n";
    ?>
PHP Max Input Vars:       <?php 
    echo ini_get('max_input_vars') . "\n";
    ?>
PHP Arg Separator:        <?php 
    echo ini_get('arg_separator.output') . "\n";
    ?>
PHP Allow URL File Open:  <?php 
    echo ini_get('allow_url_fopen') ? "Yes" : "No\n";
    ?>

WP_DEBUG:                 <?php 
    echo defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n";
    ?>

WP Table Prefix:          <?php 
    echo "Length: " . strlen($wpdb->prefix);
    echo " Status:";
    if (strlen($wpdb->prefix) > 16) {
        echo " ERROR: Too Long";
    } else {
        echo " Acceptable";
    }
    echo "\n";
    ?>

Show On Front:            <?php 
    echo get_option('show_on_front') . "\n";
    ?>
Page On Front:            <?php 
    $id = get_option('page_on_front');
    echo get_the_title($id) . ' (#' . $id . ')' . "\n";
    ?>
Page For Posts:           <?php 
    $id = get_option('page_for_posts');
    echo get_the_title($id) . ' (#' . $id . ')' . "\n";
    ?>

<?php 
    $request['cmd'] = '_notify-validate';
    $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'EDD/' . EDD_VERSION, 'body' => $request);
    $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params);
    if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
        $WP_REMOTE_POST = 'wp_remote_post() works' . "\n";
    } else {
        $WP_REMOTE_POST = 'wp_remote_post() does not work' . "\n";
    }
    ?>
WP Remote Post:           <?php 
    echo $WP_REMOTE_POST;
    ?>

Session:                  <?php 
    echo isset($_SESSION) ? 'Enabled' : 'Disabled';
    echo "\n";
    ?>
Session Name:             <?php 
    echo esc_html(ini_get('session.name'));
    echo "\n";
    ?>
Cookie Path:              <?php 
    echo esc_html(ini_get('session.cookie_path'));
    echo "\n";
    ?>
Save Path:                <?php 
    echo esc_html(ini_get('session.save_path'));
    echo "\n";
    ?>
Use Cookies:              <?php 
    echo ini_get('session.use_cookies') ? 'On' : 'Off';
    echo "\n";
    ?>
Use Only Cookies:         <?php 
    echo ini_get('session.use_only_cookies') ? 'On' : 'Off';
    echo "\n";
    ?>

DISPLAY ERRORS:           <?php 
    echo ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A';
    echo "\n";
    ?>
FSOCKOPEN:                <?php 
    echo function_exists('fsockopen') ? 'Your server supports fsockopen.' : 'Your server does not support fsockopen.';
    echo "\n";
    ?>
cURL:                     <?php 
    echo function_exists('curl_init') ? 'Your server supports cURL.' : 'Your server does not support cURL.';
    echo "\n";
    ?>
SOAP Client:              <?php 
    echo class_exists('SoapClient') ? 'Your server has the SOAP Client enabled.' : 'Your server does not have the SOAP Client enabled.';
    echo "\n";
    ?>
SUHOSIN:                  <?php 
    echo extension_loaded('suhosin') ? 'Your server has SUHOSIN installed.' : 'Your server does not have SUHOSIN installed.';
    echo "\n";
    ?>

TEMPLATES:

<?php 
    // Show templates that have been copied to the theme's edd_templates dir
    $dir = get_stylesheet_directory() . '/edd_templates/*';
    if (!empty($dir)) {
        foreach (glob($dir) as $file) {
            echo "Filename: " . basename($file) . "\n";
        }
    } else {
        echo 'No overrides found';
    }
    ?>

ACTIVE PLUGINS:

<?php 
    $plugins = get_plugins();
    $active_plugins = get_option('active_plugins', array());
    foreach ($plugins as $plugin_path => $plugin) {
        // If the plugin isn't active, don't show it.
        if (!in_array($plugin_path, $active_plugins)) {
            continue;
        }
        echo $plugin['Name'] . ': ' . $plugin['Version'] . "\n";
    }
    if (is_multisite()) {
        ?>

NETWORK ACTIVE PLUGINS:

<?php 
        $plugins = wp_get_active_network_plugins();
        $active_plugins = get_site_option('active_sitewide_plugins', array());
        foreach ($plugins as $plugin_path) {
            $plugin_base = plugin_basename($plugin_path);
            // If the plugin isn't active, don't show it.
            if (!array_key_exists($plugin_base, $active_plugins)) {
                continue;
            }
            $plugin = get_plugin_data($plugin_path);
            echo $plugin['Name'] . ' :' . $plugin['Version'] . "\n";
        }
    }
    do_action('edd_system_info_after');
    ?>
### End System Info ###</textarea>
			<p class="submit">
				<input type="hidden" name="edd-action" value="download_sysinfo" />
				<?php 
    submit_button('Download System Info File', 'primary', 'edd-download-sysinfo', false);
    ?>
			</p>
		</form>
		</div>
	</div>
<?php 
}
<div class="purchase_summary alignright">
	<table>
		<tr><th colspan="2"><?php 
_e('Purchase summary', 'yoastcom');
?>
</th></tr>
		<tr class="edd_cart_tax_row"<?php 
$hide_vat ? 'style="display:none;"' : '';
?>
>
			<th class="edd_cart_tax">
				<?php 
_e('VAT', 'yoastcom');
?>
				(<span id="yst_secondary_tax_rate"><?php 
echo esc_html(edd_get_tax_rate());
?>
</span>%)
			</th>
			<th class="edd_cart_item_price">
				<span class="edd_cart_tax_amount" id="yst_secondary_tax"><?php 
echo esc_html(edd_cart_tax());
?>
</span>
			</th>
		</tr>
		<tr>
			<th><?php 
_e('Total', 'yoastcom');
?>
:</th>