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

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

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