| 1 |
<?php |
| 2 |
/** |
| 3 |
* Donate Button shortcode class. |
| 4 |
* |
| 5 |
* @package Charitable/Shortcodes/Donate_Button |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8.2 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Donate_Button_Shortcode' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Donate_Button_Shortcode class. |
| 21 |
* |
| 22 |
* @since 1.8.2 |
| 23 |
*/ |
| 24 |
class Charitable_Donate_Button_Shortcode { |
| 25 |
|
| 26 |
/** |
| 27 |
* The callback method for the doante button shortcode. |
| 28 |
* |
| 29 |
* This receives the user-defined attributes and passes the logic off to the class. |
| 30 |
* |
| 31 |
* @since 1.8.2 |
| 32 |
* @version 1.8.10.2 |
| 33 |
* |
| 34 |
* @param array $atts User-defined shortcode attributes. |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public static function display( $atts = array() ) { |
| 38 |
$defaults = array( |
| 39 |
'url' => charitable_get_current_url(), |
| 40 |
'label' => __( 'Donate', 'charitable' ), |
| 41 |
'type' => 'button', // can also be 'link'. |
| 42 |
'css' => 'charitable-button', |
| 43 |
'new_tab' => false, |
| 44 |
'campaign' => 0, |
| 45 |
); |
| 46 |
|
| 47 |
if ( isset( $atts['campaign'] ) ) { |
| 48 |
$campaign_id = (int) $atts['campaign']; |
| 49 |
if ( $campaign_id > 0 ) { |
| 50 |
$atts['url'] = charitable_get_permalink( 'campaign_donation', array( 'campaign_id' => $campaign_id ) ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
$args = shortcode_atts( $defaults, $atts, 'charitable_donate_button' ); |
| 55 |
|
| 56 |
ob_start(); |
| 57 |
|
| 58 |
charitable_template( 'shortcodes/donate-button.php', $args ); |
| 59 |
|
| 60 |
/** |
| 61 |
* Filter the output of the login shortcode. |
| 62 |
* |
| 63 |
* @since 1.8.2 |
| 64 |
* |
| 65 |
* @param string $content Shortcode output. |
| 66 |
*/ |
| 67 |
return apply_filters( 'charitable_donate_button_shortcode', ob_get_clean() ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
endif; |
| 72 |
|