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

228 lines 5.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 * @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 // Exit if accessed directly
13 if ( ! defined( 'ABSPATH' ) ) { exit; }
14
15 if ( ! class_exists( 'Charitable_Admin_Pages' ) ) :
16
17 /**
18 * Charitable_Admin_Pages
19 *
20 * @since 1.0.0
21 */
22 final class Charitable_Admin_Pages {
23
24 /**
25 * The single instance of this class.
26 *
27 * @var Charitable_Admin_Pages|null
28 * @access private
29 * @static
30 */
31 private static $instance = null;
32
33 /**
34 * The page to use when registering sections and fields.
35 *
36 * @var string
37 * @access private
38 */
39 private $admin_menu_parent_page;
40
41 /**
42 * The capability required to view the admin menu.
43 *
44 * @var string
45 * @access private
46 */
47 private $admin_menu_capability;
48
49 /**
50 * Create class object.
51 *
52 * @access private
53 * @since 1.0.0
54 */
55 private function __construct() {
56 $this->admin_menu_capability = apply_filters( 'charitable_admin_menu_capability', 'view_charitable_sensitive_data' );
57 $this->admin_menu_parent_page = 'charitable';
58 }
59
60 /**
61 * Returns and/or create the single instance of this class.
62 *
63 * @return Charitable_Admin_Pages
64 * @access public
65 * @since 1.2.0
66 */
67 public static function get_instance() {
68 if ( is_null( self::$instance ) ) {
69 self::$instance = new Charitable_Admin_Pages();
70 }
71
72 return self::$instance;
73 }
74
75 /**
76 * Add Settings menu item under the Campaign menu tab.
77 *
78 * @return void
79 * @access public
80 * @since 1.0.0
81 */
82 public function add_menu() {
83 add_menu_page(
84 'Charitable',
85 'Charitable',
86 $this->admin_menu_capability,
87 $this->admin_menu_parent_page,
88 array( $this, 'render_welcome_page' )
89 );
90
91 foreach ( $this->get_submenu_pages() as $page ) {
92 if ( ! isset( $page['page_title'] )
93 || ! isset( $page['menu_title'] )
94 || ! isset( $page['menu_slug'] ) ) {
95 continue;
96 }
97
98 $page_title = $page['page_title'];
99 $menu_title = $page['menu_title'];
100 $capability = isset( $page['capability'] ) ? $page['capability'] : $this->admin_menu_capability;
101 $menu_slug = $page['menu_slug'];
102 $function = isset( $page['function'] ) ? $page['function'] : '';
103
104 add_submenu_page(
105 $this->admin_menu_parent_page,
106 $page_title,
107 $menu_title,
108 $capability,
109 $menu_slug,
110 $function
111 );
112 }
113 }
114
115 /**
116 * Returns an array with all the submenu pages.
117 *
118 * @return array
119 * @access private
120 * @since 1.0.0
121 */
122 private function get_submenu_pages() {
123 $campaign_post_type = get_post_type_object( 'campaign' );
124 $donation_post_type = get_post_type_object( 'donation' );
125
126 return apply_filters( 'charitable_submenu_pages', array(
127 array(
128 'page_title' => $campaign_post_type->labels->menu_name,
129 'menu_title' => $campaign_post_type->labels->menu_name,
130 'menu_slug' => 'edit.php?post_type=campaign',
131 ),
132 array(
133 'page_title' => $campaign_post_type->labels->add_new,
134 'menu_title' => $campaign_post_type->labels->add_new,
135 'menu_slug' => 'post-new.php?post_type=campaign',
136 ),
137 array(
138 'page_title' => $donation_post_type->labels->menu_name,
139 'menu_title' => $donation_post_type->labels->menu_name,
140 'menu_slug' => 'edit.php?post_type=donation',
141 ),
142 array(
143 'page_title' => __( 'Campaign Categories', 'charitable' ),
144 'menu_title' => __( 'Categories', 'charitable' ),
145 'menu_slug' => 'edit-tags.php?taxonomy=campaign_category&post_type=campaign',
146 ),
147 array(
148 'page_title' => __( 'Campaign Tags', 'charitable' ),
149 'menu_title' => __( 'Tags', 'charitable' ),
150 'menu_slug' => 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign',
151 ),
152 array(
153 'page_title' => __( 'Charitable Settings', 'charitable' ),
154 'menu_title' => __( 'Settings', 'charitable' ),
155 'menu_slug' => 'charitable-settings',
156 'function' => array( $this, 'render_settings_page' ),
157 'capability' => 'manage_charitable_settings',
158 ),
159 ) );
160 }
161
162 /**
163 * Set up the redirect to the welcome page.
164 *
165 * @return void
166 * @access public
167 * @since 1.3.0
168 */
169 public function setup_welcome_redirect() {
170 add_action( 'admin_init', array( self::get_instance(), 'redirect_to_welcome' ) );
171 }
172
173 /**
174 * Redirect to the welcome page.
175 *
176 * @return void
177 * @access public
178 * @since 1.3.0
179 */
180 public function redirect_to_welcome() {
181 wp_safe_redirect( admin_url( 'admin.php?page=charitable&install=true' ) );
182 exit;
183 }
184
185 /**
186 * Display the Charitable settings page.
187 *
188 * @return void
189 * @access public
190 * @since 1.0.0
191 */
192 public function render_settings_page() {
193 charitable_admin_view( 'settings/settings' );
194 }
195
196 /**
197 * Display the Charitable donations page.
198 *
199 * @return void
200 * @access public
201 * @since 1.0.0
202 *
203 * @deprecated 1.4.0
204 */
205 public function render_donations_page() {
206 charitable_get_deprecated()->deprecated_function(
207 __METHOD__,
208 '1.4.0',
209 __( 'Donations page now rendered by WordPress default manage_edit-donation_columns', 'charitable' )
210 );
211
212 charitable_admin_view( 'donations-page/page' );
213 }
214
215 /**
216 * Display the Charitable welcome page.
217 *
218 * @return void
219 * @access public
220 * @since 1.0.0
221 */
222 public function render_welcome_page() {
223 charitable_admin_view( 'welcome-page/page' );
224 }
225 }
226
227 endif; // End class_exists check
228