PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.0
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 1.7.0.9 1.8.0 All 210 releases
charitable / includes / admin / campaign-builder / functions.php

functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.0, at includes/admin/campaign-builder/functions.php

188 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * General functions made for the campaign builder.
4 *
5 * @package Charitable
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.0
10 * @version 1.8.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Get the list of allowed tags, used in pair with wp_kses() function.
20 * This allows getting rid of all potentially harmful HTML tags and attributes.
21 *
22 * @since 1.8.0
23 *
24 * @return array Allowed Tags.
25 */
26 function charitable_builder_preview_get_allowed_tags() {
27
28 static $allowed_tags;
29
30 if ( ! empty( $allowed_tags ) ) {
31 return $allowed_tags;
32 }
33
34 $atts = [ 'align', 'class', 'type', 'id', 'for', 'style', 'src', 'rel', 'href', 'target', 'value', 'width', 'height' ];
35 $tags = [ 'label', 'iframe', 'style', 'button', 'strong', 'small', 'table', 'span', 'abbr', 'code', 'pre', 'div', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'li', 'em', 'hr', 'br', 'th', 'tr', 'td', 'p', 'a', 'b', 'i' ];
36
37 $allowed_atts = array_fill_keys( $atts, [] );
38 $allowed_tags = array_fill_keys( $tags, $allowed_atts );
39
40 return $allowed_tags;
41 }
42
43 /**
44 * Return URL to form preview page.
45 *
46 * @since 1.8.0
47 *
48 * @param int $campaign_id Form ID.
49 * @param bool $new_window New window flag.
50 * @param string $post_status Post status of item.
51 *
52 * @return string
53 */
54 function charitable_get_campaign_preview_url( $campaign_id = false, $new_window = false, $post_status = false ) {
55
56 if ( intval( $campaign_id ) === 0 ) {
57 return false;
58 }
59
60 if ( false === $post_status ) {
61 $post_status = get_post_status( $campaign_id );
62 }
63
64 if ( $post_status === 'publish' || $post_status === 'private' || $post_status === 'draft' || $post_status === 'public' ) {
65
66 $url = add_query_arg(
67 [
68 'p' => absint( $campaign_id ),
69 'charitable_campaign_preview' => absint( $campaign_id ),
70 ],
71 home_url()
72 );
73
74 if ( $new_window ) {
75 $url = add_query_arg(
76 [
77 'new_window' => 1,
78 ],
79 $url
80 );
81 }
82
83 } else {
84
85 $url = get_preview_post_link( $campaign_id );
86
87 }
88
89 return $url;
90 }
91
92 /**
93 * Determine if we are on the campaign builder admin page
94 *
95 * @since 1.8.0
96 */
97 function campaign_is_campaign_builder_admin_page() {
98
99 if ( isset( $_POST['campaign_id'] ) ) { // @codingStandardsIgnoreLine
100 return true;
101 }
102
103 if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'charitable-campaign-builder' ) { // @codingStandardsIgnoreLine
104 return false;
105 } else {
106 return true;
107 }
108 }
109
110 /**
111 * Get template data from an existing campaign.
112 *
113 * @since 1.8.0
114 *
115 * @param int $campaign_id Form ID.
116 */
117 function charitable_get_template_data_from_campaign( $campaign_id = false ) {
118
119 if ( false === intval( $campaign_id ) ) {
120 return false;
121 }
122
123 $settings = get_post_meta( $campaign_id, 'campaign_settings_v2', true );
124
125 if ( ! empty( $settings ) ) {
126 return $settings;
127 }
128
129 if ( ! empty( $settings['template_id'] ) && ! empty( $settings['template_label'] ) ) {
130
131 return array(
132 'template_id' => esc_attr( $settings['template_id'] ),
133 esc_html( $settings['template_label'] ),
134 );
135
136 } else {
137
138 return false;
139 }
140 }
141
142 /**
143 * Get template data from an existing campaign.
144 *
145 * @since 1.8.0
146 *
147 * @param slug $template_id Template ID.
148 */
149 function charitable_show_field_names_by_default( $template_id = false ) { // phpcs:ignore
150
151 // if ( charitable_is_debug() || ( defined( 'CHARITABLE_BUILDER_SHOW_FIELD_NAMES' ) && CHARITABLE_BUILDER_SHOW_FIELD_NAMES ) ) {
152 // return apply_filters( 'chartiable_builder_show_field_names_default', true, $template_id );
153 // }
154
155 return false;
156 }
157
158 /**
159 * Check and see if preview mode is shown by default.
160 *
161 * @since 1.8.0
162 *
163 * @param slug $template_id Template ID.
164 */
165 function charitable_show_preview_mode_by_default( $template_id = false ) {
166
167 return apply_filters( 'chartiable_builder_show_preview_mode_default', false, $template_id );
168 }
169
170 /**
171 * Generate a tooltip.
172 *
173 * @since 1.8.0
174 *
175 * @param string $tooltip_text The tooltip text.
176 * @param string $extra_css Any additional CSS classes.
177 */
178 function charitable_get_tooltip_html( $tooltip_text = false, $extra_css = '' ) {
179
180 if ( false === $tooltip_text ) {
181 return false;
182 }
183
184 $html = sprintf( '<span class="charitable-help-tooltip-container"><img src="' . charitable()->get_path( 'assets', false ) . 'images/icons/info.svg" alt="" class="charitable-help-tooltip ' . esc_attr( $extra_css ) . '" title="%s"></i></span>', esc_attr( $tooltip_text ) );
185
186 return $html;
187 }
188