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-pages.php

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

213 lines 6.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 * @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', 'manage_options' );
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( 'Charitable', 'Charitable', $this->admin_menu_capability, $this->admin_menu_parent_page, array( $this, 'render_welcome_page' ) );
84
85 foreach ( $this->get_submenu_pages() as $page ) {
86 if ( ! isset( $page[ 'page_title' ] )
87 || ! isset( $page[ 'menu_title' ] )
88 || ! isset( $page[ 'menu_slug' ] ) ) {
89 continue;
90 }
91
92 $page_title = $page[ 'page_title' ];
93 $menu_title = $page[ 'menu_title' ];
94 $capability = isset( $page[ 'capability' ] ) ? $page[ 'capability' ] : $this->admin_menu_capability;
95 $menu_slug = $page[ 'menu_slug' ];
96 $function = isset( $page[ 'function' ] ) ? $page[ 'function' ] : '';
97
98 add_submenu_page(
99 $this->admin_menu_parent_page,
100 $page_title,
101 $menu_title,
102 $capability,
103 $menu_slug,
104 $function
105 );
106 }
107 }
108
109 /**
110 * Returns an array with all the submenu pages.
111 *
112 * @return array
113 * @access private
114 * @since 1.0.0
115 */
116 private function get_submenu_pages() {
117 $campaign_post_type = get_post_type_object( 'campaign' );
118 $donation_post_type = get_post_type_object( 'donation' );
119
120 return apply_filters( 'charitable_submenu_pages', array(
121 array(
122 'page_title' => $campaign_post_type->labels->menu_name,
123 'menu_title' => $campaign_post_type->labels->menu_name,
124 'menu_slug' => 'edit.php?post_type=campaign'
125 ),
126 array(
127 'page_title' => $campaign_post_type->labels->add_new,
128 'menu_title' => $campaign_post_type->labels->add_new,
129 'menu_slug' => 'post-new.php?post_type=campaign'
130 ),
131 array(
132 'page_title' => $donation_post_type->labels->menu_name,
133 'menu_title' => $donation_post_type->labels->menu_name,
134 'menu_slug' => 'charitable-donations-table',
135 'function' => array( $this, 'render_donations_page' )
136 ),
137 array(
138 'page_title' => __( 'Campaign Categories', 'charitable' ),
139 'menu_title' => __( 'Categories', 'charitable' ),
140 'menu_slug' => 'edit-tags.php?taxonomy=campaign_category&post_type=campaign'
141 ),
142 array(
143 'page_title' => __( 'Campaign Tags', 'charitable' ),
144 'menu_title' => __( 'Tags', 'charitable' ),
145 'menu_slug' => 'edit-tags.php?taxonomy=campaign_tag&post_type=campaign'
146 ),
147 array(
148 'page_title' => __( 'Settings', 'charitable' ),
149 'menu_title' => __( 'Settings', 'charitable' ),
150 'menu_slug' => 'charitable-settings',
151 'function' => array( $this, 'render_settings_page' )
152 ),
153 ) );
154 }
155
156 /**
157 * Set up the redirect to the welcome page.
158 *
159 * @return void
160 * @access public
161 * @since 1.3.0
162 */
163 public function setup_welcome_redirect() {
164 add_action( 'admin_init', array( self::get_instance(), 'redirect_to_welcome' ) );
165 }
166
167 /**
168 * Redirect to the welcome page.
169 *
170 * @return void
171 * @access public
172 * @since 1.3.0
173 */
174 public function redirect_to_welcome() {
175 wp_safe_redirect( admin_url( 'admin.php?page=charitable&install=true' ) );
176 exit;
177 }
178
179 /**
180 * Display the Charitable settings page.
181 *
182 * @return void
183 * @access public
184 * @since 1.0.0
185 */
186 public function render_settings_page() {
187 charitable_admin_view( 'settings/settings' );
188 }
189
190 /**
191 * Display the Charitable donations page.
192 *
193 * @return void
194 * @access public
195 * @since 1.0.0
196 */
197 public function render_donations_page() {
198 charitable_admin_view( 'donations-page/page' );
199 }
200
201 /**
202 * Display the Charitable welcome page.
203 *
204 * @return void
205 * @access public
206 * @since 1.0.0
207 */
208 public function render_welcome_page() {
209 charitable_admin_view( 'welcome-page/page' );
210 }
211 }
212
213 endif; // End class_exists check