| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Admin Hooks. |
| 4 |
* |
| 5 |
* @package Charitable/Functions/Admin |
| 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.3.0 |
| 10 |
* @version 1.6.40 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Enqueue Charitable's admin-area scripts & styles. |
| 20 |
* |
| 21 |
* @see Charitable_Admin::admin_enqueue_scripts() |
| 22 |
*/ |
| 23 |
add_action( 'admin_enqueue_scripts', array( Charitable_Admin::get_instance(), 'admin_enqueue_scripts' ) ); |
| 24 |
|
| 25 |
/** |
| 26 |
* Set custom admin body classes. |
| 27 |
* |
| 28 |
* @see Charitable_Admin::set_body_class() |
| 29 |
*/ |
| 30 |
add_filter( 'admin_body_class', array( Charitable_Admin::get_instance(), 'set_body_class' ) ); |
| 31 |
add_filter( 'admin_body_class', array( Charitable_User_Onboarding::get_instance(), 'add_body_class' ) ); |
| 32 |
|
| 33 |
/** |
| 34 |
* Do an admin action. |
| 35 |
* |
| 36 |
* @see Charitable_Admin::maybe_do_admin_action() |
| 37 |
*/ |
| 38 |
add_action( 'admin_init', array( Charitable_Admin::get_instance(), 'maybe_do_admin_action' ), 999 ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Check if there are any notices to be displayed in the admin. |
| 42 |
* |
| 43 |
* @see Charitable_Admin::add_notices() |
| 44 |
*/ |
| 45 |
add_action( 'admin_notices', array( Charitable_Admin::get_instance(), 'add_notices' ) ); |
| 46 |
|
| 47 |
/** |
| 48 |
* Dismiss a notice. |
| 49 |
* |
| 50 |
* @see Charitable_Admin::dismiss_notice() |
| 51 |
*/ |
| 52 |
add_action( 'wp_ajax_charitable_dismiss_notice', array( Charitable_Admin::get_instance(), 'dismiss_notice' ) ); |
| 53 |
|
| 54 |
/** |
| 55 |
* Dismiss a banner. |
| 56 |
* |
| 57 |
* @see Charitable_Admin::dismiss_banner() |
| 58 |
*/ |
| 59 |
add_action( 'wp_ajax_charitable_dismiss_admin_banner', array( Charitable_Admin::get_instance(), 'dismiss_banner' ) ); |
| 60 |
|
| 61 |
/** |
| 62 |
* Dismiss a list banner. |
| 63 |
* |
| 64 |
* @see Charitable_Admin::dismiss_banner() |
| 65 |
*/ |
| 66 |
add_action( 'wp_ajax_charitable_dismiss_admin_list_banner', array( Charitable_Admin::get_instance(), 'dismiss_list_banner' ) ); |
| 67 |
|
| 68 |
|
| 69 |
/** |
| 70 |
* Dismiss a five star rating request. |
| 71 |
* |
| 72 |
* @see Charitable_Admin::dismiss_five_star_rating() |
| 73 |
*/ |
| 74 |
add_action( 'wp_ajax_charitable_dismiss_admin_five_star_rating', array( Charitable_Admin::get_instance(), 'dismiss_five_star_rating' ) ); |
| 75 |
|
| 76 |
/** |
| 77 |
* Add a generic body class to donations page |
| 78 |
* |
| 79 |
* @see Charitable_Admin::add_admin_body_class() |
| 80 |
*/ |
| 81 |
add_filter( 'admin_body_class', array( Charitable_Admin::get_instance(), 'add_admin_body_class' ) ); |
| 82 |
|
| 83 |
/** |
| 84 |
* Remove jQuery UI styles added by Ninja Forms. |
| 85 |
* |
| 86 |
* @see Charitable_Admin::remove_jquery_ui_styles_nf() |
| 87 |
*/ |
| 88 |
// add_filter( 'media_buttons_context', array( Charitable_Admin::get_instance(), 'remove_jquery_ui_styles_nf' ), 20 ); |
| 89 |
|
| 90 |
/** |
| 91 |
* Add action links to the Charitable plugin block. |
| 92 |
* |
| 93 |
* @see Charitable_Admin::add_plugin_action_links() |
| 94 |
*/ |
| 95 |
add_filter( 'plugin_action_links_' . plugin_basename( charitable()->get_path() ), array( Charitable_Admin::get_instance(), 'add_plugin_action_links' ) ); |
| 96 |
|
| 97 |
/** |
| 98 |
* Add a link to the settings page from the Charitable plugin block. |
| 99 |
* |
| 100 |
* @see Charitable_Admin::add_plugin_row_meta() |
| 101 |
*/ |
| 102 |
add_filter( 'plugin_row_meta', array( Charitable_Admin::get_instance(), 'add_plugin_row_meta' ), 10, 2 ); |
| 103 |
|
| 104 |
/** |
| 105 |
* Export handlers. |
| 106 |
* |
| 107 |
* @see Charitable_Admin::export_donations() |
| 108 |
* @see Charitable_Admin::export_campaigns() |
| 109 |
*/ |
| 110 |
add_action( 'charitable_export_donations', array( Charitable_Admin::get_instance(), 'export_donations' ) ); |
| 111 |
add_action( 'charitable_export_campaigns', array( Charitable_Admin::get_instance(), 'export_campaigns' ) ); |
| 112 |
|
| 113 |
/** |
| 114 |
* Add Charitable menu. |
| 115 |
* |
| 116 |
* @see Charitable_Admin_Pages::add_menu() |
| 117 |
*/ |
| 118 |
add_action( 'admin_menu', array( Charitable_Admin_Pages::get_instance(), 'add_menu' ), 5 ); |
| 119 |
add_action( 'parent_file', array( Charitable_Admin_Pages::get_instance(), 'menu_highlight' ), 10 ); |
| 120 |
|
| 121 |
/** |
| 122 |
* Redirect to welcome page after install. |
| 123 |
* |
| 124 |
* @see Charitable_Admin_Pages::redirect_to_welcome() |
| 125 |
*/ |
| 126 |
add_action( 'charitable_install', array( Charitable_Admin_Pages::get_instance(), 'setup_welcome_redirect' ), 100 ); |
| 127 |
|
| 128 |
/** |
| 129 |
* Stash any notices that haven't been displayed. |
| 130 |
* |
| 131 |
* @see Charitable_Admin_Notices::shutdown() |
| 132 |
*/ |
| 133 |
add_action( 'shutdown', array( charitable_get_admin_notices(), 'shutdown' ) ); |
| 134 |
|
| 135 |
/** |
| 136 |
* Stash any notices that haven't been displayed. |
| 137 |
* |
| 138 |
* @see Charitable_Admin_Support::maybe_do_charitable_support_query() |
| 139 |
*/ |
| 140 |
add_action( 'admin_init', array( Charitable_Admin_Support::get_instance(), 'maybe_do_charitable_support_query' ), 100 ); |
| 141 |
|
| 142 |
/** |
| 143 |
* Enqueue Charitable's campaign builder related scripts & styles. |
| 144 |
* |
| 145 |
* @see Charitable_Campaign_Builder::add_page() |
| 146 |
*/ |
| 147 |
add_action( 'admin_menu', array( Charitable_Campaign_Builder::get_instance(), 'add_page' ), 5 ); |
| 148 |
|
| 149 |
/** |
| 150 |
* Enqueue Charitable's campaign builder related scripts & styles. |
| 151 |
* |
| 152 |
* @see Charitable_Campaign_Builder::init() |
| 153 |
*/ |
| 154 |
add_action( 'admin_init', array( Charitable_Campaign_Builder::get_instance(), 'init' ), 100 ); |
| 155 |
|
| 156 |
/** |
| 157 |
* Enqueue Charitable's campaign builder embed related scripts & styles. |
| 158 |
* |
| 159 |
* @see Charitable_Campaign_Embed_Wizard::init() |
| 160 |
*/ |
| 161 |
add_action( 'admin_init', array( Charitable_Campaign_Embed_Wizard::get_instance(), 'init' ), 100 ); |
| 162 |
|
| 163 |
/** |
| 164 |
* Enqueue Charitable's block releated scripts & styles. |
| 165 |
* |
| 166 |
* @see Charitable_Admin_Blocks::admin_enqueue_scripts() |
| 167 |
*/ |
| 168 |
add_action( 'admin_enqueue_scripts', array( Charitable_Admin_Blocks::get_instance(), 'admin_enqueue_scripts' ) ); |
| 169 |
|
| 170 |
/** |
| 171 |
* Enqueue Charitable's campaign builder congrats wizard related scripts & styles. |
| 172 |
* |
| 173 |
* @see Charitable_Campaign_Congrats_Wizard::init() |
| 174 |
*/ |
| 175 |
add_action( 'admin_init', array( Charitable_Campaign_Congrats_Wizard::get_instance(), 'init' ), 120 ); |
| 176 |
|
| 177 |
/** |
| 178 |
* Dismiss dashboard notices. |
| 179 |
* |
| 180 |
* @see Charitable_Admin::dismiss_dashboard_notice() |
| 181 |
*/ |
| 182 |
add_action( 'wp_ajax_charitable_dismiss_dashboard_notice', array( Charitable_Admin::get_instance(), 'dismiss_dashboard_notices' ) ); |
| 183 |
|
| 184 |
/** |
| 185 |
* Dismiss guide tool related notices. |
| 186 |
* |
| 187 |
* @see Charitable_Admin::dismiss_growth_tools_notices() |
| 188 |
*/ |
| 189 |
add_action( 'wp_ajax_charitable_dismiss_growth_tools_dashboard_notice', array( Charitable_Admin::get_instance(), 'dismiss_growth_tools_notices' ) ); |
| 190 |
|
| 191 |
/** |
| 192 |
* Do an admin action. |
| 193 |
* |
| 194 |
* @see Charitable_Admin::maybe_do_admin_action() |
| 195 |
*/ |
| 196 |
add_action( 'plugins_loaded', array( Charitable_Admin_Getting_Started::get_instance(), 'init' ), 999 ); |
| 197 |
|
| 198 |
/** |
| 199 |
* Insert HTML into the footer that can be used later by onboarding. |
| 200 |
* |
| 201 |
* @see Charitable_Campaign_Builder::render_onboarding_html() |
| 202 |
*/ |
| 203 |
add_action( 'admin_footer', array( Charitable_Campaign_Builder::get_instance(), 'render_onboarding_html' ), 5 ); |
| 204 |
|
| 205 |
/** |
| 206 |
* Save an onboarding options via AJAX. |
| 207 |
* |
| 208 |
* @see Charitable_Campaign_Builder::save_onboarding_option_ajax() |
| 209 |
*/ |
| 210 |
add_action( 'wp_ajax_charitable_onboarding_save_option', array( Charitable_Campaign_Builder::get_instance(), 'save_onboarding_option_ajax' ), 5 ); |
| 211 |
add_action( 'wp_ajax_charitable_onboarding_tour_save_option', array( Charitable_Campaign_Builder::get_instance(), 'save_tour_option_ajax' ), 5 ); |
| 212 |
add_action( 'wp_ajax_charitable_onboarding_checklist_save_option', array( Charitable_Checklist::get_instance(), 'save_checklist_option_ajax' ), 5 ); |
| 213 |
|
| 214 |
/** |
| 215 |
* Checklist: check to mark step as completed. |
| 216 |
* |
| 217 |
* @see Charitable_Checklist::check_step_first_donation() |
| 218 |
*/ |
| 219 |
add_action( 'admin_init', array( Charitable_Checklist::get_instance(), 'maybe_redirect_to_next_step' ), 999 ); |
| 220 |
|
| 221 |
/** |
| 222 |
* Plugin notifications, added mostly in 1.8.3. |
| 223 |
* |
| 224 |
* @see Charitable_Notifications::add_notifications_to_menu() |
| 225 |
* @see Charitable_Notifications::dismiss() |
| 226 |
* @see Charitable_Notifications::dismiss_multiple() |
| 227 |
* @see Charitable_Notifications::maybe_redirect_from_notifications() |
| 228 |
*/ |
| 229 |
add_filter( 'admin_init', array( Charitable_Notifications::get_instance(), 'init' ), 9 ); |
| 230 |
add_filter( 'charitable_submenu_pages', array( Charitable_Notifications::get_instance(), 'add_notifications_to_menu' ), 2 ); |
| 231 |
add_filter( 'wp_ajax_charitable_notification_dismiss', array( Charitable_Notifications::get_instance(), 'dismiss' ), 10 ); |
| 232 |
add_filter( 'wp_ajax_charitable_notification_dismiss_multiple', array( Charitable_Notifications::get_instance(), 'dismiss_multiple' ), 10 ); |
| 233 |
add_action( 'admin_init', array( Charitable_Notifications::get_instance(), 'maybe_redirect_from_notifications' ), 10 ); |
| 234 |
|
| 235 |
/** |
| 236 |
* Notifications v2 — Settings must init before Local Notifications and Cron |
| 237 |
* so is_category_enabled() is available to both. |
| 238 |
* |
| 239 |
* @since 1.8.12 |
| 240 |
*/ |
| 241 |
Charitable_Notification_Settings::get_instance()->init(); |
| 242 |
|
| 243 |
/** |
| 244 |
* Local Notifications — manages locally-generated notifications. |
| 245 |
* |
| 246 |
* @since 1.8.12 |
| 247 |
*/ |
| 248 |
Charitable_Local_Notifications::get_instance()->init(); |
| 249 |
|
| 250 |
/** |
| 251 |
* Notification Cron — schedules and runs periodic checks. |
| 252 |
* |
| 253 |
* @since 1.8.12 |
| 254 |
*/ |
| 255 |
Charitable_Notification_Cron::get_instance()->init(); |
| 256 |
|
| 257 |
/** |
| 258 |
* Notification Triggers — hook-based milestone and lifecycle events. |
| 259 |
* |
| 260 |
* @since 1.8.12 |
| 261 |
*/ |
| 262 |
Charitable_Notification_Triggers::get_instance()->init(); |
| 263 |
|
| 264 |
/** |
| 265 |
* Notifications V2 onboarding tour. |
| 266 |
* |
| 267 |
* @since 1.8.12 |
| 268 |
*/ |
| 269 |
// Charitable_Notification_Onboarding::get_instance()->init(); // TODO: re-enable before release |
| 270 |
|
| 271 |
/** |
| 272 |
* New Announcement Feed. |
| 273 |
* |
| 274 |
* @since 1.8.12 |
| 275 |
*/ |
| 276 |
Charitable_New_Feed::get_instance()->init(); |
| 277 |
|
| 278 |
/** |
| 279 |
* Notifications V2 test helper (admin-only). Triggered by ?charitable_notif_test=<action>. |
| 280 |
* |
| 281 |
* This is a development-only QA harness that seeds/clears notification state and |
| 282 |
* fires cron jobs on demand. It is a state-changing GET handler with no nonce, so |
| 283 |
* it must never be wired up in a production build. It is gated behind both WP_DEBUG |
| 284 |
* and an explicit opt-in constant; to enable it locally, define both in wp-config.php: |
| 285 |
* |
| 286 |
* define( 'WP_DEBUG', true ); |
| 287 |
* define( 'CHARITABLE_NOTIFICATION_TEST_HELPER', true ); |
| 288 |
* |
| 289 |
* @since 1.8.12 |
| 290 |
*/ |
| 291 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'CHARITABLE_NOTIFICATION_TEST_HELPER' ) && CHARITABLE_NOTIFICATION_TEST_HELPER ) { |
| 292 |
Charitable_Notification_Test_Helper::get_instance()->init(); |
| 293 |
add_action( 'admin_notices', array( Charitable_Notification_Test_Helper::get_instance(), 'maybe_show_notice' ) ); |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Event Driven notifications and items, added mostly in 1.8.3. |
| 298 |
* |
| 299 |
* @see Charitable_EventDriven::init() |
| 300 |
* @see Charitable_EventDriven::update_events() |
| 301 |
*/ |
| 302 |
add_action( 'plugins_loaded', array( Charitable_EventDriven::get_instance(), 'init' ), 999 ); |
| 303 |
add_filter( 'charitable_admin_notifications_update_data', array( Charitable_EventDriven::get_instance(), 'update_events' ), 9 ); |
| 304 |
|
| 305 |
/** |
| 306 |
* License checks. |
| 307 |
* |
| 308 |
* @see Charitable_Admin_Pages::add_menu() |
| 309 |
*/ |
| 310 |
add_action( 'admin_init', array( Charitable_Licenses_Settings::get_instance(), 'maybe_check_if_license_expired' ), 9999 ); |
| 311 |
add_action( 'admin_init', array( Charitable_Licenses_Settings::get_instance(), 'maybe_check_if_license_expiring' ), 9998 ); |
| 312 |
add_action( 'admin_init', array( Charitable_Licenses_Settings::get_instance(), 'activate_pro_plugin_after_license_activation' ), 1 ); |
| 313 |
|
| 314 |
/** |
| 315 |
* Connect for upgrade.wpcharitable.com. |
| 316 |
* |
| 317 |
* @see Charitable_Admin_Connect::settings_enqueues() |
| 318 |
* @see Charitable_Admin_Connect::generate_url() |
| 319 |
* @see Charitable_Admin_Connect::process() |
| 320 |
*/ |
| 321 |
add_action( 'after_charitable_admin_enqueue_scripts', array( Charitable_Admin_Connect::get_instance(), 'settings_enqueues' ), 10, 3 ); |
| 322 |
add_action( 'wp_ajax_charitable_connect_url', array( Charitable_Admin_Connect::get_instance(), 'generate_url' ) ); |
| 323 |
add_filter( 'charitable_license_verify_success_data', array( Charitable_Admin_Connect::get_instance(), 'add_upgrade_url_to_license_response' ), 10, 2 ); |
| 324 |
add_action( 'wp_ajax_nopriv_charitable_connect_process', array( Charitable_Admin_Connect::get_instance(), 'process' ) ); |
| 325 |
add_action( 'wp_ajax_charitable_download_pro', array( Charitable_Admin_Connect::get_instance(), 'download_pro_plugin' ) ); |
| 326 |
add_action( 'wp_ajax_charitable_activate_pro', array( Charitable_Admin_Connect::get_instance(), 'activate_pro_plugin' ) ); |
| 327 |
|
| 328 |
/** |
| 329 |
* Initialize splash data. |
| 330 |
* |
| 331 |
* @see Charitable_Admin_Splash::initialize_splash_data() |
| 332 |
*/ |
| 333 |
add_action( 'admin_init', [ Charitable_Admin_Splash::get_instance(), 'initialize_splash_data' ], 15 ); |
| 334 |
add_action( 'admin_enqueue_scripts', [ Charitable_Admin_Splash::get_instance(), 'admin_enqueue_scripts' ] ); |
| 335 |
add_action( 'admin_footer', [ Charitable_Admin_Splash::get_instance(), 'admin_footer' ] ); |
| 336 |
|
| 337 |
/** |
| 338 |
* Show a notice if GiveWP is detected. |
| 339 |
* |
| 340 |
* @see Charitable_GiveWP_Notice::get_dashboard_notices() |
| 341 |
*/ |
| 342 |
add_filter( 'charitable_admin_dashboard_init_end', array( Charitable_GiveWP_Notice::get_instance(), 'get_dashboard_notices' ), 10 ); |
| 343 |
|
| 344 |
/** |
| 345 |
* Display Charitable banners on external (non-Charitable) admin screens. |
| 346 |
* |
| 347 |
* @see Charitable_External_Banner |
| 348 |
*/ |
| 349 |
Charitable_External_Banner::get_instance(); |
| 350 |
|
| 351 |
/** |
| 352 |
* Dashboard AJAX handlers. |
| 353 |
* |
| 354 |
* @see Charitable_Dashboard::ajax_activate_addon() |
| 355 |
* @see Charitable_Dashboard::ajax_approve_comment() |
| 356 |
* @see Charitable_Dashboard::ajax_delete_comment() |
| 357 |
* @see Charitable_Dashboard::ajax_install_charitable_addon() |
| 358 |
* @see Charitable_Dashboard::ajax_activate_charitable_addon() |
| 359 |
*/ |
| 360 |
add_action( 'wp_ajax_charitable_activate_addon', array( Charitable_Dashboard::get_instance(), 'ajax_activate_addon' ) ); |
| 361 |
add_action( 'wp_ajax_charitable_approve_comment', array( Charitable_Dashboard::get_instance(), 'ajax_approve_comment' ) ); |
| 362 |
add_action( 'wp_ajax_charitable_delete_comment', array( Charitable_Dashboard::get_instance(), 'ajax_delete_comment' ) ); |
| 363 |
add_action( 'wp_ajax_charitable_install_charitable_addon', array( Charitable_Dashboard::get_instance(), 'ajax_install_charitable_addon' ) ); |
| 364 |
add_action( 'wp_ajax_charitable_activate_charitable_addon', array( Charitable_Dashboard::get_instance(), 'ajax_activate_charitable_addon' ) ); |
| 365 |
|