-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdashicons-picker-example-plugin.php
94 lines (82 loc) · 3.16 KB
/
dashicons-picker-example-plugin.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
<?php
/**
* Plugin Name: Dashicons Picker Example Plugin
* Description: A plugin to showcase the dashicons picker
* Author: Brad Vincent
* Author URI: http://themergency.com
* Version: 1.1
*/
/**
* Register example picker setting
*
* @since 1.1
*/
function dashicons_picker_register_settings() {
register_setting( 'dashicons_picker_settings_group', 'dashicons_picker_settings' );
}
add_action( 'admin_init', 'dashicons_picker_register_settings' );
/**
* Register menu for example settings page
*
* @since 1.1
*/
function dashicons_picker_settings_menu() {
add_options_page( __( 'Dashicons Picker Example' ), __( 'Dashicons Picker Example' ), 'manage_options', 'dashicons_picker_settings', 'dashicons_picker_settings_page' );
}
add_action( 'admin_menu', 'dashicons_picker_settings_menu' );
/**
* Enqueue dashicons picker scripts
*
* @since 1.1
*/
function dashicons_picker_scripts() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'dashicons-picker', $plugin_url . 'css/dashicons-picker.css', array( 'dashicons' ), '1.0', false );
wp_enqueue_script( 'dashicons-picker', $plugin_url . 'js/dashicons-picker.js', array( 'jquery' ), '1.1', true );
}
add_action( 'admin_enqueue_scripts', 'dashicons_picker_scripts' );
/**
* Ouput for the example dashicons picker page
*
* @since 1.1
*/
function dashicons_picker_settings_page() {
$options = get_option( 'dashicons_picker_settings' ); ?>
<div class="wrap">
<h2><?php _e( 'Dashicons Example Settings' ); ?></h2>
<form method="post" action="options.php" class="options_form">
<?php settings_fields( 'dashicons_picker_settings_group' ); ?>
<table class="form-table">
<tr>
<th scope="row">
<label for="dashicons_picker_example_icon1"><?php _e( 'Icon 1' ); ?></label>
</th>
<td>
<input class="regular-text" type="text" id="dashicons_picker_example_icon1" name="dashicons_picker_settings[icon1]" value="<?php if( isset( $options['icon1'] ) ) { echo esc_attr( $options['icon1'] ); } ?>"/>
<input type="button" data-target="#dashicons_picker_example_icon1" class="button dashicons-picker" value="Choose Icon" />
</td>
</tr>
<tr>
<th scope="row">
<label for="dashicons_picker_example_icon2"><?php _e( 'Icon 2' ); ?></label>
</th>
<td>
<input class="regular-text" type="text" id="dashicons_picker_example_icon2" name="dashicons_picker_settings[icon2]" value="<?php if( isset( $options['icon2'] ) ) { echo esc_attr( $options['icon2'] ); } ?>"/>
<input type="button" data-target="#dashicons_picker_example_icon2" class="button dashicons-picker" value="pick" />
</td>
</tr>
<tr>
<th scope="row">
<label for="dashicons_picker_example_icon3"><?php _e( 'Icon 3' ); ?></label>
</th>
<td>
<input class="regular-text" type="text" id="dashicons_picker_example_icon3" name="dashicons_picker_settings[icon3]" value="<?php if( isset( $options['icon2'] ) ) { echo esc_attr( $options['icon3'] ); } ?>"/>
<input type="button" data-target="#dashicons_picker_example_icon3" class="button dashicons-picker" value="..." />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}