| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class that sets up the Charitable Admin functionality. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Admin |
| 6 |
* @version 1.0.0 |
| 7 |
* @author Eric Daams |
| 8 |
* @copyright Copyright (c) 2015, Studio 164a |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly |
| 13 |
|
| 14 |
if ( ! class_exists( 'Charitable_Admin' ) ) : |
| 15 |
|
| 16 |
/** |
| 17 |
* Charitable_Admin |
| 18 |
* |
| 19 |
* @final |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
final class Charitable_Admin { |
| 23 |
|
| 24 |
/** |
| 25 |
* The single instance of this class. |
| 26 |
* |
| 27 |
* @var Charitable_Admin|null |
| 28 |
* @access private |
| 29 |
* @static |
| 30 |
*/ |
| 31 |
private static $instance = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* Set up the class. |
| 35 |
* |
| 36 |
* Note that the only way to instantiate an object is with the charitable_start method, |
| 37 |
* which can only be called during the start phase. In other words, don't try |
| 38 |
* to instantiate this object. |
| 39 |
* |
| 40 |
* @access protected |
| 41 |
* @since 1.0.0 |
| 42 |
*/ |
| 43 |
protected function __construct() { |
| 44 |
$this->load_dependencies(); |
| 45 |
|
| 46 |
do_action( 'charitable_admin_loaded' ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns and/or create the single instance of this class. |
| 51 |
* |
| 52 |
* @return Charitable_Admin |
| 53 |
* @access public |
| 54 |
* @since 1.2.0 |
| 55 |
*/ |
| 56 |
public static function get_instance() { |
| 57 |
if ( is_null( self::$instance ) ) { |
| 58 |
self::$instance = new Charitable_Admin(); |
| 59 |
} |
| 60 |
|
| 61 |
return self::$instance; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Include admin-only files. |
| 66 |
* |
| 67 |
* @return void |
| 68 |
* @access private |
| 69 |
* @since 1.0.0 |
| 70 |
*/ |
| 71 |
private function load_dependencies() { |
| 72 |
$admin_dir = charitable()->get_path( 'admin' ); |
| 73 |
|
| 74 |
require_once( $admin_dir . 'charitable-core-admin-functions.php' ); |
| 75 |
require_once( $admin_dir . 'class-charitable-meta-box-helper.php' ); |
| 76 |
require_once( $admin_dir . 'class-charitable-admin-pages.php' ); |
| 77 |
require_once( $admin_dir . 'class-charitable-admin-notices.php' ); |
| 78 |
|
| 79 |
/* Campaigns */ |
| 80 |
require_once( $admin_dir . 'campaigns/class-charitable-campaign-post-type.php' ); |
| 81 |
|
| 82 |
/* Donations */ |
| 83 |
require_once( $admin_dir . 'donations/class-charitable-donation-post-type.php' ); |
| 84 |
|
| 85 |
/* Settings */ |
| 86 |
require_once( $admin_dir . 'settings/class-charitable-settings.php' ); |
| 87 |
require_once( $admin_dir . 'settings/class-charitable-general-settings.php' ); |
| 88 |
require_once( $admin_dir . 'settings/class-charitable-email-settings.php' ); |
| 89 |
require_once( $admin_dir . 'settings/class-charitable-gateway-settings.php' ); |
| 90 |
require_once( $admin_dir . 'settings/class-charitable-licenses-settings.php' ); |
| 91 |
require_once( $admin_dir . 'settings/class-charitable-advanced-settings.php' ); |
| 92 |
require_once( $admin_dir . 'settings/charitable-settings-admin-hooks.php' ); |
| 93 |
|
| 94 |
/* Dashboard widgets */ |
| 95 |
require_once( $admin_dir . 'dashboard-widgets/class-charitable-donations-dashboard-widget.php' ); |
| 96 |
require_once( $admin_dir . 'dashboard-widgets/charitable-dashboard-widgets-hooks.php' ); |
| 97 |
|
| 98 |
/* Upgrades */ |
| 99 |
require_once( $admin_dir . 'upgrades/class-charitable-upgrade.php' ); |
| 100 |
require_once( $admin_dir . 'upgrades/class-charitable-upgrade-page.php' ); |
| 101 |
require_once( $admin_dir . 'upgrades/charitable-upgrade-hooks.php' ); |
| 102 |
|
| 103 |
/** |
| 104 |
* We are registering this object only for backwards compatibility. It |
| 105 |
* will be removed in or after Charitable 1.3. |
| 106 |
* |
| 107 |
* @deprecated |
| 108 |
*/ |
| 109 |
charitable()->register_object( Charitable_Settings::get_instance() ); |
| 110 |
charitable()->register_object( Charitable_Campaign_Post_Type::get_instance() ); |
| 111 |
charitable()->register_object( Charitable_Donation_Post_Type::get_instance() ); |
| 112 |
charitable()->register_object( Charitable_Admin_Pages::get_instance() ); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Loads admin-only scripts and stylesheets. |
| 117 |
* |
| 118 |
* @return void |
| 119 |
* @access public |
| 120 |
* @since 1.0.0 |
| 121 |
*/ |
| 122 |
public function admin_enqueue_scripts() { |
| 123 |
|
| 124 |
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { |
| 125 |
$suffix = ''; |
| 126 |
$version = time(); |
| 127 |
} else { |
| 128 |
$suffix = '.min'; |
| 129 |
$version = charitable()->get_version(); |
| 130 |
} |
| 131 |
|
| 132 |
$assets_path = charitable()->get_path( 'assets', false ); |
| 133 |
|
| 134 |
/* Menu styles are loaded everywhere in the WordPress dashboard. */ |
| 135 |
wp_register_style( |
| 136 |
'charitable-admin-menu', |
| 137 |
$assets_path . 'css/charitable-admin-menu' . $suffix . '.css', |
| 138 |
array(), |
| 139 |
$version |
| 140 |
); |
| 141 |
|
| 142 |
wp_enqueue_style( 'charitable-admin-menu' ); |
| 143 |
|
| 144 |
/* Admin page styles are registered but only enqueued when necessary. */ |
| 145 |
wp_register_style( |
| 146 |
'charitable-admin-pages', |
| 147 |
$assets_path . 'css/charitable-admin-pages' . $suffix . '.css', |
| 148 |
array(), |
| 149 |
$version |
| 150 |
); |
| 151 |
|
| 152 |
/* The following styles are only loaded on Charitable screens. */ |
| 153 |
$screen = get_current_screen(); |
| 154 |
|
| 155 |
if ( in_array( $screen->id, $this->get_charitable_screens() ) ) { |
| 156 |
|
| 157 |
wp_register_style( |
| 158 |
'charitable-admin', |
| 159 |
$assets_path . 'css/charitable-admin' . $suffix . '.css', |
| 160 |
array(), |
| 161 |
$version |
| 162 |
); |
| 163 |
|
| 164 |
wp_enqueue_style( 'charitable-admin' ); |
| 165 |
|
| 166 |
wp_register_script( |
| 167 |
'charitable-admin', |
| 168 |
$assets_path . 'js/charitable-admin' . $suffix . '.js', |
| 169 |
array( 'jquery-ui-datepicker', 'jquery-ui-tabs', 'jquery-ui-sortable' ), |
| 170 |
$version, |
| 171 |
false |
| 172 |
); |
| 173 |
|
| 174 |
wp_enqueue_script( 'charitable-admin' ); |
| 175 |
|
| 176 |
$localized_vars = apply_filters( 'charitable_localized_javascript_vars', array( |
| 177 |
'suggested_amount_description_placeholder' => __( 'Optional Description', 'charitable' ), |
| 178 |
'suggested_amount_placeholder' => __( 'Amount', 'charitable' ), |
| 179 |
) ); |
| 180 |
|
| 181 |
wp_localize_script( 'charitable-admin', 'CHARITABLE', $localized_vars ); |
| 182 |
} |
| 183 |
|
| 184 |
wp_register_script( |
| 185 |
'charitable-admin-notice', |
| 186 |
$assets_path . 'js/charitable-admin-notice' . $suffix . '.js', |
| 187 |
array( 'jquery-core' ), |
| 188 |
$version, |
| 189 |
false |
| 190 |
); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Add notices to the dashboard. |
| 195 |
* |
| 196 |
* @return void |
| 197 |
* @access public |
| 198 |
* @since 1.4.0 |
| 199 |
*/ |
| 200 |
public function add_notices() { |
| 201 |
|
| 202 |
/* Get any version update notices first. */ |
| 203 |
$this->add_version_update_notices(); |
| 204 |
|
| 205 |
/* Also pick up any settings notices. */ |
| 206 |
// $this->add_settings_update_notices(); |
| 207 |
|
| 208 |
/* Render notices. */ |
| 209 |
charitable_get_admin_notices()->render(); |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Add version update notices to the dashboard. |
| 215 |
* |
| 216 |
* @return void |
| 217 |
* @access public |
| 218 |
* @since 1.4.6 |
| 219 |
*/ |
| 220 |
public function add_version_update_notices() { |
| 221 |
|
| 222 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
$notices = array(); |
| 227 |
|
| 228 |
$notices['release-140'] = sprintf( __( "Thanks for upgrading to Charitable 1.4. <a href='%s'>Find out what's new in this release</a>.", 'charitable' ), |
| 229 |
'https://www.wpcharitable.com/charitable-1-4-features-responsive-campaign-grids-a-new-shortcode?utm_source=notice&utm_medium=wordpress-dashboard&utm_campaign=release-notes&utm_content=release-140' |
| 230 |
); |
| 231 |
|
| 232 |
$notices['release-142'] = sprintf( __( "In Charitable 1.4.2, we have improved the login and registration forms. <a href='%s'>Find out how</a>.", 'charitable' ), |
| 233 |
'https://www.wpcharitable.com/how-we-improved-logins-and-registrations-in-charitable/?utm_source=notice&utm_medium=wordpress-dashboard&utm_campaign=release-notes&utm_content=release-142' |
| 234 |
); |
| 235 |
|
| 236 |
if ( Charitable_Gateways::get_instance()->is_active_gateway( 'paypal' ) ) { |
| 237 |
|
| 238 |
$notices['release-143-paypal'] = sprintf( __( "PayPal is upgrading its SSL certificates. <a href='%s'>Test your integration now to avoid disruption.</a>", 'charitable' ), |
| 239 |
esc_url( add_query_arg( array( |
| 240 |
'page' => 'charitable-settings', |
| 241 |
'tab' => 'gateways', |
| 242 |
'group' => 'gateways_paypal', |
| 243 |
), admin_url( 'admin.php#paypal-sandbox-test' ) ) ) |
| 244 |
); |
| 245 |
|
| 246 |
} else { |
| 247 |
|
| 248 |
delete_transient( 'charitable_release-143-paypal_notice' ); |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
$helper = charitable_get_admin_notices(); |
| 253 |
|
| 254 |
foreach ( $notices as $notice => $message ) { |
| 255 |
|
| 256 |
if ( ! get_transient( 'charitable_' . $notice . '_notice' ) ) { |
| 257 |
continue; |
| 258 |
} |
| 259 |
|
| 260 |
$helper->add_version_update( $message, $notice ); |
| 261 |
|
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Dismiss a notice. |
| 267 |
* |
| 268 |
* @return void |
| 269 |
* @access public |
| 270 |
* @since 1.4.0 |
| 271 |
*/ |
| 272 |
public function dismiss_notice() { |
| 273 |
if ( ! isset( $_POST['notice'] ) ) { |
| 274 |
wp_send_json_error(); |
| 275 |
} |
| 276 |
|
| 277 |
$ret = delete_transient( 'charitable_' . $_POST['notice'] . '_notice', true ); |
| 278 |
|
| 279 |
if ( ! $ret ) { |
| 280 |
wp_send_json_error( $ret ); |
| 281 |
} |
| 282 |
|
| 283 |
wp_send_json_success(); |
| 284 |
} |
| 285 |
|
| 286 |
/** |
| 287 |
* Adds one or more classes to the body tag in the dashboard. |
| 288 |
* |
| 289 |
* @param string $classes Current body classes. |
| 290 |
* @return string Altered body classes. |
| 291 |
* @since 1.0.0 |
| 292 |
*/ |
| 293 |
public function add_admin_body_class( $classes ) { |
| 294 |
$screen = get_current_screen(); |
| 295 |
|
| 296 |
if ( Charitable::DONATION_POST_TYPE == $screen->post_type ) { |
| 297 |
$classes .= ' post-type-charitable'; |
| 298 |
} |
| 299 |
|
| 300 |
return $classes; |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Add custom links to the plugin actions. |
| 305 |
* |
| 306 |
* @param string[] $links |
| 307 |
* @return string[] |
| 308 |
* @access public |
| 309 |
* @since 1.0.0 |
| 310 |
*/ |
| 311 |
public function add_plugin_action_links( $links ) { |
| 312 |
$links[] = '<a href="' . admin_url( 'admin.php?page=charitable-settings' ) . '">' . __( 'Settings', 'charitable' ) . '</a>'; |
| 313 |
return $links; |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Add Extensions link to the plugin row meta. |
| 318 |
* |
| 319 |
* @param string[] $links |
| 320 |
* @param string $file The plugin file |
| 321 |
* @return string[] $links |
| 322 |
* @access public |
| 323 |
* @since 1.2.0 |
| 324 |
*/ |
| 325 |
public function add_plugin_row_meta( $links, $file ) { |
| 326 |
if ( plugin_basename( charitable()->get_path() ) != $file ) { |
| 327 |
return $links; |
| 328 |
} |
| 329 |
|
| 330 |
$extensions_link = esc_url( add_query_arg( array( |
| 331 |
'utm_source' => 'plugins-page', |
| 332 |
'utm_medium' => 'plugin-row', |
| 333 |
'utm_campaign' => 'admin', |
| 334 |
), |
| 335 |
'https://wpcharitable.com/extensions/' |
| 336 |
) ); |
| 337 |
|
| 338 |
$links[] = '<a href="' . $extensions_link . '">' . __( 'Extensions', 'charitable' ) . '</a>'; |
| 339 |
|
| 340 |
return $links; |
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* Remove the jQuery UI styles added by Ninja Forms. |
| 345 |
* |
| 346 |
* @return void |
| 347 |
* @access public |
| 348 |
* @since 1.2.0 |
| 349 |
*/ |
| 350 |
public function remove_jquery_ui_styles_nf( $context ) { |
| 351 |
wp_dequeue_style( 'jquery-smoothness' ); |
| 352 |
return $context; |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* Export donations. |
| 357 |
* |
| 358 |
* @return void |
| 359 |
* @access public |
| 360 |
* @since 1.3.0 |
| 361 |
*/ |
| 362 |
public function export_donations() { |
| 363 |
if ( ! wp_verify_nonce( $_GET['_charitable_export_nonce'], 'charitable_export_donations' ) ) { |
| 364 |
return false; |
| 365 |
} |
| 366 |
|
| 367 |
require_once( charitable()->get_path( 'admin' ) . 'reports/class-charitable-export-donations.php' ); |
| 368 |
|
| 369 |
$report_type = $_GET['report_type']; |
| 370 |
|
| 371 |
$export_args = apply_filters( 'charitable_donations_export_args', array( |
| 372 |
'start_date' => $_GET['start_date'], |
| 373 |
'end_date' => $_GET['end_date'], |
| 374 |
'status' => $_GET['post_status'], |
| 375 |
'campaign_id' => $_GET['campaign_id'], |
| 376 |
'report_type' => $report_type, |
| 377 |
) ); |
| 378 |
|
| 379 |
$export_class = apply_filters( 'charitable_donations_export_class', 'Charitable_Export_Donations', $report_type, $export_args ); |
| 380 |
|
| 381 |
new $export_class( $export_args ); |
| 382 |
|
| 383 |
exit(); |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* Returns an array of screen IDs where the Charitable scripts should be loaded. |
| 388 |
* |
| 389 |
* @uses charitable_admin_screens |
| 390 |
* @return array |
| 391 |
* @access public |
| 392 |
* @since 1.0.0 |
| 393 |
*/ |
| 394 |
public function get_charitable_screens() { |
| 395 |
return apply_filters( 'charitable_admin_screens', array( |
| 396 |
'campaign', |
| 397 |
'donation', |
| 398 |
'charitable_page_charitable-settings', |
| 399 |
'edit-donation', |
| 400 |
'dashboard', |
| 401 |
) ); |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
endif; |
| 406 |
|