PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.7
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 / charitable-core-admin-functions.php

charitable-core-admin-functions.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.7, at includes/admin/charitable-core-admin-functions.php

206 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Core Admin Functions
4 *
5 * General core functions available only within the admin area.
6 *
7 * @package Charitable/Functions/Admin
8 * @version 1.0.0
9 * @author Eric Daams
10 * @copyright Copyright (c) 2018, Studio 164a
11 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) { exit; }
16
17 /**
18 * Load a view from the admin/views folder.
19 *
20 * If the view is not found, an Exception will be thrown.
21 *
22 * Example usage: charitable_admin_view('metaboxes/campaign-title');
23 *
24 * @since 1.0.0
25 *
26 * @param string $view The view to display.
27 * @param array $view_args Optional. Arguments to pass through to the view itself.
28 * @return boolean True if the view exists and was rendered. False otherwise.
29 */
30 function charitable_admin_view( $view, $view_args = array() ) {
31 $base_path = array_key_exists( 'base_path', $view_args ) ? $view_args['base_path'] : charitable()->get_path( 'admin' ) . 'views/';
32
33 /**
34 * Filter the path to the view.
35 *
36 * @since 1.0.0
37 *
38 * @param string $path The default path.
39 * @param string $view The view.
40 * @param array $view_args View args.
41 */
42 $filename = apply_filters( 'charitable_admin_view_path', $base_path . $view . '.php', $view, $view_args );
43
44 if ( ! is_readable( $filename ) ) {
45 charitable_get_deprecated()->doing_it_wrong(
46 __FUNCTION__,
47 __( 'Passed view (' . $filename . ') not found or is not readable.', 'charitable' ),
48 '1.0.0'
49 );
50
51 return false;
52 }
53
54 ob_start();
55
56 include( $filename );
57
58 ob_end_flush();
59
60 return true;
61 }
62
63 /**
64 * Returns the Charitable_Settings helper.
65 *
66 * @since 1.0.0
67 *
68 * @return Charitable_Settings
69 */
70 function charitable_get_admin_settings() {
71 return Charitable_Settings::get_instance();
72 }
73
74 /**
75 * Returns the Charitable_Admin_Notices helper.
76 *
77 * @since 1.4.6
78 *
79 * @return Charitable_Admin_Notices
80 */
81 function charitable_get_admin_notices() {
82 return charitable()->registry()->get( 'admin_notices' );
83 }
84
85 /**
86 * Returns whether we are currently viewing the Charitable settings area.
87 *
88 * @since 1.2.0
89 *
90 * @param string $tab Optional. If passed, the function will also check that we are on the given tab.
91 * @return boolean
92 */
93 function charitable_is_settings_view( $tab = '' ) {
94 if ( ! empty( $_POST ) ) {
95 $is_settings = array_key_exists( 'option_page', $_POST ) && 'charitable_settings' === $_POST['option_page'];
96
97 if ( ! $is_settings || empty( $tab ) ) {
98 return $is_settings;
99 }
100
101 return array_key_exists( 'charitable_settings', $_POST ) && array_key_exists( $tab, $_POST['charitable_settings'] );
102 }
103
104 $is_settings = isset( $_GET['page'] ) && 'charitable-settings' == $_GET['page'];
105
106 if ( ! $is_settings || empty( $tab ) ) {
107 return $is_settings;
108 }
109
110 /* The general tab can be loaded when tab is not set. */
111 if ( 'general' == $tab ) {
112 return ! isset( $_GET['tab'] ) || 'general' == $_GET['tab'];
113 }
114
115 return isset( $_GET['tab'] ) && $tab == $_GET['tab'];
116 }
117
118 /**
119 * Print out the settings fields for a particular settings section.
120 *
121 * This is based on WordPress' do_settings_fields but allows the possibility
122 * of leaving out a field lable/title, for fullwidth fields.
123 *
124 * @see do_settings_fields
125 *
126 * @since 1.0.0
127 *
128 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
129 *
130 * @param string $page Slug title of the admin page who's settings fields you want to show.
131 * @param string $section Slug title of the settings section who's fields you want to show.
132 * @return string
133 */
134 function charitable_do_settings_fields( $page, $section ) {
135 global $wp_settings_fields;
136
137 if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
138 return;
139 }
140
141 foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
142 $class = '';
143
144 if ( ! empty( $field['args']['class'] ) ) {
145 $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
146 }
147
148 echo "<tr{$class}>";
149
150 if ( ! empty( $field['args']['label_for'] ) ) {
151 echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
152 echo '<td>';
153 call_user_func( $field['callback'], $field['args'] );
154 echo '</td>';
155 } elseif ( ! empty( $field['title'] ) ) {
156 echo '<th scope="row">' . $field['title'] . '</th>';
157 echo '<td>';
158 call_user_func( $field['callback'], $field['args'] );
159 echo '</td>';
160 } else {
161 echo '<td colspan="2" class="charitable-fullwidth">';
162 call_user_func( $field['callback'], $field['args'] );
163 echo '</td>';
164 }
165
166 echo '</tr>';
167 }
168 }
169
170 /**
171 * Add new tab to the Charitable settings area.
172 *
173 * @since 1.3.0
174 *
175 * @param string[] $tabs
176 * @param string $key
177 * @param string $name
178 * @param mixed[] $args
179 * @return string[]
180 */
181 function charitable_add_settings_tab( $tabs, $key, $name, $args = array() ) {
182 $defaults = array(
183 'index' => 3,
184 );
185
186 $args = wp_parse_args( $args, $defaults );
187 $keys = array_keys( $tabs );
188 $values = array_values( $tabs );
189
190 array_splice( $keys, $args['index'], 0, $key );
191 array_splice( $values, $args['index'], 0, $name );
192
193 return array_combine( $keys, $values );
194 }
195
196 /**
197 * Return the donation actions class.
198 *
199 * @since 1.5.0
200 *
201 * @return Charitable_Donation_Admin_Actions
202 */
203 function charitable_get_donation_actions() {
204 return Charitable_Admin::get_instance()->get_donation_actions();
205 }
206