| 1 |
<?php |
| 2 |
/** |
| 3 |
* My Donations shortcode class. |
| 4 |
* |
| 5 |
* @package Charitable/Shortcodes/My Donations |
| 6 |
* @author Eric Daams |
| 7 |
* @copyright Copyright (c) 2022, Studio 164a |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.4.0 |
| 10 |
* @version 1.6.45 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'Charitable_My_Donations_Shortcode' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* Charitable_My_Donations_Shortcode class. |
| 22 |
* |
| 23 |
* @since 1.4.0 |
| 24 |
*/ |
| 25 |
class Charitable_My_Donations_Shortcode { |
| 26 |
|
| 27 |
/** |
| 28 |
* The callback method for the campaigns shortcode. |
| 29 |
* |
| 30 |
* This receives the user-defined attributes and passes the logic off to the class. |
| 31 |
* |
| 32 |
* @since 1.4.0 |
| 33 |
* |
| 34 |
* @param array $atts User-defined shortcode attributes. |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public static function display( $atts ) { |
| 38 |
$defaults = array( |
| 39 |
'hide_login' => false, |
| 40 |
); |
| 41 |
|
| 42 |
$args = shortcode_atts( $defaults, $atts, 'charitable_my_donations' ); |
| 43 |
|
| 44 |
ob_start(); |
| 45 |
|
| 46 |
/* If the user is logged out, show the login form. */ |
| 47 |
if ( ! is_user_logged_in() ) { |
| 48 |
|
| 49 |
if ( false === $args['hide_login'] ) { |
| 50 |
$args['redirect'] = charitable_get_current_url(); |
| 51 |
|
| 52 |
echo Charitable_Login_Shortcode::display( $args ); |
| 53 |
} |
| 54 |
|
| 55 |
return ob_get_clean(); |
| 56 |
} |
| 57 |
|
| 58 |
/* If the user is logged in, show the my donations template. */ |
| 59 |
$user = charitable_get_user( get_current_user_id(), true ); |
| 60 |
$donor_id = $user->get_donor_id(); |
| 61 |
|
| 62 |
if ( false === $donor_id ) { |
| 63 |
$donations = array(); |
| 64 |
$query_args = array(); |
| 65 |
} else { |
| 66 |
$query_args = array( |
| 67 |
'output' => 'posts', |
| 68 |
'orderby' => 'date', |
| 69 |
'order' => 'DESC', |
| 70 |
'number' => -1, |
| 71 |
'donor_id' => $donor_id, |
| 72 |
); |
| 73 |
|
| 74 |
if ( ! $user->is_verified() ) { |
| 75 |
$query_args['user_id'] = $user->ID; |
| 76 |
|
| 77 |
if ( array_key_exists( 'charitable_action', $_GET ) && 'verify_email' === $_GET['charitable_action'] ) { |
| 78 |
$redirect = array_key_exists( 'redirect_url', $_GET ) ? $_GET['redirect_url'] : false; |
| 79 |
$message = sprintf( |
| 80 |
/* translators: %s: email verification link */ |
| 81 |
__( 'We have sent you an email to confirm your email address. Haven\'t received the email? <a href="%s">Click here to send it again.</a>', 'charitable' ), |
| 82 |
esc_url_raw( charitable_get_email_verification_link( $user, $redirect, true ) ) |
| 83 |
); |
| 84 |
} else { |
| 85 |
$message = sprintf( |
| 86 |
/* translators: %s: email verification link */ |
| 87 |
__( '<a href="%s">Confirm your email address</a> to access your full donation history.', 'charitable' ), |
| 88 |
esc_url( charitable_get_email_verification_link( $user, charitable_get_current_url(), true ) ) |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
charitable_get_notices()->add_error( $message ); |
| 93 |
} |
| 94 |
|
| 95 |
$donations = new Charitable_Donations_Query( $query_args ); |
| 96 |
} |
| 97 |
|
| 98 |
$args['donations'] = $donations; |
| 99 |
$args['user'] = $user; |
| 100 |
|
| 101 |
charitable_template( 'shortcodes/my-donations.php', $args ); |
| 102 |
|
| 103 |
/** |
| 104 |
* Filter the output of the shortcode. |
| 105 |
* |
| 106 |
* @since 1.4.0 |
| 107 |
* |
| 108 |
* @param string $output The default output. |
| 109 |
* @param array $args The view arguments. |
| 110 |
* @param array $args The query arguments. |
| 111 |
*/ |
| 112 |
return apply_filters( 'charitable_my_donations_shortcode', ob_get_clean(), $args, $query_args ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
endif; |
| 117 |
|