| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin General Settings |
| 4 |
* |
| 5 |
* @package GamiPress\Admin\Settings\General |
| 6 |
* @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 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 GamiPress shortcodes editor.', 'gamipress' ), |
| 65 |
'label_cb' => 'cmb_tooltip_label_cb', |
| 66 |
'type' => 'checkbox', |
| 67 |
'classes' => 'gamipress-switch', |
| 68 |
), |
| 69 |
) ) |
| 70 |
); |
| 71 |
|
| 72 |
$meta_boxes['general-advanced-settings'] = array( |
| 73 |
'title' => gamipress_dashicon( 'admin-settings' ) . __( 'Advanced Settings', 'gamipress' ), |
| 74 |
'fields' => apply_filters( 'gamipress_general_advanced_settings_fields', array( |
| 75 |
'debug_mode' => array( |
| 76 |
'name' => __( 'Debug Mode', 'gamipress' ), |
| 77 |
'tooltip' => __( 'Enable the GamiPress debug mode.', 'gamipress' ), |
| 78 |
'label_cb' => 'cmb_tooltip_label_cb', |
| 79 |
'type' => 'checkbox', |
| 80 |
'classes' => 'gamipress-switch', |
| 81 |
), |
| 82 |
'clear_cache' => array( |
| 83 |
'name' => __( 'Clear Cache', 'gamipress' ), |
| 84 |
'tooltip' => __( 'Clear the GamiPress internal cache.', 'gamipress' ), |
| 85 |
'label_cb' => 'cmb_tooltip_label_cb', |
| 86 |
'type' => 'html', |
| 87 |
'content_cb' => 'gamipress_clear_cache_content_cb', |
| 88 |
), |
| 89 |
) ) |
| 90 |
); |
| 91 |
|
| 92 |
return $meta_boxes; |
| 93 |
|
| 94 |
} |
| 95 |
add_filter( 'gamipress_settings_general_meta_boxes', 'gamipress_settings_general_meta_boxes' ); |
| 96 |
|
| 97 |
/** |
| 98 |
* Register custom WordPress image size(s) |
| 99 |
* |
| 100 |
* @since 1.0.0 |
| 101 |
*/ |
| 102 |
function gamipress_register_image_sizes() { |
| 103 |
|
| 104 |
// Register points image size |
| 105 |
$points_image_size = gamipress_get_option( 'points_image_size', array( 'width' => 50, 'height' => 50 ) ); |
| 106 |
|
| 107 |
add_image_size( 'gamipress-points', absint( $points_image_size['width'] ), absint( $points_image_size['height'] ) ); |
| 108 |
|
| 109 |
// Register achievement image size |
| 110 |
$achievement_image_size = gamipress_get_option( 'achievement_image_size', array( 'width' => 100, 'height' => 100 ) ); |
| 111 |
|
| 112 |
add_image_size( 'gamipress-achievement', absint( $achievement_image_size['width'] ), absint( $achievement_image_size['height'] ) ); |
| 113 |
|
| 114 |
// Register rank image size |
| 115 |
$rank_image_size = gamipress_get_option( 'rank_image_size', array( 'width' => 100, 'height' => 100 ) ); |
| 116 |
|
| 117 |
add_image_size( 'gamipress-rank', absint( $rank_image_size['width'] ), absint( $rank_image_size['height'] ) ); |
| 118 |
|
| 119 |
} |
| 120 |
add_action( 'init', 'gamipress_register_image_sizes' ); |
| 121 |
|
| 122 |
/** |
| 123 |
* Get capability required for GamiPress administration. |
| 124 |
* |
| 125 |
* @since 1.0.0 |
| 126 |
* |
| 127 |
* @return string User capability. |
| 128 |
*/ |
| 129 |
function gamipress_get_manager_capability() { |
| 130 |
|
| 131 |
$minimum_role = gamipress_get_option( 'minimum_role', 'manage_options' ); |
| 132 |
$allowed_capabilities = array_keys( gamipress_get_allowed_manager_capabilities() ); |
| 133 |
|
| 134 |
// Do not allow to bypass subscribers capability in any way |
| 135 |
$excluded_capabilities = array( 'read' ); |
| 136 |
|
| 137 |
// Check if capability is allowed |
| 138 |
if ( ! in_array( $minimum_role, $allowed_capabilities ) || in_array( $minimum_role, $excluded_capabilities ) ) { |
| 139 |
// If not allowed, manually update the settings |
| 140 |
$update_capability = get_option( 'gamipress_settings' ); |
| 141 |
$update_capability['minimum_role'] = 'manage_options'; |
| 142 |
update_option( 'gamipress_settings', $update_capability ); |
| 143 |
|
| 144 |
// Set minimum role to manage_options |
| 145 |
$minimum_role = 'manage_options'; |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
return $minimum_role; |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Allowed capabilities |
| 155 |
* |
| 156 |
* @since 6.0.0 |
| 157 |
* |
| 158 |
* @return array |
| 159 |
*/ |
| 160 |
function gamipress_get_allowed_manager_capabilities() { |
| 161 |
|
| 162 |
if ( did_action( 'init' ) ) { |
| 163 |
$allowed_capabilities = array( |
| 164 |
'manage_options' => __( 'Administrator', 'gamipress' ), |
| 165 |
'delete_others_posts' => __( 'Editor', 'gamipress' ), |
| 166 |
'publish_posts' => __( 'Author', 'gamipress' ), |
| 167 |
); |
| 168 |
} else { |
| 169 |
$allowed_capabilities = array( |
| 170 |
'manage_options' => 'manage_options', |
| 171 |
'delete_others_posts' => 'delete_others_posts', |
| 172 |
'publish_posts' => 'publish_posts', |
| 173 |
); |
| 174 |
} |
| 175 |
|
| 176 |
return apply_filters( 'gamipress_allowed_manager_capabilities', $allowed_capabilities ); |
| 177 |
} |
| 178 |
|
| 179 |
function gamipress_clear_cache_content_cb( $field_args, $field ) { |
| 180 |
$url = admin_url( 'admin.php?page=gamipress&gamipress-action=clear_cache' ); |
| 181 |
$nonce_url = wp_nonce_url( $url, 'clear_cache' ); |
| 182 |
?> |
| 183 |
<a href="<?php echo esc_attr( $nonce_url ); ?>" class="button button-primary"><?php _e( 'Clear cache now!', 'gamipress' ) ?></a> |
| 184 |
<?php |
| 185 |
} |