Menu Icons by ThemeIsle - Version 0.1.1

Version Description

  • Improve icon selection UX
Download this release

Release Info

Developer kucrut
Plugin Icon 128x128 Menu Icons by ThemeIsle
Version 0.1.1
Comparing to
See all releases

Code changes from version 0.1.0 to 0.1.1

css/admin.css ADDED
@@ -0,0 +1,8 @@
1
+ .menu-icons-wrap {
2
+ margin-top: 5px;
3
+ margin-bottom: 5px;
4
+ }
5
+ .menu-icons-wrap label {
6
+ display: inline-block;
7
+ min-width: 7em;
8
+ }
includes/admin.php CHANGED
@@ -2,7 +2,7 @@
2
/**
3
* Menu editor handler
4
* @package Menu_Icons
5
- * @version 0.1.0
6
* @author Dzikri Aziz <kvcrvt@gmail.com>
7
*/
8
@@ -18,6 +18,7 @@ class Menu_Icons_Admin_Nav_Menus {
18
* Initialize class
19
*/
20
public static function init() {
21
add_action( 'menu_item_custom_fields', array( __CLASS__, '_fields' ), 10, 3 );
22
add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 );
23
add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 );
@@ -48,6 +49,38 @@ class Menu_Icons_Admin_Nav_Menus {
48
}
49
50
51
/**
52
* Print fields
53
*
@@ -86,7 +119,11 @@ class Menu_Icons_Admin_Nav_Menus {
86
?>
87
<p class="description">
88
<label for="<?php echo esc_attr( $input_id ) ?>"><?php esc_html_e( 'Icon type', 'menu-icons' ); ?></label>
89
- <select id="<?php echo esc_attr( $input_id ) ?>" name="<?php echo esc_attr( $input_name ) ?>">
90
<?php foreach ( self::_get_types() as $id => $props ) : ?>
91
<?php printf(
92
'<option value="%s"%s>%s</option>',
2
/**
3
* Menu editor handler
4
* @package Menu_Icons
5
+ * @version 0.1.1
6
* @author Dzikri Aziz <kvcrvt@gmail.com>
7
*/
8
18
* Initialize class
19
*/
20
public static function init() {
21
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, '_scripts_styles' ) );
22
add_action( 'menu_item_custom_fields', array( __CLASS__, '_fields' ), 10, 3 );
23
add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 );
24
add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 );
49
}
50
51
52
+ /**
53
+ * Enqueue scripts & styles on wp-admin/nav-menus.php
54
+ *
55
+ * @since 0.1.1
56
+ * @access protected
57
+ * @wp_hook admin_enqueue_scripts
58
+ */
59
+ public static function _scripts_styles() {
60
+ wp_register_script(
61
+ 'kucrut-jquery-input-dependencies',
62
+ Menu_Icons::get( 'url' ) . 'js/input-dependencies.js',
63
+ array( 'jquery' ),
64
+ '0.1.0',
65
+ true
66
+ );
67
+ wp_enqueue_script(
68
+ 'menu-icons',
69
+ Menu_Icons::get( 'url' ) . 'js/admin.js',
70
+ array( 'kucrut-jquery-input-dependencies' ),
71
+ Menu_Icons::VERSION,
72
+ true
73
+ );
74
+
75
+ wp_enqueue_style(
76
+ 'menu-icons',
77
+ Menu_Icons::get( 'url' ) . 'css/admin.css',
78
+ false,
79
+ Menu_Icons::VERSION
80
+ );
81
+ }
82
+
83
+
84
/**
85
* Print fields
86
*
119
?>
120
<p class="description">
121
<label for="<?php echo esc_attr( $input_id ) ?>"><?php esc_html_e( 'Icon type', 'menu-icons' ); ?></label>
122
+ <?php printf(
123
+ '<select id="%s" name="%s" class="hasdep" data-dep-scope="div.menu-icons-wrap" data-dep-children=".field-icon-child">',
124
+ esc_attr( $input_id ),
125
+ esc_attr( $input_name )
126
+ ) ?>
127
<?php foreach ( self::_get_types() as $id => $props ) : ?>
128
<?php printf(
129
'<option value="%s"%s>%s</option>',
includes/menu-item-custom-fields/menu-item-custom-fields.php CHANGED
@@ -4,13 +4,13 @@
4
* Menu Item Custom Fields
5
*
6
* @package Menu_Item_Custom_Fields
7
- * @version 0.1.0
8
* @author Dzikri Aziz <kvcrvt@gmail.com>
9
*
10
* Plugin name: Menu Item Custom Fields
11
* Plugin URI: https://github.com/kucrut/wp-menu-item-custom-fields
12
* Description: Easily add custom fields to nav menu items
13
- * Version: 0.1.0
14
* Author: Dzikri Aziz
15
* Author URI: http://kucrut.org/
16
* License: GPLv2
4
* Menu Item Custom Fields
5
*
6
* @package Menu_Item_Custom_Fields
7
+ * @version 0.1.1
8
* @author Dzikri Aziz <kvcrvt@gmail.com>
9
*
10
* Plugin name: Menu Item Custom Fields
11
* Plugin URI: https://github.com/kucrut/wp-menu-item-custom-fields
12
* Description: Easily add custom fields to nav menu items
13
+ * Version: 0.1.1
14
* Author: Dzikri Aziz
15
* Author URI: http://kucrut.org/
16
* License: GPLv2
includes/menu-item-custom-fields/readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://kucrut.org/#coffee
4
Tags: menu, nav-menu, custom-fields, metadata
5
Requires at least: 3.8
6
Tested up to: 3.8.1
7
- Stable tag: 0.1.0
8
License: GPLv2
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -38,5 +38,8 @@ Copy (and customize) and include the `menu-item-custom-fields-example.php` file
38
39
40
== Changelog ==
41
= 0.1.0 =
42
* Initial public release
4
Tags: menu, nav-menu, custom-fields, metadata
5
Requires at least: 3.8
6
Tested up to: 3.8.1
7
+ Stable tag: 0.1.1
8
License: GPLv2
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
38
39
40
== Changelog ==
41
+ = 0.1.1 =
42
+ * Move custom fields up (before `<p.field-move />`)
43
+
44
= 0.1.0 =
45
* Initial public release
includes/menu-item-custom-fields/walker-nav-menu-edit.php CHANGED
@@ -7,7 +7,7 @@
7
* is only loaded on the wp-admin/nav-menus.php page.
8
*
9
* @package Menu_Item_Custom_Fields
10
- * @version 0.1.0
11
* @author Dzikri Aziz <kvcrvt@gmail.com>
12
*/
13
@@ -39,7 +39,7 @@ class Menu_Item_Custom_Fields_Walker extends Walker_Nav_Menu_Edit {
39
parent::start_el( $item_output, $item, $depth, $args, $id );
40
$output .= preg_replace(
41
// NOTE: Check this regex from time to time!
42
- '/(?=<div[^>]+class="[^"]*submitbox)/',
43
$this->get_fields( $item, $depth, $args ),
44
$item_output
45
);
7
* is only loaded on the wp-admin/nav-menus.php page.
8
*
9
* @package Menu_Item_Custom_Fields
10
+ * @version 0.1.1
11
* @author Dzikri Aziz <kvcrvt@gmail.com>
12
*/
13
39
parent::start_el( $item_output, $item, $depth, $args, $id );
40
$output .= preg_replace(
41
// NOTE: Check this regex from time to time!
42
+ '/(?=<p[^>]+class="[^"]*field-move)/',
43
$this->get_fields( $item, $depth, $args ),
44
$item_output
45
);
includes/type-fonts.php CHANGED
@@ -3,7 +3,7 @@
3
* Icon fonts handler
4
*
5
* @package Menu_Icons
6
- * @version 0.1.0
7
* @author Dzikri Aziz <kvcrvt@gmail.com>
8
*/
9
@@ -120,7 +120,10 @@ abstract class Menu_Icons_Fonts {
120
$input_id = sprintf( 'menu-icons-%d-%s', $id, $this->_key );
121
$input_name = sprintf( 'menu-icons[%d][%s]', $id, $this->_key );
122
?>
123
- <p class="description menu-icon-type-<?php echo esc_attr( $this->type ) ?>">
124
<label for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_html( $this->label ); ?></label>
125
<select id="<?php echo esc_attr( $input_id ) ?>" name="<?php echo esc_attr( $input_name ) ?>">
126
<?php printf(
3
* Icon fonts handler
4
*
5
* @package Menu_Icons
6
+ * @version 0.1.1
7
* @author Dzikri Aziz <kvcrvt@gmail.com>
8
*/
9
120
$input_id = sprintf( 'menu-icons-%d-%s', $id, $this->_key );
121
$input_name = sprintf( 'menu-icons[%d][%s]', $id, $this->_key );
122
?>
123
+ <?php printf(
124
+ '<p class="field-icon-child description menu-icon-type-%1$s" data-dep-on="%1$s">',
125
+ esc_attr( $this->type )
126
+ ) ?>
127
<label for="<?php echo esc_attr( $input_id ) ?>"><?php echo esc_html( $this->label ); ?></label>
128
<select id="<?php echo esc_attr( $input_id ) ?>" name="<?php echo esc_attr( $input_name ) ?>">
129
<?php printf(
js/admin.js ADDED
@@ -0,0 +1,15 @@
1
+ /* Global jQuery */
2
+ /**
3
+ * Menu Icons
4
+ *
5
+ * @author Dzikri Aziz <kvcrvt@gmail.com>
6
+ * @version 0.1.0
7
+ *
8
+ */
9
+ (function($) {
10
+ 'use strict';
11
+
12
+ $.inputDependencies({
13
+ selector: 'select.hasdep'
14
+ });
15
+ }(jQuery));
js/input-dependencies.js ADDED
@@ -0,0 +1,148 @@
1
+ /* global jQuery */
2
+ /**
3
+ * Input dependencies
4
+ *
5
+ * This jQuery plugin will help you toggle the visibility of form fields that
6
+ * depends on another field.
7
+ *
8
+ * To use this, you need to add some data- attributes to the input fields that
9
+ * have 'children':
10
+ * data-dep-children: This is where you define the selector of the children of
11
+ * this input
12
+ * data-dep-scope: Selector for the scope where the children should be found
13
+ *
14
+ * @author Dzikri Aziz <kvcrvt@gmail.com>
15
+ * @version 0.1.0
16
+ *
17
+ */
18
+ (function($) {
19
+ 'use strict';
20
+
21
+ var instances = {};
22
+
23
+ var defaults = {
24
+ selector : '.hasdep',
25
+ disable : true
26
+ };
27
+
28
+ var getState = function ( $el, depOn ) {
29
+ var currentValue = $el.val();
30
+
31
+ if (
32
+ ! $el.prop('disabled')
33
+ && (
34
+ (
35
+ ('string' === typeof depOn || 'number' === typeof depOn)
36
+ && (depOn == currentValue || $.inArray(depOn, currentValue) > -1)
37
+ )
38
+ || ('object' === typeof depOn && $.inArray(currentValue, depOn) > -1)
39
+ )
40
+ ) {
41
+ return true;
42
+ }
43
+ else {
44
+ return false;
45
+ }
46
+ };
47
+
48
+ var getChildren = function( $el, options ) {
49
+ var childrenSelector = $el.data('dep-children');
50
+ if ( !childrenSelector ) {
51
+ window.log( 'jQuery.inputDependencies', 'childrenSelector is not valid.', options, $el );
52
+ return false;
53
+ }
54
+
55
+ var childrenScope = $el.data('dep-scope');
56
+ if ( childrenScope )
57
+ return $el.closest( childrenScope ).find( childrenSelector );
58
+ else
59
+ return $( childrenSelector );
60
+ };
61
+
62
+ var onChange = function( e ) {
63
+ var $el = $(e.target);
64
+
65
+ // If this input is already initialized, do nothing
66
+ // This is to prevent unnecessary actions when the change event is
67
+ // triggered by our ajaxComplete callback
68
+ if ( e.inputDependenciesInit && $el.data('inputDependenciesInit') )
69
+ return;
70
+ else
71
+ $el.data('inputDependenciesInit', true );
72
+
73
+ var options = e.data;
74
+ var $children = getChildren( $el, options );
75
+
76
+ if ( ! $children.length )
77
+ return false;
78
+
79
+ $children.each(function() {
80
+ var $child = $(this);
81
+ var depOn = $child.data('dep-on');
82
+ if ( ! depOn )
83
+ return false;
84
+
85
+ var show = getState( $el, depOn );
86
+ $child.toggle( show );
87
+
88
+
89
+ if ( true === options.disable ) {
90
+ $child.filter(':input')
91
+ .add( $child.find(':input') )
92
+ .prop('disabled', !show)
93
+ .trigger('change');
94
+ }
95
+ });
96
+ };
97
+
98
+ var init = function( selector ) {
99
+ $(selector).trigger({
100
+ type: 'change',
101
+ inputDependenciesInit: true
102
+ });
103
+ };
104
+
105
+ $.inputDependencies = function( options ) {
106
+ options = $.extend( true, {}, defaults, options );
107
+
108
+ if ( !options.selector ) {
109
+ window.log( 'jQuery.inputDependencies', 'Invalid selector.', options );
110
+ return false;
111
+ }
112
+
113
+ if ( instances.hasOwnProperty( options.selector ) ) {
114
+ window.log( 'jQuery.inputDependencies', 'Selector is already registered.', options );
115
+ return false;
116
+ }
117
+
118
+ instances[ options.selector ] = options;
119
+
120
+ console.log( instances );
121
+
122
+ // Delegate event
123
+ $(document)
124
+ .on('change', options.selector, options, onChange)
125
+ .ajaxComplete(function() {
126
+ init(options.selector);
127
+ });
128
+
129
+ // Trigger event
130
+ init(options.selector);
131
+
132
+ return true;
133
+ };
134
+ }(jQuery));
135
+
136
+ if ( undefined === window.log ) {
137
+ /**
138
+ * usage: log('inside coolFunc',this,arguments);
139
+ * http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
140
+ */
141
+ window.log = function(){
142
+ log.history = log.history || []; // store logs to an array for reference
143
+ log.history.push(arguments);
144
+ if ( this.console ) {
145
+ console.log( Array.prototype.slice.call(arguments) );
146
+ }
147
+ };
148
+ }
menu-icons.php CHANGED
@@ -4,14 +4,14 @@
4
* Menu Icons
5
*
6
* @package Menu_Icons
7
- * @version 0.1.0
8
* @author Dzikri Aziz <kvcrvt@gmail.com>
9
*
10
*
11
* Plugin name: Menu Icons
12
* Plugin URI: http://kucrut.org/
13
* Description: Easily add icons to your navigation menu items
14
- * Version: 0.1.0
15
* Author: Dzikri Aziz
16
* Author URI: http://kucrut.org/
17
* License: GPLv2
4
* Menu Icons
5
*
6
* @package Menu_Icons
7
+ * @version 0.1.1
8
* @author Dzikri Aziz <kvcrvt@gmail.com>
9
*
10
*
11
* Plugin name: Menu Icons
12
* Plugin URI: http://kucrut.org/
13
* Description: Easily add icons to your navigation menu items
14
+ * Version: 0.1.1
15
* Author: Dzikri Aziz
16
* Author URI: http://kucrut.org/
17
* License: GPLv2
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://kucrut.org/#coffee
4
Tags: menu, nav-menu, icons, navigation
5
Requires at least: 3.8
6
Tested up to: 3.8.1
7
- Stable tag: 0.1.0
8
License: GPLv2
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -78,5 +78,8 @@ add_filter( 'menu_icons_load_extra_style', '__return_false' );
78
79
80
== Changelog ==
81
= 0.1.0 =
82
* Initial public release
4
Tags: menu, nav-menu, icons, navigation
5
Requires at least: 3.8
6
Tested up to: 3.8.1
7
+ Stable tag: 0.1.1
8
License: GPLv2
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
78
79
80
== Changelog ==
81
+ = 0.1.1 =
82
+ * Improve icon selection UX
83
+
84
= 0.1.0 =
85
* Initial public release