PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.60
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.60
1.8.13 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 All 211 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.6.60, at includes/admin/class-charitable-admin-pages.php

302 lines 7.2 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 Eric Daams
7 * @copyright Copyright (c) 2022, Studio 164a
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 * Add Settings menu item under the Campaign menu tab.
82 *
83 * @since 1.0.0
84 *
85 * @return void
86 */
87 public function add_menu() {
88 add_menu_page(
89 'Charitable',
90 'Charitable',
91 'edit_campaigns',
92 $this->admin_menu_parent_page,
93 array( $this, 'render_welcome_page' )
94 );
95
96 foreach ( $this->get_submenu_pages() as $page ) {
97 if ( ! isset( $page['page_title'] )
98 || ! isset( $page['menu_title'] )
99 || ! isset( $page['menu_slug'] ) ) {
100 continue;
101 }
102
103 $page_title = $page['page_title'];
104 $menu_title = $page['menu_title'];
105 $capability = isset( $page['capability'] ) ? $page['capability'] : $this->admin_menu_capability;
106 $menu_slug = $page['menu_slug'];
107 $function = isset( $page['function'] ) ? $page['function'] : '';
108
109 add_submenu_page(
110 $this->admin_menu_parent_page,
111 $page_title,
112 $menu_title,
113 $capability,
114 $menu_slug,
115 $function
116 );
117 }
118 }
119
120 /**
121 * Returns an array with all the submenu pages.
122 *
123 * @since 1.0.0
124 *
125 * @return array
126 */
127 private function get_submenu_pages() {
128 $campaign_post_type = get_post_type_object( 'campaign' );
129 $donation_post_type = get_post_type_object( 'donation' );
130
131 /**
132 * Filter the list of submenu pages that come
133 * under the Charitable menu tab.
134 *
135 * @since 1.0.0
136 *
137 * @param array $pages Every page is an array with at least a page_title,
138 * menu_title and menu_slug set.
139 */
140 return apply_filters(
141 'charitable_submenu_pages',
142 array(
143 array(
144 'page_title' => $campaign_post_type->labels->menu_name,
145 'menu_title' => $campaign_post_type->labels->menu_name,
146 'menu_slug' => 'edit.php?post_type=campaign',
147 'capability' => 'edit_campaigns',
148 ),
149 array(
150 'page_title' => $campaign_post_type->labels->add_new,
151 'menu_title' => $campaign_post_type->labels->add_new,
152 'menu_slug' => 'post-new.php?post_type=campaign',
153 'capability' => 'edit_campaigns',
154 ),
155 array(
156 'page_title' => $donation_post_type->labels->menu_name,
157 'menu_title' => $donation_post_type->labels->menu_name,
158 'menu_slug' => 'edit.php?post_type=donation',
159 'capability' => 'edit_donations',
160 ),
161 array(
162 'page_title' => __( 'Campaign Categories', 'charitable' ),
163 'menu_title' => __( 'Categories', 'charitable' ),
164 'menu_slug' => 'edit-tags.php?taxonomy=campaign_category&post_type=campaign',
165 'capability' => 'manage_campaign_terms',
166 ),
167 array(
168 'page_title' => __( 'Campaign Tags', 'charitable' ),
169 'menu_title' => __( 'Tags', 'charitable' ),
170 'menu_slug' => 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign',
171 'capability' => 'manage_campaign_terms',
172 ),
173 array(
174 'page_title' => __( 'Customize', 'charitable' ),
175 'menu_title' => __( 'Customize', 'charitable' ),
176 'menu_slug' => 'customize.php?autofocus[panel]=charitable&url=' . $this->get_customizer_campaign_preview_url(),
177 'capability' => 'manage_charitable_settings',
178 ),
179 array(
180 'page_title' => __( 'Charitable Settings', 'charitable' ),
181 'menu_title' => __( 'Settings', 'charitable' ),
182 'menu_slug' => 'charitable-settings',
183 'function' => array( $this, 'render_settings_page' ),
184 'capability' => 'manage_charitable_settings',
185 ),
186 )
187 );
188 }
189
190 /**
191 * Set up the redirect to the welcome page.
192 *
193 * @since 1.3.0
194 *
195 * @return void
196 */
197 public function setup_welcome_redirect() {
198 add_action( 'admin_init', array( self::get_instance(), 'redirect_to_welcome' ) );
199 }
200
201 /**
202 * Redirect to the welcome page.
203 *
204 * @since 1.3.0
205 *
206 * @return void
207 */
208 public function redirect_to_welcome() {
209 wp_safe_redirect( admin_url( 'admin.php?page=charitable&install=true' ) );
210 exit;
211 }
212
213 /**
214 * Display the Charitable settings page.
215 *
216 * @since 1.0.0
217 *
218 * @return void
219 */
220 public function render_settings_page() {
221 charitable_admin_view( 'settings/settings' );
222 }
223
224 /**
225 * Display the Charitable donations page.
226 *
227 * @since 1.0.0
228 *
229 * @return void
230 *
231 * @deprecated 1.4.0
232 */
233 public function render_donations_page() {
234 charitable_get_deprecated()->deprecated_function(
235 __METHOD__,
236 '1.4.0',
237 __( 'Donations page now rendered by WordPress default manage_edit-donation_columns', 'charitable' )
238 );
239
240 charitable_admin_view( 'donations-page/page' );
241 }
242
243 /**
244 * Display the Charitable welcome page.
245 *
246 * @since 1.0.0
247 *
248 * @return void
249 */
250 public function render_welcome_page() {
251 charitable_admin_view( 'welcome-page/page' );
252 }
253
254 /**
255 * Return a preview URL for the customizer.
256 *
257 * @since 1.6.0
258 *
259 * @return string
260 */
261 private function get_customizer_campaign_preview_url() {
262 $campaign = Charitable_Campaigns::query(
263 array(
264 'posts_per_page' => 1,
265 'post_status' => 'publish',
266 'fields' => 'ids',
267 'meta_query' => array(
268 'relation' => 'OR',
269 array(
270 'key' => '_campaign_end_date',
271 'value' => date( 'Y-m-d H:i:s' ),
272 'compare' => '>=',
273 'type' => 'datetime',
274 ),
275 array(
276 'key' => '_campaign_end_date',
277 'value' => 0,
278 'compare' => '=',
279 ),
280 ),
281 )
282 );
283
284 if ( $campaign->found_posts ) {
285 $url = charitable_get_permalink(
286 'campaign_donation',
287 array(
288 'campaign_id' => current( $campaign->posts ),
289 )
290 );
291 }
292
293 if ( ! isset( $url ) || false === $url ) {
294 $url = home_url();
295 }
296
297 return urlencode( $url );
298 }
299 }
300
301 endif;
302