| 1 |
<?php |
| 2 |
/** |
| 3 |
* Payment class management panel. |
| 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.1.4 |
| 11 |
* @version 1.8.7.1 - Added Square to the list of gateways that are built in. |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'Charitable_Builder_Panel_Payment' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* Design management panel. |
| 22 |
* |
| 23 |
* @since 1.8.0 |
| 24 |
*/ |
| 25 |
class Charitable_Builder_Panel_Payment extends Charitable_Builder_Panel { |
| 26 |
|
| 27 |
/** |
| 28 |
* Form data and payment. |
| 29 |
* |
| 30 |
* @since 1.8.0 |
| 31 |
* |
| 32 |
* @var array |
| 33 |
*/ |
| 34 |
public $campaign_data; |
| 35 |
|
| 36 |
/** |
| 37 |
* Panels for the submenu campaign builder. |
| 38 |
* |
| 39 |
* @since 1.8.0 |
| 40 |
* |
| 41 |
* @var array |
| 42 |
*/ |
| 43 |
public $submenu_panels; |
| 44 |
|
| 45 |
/** |
| 46 |
* All systems go. |
| 47 |
* |
| 48 |
* @since 1.8.0 |
| 49 |
*/ |
| 50 |
public function init() { |
| 51 |
|
| 52 |
// Define panel information. |
| 53 |
$this->name = esc_html__( 'Payment', 'charitable' ); |
| 54 |
$this->slug = 'payment'; |
| 55 |
$this->icon = 'panel_payment.svg'; |
| 56 |
$this->order = 50; |
| 57 |
$this->sidebar = true; |
| 58 |
|
| 59 |
// This should never be called unless we are on the campaign builder page. |
| 60 |
if ( campaign_is_campaign_builder_admin_page() ) { |
| 61 |
$this->load_submenu_panels(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Enqueue assets for the Design panel. |
| 67 |
* |
| 68 |
* @since 1.8.0 |
| 69 |
*/ |
| 70 |
public function enqueues() { |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Load panels. |
| 75 |
* |
| 76 |
* @since 1.8.0 |
| 77 |
* @version 1.8.7.1 - Square below Stripe. |
| 78 |
*/ |
| 79 |
public function load_submenu_panels() { |
| 80 |
|
| 81 |
$this->submenu_panels = apply_filters( |
| 82 |
'charitable_builder_panels_payment', |
| 83 |
array( |
| 84 |
'stripe', |
| 85 |
'square', |
| 86 |
'paypal', |
| 87 |
'braintree', |
| 88 |
'mollie', |
| 89 |
'gocardless', |
| 90 |
'authorize-net', |
| 91 |
'payfast', |
| 92 |
'payrexx', |
| 93 |
'paystack', |
| 94 |
'payumoney', |
| 95 |
'windcave', |
| 96 |
'request', |
| 97 |
) |
| 98 |
); |
| 99 |
|
| 100 |
foreach ( $this->submenu_panels as $panel ) { |
| 101 |
$panel = sanitize_file_name( $panel ); |
| 102 |
$file = apply_filters( 'charitable_builder_panels_payment_classfile', charitable()->get_path( 'includes' ) . "admin/campaign-builder/panels/payment/class-payment-{$panel}.php", $panel ); |
| 103 |
|
| 104 |
if ( file_exists( $file ) ) { |
| 105 |
require_once $file; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
/** |
| 112 |
* Output the Field panel sidebar. |
| 113 |
* |
| 114 |
* @since 1.8.0 |
| 115 |
*/ |
| 116 |
public function panel_sidebar() { |
| 117 |
|
| 118 |
// This should never be called unless we are on the campaign builder page. |
| 119 |
if ( ! campaign_is_campaign_builder_admin_page() ) { |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
do_action( 'charitable_campaign_builder_payment_sidebar', $this->campaign_data ); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Process payment for campaigns, mostly via the builder. |
| 128 |
* |
| 129 |
* @since 1.8.0 |
| 130 |
* |
| 131 |
* @param string $field Field. |
| 132 |
* @param string $section Payment section. |
| 133 |
* @param string $top_level Level. |
| 134 |
* @param string $meta_key Alt legacy location to try to pull payment. |
| 135 |
*/ |
| 136 |
public function campaign_data_payment( $field = 'title', $section = 'general', $top_level = 'payment', $meta_key = false ) { |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Process education payment text. |
| 141 |
* |
| 142 |
* @since 1.8.0 |
| 143 |
* @version 1.8.7.1 - Added Square to the list of gateways that are built in. |
| 144 |
* |
| 145 |
* @param string $label Reader friendly output of object. |
| 146 |
* @param string $slug Object slug. |
| 147 |
* @param string $type Type of request. |
| 148 |
*/ |
| 149 |
public function education_payment_text( $label = false, $slug = false, $type = false ) { |
| 150 |
|
| 151 |
$learn_more_url = charitable_ga_url( |
| 152 |
'https://wpcharitable.com/lite-vs-pro/', // base url. |
| 153 |
rawurlencode( esc_html( $label ) . ' Payment Page' ), // utm-medium. |
| 154 |
rawurlencode( 'Learn More' ) // utm-content. |
| 155 |
); |
| 156 |
|
| 157 |
$big_icon = apply_filters( 'charitable_campaign_builder_payment_icon_url', charitable()->get_path( 'assets', false ) . 'images/campaign-builder/settings/payment/' . esc_attr( $slug ) . '_big.png', $slug ); |
| 158 |
?> |
| 159 |
|
| 160 |
<?php |
| 161 |
|
| 162 |
if ( $big_icon ) : |
| 163 |
echo '<img class="charitable-builder-sidebar-icon" src="' . $big_icon . '" wdith="178" height="178" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 164 |
endif; |
| 165 |
|
| 166 |
?> |
| 167 |
|
| 168 |
<section class="header-content"> |
| 169 |
|
| 170 |
<?php if ( $slug === 'stripe' || $slug === 'paypal' || $slug === 'square' ) : ?> |
| 171 |
|
| 172 |
<h2> |
| 173 |
<?php |
| 174 |
printf( |
| 175 |
// translators: %s is the name of the addon. |
| 176 |
esc_html__( 'Charitable has %s built in.', 'charitable' ), |
| 177 |
'<span>' . esc_html( $label ) . '</span>' |
| 178 |
); |
| 179 |
?> |
| 180 |
</h2> |
| 181 |
|
| 182 |
<p><?php echo esc_html( $label ); ?> <?php echo esc_html__( 'allows you to easily reach more supporters and increase donations.', 'charitable' ); ?></p> |
| 183 |
|
| 184 |
<?php elseif ( 'request' === $type ) : ?> |
| 185 |
|
| 186 |
<h2><?php echo esc_html__( 'Don\'t see an integration with ', 'charitable' ); ?><strong><?php echo esc_html__( 'Charitable', 'charitable' ); ?></strong> <?php echo esc_html__( 'and your favorite payment method?', 'charitable' ); ?></h2> |
| 187 |
<h2><?php echo esc_html__( 'Let us know!', 'charitable' ); ?></h2> |
| 188 |
|
| 189 |
<?php else : ?> |
| 190 |
|
| 191 |
<h2><strong><?php echo esc_html__( 'Charitable Pro', 'charitable' ); ?></strong> <?php echo esc_html__( 'allows you to integrate seamlessly with ', 'charitable' ); ?><span><?php echo esc_html( $label ); ?></span>.</h2> |
| 192 |
|
| 193 |
<p><?php echo esc_html( $label ); ?> <?php echo esc_html__( 'allows you to easily reach more supporters and increase donations with payment platforms including PayPal, Venmo, Apple Pay and Google Pay.', 'charitable' ); ?></p> |
| 194 |
|
| 195 |
<div class="education-buttons education-buttons-top"> |
| 196 |
<a class="button-link" target="_blank" href="<?php echo esc_url( $learn_more_url ); ?>"><?php echo esc_html__( 'Learn More', 'charitable' ); ?></a> <button type="button" class="btn btn-confirm update-to-pro-link"><?php echo esc_html__( 'Upgrade to PRO', 'charitable' ); ?></button> |
| 197 |
</div> |
| 198 |
|
| 199 |
<?php endif; ?> |
| 200 |
|
| 201 |
</section> |
| 202 |
|
| 203 |
<?php if ( $slug === 'stripe' || $slug === 'paypal' || $slug === 'square' ) : ?> |
| 204 |
|
| 205 |
<?php |
| 206 |
elseif ( 'request' === $type ) : |
| 207 |
|
| 208 |
// attempt to prefill name and email fields. |
| 209 |
$current_user = wp_get_current_user(); |
| 210 |
$name = ( $current_user ) ? charitable_get_creator_data() : false; |
| 211 |
$email = ! empty( $current_user->user_email ) ? $current_user->user_email : false; |
| 212 |
|
| 213 |
?> |
| 214 |
|
| 215 |
<!-- start feedback form --> |
| 216 |
|
| 217 |
<div class="charitable-feedback-form-container-payment"> |
| 218 |
|
| 219 |
<div id="charitable-marketing-form" class="charitable-form charitable-feedback-form"> |
| 220 |
|
| 221 |
<div class="charitable-feedback-form-interior"> |
| 222 |
|
| 223 |
<input type="hidden" class="charitable-feedback-form-type" value="payment" /> |
| 224 |
|
| 225 |
<div class="charitable-form-row charitable-feedback-form-row"> |
| 226 |
<label><?php echo esc_html__( 'Name', 'charitable' ); ?> <span class="charitable-feedback-form-required">*</span></label> |
| 227 |
<input name="charitable-feedback-form-name" type="text" class="charitable-feedback-form-name" value="<?php echo esc_html( $name ); ?>" /> |
| 228 |
</div> |
| 229 |
<div class="charitable-form-row charitable-feedback-form-row"> |
| 230 |
<label><?php echo esc_html__( 'Email', 'charitable' ); ?> <span class="charitable-feedback-form-required">*</span></label> |
| 231 |
<input name="charitable-feedback-form-email" type="email" class="charitable-feedback-form-email" value="<?php echo esc_html( $email ); ?>" /> |
| 232 |
</div> |
| 233 |
<div class="charitable-form-row charitable-feedback-form-row"> |
| 234 |
<label><?php echo esc_html__( 'What intergration(s) would you like to see?', 'charitable' ); ?><span class="charitable-feedback-form-required">*</span></label> |
| 235 |
<textarea name="charitable-feedback-form-feedback" class="charitable-feedback-form-feedback"></textarea> |
| 236 |
</div> |
| 237 |
<div class="charitable-form-row charitable-feedback-form-row"> |
| 238 |
<p class="charitable-feedback-form-required">* = <?php echo esc_html__( 'Required', 'charitable' ); ?></p> |
| 239 |
</div> |
| 240 |
<div class="charitable-form-row charitable-feedback-form-row"> |
| 241 |
<a class="button-link"><?php echo esc_html__( 'Send Request', 'charitable' ); ?></a> |
| 242 |
</div> |
| 243 |
<i class="charitable-loading-spinner charitable-loading-black charitable-loading-inline charitable-hidden"></i> |
| 244 |
|
| 245 |
</div> |
| 246 |
|
| 247 |
<div class="charitable-feedback-form-interior-confirmation"> |
| 248 |
|
| 249 |
<!-- confirmation --> |
| 250 |
<div id="charitable-feedback-form-confirmation" class="charitable-form charitable-feedback-form charitable-form-confirmation charitable-hidden"> |
| 251 |
<h2><?php echo esc_html__( 'Thank You!', 'charitable' ); ?></h2> |
| 252 |
<p><?php echo esc_html__( 'Your feedback has been sent to our team. Stay tuned to our updates on', 'charitable' ); ?> <a href="https://wpcharitable.com" target="_blank">wpcharitable.com</a>.</p> |
| 253 |
</div> |
| 254 |
|
| 255 |
</div> |
| 256 |
|
| 257 |
</div> |
| 258 |
|
| 259 |
</div> |
| 260 |
|
| 261 |
<!-- end feedback form --> |
| 262 |
|
| 263 |
<div id="charitable-marketing-form-confirmation" class="charitable-form charitable-marketing-form charitable-form-confirmation charitable-hidden"> |
| 264 |
<h2><?php echo esc_html__( 'Thank you!', 'charitable' ); ?></h2> |
| 265 |
<p><?php echo esc_html__( 'Your feedback has been sent to our team. Stay tuned to our updates on', 'charitable' ); ?> <a href="https://wpcharitable.com" target="_blank">wpcharitable.com</a>.</p> |
| 266 |
</div> |
| 267 |
|
| 268 |
<?php |
| 269 |
|
| 270 |
if ( ! charitable_is_pro() ) : |
| 271 |
?> |
| 272 |
<section class="main-content"> |
| 273 |
|
| 274 |
<p><?php echo esc_html__( 'Upgrading to ', 'charitable' ); ?><strong><?php echo esc_html__( 'Pro', 'charitable' ); ?></strong> <?php echo esc_html__( 'gives you the following capabilities...', 'charitable' ); ?></p> |
| 275 |
|
| 276 |
<ul> |
| 277 |
<li><?php echo esc_html__( 'Integrate with a wide variety of gateways including', 'charitable' ); ?> <strong><?php echo esc_html__( 'Payfast', 'charitable' ); ?></strong>, <strong><?php echo esc_html__( 'Mollie', 'charitable' ); ?></strong>, <strong><?php echo esc_html__( 'Authorize.Net', 'charitable' ); ?></strong> <?php echo esc_html__( 'and more.', 'charitable' ); ?></li> |
| 278 |
<li> |
| 279 |
<?php |
| 280 |
// translators: %s is the name of the addon. |
| 281 |
echo esc_html__( 'With the <strong>Gift Aid</strong> addon, a tax incentive for UK charities, you can boost your donations by 25 percent.', 'charitable' ); |
| 282 |
|
| 283 |
?> |
| 284 |
</li> |
| 285 |
<li><?php echo esc_html__( 'Allow your donors to donate anonmously.', 'charitable' ); ?></li> |
| 286 |
<li><?php echo esc_html__( 'Give your donors the ability to share a message when they donate.', 'charitable' ); ?></li> |
| 287 |
<li><?php echo esc_html__( 'Help your donors with their record keeping by providing downloadable annual receipts.', 'charitable' ); ?></li> |
| 288 |
<li><?php echo esc_html__( 'Make life easy for your donors by providing them with a PDF receipt for their donation.', 'charitable' ); ?></li> |
| 289 |
</ul> |
| 290 |
|
| 291 |
</section> |
| 292 |
|
| 293 |
<?php endif; ?> |
| 294 |
|
| 295 |
<?php else : ?> |
| 296 |
|
| 297 |
<div class="education-images"> |
| 298 |
|
| 299 |
<img class="charitable-payment-image charitable-payment-image-1 charitable-payment-image-<?php echo esc_attr( $slug ); ?>" src="<?php echo esc_url( charitable()->get_path( 'assets', false ) . 'images/campaign-builder/settings/payment/education/' . esc_attr( $slug ) . '.gif' ); ?>" alt="<?php echo esc_html( $label ); ?>" /> |
| 300 |
|
| 301 |
</div> |
| 302 |
|
| 303 |
<section class="main-content"> |
| 304 |
|
| 305 |
<p><?php echo esc_html__( 'Upgrading to ', 'charitable' ); ?><strong><?php echo esc_html__( 'Pro', 'charitable' ); ?></strong> <?php echo esc_html__( 'gives you the following capabilities...', 'charitable' ); ?></p> |
| 306 |
|
| 307 |
<ul> |
| 308 |
<li><?php echo esc_html__( 'Integrate with a wide variety of gateways including', 'charitable' ); ?> <strong><?php echo esc_html__( 'Payfast', 'charitable' ); ?></strong>, <strong><?php echo esc_html__( 'Mollie', 'charitable' ); ?></strong>, <strong><?php echo esc_html__( 'Authorize.Net', 'charitable' ); ?></strong> <?php echo esc_html__( 'and more.', 'charitable' ); ?></li> |
| 309 |
<li> |
| 310 |
<?php |
| 311 |
// translators: %s is the name of the addon. |
| 312 |
echo esc_html__( 'With the <strong>Gift Aid</strong> addon, a tax incentive for UK charities, you can boost your donations by 25 percent.', 'charitable' ); |
| 313 |
|
| 314 |
?> |
| 315 |
</li> |
| 316 |
<li><?php echo esc_html__( 'Allow your donors to donate anonmously.', 'charitable' ); ?></li> |
| 317 |
<li><?php echo esc_html__( 'Give your donors the ability to share a message when they donate.', 'charitable' ); ?></li> |
| 318 |
<li><?php echo esc_html__( 'Help your donors with their record keeping by providing downloadable annual receipts.', 'charitable' ); ?></li> |
| 319 |
<li><?php echo esc_html__( 'Make life easy for your donors by providing them with a PDF receipt for their donation.', 'charitable' ); ?></li> |
| 320 |
</ul> |
| 321 |
|
| 322 |
</section> |
| 323 |
|
| 324 |
<?php endif; ?> |
| 325 |
|
| 326 |
<div class="education-buttons"> |
| 327 |
|
| 328 |
<?php if ( $slug === 'stripe' || $slug === 'paypal' || $slug === 'square' ) { ?> |
| 329 |
|
| 330 |
<?php |
| 331 |
|
| 332 |
$helper = charitable_get_helper( 'gateways' ); |
| 333 |
|
| 334 |
if ( $slug === 'stripe' ) { |
| 335 |
|
| 336 |
$gateway = new Charitable_Gateway_Stripe_AM(); |
| 337 |
$is_active = $helper->is_active_gateway( $gateway->get_gateway_id() ); |
| 338 |
|
| 339 |
if ( $is_active ) { |
| 340 |
|
| 341 |
$action_url = admin_url( 'admin.php?page=charitable-settings&tab=gateways&group=gateways_stripe' ); |
| 342 |
|
| 343 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Go To Payment Gateway Settings', 'charitable' ) . '</a>'; |
| 344 |
|
| 345 |
} else { |
| 346 |
|
| 347 |
$action_url = esc_url( |
| 348 |
add_query_arg( |
| 349 |
array( |
| 350 |
'charitable_action' => 'enable_gateway', |
| 351 |
'gateway_id' => $gateway->get_gateway_id(), |
| 352 |
'_nonce' => wp_create_nonce( 'gateway' ), |
| 353 |
), |
| 354 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 355 |
) |
| 356 |
); |
| 357 |
|
| 358 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Enable Stripe', 'charitable' ) . '</a>'; |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
if ( $slug === 'square' && version_compare( PHP_VERSION, '8.1.0', '>=' ) && class_exists( 'Charitable_Gateway_Square' ) ) { |
| 363 |
|
| 364 |
$gateway = new Charitable_Gateway_Square(); |
| 365 |
$is_active = $helper->is_active_gateway( $gateway->get_gateway_id() ); |
| 366 |
|
| 367 |
if ( $is_active ) { |
| 368 |
|
| 369 |
$action_url = admin_url( 'admin.php?page=charitable-settings&tab=gateways&group=gateways_square_core' ); |
| 370 |
|
| 371 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Go To Payment Gateway Settings', 'charitable' ) . '</a>'; |
| 372 |
|
| 373 |
} else { |
| 374 |
|
| 375 |
$action_url = esc_url( |
| 376 |
add_query_arg( |
| 377 |
array( |
| 378 |
'charitable_action' => 'enable_gateway', |
| 379 |
'gateway_id' => $gateway->get_gateway_id(), |
| 380 |
'_nonce' => wp_create_nonce( 'gateway' ), |
| 381 |
), |
| 382 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 383 |
) |
| 384 |
); |
| 385 |
|
| 386 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Enable Square', 'charitable' ) . '</a>'; |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
if ( $slug === 'paypal' ) { |
| 391 |
|
| 392 |
$gateway = new Charitable_Gateway_Paypal(); |
| 393 |
$is_active = $helper->is_active_gateway( $gateway->get_gateway_id() ); |
| 394 |
|
| 395 |
if ( $is_active ) { |
| 396 |
|
| 397 |
$action_url = admin_url( 'admin.php?page=charitable-settings&tab=gateways&group=gateways_paypal' ); |
| 398 |
|
| 399 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Go To Payment Gateway Settings', 'charitable' ) . '</a>'; |
| 400 |
|
| 401 |
} else { |
| 402 |
|
| 403 |
$action_url = esc_url( |
| 404 |
add_query_arg( |
| 405 |
array( |
| 406 |
'charitable_action' => 'enable_gateway', |
| 407 |
'gateway_id' => $gateway->get_gateway_id(), |
| 408 |
'_nonce' => wp_create_nonce( 'gateway' ), |
| 409 |
), |
| 410 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 411 |
) |
| 412 |
); |
| 413 |
|
| 414 |
echo '<a class="button-link" href="' . esc_url( $action_url ) . '" target="_blank">' . esc_html__( 'Enable Paypal', 'charitable' ) . '</a>'; |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
?> |
| 419 |
|
| 420 |
<?php } elseif ( ! charitable_is_pro() ) { ?> |
| 421 |
|
| 422 |
<h2><?php echo esc_html__( 'Get the most out of your campaigns with ', 'charitable' ); ?><strong><?php echo esc_html__( 'Pro', 'charitable' ); ?></strong>.</h2> |
| 423 |
|
| 424 |
<a class="button-link" href="<?php echo esc_url( $learn_more_url ); ?>"><?php echo esc_html__( 'Learn More', 'charitable' ); ?></a> <button type="button" class="btn btn-confirm"><?php echo esc_html__( 'Upgrade to PRO', 'charitable' ); ?></button> |
| 425 |
|
| 426 |
<?php } ?> |
| 427 |
|
| 428 |
</div> |
| 429 |
|
| 430 |
<?php |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Process addon not activated text. |
| 435 |
* |
| 436 |
* @since 1.8.1.4 |
| 437 |
* |
| 438 |
* @param string $label Reader friendly output of object. |
| 439 |
* @param string $slug Object slug. |
| 440 |
* @param string $needed_addon_url Needed addon URL, used to check if the plugin information is stored in the db. |
| 441 |
* |
| 442 |
* @return void |
| 443 |
*/ |
| 444 |
public function plugin_not_activated_text( $label = false, $slug = false, $needed_addon_url = '' ) { |
| 445 |
|
| 446 |
// Get the first part of the main slug before any "-" or "_" to pass to the search param for the addon page. |
| 447 |
$search_slug = explode( '-', $slug ); |
| 448 |
$search_slug = ! empty( $search_slug ) ? $search_slug[0] : $slug; |
| 449 |
|
| 450 |
$addons_url = esc_url( |
| 451 |
add_query_arg( |
| 452 |
array( |
| 453 |
'search' => $search_slug, |
| 454 |
), |
| 455 |
admin_url( 'admin.php?page=charitable-addons' ) |
| 456 |
) |
| 457 |
); |
| 458 |
$addon_description = esc_html( $label ) . ' ' . esc_html__( 'allows you to easily reach more supporters and increase donations.', 'charitable' ); // default description. |
| 459 |
|
| 460 |
// attempt to get the "slug" so we can eventually see if we can get the plugin description from the stored plugin versions in the databse. |
| 461 |
$plugin_version_slug = explode( '/', $slug ); |
| 462 |
$plugin_version_slug_string = ! empty( $plugin_version_slug ) ? 'charitable-' . $plugin_version_slug[0] : ''; |
| 463 |
|
| 464 |
// start the output. |
| 465 |
echo '<img class="charitable-builder-sidebar-icon" src="' . charitable()->get_path( 'assets', false ) . 'images/campaign-builder/settings/payment/' . esc_attr( $slug ) . '_big.png" wdith="178" height="178" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 466 |
|
| 467 |
?> |
| 468 |
|
| 469 |
<section class="header-content"> |
| 470 |
|
| 471 |
<h2><strong><?php echo esc_html__( 'Charitable Pro', 'charitable' ); ?></strong> <?php echo esc_html__( 'allows you to integrate seamlessly with ', 'charitable' ); ?><span><?php echo esc_html( $label ); ?></span>.</h2> |
| 472 |
|
| 473 |
<?php |
| 474 |
|
| 475 |
// attempt to get the addon description from addon itself, if that information is stored in the database. If not, go with a default description. |
| 476 |
$versions = get_site_option( 'wpc_plugin_versions' ); |
| 477 |
|
| 478 |
if ( false !== $versions && ! empty( $versions['data'] ) ) : |
| 479 |
foreach ( $versions['data'] as $version ) : |
| 480 |
if ( empty( $version['slug'] ) || $version['slug'] !== $plugin_version_slug_string || empty( $version['sections'] ) ) { |
| 481 |
continue; |
| 482 |
} |
| 483 |
$section = rawurlencode( $version['sections'] ); |
| 484 |
$addon_description = ! empty( $section ) ? wp_strip_all_tags( $section['description'] ) : $addon_description; |
| 485 |
endforeach; |
| 486 |
endif; |
| 487 |
|
| 488 |
?> |
| 489 |
|
| 490 |
<p><?php echo esc_html( $addon_description ); ?></p> |
| 491 |
|
| 492 |
<div class="education-buttons education-buttons-top"> |
| 493 |
<a class="button-link" target="_blank" href="<?php echo esc_url( $addons_url ); ?>"><?php echo esc_html__( 'Install This Addon', 'charitable' ); ?></a></button> |
| 494 |
</div> |
| 495 |
|
| 496 |
</section> |
| 497 |
|
| 498 |
<?php |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* Process education marketing text. |
| 503 |
* |
| 504 |
* @since 1.8.1.4 |
| 505 |
* |
| 506 |
* @param string $marketing_item_label Marketing item label. Example: Mailchimp. |
| 507 |
* @param string $marketing_item_slug Marketing item slug. Exmaple: campaign-monitor. |
| 508 |
* @param string $addon_name Addon name. |
| 509 |
* @param string $button_label Button label. |
| 510 |
* @param string $button_url Button URL. |
| 511 |
* @param string $addon_url Addon URL. |
| 512 |
* @param bool $generic_button Whether to use a generic button label. Default is false. |
| 513 |
*/ |
| 514 |
public function plugin_activated_text( $marketing_item_label = false, $marketing_item_slug = false, $addon_name = '', $button_label = 'View Settings', $button_url = '', $addon_url = '', $generic_button = false ) { |
| 515 |
|
| 516 |
echo '<img class="charitable-builder-sidebar-icon" src="' . charitable()->get_path( 'assets', false ) . 'images/campaign-builder/settings/payment/' . esc_attr( $marketing_item_slug ) . '_big.png" wdith="178" height="178" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 517 |
|
| 518 |
?> |
| 519 |
|
| 520 |
<section class="header-content"> |
| 521 |
|
| 522 |
<h2> |
| 523 |
<?php |
| 524 |
// translators: %s is the name of the addon. |
| 525 |
printf( esc_html__( 'You have the %s addon activated.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>' ); |
| 526 |
?> |
| 527 |
</h2> |
| 528 |
|
| 529 |
<p> |
| 530 |
<?php |
| 531 |
// translators: %s is the name of the addon. |
| 532 |
printf( esc_html__( 'The %1$s addon allows you to integrate seamlessly with %2$s as a payment gateway.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>', '<strong>' . esc_html( $marketing_item_label ) . '</strong>' ); |
| 533 |
?> |
| 534 |
</p> |
| 535 |
|
| 536 |
|
| 537 |
</section> |
| 538 |
|
| 539 |
|
| 540 |
<div class="education-buttons education-buttons-bottom"> |
| 541 |
|
| 542 |
<?php |
| 543 |
|
| 544 |
echo '<a class="button-link" href="' . esc_url( $button_url ) . '" target="_blank">' . esc_html( $button_label ) . '</a>'; |
| 545 |
|
| 546 |
?> |
| 547 |
|
| 548 |
</div> |
| 549 |
|
| 550 |
<?php |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* Process installed text related to plugin installed/installing. |
| 555 |
* |
| 556 |
* @since 1.8.1.12 |
| 557 |
* |
| 558 |
* @param string $marketing_item_label Marketing item label. Example: Mailchimp. |
| 559 |
* @param string $marketing_item_slug Marketing item slug. Exmaple: campaign-monitor. |
| 560 |
* @param string $addon_name Addon name. |
| 561 |
* @param string $button_label Button label. |
| 562 |
* @param string $button_url Button URL. |
| 563 |
* @param string $addon_url Addon URL. |
| 564 |
* @param bool $generic_button Whether to use a generic button label. Default is false. |
| 565 |
*/ |
| 566 |
public function plugin_installed_text( $marketing_item_label = false, $marketing_item_slug = false, $addon_name = '', $button_label = 'View Settings', $button_url = '', $addon_url = '', $generic_button = false ) { |
| 567 |
|
| 568 |
echo '<img class="charitable-builder-sidebar-icon" src="' . charitable()->get_path( 'assets', false ) . 'images/campaign-builder/settings/payment/' . esc_attr( $marketing_item_slug ) . '_big.png" wdith="178" height="178" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 569 |
|
| 570 |
// Determine if the plugin in question is installed and/or activated. |
| 571 |
$status = $this->check_plugin_status( $addon_url ); |
| 572 |
$button_label = ''; |
| 573 |
switch ( $status ) { |
| 574 |
case 'installed': |
| 575 |
$button_label = esc_html__( 'Activate', 'charitable' ); |
| 576 |
$action_css_class = 'charitable-not-activated-button'; |
| 577 |
break; |
| 578 |
case 'activated': |
| 579 |
$button_label = esc_html__( 'View Settings', 'charitable' ); |
| 580 |
$action_css_class = 'charitable-view-settings-button'; |
| 581 |
break; |
| 582 |
default: |
| 583 |
// doesn't exist. |
| 584 |
$button_label = esc_html__( 'Install And Activate', 'charitable' ); |
| 585 |
$action_css_class = 'charitable-not-installed-button'; |
| 586 |
break; |
| 587 |
} |
| 588 |
|
| 589 |
// Setup defaults for a few variables. |
| 590 |
$settings_url = false; |
| 591 |
$gateway_id = ''; |
| 592 |
$settings_url = ''; |
| 593 |
$enable_url = ''; |
| 594 |
|
| 595 |
// Get the gateway ID, which in this case is the first part of the addon_url before the '/' and remove the 'charitable-' prefix. |
| 596 |
if ( ! empty( $addon_url ) ) { |
| 597 |
$gateway_id = explode( '/', $addon_url ); |
| 598 |
$gateway_id = ! empty( $gateway_id ) ? str_replace( 'charitable-', '', $gateway_id[0] ) : ''; |
| 599 |
$gateway_id = str_replace( '-', '_', $gateway_id ); |
| 600 |
|
| 601 |
$settings_url = esc_url( |
| 602 |
add_query_arg( |
| 603 |
array( |
| 604 |
'group' => 'gateways_' . $gateway_id, |
| 605 |
), |
| 606 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 607 |
) |
| 608 |
); |
| 609 |
} |
| 610 |
|
| 611 |
if ( ! empty( $gateway_id ) ) { |
| 612 |
$enable_url = esc_url( |
| 613 |
add_query_arg( |
| 614 |
array( |
| 615 |
'charitable_action' => 'enable_gateway', |
| 616 |
'gateway_id' => $gateway_id, |
| 617 |
'_nonce' => wp_create_nonce( 'gateway' ), |
| 618 |
), |
| 619 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 620 |
) |
| 621 |
); |
| 622 |
} |
| 623 |
|
| 624 |
// get license stuff once. |
| 625 |
$charitable_addons = get_transient( '_charitable_addons' ); // @codingStandardsIgnoreLine - testing. |
| 626 |
|
| 627 |
// Get addons data from transient or perform API query if no transient. |
| 628 |
if ( false === $charitable_addons ) { |
| 629 |
$charitable_addons = charitable_get_addons_data_from_server(); |
| 630 |
} |
| 631 |
|
| 632 |
if ( empty( $addon_url ) ) { |
| 633 |
return; |
| 634 |
} |
| 635 |
|
| 636 |
$addon_url_slug = explode( '/', $addon_url ); |
| 637 |
$addon_url_slug = $addon_url_slug[0]; // example: charitable-newsletter-connect. |
| 638 |
|
| 639 |
$addon_information = array(); |
| 640 |
|
| 641 |
// Extract the correct addon data. |
| 642 |
if ( ! empty( $charitable_addons ) ) { |
| 643 |
foreach ( $charitable_addons as $addon ) { |
| 644 |
if ( ! empty( $addon['slug'] ) && (string) $addon_url_slug === (string) $addon['slug'] ) { |
| 645 |
$addon_information = $addon; |
| 646 |
break; |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
$addon_information_install = ! empty( $addon_information['install'] ) ? $addon_information['install'] : ''; |
| 652 |
$addon_information_name = ! empty( $addon_information['name'] ) ? $addon_information['name'] : ''; |
| 653 |
|
| 654 |
?> |
| 655 |
|
| 656 |
<section class="header-content"> |
| 657 |
|
| 658 |
<h2 class="charitable-header-content-installed |
| 659 |
<?php |
| 660 |
if ( 'installed' !== $status ) : |
| 661 |
?> |
| 662 |
charitable-hidden<?php endif; ?>"> |
| 663 |
<?php |
| 664 |
// translators: %s is the name of the addon. |
| 665 |
printf( esc_html__( 'You have the %s addon installed, but not activated.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>' ); |
| 666 |
?> |
| 667 |
</h2> |
| 668 |
<h2 class="charitable-header-content-activated |
| 669 |
<?php |
| 670 |
if ( 'activated' !== $status ) : |
| 671 |
?> |
| 672 |
charitable-hidden<?php endif; ?>"> |
| 673 |
<?php |
| 674 |
// translators: %s is the name of the addon. |
| 675 |
printf( esc_html__( 'You have the %s addon installed and activated.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>' ); |
| 676 |
?> |
| 677 |
</h2> |
| 678 |
<h2 class="charitable-header-content-nonexist |
| 679 |
<?php |
| 680 |
if ( 'nonexist' !== $status ) : |
| 681 |
?> |
| 682 |
charitable-hidden<?php endif; ?>"> |
| 683 |
<?php |
| 684 |
// translators: %s is the name of the addon. |
| 685 |
printf( esc_html__( 'You need to install the %s addon.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>' ); |
| 686 |
?> |
| 687 |
</h2> |
| 688 |
|
| 689 |
<?php |
| 690 |
|
| 691 |
if ( strpos( $addon_url, 'charitable-automation-connect' ) !== false ) : |
| 692 |
|
| 693 |
$direct_automation_services = array( 'zapier', 'integromat', 'zoho-flow', 'automateio' ); |
| 694 |
|
| 695 |
if ( in_array( $marketing_item_slug, $direct_automation_services, true ) ) : |
| 696 |
|
| 697 |
?> |
| 698 |
|
| 699 |
<p> |
| 700 |
<?php |
| 701 |
// translators: %1$s is the name of the addon, %2$s is the marketing item label, %3$s is the link to the documentation. |
| 702 |
printf( esc_html__( 'The %1$s addon allows you to integrate seamlessly with %2$s. %3$s for assistance.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>', '<strong>' . esc_html( $marketing_item_label ) . '</strong>', '<a href="https://www.wpcharitable.com/documentation/charitable-automation-connect/" target="_blank">View our documentation</a>' ); |
| 703 |
?> |
| 704 |
</p> |
| 705 |
|
| 706 |
<?php else : ?> |
| 707 |
<p> |
| 708 |
<?php |
| 709 |
// translators: %1$s is the name of the addon, %2$s is the marketing item label, %3$s is the service name, %4$s is the link to the documentation. |
| 710 |
printf( esc_html__( 'The %1$s addon allows you to integrate seamlessly with %2$s via services such as %3$s. %4$s for assistance.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>', '<strong>' . esc_html( $marketing_item_label ) . '</strong>', '<strong>Zapier</strong>', '<a href="https://www.wpcharitable.com/documentation/charitable-automation-connect/" target="_blank">View our documentation</a>' ); |
| 711 |
?> |
| 712 |
</p> |
| 713 |
|
| 714 |
<?php endif; ?> |
| 715 |
|
| 716 |
<?php else : ?> |
| 717 |
|
| 718 |
<p> |
| 719 |
<?php |
| 720 |
// translators: %s is the name of the addon. |
| 721 |
printf( esc_html__( 'The %1$s addon allows you to integrate seamlessly with %2$s.', 'charitable' ), '<strong>' . esc_html( $addon_name ) . '</strong>', '<strong>' . esc_html( $marketing_item_label ) . '</strong>' ); |
| 722 |
?> |
| 723 |
</p> |
| 724 |
|
| 725 |
<?php endif; ?> |
| 726 |
|
| 727 |
|
| 728 |
</section> |
| 729 |
|
| 730 |
<div class="education-buttons education-buttons-bottom"> |
| 731 |
|
| 732 |
<div class="action-button"> |
| 733 |
<?php echo '<a class="button-link ' . esc_attr( $action_css_class ) . '" data-enable-url="' . esc_url( $enable_url ) . '" data-settings-url="' . esc_url( $settings_url ) . '" data-plugin-url="' . esc_url( $addon_information_install ) . '" data-name="' . esc_html( $addon_information_name ) . '" data-plugin-slug="' . esc_html( $addon_url ) . '" data-field-icon="">' . esc_html( $button_label ) . '</a>'; ?> |
| 734 |
</div> |
| 735 |
|
| 736 |
</div> |
| 737 |
|
| 738 |
<?php |
| 739 |
} |
| 740 |
|
| 741 |
/** |
| 742 |
* Get button label and URL if the newsletter adoon is active. |
| 743 |
* |
| 744 |
* @since 1.8.1.4 |
| 745 |
* |
| 746 |
* @param string $provider_slug Provider slug. |
| 747 |
* @param string $button_url Default Button URL. |
| 748 |
* @param string $button_label Default Button label. |
| 749 |
* |
| 750 |
* @return array |
| 751 |
*/ |
| 752 |
public function get_gateway_button_info( $provider_slug = '', $button_url = '', $button_label = '' ) { |
| 753 |
|
| 754 |
$button_info = array( |
| 755 |
'button_url' => $button_url, |
| 756 |
'button_label' => $button_label, |
| 757 |
); |
| 758 |
|
| 759 |
$helper = charitable_get_helper( 'gateways' ); |
| 760 |
$gateways = $helper->get_available_gateways(); |
| 761 |
|
| 762 |
foreach ( $gateways as $gateway_slug => $gateway ) : |
| 763 |
|
| 764 |
if ( $gateway_slug !== $provider_slug ) { |
| 765 |
continue; |
| 766 |
} |
| 767 |
|
| 768 |
$gateway = new $gateway(); |
| 769 |
$is_active = $helper->is_active_gateway( $gateway->get_gateway_id() ); |
| 770 |
|
| 771 |
if ( $is_active ) { |
| 772 |
$action_url = esc_url( |
| 773 |
add_query_arg( |
| 774 |
array( |
| 775 |
'group' => 'gateways_' . $gateway->get_gateway_id(), |
| 776 |
), |
| 777 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 778 |
) |
| 779 |
); |
| 780 |
$action_text = __( 'Go To Settings', 'charitable' ); |
| 781 |
} else { |
| 782 |
$action_url = esc_url( |
| 783 |
add_query_arg( |
| 784 |
array( |
| 785 |
'charitable_action' => 'enable_gateway', |
| 786 |
'gateway_id' => $gateway->get_gateway_id(), |
| 787 |
'_nonce' => wp_create_nonce( 'gateway' ), |
| 788 |
), |
| 789 |
admin_url( 'admin.php?page=charitable-settings&tab=gateways' ) |
| 790 |
) |
| 791 |
); |
| 792 |
$action_text = __( 'Enable Gateway', 'charitable' ); |
| 793 |
} |
| 794 |
|
| 795 |
$button_info = array( |
| 796 |
'button_url' => $action_url, |
| 797 |
'button_label' => $action_text, |
| 798 |
); |
| 799 |
|
| 800 |
endforeach; |
| 801 |
|
| 802 |
return $button_info; |
| 803 |
} |
| 804 |
|
| 805 |
/** |
| 806 |
* Output the Field panel primary content. |
| 807 |
* |
| 808 |
* @since 1.8.0 |
| 809 |
*/ |
| 810 |
public function panel_content() { |
| 811 |
|
| 812 |
// This should never be called unless we are on the campaign builder page. |
| 813 |
if ( ! campaign_is_campaign_builder_admin_page() ) { |
| 814 |
return; |
| 815 |
} |
| 816 |
|
| 817 |
do_action( 'charitable_campaign_builder_payment_panels', $this->campaign_data ); |
| 818 |
} |
| 819 |
|
| 820 |
/** |
| 821 |
* Builder field buttons. |
| 822 |
* |
| 823 |
* @since 1.8.0 |
| 824 |
*/ |
| 825 |
public function fields() { |
| 826 |
} |
| 827 |
|
| 828 |
/** |
| 829 |
* Sort Add Field buttons by order provided. |
| 830 |
* |
| 831 |
* @since 1.8.0 |
| 832 |
* |
| 833 |
* @param array $a First item. |
| 834 |
* @param array $b Second item. |
| 835 |
* |
| 836 |
* @return array |
| 837 |
*/ |
| 838 |
public function field_order( $a, $b ) { |
| 839 |
|
| 840 |
return $a['order'] - $b['order']; |
| 841 |
} |
| 842 |
|
| 843 |
/** |
| 844 |
* Check the installation and activation status of a plugin. |
| 845 |
* |
| 846 |
* @since 1.8.1.12 |
| 847 |
* |
| 848 |
* @param string $plugin_slug The plugin slug, e.g., 'my-plugin/my-plugin.php'. |
| 849 |
* |
| 850 |
* @return string Status message indicating plugin state. |
| 851 |
*/ |
| 852 |
public function check_plugin_status( $plugin_slug = '' ) { |
| 853 |
|
| 854 |
if ( '' === $plugin_slug ) { |
| 855 |
return 'nonexist'; |
| 856 |
} |
| 857 |
|
| 858 |
// Check if the plugin is installed. |
| 859 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 860 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 861 |
} |
| 862 |
$all_plugins = get_plugins(); |
| 863 |
$plugin_installed = array_key_exists( $plugin_slug, $all_plugins ); |
| 864 |
|
| 865 |
if ( $plugin_installed && is_plugin_active( $plugin_slug ) ) { |
| 866 |
return 'activated'; |
| 867 |
} elseif ( $plugin_installed ) { |
| 868 |
return 'installed'; |
| 869 |
} else { |
| 870 |
return 'nonexist'; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
endif; |
| 876 |
|
| 877 |
new Charitable_Builder_Panel_Payment(); |
| 878 |
|