PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0
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-pages.php

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

325 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This class is responsible for adding the Charitable admin pages.
4 *
5 * @package Charitable/Classes/Charitable_Admin_Pages
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.6.39
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Admin_Pages' ) ) :
19
20 /**
21 * Charitable_Admin_Pages
22 *
23 * @since 1.0.0
24 */
25 final class Charitable_Admin_Pages {
26
27 /**
28 * The single instance of this class.
29 *
30 * @var Charitable_Admin_Pages|null
31 */
32 private static $instance = null;
33
34 /**
35 * The page to use when registering sections and fields.
36 *
37 * @var string
38 */
39 private $admin_menu_parent_page;
40
41 /**
42 * The capability required to view the admin menu.
43 *
44 * @var string
45 */
46 private $admin_menu_capability;
47
48 /**
49 * Create class object.
50 *
51 * @since 1.0.0
52 */
53 private function __construct() {
54 /**
55 * The default capability required to view Charitable pages.
56 *
57 * @since 1.0.0
58 *
59 * @param string $cap The capability required.
60 */
61 $this->admin_menu_capability = apply_filters( 'charitable_admin_menu_capability', 'view_charitable_sensitive_data' );
62 $this->admin_menu_parent_page = 'charitable';
63 }
64
65 /**
66 * Returns and/or create the single instance of this class.
67 *
68 * @since 1.2.0
69 *
70 * @return Charitable_Admin_Pages
71 */
72 public static function get_instance() {
73 if ( is_null( self::$instance ) ) {
74 self::$instance = new self();
75 }
76
77 return self::$instance;
78 }
79
80 /**
81 * This forces the charitable menu to be open for category and tag pages.
82 *
83 * @since 1.7.0
84 *
85 * @return string
86 */
87 public function menu_highlight( $parent_file ) {
88 global $current_screen;
89
90 $taxonomy = isset( $current_screen->taxonomy ) ? $current_screen->taxonomy : false;
91 if ( false !== $taxonomy && ( 'campaign_category' === $taxonomy || 'campaign_tag' === $taxonomy ) ) {
92 $parent_file = 'charitable';
93 }
94
95 $post_type = isset( $current_screen->post_type ) ? $current_screen->post_type : false;
96 if ( false !== $post_type && ( 'campaign' === $post_type || 'donation' === $post_type ) ) {
97 $parent_file = 'charitable';
98 }
99
100 return $parent_file;
101 }
102
103 /**
104 * Add Settings menu item under the Campaign menu tab.
105 *
106 * @since 1.0.0
107 *
108 * @return void
109 */
110 public function add_menu() {
111 add_menu_page(
112 'Charitable',
113 'Charitable',
114 'edit_campaigns',
115 $this->admin_menu_parent_page,
116 array( $this, 'render_welcome_page' )
117 );
118
119 foreach ( $this->get_submenu_pages() as $page ) {
120 if ( ! isset( $page['page_title'] )
121 || ! isset( $page['menu_title'] )
122 || ! isset( $page['menu_slug'] ) ) {
123 continue;
124 }
125
126 $page_title = $page['page_title'];
127 $menu_title = $page['menu_title'];
128 $capability = isset( $page['capability'] ) ? $page['capability'] : $this->admin_menu_capability;
129 $menu_slug = $page['menu_slug'];
130 $function = isset( $page['function'] ) ? $page['function'] : '';
131
132 add_submenu_page(
133 $this->admin_menu_parent_page,
134 $page_title,
135 $menu_title,
136 $capability,
137 $menu_slug,
138 $function
139 );
140 }
141 }
142
143 /**
144 * Returns an array with all the submenu pages.
145 *
146 * @since 1.0.0
147 *
148 * @return array
149 */
150 private function get_submenu_pages() {
151 $campaign_post_type = get_post_type_object( 'campaign' );
152 $donation_post_type = get_post_type_object( 'donation' );
153
154 /**
155 * Filter the list of submenu pages that come
156 * under the Charitable menu tab.
157 *
158 * @since 1.0.0
159 *
160 * @param array $pages Every page is an array with at least a page_title,
161 * menu_title and menu_slug set.
162 */
163 return apply_filters(
164 'charitable_submenu_pages',
165 array(
166 array(
167 'page_title' => $campaign_post_type->labels->menu_name,
168 'menu_title' => $campaign_post_type->labels->menu_name,
169 'menu_slug' => 'edit.php?post_type=campaign',
170 'capability' => 'edit_campaigns',
171 ),
172 array(
173 'page_title' => $campaign_post_type->labels->add_new,
174 'menu_title' => $campaign_post_type->labels->add_new,
175 'menu_slug' => 'post-new.php?post_type=campaign',
176 'capability' => 'edit_campaigns',
177 ),
178 array(
179 'page_title' => $donation_post_type->labels->menu_name,
180 'menu_title' => $donation_post_type->labels->menu_name,
181 'menu_slug' => 'edit.php?post_type=donation',
182 'capability' => 'edit_donations',
183 ),
184 array(
185 'page_title' => __( 'Campaign Categories', 'charitable' ),
186 'menu_title' => __( 'Categories', 'charitable' ),
187 'menu_slug' => 'edit-tags.php?taxonomy=campaign_category&post_type=campaign',
188 'capability' => 'manage_campaign_terms',
189 ),
190 array(
191 'page_title' => __( 'Campaign Tags', 'charitable' ),
192 'menu_title' => __( 'Tags', 'charitable' ),
193 'menu_slug' => 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign',
194 'capability' => 'manage_campaign_terms',
195 ),
196 array(
197 'page_title' => __( 'Customize', 'charitable' ),
198 'menu_title' => __( 'Customize', 'charitable' ),
199 'menu_slug' => 'customize.php?autofocus[panel]=charitable&url=' . $this->get_customizer_campaign_preview_url(),
200 'capability' => 'manage_charitable_settings',
201 ),
202 array(
203 'page_title' => __( 'Charitable Settings', 'charitable' ),
204 'menu_title' => __( 'Settings', 'charitable' ),
205 'menu_slug' => 'charitable-settings',
206 'function' => array( $this, 'render_settings_page' ),
207 'capability' => 'manage_charitable_settings',
208 ),
209 )
210 );
211 }
212
213 /**
214 * Set up the redirect to the welcome page.
215 *
216 * @since 1.3.0
217 *
218 * @return void
219 */
220 public function setup_welcome_redirect() {
221 add_action( 'admin_init', array( self::get_instance(), 'redirect_to_welcome' ) );
222 }
223
224 /**
225 * Redirect to the welcome page.
226 *
227 * @since 1.3.0
228 *
229 * @return void
230 */
231 public function redirect_to_welcome() {
232 wp_safe_redirect( admin_url( 'admin.php?page=charitable&install=true' ) );
233 exit;
234 }
235
236 /**
237 * Display the Charitable settings page.
238 *
239 * @since 1.0.0
240 *
241 * @return void
242 */
243 public function render_settings_page() {
244 charitable_admin_view( 'settings/settings' );
245 }
246
247 /**
248 * Display the Charitable donations page.
249 *
250 * @since 1.0.0
251 *
252 * @return void
253 *
254 * @deprecated 1.4.0
255 */
256 public function render_donations_page() {
257 charitable_get_deprecated()->deprecated_function(
258 __METHOD__,
259 '1.4.0',
260 __( 'Donations page now rendered by WordPress default manage_edit-donation_columns', 'charitable' )
261 );
262
263 charitable_admin_view( 'donations-page/page' );
264 }
265
266 /**
267 * Display the Charitable welcome page.
268 *
269 * @since 1.0.0
270 *
271 * @return void
272 */
273 public function render_welcome_page() {
274 charitable_admin_view( 'welcome-page/page' );
275 }
276
277 /**
278 * Return a preview URL for the customizer.
279 *
280 * @since 1.6.0
281 *
282 * @return string
283 */
284 private function get_customizer_campaign_preview_url() {
285 $campaign = Charitable_Campaigns::query(
286 array(
287 'posts_per_page' => 1,
288 'post_status' => 'publish',
289 'fields' => 'ids',
290 'meta_query' => array(
291 'relation' => 'OR',
292 array(
293 'key' => '_campaign_end_date',
294 'value' => date( 'Y-m-d H:i:s' ),
295 'compare' => '>=',
296 'type' => 'datetime',
297 ),
298 array(
299 'key' => '_campaign_end_date',
300 'value' => 0,
301 'compare' => '=',
302 ),
303 ),
304 )
305 );
306
307 if ( $campaign->found_posts ) {
308 $url = charitable_get_permalink(
309 'campaign_donation',
310 array(
311 'campaign_id' => current( $campaign->posts ),
312 )
313 );
314 }
315
316 if ( ! isset( $url ) || false === $url ) {
317 $url = home_url();
318 }
319
320 return urlencode( $url );
321 }
322 }
323
324 endif;
325