forked from helen/wp-style-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-style-guide.php
150 lines (128 loc) · 3.89 KB
/
wp-style-guide.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/*
Plugin Name: WordPress Admin Pattern Library
Plugin URI: https://github.com/helenhousandi/wp-style-guide
Description: Because it's horrible that we don't have one.
Version: 1.0
Author: The WordPress Team
Author URI: http://wordpress.org
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
class WP_Style_Guide {
/**
* Screens added.
* @var array
*/
private $screens;
/**
* Hook name of the top level page.
* @var string
*/
private $hookname;
/**
* Set up hooks.
*/
public function __construct() {
// define our screens
$this->screens = array(
'wp-patterns-forms' => array(
'page_title' => __( 'Forms' ),
'menu_title' => __( 'Forms' ),
'callback' => 'forms_page', // note that this has to be a class method
'hookname' => null,
),
'wp-patterns-jquery-ui' => array(
'page_title' => __( 'jQuery UI Components' ),
'menu_title' => __( 'jQuery UI Components' ),
'callback' => 'jquery_ui', // note that this has to be a class method
'hookname' => null,
),
'wp-patterns-helper-classes' => array(
'page_title' => __( 'Helper Classes' ),
'menu_title' => __( 'Helper Classes' ),
'callback' => 'helper_classes', // note that this has to be a class method
'hookname' => null,
),
);
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
/**
* Enqueue scripts and styles as needed.
* @return void
*/
public function admin_enqueue_scripts() {
if ( get_current_screen()->base === $this->screens['wp-patterns-jquery-ui']['hookname'] ) {
wp_enqueue_script( 'jquery-ui-accordion' );
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'jquery-ui-dialog' );
wp_enqueue_script( 'jquery-ui-slider' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-progressbar' );
wp_enqueue_script( 'jquery-ui-button' );
wp_enqueue_style( 'wp-jquery-ui', plugins_url( 'css/jquery-ui.css', __FILE__ ), false );
}
wp_enqueue_style( 'wp-style-guide', plugins_url( 'css/wp-style-guide.css', __FILE__ ), false );
wp_enqueue_style( 'dashicons-guide', plugins_url( 'css/dashicons.css', __FILE__ ), false );
}
public function admin_head() {
?>
<style>
.mp6 #adminmenu .<?php echo $this->hookname; ?> .wp-menu-image:before {
content: '\f309';
}
</style>
<?php
}
/**
* Add admin screens
* @return void
*/
public function admin_menu() {
$this->hookname = add_menu_page( 'WordPress Admin Pattern Library', 'Pattern Library', 'read', 'wp-patterns', array( $this, 'toc' ) );
foreach ( $this->screens as $slug => $args ) {
$this->screens[$slug]['hookname'] = add_submenu_page( 'wp-patterns', $args['page_title'], $args['menu_title'], 'read', $slug, array( $this, $args['callback'] ) );
}
}
/**
* Output for our top level screen
* @return void
*/
public function toc() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e( 'WordPress Admin Pattern Library' ); ?></h2>
<h3><?php _e( 'Table of Contents' ); ?></h3>
<ul class="ul-disc">
<?php foreach( $this->screens as $slug => $args ) : ?>
<li><a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $slug ) ); ?>"><?php echo esc_html( $args['page_title'] ); ?></a></li>
<?php endforeach; ?>
</ul>
</div><!-- .wrap -->
<?php
}
/**
* Output jQuery UI components admin page using jQuery UI's theme visual test
* @return void
*/
public function jquery_ui() {
include_once( 'pages/jquery-ui.php' );
}
/**
* Output form component admin page
* @return void
*/
public function forms_page() {
include_once( 'pages/forms-page.php' );
}
public function helper_classes() {
include_once( 'pages/helper-classes.php' );
}
public function dashicons() {
include_once( 'pages/dashicons.php' );
}
}
$wp_style_guide = new WP_Style_Guide;