PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / endpoints / class-charitable-campaign-widget-endpoint.php

class-charitable-campaign-widget-endpoint.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/endpoints/class-charitable-campaign-widget-endpoint.php

121 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donate endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Campaign_Widget_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 } // Exit if accessed directly
16
17 if ( ! class_exists( 'Charitable_Campaign_Widget_Endpoint' ) ) :
18
19 /**
20 * Charitable_Campaign_Widget_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Campaign_Widget_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'campaign_widget';
28
29 /**
30 * Return the endpoint ID.
31 *
32 * @since 1.5.0
33 *
34 * @return string
35 */
36 public static function get_endpoint_id() {
37 return self::ID;
38 }
39
40 /**
41 * Add rewrite rules for the endpoint.
42 *
43 * @since 1.5.0
44 */
45 public function setup_rewrite_rules() {
46 add_rewrite_endpoint( 'widget', EP_PERMALINK );
47 }
48
49 /**
50 * Return the endpoint URL.
51 *
52 * @since 1.5.0
53 * @version 1.8.9.1
54 *
55 * @global WP_Rewrite $wp_rewrite
56 * @param array $args Mixed args.
57 * @return string
58 */
59 public function get_page_url( $args = array() ) {
60 global $wp_rewrite;
61
62 $campaign_id = array_key_exists( 'campaign_id', $args ) ? $args['campaign_id'] : get_the_ID();
63
64 // phpcs:disable WordPress.Security.NonceVerification.Recommended
65 if ( $wp_rewrite->using_permalinks() && ! isset( $_GET['preview'] ) ) {
66 // phpcs:enable WordPress.Security.NonceVerification.Recommended
67 $url = trailingslashit( get_permalink( $campaign_id ) ) . 'widget/';
68 } else {
69 $url = esc_url_raw( add_query_arg( array( 'widget' => 1 ), get_permalink( $campaign_id ) ) );
70 }
71
72 return $url;
73 }
74
75 /**
76 * Return whether we are currently viewing the endpoint.
77 *
78 * @since 1.5.0
79 *
80 * @global WP_Query $wp_query
81 * @param array $args Mixed args.
82 * @return boolean
83 */
84 public function is_page( $args = array() ) {
85 global $wp_query;
86
87 return $wp_query->is_main_query()
88 && array_key_exists( 'widget', $wp_query->query_vars )
89 && $wp_query->is_singular( Charitable::CAMPAIGN_POST_TYPE );
90 }
91
92 /**
93 * Prepare the template for the endpoint.
94 *
95 * @since 1.6.55
96 *
97 * @return void
98 */
99 public function setup_template() {
100 do_action( 'charitable_is_widget' );
101
102 add_filter( 'show_admin_bar', '__return_false' );
103 add_action( 'wp_head', 'charitable_hide_admin_bar' );
104 }
105
106 /**
107 * Return the template to display for this endpoint.
108 *
109 * @since 1.5.0
110 * @since 1.6.55 Returns array instead of string.
111 *
112 * @param string $template The default template.
113 * @return array
114 */
115 public function get_template( $template ) {
116 return apply_filters( 'charitable_widget_page_template', array( 'campaign-widget.php' ) );
117 }
118 }
119
120 endif;
121