PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 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 All 46 releases
gamipress / includes / admin / settings / general.php

general.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at includes/admin/settings/general.php

178 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin General Settings
4 *
5 * @package GamiPress\Admin\Settings\General
6 * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.3.7
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * General Settings meta boxes
14 *
15 * @since 1.0.0
16 *
17 * @param array $meta_boxes
18 *
19 * @return array
20 */
21 function gamipress_settings_general_meta_boxes( $meta_boxes ) {
22
23 $meta_boxes['general-settings'] = array(
24 'title' => gamipress_dashicon( 'admin-generic' ) . __( 'General Settings', 'gamipress' ),
25 'fields' => apply_filters( 'gamipress_general_settings_fields', array(
26 'minimum_role' => array(
27 'name' => __( 'Minimum Access Role', 'gamipress' ),
28 'tooltip' => __( 'Minimum role a user needs to access to GamiPress management areas.', 'gamipress' ),
29 'label_cb' => 'cmb_tooltip_label_cb',
30 'type' => 'select',
31 'options' => gamipress_get_allowed_manager_capabilities(),
32 ),
33 'points_image_size' => array(
34 'name' => __( 'Points Image Size', 'gamipress' ),
35 'tooltip' => __( 'Maximum dimensions for the points featured image.', 'gamipress' ),
36 'label_cb' => 'cmb_tooltip_label_cb',
37 'type' => 'size',
38 'default' => array(
39 'width' => 50,
40 'height' => 50,
41 ),
42 ),
43 'achievement_image_size' => array(
44 'name' => __( 'Achievement Image Size', 'gamipress' ),
45 'tooltip' => __( 'Maximum dimensions for the achievements featured image.', 'gamipress' ),
46 'label_cb' => 'cmb_tooltip_label_cb',
47 'type' => 'size',
48 ),
49 'rank_image_size' => array(
50 'name' => __( 'Rank Image Size', 'gamipress' ),
51 'tooltip' => __( 'Maximum dimensions for ranks featured image.', 'gamipress' ),
52 'label_cb' => 'cmb_tooltip_label_cb',
53 'type' => 'size',
54 ),
55 'disable_admin_bar_menu' => array(
56 'name' => __( 'Disable Top Bar Menu', 'gamipress' ),
57 'tooltip' => __( 'Disable the GamiPress top bar menu.', 'gamipress' ),
58 'label_cb' => 'cmb_tooltip_label_cb',
59 'type' => 'checkbox',
60 'classes' => 'gamipress-switch',
61 ),
62 'disable_shortcodes_editor' => array(
63 'name' => __( 'Disable Shortcodes Editor', 'gamipress' ),
64 'tooltip' => __( 'Disable the shortcodes editor.', 'gamipress' ) . '<br>'
65 . '<small>' . __( 'Check this option if you are experiencing black screens in your theme settings or in your page builder forms.', 'gamipress' ) . '</small>',
66 'label_cb' => 'cmb_tooltip_label_cb',
67 'type' => 'checkbox',
68 'classes' => 'gamipress-switch',
69 ),
70 'debug_mode' => array(
71 'name' => __( 'Debug Mode', 'gamipress' ),
72 'tooltip' => __( 'Enable the GamiPress debug mode.', 'gamipress' ),
73 'label_cb' => 'cmb_tooltip_label_cb',
74 'type' => 'checkbox',
75 'classes' => 'gamipress-switch',
76 ),
77 'clear_cache' => array(
78 'name' => __( 'Clear Cache', 'gamipress' ),
79 'type' => 'html',
80 'content_cb' => 'gamipress_clear_cache_content_cb',
81 ),
82 ) )
83 );
84
85 return $meta_boxes;
86
87 }
88 add_filter( 'gamipress_settings_general_meta_boxes', 'gamipress_settings_general_meta_boxes' );
89
90 /**
91 * Register custom WordPress image size(s)
92 *
93 * @since 1.0.0
94 */
95 function gamipress_register_image_sizes() {
96
97 // Register points image size
98 $points_image_size = gamipress_get_option( 'points_image_size', array( 'width' => 50, 'height' => 50 ) );
99
100 add_image_size( 'gamipress-points', absint( $points_image_size['width'] ), absint( $points_image_size['height'] ) );
101
102 // Register achievement image size
103 $achievement_image_size = gamipress_get_option( 'achievement_image_size', array( 'width' => 100, 'height' => 100 ) );
104
105 add_image_size( 'gamipress-achievement', absint( $achievement_image_size['width'] ), absint( $achievement_image_size['height'] ) );
106
107 // Register rank image size
108 $rank_image_size = gamipress_get_option( 'rank_image_size', array( 'width' => 100, 'height' => 100 ) );
109
110 add_image_size( 'gamipress-rank', absint( $rank_image_size['width'] ), absint( $rank_image_size['height'] ) );
111
112 }
113 add_action( 'init', 'gamipress_register_image_sizes' );
114
115 /**
116 * Get capability required for GamiPress administration.
117 *
118 * @since 1.0.0
119 *
120 * @return string User capability.
121 */
122 function gamipress_get_manager_capability() {
123
124 $minimum_role = gamipress_get_option( 'minimum_role', 'manage_options' );
125 $allowed_capabilities = array_keys( gamipress_get_allowed_manager_capabilities() );
126
127 // Do not allow to bypass subscribers capability in any way
128 $excluded_capabilities = array( 'read' );
129
130 // Check if capability is allowed
131 if ( ! in_array( $minimum_role, $allowed_capabilities ) || in_array( $minimum_role, $excluded_capabilities ) ) {
132 // If not allowed, manually update the settings
133 $update_capability = get_option( 'gamipress_settings' );
134 $update_capability['minimum_role'] = 'manage_options';
135 update_option( 'gamipress_settings', $update_capability );
136
137 // Set minimum role to manage_options
138 $minimum_role = 'manage_options';
139
140 }
141
142 return $minimum_role;
143
144 }
145
146 /**
147 * Allowed capabilities
148 *
149 * @since 6.0.0
150 *
151 * @return array
152 */
153 function gamipress_get_allowed_manager_capabilities() {
154
155 if ( did_action( 'init' ) ) {
156 $allowed_capabilities = array(
157 'manage_options' => __( 'Administrator', 'gamipress' ),
158 'delete_others_posts' => __( 'Editor', 'gamipress' ),
159 'publish_posts' => __( 'Author', 'gamipress' ),
160 );
161 } else {
162 $allowed_capabilities = array(
163 'manage_options' => 'manage_options',
164 'delete_others_posts' => 'delete_others_posts',
165 'publish_posts' => 'publish_posts',
166 );
167 }
168
169 return apply_filters( 'gamipress_allowed_manager_capabilities', $allowed_capabilities );
170 }
171
172 function gamipress_clear_cache_content_cb( $field_args, $field ) {
173 $url = admin_url( 'admin.php?page=gamipress&gamipress-action=clear_cache' );
174 $nonce_url = wp_nonce_url( $url, 'clear_cache' );
175 ?>
176 <a href="<?php echo esc_attr( $nonce_url ); ?>" class="button button-primary"><?php _e( 'Clear cache now!', 'gamipress' ) ?></a>
177 <?php
178 }