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

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