Version Description
- Released on 26th March 2013
- Add support for active and hover menu item images
Download this release
Release Info
Developer | dimadin |
Plugin | Nav Menu Images |
Version | 3.0 |
Comparing to | |
See all releases |
Code changes from version 2.0 to 3.0
- inc/admin.php +100 -5
- languages/nmi-sr_RS.mo +0 -0
- languages/nmi-sr_RS.po +24 -7
- languages/nmi.pot +27 -8
- nav-menu-images.php +88 -6
- readme.txt +13 -4
inc/admin.php
CHANGED
@@ -28,13 +28,19 @@ class Nav_Menu_Images_Admin extends Nav_Menu_Images {
|
|
28 |
*/
|
29 |
public function __construct() {
|
30 |
// Register new AJAX thumbnail response
|
31 |
-
add_filter( 'admin_post_thumbnail_html', array( &$this, '_wp_post_thumbnail_html'
|
32 |
|
33 |
// Register walker replacement
|
34 |
-
add_filter( 'wp_edit_nav_menu_walker', array( &$this, 'filter_walker'
|
35 |
|
36 |
// Register enqueuing of scripts
|
37 |
-
add_action( 'admin_menu', array( &$this, 'register_enqueuing'
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
|
40 |
/**
|
@@ -112,7 +118,7 @@ class Nav_Menu_Images_Admin extends Nav_Menu_Images {
|
|
112 |
* @since 2.0
|
113 |
* @access public
|
114 |
*
|
115 |
-
* @uses get_post()
|
116 |
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
117 |
* @uses admin_url() To get URL of uploader.
|
118 |
* @uses esc_url() To escape URL.
|
@@ -177,4 +183,93 @@ class Nav_Menu_Images_Admin extends Nav_Menu_Images {
|
|
177 |
// Filter returned HTML output
|
178 |
return apply_filters( 'nmi_admin_post_thumbnail_html', $content, $post->ID );
|
179 |
}
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
*/
|
29 |
public function __construct() {
|
30 |
// Register new AJAX thumbnail response
|
31 |
+
add_filter( 'admin_post_thumbnail_html', array( &$this, '_wp_post_thumbnail_html' ), 10, 2 );
|
32 |
|
33 |
// Register walker replacement
|
34 |
+
add_filter( 'wp_edit_nav_menu_walker', array( &$this, 'filter_walker' ) );
|
35 |
|
36 |
// Register enqueuing of scripts
|
37 |
+
add_action( 'admin_menu', array( &$this, 'register_enqueuing' ) );
|
38 |
+
|
39 |
+
// Register attachment fields display
|
40 |
+
add_filter( 'attachment_fields_to_edit', array( &$this, 'attachment_fields_to_edit' ), 10, 2 );
|
41 |
+
|
42 |
+
// Register attachment fields handling
|
43 |
+
add_filter( 'attachment_fields_to_save', array( &$this, 'attachment_fields_to_save' ), 10, 2 );
|
44 |
}
|
45 |
|
46 |
/**
|
118 |
* @since 2.0
|
119 |
* @access public
|
120 |
*
|
121 |
+
* @uses get_post() To get post's object.
|
122 |
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
123 |
* @uses admin_url() To get URL of uploader.
|
124 |
* @uses esc_url() To escape URL.
|
183 |
// Filter returned HTML output
|
184 |
return apply_filters( 'nmi_admin_post_thumbnail_html', $content, $post->ID );
|
185 |
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Display hover & active image checkboxes.
|
189 |
+
*
|
190 |
+
* @since 3.0
|
191 |
+
* @access public
|
192 |
+
*
|
193 |
+
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
194 |
+
* @uses get_post_meta() To get item's hover & active images IDs.
|
195 |
+
* @uses checked() To set proper checkbox status.
|
196 |
+
* @uses apply_filters() Calls 'nmi_attachment_fields_to_edit' to
|
197 |
+
* overwrite returned form fields.
|
198 |
+
*
|
199 |
+
* @param array $form_fields Original attachment form fields.
|
200 |
+
* @param object $post The post object data of attachment.
|
201 |
+
* @return string New attachment form fields.
|
202 |
+
*/
|
203 |
+
function attachment_fields_to_edit( $form_fields, $post ) {
|
204 |
+
// Display only for images
|
205 |
+
if ( ! wp_attachment_is_image( $post->ID ) )
|
206 |
+
return $form_fields;
|
207 |
+
|
208 |
+
// Display only for nav menu items
|
209 |
+
if ( 'nav_menu_item' != get_post_type( $post->post_parent ) )
|
210 |
+
return $form_fields;
|
211 |
+
|
212 |
+
// Load translations
|
213 |
+
$this->load_textdomain();
|
214 |
+
|
215 |
+
// Add "hover" checkbox
|
216 |
+
$parent_hover_id = get_post_meta( $post->post_parent, '_nmi_hover', true );
|
217 |
+
$is_hover = ( $parent_hover_id == $post->ID ) ? true : false;
|
218 |
+
$is_hover_checked = checked( $is_hover, true, false );
|
219 |
+
|
220 |
+
$form_fields['nmihover'] = array(
|
221 |
+
'label' => __( 'Used on hover?', 'nmi' ),
|
222 |
+
'input' => 'html',
|
223 |
+
'html' => "<input type='checkbox' class='nmi-hover-checkbox' {$is_hover_checked} name='attachments[{$post->ID}][nmihover]' id='attachments[{$post->ID}][nmihover]' data-parent='{$post->post_parent}' data-checked='{$is_hover}' />",
|
224 |
+
'value' => $is_hover,
|
225 |
+
'helps' => __( 'Should this image be used on hover', 'nmi' ),
|
226 |
+
'show_in_edit' => false
|
227 |
+
);
|
228 |
+
|
229 |
+
// Add "active" checkbox
|
230 |
+
$parent_active_id = get_post_meta( $post->post_parent, '_nmi_active', true );
|
231 |
+
$is_active = ( $parent_active_id == $post->ID ) ? true : false;
|
232 |
+
$is_active_checked = checked( $is_active, true, false );
|
233 |
+
|
234 |
+
$form_fields['nmiactive'] = array(
|
235 |
+
'label' => __( 'Used when active?', 'nmi' ),
|
236 |
+
'input' => 'html',
|
237 |
+
'html' => "<input type='checkbox' class='nmi-active-checkbox' {$is_active_checked} name='attachments[{$post->ID}][nmiactive]' id='attachments[{$post->ID}][nmiactive]' data-parent='{$post->post_parent}' data-checked='{$is_active}' />",
|
238 |
+
'value' => $is_active,
|
239 |
+
'helps' => __( 'Should this image be used when menu item is active', 'nmi' ),
|
240 |
+
'show_in_edit' => false
|
241 |
+
);
|
242 |
+
|
243 |
+
// Filter returned HTML output
|
244 |
+
return apply_filters( 'nmi_attachment_fields_to_edit', $form_fields, $post );
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Save hover & active image checkboxes submissions.
|
249 |
+
*
|
250 |
+
* @since 3.0
|
251 |
+
* @access public
|
252 |
+
*
|
253 |
+
* @uses update_post_meta() To save new item's hover or active images IDs.
|
254 |
+
* @uses delete_post_meta() To delete old item's hover or active images IDs.
|
255 |
+
*
|
256 |
+
* @param object $post The post object data of attachment.
|
257 |
+
* @param array $attachment Submitted data of attachment.
|
258 |
+
* @return object $post The post object data of attachment.
|
259 |
+
*/
|
260 |
+
function attachment_fields_to_save( $post, $attachment ) {
|
261 |
+
// Save "hover" checkbox
|
262 |
+
if ( 'on' == $attachment['nmihover'] )
|
263 |
+
update_post_meta( $post['post_parent'], '_nmi_hover', $post['ID'] );
|
264 |
+
else
|
265 |
+
delete_post_meta( $post['post_parent'], '_nmi_hover', $post['ID'] );
|
266 |
+
|
267 |
+
// Save "active" checkbox
|
268 |
+
if ( 'on' == $attachment['nmiactive'] )
|
269 |
+
update_post_meta( $post['post_parent'], '_nmi_active', $post['ID'] );
|
270 |
+
else
|
271 |
+
delete_post_meta( $post['post_parent'], '_nmi_active', $post['ID'] );
|
272 |
+
|
273 |
+
return $post;
|
274 |
+
}
|
275 |
+
}
|
languages/nmi-sr_RS.mo
CHANGED
Binary file
|
languages/nmi-sr_RS.po
CHANGED
@@ -4,8 +4,8 @@ msgid ""
|
|
4 |
msgstr ""
|
5 |
"Project-Id-Version: Nav Menu Images\n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
-
"POT-Creation-Date: 2013-
|
8 |
-
"PO-Revision-Date: 2013-
|
9 |
"Last-Translator: Milan Dinić <milan@srpski.biz>\n"
|
10 |
"Language-Team: \n"
|
11 |
"MIME-Version: 1.0\n"
|
@@ -15,7 +15,7 @@ msgstr ""
|
|
15 |
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
16 |
"X-Generator: Poedit 1.5.5\n"
|
17 |
|
18 |
-
#: inc/admin.php:
|
19 |
msgid ""
|
20 |
"You need to set an image as a featured image to be able to use it as an menu "
|
21 |
"item image"
|
@@ -23,19 +23,36 @@ msgstr ""
|
|
23 |
"Потребно је да поставите слику као одабрану да бисте могли да је користите "
|
24 |
"као слику ставке изборника"
|
25 |
|
26 |
-
#: inc/admin.php:
|
27 |
msgid "Upload menu item image"
|
28 |
msgstr "Отпреми слику ставке изборника"
|
29 |
|
30 |
-
#: inc/admin.php:
|
31 |
msgid "Change menu item image"
|
32 |
msgstr "Промени слику ставке изборника"
|
33 |
|
34 |
-
#: inc/admin.php:
|
35 |
msgid "Remove menu item image"
|
36 |
msgstr "Уклони слику ставке изборника"
|
37 |
|
38 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
msgid "Donate"
|
40 |
msgstr "Донирај"
|
41 |
|
4 |
msgstr ""
|
5 |
"Project-Id-Version: Nav Menu Images\n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
+
"POT-Creation-Date: 2013-03-26 16:01:26+00:00\n"
|
8 |
+
"PO-Revision-Date: 2013-03-26 17:04+0100\n"
|
9 |
"Last-Translator: Milan Dinić <milan@srpski.biz>\n"
|
10 |
"Language-Team: \n"
|
11 |
"MIME-Version: 1.0\n"
|
15 |
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
16 |
"X-Generator: Poedit 1.5.5\n"
|
17 |
|
18 |
+
#: inc/admin.php:83
|
19 |
msgid ""
|
20 |
"You need to set an image as a featured image to be able to use it as an menu "
|
21 |
"item image"
|
23 |
"Потребно је да поставите слику као одабрану да бисте могли да је користите "
|
24 |
"као слику ставке изборника"
|
25 |
|
26 |
+
#: inc/admin.php:167 inc/walker.php:84
|
27 |
msgid "Upload menu item image"
|
28 |
msgstr "Отпреми слику ставке изборника"
|
29 |
|
30 |
+
#: inc/admin.php:174 inc/walker.php:75
|
31 |
msgid "Change menu item image"
|
32 |
msgstr "Промени слику ставке изборника"
|
33 |
|
34 |
+
#: inc/admin.php:176 inc/walker.php:80
|
35 |
msgid "Remove menu item image"
|
36 |
msgstr "Уклони слику ставке изборника"
|
37 |
|
38 |
+
#: inc/admin.php:221
|
39 |
+
msgid "Used on hover?"
|
40 |
+
msgstr "Користи се приликом преласка?"
|
41 |
+
|
42 |
+
#: inc/admin.php:225
|
43 |
+
msgid "Should this image be used on hover"
|
44 |
+
msgstr "Да ли би ова слика требало да се користи приликом преласка"
|
45 |
+
|
46 |
+
#: inc/admin.php:235
|
47 |
+
msgid "Used when active?"
|
48 |
+
msgstr "Користи је када је активна?"
|
49 |
+
|
50 |
+
#: inc/admin.php:239
|
51 |
+
msgid "Should this image be used when menu item is active"
|
52 |
+
msgstr ""
|
53 |
+
"Да ли би ова слика требало да се користи када је ставка изборника активна"
|
54 |
+
|
55 |
+
#: nav-menu-images.php:320
|
56 |
msgid "Donate"
|
57 |
msgstr "Донирај"
|
58 |
|
languages/nmi.pot
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
# This file is distributed under the same license as the Nav Menu Images package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: Nav Menu Images
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
-
"POT-Creation-Date: 2013-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -12,25 +12,44 @@ msgstr ""
|
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
-
#: inc/admin.php:
|
16 |
-
msgid "
|
|
|
|
|
17 |
msgstr ""
|
18 |
|
19 |
-
#: inc/admin.php:
|
20 |
msgid "Upload menu item image"
|
21 |
msgstr ""
|
22 |
|
23 |
-
#: inc/admin.php:
|
24 |
msgid "Change menu item image"
|
25 |
msgstr ""
|
26 |
|
27 |
-
#: inc/admin.php:
|
28 |
msgid "Remove menu item image"
|
29 |
msgstr ""
|
30 |
|
31 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
msgid "Donate"
|
33 |
msgstr ""
|
|
|
34 |
#. Plugin Name of the plugin/theme
|
35 |
msgid "Nav Menu Images"
|
36 |
msgstr ""
|
2 |
# This file is distributed under the same license as the Nav Menu Images package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: Nav Menu Images 3.0\n"
|
6 |
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
+
"POT-Creation-Date: 2013-03-26 16:01:26+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
+
#: inc/admin.php:83
|
16 |
+
msgid ""
|
17 |
+
"You need to set an image as a featured image to be able to use it as an menu "
|
18 |
+
"item image"
|
19 |
msgstr ""
|
20 |
|
21 |
+
#: inc/admin.php:167 inc/walker.php:84
|
22 |
msgid "Upload menu item image"
|
23 |
msgstr ""
|
24 |
|
25 |
+
#: inc/admin.php:174 inc/walker.php:75
|
26 |
msgid "Change menu item image"
|
27 |
msgstr ""
|
28 |
|
29 |
+
#: inc/admin.php:176 inc/walker.php:80
|
30 |
msgid "Remove menu item image"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: inc/admin.php:221
|
34 |
+
msgid "Used on hover?"
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
#: inc/admin.php:225
|
38 |
+
msgid "Should this image be used on hover"
|
39 |
+
msgstr ""
|
40 |
+
|
41 |
+
#: inc/admin.php:235
|
42 |
+
msgid "Used when active?"
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#: inc/admin.php:239
|
46 |
+
msgid "Should this image be used when menu item is active"
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#: nav-menu-images.php:320
|
50 |
msgid "Donate"
|
51 |
msgstr ""
|
52 |
+
|
53 |
#. Plugin Name of the plugin/theme
|
54 |
msgid "Nav Menu Images"
|
55 |
msgstr ""
|
nav-menu-images.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
* Description: Display image as a menu content.
|
16 |
* Author: Milan Dinić
|
17 |
* Author URI: http://blog.milandinic.com/
|
18 |
-
* Version:
|
19 |
* Text Domain: nmi
|
20 |
* Domain Path: /languages/
|
21 |
* License: GPL
|
@@ -39,6 +39,15 @@ class Nav_Menu_Images {
|
|
39 |
*/
|
40 |
protected $plugin_basename;
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
/**
|
43 |
* Sets class properties.
|
44 |
*
|
@@ -181,23 +190,94 @@ class Nav_Menu_Images {
|
|
181 |
return $content;
|
182 |
}
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
/**
|
185 |
* Register menu item content filter.
|
186 |
*
|
|
|
|
|
|
|
187 |
* @since 1.0
|
188 |
* @access public
|
189 |
*
|
190 |
* @uses has_post_thumbnail() To check if item has thumb.
|
191 |
* @uses add_filter() To hook filter.
|
192 |
*
|
193 |
-
* @param array $item_classes Item's classes
|
194 |
* @param object $item Menu item data object.
|
195 |
* @param object $args Item's arguments.
|
196 |
-
* @return array $item_classes Item's classes
|
197 |
*/
|
198 |
public function register_menu_item_filter( $item_classes, $item, $args ) {
|
199 |
-
if ( has_post_thumbnail( $item->ID ) )
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
return $item_classes;
|
203 |
}
|
@@ -215,7 +295,9 @@ class Nav_Menu_Images {
|
|
215 |
* @return string $item_output Item's content
|
216 |
*/
|
217 |
public function deregister_menu_item_filter( $item_output, $item ) {
|
218 |
-
remove_filter( 'the_title',
|
|
|
|
|
219 |
|
220 |
return $item_output;
|
221 |
}
|
15 |
* Description: Display image as a menu content.
|
16 |
* Author: Milan Dinić
|
17 |
* Author URI: http://blog.milandinic.com/
|
18 |
+
* Version: 3.0
|
19 |
* Text Domain: nmi
|
20 |
* Domain Path: /languages/
|
21 |
* License: GPL
|
39 |
*/
|
40 |
protected $plugin_basename;
|
41 |
|
42 |
+
/**
|
43 |
+
* Is last menu item of current page.
|
44 |
+
*
|
45 |
+
* @var $is_current_item
|
46 |
+
* @since 3.0
|
47 |
+
* @access public
|
48 |
+
*/
|
49 |
+
public $is_current_item;
|
50 |
+
|
51 |
/**
|
52 |
* Sets class properties.
|
53 |
*
|
190 |
return $content;
|
191 |
}
|
192 |
|
193 |
+
/**
|
194 |
+
* Display a hover image for menu item image.
|
195 |
+
*
|
196 |
+
* @since 3.0
|
197 |
+
* @access public
|
198 |
+
*
|
199 |
+
* Thanks {@link http://www.webmasterworld.com/forum21/6615.htm}
|
200 |
+
*
|
201 |
+
* @uses get_post_meta() To get item's hover & active images IDs.
|
202 |
+
* @uses wp_get_attachment_image_src() To get hover image's data.
|
203 |
+
* @uses apply_filters() Calls 'nmi_menu_item_hover' to
|
204 |
+
* filter returned attributes.
|
205 |
+
*
|
206 |
+
* @param array $attr Image's attributes.
|
207 |
+
* @param object $attachment Image's post object data.
|
208 |
+
* @return array $attr New image's attributes.
|
209 |
+
*/
|
210 |
+
public function menu_item_hover( $attr, $attachment ) {
|
211 |
+
if ( ( $hover_id = get_post_meta( $attachment->post_parent, '_nmi_hover', true ) ) && ! ( $this->is_current_item && get_post_meta( $attachment->post_parent, '_nmi_active', true ) ) ) {
|
212 |
+
$image = wp_get_attachment_image_src( $hover_id, 'full', false );
|
213 |
+
$url = $image[0];
|
214 |
+
$src = $attr['src'];
|
215 |
+
$attr['onmouseover'] = 'this.src=\'' . $url . '\'';
|
216 |
+
$attr['onmouseout'] = 'this.src=\'' . $src . '\'';
|
217 |
+
|
218 |
+
$attr = apply_filters( 'nmi_menu_item_hover', $attr, $attachment );
|
219 |
+
}
|
220 |
+
|
221 |
+
return $attr;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Display an active image for menu item.
|
226 |
+
*
|
227 |
+
* @since 3.0
|
228 |
+
* @access public
|
229 |
+
*
|
230 |
+
* @uses get_post_meta() To get item's active image ID.
|
231 |
+
* @uses wp_get_attachment_image_src() To get active image's data.
|
232 |
+
* @uses apply_filters() Calls 'nmi_menu_item_active' to
|
233 |
+
* filter returned attributes.
|
234 |
+
*
|
235 |
+
* @param array $attr Image's attributes.
|
236 |
+
* @param object $attachment Image's post object data.
|
237 |
+
* @return array $attr New image's attributes.
|
238 |
+
*/
|
239 |
+
public function menu_item_active( $attr, $attachment ) {
|
240 |
+
if ( $this->is_current_item && ( $active_id = get_post_meta( $attachment->post_parent, '_nmi_active', true ) ) ) {
|
241 |
+
$image = wp_get_attachment_image_src( $active_id, 'full', false );
|
242 |
+
$url = $image[0];
|
243 |
+
$attr['src'] = $url;
|
244 |
+
|
245 |
+
$attr = apply_filters( 'nmi_menu_item_active', $attr, $attachment );
|
246 |
+
}
|
247 |
+
|
248 |
+
return $attr;
|
249 |
+
}
|
250 |
+
|
251 |
/**
|
252 |
* Register menu item content filter.
|
253 |
*
|
254 |
+
* Also check if menu item is of
|
255 |
+
* currently displayed page.
|
256 |
+
*
|
257 |
* @since 1.0
|
258 |
* @access public
|
259 |
*
|
260 |
* @uses has_post_thumbnail() To check if item has thumb.
|
261 |
* @uses add_filter() To hook filter.
|
262 |
*
|
263 |
+
* @param array $item_classes Item's classes.
|
264 |
* @param object $item Menu item data object.
|
265 |
* @param object $args Item's arguments.
|
266 |
+
* @return array $item_classes Item's classes.
|
267 |
*/
|
268 |
public function register_menu_item_filter( $item_classes, $item, $args ) {
|
269 |
+
if ( has_post_thumbnail( $item->ID ) ) {
|
270 |
+
// Register filters
|
271 |
+
add_filter( 'the_title', array( &$this, 'menu_item_content' ), 15, 2 );
|
272 |
+
add_filter( 'wp_get_attachment_image_attributes', array( &$this, 'menu_item_hover' ), 15, 2 );
|
273 |
+
add_filter( 'wp_get_attachment_image_attributes', array( &$this, 'menu_item_active' ), 15, 2 );
|
274 |
+
|
275 |
+
// Mark current item status
|
276 |
+
if ( in_array( 'current-menu-item', $item_classes ) )
|
277 |
+
$this->is_current_item = true;
|
278 |
+
else
|
279 |
+
$this->is_current_item = false;
|
280 |
+
}
|
281 |
|
282 |
return $item_classes;
|
283 |
}
|
295 |
* @return string $item_output Item's content
|
296 |
*/
|
297 |
public function deregister_menu_item_filter( $item_output, $item ) {
|
298 |
+
remove_filter( 'the_title', array( &$this, 'menu_item_content' ), 15, 2 );
|
299 |
+
remove_filter( 'wp_get_attachment_image_attributes', array( &$this, 'menu_item_hover' ), 15, 2 );
|
300 |
+
remove_filter( 'wp_get_attachment_image_attributes', array( &$this, 'menu_item_active' ), 15, 2 );
|
301 |
|
302 |
return $item_output;
|
303 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://blog.milandinic.com/donate/
|
|
4 |
Tags: nav menu, menu, media, image
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5.1
|
7 |
-
Stable tag:
|
8 |
|
9 |
Display image as a menu item content.
|
10 |
|
@@ -14,11 +14,13 @@ Display image as a menu item content.
|
|
14 |
|
15 |
This plugin enables you to upload images for nav menu items on a menu edit screen. By default, those images will be displayed instead of text for respective menu items. Note that after upload, you should set an image as 'featured' to be able to display it.
|
16 |
|
17 |
-
|
|
|
|
|
18 |
|
19 |
Although this plugin displays uploaded images out of the box, it will probably not give best possible look, so it's recommended to create custom CSS styles for affected elements.
|
20 |
|
21 |
-
Nav Menu Images code is
|
22 |
](http://huellaspyp.com/)/[∞manos s.a.s](http://8manos.com/) and a code from plugin [Metronet Profile Picture](http://wordpress.org/extend/plugins/metronet-profile-picture/) by [Ronald Huereca](http://www.ronalfy.com/)/[Metronet Norge AS](http://www.metronet.no/).
|
23 |
|
24 |
== Installation ==
|
@@ -33,11 +35,18 @@ There are no configuration options in this plugin.
|
|
33 |
== Screenshots ==
|
34 |
|
35 |
1. Link to upload form on nav menu item's edit screen
|
36 |
-
2.
|
|
|
|
|
37 |
|
38 |
== Changelog ==
|
39 |
|
|
|
|
|
|
|
|
|
40 |
= 2.0 =
|
|
|
41 |
* Use new media views for WordPress 3.5+
|
42 |
* Add more hooks for developers
|
43 |
|
4 |
Tags: nav menu, menu, media, image
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.5.1
|
7 |
+
Stable tag: 3.0
|
8 |
|
9 |
Display image as a menu item content.
|
10 |
|
14 |
|
15 |
This plugin enables you to upload images for nav menu items on a menu edit screen. By default, those images will be displayed instead of text for respective menu items. Note that after upload, you should set an image as 'featured' to be able to display it.
|
16 |
|
17 |
+
You can also set images that will be displayed only when you hover menu item, or when menu item is of currently displayed page. See screenshots to get an idea how to do this.
|
18 |
+
|
19 |
+
Developers can use many available filters to make their own way of displaying images, or even create a child class on top of base one. See source code for more ideas.
|
20 |
|
21 |
Although this plugin displays uploaded images out of the box, it will probably not give best possible look, so it's recommended to create custom CSS styles for affected elements.
|
22 |
|
23 |
+
Nav Menu Images code is partly based on a code from now defunct plugin Custom Menu Images by [Anabelle Handdoek
|
24 |
](http://huellaspyp.com/)/[∞manos s.a.s](http://8manos.com/) and a code from plugin [Metronet Profile Picture](http://wordpress.org/extend/plugins/metronet-profile-picture/) by [Ronald Huereca](http://www.ronalfy.com/)/[Metronet Norge AS](http://www.metronet.no/).
|
25 |
|
26 |
== Installation ==
|
35 |
== Screenshots ==
|
36 |
|
37 |
1. Link to upload form on nav menu item's edit screen
|
38 |
+
2. Setting featured image from media modal screen
|
39 |
+
3. Uploaded image on nav menu item's edit screen
|
40 |
+
4. Setting image used on hover from media modal screen
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 3.0 =
|
45 |
+
* Released on 26th March 2013
|
46 |
+
* Add support for active and hover menu item images
|
47 |
+
|
48 |
= 2.0 =
|
49 |
+
* Released on 11th February 2013
|
50 |
* Use new media views for WordPress 3.5+
|
51 |
* Add more hooks for developers
|
52 |
|