-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
WpAdminStyle.php
executable file
·429 lines (365 loc) · 10.5 KB
/
WpAdminStyle.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?php /** @noinspection HtmlUnknownTarget */
/**
* Plugin Name: WordPress Admin Style
* Plugin URI: https://github.com/bueltge/wordpress-admin-style
* Text Domain: WpAdminStyle
* Domain Path: /languages
* GitHub URI: https://github.com/bueltge/wordpress-admin-style
* GitHub Plugin URI: https://github.com/bueltge/wordpress-admin-style
* Description: Shows the WordPress admin styles on one page to help you to develop WordPress compliant.
* Author: Frank Bültge
* Version: 1.6.1
* Licence: GPLv2+
* License URI: ./LICENSE
* Author URI: https://bueltge.de
* Last Change: 2023-12-22
*/
! defined( 'ABSPATH' ) && exit;
add_action(
'plugins_loaded',
array( WpAdminStyle::get_instance(), 'plugin_setup' )
);
/**
* Class WpAdminStyle
*/
class WpAdminStyle {
/**
* Characters there we replace in the files.
*
* @var array
*/
protected static $file_replace = array( '.php', '_', '-', ' ' );
/**
* Directory of patters of examples.
*
* @var string
*/
protected $patterns_dir = '';
/**
* Constructor
*
* @since 0.0.1
*/
public function __construct() {
}
/**
* Points the class, singleton.
*
* @access public
* @since 0.0.1
*/
public static function get_instance() {
static $instance;
if ( null === $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Used for regular plugin work.
*
* @wp-hook plugins_loaded
* @since 05/02/2013
*/
public function plugin_setup() {
$this->load_classes();
if ( ! is_admin() ) {
return null;
}
$this->patterns_dir = plugin_dir_path( __FILE__ ) . 'patterns';
// add menu item incl. the example source.
add_action( 'admin_menu', array( $this, 'add_menu_page' ) );
// Plugin love.
add_filter( 'plugin_row_meta', array( $this, 'donate_link' ), 10, 2 );
}
/**
* Scans the plugins subfolder and include files.
*
* @return void
* @since 05/02/2013
*/
protected function load_classes() {
// Load required classes.
foreach ( glob( __DIR__ . '/inc/*.php' ) as $path ) {
/** @noinspection PhpIncludeInspection */
require_once $path;
}
}
/**
* Add Menu item on WP Backend
*
* @return void
* @since 0.0.1
* @uses add_menu_page
* @access public
*/
public function add_menu_page() {
$page_hook_suffix = add_menu_page(
esc_html__( 'WordPress Admin Style', 'WpAdminStyle' ),
esc_html__( 'Admin Style', 'WpAdminStyle' ),
'read',
'WordPress_Admin_Style',
array( $this, 'get_style_examples' )
);
add_action( 'admin_print_scripts-' . $page_hook_suffix, array( $this, 'enqueue_assets' ) );
}
/**
* Echo Markup examples
*
* @return void
* @since 0.0.1
* @uses
* @access public
*/
public function get_style_examples() {
?>
<div class="wrap">
<h1><?php echo esc_html( $this->get_plugin_data( 'Name' ) ); ?></h1>
<?php
$this->get_mini_menu();
$files = $this->get_patterns();
// Load files and get data for view and list source.
foreach ( $files as $file ) {
$anker = str_replace( self::$file_replace, '', $file );
$patterns = $this->patterns_dir . '/' . $file;
echo '<section class="pattern" id="' . esc_attr( $anker ) . '">';
/** @noinspection PhpIncludeInspection */
include_once $patterns;
echo '<details class="primer" style="display: inline-block; width: 100%;">';
echo '<summary title="Show markup and usage">••• '
. esc_attr__( 'Show markup and usage', 'WpAdminStyle' )
. '</summary>';
echo '<section>';
echo '<pre><code class="language-php">';
echo htmlspecialchars(
file_get_contents(
$patterns,
FILE_USE_INCLUDE_PATH
),
ENT_QUOTES
);
echo '</code></pre>';
echo '</section>';
echo '</details><!--/.primer-->';
echo '<p>';
echo '<a class="alignright button" href="javascript:void(0);" onclick="window.scrollTo(0,0);" style="margin:3px 0 0 30px;">' . esc_attr__(
'scroll to top',
'WpAdminStyle'
)
. '</a><br class="clear" />';
echo '</p>';
echo '</section><!--/.pattern-->';
echo '<hr>';
}
?>
</div> <!-- .wrap -->
<?php
}
/**
* Return plugin comment data.
*
* @param string $value default = 'Version'
* also possible is: Name, PluginURI, Version, Description, Author,
* AuthorURI, TextDomain, DomainPath, Network, Title.
*
* @return string
* @uses get_plugin_data
* @access public
* @since 0.0.1
*/
private function get_plugin_data( $value = 'Version' ) {
static $plugin_data = array();
// fetch the data just once.
if ( isset( $plugin_data[ $value ] ) ) {
return $plugin_data[ $value ];
}
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __FILE__ );
return empty( $plugin_data[ $value ] ) ? '' : $plugin_data[ $value ];
}
/**
* Print the mini menu for a short navigation.
*/
public function get_mini_menu() {
$patterns = $this->get_patterns( 'headers' );
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<!-- main content -->
<div id="post-body-content">
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2><span><?php esc_attr_e( 'MiniMenu', 'WpAdminStyle' ); ?></span></h2>
<div class="inside">
<table class="widefat">
<?php
$class = '';
foreach ( $patterns as $pattern ) {
$class = '' === $class ? $class = ' class="alternate"' : '';
$anker = str_replace( self::$file_replace, '', $pattern );
?>
<tr<?php echo $class; ?>>
<td class="row-title">
<a href="#<?php echo esc_attr( $anker ); ?>">
<?php echo esc_attr( ucfirst( $pattern ) ); ?>
</a>
</td>
</tr>
<?php
} // end foreach patterns
?>
</table>
</div>
<!-- .inside -->
</div>
<!-- .postbox -->
</div>
<!-- .meta-box-sortables .ui-sortable -->
</div>
<!-- post-body-content -->
<!-- sidebar -->
<div id="postbox-container-1" class="postbox-container">
<div class="meta-box-sortables">
<div class="postbox">
<h2><span><?php esc_attr_e( 'About the plugin', 'WpAdminStyle' ); ?></span></h2>
<div class="inside">
<p>
<?php
printf(
// translators: The two strings will be replaced by the url to the development repository and the post about the idea.
__(
'Please read more about this small plugin on <a href="%1$s">github</a> or in <a href="%2$s">this post</a> on the blog of WP Engineer.',
'WpAdminStyle'
),
'https://github.com/bueltge/WordPress-Admin-Style',
'http://wpengineer.com/2226/new-plugin-to-style-your-plugin-on-wordpress-admin-with-default-styles/'
);
?>
</p>
<p>© Copyright 2008 - <?php echo esc_attr( date( 'Y' ) ); ?>
<a href="https://bueltge.de">Frank Bültge</a></p>
</div>
</div>
<!-- .postbox -->
<div class="postbox">
<h2><span><?php esc_attr_e( 'Resources & Reference', 'WpAdminStyle' ); ?></span></h2>
<div class="inside">
<ul>
<li>
<a href="https://developer.wordpress.org/block-editor/designers/">Editor
'Gutenberg' Designer Documentation, include patterns and resources</a>
</li>
<li>
<a href="http://dotorgstyleguide.wordpress.com/">WordPress.org UI Style
Guide</a>
</li>
<li>
<a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/html/">HTML
Coding Standards</a>
</li>
<li>
<a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/">CSS
Coding Standards</a>
</li>
<li>
<a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/">PHP
Coding Standards</a>
</li>
<li>
<a href="https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/">JavaScript
Coding Standards</a>
</li>
<li><a href="https://make.wordpress.org/design/">WordPress UI Group</a></li>
</ul>
</div>
</div>
<!-- .postbox -->
</div>
<!-- .meta-box-sortables -->
</div>
<!-- #postbox-container-1 .postbox-container -->
</div>
<br class="clear">
</div>
<?php
}
/**
* Return list of pattern files or name of files
*
* @param string $type Type of patters, default '', possible is 'headers'.
*
* @param bool $sort
*
* @return array|mixed
* @since 2015-03-25
*/
public function get_patterns( $type = '', $sort = true ) {
$files = array();
$this->patterns_dir = plugin_dir_path( __FILE__ ) . 'patterns';
$handle = opendir( $this->patterns_dir );
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( false !== stripos( $file, '.php' ) ) {
$files[] = $file;
}
}
if ( $sort ) {
sort( $files );
}
$files_h = str_replace( self::$file_replace, ' ', $files );
if ( 'headers' === $type ) {
return $files_h;
}
return $files;
}
/**
* Add donate link to plugin description in /wp-admin/plugins.php
*
* @param array $plugin_meta All met data to a plugin.
* @param string $plugin_file The main file of the plugin with the meta data.
*
* @return array
*/
public function donate_link( $plugin_meta, $plugin_file ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
$plugin_meta[] = sprintf(
'♥ <a href="%s">%s</a>',
'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6069955',
esc_html__( 'Donate', 'WpAdminStyle' )
);
}
return $plugin_meta;
}
/**
* Register and enqueue script and styles for highlighting source.
*
* @since 2016-05-20
*/
public function enqueue_assets() {
wp_register_style(
'prism',
plugins_url( 'css/prism.css', __FILE__ ),
array(),
'2021-05-28',
'screen'
);
wp_enqueue_style( 'prism' );
wp_register_script(
'prism',
plugins_url( 'js/prism.js', __FILE__ ),
array(),
'2021-05-28',
true
);
wp_enqueue_script( 'prism' );
wp_register_script(
'example-color-picker',
plugins_url( 'js/color-picker.js', __FILE__ ),
array( 'jquery', 'wp-color-picker' ),
'2021-05-28',
true
);
wp_enqueue_script( 'example-color-picker' );
}
} // end class