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

207 lines 5.2 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
96 $is_settings = isset( $_POST['charitable_settings'] );
97
98 if ( ! $is_settings || empty( $tab ) ) {
99 return $is_settings;
100 }
101
102 return array_key_exists( $tab, $_POST['charitable_settings'] );
103 }
104
105 $is_settings = isset( $_GET['page'] ) && 'charitable-settings' == $_GET['page'];
106
107 if ( ! $is_settings || empty( $tab ) ) {
108 return $is_settings;
109 }
110
111 /* The general tab can be loaded when tab is not set. */
112 if ( 'general' == $tab ) {
113 return ! isset( $_GET['tab'] ) || 'general' == $_GET['tab'];
114 }
115
116 return isset( $_GET['tab'] ) && $tab == $_GET['tab'];
117 }
118
119 /**
120 * Print out the settings fields for a particular settings section.
121 *
122 * This is based on WordPress' do_settings_fields but allows the possibility
123 * of leaving out a field lable/title, for fullwidth fields.
124 *
125 * @see do_settings_fields
126 *
127 * @since 1.0.0
128 *
129 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
130 *
131 * @param string $page Slug title of the admin page who's settings fields you want to show.
132 * @param string $section Slug title of the settings section who's fields you want to show.
133 * @return string
134 */
135 function charitable_do_settings_fields( $page, $section ) {
136 global $wp_settings_fields;
137
138 if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
139 return;
140 }
141
142 foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) {
143 $class = '';
144
145 if ( ! empty( $field['args']['class'] ) ) {
146 $class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
147 }
148
149 echo "<tr{$class}>";
150
151 if ( ! empty( $field['args']['label_for'] ) ) {
152 echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
153 echo '<td>';
154 call_user_func( $field['callback'], $field['args'] );
155 echo '</td>';
156 } elseif ( ! empty( $field['title'] ) ) {
157 echo '<th scope="row">' . $field['title'] . '</th>';
158 echo '<td>';
159 call_user_func( $field['callback'], $field['args'] );
160 echo '</td>';
161 } else {
162 echo '<td colspan="2" class="charitable-fullwidth">';
163 call_user_func( $field['callback'], $field['args'] );
164 echo '</td>';
165 }
166
167 echo '</tr>';
168 }
169 }
170
171 /**
172 * Add new tab to the Charitable settings area.
173 *
174 * @since 1.3.0
175 *
176 * @param string[] $tabs
177 * @param string $key
178 * @param string $name
179 * @param mixed[] $args
180 * @return string[]
181 */
182 function charitable_add_settings_tab( $tabs, $key, $name, $args = array() ) {
183 $defaults = array(
184 'index' => 3,
185 );
186
187 $args = wp_parse_args( $args, $defaults );
188 $keys = array_keys( $tabs );
189 $values = array_values( $tabs );
190
191 array_splice( $keys, $args['index'], 0, $key );
192 array_splice( $values, $args['index'], 0, $name );
193
194 return array_combine( $keys, $values );
195 }
196
197 /**
198 * Return the donation actions class.
199 *
200 * @since 1.5.0
201 *
202 * @return Charitable_Donation_Admin_Actions
203 */
204 function charitable_get_donation_actions() {
205 return Charitable_Admin::get_instance()->get_donation_actions();
206 }
207