| 1 |
<?php |
| 2 |
/** |
| 3 |
* Donation processing endpoint. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Donation_Processing_Endpoint |
| 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.5.0 |
| 10 |
* @version 1.6.55 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Donation_Processing_Endpoint' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Donation_Processing_Endpoint |
| 21 |
* |
| 22 |
* @since 1.5.0 |
| 23 |
*/ |
| 24 |
class Charitable_Donation_Processing_Endpoint extends Charitable_Endpoint { |
| 25 |
|
| 26 |
/** Endpoint ID. */ |
| 27 |
const ID = 'donation_processing'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Object instantiation. |
| 31 |
* |
| 32 |
* @since 1.5.4 |
| 33 |
*/ |
| 34 |
public function __construct() { |
| 35 |
$this->cacheable = false; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Return the endpoint ID. |
| 40 |
* |
| 41 |
* @since 1.5.0 |
| 42 |
* |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
public static function get_endpoint_id() { |
| 46 |
return self::ID; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Add rewrite rules for the endpoint. |
| 51 |
* |
| 52 |
* @since 1.5.0 |
| 53 |
*/ |
| 54 |
public function setup_rewrite_rules() { |
| 55 |
add_rewrite_endpoint( 'donation_processing', EP_ROOT ); |
| 56 |
add_rewrite_rule( 'donation-processing/([0-9]+)/?$', 'index.php?donation_id=$matches[1]&donation_processing=1', 'top' ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Return the endpoint URL. |
| 61 |
* |
| 62 |
* @since 1.5.0 |
| 63 |
* |
| 64 |
* @global WP_Rewrite $wp_rewrite |
| 65 |
* @param array $args Mixed args. |
| 66 |
* @return string |
| 67 |
*/ |
| 68 |
public function get_page_url( $args = array() ) { |
| 69 |
global $wp_rewrite; |
| 70 |
|
| 71 |
$donation_id = array_key_exists( 'donation_id', $args ) ? $args['donation_id'] : get_the_ID(); |
| 72 |
|
| 73 |
if ( $wp_rewrite->using_permalinks() ) { |
| 74 |
$url = sprintf( '%s/donation-processing/%d', untrailingslashit( home_url() ), $donation_id ); |
| 75 |
} else { |
| 76 |
$url = esc_url_raw( |
| 77 |
add_query_arg( |
| 78 |
array( |
| 79 |
'donation_processing' => 1, |
| 80 |
'donation_id' => $donation_id, |
| 81 |
), |
| 82 |
home_url() |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
return $url; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Return whether we are currently viewing the endpoint. |
| 92 |
* |
| 93 |
* @since 1.5.0 |
| 94 |
* |
| 95 |
* @global WP_Query $wp_query |
| 96 |
* @param array $args Mixed args. |
| 97 |
* @return boolean |
| 98 |
*/ |
| 99 |
public function is_page( $args = array() ) { |
| 100 |
global $wp_query; |
| 101 |
|
| 102 |
return is_main_query() |
| 103 |
&& array_key_exists( 'donation_processing', $wp_query->query_vars ) |
| 104 |
&& array_key_exists( 'donation_id', $wp_query->query_vars ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Prepare the template for the endpoint. |
| 109 |
* |
| 110 |
* @since 1.6.55 |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
public function setup_template() { |
| 115 |
new Charitable_Ghost_Page( |
| 116 |
'donation-processing-page', |
| 117 |
array( |
| 118 |
'title' => __( 'Thank you for your donation', 'charitable' ), |
| 119 |
'content' => sprintf( '<p>%s</p>', __( 'You will shortly be redirected to the payment gateway to complete your donation.', 'charitable' ) ), |
| 120 |
) |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Return the template to display for this endpoint. |
| 126 |
* |
| 127 |
* @since 1.5.0 |
| 128 |
* |
| 129 |
* @param string $template The default template. |
| 130 |
* @return array |
| 131 |
*/ |
| 132 |
public function get_template( $template ) { |
| 133 |
return array( 'donation-processing-page.php', 'page.php', 'singular.php', 'index.php' ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Get the content to display for the endpoint. |
| 138 |
* |
| 139 |
* @since 1.5.0 |
| 140 |
* |
| 141 |
* @param string $content The default content to show. |
| 142 |
* @return string |
| 143 |
*/ |
| 144 |
public function get_content( $content ) { |
| 145 |
$donation = charitable_get_current_donation(); |
| 146 |
|
| 147 |
if ( ! $donation ) { |
| 148 |
return $content; |
| 149 |
} |
| 150 |
|
| 151 |
return apply_filters( 'charitable_processing_donation_' . $donation->get_gateway(), $content, $donation ); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Return the body class to add for the endpoint. |
| 156 |
* |
| 157 |
* @since 1.5.0 |
| 158 |
* |
| 159 |
* @return string |
| 160 |
*/ |
| 161 |
public function get_body_class() { |
| 162 |
return 'campaign-donation-processing'; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
endif; |
| 167 |
|