-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-dark-mode.php
More file actions
96 lines (87 loc) · 2.7 KB
/
Copy pathadmin-dark-mode.php
File metadata and controls
96 lines (87 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Plugin Name: Admin Dark Mode
* Plugin URI: https://github.com/coded-letter/admin-dark-mode
* Description: Adds a minimal dark mode switch to the WordPress admin bar and block editor.
* Tested up to: 7.0
* Version: 1.8.10
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: Coded Letter
* Author URI: https://codedletter.com/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: admin-dark-mode
* Update URI: https://github.com/coded-letter/admin-dark-mode
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'ADM_DARK_MODE_VERSION', '1.8.10' );
require_once plugin_dir_path( __FILE__ ) . 'includes/superfunky-update-client.php';
Superfunky_Update_Client::register_product(
array(
'access' => 'public',
'file' => __FILE__,
'name' => 'Admin Dark Mode',
'product_id' => 'admin-dark-mode',
'requires_php' => '7.4',
'slug' => 'admin-dark-mode',
'type' => 'plugin',
'url' => 'https://github.com/coded-letter/admin-dark-mode',
'version' => ADM_DARK_MODE_VERSION,
)
);
/**
* Adds the dark mode switch to the right end of the admin bar.
*
* @param WP_Admin_Bar $wp_admin_bar WordPress admin bar instance.
*/
function adm_add_admin_bar_toggle( $wp_admin_bar ) {
if ( ! is_admin() ) {
return;
}
$wp_admin_bar->add_node(
array(
'id' => 'adm-dark-mode-toggle',
'parent' => 'top-secondary',
'title' => '<span class="adm-dark-mode-icon" aria-hidden="true"></span><span class="screen-reader-text">' . esc_html__( 'Switch to dark mode', 'admin-dark-mode' ) . '</span>',
'href' => '#',
'meta' => array(
'class' => 'adm-dark-mode-toggle',
'title' => esc_attr__( 'Switch to dark mode', 'admin-dark-mode' ),
'aria-label' => esc_attr__( 'Switch to dark mode', 'admin-dark-mode' ),
),
)
);
}
add_action( 'admin_bar_menu', 'adm_add_admin_bar_toggle', 9999 );
/**
* Loads dark mode assets throughout the WordPress admin.
*/
function adm_enqueue_admin_assets() {
$asset_url = plugin_dir_url( __FILE__ ) . 'assets/';
$asset_path = plugin_dir_path( __FILE__ ) . 'assets/';
wp_enqueue_style(
'admin-dark-mode',
$asset_url . 'admin-dark-mode.css',
array(),
(string) filemtime( $asset_path . 'admin-dark-mode.css' )
);
wp_enqueue_script(
'admin-dark-mode',
$asset_url . 'admin-dark-mode.js',
array(),
(string) filemtime( $asset_path . 'admin-dark-mode.js' ),
false
);
wp_localize_script(
'admin-dark-mode',
'adminDarkMode',
array(
'darkLabel' => __( 'Switch to dark mode', 'admin-dark-mode' ),
'lightLabel' => __( 'Switch to light mode', 'admin-dark-mode' ),
)
);
}
add_action( 'admin_enqueue_scripts', 'adm_enqueue_admin_assets' );