/** * Purchase Link Shortcode * * Retrieves a download and displays the purchase form. * * @since 1.0 * @param array $atts Shortcode attributes * @param string $content * @return string Fully formatted purchase link */ function edd_download_shortcode($atts, $content = null) { global $post; $post_id = is_object($post) ? $post->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_option('checkout_color', 'blue'), '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')); } } // Override color if color == inherit if (isset($atts['color'])) { $atts['color'] = $atts['color'] == 'inherit' ? '' : $atts['color']; } if (!empty($atts['sku'])) { $download = edd_get_download_by('sku', $atts['sku']); $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); } }
/** * Purchase Link Shortcode * * Retrieves a download and displays the purchase form. * * @since 1.0 * @param array $atts Shortcode attributes * @param string $content * @return string Fully formatted purchase link */ function edd_download_shortcode($atts, $content = null) { global $post, $edd_options; $post_id = is_object($post) ? $post->ID : 0; $atts = shortcode_atts(array('id' => $post_id, 'sku' => '', 'price' => '1', 'direct' => '0', 'text' => isset($edd_options['add_to_cart_text']) && $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', 'form_id' => ''), $atts, 'purchase_link'); // Override color if color == inherit if (isset($atts['color'])) { $atts['color'] = $atts['color'] == 'inherit' ? '' : $atts['color']; } if (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']); } elseif (isset($atts['sku'])) { $download = edd_get_download_by('sku', $atts['sku']); $atts['download_id'] = $download->ID; } if ($download) { return edd_get_purchase_link($atts); } }