$download_id ) ); } } add_action( 'edd_after_download_content', 'edd_append_purchase_link' ); /** * 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 Settings to set one.', 'edd' ), admin_url( 'edit.php?post_type=download&page=edd-settings' ) ) ); edd_print_errors(); return false; } $defaults = apply_filters( 'edd_purchase_link_defaults', array( 'download_id' => $post->ID, 'price' => (bool) true, '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 ); $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'] ); $args['text'] = edd_currency_filter( edd_format_amount( $price ) ) . ' – ' . $args['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;"'; } ob_start(); ?>
post_type == 'download' && is_singular() && is_main_query() ) { ob_start(); $content .= ob_get_clean(); do_action( 'edd_before_download_content', $post->ID ); } return $content; } add_filter( 'the_content', 'edd_before_download_content' ); /** * After Download Content * * Adds an action to the end of download post content that can be hooked to by * other functions. * * @since 1.0.8 * @global $post * @param $content string The the_content field of the download object * @return $content string the content with any additional data attached */ function edd_after_download_content( $content ) { global $post; if ( $post && $post->post_type == 'download' && is_singular() && is_main_query() ) { ob_start(); do_action( 'edd_after_download_content', $post->ID ); $content .= ob_get_clean(); } return $content; } add_filter( 'the_content', 'edd_after_download_content' ); /** * Filter Success Page Content * * Applies filters to the success page content. * * @since 1.0 * @param string $content Content before filters * @return string $content Filtered content */ function edd_filter_success_page_content( $content ) { global $edd_options; if ( isset( $edd_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $edd_options['success_page'] ) ) { if ( has_filter( 'edd_payment_confirm_' . $_GET['payment-confirmation'] ) ) { $content = apply_filters( 'edd_payment_confirm_' . $_GET['payment-confirmation'], $content ); } } return $content; } add_filter( 'the_content', 'edd_filter_success_page_content' ); /** * Get Button Colors * * Returns an array of button colors. * * @since 1.0 * @return array $colors Button colors */ function edd_get_button_colors() { $colors = array( 'gray' => __( 'Gray', 'edd' ), 'blue' => __( 'Blue', 'edd' ), 'green' => __( 'Green', 'edd' ), 'yellow' => __( 'Yellow', 'edd' ), 'dark-gray' => __( 'Dark Gray', 'edd' ), ); return apply_filters( 'edd_button_colors', $colors ); } /** * Get Button Styles * * Returns an array of button styles. * * @since 1.2.2 * @return array $styles Button styles */ function edd_get_button_styles() { $styles = array( 'button' => __( 'Button', 'edd' ), 'plain' => __( 'Plain Text', 'edd' ) ); return apply_filters( 'edd_button_styles', $styles ); } /** * Show Has Purchased Item Message * * Prints a notice when user has already purchased the item. * * @since 1.0 * @global $user_ID * @param int $download_id Download ID * @return void */ function edd_show_has_purchased_item_message( $download_id ) { global $user_ID; if ( edd_has_user_purchased( $user_ID, $download_id ) ) { $alert = '' . __( 'You have already purchased this item, but you may purchase it again.', 'edd' ) . '
'; echo apply_filters( 'edd_show_has_purchased_item_message', $alert ); } } add_action( 'edd_after_download_content', 'edd_show_has_purchased_item_message' ); /** * Default formatting for download excerpts * * This excerpt is primarily used in the [downloads] short code * * @since 1.0.8.4 * @param string $excerpt Content before filterting * @return string $excerpt Content after filterting * @return string */ function edd_downloads_default_excerpt( $excerpt ) { return do_shortcode( wpautop( $excerpt ) ); } add_filter( 'edd_downloads_excerpt', 'edd_downloads_default_excerpt' ); /** * Default formatting for full download content * * This is primarily used in the [downloads] short code * * @since 1.0.8.4 * @param string $content Content before filterting * @return string $content Content after filterting */ function edd_downloads_default_content( $content ) { return do_shortcode( wpautop( $content ) ); } add_filter( 'edd_downloads_content', 'edd_downloads_default_content' ); /** * Gets the download links for each item purchased * * @since 1.1.5 * @param array $purchase_data Purchase data * @return string */ function edd_get_purchase_download_links( $purchase_data ) { if ( ! is_array( $purchase_data['downloads'] ) ) return '