| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Bottom Admin Toolbar |
| 4 |
* Plugin URI: https://wordpress.org/plugins/bottom-admin-toolbar/ |
| 5 |
* Description: Stick the WordPress admin bar to the bottom of the screen and hide it with a keyboard shortcut. |
| 6 |
* Version: 1.5.4 |
| 7 |
* Requires at least: 4.9 or higher |
| 8 |
* Requires PHP: 5.6 |
| 9 |
* Tested up to: 7.0 |
| 10 |
* Author: M . Code |
| 11 |
* License: GPL v2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* Contributors: M . Code |
| 14 |
*/ |
| 15 |
|
| 16 |
if ( ! class_exists( 'BottomAdminToolbar' ) ) : |
| 17 |
/** |
| 18 |
* BottomAdminToolbar |
| 19 |
*/ |
| 20 |
class BottomAdminToolbar { |
| 21 |
/** |
| 22 |
* Plugin version |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
const VERSION = '1.5.4'; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 32 |
define( 'BAB_PATH', plugin_dir_path( __FILE__ ) ); |
| 33 |
define( 'BAB_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets/' ); |
| 34 |
define( 'BAB_BASENAME', plugin_basename( __FILE__ ) ); |
| 35 |
add_action( 'after_setup_theme', array( $this, 'setup_admin_bar_support' ) ); |
| 36 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_files' ) ); |
| 37 |
add_action( 'admin_init', array( $this, 'register_settings_section' ) ); |
| 38 |
add_action( 'admin_menu', array( $this, 'register_submenu_page' ) ); |
| 39 |
|
| 40 |
if ( $this->should_show_in_admin() ) { |
| 41 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_files' ) ); |
| 42 |
} |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Register admin bar theme support. |
| 48 |
*/ |
| 49 |
public function setup_admin_bar_support() { |
| 50 |
add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Check if admin bar should be shown in admin area |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
private function should_show_in_admin() { |
| 59 |
$options = get_option( 'bab_show_in_admin' ); |
| 60 |
if ( ! is_array( $options ) || empty( $options ) ) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
$value = reset( $options ); |
| 64 |
return $value === 'yes'; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Enqueue custom files |
| 69 |
*/ |
| 70 |
public function enqueue_files() { |
| 71 |
if ( is_admin_bar_showing() ) { |
| 72 |
wp_enqueue_style( 'bab-css', BAB_ASSETS_URL . 'bab.css', array(), self::VERSION, 'all' ); |
| 73 |
wp_enqueue_script( 'bab-js', BAB_ASSETS_URL . 'bab.js', array(), self::VERSION, true ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Register settings section |
| 79 |
*/ |
| 80 |
public function register_settings_section() { |
| 81 |
|
| 82 |
register_setting( |
| 83 |
'bottom-admin-bar', |
| 84 |
'bab_show_in_admin', |
| 85 |
array( |
| 86 |
'sanitize_callback' => array( $this, 'sanitize_bab_show_in_admin' ), |
| 87 |
) |
| 88 |
); |
| 89 |
|
| 90 |
add_settings_section( |
| 91 |
'bab_settings_section', |
| 92 |
false, |
| 93 |
false, |
| 94 |
'bottom-admin-bar' |
| 95 |
); |
| 96 |
|
| 97 |
add_settings_field( |
| 98 |
'bab_show_in_admin', |
| 99 |
__( 'Activer dans l\'administration', 'bottom-admin-toolbar' ), |
| 100 |
array( $this, 'bab_show_in_admin_cb' ), |
| 101 |
'bottom-admin-bar', |
| 102 |
'bab_settings_section', |
| 103 |
array( |
| 104 |
'label_for' => 'bab_show_in_admin', |
| 105 |
'bab_custom_data' => 'custom', |
| 106 |
) |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Sanitize setting value |
| 112 |
* |
| 113 |
* @param array $input Input value. |
| 114 |
* @return array Sanitized value. |
| 115 |
*/ |
| 116 |
public function sanitize_bab_show_in_admin( $input ) { |
| 117 |
if ( ! is_array( $input ) ) { |
| 118 |
return array(); |
| 119 |
} |
| 120 |
$sanitized = array(); |
| 121 |
foreach ( $input as $key => $value ) { |
| 122 |
$sanitized[ sanitize_key( $key ) ] = ( 'yes' === $value ) ? 'yes' : 'no'; |
| 123 |
} |
| 124 |
return $sanitized; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Show html output |
| 129 |
*/ |
| 130 |
public function bab_show_in_admin_cb( $args ) { |
| 131 |
$options = get_option( 'bab_show_in_admin', array() ); |
| 132 |
$field_value = isset( $options[ $args['label_for'] ] ) ? $options[ $args['label_for'] ] : 'no'; |
| 133 |
?> |
| 134 |
<select id="<?php echo esc_attr( $args['label_for'] ); ?>" data-custom="<?php echo esc_attr( $args['bab_custom_data'] ); ?>" name="bab_show_in_admin[<?php echo esc_attr( $args['label_for'] ); ?>]"> |
| 135 |
<option value="yes" <?php selected( $field_value, 'yes' ); ?>> |
| 136 |
<?php esc_html_e( 'Oui', 'bottom-admin-toolbar' ); ?> |
| 137 |
</option> |
| 138 |
<option value="no" <?php selected( $field_value, 'no' ); ?>> |
| 139 |
<?php esc_html_e( 'Non', 'bottom-admin-toolbar' ); ?> |
| 140 |
</option> |
| 141 |
</select> |
| 142 |
<?php |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Register sub menu page |
| 147 |
*/ |
| 148 |
public function register_submenu_page() { |
| 149 |
add_submenu_page( |
| 150 |
'options-general.php', |
| 151 |
'Bottom Admin Toolbar', |
| 152 |
'Bottom Admin Toolbar', |
| 153 |
'manage_options', |
| 154 |
'bab-settings', |
| 155 |
array( $this, 'bab_settings_display' ) |
| 156 |
); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Display settings |
| 161 |
*/ |
| 162 |
public function bab_settings_display() { |
| 163 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
settings_errors( 'bottom-admin-bar' ); |
| 168 |
?> |
| 169 |
<div class="wrap"> |
| 170 |
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
| 171 |
<form action="options.php" method="post"> |
| 172 |
<?php |
| 173 |
settings_fields( 'bottom-admin-bar' ); |
| 174 |
do_settings_sections( 'bottom-admin-bar' ); |
| 175 |
submit_button( 'Sauvegarder' ); |
| 176 |
?> |
| 177 |
</form> |
| 178 |
</div> |
| 179 |
<?php |
| 180 |
} |
| 181 |
|
| 182 |
} |
| 183 |
new BottomAdminToolbar(); |
| 184 |
endif; |
| 185 |
|