Menu Image - Version 2.0

Version Description

  • Added support of media uploader.
  • Fixed php strict warnings.
  • Added .ico image support, thanks to ivol84
Download this release

Release Info

Developer zviryatko
Plugin Icon 128x128 Menu Image
Version 2.0
Comparing to
See all releases

Version 2.0

README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Menu Image #
2
+ **Contributors:** @zviryatko
3
+ **Tags:** menu, image, field, hover
4
+ **Donate link:** (http://makeyoulivebetter.org.ua/buy-beer)
5
+ **Requires at least:** 3.5.1
6
+ **Tested up to:** 3.9.1
7
+ **Stable tag:** 2.0
8
+ **License:** GPLv2 or later
9
+ **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Adds a field to load the image in a menu item and displays the image inside the link in the menu before the text.
12
+
13
+ ## Description ##
14
+
15
+ Adds a field to load the image in a menu item and displays the image inside the link in the menu before the text.
16
+ Now you can upload the second image and set to the mouse over/out effect.
17
+ And also change position of title or hide title if need.
18
+ And... load images via media uploader!
19
+
20
+ ## Installation ##
21
+
22
+ 1. Upload `menu-image` to the `/wp-content/plugins/` directory
23
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
24
+ 3. Go to `/wp-admin/nav-menus.php`
25
+ 4. Edit exist menu item or add new menu item and just upload image than click `Save Menu`
26
+ 5. See your menu on site
27
+
28
+ ## Frequently Asked Questions ##
29
+
30
+ ### How to wrap menu link text in `span` html element ###
31
+
32
+ Where you show your menu with function `<?php wp_nav_menu(); ?>` as param you can add `array('link_before' => '<span>', 'link_after' => '</span>')`.
33
+ It makes css markup easier.
34
+
35
+ ### How to add another size for image? ###
36
+
37
+ Just register another image size in your theme with function `add_image_size()`.
38
+
39
+ ## Screenshots ##
40
+
41
+ ###1. Admin screen###
42
+ ![Admin screen](http://s-plugins.wordpress.org/menu-image/assets/screenshot-1.png)
43
+
44
+ ###2. Menu preview in standard twenty-twelve theme###
45
+ ![Menu preview in standard twenty-twelve theme](http://s-plugins.wordpress.org/menu-image/assets/screenshot-2.png)
46
+
47
+
48
+ ## Changelog ##
49
+
50
+ ### 2.0 ###
51
+ * Added support of media uploader.
52
+ * Fixed php strict warnings.
53
+ * Added .ico image support, thanks to [ivol84](https://github.com/ivol84)
54
+
55
+ ### 1.3 ###
56
+ * Added ability to set title position, an example: before, after image or hide
57
+
58
+ ### 1.2 ###
59
+ * Fix styles for hovered image
60
+
61
+ ### 1.1 ###
62
+ * Added style file with vertical align of menu image item by default
63
+ * Added ability to upload image that which will be replaced on hover
64
+ * Added default image sizes for menu items: 24x24, 36x36 and 48x48
65
+
66
+ ## Upgrade Notice ##
67
+
68
+ ### 2.0 ###
69
+ WARNING! You need to re-select the images! Now, with media uploader support, it's easy peasy.
70
+ Media uploader support. Upload once, use many times!
71
+
72
+ ### 1.2 ###
73
+ Now you can change title text position
74
+
75
+ ### 1.1 ###
76
+ Now you can upload image that replaced default on mouse hover
languages/menu-image-ru_RU.mo ADDED
Binary file
languages/menu-image-ru_RU.po ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Menu Image\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-05-17 16:51+0300\n"
6
+ "PO-Revision-Date: 2014-05-17 16:59+0300\n"
7
+ "Last-Translator: Alex Davyskiba <sanya.davyskiba@gmail.com>\n"
8
+ "Language-Team: MakeYouLiveBetter <team@makeyoulivebetter.org.ua>\n"
9
+ "Language: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: __;_e;esc_attr__;esc_html__\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Poedit-Language: English\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+
18
+ #: ../menu-image.php:83
19
+ msgid "Image"
20
+ msgstr "Картинка"
21
+
22
+ #: ../menu-image.php:211
23
+ msgid "Chose menu image"
24
+ msgstr "Выберите изображение"
25
+
26
+ #: ../menu-image.php:252
27
+ msgid "Menu image"
28
+ msgstr "Картинками меню"
29
+
30
+ #: ../menu-image.php:253
31
+ msgid "Change menu item image"
32
+ msgstr "Изменить картинку для пункта меню"
33
+
34
+ #: ../menu-image.php:253
35
+ msgid "Set menu item image"
36
+ msgstr "Выбрать картинку для пункта меню"
37
+
38
+ #: ../menu-image.php:256
39
+ msgid "Set image"
40
+ msgstr "Выбрать картинку"
41
+
42
+ #: ../menu-image.php:257
43
+ #: ../menu-image.php:267
44
+ #: ../menu-image.php:541
45
+ msgid "Remove"
46
+ msgstr "Удалить"
47
+
48
+ #: ../menu-image.php:262
49
+ msgid "Image on hover"
50
+ msgstr "Картинка при наведении"
51
+
52
+ #: ../menu-image.php:263
53
+ msgid "Change menu item image on hover"
54
+ msgstr "Изменить картинку при наведении для пункта меню"
55
+
56
+ #: ../menu-image.php:263
57
+ msgid "Set menu item image on hover"
58
+ msgstr "Выбрать картинку при наведении для пункта меню"
59
+
60
+ #: ../menu-image.php:266
61
+ msgid "Set image on hover"
62
+ msgstr "Выбрать картинку"
63
+
64
+ #: ../menu-image.php:279
65
+ msgid "Image size"
66
+ msgstr "Размер"
67
+
68
+ #: ../menu-image.php:294
69
+ msgid "Title position"
70
+ msgstr "Положение заголовка"
71
+
72
+ #: ../menu-image.php:297
73
+ msgid "Before"
74
+ msgstr "До"
75
+
76
+ #: ../menu-image.php:298
77
+ msgid "Hide"
78
+ msgstr "Нет"
79
+
80
+ #: ../menu-image.php:299
81
+ msgid "After"
82
+ msgstr "После"
83
+
languages/menu-image-ua_UA.mo ADDED
Binary file
languages/menu-image-ua_UA.po ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Menu Image\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-05-17 16:51+0300\n"
6
+ "PO-Revision-Date: 2014-05-17 17:05+0300\n"
7
+ "Last-Translator: Alex Davyskiba <sanya.davyskiba@gmail.com>\n"
8
+ "Language-Team: MakeYouLiveBetter <team@makeyoulivebetter.org.ua>\n"
9
+ "Language: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: __;_e;esc_attr__;esc_html__\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Poedit-Language: English\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+
18
+ #: ../menu-image.php:83
19
+ msgid "Image"
20
+ msgstr "Зображення"
21
+
22
+ #: ../menu-image.php:211
23
+ msgid "Chose menu image"
24
+ msgstr "Виберіть зображення"
25
+
26
+ #: ../menu-image.php:252
27
+ msgid "Menu image"
28
+ msgstr "Зображення меню"
29
+
30
+ #: ../menu-image.php:253
31
+ msgid "Change menu item image"
32
+ msgstr "Змінити картинку для пункту меню"
33
+
34
+ #: ../menu-image.php:253
35
+ msgid "Set menu item image"
36
+ msgstr "Виберіть зображення для пункту меню"
37
+
38
+ #: ../menu-image.php:256
39
+ msgid "Set image"
40
+ msgstr "Виберіть зображення"
41
+
42
+ #: ../menu-image.php:257
43
+ #: ../menu-image.php:267
44
+ #: ../menu-image.php:541
45
+ msgid "Remove"
46
+ msgstr "Видалити"
47
+
48
+ #: ../menu-image.php:262
49
+ msgid "Image on hover"
50
+ msgstr "Зображення при наведенні"
51
+
52
+ #: ../menu-image.php:263
53
+ msgid "Change menu item image on hover"
54
+ msgstr "Змінити картинку при наведенні для пункту меню"
55
+
56
+ #: ../menu-image.php:263
57
+ msgid "Set menu item image on hover"
58
+ msgstr "Вибрати картинку при наведенні для пункту меню"
59
+
60
+ #: ../menu-image.php:266
61
+ msgid "Set image on hover"
62
+ msgstr "Виберіть зображення"
63
+
64
+ #: ../menu-image.php:279
65
+ msgid "Image size"
66
+ msgstr "Розмір"
67
+
68
+ #: ../menu-image.php:294
69
+ msgid "Title position"
70
+ msgstr "Розташування заголовка"
71
+
72
+ #: ../menu-image.php:297
73
+ msgid "Before"
74
+ msgstr "До"
75
+
76
+ #: ../menu-image.php:298
77
+ msgid "Hide"
78
+ msgstr "Нема"
79
+
80
+ #: ../menu-image.php:299
81
+ msgid "After"
82
+ msgstr "Після"
83
+
languages/menu-image.pot ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Menu Image\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-05-17 16:56+0300\n"
6
+ "PO-Revision-Date: 2014-05-17 16:56+0300\n"
7
+ "Last-Translator: Alex Davyskiba <sanya.davyskiba@gmail.com>\n"
8
+ "Language-Team: MakeYouLiveBetter <team@makeyoulivebetter.org.ua>\n"
9
+ "Language: \n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Poedit-KeywordsList: __;_e;esc_attr__;esc_html__\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "X-Poedit-Language: English\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+
18
+ #: ../menu-image.php:83
19
+ msgid "Image"
20
+ msgstr ""
21
+
22
+ #: ../menu-image.php:211
23
+ msgid "Chose menu image"
24
+ msgstr ""
25
+
26
+ #: ../menu-image.php:252
27
+ msgid "Menu image"
28
+ msgstr ""
29
+
30
+ #: ../menu-image.php:253
31
+ msgid "Change menu item image"
32
+ msgstr ""
33
+
34
+ #: ../menu-image.php:253
35
+ msgid "Set menu item image"
36
+ msgstr ""
37
+
38
+ #: ../menu-image.php:256
39
+ msgid "Set image"
40
+ msgstr ""
41
+
42
+ #: ../menu-image.php:257
43
+ #: ../menu-image.php:267
44
+ #: ../menu-image.php:541
45
+ msgid "Remove"
46
+ msgstr ""
47
+
48
+ #: ../menu-image.php:262
49
+ msgid "Image on hover"
50
+ msgstr ""
51
+
52
+ #: ../menu-image.php:263
53
+ msgid "Change menu item image on hover"
54
+ msgstr ""
55
+
56
+ #: ../menu-image.php:263
57
+ msgid "Set menu item image on hover"
58
+ msgstr ""
59
+
60
+ #: ../menu-image.php:266
61
+ msgid "Set image on hover"
62
+ msgstr ""
63
+
64
+ #: ../menu-image.php:279
65
+ msgid "Image size"
66
+ msgstr ""
67
+
68
+ #: ../menu-image.php:294
69
+ msgid "Title position"
70
+ msgstr ""
71
+
72
+ #: ../menu-image.php:297
73
+ msgid "Before"
74
+ msgstr ""
75
+
76
+ #: ../menu-image.php:298
77
+ msgid "Hide"
78
+ msgstr ""
79
+
80
+ #: ../menu-image.php:299
81
+ msgid "After"
82
+ msgstr ""
menu-image-admin.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+ $(document).ready(function () {
3
+ var menuImageUpdate = function( item_id, thumb_id, is_hover ) {
4
+ wp.media.post( 'set-menu-item-thumbnail', {
5
+ json: true,
6
+ post_id: item_id,
7
+ thumbnail_id: thumb_id,
8
+ is_hover: is_hover ? 1 : 0,
9
+ _wpnonce: menuImage.settings.nonce
10
+ }).done( function( html ) {
11
+ $('.field-image', '#menu-item-' + item_id).html( html );
12
+ });
13
+ };
14
+
15
+ $('#menu-to-edit').find('.menu-item')
16
+ .on('click', '.set-post-thumbnail', function (e) {
17
+ e.preventDefault();
18
+ e.stopPropagation();
19
+
20
+ var item_id = $(this).parents('.field-image').siblings('input.menu-item-data-db-id').val(),
21
+ is_hover = $(this).hasClass('hover-image'),
22
+ uploader = wp.media({
23
+ title: menuImage.l10n.uploaderTitle, // todo: translate
24
+ button: { text: 'Select' },
25
+ multiple: false
26
+ }).on('select', function () {
27
+ var attachment = uploader.state().get('selection').first().toJSON();
28
+ menuImageUpdate( item_id, attachment.id, is_hover );
29
+ }).open();
30
+ })
31
+ .on('click', '.remove-post-thumbnail', function (e) {
32
+ e.preventDefault();
33
+ e.stopPropagation();
34
+
35
+ var item_id = $(this).parents('.field-image').siblings('input.menu-item-data-db-id').val();
36
+ menuImageUpdate( item_id, -1, $(this).hasClass('hover-image') );
37
+ });
38
+ });
39
+ })(jQuery);
menu-image.css ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .menu-item a img {
2
+ border: none;
3
+ box-shadow: none;
4
+ vertical-align: middle;
5
+ }
6
+ .menu-item a .menu-image-hover-wrapper {
7
+ display: block;
8
+ overflow: hidden;
9
+ }
10
+ .menu-item a .menu-image-hover-wrapper,
11
+ .menu-item a .menu-image-hover-wrapper img {
12
+ float: left;
13
+ }
14
+ .menu-item a.menu-image-hovered .menu-image-hover-wrapper img.hovered-image,
15
+ .menu-item a.menu-image-hovered:hover .menu-image-hover-wrapper img.menu-image {
16
+ opacity: 0;
17
+ }
18
+ .menu-item a.menu-image-hovered:hover .menu-image-hover-wrapper img.hovered-image {
19
+ opacity: 1;
20
+ }
21
+ .menu-item a.menu-image-title-hide .menu-image-hover-wrapper,
22
+ .menu-item a.menu-image-title-before .menu-image-hover-wrapper {
23
+ vertical-align: top;
24
+ display: inline-block;
25
+ float: none;
26
+ }
27
+ .menu-item a.menu-image-title-after img,
28
+ .menu-item a.menu-image-hovered.menu-image-title-after .menu-image-hover-wrapper {
29
+ padding-right: 10px;
30
+ }
31
+ .menu-item a.menu-image-title-before img,
32
+ .menu-item a.menu-image-hovered.menu-image-title-before .menu-image-hover-wrapper {
33
+ padding-left: 10px;
34
+ }
35
+ .menu-item a .menu-image-hover-wrapper img {
36
+ padding: 0;
37
+ position: absolute;
38
+ transition: opacity 0.25s ease-in-out 0s;
39
+ }
menu-image.php ADDED
@@ -0,0 +1,575 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Menu_Image
4
+ * @version 2.0
5
+ * @licence GPLv2
6
+ */
7
+
8
+ /*
9
+ Plugin Name: Menu Image
10
+ Plugin URI: http://html-and-cms.com/plugins/menu-image/
11
+ Description: Provide uploading images to menu item
12
+ Author: Alex Davyskiba aka Zviryatko
13
+ Version: 2.0
14
+ Author URI: http://makeyoulivebetter.org.ua/
15
+ */
16
+
17
+ /* Copyright 2013 Zviryatko (email : sanya.davyskiba@gmail.com)
18
+
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License, version 2, as
21
+ published by the Free Software Foundation.
22
+
23
+ This program is distributed in the hope that it will be useful,
24
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ GNU General Public License for more details.
27
+
28
+ You should have received a copy of the GNU General Public License
29
+ along with this program; if not, write to the Free Software
30
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
+ */
32
+
33
+ /**
34
+ * Provide attaching images to menu items.
35
+ *
36
+ * @package Menu_Image
37
+ */
38
+ class Menu_Image_Plugin {
39
+ protected $image_sizes = array(
40
+ 'menu-24x24' => array( 24, 24, false ),
41
+ 'menu-36x36' => array( 36, 36, false ),
42
+ 'menu-48x48' => array( 48, 48, false ),
43
+ );
44
+ /**
45
+ * @var array
46
+ */
47
+ private $additionalDisplayableImageExtensions = array('ico');
48
+
49
+ public function __construct() {
50
+ add_action( 'init', array( $this, 'menu_image_init' ) );
51
+ add_filter( 'manage_nav-menus_columns', array( $this, 'menu_image_nav_menu_manage_columns' ), 11 );
52
+ add_action( 'save_post', array( $this, 'menu_image_save_post_action' ), 10, 2 );
53
+ add_action( 'admin_head-nav-menus.php', array( $this, 'menu_image_admin_head_nav_menus_action' ) );
54
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'menu_image_edit_nav_menu_walker_filter' ) );
55
+ add_filter( 'wp_setup_nav_menu_item', array( $this, 'menu_image_wp_setup_nav_menu_item' ) );
56
+ add_filter( 'walker_nav_menu_start_el', array( $this, 'menu_image_nav_menu_item_filter' ), 10, 4 );
57
+ add_action( 'wp_enqueue_scripts', array( $this, 'menu_image_add_inline_style_action' ) );
58
+ add_action( 'admin_action_delete-menu-item-image', array( $this, 'menu_image_delete_menu_item_image_action' ) );
59
+ add_action( 'wp_ajax_set-menu-item-thumbnail', array( $this, 'wp_ajax_set_menu_item_thumbnail' ) );
60
+ // Add support for additional image types
61
+ add_filter('file_is_displayable_image', array($this, 'file_is_displayable_image'), 10, 2);
62
+ }
63
+
64
+ /**
65
+ * Filter adds additional validation for image type
66
+ *
67
+ * @param bool $result
68
+ * @param string $path
69
+ * @return bool
70
+ */
71
+ public function file_is_displayable_image($result, $path) {
72
+ if ($result) { return true; }
73
+ $fileExtension = pathinfo($path, PATHINFO_EXTENSION);
74
+ return in_array($fileExtension, $this->additionalDisplayableImageExtensions);
75
+ }
76
+
77
+ /**
78
+ * Initialization action.
79
+ *
80
+ * Adding image sizes for most popular menu icon sizes. Adding thumbnail
81
+ * support to menu post type.
82
+ */
83
+ public function menu_image_init() {
84
+ add_post_type_support( 'nav_menu_item', array( 'thumbnail' ) );
85
+
86
+ $this->image_sizes = apply_filters( 'menu_image_default_sizes', $this->image_sizes );
87
+ foreach ( $this->image_sizes as $name => $params ) {
88
+ add_image_size( $name, $params[0], $params[1], $params[2] );
89
+ }
90
+ load_plugin_textdomain('menu-image', false, basename( dirname( __FILE__ ) ) . '/languages' );
91
+ }
92
+
93
+ /**
94
+ * Adding images as screen options.
95
+ *
96
+ * If not checked screen option 'image', uploading form not showed.
97
+ *
98
+ * @param $columns
99
+ * @return array
100
+ */
101
+ public function menu_image_nav_menu_manage_columns( $columns ) {
102
+ return $columns + array( 'image' => __( 'Image', 'menu-image' ) );
103
+ }
104
+
105
+ /**
106
+ * Saving post action.
107
+ *
108
+ * Saving uploaded images and attach/detach to image post type.
109
+ *
110
+ * @param $post_id
111
+ * @param $post
112
+ */
113
+ public function menu_image_save_post_action( $post_id, $post ) {
114
+ $menu_image_settings = array(
115
+ 'menu_item_image_size',
116
+ 'menu_item_image_title_position'
117
+ );
118
+ foreach ( $menu_image_settings as $setting_name ) {
119
+ if ( isset( $_POST[$setting_name][$post_id] ) && !empty( $_POST[$setting_name][$post_id] ) ) {
120
+ update_post_meta( $post_id, "_$setting_name", esc_sql( $_POST[$setting_name][$post_id] ) );
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Replacement edit menu walker class.
127
+ *
128
+ * @return string
129
+ */
130
+ public function menu_image_edit_nav_menu_walker_filter() {
131
+ return 'Menu_Image_Walker_Nav_Menu_Edit';
132
+ }
133
+
134
+ /**
135
+ * Load menu image meta for each menu item.
136
+ *
137
+ * @since 2.0
138
+ */
139
+ public function menu_image_wp_setup_nav_menu_item( $item ) {
140
+ if ( !isset( $item->thumbnail_id ) ) {
141
+ $item->thumbnail_id = get_post_thumbnail_id( $item->ID );
142
+ }
143
+ if ( !isset( $item->thumbnail_hover_id ) ) {
144
+ $item->thumbnail_hover_id = get_post_meta( $item->ID, '_thumbnail_hover_id', true );
145
+ }
146
+ if ( !isset( $item->image_size ) ) {
147
+ $item->image_size = get_post_meta( $item->ID, '_menu_item_image_size', true );
148
+ }
149
+ if ( !isset( $item->title_position ) ) {
150
+ $item->title_position = get_post_meta( $item->ID, '_menu_item_image_title_position', true );
151
+ }
152
+
153
+ return $item;
154
+ }
155
+
156
+ /**
157
+ * Replacement default menu item output.
158
+ *
159
+ * @param string $item_output Default item output
160
+ * @param object $item Menu item data object.
161
+ * @param int $depth Depth of menu item. Used for padding.
162
+ * @param object $args
163
+ * @return string
164
+ */
165
+ public function menu_image_nav_menu_item_filter( $item_output, $item, $depth, $args ) {
166
+ $attributes = !empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
167
+ $attributes .= !empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
168
+ $attributes .= !empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
169
+ $attributes .= !empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
170
+
171
+ $image_size = $item->image_size ? $item->image_size : apply_filters( 'menu_image_default_size', 'menu-36x36' );
172
+ $position = $item->title_position ? $item->title_position : apply_filters( 'menu_image_default_title_position', 'after' );
173
+ $class = "menu-image-title-{$position}";
174
+ if ( $item->thumbnail_hover_id ) {
175
+ $hover_image_src = wp_get_attachment_image_src( $item->thumbnail_hover_id, $image_size );
176
+ $style = '';
177
+ if ( isset( $hover_image_src[1] ) && isset( $hover_image_src[1] ) ) {
178
+ $width = $hover_image_src[1];
179
+ $height = $hover_image_src[2] + 1; // +1px because span have small inline space..
180
+ $style .= " style='width: {$width}px; height: {$height}px;'";
181
+ $attributes .= " style='line-height: {$height}px'";
182
+ }
183
+ $image = "<span class='menu-image-hover-wrapper'" . $style . ">";
184
+ $image .= wp_get_attachment_image( $item->thumbnail_id, $image_size, false, "class=menu-image {$class}" );
185
+ $image .= wp_get_attachment_image( $item->thumbnail_hover_id, $image_size, false, "class=hovered-image {$class}" );
186
+ $image .= '</span>';
187
+ $class .= ' menu-image-hovered';
188
+ } else {
189
+ $image = wp_get_attachment_image( $item->thumbnail_id, $image_size, false, "class=menu-image {$class}" );
190
+ }
191
+
192
+ $item_output = "{$args->before}<a{$attributes} class='{$class}'>";
193
+ $link = $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
194
+ switch ( $position ) {
195
+ case 'hide':
196
+ $item_output .= $image;
197
+ break;
198
+ case 'before':
199
+ $item_output .= $link . $image;
200
+ break;
201
+ case 'after':
202
+ default:
203
+ $item_output .= $image . $link;
204
+ break;
205
+ }
206
+ $item_output .= "</a>{$args->after}";
207
+
208
+ return $item_output;
209
+ }
210
+
211
+ /**
212
+ * Loading additional stylesheet.
213
+ *
214
+ * Loading custom stylesheet to fix images positioning in match themes
215
+ */
216
+ public function menu_image_add_inline_style_action() {
217
+ wp_register_style( 'menu-image', plugins_url( '', __FILE__ ) . '/menu-image.css', array(), '1.1', 'all' );
218
+ wp_enqueue_style( 'menu-image' );
219
+ }
220
+
221
+ /**
222
+ * Loading media-editor script ot nav-menus page.
223
+ *
224
+ * @since 2.0
225
+ */
226
+ public function menu_image_admin_head_nav_menus_action() {
227
+ wp_enqueue_script('menu-image-admin', plugins_url( 'menu-image-admin.js' , __FILE__ ), array('jquery'));
228
+ wp_localize_script('menu-image-admin', 'menuImage', array(
229
+ 'l10n' => array(
230
+ 'uploaderTitle' => __( 'Chose menu image', 'menu-image' ),
231
+ ),
232
+ 'settings' => array(
233
+ 'nonce' => wp_create_nonce( 'update-menu-item' ),
234
+ ),
235
+ ));
236
+ wp_enqueue_media();
237
+ wp_enqueue_style('editor-buttons');
238
+ }
239
+
240
+ /**
241
+ * When menu item removed remove menu image metadata.
242
+ */
243
+ public function menu_image_delete_menu_item_image_action() {
244
+
245
+ $menu_item_id = (int) $_REQUEST['menu-item'];
246
+
247
+ check_admin_referer( 'delete-menu_item_image_' . $menu_item_id );
248
+
249
+ if ( is_nav_menu_item( $menu_item_id ) && has_post_thumbnail( $menu_item_id ) ) {
250
+ delete_post_thumbnail( $menu_item_id );
251
+ delete_post_meta( $menu_item_id, '_thumbnail_hover_id');
252
+ delete_post_meta( $menu_item_id, '_menu_item_image_size');
253
+ delete_post_meta( $menu_item_id, '_menu_item_image_title_position');
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Output HTML for the menu item images section.
259
+ *
260
+ * @since 2.0
261
+ *
262
+ * @param int $item_id The post ID or object associated with the thumbnail, defaults to global $post.
263
+ * @return string html
264
+ */
265
+ static public function wp_post_thumbnail_html( $item_id ) {
266
+ $default_size = apply_filters( 'menu_image_default_size', 'menu-36x36' );;
267
+ $markup = '<p class="description description-thin" ><label>%s<br /><a title="%s" href="#" class="set-post-thumbnail button%s" data-item-id="%s" style="height: auto;">%s</a>%s</label></p>';
268
+
269
+ $thumbnail_id = get_post_thumbnail_id( $item_id );
270
+ $content = sprintf( $markup,
271
+ esc_html__( 'Menu image', 'menu-image' ),
272
+ $thumbnail_id ? esc_attr__( 'Change menu item image', 'menu-image' ) : esc_attr__( 'Set menu item image', 'menu-image' ),
273
+ '',
274
+ $item_id,
275
+ $thumbnail_id ? wp_get_attachment_image( $thumbnail_id, $default_size ) : esc_html__( 'Set image', 'menu-image' ),
276
+ $thumbnail_id ? '<a href="#" class="remove-post-thumbnail">' . __( 'Remove', 'menu-image' ) . '</a>' : ''
277
+ );
278
+
279
+ $hover_id = get_post_meta( $item_id, '_thumbnail_hover_id', true );
280
+ $content .= sprintf( $markup,
281
+ esc_html__( 'Image on hover', 'menu-image' ),
282
+ $hover_id ? esc_attr__( 'Change menu item image on hover', 'menu-image' ) : esc_attr__( 'Set menu item image on hover', 'menu-image' ),
283
+ ' hover-image',
284
+ $item_id,
285
+ $hover_id ? wp_get_attachment_image( $hover_id, $default_size ) : esc_html__( 'Set image on hover', 'menu-image' ),
286
+ $hover_id ? '<a href="#" class="remove-post-thumbnail hover-image">' . __( 'Remove', 'menu-image' ) . '</a>' : ''
287
+ );
288
+
289
+ $image_size = get_post_meta( $item_id, '_menu_item_image_size', true );
290
+ if (!$image_size) $image_size = $default_size;
291
+ $title_position = get_post_meta( $item_id, '_menu_item_image_title_position', true );
292
+ if (!$title_position) $title_position = apply_filters( 'menu_image_default_title_position', 'after' );
293
+
294
+ ob_start(); ?>
295
+
296
+ <div class="menu-item-image-options">
297
+ <p class="description description-thin">
298
+ <label for="edit-menu-item-image-size-<?php echo $item_id; ?>"><?php _e( 'Image size', 'menu-image' ); ?><br/>
299
+ <select id="edit-menu-item-image-size-<?php echo $item_id; ?>"
300
+ class="widefat edit-menu-item-image-size"
301
+ name="menu_item_image_size[<?php echo $item_id; ?>]">
302
+ <?php foreach ( get_intermediate_image_sizes() as $size ) :
303
+ printf("<option value='%s'%s>%s</option>\n",
304
+ esc_attr($size),
305
+ $image_size == $size ? ' selected="selected"' : '',
306
+ ucfirst($size)
307
+ ); ?>
308
+ <?php endforeach; ?>
309
+ </select>
310
+ </label>
311
+ </p>
312
+ <p class="description description-thin">
313
+ <label><?php _e( 'Title position', 'menu-image' ); ?></label><br/>
314
+ <?php
315
+ $positions = array(
316
+ 'before' => __( 'Before', 'menu-image' ),
317
+ 'hide' => __( 'Hide', 'menu-image' ),
318
+ 'after' => __( 'After', 'menu-image' ),
319
+ );
320
+ foreach ( $positions as $position => $label) :
321
+ printf("<label><input type='radio' name='menu_item_image_title_position[%s]' value='%s'%s/> %s</label>%s",
322
+ $item_id,
323
+ esc_attr($position),
324
+ $title_position == $position ? ' checked="checked"' : '',
325
+ $label,
326
+ $position != 'after' ? ' | ' : ''
327
+ );
328
+ endforeach; ?>
329
+
330
+ </p>
331
+ </div>
332
+
333
+ <?php
334
+ $content = "<div class='menu-item-images' style='min-height:70px'>$content</div>" . ob_get_clean();
335
+
336
+ /**
337
+ * Filter the admin menu item thumbnail HTML markup to return.
338
+ *
339
+ * @since 2.0
340
+ *
341
+ * @param string $content Admin menu item images HTML markup.
342
+ * @param int $item_id Post ID.
343
+ */
344
+ return apply_filters( 'admin_menu_item_thumbnail_html', $content, $item_id );
345
+ }
346
+
347
+ /**
348
+ * Update item thumbnail via ajax action.
349
+ *
350
+ * @since 2.0
351
+ */
352
+ public function wp_ajax_set_menu_item_thumbnail() {
353
+ $json = ! empty( $_REQUEST['json'] );
354
+
355
+ $post_ID = intval( $_POST['post_id'] );
356
+ if ( ! current_user_can( 'edit_post', $post_ID ) )
357
+ wp_die( -1 );
358
+
359
+ $thumbnail_id = intval( $_POST['thumbnail_id'] );
360
+ $is_hovered = (bool) $_POST['is_hover'];
361
+
362
+ check_ajax_referer( "update-menu-item" );
363
+
364
+ if ( $thumbnail_id == '-1' ) {
365
+ if ( $is_hovered ) {
366
+ $success = delete_post_meta( $post_ID, '_thumbnail_hover_id' );
367
+ } else {
368
+ $success = delete_post_thumbnail( $post_ID );
369
+ }
370
+ } else {
371
+ if ( $is_hovered ) {
372
+ $success = update_post_meta( $post_ID, '_thumbnail_hover_id', $thumbnail_id);
373
+ } else {
374
+ $success = set_post_thumbnail( $post_ID, $thumbnail_id );
375
+ }
376
+ }
377
+
378
+ if ($success) {
379
+ $return = self::wp_post_thumbnail_html( $post_ID );
380
+ $json ? wp_send_json_success( $return ) : wp_die( $return );
381
+ }
382
+
383
+ wp_die( 0 );
384
+ }
385
+ }
386
+
387
+ $menu_image = new Menu_Image_Plugin();
388
+
389
+ require_once(ABSPATH . 'wp-admin/includes/nav-menu.php');
390
+ class Menu_Image_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
391
+
392
+ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
393
+ global $_wp_nav_menu_max_depth;
394
+ $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
395
+
396
+ ob_start();
397
+ $item_id = esc_attr( $item->ID );
398
+ $removed_args = array(
399
+ 'action',
400
+ 'customlink-tab',
401
+ 'edit-menu-item',
402
+ 'menu-item',
403
+ 'page-tab',
404
+ '_wpnonce',
405
+ );
406
+
407
+ $original_title = '';
408
+ if ( 'taxonomy' == $item->type ) {
409
+ $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
410
+ if ( is_wp_error( $original_title ) )
411
+ $original_title = false;
412
+ } elseif ( 'post_type' == $item->type ) {
413
+ $original_object = get_post( $item->object_id );
414
+ $original_title = get_the_title( $original_object->ID );
415
+ }
416
+
417
+ $classes = array(
418
+ 'menu-item menu-item-depth-' . $depth,
419
+ 'menu-item-' . esc_attr( $item->object ),
420
+ 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
421
+ );
422
+
423
+ $title = $item->title;
424
+
425
+ if ( ! empty( $item->_invalid ) ) {
426
+ $classes[] = 'menu-item-invalid';
427
+ /* translators: %s: title of menu item which is invalid */
428
+ $title = sprintf( __( '%s (Invalid)' ), $item->title );
429
+ } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
430
+ $classes[] = 'pending';
431
+ /* translators: %s: title of menu item in draft status */
432
+ $title = sprintf( __('%s (Pending)'), $item->title );
433
+ }
434
+
435
+ $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
436
+
437
+ $submenu_text = '';
438
+ if ( 0 == $depth )
439
+ $submenu_text = 'style="display: none;"';
440
+
441
+ ?>
442
+ <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
443
+ <dl class="menu-item-bar">
444
+ <dt class="menu-item-handle">
445
+ <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
446
+ <span class="item-controls">
447
+ <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
448
+ <span class="item-order hide-if-js">
449
+ <a href="<?php
450
+ echo wp_nonce_url(
451
+ add_query_arg(
452
+ array(
453
+ 'action' => 'move-up-menu-item',
454
+ 'menu-item' => $item_id,
455
+ ),
456
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
457
+ ),
458
+ 'move-menu_item'
459
+ );
460
+ ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
461
+ |
462
+ <a href="<?php
463
+ echo wp_nonce_url(
464
+ add_query_arg(
465
+ array(
466
+ 'action' => 'move-down-menu-item',
467
+ 'menu-item' => $item_id,
468
+ ),
469
+ remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
470
+ ),
471
+ 'move-menu_item'
472
+ );
473
+ ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
474
+ </span>
475
+ <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
476
+ echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
477
+ ?>"><?php _e( 'Edit Menu Item' ); ?></a>
478
+ </span>
479
+ </dt>
480
+ </dl>
481
+
482
+ <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
483
+ <?php if( 'custom' == $item->type ) : ?>
484
+ <p class="field-url description description-wide">
485
+ <label for="edit-menu-item-url-<?php echo $item_id; ?>">
486
+ <?php _e( 'URL' ); ?><br />
487
+ <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
488
+ </label>
489
+ </p>
490
+ <?php endif; ?>
491
+ <p class="description description-thin">
492
+ <label for="edit-menu-item-title-<?php echo $item_id; ?>">
493
+ <?php _e( 'Navigation Label' ); ?><br />
494
+ <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
495
+ </label>
496
+ </p>
497
+ <p class="description description-thin">
498
+ <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
499
+ <?php _e( 'Title Attribute' ); ?><br />
500
+ <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
501
+ </label>
502
+ </p>
503
+ <p class="field-link-target description">
504
+ <label for="edit-menu-item-target-<?php echo $item_id; ?>">
505
+ <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
506
+ <?php _e( 'Open link in a new window/tab' ); ?>
507
+ </label>
508
+ </p>
509
+ <p class="field-css-classes description description-thin">
510
+ <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
511
+ <?php _e( 'CSS Classes (optional)' ); ?><br />
512
+ <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
513
+ </label>
514
+ </p>
515
+ <p class="field-xfn description description-thin">
516
+ <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
517
+ <?php _e( 'Link Relationship (XFN)' ); ?><br />
518
+ <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
519
+ </label>
520
+ </p>
521
+ <div class="field-image hide-if-no-js wp-media-buttons">
522
+ <?php echo Menu_Image_Plugin::wp_post_thumbnail_html( $item_id) ?>
523
+ </div>
524
+
525
+ <p class="field-description description description-wide">
526
+ <label for="edit-menu-item-description-<?php echo $item_id; ?>">
527
+ <?php _e( 'Description' ); ?><br />
528
+ <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
529
+ <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
530
+ </label>
531
+ </p>
532
+
533
+ <p class="field-move hide-if-no-js description description-wide">
534
+ <label>
535
+ <span><?php _e( 'Move' ); ?></span>
536
+ <a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a>
537
+ <a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a>
538
+ <a href="#" class="menus-move-left"></a>
539
+ <a href="#" class="menus-move-right"></a>
540
+ <a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a>
541
+ </label>
542
+ </p>
543
+
544
+ <div class="menu-item-actions description-wide submitbox">
545
+ <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
546
+ <p class="link-to-original">
547
+ <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
548
+ </p>
549
+ <?php endif; ?>
550
+ <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
551
+ echo wp_nonce_url(
552
+ add_query_arg(
553
+ array(
554
+ 'action' => 'delete-menu-item',
555
+ 'menu-item' => $item_id,
556
+ ),
557
+ admin_url( 'nav-menus.php' )
558
+ ),
559
+ 'delete-menu_item_' . $item_id
560
+ ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
561
+ ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
562
+ </div>
563
+
564
+ <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
565
+ <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
566
+ <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
567
+ <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
568
+ <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
569
+ <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
570
+ </div><!-- .menu-item-settings-->
571
+ <ul class="menu-item-transport"></ul>
572
+ <?php
573
+ $output .= ob_get_clean();
574
+ }
575
+ }
readme.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Menu Image ===
2
+ Contributors: zviryatko
3
+ Tags: menu, image, field, hover
4
+ Donate link: http://makeyoulivebetter.org.ua/buy-beer
5
+ Requires at least: 3.5.1
6
+ Tested up to: 3.9.1
7
+ Stable tag: 2.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Adds a field to load the image in a menu item and displays the image inside the link in the menu before the text.
12
+
13
+ == Description ==
14
+
15
+ Adds a field to load the image in a menu item and displays the image inside the link in the menu before the text.
16
+ Now you can upload the second image and set to the mouse over/out effect.
17
+ And also change position of title or hide title if need.
18
+ And... load images via media uploader!
19
+
20
+ == Installation ==
21
+
22
+ 1. Upload `menu-image` to the `/wp-content/plugins/` directory
23
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
24
+ 3. Go to `/wp-admin/nav-menus.php`
25
+ 4. Edit exist menu item or add new menu item and just upload image than click `Save Menu`
26
+ 5. See your menu on site
27
+
28
+ == Frequently Asked Questions ==
29
+
30
+ = How to wrap menu link text in `span` html element =
31
+
32
+ Where you show your menu with function `<?php wp_nav_menu(); ?>` as param you can add `array('link_before' => '<span>', 'link_after' => '</span>')`.
33
+ It makes css markup easier.
34
+
35
+ = How to add another size for image? =
36
+
37
+ Just register another image size in your theme with function `add_image_size()`.
38
+
39
+ == Screenshots ==
40
+
41
+ 1. Admin screen
42
+ 2. Menu preview in standard twenty-thirteen theme
43
+
44
+ == Changelog ==
45
+
46
+ = 2.0 =
47
+ * Added support of media uploader.
48
+ * Fixed php strict warnings.
49
+ * Added .ico image support, thanks to [ivol84](https://github.com/ivol84)
50
+
51
+ = 1.3 =
52
+ * Added ability to set title position, an example: before, after image or hide
53
+
54
+ = 1.2 =
55
+ * Fix styles for hovered image
56
+
57
+ = 1.1 =
58
+ * Added style file with vertical align of menu image item by default
59
+ * Added ability to upload image that which will be replaced on hover
60
+ * Added default image sizes for menu items: 24x24, 36x36 and 48x48
61
+
62
+ == Upgrade Notice ==
63
+
64
+ = 2.0 =
65
+ WARNING! You need to re-select the images! Now, with media uploader support, it's easy peasy.
66
+ Media uploader support. Upload once, use many times!
67
+
68
+ = 1.2 =
69
+ Now you can change title text position
70
+
71
+ = 1.1 =
72
+ Now you can upload image that replaced default on mouse hover