PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.3.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.3.2
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / admin / class-charitable-admin.php

class-charitable-admin.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.3.2, at includes/admin/class-charitable-admin.php

255 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
47 /**
48 * Returns and/or create the single instance of this class.
49 *
50 * @return Charitable_Admin
51 * @access public
52 * @since 1.2.0
53 */
54 public static function get_instance() {
55 if ( is_null( self::$instance ) ) {
56 self::$instance = new Charitable_Admin();
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * Include admin-only files.
64 *
65 * @return void
66 * @access private
67 * @since 1.0.0
68 */
69 private function load_dependencies() {
70 $admin_dir = charitable()->get_path( 'admin' );
71
72 require_once( $admin_dir . 'charitable-core-admin-functions.php' );
73 require_once( $admin_dir . 'class-charitable-meta-box-helper.php' );
74 require_once( $admin_dir . 'class-charitable-admin-pages.php' );
75
76 /* Campaigns */
77 require_once( $admin_dir . 'campaigns/class-charitable-campaign-post-type.php' );
78
79 /* Donations */
80 require_once( $admin_dir . 'donations/class-charitable-donation-post-type.php' );
81
82 /* Settings */
83 require_once( $admin_dir . 'settings/class-charitable-settings.php' );
84 require_once( $admin_dir . 'settings/class-charitable-general-settings.php' );
85 require_once( $admin_dir . 'settings/class-charitable-email-settings.php' );
86 require_once( $admin_dir . 'settings/class-charitable-gateway-settings.php' );
87 require_once( $admin_dir . 'settings/class-charitable-licenses-settings.php' );
88 require_once( $admin_dir . 'settings/class-charitable-advanced-settings.php' );
89 require_once( $admin_dir . 'settings/charitable-settings-admin-hooks.php' );
90
91 /* Dashboard widgets */
92 require_once( $admin_dir . 'dashboard-widgets/class-charitable-donations-dashboard-widget.php' );
93 require_once( $admin_dir . 'dashboard-widgets/charitable-dashboard-widgets-hooks.php' );
94
95 /* Upgrades */
96 require_once( $admin_dir . 'upgrades/class-charitable-upgrade.php' );
97 require_once( $admin_dir . 'upgrades/class-charitable-upgrade-page.php' );
98 require_once( $admin_dir . 'upgrades/charitable-upgrade-hooks.php' );
99
100 /**
101 * We are registering this object only for backwards compatibility. It
102 * will be removed in or after Charitable 1.3.
103 *
104 * @deprecated
105 */
106 charitable()->register_object( Charitable_Settings::get_instance() );
107 charitable()->register_object( Charitable_Campaign_Post_Type::get_instance() );
108 charitable()->register_object( Charitable_Donation_Post_Type::get_instance() );
109 charitable()->register_object( Charitable_Admin_Pages::get_instance() );
110 }
111
112 /**
113 * Loads admin-only scripts and stylesheets.
114 *
115 * @global WP_Scripts $wp_scripts
116 * @return void
117 * @access public
118 * @since 1.0.0
119 */
120 public function admin_enqueue_scripts() {
121 global $wp_scripts;
122
123 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
124
125 /* Menu styles are loaded everywhere in the WordPress dashboard. */
126 wp_register_style( 'charitable-admin-menu', charitable()->get_path( 'assets', false ) . 'css/charitable-admin-menu' .$suffix . '.css', array(), charitable()->get_version() );
127 wp_enqueue_style( 'charitable-admin-menu' );
128
129 /* Admin page styles are registered but only enqueued when necessary. */
130 wp_register_style( 'charitable-admin-pages', charitable()->get_path( 'assets', false ) . 'css/charitable-admin-pages' .$suffix . '.css', array(), charitable()->get_version() );
131
132 /* The following styles are only loaded on Charitable screens. */
133 $screen = get_current_screen();
134
135 if ( in_array( $screen->id, $this->get_charitable_screens() ) ) {
136
137 wp_register_style( 'charitable-admin', charitable()->get_path( 'assets', false ) . 'css/charitable-admin' . $suffix . '.css', array(), charitable()->get_version() );
138 wp_enqueue_style( 'charitable-admin' );
139
140 wp_register_script( 'charitable-admin', charitable()->get_path( 'assets', false ) . 'js/charitable-admin' . $suffix . '.js', array( 'jquery-ui-datepicker', 'jquery-ui-tabs', 'jquery-ui-sortable' ), charitable()->get_version(), false );
141 wp_enqueue_script( 'charitable-admin' );
142
143 $localized_vars = apply_filters( 'charitable_localized_javascript_vars', array(
144 'suggested_amount_placeholder' => __( 'Amount', 'charitable' ),
145 'suggested_amount_description_placeholder' => __( 'Optional Description', 'charitable' )
146 ) );
147
148 wp_localize_script( 'charitable-admin', 'CHARITABLE', $localized_vars );
149 }
150 }
151
152 /**
153 * Add custom links to the plugin actions.
154 *
155 * @param string[] $links
156 * @return string[]
157 * @access public
158 * @since 1.0.0
159 */
160 public function add_plugin_action_links( $links ) {
161 $links[] = '<a href="' . admin_url( 'admin.php?page=charitable-settings' ) . '">' . __( 'Settings', 'charitable' ) . '</a>';
162 return $links;
163 }
164
165 /**
166 * Add Extensions link to the plugin row meta.
167 *
168 * @param string[] $links
169 * @param string $file The plugin file
170 * @return string[] $links
171 * @access public
172 * @since 1.2.0
173 */
174 public function add_plugin_row_meta( $links, $file ) {
175 if ( plugin_basename( charitable()->get_path() ) != $file ) {
176 return $links;
177 }
178
179 $extensions_link = esc_url( add_query_arg( array(
180 'utm_source' => 'plugins-page',
181 'utm_medium' => 'plugin-row',
182 'utm_campaign' => 'admin'
183 ),
184 'https://wpcharitable.com/extensions/'
185 ) );
186
187 $links[] = '<a href="' . $extensions_link . '">' . __( 'Extensions', 'charitable' ) . '</a>';
188
189 return $links;
190 }
191
192 /**
193 * Remove the jQuery UI styles added by Ninja Forms.
194 *
195 * @return void
196 * @access public
197 * @since 1.2.0
198 */
199 public function remove_jquery_ui_styles_nf( $context ) {
200 wp_dequeue_style( 'jquery-smoothness' );
201 return $context;
202 }
203
204 /**
205 * Export donations.
206 *
207 * @return void
208 * @access public
209 * @since 1.3.0
210 */
211 public function export_donations() {
212 if ( ! wp_verify_nonce( $_GET[ '_charitable_export_nonce' ], 'charitable_export_donations' ) ) {
213 return false;
214 }
215
216 require_once( charitable()->get_path( 'admin' ) . 'reports/class-charitable-export-donations.php' );
217
218 $report_type = $_GET[ 'report_type' ];
219
220 $export_args = apply_filters( 'charitable_donations_export_args', array(
221 'start_date' => $_GET[ 'start_date' ],
222 'end_date' => $_GET[ 'end_date' ],
223 'status' => $_GET[ 'post_status' ],
224 'campaign_id' => $_GET[ 'campaign_id' ],
225 'report_type' => $report_type
226 ) );
227
228 $export_class = apply_filters( 'charitable_donations_export_class', 'Charitable_Export_Donations', $report_type, $export_args );
229
230 new $export_class( $export_args );
231
232 exit();
233 }
234
235 /**
236 * Returns an array of screen IDs where the Charitable scripts should be loaded.
237 *
238 * @uses charitable_admin_screens
239 *
240 * @return array
241 * @access private
242 * @since 1.0.0
243 */
244 private function get_charitable_screens() {
245 return apply_filters( 'charitable_admin_screens', array(
246 'campaign',
247 'donation',
248 'charitable_page_charitable-settings',
249 'charitable_page_charitable-donations-table',
250 'dashboard'
251 ) );
252 }
253 }
254
255 endif;