PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / trunk
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI vtrunk
8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 7.8.6 7.8.5 All 44 releases
gamipress / includes / admin / pages / tools.php

tools.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI trunk, at includes/admin/pages/tools.php

229 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Tools Page
4 *
5 * @package GamiPress\Admin\Tools
6 * @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.1.5
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 // GamiPress Tools
13 // General
14 require_once GAMIPRESS_DIR . 'includes/admin/tools/bulk-awards.php';
15 require_once GAMIPRESS_DIR . 'includes/admin/tools/bulk-revokes.php';
16 require_once GAMIPRESS_DIR . 'includes/admin/tools/recount-activity.php';
17 require_once GAMIPRESS_DIR . 'includes/admin/tools/logs-clean-up.php';
18 require_once GAMIPRESS_DIR . 'includes/admin/tools/reset-data.php';
19 // Import/Export
20 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-achievements.php';
21 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-points.php';
22 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-ranks.php';
23 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-earnings.php';
24 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-setup.php';
25 require_once GAMIPRESS_DIR . 'includes/admin/tools/import-export-settings.php';
26 // System Info
27 require_once GAMIPRESS_DIR . 'includes/admin/tools/system-info.php';
28
29 /**
30 * Register tools page.
31 *
32 * @since 1.1.5
33 *
34 * @return void
35 */
36 function gamipress_register_tools_page() {
37
38 $tabs = array();
39 $boxes = array();
40
41 $is_tools_page = ( isset( $_GET['page'] ) && $_GET['page'] === 'gamipress_tools' );
42
43 if( $is_tools_page ) {
44
45 // Loop tools sections
46 foreach( gamipress_get_tools_sections() as $section_id => $section ) {
47
48 $meta_boxes = array();
49
50 /**
51 * Filter: gamipress_tools_{$section_id}_meta_boxes
52 *
53 * @param array $meta_boxes
54 *
55 * @return array
56 */
57 $meta_boxes = apply_filters( "gamipress_tools_{$section_id}_meta_boxes", $meta_boxes );
58
59 if( ! empty( $meta_boxes ) ) {
60
61 // Loop tools section meta boxes
62 foreach( $meta_boxes as $meta_box_id => $meta_box ) {
63
64 // Check meta box tabs
65 if( isset( $meta_box['tabs'] ) && ! empty( $meta_box['tabs'] ) ) {
66
67 // Loop meta box tabs
68 foreach( $meta_box['tabs'] as $tab_id => $tab ) {
69
70 $tab['id'] = $tab_id;
71
72 $meta_box['tabs'][$tab_id] = $tab;
73
74 }
75
76 }
77
78 // Only add tools meta box if has fields
79 if( isset( $meta_box['fields'] ) && ! empty( $meta_box['fields'] ) ) {
80
81 // Loop meta box fields
82 foreach( $meta_box['fields'] as $field_id => $field ) {
83
84 $field['id'] = $field_id;
85
86 $meta_box['fields'][$field_id] = $field;
87
88 }
89
90 $meta_box['id'] = $meta_box_id;
91
92 $meta_box['display_cb'] = false;
93 $meta_box['admin_menu_hook'] = false;
94 $meta_box['priority'] = 'high'; // Fixes issue with CMB2 2.9.0
95
96 $meta_box['show_on'] = array(
97 'key' => 'options-page',
98 'value' => array( 'gamipress_tools' ),
99 );
100
101 $box = new_cmb2_box( $meta_box );
102
103 $box->object_type( 'options-page' );
104
105 $boxes[] = $box;
106
107 }
108 }
109
110 $tabs[] = array(
111 'id' => $section_id,
112 'title' => ( ( isset( $section['icon'] ) ) ? '<i class="dashicons ' . $section['icon'] . '"></i>' : '' ) . $section['title'],
113 'desc' => '',
114 'boxes' => array_keys( $meta_boxes ),
115 );
116 }
117 }
118
119 }
120
121 $minimum_role = gamipress_get_manager_capability();
122
123 try {
124 // Create the options page
125 new Cmb2_Metatabs_Options( array(
126 'key' => 'gamipress_tools',
127 'class' => 'gamipress-page',
128 'title' => __( 'Tools', 'gamipress' ),
129 'topmenu' => 'gamipress',
130 'cols' => 1,
131 'boxes' => $boxes,
132 'tabs' => $tabs,
133 'menuargs' => array(
134 'menu_title' => __( 'Tools', 'gamipress' ),
135 'capability' => $minimum_role,
136 'view_capability' => $minimum_role,
137 ),
138 'savetxt' => false,
139 'resettxt' => false,
140 ) );
141 } catch ( Exception $e ) {
142
143 }
144
145 }
146 add_action( 'cmb2_admin_init', 'gamipress_register_tools_page', 11 );
147
148 /**
149 * GamiPress registered tools sections
150 *
151 * @since 1.1.5
152 *
153 * @return array
154 */
155 function gamipress_get_tools_sections() {
156
157 $gamipress_tools_sections = array(
158 'general' => array(
159 'title' => __( 'General', 'gamipress' ),
160 'icon' => 'dashicons-admin-tools',
161 ),
162 'import_export' => array(
163 'title' => __( 'Import/Export', 'gamipress' ),
164 'icon' => 'dashicons-upload',
165 ),
166 'system' => array(
167 'title' => __( 'System', 'gamipress' ),
168 'icon' => 'dashicons-performance',
169 ),
170 );
171
172 return apply_filters( 'gamipress_tools_sections', $gamipress_tools_sections );
173
174 }
175
176 /**
177 * GamiPress Tools Page bottom
178 *
179 * @since 1.1.5
180 *
181 * @param string $content Content to be filtered
182 * @param string $page Current page slug
183 *
184 * @return mixed string $host if detected, false otherwise
185 */
186 function gamipress_tools_page_bottom( $content, $page ) {
187
188 if( $page !== 'gamipress_tools' ) {
189 return $content;
190 }
191
192 $content = apply_filters( 'gamipress_tools_page_bottom', $content );
193
194 return $content;
195 }
196 add_filter( 'cmb2metatabs_after_form', 'gamipress_tools_page_bottom', 10, 2 );
197
198 /**
199 * Adds a custom nonce on the tools page
200 *
201 * @since 1.9.1.3
202 *
203 * @param array $cmb_id The current box ID.
204 * @param int $object_id The ID of the current object.
205 * @param string $object_type The type of object you are working with.
206 * Usually `post` (this applies to all post-types).
207 * Could also be `comment`, `user` or `options-page`.
208 * @param array $cmb This CMB2 object.
209 */
210 function gamipress_tools_nonce( $cmb_id, $object_id, $object_type, $cmb ) {
211
212 global $gamipress_tools_nonce;
213
214 if( $object_id !== 'gamipress_tools' ) {
215 return;
216 }
217
218 if( $object_type !== 'options-page' ) {
219 return;
220 }
221
222 if( $gamipress_tools_nonce ) {
223 return;
224 }
225
226 wp_nonce_field( 'gamipress_admin' );
227
228 }
229 add_action( 'cmb2_after_form', 'gamipress_tools_nonce', 10, 4 );