| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Charitable |
| 4 |
* Plugin URI: https://www.wpcharitable.com |
| 5 |
* Description: The WordPress fundraising alternative for non-profits, created to help non-profits raise money on their own website. |
| 6 |
* Version: 1.8.1.3 |
| 7 |
* Author: Charitable Donations & Fundraising Team |
| 8 |
* Author URI: https://wpcharitable.com |
| 9 |
* Requires at least: 4.1 |
| 10 |
* Tested up to: 6.4.3 |
| 11 |
* Stable tag: 1.8.1.3 |
| 12 |
* |
| 13 |
* Text Domain: charitable |
| 14 |
* Domain Path: /i18n/languages/ |
| 15 |
* |
| 16 |
* @package Charitable |
| 17 |
* @author David Bisset |
| 18 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 19 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 20 |
*/ |
| 21 |
|
| 22 |
// Exit if accessed directly. |
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
if ( ! class_exists( 'Charitable' ) ) : |
| 28 |
|
| 29 |
/** |
| 30 |
* Main Charitable class. |
| 31 |
*/ |
| 32 |
class Charitable { |
| 33 |
|
| 34 |
/** The product name. */ |
| 35 |
const NAME = 'Charitable'; |
| 36 |
|
| 37 |
/** The plugin author name. */ |
| 38 |
const AUTHOR = 'WP Charitable'; |
| 39 |
|
| 40 |
/* Plugin version. */ |
| 41 |
const VERSION = '1.8.1.3'; |
| 42 |
|
| 43 |
/* Version of database schema. */ |
| 44 |
const DB_VERSION = '20180522'; |
| 45 |
|
| 46 |
/* Campaign post type. */ |
| 47 |
const CAMPAIGN_POST_TYPE = 'campaign'; |
| 48 |
|
| 49 |
/* Donation post type. */ |
| 50 |
const DONATION_POST_TYPE = 'donation'; |
| 51 |
|
| 52 |
/** |
| 53 |
* Single instance of this class. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* |
| 57 |
* @var Charitable |
| 58 |
*/ |
| 59 |
private static $instance = null; |
| 60 |
|
| 61 |
/** |
| 62 |
* The absolute path to this plugin's directory. |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
* |
| 66 |
* @var string |
| 67 |
*/ |
| 68 |
private $directory_path; |
| 69 |
|
| 70 |
/** |
| 71 |
* The URL of this plugin's directory. |
| 72 |
* |
| 73 |
* @since 1.0.0 |
| 74 |
* |
| 75 |
* @var string |
| 76 |
*/ |
| 77 |
private $directory_url; |
| 78 |
|
| 79 |
/** |
| 80 |
* Directory path for the includes folder of the plugin. |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
* |
| 84 |
* @var string |
| 85 |
*/ |
| 86 |
private $includes_path; |
| 87 |
|
| 88 |
/** |
| 89 |
* Store of registered objects. |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* @since 1.5.0 Changed to Charitable_Registry object. Previously it was an array. |
| 93 |
* |
| 94 |
* @var Charitable_Registry |
| 95 |
*/ |
| 96 |
private $registry; |
| 97 |
|
| 98 |
/** |
| 99 |
* Classmap. |
| 100 |
* |
| 101 |
* @since 1.5.0 |
| 102 |
* |
| 103 |
* @var array |
| 104 |
*/ |
| 105 |
private $classmap; |
| 106 |
|
| 107 |
/** |
| 108 |
* Plugin. |
| 109 |
* |
| 110 |
* @since 1.8.0 |
| 111 |
* |
| 112 |
* @var array |
| 113 |
*/ |
| 114 |
private $plugin; |
| 115 |
|
| 116 |
/** |
| 117 |
* Create class instance. |
| 118 |
* |
| 119 |
* @since 1.0.0 |
| 120 |
*/ |
| 121 |
public function __construct() { |
| 122 |
$this->directory_path = plugin_dir_path( __FILE__ ); |
| 123 |
$this->directory_url = plugin_dir_url( __FILE__ ); |
| 124 |
$this->includes_path = $this->directory_path . 'includes/'; |
| 125 |
|
| 126 |
define( 'CHARTIABLE_DIRECTORY_PATH', plugin_dir_path( __FILE__ ) ); |
| 127 |
define( 'CHARTIABLE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 128 |
define( 'CHARTIABLE_MARKETING_URL', 'https://wpcharitable.com/' ); |
| 129 |
|
| 130 |
define( 'CHARITABLE_BUILDER_SHOW_LEGACY_EDIT_LINKS', true ); // 1.8.0 specific. |
| 131 |
|
| 132 |
spl_autoload_register( array( $this, 'autoloader' ) ); |
| 133 |
|
| 134 |
$this->load_dependencies(); |
| 135 |
|
| 136 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 137 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 138 |
|
| 139 |
add_filter( 'plugin_action_links_' . CHARTIABLE_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ), 99, 2 ); |
| 140 |
add_action( 'plugins_loaded', array( $this, 'start' ), 3 ); |
| 141 |
|
| 142 |
add_action( 'plugins_loaded', array( $this, 'check_for_version_conflicts' ), 2 ); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Returns the original instance of this class. |
| 147 |
* |
| 148 |
* @since 1.0.0 |
| 149 |
* |
| 150 |
* @return Charitable |
| 151 |
*/ |
| 152 |
public static function get_instance() { |
| 153 |
return self::$instance; |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Run the startup sequence. |
| 158 |
* |
| 159 |
* This is only ever executed once. |
| 160 |
* |
| 161 |
* @since 1.0.0 |
| 162 |
* |
| 163 |
* @return void |
| 164 |
*/ |
| 165 |
public function start() { |
| 166 |
/* If we've already started (i.e. run this function once before), do not pass go. */ |
| 167 |
if ( $this->started() ) { |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
/* Set static instance. */ |
| 172 |
self::$instance = $this; |
| 173 |
|
| 174 |
/* Set up the registry and instantiate objects we need straight away. */ |
| 175 |
$this->registry(); |
| 176 |
|
| 177 |
$this->setup_licensing(); |
| 178 |
|
| 179 |
$this->maybe_start_ajax(); |
| 180 |
|
| 181 |
$this->attach_hooks_and_filters(); |
| 182 |
|
| 183 |
$this->maybe_start_admin(); |
| 184 |
|
| 185 |
$this->maybe_start_public(); |
| 186 |
|
| 187 |
Charitable_Addons::load( $this ); |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Include necessary files. |
| 192 |
* |
| 193 |
* @since 1.0.0 |
| 194 |
* |
| 195 |
* @return void |
| 196 |
*/ |
| 197 |
private function load_dependencies() { |
| 198 |
$includes_path = $this->get_path( 'includes' ); |
| 199 |
|
| 200 |
/* Load files with hooks & functions. Classes are autoloaded. */ |
| 201 |
require_once $includes_path . 'charitable-core-functions.php'; |
| 202 |
require_once $includes_path . 'api/charitable-api-functions.php'; |
| 203 |
require_once $includes_path . 'campaigns/charitable-campaign-functions.php'; |
| 204 |
require_once $includes_path . 'campaigns/charitable-campaign-hooks.php'; |
| 205 |
require_once $includes_path . 'compat/charitable-compat-functions.php'; |
| 206 |
require_once $includes_path . 'currency/charitable-currency-functions.php'; |
| 207 |
require_once $includes_path . 'deprecated/charitable-deprecated-functions.php'; |
| 208 |
require_once $includes_path . 'donations/charitable-donation-hooks.php'; |
| 209 |
require_once $includes_path . 'donations/charitable-donation-functions.php'; |
| 210 |
require_once $includes_path . 'emails/charitable-email-hooks.php'; |
| 211 |
require_once $includes_path . 'endpoints/charitable-endpoints-functions.php'; |
| 212 |
require_once $includes_path . 'privacy/charitable-privacy-functions.php'; |
| 213 |
require_once $includes_path . 'public/charitable-template-helpers.php'; |
| 214 |
require_once $includes_path . 'shortcodes/charitable-shortcodes-hooks.php'; |
| 215 |
require_once $includes_path . 'upgrades/charitable-upgrade-hooks.php'; |
| 216 |
require_once $includes_path . 'users/charitable-user-functions.php'; |
| 217 |
require_once $includes_path . 'user-management/charitable-user-management-hooks.php'; |
| 218 |
require_once $includes_path . 'utilities/charitable-utility-functions.php'; |
| 219 |
|
| 220 |
/* Load Stripe SDK */ |
| 221 |
require_once $this->get_path( 'directory' ) . 'vendor/autoload.php'; // todo: move to load_dependencies()? |
| 222 |
|
| 223 |
if ( $this->load_core_stripe() ) : |
| 224 |
|
| 225 |
/* Load Stripe SDK */ |
| 226 |
require_once $this->get_path( 'directory' ) . 'vendor/autoload.php'; |
| 227 |
|
| 228 |
/* Interfaces */ |
| 229 |
require_once $includes_path . 'stripe/interfaces/interface-charitable-stripe-gateway-processor.php'; |
| 230 |
|
| 231 |
/* Abstract classes */ |
| 232 |
require_once $includes_path . 'stripe/abstracts/class-charitable-stripe-gateway-processor.php'; |
| 233 |
|
| 234 |
/* Classes */ |
| 235 |
require_once $includes_path . 'stripe/donations/class-charitable-stripe-donation-log.php'; |
| 236 |
require_once $includes_path . 'stripe/donations/class-charitable-stripe-recurring-donation-log.php'; |
| 237 |
require_once $includes_path . 'stripe/i18n/class-charitable-stripe-i18n.php'; |
| 238 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-connected-customer.php'; |
| 239 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-customer.php'; |
| 240 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-gateway-processor-payment-intents.php'; |
| 241 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-payment-intent.php'; |
| 242 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-plan.php'; |
| 243 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-product.php'; |
| 244 |
|
| 245 |
require_once $includes_path . 'stripe/connect/charitable-stripe-connect-functions.php'; |
| 246 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-gateway-processor-checkout.php'; |
| 247 |
|
| 248 |
/* Functions & Hooks */ |
| 249 |
require_once $includes_path . 'stripe/charitable-stripe-core-functions.php'; |
| 250 |
require_once $includes_path . 'stripe/donations/charitable-stripe-donation-functions.php'; |
| 251 |
require_once $includes_path . 'stripe/gateway/charitable-stripe-gateway-hooks.php'; |
| 252 |
|
| 253 |
/* webhooks */ |
| 254 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-webhook-api.php'; |
| 255 |
require_once $includes_path . 'stripe/gateway/class-charitable-stripe-webhook-processor.php'; |
| 256 |
|
| 257 |
endif; |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Load the template functions after theme is loaded. |
| 262 |
* |
| 263 |
* This gives themes time to override the functions. |
| 264 |
* |
| 265 |
* @since 1.6.10 |
| 266 |
* |
| 267 |
* @return void |
| 268 |
*/ |
| 269 |
public function load_template_files() { |
| 270 |
$includes_path = $this->get_path( 'includes' ); |
| 271 |
|
| 272 |
require_once $includes_path . 'public/charitable-template-functions.php'; |
| 273 |
require_once $includes_path . 'public/charitable-template-hooks.php'; |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Dynamically loads the class attempting to be instantiated elsewhere in the |
| 278 |
* plugin by looking at the $class_name parameter being passed as an argument. |
| 279 |
* |
| 280 |
* @since 1.5.0 |
| 281 |
* |
| 282 |
* @param string $class_name The fully-qualified name of the class to load. |
| 283 |
* @return boolean |
| 284 |
*/ |
| 285 |
public function autoloader( $class_name ) { |
| 286 |
/* If the specified $class_name already exists, bail. */ |
| 287 |
if ( class_exists( $class_name ) ) { |
| 288 |
return false; |
| 289 |
} |
| 290 |
|
| 291 |
/* If the specified $class_name does not include our namespace, duck out. */ |
| 292 |
if ( false === strpos( $class_name, 'Charitable_' ) ) { |
| 293 |
return false; |
| 294 |
} |
| 295 |
|
| 296 |
/* Autogenerated class map. */ |
| 297 |
if ( ! isset( $this->classmap ) ) { |
| 298 |
$this->classmap = include 'includes/autoloader/charitable-class-map.php'; |
| 299 |
|
| 300 |
$this->classmap['Charitable_Gateway_Stripe_AM'] = 'gateways/class-charitable-gateway-stripe-am.php'; |
| 301 |
$this->classmap['Charitable_Gateway_Stripe'] = 'gateways/class-charitable-gateway-stripe-am.php'; |
| 302 |
} |
| 303 |
|
| 304 |
$file_path = isset( $this->classmap[ $class_name ] ) ? $this->get_path( 'includes' ) . $this->classmap[ $class_name ] : false; |
| 305 |
|
| 306 |
if ( false !== $file_path && file_exists( $file_path ) && is_file( $file_path ) ) { |
| 307 |
require_once $file_path; |
| 308 |
return true; |
| 309 |
} |
| 310 |
return false; |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Returns a registered class object. |
| 315 |
* |
| 316 |
* @since 1.5.0 |
| 317 |
* |
| 318 |
* @return Charitable_Registry |
| 319 |
*/ |
| 320 |
public function registry() { |
| 321 |
if ( ! isset( $this->registry ) ) { |
| 322 |
$this->registry = new Charitable_Registry(); |
| 323 |
$this->registry->register_object( Charitable_Emails::get_instance() ); |
| 324 |
$this->registry->register_object( Charitable_Request::get_instance() ); |
| 325 |
$this->registry->register_object( Charitable_Gateways::get_instance() ); |
| 326 |
$this->registry->register_object( Charitable_i18n::get_instance() ); |
| 327 |
$this->registry->register_object( Charitable_Post_Types::get_instance() ); |
| 328 |
$this->registry->register_object( Charitable_Cron::get_instance() ); |
| 329 |
$this->registry->register_object( Charitable_Widgets::get_instance() ); |
| 330 |
$this->registry->register_object( Charitable_Licenses::get_instance() ); |
| 331 |
$this->registry->register_object( Charitable_User_Dashboard::get_instance() ); |
| 332 |
$this->registry->register_object( Charitable_Locations::get_instance() ); |
| 333 |
$this->registry->register_object( Charitable_Currency::get_instance() ); |
| 334 |
$this->registry->register_object( Charitable_Notifications::get_instance() ); |
| 335 |
|
| 336 |
$this->registry->register_object( new Charitable_Privacy() ); |
| 337 |
$this->registry->register_object( new Charitable_Debugging() ); |
| 338 |
$this->registry->register_object( new Charitable_Locale() ); |
| 339 |
} |
| 340 |
|
| 341 |
return $this->registry; |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Set up hook and filter callback functions. |
| 346 |
* |
| 347 |
* @since 1.0.0 |
| 348 |
* |
| 349 |
* @return void |
| 350 |
*/ |
| 351 |
private function attach_hooks_and_filters() { |
| 352 |
add_action( 'wpmu_new_blog', array( $this, 'maybe_activate_charitable_on_new_site' ) ); |
| 353 |
add_action( 'plugins_loaded', array( $this, 'charitable_install' ), 100 ); |
| 354 |
add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 ); |
| 355 |
add_action( 'plugins_loaded', array( $this, 'endpoints' ), 100 ); |
| 356 |
add_action( 'plugins_loaded', array( $this, 'donation_fields' ), 100 ); |
| 357 |
add_action( 'plugins_loaded', array( $this, 'campaign_fields' ), 100 ); |
| 358 |
add_action( 'plugins_loaded', array( $this, 'register_donormeta_table' ) ); |
| 359 |
add_action( 'plugins_loaded', 'charitable_load_compat_functions' ); |
| 360 |
add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) ); |
| 361 |
add_action( 'after_setup_theme', array( $this, 'load_template_files' ) ); |
| 362 |
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_start_qunit' ), 100 ); |
| 363 |
add_action( 'rest_api_init', 'charitable_register_api_routes' ); |
| 364 |
|
| 365 |
/** |
| 366 |
* We do this on priority 20 so that any functionality that is loaded on init (such |
| 367 |
* as addons) has a chance to run before the event. |
| 368 |
*/ |
| 369 |
add_action( 'init', array( $this, 'do_charitable_actions' ), 20 ); |
| 370 |
|
| 371 |
if ( $this->load_core_stripe() ) : |
| 372 |
|
| 373 |
/** |
| 374 |
* Set up scripts & stylesheets & enqueue them when appropriate. |
| 375 |
*/ |
| 376 |
add_action( 'charitable_form_after_fields', array( $this, 'maybe_setup_stripe_scripts_in_donation_form' ) ); |
| 377 |
add_action( 'charitable_campaign_loop_after', array( $this, 'maybe_setup_stripe_scripts_in_campaign_loop' ) ); |
| 378 |
|
| 379 |
endif; |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
/** |
| 384 |
* Load Stripe JS, as well as our handling scripts. |
| 385 |
* |
| 386 |
* @since 1.4.0 |
| 387 |
* |
| 388 |
* @return boolean |
| 389 |
*/ |
| 390 |
public function enqueue_stripe_scripts() { |
| 391 |
if ( ! Charitable_Gateways::get_instance()->is_active_gateway( Charitable_Gateway_Stripe_AM::get_gateway_id() ) ) { |
| 392 |
return false; |
| 393 |
} |
| 394 |
|
| 395 |
wp_enqueue_script( 'charitable-stripe' ); |
| 396 |
|
| 397 |
return true; |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* Load Stripe JS or Stripe Checkout, as well as our handling script. |
| 402 |
* |
| 403 |
* @uses Charitable_Stripe::enqueue_scripts() |
| 404 |
* |
| 405 |
* @since 1.4.0 |
| 406 |
* |
| 407 |
* @param Charitable_Donation_Form $form The current form object. |
| 408 |
* @return boolean |
| 409 |
*/ |
| 410 |
public function maybe_setup_stripe_scripts_in_donation_form( $form ) { |
| 411 |
if ( ! is_a( $form, 'Charitable_Donation_Form' ) ) { |
| 412 |
return false; |
| 413 |
} |
| 414 |
|
| 415 |
if ( 'make_donation' !== $form->get_form_action() ) { |
| 416 |
return false; |
| 417 |
} |
| 418 |
|
| 419 |
return $this->enqueue_stripe_scripts(); |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Enqueue the Stripe JS/Checkout scripts after a campaign loop if modal donations are in use. |
| 424 |
* |
| 425 |
* @uses Charitable_Stripe::enqueue_scripts() |
| 426 |
* |
| 427 |
* @since 1.4.0 |
| 428 |
* |
| 429 |
* @return boolean |
| 430 |
*/ |
| 431 |
public function maybe_setup_stripe_scripts_in_campaign_loop() { |
| 432 |
if ( 'modal' !== charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 433 |
return false; |
| 434 |
} |
| 435 |
|
| 436 |
return $this->enqueue_stripe_scripts(); |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Checks whether we're in the admin area and if so, loads the admin-only functionality. |
| 441 |
* |
| 442 |
* @since 1.0.0 |
| 443 |
* |
| 444 |
* @return Charitable_Admin|false |
| 445 |
*/ |
| 446 |
private function maybe_start_admin() { |
| 447 |
if ( ! is_admin() ) { |
| 448 |
return false; |
| 449 |
} |
| 450 |
|
| 451 |
// load blocks/Gutenberg related. |
| 452 |
require_once $this->get_path( 'admin' ) . 'class-charitable-admin-blocks.php'; |
| 453 |
|
| 454 |
require_once $this->get_path( 'admin' ) . 'class-charitable-admin.php'; |
| 455 |
require_once $this->get_path( 'admin' ) . 'charitable-admin-hooks.php'; |
| 456 |
|
| 457 |
// load campaign builder. |
| 458 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/util.php'; |
| 459 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/functions.php'; |
| 460 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/ajax-actions.php'; |
| 461 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/debug.php'; |
| 462 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/access.php'; |
| 463 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/class-builder-fields.php'; |
| 464 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/class-builder-form-fields.php'; |
| 465 |
|
| 466 |
// misc |
| 467 |
require_once $this->get_path( 'admin' ) . 'plugins/charitable-admin-plugin-hooks.php'; |
| 468 |
|
| 469 |
$admin = Charitable_Admin::get_instance(); |
| 470 |
$this->registry->register_object( $admin ); |
| 471 |
|
| 472 |
// Stripe. |
| 473 |
require_once $this->get_path( 'includes' ) . 'stripe/admin/class-charitable-stripe-admin.php'; |
| 474 |
|
| 475 |
new Charitable_Stripe_Admin(); |
| 476 |
|
| 477 |
return $admin; |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* Checks whether we're on the public-facing side and if so, loads the public-facing functionality. |
| 482 |
* |
| 483 |
* @since 1.0.0 |
| 484 |
* |
| 485 |
* @return Charitable_Public|false |
| 486 |
*/ |
| 487 |
private function maybe_start_public() { |
| 488 |
if ( is_admin() && ! $this->is_ajax() ) { |
| 489 |
return false; |
| 490 |
} |
| 491 |
|
| 492 |
require_once $this->get_path( 'public' ) . 'class-charitable-public.php'; |
| 493 |
|
| 494 |
// Campaign Builder related (v1.8.0). |
| 495 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/class-campaign-builder-preview.php'; |
| 496 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/class-builder-fields.php'; |
| 497 |
require_once $this->get_path( 'admin' ) . 'campaign-builder/class-builder-form-fields.php'; |
| 498 |
|
| 499 |
// load blocks/Gutenberg related. |
| 500 |
require_once $this->get_path( 'admin' ) . 'class-charitable-admin-blocks.php'; |
| 501 |
|
| 502 |
$public = Charitable_Public::get_instance(); |
| 503 |
|
| 504 |
$this->registry->register_object( $public ); |
| 505 |
|
| 506 |
return $public; |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* Load the QUnit tests if ?qunit is appended to the request. |
| 511 |
* |
| 512 |
* @since 1.4.17 |
| 513 |
* |
| 514 |
* @return boolean |
| 515 |
*/ |
| 516 |
public function maybe_start_qunit() { |
| 517 |
/* Skip out early if ?qunit isn't included in the request. */ |
| 518 |
if ( ! array_key_exists( 'qunit', $_GET ) ) { |
| 519 |
return false; |
| 520 |
} |
| 521 |
|
| 522 |
/* The unit tests have to exist. */ |
| 523 |
if ( ! file_exists( $this->get_path( 'directory' ) . 'tests/qunit/tests.js' ) ) { |
| 524 |
return false; |
| 525 |
} |
| 526 |
|
| 527 |
wp_register_script( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.js', array(), '2.3.3', true ); |
| 528 |
|
| 529 |
/* Version: '20170615-15:44' */ |
| 530 |
wp_register_script( 'qunit-tests', $this->get_path( 'directory', false ) . 'tests/qunit/tests.js', array( 'jquery', 'qunit' ), time(), true ); |
| 531 |
wp_enqueue_script( 'qunit-tests' ); |
| 532 |
|
| 533 |
wp_register_style( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.css', array(), '2.3.3', 'all' ); |
| 534 |
wp_enqueue_style( 'qunit' ); |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* Checks whether the current request is an AJAX request. |
| 539 |
* |
| 540 |
* @since 1.5.0 |
| 541 |
* |
| 542 |
* @return boolean |
| 543 |
*/ |
| 544 |
private function is_ajax() { |
| 545 |
return false !== ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
| 546 |
} |
| 547 |
|
| 548 |
/** |
| 549 |
* Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality. |
| 550 |
* |
| 551 |
* @since 1.0.0 |
| 552 |
* |
| 553 |
* @return void |
| 554 |
*/ |
| 555 |
private function maybe_start_ajax() { |
| 556 |
if ( ! $this->is_ajax() ) { |
| 557 |
return; |
| 558 |
} |
| 559 |
|
| 560 |
require_once $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php'; |
| 561 |
require_once $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php'; |
| 562 |
} |
| 563 |
|
| 564 |
/** |
| 565 |
* This method is fired after all plugins are loaded and simply fires the charitable_start hook. |
| 566 |
* |
| 567 |
* Extensions can use the charitable_start event to load their own functionality. |
| 568 |
* |
| 569 |
* @since 1.0.0 |
| 570 |
* |
| 571 |
* @return void |
| 572 |
*/ |
| 573 |
public function charitable_start() { |
| 574 |
do_action( 'charitable_start', $this ); |
| 575 |
} |
| 576 |
|
| 577 |
/** |
| 578 |
* Fires off an action right after Charitable is installed, allowing other |
| 579 |
* plugins/themes to do something at this point. |
| 580 |
* |
| 581 |
* @since 1.0.1 |
| 582 |
* |
| 583 |
* @return void |
| 584 |
*/ |
| 585 |
public function charitable_install() { |
| 586 |
$install = get_transient( 'charitable_install' ); |
| 587 |
|
| 588 |
if ( ! $install ) { |
| 589 |
return; |
| 590 |
} |
| 591 |
|
| 592 |
require_once $this->get_path( 'includes' ) . 'plugin/class-charitable-install.php'; |
| 593 |
|
| 594 |
Charitable_Install::finish_installing(); |
| 595 |
|
| 596 |
do_action( 'charitable_install' ); |
| 597 |
|
| 598 |
delete_transient( 'charitable_install' ); |
| 599 |
|
| 600 |
// Store the date when the initial activation was performed. |
| 601 |
$type = function_exists( 'charitable_is_pro' ) && charitable_is_pro() ? 'pro' : 'lite'; |
| 602 |
$activated = get_option( 'charitable_activated', array() ); |
| 603 |
if ( empty( $activated[ $type ] ) ) { |
| 604 |
$activated[ $type ] = time(); |
| 605 |
update_option( 'charitable_activated', $activated ); |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
/** |
| 610 |
* Returns whether we are currently in the start phase of the plugin. |
| 611 |
* |
| 612 |
* @since 1.0.0 |
| 613 |
* |
| 614 |
* @return boolean |
| 615 |
*/ |
| 616 |
public function is_start() { |
| 617 |
return current_filter() == 'charitable_start'; |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* Returns whether the plugin has already started. |
| 622 |
* |
| 623 |
* @since 1.0.0 |
| 624 |
* |
| 625 |
* @return boolean |
| 626 |
*/ |
| 627 |
public function started() { |
| 628 |
return did_action( 'charitable_start' ) || current_filter() == 'charitable_start'; |
| 629 |
} |
| 630 |
|
| 631 |
/** |
| 632 |
* Returns whether the plugin is being activated. |
| 633 |
* |
| 634 |
* @since 1.0.0 |
| 635 |
* |
| 636 |
* @return boolean |
| 637 |
*/ |
| 638 |
public function is_activation() { |
| 639 |
return current_filter() == 'activate_charitable/charitable.php'; |
| 640 |
} |
| 641 |
|
| 642 |
/** |
| 643 |
* Returns whether the plugin is being deactivated. |
| 644 |
* |
| 645 |
* @since 1.0.0 |
| 646 |
* |
| 647 |
* @return boolean |
| 648 |
*/ |
| 649 |
public function is_deactivation() { |
| 650 |
return current_filter() == 'deactivate_charitable/charitable.php'; |
| 651 |
} |
| 652 |
|
| 653 |
/** |
| 654 |
* Returns plugin paths. |
| 655 |
* |
| 656 |
* @since 1.0.0 |
| 657 |
* |
| 658 |
* @param string $type If empty, returns the path to the plugin. |
| 659 |
* @param boolean $absolute_path If true, returns the file system path. If false, returns it as a URL. |
| 660 |
* @return string |
| 661 |
*/ |
| 662 |
public function get_path( $type = '', $absolute_path = true ) { |
| 663 |
$base = $absolute_path ? $this->directory_path : $this->directory_url; |
| 664 |
|
| 665 |
switch ( $type ) { |
| 666 |
case 'includes': |
| 667 |
$path = $base . 'includes/'; |
| 668 |
break; |
| 669 |
|
| 670 |
case 'admin': |
| 671 |
$path = $base . 'includes/admin/'; |
| 672 |
break; |
| 673 |
|
| 674 |
case 'public': |
| 675 |
$path = $base . 'includes/public/'; |
| 676 |
break; |
| 677 |
|
| 678 |
case 'assets': |
| 679 |
$path = $base . 'assets/'; |
| 680 |
break; |
| 681 |
|
| 682 |
case 'templates': |
| 683 |
$path = $base . 'templates/'; |
| 684 |
break; |
| 685 |
|
| 686 |
case 'plugin-directory': |
| 687 |
$path = WP_PLUGIN_DIR; |
| 688 |
break; |
| 689 |
|
| 690 |
case 'directory': |
| 691 |
$path = $base; |
| 692 |
break; |
| 693 |
|
| 694 |
default: |
| 695 |
$path = __FILE__; |
| 696 |
|
| 697 |
}//end switch |
| 698 |
|
| 699 |
return $path; |
| 700 |
} |
| 701 |
|
| 702 |
/** |
| 703 |
* Returns the plugin's version number. |
| 704 |
* |
| 705 |
* @since 1.0.0 |
| 706 |
* |
| 707 |
* @return string |
| 708 |
*/ |
| 709 |
public function get_version() { |
| 710 |
$version = self::VERSION; |
| 711 |
|
| 712 |
if ( false !== strpos( $version, '-' ) ) { |
| 713 |
$parts = explode( '-', $version ); |
| 714 |
$version = $parts[0]; |
| 715 |
} |
| 716 |
|
| 717 |
return $version; |
| 718 |
} |
| 719 |
|
| 720 |
/** |
| 721 |
* Get the campaign fields registry |
| 722 |
* |
| 723 |
* If the registry has not been set up yet, this will also |
| 724 |
* perform the task of setting it up initially. |
| 725 |
* |
| 726 |
* This method is called on the plugins_loaded hook. |
| 727 |
* |
| 728 |
* @since 1.6.0 |
| 729 |
* |
| 730 |
* @return Charitable_Campaign_Field_Registry |
| 731 |
*/ |
| 732 |
public function campaign_fields() { |
| 733 |
if ( ! $this->registry->has( 'campaign_field_registry' ) ) { |
| 734 |
$campaign_fields = new Charitable_Campaign_Field_Registry(); |
| 735 |
|
| 736 |
/* Register it immediately to avoid endless recursion. */ |
| 737 |
$this->registry->register_object( $campaign_fields ); |
| 738 |
|
| 739 |
$fields = include $this->get_path( 'includes' ) . 'fields/default-fields/campaign-fields.php'; |
| 740 |
|
| 741 |
foreach ( $fields as $key => $args ) { |
| 742 |
$campaign_fields->register_field( new Charitable_Campaign_Field( $key, $args ) ); |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
return $this->registry->get( 'campaign_field_registry' ); |
| 747 |
} |
| 748 |
|
| 749 |
/** |
| 750 |
* Get the donation fields registry |
| 751 |
* |
| 752 |
* If the registry has not been set up yet, this will also |
| 753 |
* perform the task of setting it up initially. |
| 754 |
* |
| 755 |
* This method is called on the plugins_loaded hook. |
| 756 |
* |
| 757 |
* @since 1.5.0 |
| 758 |
* |
| 759 |
* @return Charitable_Donation_Field_Registry |
| 760 |
*/ |
| 761 |
public function donation_fields() { |
| 762 |
if ( ! $this->registry->has( 'donation_field_registry' ) ) { |
| 763 |
$donation_fields = new Charitable_Donation_Field_Registry(); |
| 764 |
|
| 765 |
/* Register it immediately to avoid endless recursion. */ |
| 766 |
$this->registry->register_object( $donation_fields ); |
| 767 |
|
| 768 |
$fields = include $this->get_path( 'includes' ) . 'fields/default-fields/donation-fields.php'; |
| 769 |
|
| 770 |
foreach ( $fields as $key => $args ) { |
| 771 |
$donation_fields->register_field( new Charitable_Donation_Field( $key, $args ) ); |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
return $this->registry->get( 'donation_field_registry' ); |
| 776 |
} |
| 777 |
|
| 778 |
/** |
| 779 |
* Return the Endpoints API object. |
| 780 |
* |
| 781 |
* If the Endpoints API has not been set up yet, this will also |
| 782 |
* perform the task of setting it up initially. |
| 783 |
* |
| 784 |
* This method is called on the plugins_loaded hook. |
| 785 |
* |
| 786 |
* @since 1.5.0 |
| 787 |
* |
| 788 |
* @return Charitable_Endpoints |
| 789 |
*/ |
| 790 |
public function endpoints() { |
| 791 |
if ( ! $this->registry->has( 'endpoints' ) ) { |
| 792 |
/** |
| 793 |
* The order in which we register endpoints is important, because |
| 794 |
* it determines the order in which the endpoints are checked to |
| 795 |
* find whether they are the current page. |
| 796 |
* |
| 797 |
* Any endpoint that builds on another endpoint should be registered |
| 798 |
* BEFORE the endpoint it builds on. In other words, move from |
| 799 |
* most specific to least specific. |
| 800 |
*/ |
| 801 |
$endpoints = new Charitable_Endpoints(); |
| 802 |
$endpoints->register( new Charitable_Campaign_Donation_Endpoint() ); |
| 803 |
$endpoints->register( new Charitable_Campaign_Widget_Endpoint() ); |
| 804 |
$endpoints->register( new Charitable_Campaign_Endpoint() ); |
| 805 |
$endpoints->register( new Charitable_Donation_Cancellation_Endpoint() ); |
| 806 |
$endpoints->register( new Charitable_Donation_Processing_Endpoint() ); |
| 807 |
$endpoints->register( new Charitable_Donation_Receipt_Endpoint() ); |
| 808 |
$endpoints->register( new Charitable_Email_Preview_Endpoint() ); |
| 809 |
$endpoints->register( new Charitable_Email_Verification_Endpoint() ); |
| 810 |
$endpoints->register( new Charitable_Forgot_Password_Endpoint() ); |
| 811 |
$endpoints->register( new Charitable_Reset_Password_Endpoint() ); |
| 812 |
$endpoints->register( new Charitable_Registration_Endpoint() ); |
| 813 |
$endpoints->register( new Charitable_Login_Endpoint() ); |
| 814 |
$endpoints->register( new Charitable_Profile_Endpoint() ); |
| 815 |
$endpoints->register( new Charitable_Webhook_Listener_Endpoint() ); |
| 816 |
|
| 817 |
$this->registry->register_object( $endpoints ); |
| 818 |
} |
| 819 |
|
| 820 |
return $this->registry->get( 'endpoints' ); |
| 821 |
} |
| 822 |
|
| 823 |
/** |
| 824 |
* Returns a registered object. |
| 825 |
* |
| 826 |
* @since 1.0.0 |
| 827 |
* |
| 828 |
* @param string $class The type of class to be retrieved. |
| 829 |
* @return object |
| 830 |
*/ |
| 831 |
public function get_registered_object( $class ) { |
| 832 |
return $this->registry->get( $class ); |
| 833 |
} |
| 834 |
|
| 835 |
/** |
| 836 |
* Registers our donormeta table as a meta data table. |
| 837 |
* |
| 838 |
* @since 1.6.0 |
| 839 |
* |
| 840 |
* @global WPDB $wpdb |
| 841 |
* @return void |
| 842 |
*/ |
| 843 |
public function register_donormeta_table() { |
| 844 |
global $wpdb; |
| 845 |
|
| 846 |
$wpdb->donormeta = $wpdb->prefix . 'charitable_donormeta'; |
| 847 |
} |
| 848 |
|
| 849 |
/** |
| 850 |
* Returns the model for one of Charitable's database tables. |
| 851 |
* |
| 852 |
* @since 1.0.0 |
| 853 |
* |
| 854 |
* @param string $table The database table to retrieve. |
| 855 |
* @return Charitable_DB |
| 856 |
*/ |
| 857 |
public function get_db_table( $table ) { |
| 858 |
$tables = $this->get_tables(); |
| 859 |
|
| 860 |
if ( ! isset( $tables[ $table ] ) ) { |
| 861 |
charitable_get_deprecated()->doing_it_wrong( |
| 862 |
__METHOD__, |
| 863 |
sprintf( 'Invalid table %s passed', $table ), |
| 864 |
'1.0.0' |
| 865 |
); |
| 866 |
return null; |
| 867 |
} |
| 868 |
|
| 869 |
return $this->registry->get( $tables[ $table ] ); |
| 870 |
} |
| 871 |
|
| 872 |
/** |
| 873 |
* Return the filtered list of registered tables. |
| 874 |
* |
| 875 |
* @since 1.0.0 |
| 876 |
* |
| 877 |
* @return string[] |
| 878 |
*/ |
| 879 |
private function get_tables() { |
| 880 |
/** |
| 881 |
* Filter the array of available Charitable table classes. |
| 882 |
* |
| 883 |
* @since 1.0.0 |
| 884 |
* @version 1.8.1 |
| 885 |
* |
| 886 |
* @param array $tables List of tables as a key=>value array. |
| 887 |
*/ |
| 888 |
return apply_filters( |
| 889 |
'charitable_db_tables', |
| 890 |
array( |
| 891 |
'campaign_donations' => 'Charitable_Campaign_Donations_DB', |
| 892 |
'donors' => 'Charitable_Donors_DB', |
| 893 |
'donormeta' => 'Charitable_Donormeta_DB', |
| 894 |
'donation_activities' => 'Charitable_Donation_Activities_DB', |
| 895 |
'campaign_activities' => 'Charitable_Campaign_Activities_DB', |
| 896 |
) |
| 897 |
); |
| 898 |
} |
| 899 |
|
| 900 |
/** |
| 901 |
* Maybe activate Charitable when a new site is added in a multisite network. |
| 902 |
* |
| 903 |
* @since 1.4.6 |
| 904 |
* |
| 905 |
* @param int $blog_id The blog to activate Charitable on. |
| 906 |
* @return void |
| 907 |
*/ |
| 908 |
public function maybe_activate_charitable_on_new_site( $blog_id ) { |
| 909 |
if ( is_plugin_active_for_network( basename( $this->directory_path ) . '/charitable.php' ) ) { |
| 910 |
switch_to_blog( $blog_id ); |
| 911 |
$this->activate( false ); |
| 912 |
restore_current_blog(); |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* Runs on plugin activation. |
| 918 |
* |
| 919 |
* @see register_activation_hook |
| 920 |
* |
| 921 |
* @since 1.0.0 |
| 922 |
* |
| 923 |
* @param boolean $network_wide Whether to enable the plugin for all sites in the network |
| 924 |
* or just the current site. Multisite only. Default is false. |
| 925 |
* @return void |
| 926 |
*/ |
| 927 |
public function activate( $network_wide = false ) { |
| 928 |
require_once $this->get_path( 'includes' ) . 'plugin/class-charitable-install.php'; |
| 929 |
|
| 930 |
if ( is_multisite() && $network_wide ) { |
| 931 |
global $wpdb; |
| 932 |
|
| 933 |
foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { |
| 934 |
switch_to_blog( $blog_id ); |
| 935 |
new Charitable_Install( $this->includes_path ); |
| 936 |
restore_current_blog(); |
| 937 |
} |
| 938 |
} else { |
| 939 |
new Charitable_Install( $this->includes_path ); |
| 940 |
} |
| 941 |
|
| 942 |
// create or update the install date for future reference. |
| 943 |
update_option( 'wpcharitable_activated_datetime', current_time( 'timestamp' ) ); |
| 944 |
} |
| 945 |
|
| 946 |
/** |
| 947 |
* Runs on plugin deactivation. |
| 948 |
* |
| 949 |
* @see register_deactivation_hook |
| 950 |
* |
| 951 |
* @since 1.0.0 |
| 952 |
* |
| 953 |
* @return void |
| 954 |
*/ |
| 955 |
public function deactivate() { |
| 956 |
require_once $this->get_path( 'includes' ) . 'plugin/class-charitable-uninstall.php'; |
| 957 |
new Charitable_Uninstall(); |
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* If a charitable_action event is triggered, delegate the event using do_action. |
| 962 |
* |
| 963 |
* @since 1.0.0 |
| 964 |
* |
| 965 |
* @return void |
| 966 |
*/ |
| 967 |
public function do_charitable_actions() { |
| 968 |
if ( isset( $_REQUEST['charitable_action'] ) ) { |
| 969 |
|
| 970 |
$action = esc_attr( $_REQUEST['charitable_action'] ); |
| 971 |
|
| 972 |
/** |
| 973 |
* Handle Charitable action. |
| 974 |
* |
| 975 |
* @since 1.0.0 |
| 976 |
*/ |
| 977 |
do_action( 'charitable_' . $action ); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
/** |
| 982 |
* Throw error on object clone. |
| 983 |
* |
| 984 |
* This class is specifically designed to be instantiated once. You can retrieve the instance using charitable() |
| 985 |
* |
| 986 |
* @since 1.0.0 |
| 987 |
* |
| 988 |
* @return void |
| 989 |
*/ |
| 990 |
public function __clone() { |
| 991 |
charitable_get_deprecated()->doing_it_wrong( |
| 992 |
__FUNCTION__, |
| 993 |
__( 'Cloning this object is forbidden.', 'charitable' ), |
| 994 |
'1.0.0' |
| 995 |
); |
| 996 |
} |
| 997 |
|
| 998 |
/** |
| 999 |
* Disable unserializing of the class. |
| 1000 |
* |
| 1001 |
* @since 1.0.0 |
| 1002 |
* |
| 1003 |
* @return void |
| 1004 |
*/ |
| 1005 |
public function __wakeup() { |
| 1006 |
charitable_get_deprecated()->doing_it_wrong( |
| 1007 |
__FUNCTION__, |
| 1008 |
__( 'Unserializing instances of this class is forbidden.', 'charitable' ), |
| 1009 |
'1.0.0' |
| 1010 |
); |
| 1011 |
} |
| 1012 |
|
| 1013 |
/** |
| 1014 |
* DEPRECATED METHODS |
| 1015 |
*/ |
| 1016 |
|
| 1017 |
/** |
| 1018 |
* Load plugin compatibility files on plugins_loaded hook. |
| 1019 |
* |
| 1020 |
* @deprecated 1.8.0 |
| 1021 |
* |
| 1022 |
* @since 1.4.18 |
| 1023 |
* @since 1.5.0 Deprecated. |
| 1024 |
* |
| 1025 |
* @return void |
| 1026 |
*/ |
| 1027 |
public function load_plugin_compat_files() { |
| 1028 |
charitable_get_deprecated()->deprecated_function( |
| 1029 |
__METHOD__, |
| 1030 |
'1.5.0.', |
| 1031 |
'charitable_load_compat_functions' |
| 1032 |
); |
| 1033 |
|
| 1034 |
charitable_load_compat_functions(); |
| 1035 |
} |
| 1036 |
|
| 1037 |
/** |
| 1038 |
* Stores an object in the plugin's registry. |
| 1039 |
* |
| 1040 |
* @deprecated 1.8.0 |
| 1041 |
* |
| 1042 |
* @since 1.0.0 |
| 1043 |
* @since 1.5.0 Deprecated. |
| 1044 |
* |
| 1045 |
* @param mixed $object Object to be registered. |
| 1046 |
* @return void |
| 1047 |
*/ |
| 1048 |
public function register_object( $object ) { |
| 1049 |
charitable_get_deprecated()->deprecated_function( |
| 1050 |
__METHOD__, |
| 1051 |
'1.5.0', |
| 1052 |
'charitable()->registry()->register_object()' |
| 1053 |
); |
| 1054 |
|
| 1055 |
$this->registry->register_object( $object ); |
| 1056 |
} |
| 1057 |
|
| 1058 |
/** |
| 1059 |
* Returns the public class. |
| 1060 |
* |
| 1061 |
* @deprecated 1.8.0 |
| 1062 |
* |
| 1063 |
* @since 1.0.0 |
| 1064 |
* @since 1.5.0 Deprecated. |
| 1065 |
* |
| 1066 |
* @return Charitable_Public |
| 1067 |
*/ |
| 1068 |
public function get_public() { |
| 1069 |
charitable_get_deprecated()->deprecated_function( |
| 1070 |
__METHOD__, |
| 1071 |
'1.5.0', |
| 1072 |
'charitable_get_helper' |
| 1073 |
); |
| 1074 |
|
| 1075 |
return $this->registry->get( 'Charitable_Public' ); |
| 1076 |
} |
| 1077 |
|
| 1078 |
/** |
| 1079 |
* Returns the admin class. |
| 1080 |
* |
| 1081 |
* @deprecated 1.8.0 |
| 1082 |
* |
| 1083 |
* @since 1.0.0 |
| 1084 |
* @since 1.5.0 Deprecated. |
| 1085 |
* |
| 1086 |
* @return Charitable_Admin |
| 1087 |
*/ |
| 1088 |
public function get_admin() { |
| 1089 |
charitable_get_deprecated()->deprecated_function( |
| 1090 |
__METHOD__, |
| 1091 |
'1.5.0', |
| 1092 |
'charitable_get_helper' |
| 1093 |
); |
| 1094 |
|
| 1095 |
return $this->registry->get( 'Charitable_Admin' ); |
| 1096 |
} |
| 1097 |
|
| 1098 |
/** |
| 1099 |
* Return the current request object. |
| 1100 |
* |
| 1101 |
* @deprecated 1.8.0 |
| 1102 |
* |
| 1103 |
* @since 1.0.0 |
| 1104 |
* @since 1.5.0 Deprecated. |
| 1105 |
* |
| 1106 |
* @return Charitable_Request |
| 1107 |
*/ |
| 1108 |
public function get_request() { |
| 1109 |
charitable_get_deprecated()->deprecated_function( |
| 1110 |
__METHOD__, |
| 1111 |
'1.5.0', |
| 1112 |
'charitable_get_helper' |
| 1113 |
); |
| 1114 |
|
| 1115 |
return $this->registry->get( 'Charitable_Request' ); |
| 1116 |
} |
| 1117 |
|
| 1118 |
/** |
| 1119 |
* Returns the instance of Charitable_Currency. |
| 1120 |
* |
| 1121 |
* @deprecated 1.7.0 |
| 1122 |
* |
| 1123 |
* @since 1.4.0 Deprecated. |
| 1124 |
*/ |
| 1125 |
public function get_currency_helper() { |
| 1126 |
charitable_get_deprecated()->deprecated_function( __METHOD__, '1.4.0', 'charitable_get_currency_helper' ); |
| 1127 |
return charitable_get_currency_helper(); |
| 1128 |
} |
| 1129 |
|
| 1130 |
/** |
| 1131 |
* Returns the instance of Charitable_Locations. |
| 1132 |
* |
| 1133 |
* @deprecated 1.6.0 |
| 1134 |
* |
| 1135 |
* @since 1.2.0 Deprecated. |
| 1136 |
*/ |
| 1137 |
public function get_location_helper() { |
| 1138 |
charitable_get_deprecated()->deprecated_function( __METHOD__, '1.2.0', 'charitable_get_location_helper' ); |
| 1139 |
return charitable_get_location_helper(); |
| 1140 |
} |
| 1141 |
|
| 1142 |
/** |
| 1143 |
* Determine if we use Stripe core files or use an addon if that's installed and active. Checks for USE_NEW_STRIPE first. |
| 1144 |
* |
| 1145 |
* @since 1.7.0 |
| 1146 |
* |
| 1147 |
* @return boolean |
| 1148 |
*/ |
| 1149 |
public function load_core_stripe() { |
| 1150 |
|
| 1151 |
if ( false !== ( defined( 'USE_NEW_STRIPE' ) && USE_NEW_STRIPE ) ) { |
| 1152 |
return true; |
| 1153 |
} |
| 1154 |
|
| 1155 |
// check and see if the core Stripe AM gateway is an active gateway, and if it is not, don't load the core stripe JS, etc. |
| 1156 |
if ( class_exists( 'Charitable_Gateways' ) && class_exists( 'Charitable_Gateway_Stripe_AM' ) && ! Charitable_Gateways::get_instance()->is_active_gateway( Charitable_Gateway_Stripe_AM::get_gateway_id() ) ) { |
| 1157 |
return false; |
| 1158 |
} |
| 1159 |
|
| 1160 |
return true; |
| 1161 |
} |
| 1162 |
|
| 1163 |
/** |
| 1164 |
* Determine Stripe Connect is active. |
| 1165 |
* |
| 1166 |
* @since 1.7.0 |
| 1167 |
* |
| 1168 |
* @return boolean |
| 1169 |
*/ |
| 1170 |
public function is_stripe_connect_addon() { |
| 1171 |
|
| 1172 |
if ( in_array( 'charitable-stripe/charitable-stripe.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 1173 |
return true; |
| 1174 |
} |
| 1175 |
|
| 1176 |
return false; |
| 1177 |
} |
| 1178 |
|
| 1179 |
/** |
| 1180 |
* Action links for the plugins page. |
| 1181 |
* |
| 1182 |
* @since 1.7.0 |
| 1183 |
* |
| 1184 |
* @param array $actions An array of existing actions. |
| 1185 |
* @param string $plugin_file The plugin file we are modifying. |
| 1186 |
* @return array An array of action links. |
| 1187 |
*/ |
| 1188 |
public function plugin_action_links( $actions, $plugin_file, $action_links = false ) { |
| 1189 |
|
| 1190 |
if ( ! charitable_is_pro() ) : |
| 1191 |
|
| 1192 |
// if this isn't pro, add the upgrade link which is visible on the plugins page until the plugin name. |
| 1193 |
|
| 1194 |
$action_links = [ |
| 1195 |
'proupgrade' => [ |
| 1196 |
// Translators: This is an action link users can click to purchase a license for All in One SEO Pro. |
| 1197 |
'label' => __( 'Upgrade to Pro', 'charitable' ), |
| 1198 |
'url' => 'https://wpcharitable.com/lite-vs-pro/?utm_source=WordPress&utm_campaign=WP+Charitable&utm_medium=Action+Link+Plugins+Page&utm_content=Upgrade+to+Pro', |
| 1199 |
], |
| 1200 |
]; |
| 1201 |
|
| 1202 |
endif; |
| 1203 |
|
| 1204 |
if ( isset( $actions['edit'] ) ) { |
| 1205 |
unset( $actions['edit'] ); |
| 1206 |
} |
| 1207 |
|
| 1208 |
return $this->parse_action_links( $actions, $plugin_file, $action_links, 'before' ); |
| 1209 |
} |
| 1210 |
|
| 1211 |
/** |
| 1212 |
* Parse the action links. |
| 1213 |
* |
| 1214 |
* @since 1.7.0 |
| 1215 |
* |
| 1216 |
* @param array $actions |
| 1217 |
* @param string $pluginFile |
| 1218 |
* @param |
| 1219 |
* @return array |
| 1220 |
*/ |
| 1221 |
protected function parse_action_links( $actions, $pluginFile, $action_links = [], $position = 'after' ) { |
| 1222 |
if ( empty( $this->plugin ) ) { |
| 1223 |
$this->plugin = CHARTIABLE_PLUGIN_BASENAME; |
| 1224 |
} |
| 1225 |
|
| 1226 |
if ( $this->plugin === $pluginFile && ! empty( $action_links ) ) { |
| 1227 |
foreach ( $action_links as $key => $value ) { |
| 1228 |
$link = [ |
| 1229 |
$key => '<a href="' . $value['url'] . '">' . $value['label'] . '</a>', |
| 1230 |
]; |
| 1231 |
|
| 1232 |
$actions = 'after' === $position ? array_merge( $actions, $link ) : array_merge( $link, $actions ); |
| 1233 |
} |
| 1234 |
} |
| 1235 |
|
| 1236 |
return $actions; |
| 1237 |
} |
| 1238 |
|
| 1239 |
/** |
| 1240 |
* Set up licensing for pro. |
| 1241 |
* |
| 1242 |
* @since 1.7.0 |
| 1243 |
* |
| 1244 |
* @return void |
| 1245 |
*/ |
| 1246 |
public function setup_licensing() { |
| 1247 |
charitable_get_helper( 'licenses' )->register_licensed_product( |
| 1248 |
self::NAME, // . ' Pro', |
| 1249 |
self::AUTHOR, |
| 1250 |
self::VERSION, |
| 1251 |
__FILE__ |
| 1252 |
); |
| 1253 |
} |
| 1254 |
|
| 1255 |
/** |
| 1256 |
* Deativates and/or warnings about any Charitable verison conflicts. |
| 1257 |
* |
| 1258 |
* @since 1.7.0 |
| 1259 |
*/ |
| 1260 |
public function check_for_version_conflicts() { |
| 1261 |
|
| 1262 |
// Check for Charitable Stripe < 1.5.0. |
| 1263 |
if ( in_array( 'charitable-stripe/charitable-stripe.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 1264 |
if ( class_exists( 'Charitable_Stripe' ) && version_compare( Charitable_Stripe::VERSION, '1.5.0', '<' ) ) { |
| 1265 |
// manually deactivate plugin. |
| 1266 |
$found = false; |
| 1267 |
$current = get_option( 'active_plugins', array() ); |
| 1268 |
$key = array_search( 'charitable-stripe/charitable-stripe.php', $current, true ); |
| 1269 |
if ( false !== $key ) { |
| 1270 |
$found = true; |
| 1271 |
|
| 1272 |
unset( $current[ $key ] ); |
| 1273 |
update_option( 'active_plugins', $current ); |
| 1274 |
|
| 1275 |
$message = __( '<p><strong style="color:red;">NOTICE:</strong> <strong>Charitable</strong> detected an out-of-date and incompatible version of <strong>Charitable Stripe</strong> addon. To avoid issues with Stripe donations, <strong>Charitable Stripe</strong> ' . Charitable_Stripe::VERSION . ' was deactivated. Please update <strong>Charitable Stripe</strong> to version 1.5.0 or higher.</p><p>You can get the latest version of <strong>Charitable Stripe</strong> through your <a href="https://www.wpcharitable.com/account/" target="_blank">Charitable account at wpcharitable.com</a>. All active licenses are accessible in the "My Downloads" tab.</p>', 'charitable-stripe' ); |
| 1276 |
|
| 1277 |
wp_die( $message . ' <a href="' . admin_url( 'plugins.php' ) . '">Click here to return to the plugins screen.</a>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1278 |
} |
| 1279 |
add_option( 'chartiable_version_warning', $message ); |
| 1280 |
} else { |
| 1281 |
delete_option( 'chartiable_version_warning' ); |
| 1282 |
} |
| 1283 |
} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
|
| 1287 |
$charitable = new Charitable(); |
| 1288 |
|
| 1289 |
endif; |
| 1290 |
|