Version Description
Download this release
Release Info
Developer | dimadin |
Plugin | Nav Menu Images |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- inc/admin.php +90 -0
- inc/nmi.js +54 -0
- inc/walker.php +73 -0
- languages/nmi-sr_RS.mo +0 -0
- languages/nmi-sr_RS.po +56 -0
- languages/nmi.pot +51 -0
- nav-menu-images.php +253 -0
- readme.txt +36 -0
inc/admin.php
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Nav Menu Images Admin Functions
|
4 |
+
*
|
5 |
+
* @package Nav Menu Images
|
6 |
+
* @subpackage Admin Functions
|
7 |
+
*/
|
8 |
+
|
9 |
+
/* Exit if accessed directly */
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Nav Menu Images admin functions.
|
14 |
+
*
|
15 |
+
* @since 1.0
|
16 |
+
*
|
17 |
+
* @uses Nav_Menu_Images
|
18 |
+
*/
|
19 |
+
class Nav_Menu_Images_Admin extends Nav_Menu_Images {
|
20 |
+
/**
|
21 |
+
* Sets class properties.
|
22 |
+
*
|
23 |
+
* @since 1.0
|
24 |
+
* @access public
|
25 |
+
*
|
26 |
+
* @uses add_filter() To hook filters.
|
27 |
+
* @uses add_action() To hook function.
|
28 |
+
*/
|
29 |
+
public function __construct() {
|
30 |
+
// Register walker replacement
|
31 |
+
add_filter( 'wp_edit_nav_menu_walker', array( &$this, 'filter_walker' ) );
|
32 |
+
|
33 |
+
// Register enqueuing of scripts
|
34 |
+
add_action( 'admin_menu', array( &$this, 'register_enqueuing' ) );
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Register script enqueuing on nav menu page.
|
39 |
+
*
|
40 |
+
* @since 1.0
|
41 |
+
* @access public
|
42 |
+
*
|
43 |
+
* @uses add_action() To hook function.
|
44 |
+
*/
|
45 |
+
public function register_enqueuing() {
|
46 |
+
add_action( 'admin_print_scripts-nav-menus.php', array( &$this, 'enqueue_scripts' ) );
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Enqueue necessary scripts.
|
51 |
+
*
|
52 |
+
* @since 1.0
|
53 |
+
* @access public
|
54 |
+
*
|
55 |
+
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
56 |
+
* @uses wp_enqueue_script() To enqueue script.
|
57 |
+
* @uses plugins_url() To get URL of the file.
|
58 |
+
* @uses wp_localize_script() To add script's variables.
|
59 |
+
* @uses wp_enqueue_style() To enqueue style.
|
60 |
+
*/
|
61 |
+
public function enqueue_scripts() {
|
62 |
+
// Load translations
|
63 |
+
$this->load_textdomain();
|
64 |
+
|
65 |
+
wp_enqueue_script( 'nmi-scripts', plugins_url( 'nmi.js', __FILE__ ), array( 'media-upload', 'thickbox' ), '1', true );
|
66 |
+
wp_localize_script( 'nmi-scripts', 'nmi_vars', array(
|
67 |
+
'alert' => __( 'You need to set an image as a featured image to be able to use it as an menu item image', 'nmi' )
|
68 |
+
)
|
69 |
+
);
|
70 |
+
wp_enqueue_style( 'thickbox' );
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Use custom walker for nav menu edit.
|
75 |
+
*
|
76 |
+
* @since 1.0
|
77 |
+
* @access public
|
78 |
+
*
|
79 |
+
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
80 |
+
*
|
81 |
+
* @param string $walker Name of used walker class.
|
82 |
+
*/
|
83 |
+
public function filter_walker( $walker ) {
|
84 |
+
// Load translations
|
85 |
+
$this->load_textdomain();
|
86 |
+
|
87 |
+
require_once dirname( __FILE__ ) . '/walker.php';
|
88 |
+
return 'NMI_Walker_Nav_Menu_Edit';
|
89 |
+
}
|
90 |
+
}
|
inc/nmi.js
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Display thumb when set as featured.
|
3 |
+
*
|
4 |
+
* Overwritess built in function.
|
5 |
+
*/
|
6 |
+
function WPSetThumbnailID( id ) {
|
7 |
+
tb_remove();
|
8 |
+
jQuery.post( ajaxurl, {
|
9 |
+
action: "nmi_added_thumbnail",
|
10 |
+
thumbnail_id: id,
|
11 |
+
post_id: window.clicked_item_id
|
12 |
+
}, function( response ) {
|
13 |
+
jQuery("li#menu-item-"+window.clicked_item_id+" .nmi-current-image").html( response );
|
14 |
+
tb_remove();
|
15 |
+
}
|
16 |
+
);
|
17 |
+
};
|
18 |
+
|
19 |
+
function WPSetThumbnailHTML( html ) {
|
20 |
+
};
|
21 |
+
|
22 |
+
jQuery( document ).ready( function( $ ) {
|
23 |
+
// Get all menu items
|
24 |
+
var items = $("ul#menu-to-edit li.menu-item");
|
25 |
+
|
26 |
+
// Go through all items and display link & thumb
|
27 |
+
for ( var i = 0; i < items.length; i++ ) {
|
28 |
+
var id = $(items[i]).children("#nmi_item_id").val();
|
29 |
+
|
30 |
+
var sibling = $("#edit-menu-item-attr-title-"+id).parent().parent();
|
31 |
+
var image_div = $("li#menu-item-"+id+" .nmi-current-image");
|
32 |
+
var link_div = $("li#menu-item-"+id+" .nmi-upload-link");
|
33 |
+
|
34 |
+
if ( image_div ) {
|
35 |
+
sibling.after( image_div );
|
36 |
+
image_div.show();
|
37 |
+
}
|
38 |
+
if ( link_div ) {
|
39 |
+
sibling.after( link_div );
|
40 |
+
link_div.show();
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
// Save item ID on click on a link
|
45 |
+
$(".nmi-upload-link").click( function() {
|
46 |
+
window.clicked_item_id = $(this).parent().parent().children("#nmi_item_id").val();
|
47 |
+
} );
|
48 |
+
|
49 |
+
// Display alert when not added as featured
|
50 |
+
window.send_to_editor = function( html ) {
|
51 |
+
alert(nmi_vars.alert);
|
52 |
+
tb_remove();
|
53 |
+
};
|
54 |
+
} );
|
inc/walker.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Nav Menu Images Nav Menu Edit Walker
|
4 |
+
*
|
5 |
+
* @package Nav Menu Images
|
6 |
+
* @subpackage Nav Menu Edit Walker
|
7 |
+
*/
|
8 |
+
|
9 |
+
/* Exit if accessed directly */
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Filter nav menu items on edit screen.
|
14 |
+
*
|
15 |
+
* @since 1.0
|
16 |
+
*
|
17 |
+
* @uses Walker_Nav_Menu_Edit
|
18 |
+
*/
|
19 |
+
class NMI_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
|
20 |
+
/**
|
21 |
+
* @see Walker_Nav_Menu_Edit::start_el()
|
22 |
+
* @since 1.0
|
23 |
+
* @access public
|
24 |
+
*
|
25 |
+
* @uses Walker_Nav_Menu_Edit::start_el()
|
26 |
+
* @uses admin_url() To get URL of uploader.
|
27 |
+
* @uses esc_url() To escape URL.
|
28 |
+
* @uses add_query_arg() To append variables to URL.
|
29 |
+
* @uses esc_attr() To escape string.
|
30 |
+
* @uses has_post_thumbnail() To check if item has thumb.
|
31 |
+
* @uses get_the_post_thumbnail() To get item's thumb.
|
32 |
+
* @uses esc_html() To escape string.
|
33 |
+
*
|
34 |
+
* @param string $output Passed by reference. Used to append additional content.
|
35 |
+
* @param object $item Menu item data object.
|
36 |
+
* @param int $depth Depth of menu item. Used for padding.
|
37 |
+
* @param object $args
|
38 |
+
*/
|
39 |
+
public function start_el( &$output, $item, $depth, $args ) {
|
40 |
+
// First, make item with standard class
|
41 |
+
parent::start_el( $output, $item, $depth, $args );
|
42 |
+
|
43 |
+
// Now add additional content
|
44 |
+
$item_id = $item->ID;
|
45 |
+
|
46 |
+
// Form upload link
|
47 |
+
$upload_url = admin_url( 'media-upload.php' );
|
48 |
+
$query_args = array(
|
49 |
+
'post_id' => $item_id,
|
50 |
+
'tab' => 'gallery',
|
51 |
+
'TB_iframe' => '1',
|
52 |
+
'width' => '640',
|
53 |
+
'height' => '425'
|
54 |
+
);
|
55 |
+
$upload_url = esc_url( add_query_arg( $query_args, $upload_url ) );
|
56 |
+
|
57 |
+
// Hidden field with item's ID
|
58 |
+
$output .= '<input type="hidden" name="nmi_item_id" id="nmi_item_id" value="' . esc_attr( $item_id ) . '" />';
|
59 |
+
|
60 |
+
// Generate menu item image & link's text string
|
61 |
+
if ( has_post_thumbnail( $item_id ) ) {
|
62 |
+
$post_thumbnail = get_the_post_thumbnail( $item_id, 'thumb' );
|
63 |
+
$output .= '<div class="nmi-current-image" style="display: none;"><a href="' . $upload_url . '" class="thickbox add_media">' . $post_thumbnail . '</a></div>';
|
64 |
+
$link_text = __( 'Change menu item image', 'nmi' );
|
65 |
+
} else {
|
66 |
+
$output .= '<div class="nmi-current-image" style="display: none;"></div>';
|
67 |
+
$link_text = __( 'Upload menu item image', 'nmi' );
|
68 |
+
}
|
69 |
+
|
70 |
+
// Generate menu item upload link
|
71 |
+
$output .= '<div class="nmi-upload-link" style="display: none;"><a href="' . $upload_url . '" class="thickbox add_media">' . esc_html( $link_text ) . '</a></div>';
|
72 |
+
}
|
73 |
+
}
|
languages/nmi-sr_RS.mo
ADDED
Binary file
|
languages/nmi-sr_RS.po
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Translation of Nav Menu Images in Serbian
|
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\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
+
"POT-Creation-Date: 2012-10-04 19:54:38+00:00\n"
|
8 |
+
"PO-Revision-Date: 2012-10-08 21:16+0100\n"
|
9 |
+
"Last-Translator: Milan Dinić <milan@srpski.biz>\n"
|
10 |
+
"Language-Team: \n"
|
11 |
+
"MIME-Version: 1.0\n"
|
12 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
13 |
+
"Content-Transfer-Encoding: 8bit\n"
|
14 |
+
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
|
15 |
+
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
16 |
+
"X-Generator: Poedit 1.5.3\n"
|
17 |
+
|
18 |
+
#: inc/admin.php:46
|
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"
|
22 |
+
msgstr ""
|
23 |
+
"Потребно је да поставите слику као одабрану да бисте могли да је користите "
|
24 |
+
"као слику ставке изборника"
|
25 |
+
|
26 |
+
#: inc/walker.php:50
|
27 |
+
msgid "Change menu item image"
|
28 |
+
msgstr "Промени слику ставке изборника"
|
29 |
+
|
30 |
+
#: inc/walker.php:53
|
31 |
+
msgid "Upload menu item image"
|
32 |
+
msgstr "Отпреми слику ставке изборника"
|
33 |
+
|
34 |
+
#: nav-menu-images.php:165
|
35 |
+
msgid "Donate"
|
36 |
+
msgstr "Донирај"
|
37 |
+
|
38 |
+
#. Plugin Name of the plugin/theme
|
39 |
+
msgid "Nav Menu Images"
|
40 |
+
msgstr "Слике у изборнику кретања"
|
41 |
+
|
42 |
+
#. Plugin URI of the plugin/theme
|
43 |
+
msgid "http://blog.milandinic.com/wordpress/plugins/nav-menu-images/"
|
44 |
+
msgstr "http://blog.milandinic.com/wordpress/plugins/nav-menu-images/"
|
45 |
+
|
46 |
+
#. Description of the plugin/theme
|
47 |
+
msgid "Display image as a menu content."
|
48 |
+
msgstr "Прикажите слику као садржај ставке изборника."
|
49 |
+
|
50 |
+
#. Author of the plugin/theme
|
51 |
+
msgid "Milan Dinić"
|
52 |
+
msgstr "Милан Динић"
|
53 |
+
|
54 |
+
#. Author URI of the plugin/theme
|
55 |
+
msgid "http://blog.milandinic.com/"
|
56 |
+
msgstr "http://www.milandinic.com/"
|
languages/nmi.pot
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2012 Nav Menu Images
|
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 1.0\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/nav-menu-images\n"
|
7 |
+
"POT-Creation-Date: 2012-10-04 19:54:38+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
|
12 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
+
|
15 |
+
#: inc/admin.php:46
|
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/walker.php:50
|
22 |
+
msgid "Change menu item image"
|
23 |
+
msgstr ""
|
24 |
+
|
25 |
+
#: inc/walker.php:53
|
26 |
+
msgid "Upload menu item image"
|
27 |
+
msgstr ""
|
28 |
+
|
29 |
+
#: nav-menu-images.php:165
|
30 |
+
msgid "Donate"
|
31 |
+
msgstr ""
|
32 |
+
|
33 |
+
#. Plugin Name of the plugin/theme
|
34 |
+
msgid "Nav Menu Images"
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
#. Plugin URI of the plugin/theme
|
38 |
+
msgid "http://blog.milandinic.com/wordpress/plugins/nav-menu-images/"
|
39 |
+
msgstr ""
|
40 |
+
|
41 |
+
#. Description of the plugin/theme
|
42 |
+
msgid "Display image as a menu content."
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#. Author of the plugin/theme
|
46 |
+
msgid "Milan Dinić"
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#. Author URI of the plugin/theme
|
50 |
+
msgid "http://blog.milandinic.com/"
|
51 |
+
msgstr ""
|
nav-menu-images.php
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The Nav Menu Images Plugin
|
5 |
+
*
|
6 |
+
* Display image as a menu item content.
|
7 |
+
*
|
8 |
+
* @package Nav Menu Images
|
9 |
+
* @subpackage Main
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Plugin Name: Nav Menu Images
|
14 |
+
* Plugin URI: http://blog.milandinic.com/wordpress/plugins/nav-menu-images/
|
15 |
+
* Description: Display image as a menu content.
|
16 |
+
* Author: Milan Dinić
|
17 |
+
* Author URI: http://blog.milandinic.com/
|
18 |
+
* Version: 1.0
|
19 |
+
* Text Domain: nmi
|
20 |
+
* Domain Path: /languages/
|
21 |
+
* License: GPL
|
22 |
+
*/
|
23 |
+
|
24 |
+
/* Exit if accessed directly */
|
25 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Display image as a menu content.
|
29 |
+
*
|
30 |
+
* @since 1.0
|
31 |
+
*/
|
32 |
+
class Nav_Menu_Images {
|
33 |
+
/**
|
34 |
+
* Name of a plugin's file.
|
35 |
+
*
|
36 |
+
* @var $plugin_basename
|
37 |
+
* @since 1.0
|
38 |
+
* @access protected
|
39 |
+
*/
|
40 |
+
protected $plugin_basename;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Sets class properties.
|
44 |
+
*
|
45 |
+
* @since 1.0
|
46 |
+
* @access public
|
47 |
+
*
|
48 |
+
* @uses add_action() To hook function.
|
49 |
+
* @uses plugin_basename() To get plugin's file name.
|
50 |
+
*/
|
51 |
+
public function __construct() {
|
52 |
+
// Register init
|
53 |
+
add_action( 'init', array( &$this, 'init' ) );
|
54 |
+
|
55 |
+
// Get a basename
|
56 |
+
$this->plugin_basename = plugin_basename( __FILE__ );
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Register actions & filters on init.
|
61 |
+
*
|
62 |
+
* @since 1.0
|
63 |
+
* @access public
|
64 |
+
*
|
65 |
+
* @uses add_post_type_support() To enable thumbs for nav menu.
|
66 |
+
* @uses is_admin() To see if it's admin area.
|
67 |
+
* @uses Nav_Menu_Images_Admin() To call admin functions.
|
68 |
+
* @uses add_action() To hook function.
|
69 |
+
* @uses apply_filters() Calls 'nmi_filter_menu_item_content' to
|
70 |
+
* overwrite menu item filter.
|
71 |
+
* @uses add_filter() To hook filters.
|
72 |
+
*/
|
73 |
+
public function init() {
|
74 |
+
// Add thumbnail support to menus
|
75 |
+
add_post_type_support( 'nav_menu_item', 'thumbnail' );
|
76 |
+
|
77 |
+
// Load admin file
|
78 |
+
if ( is_admin() ) {
|
79 |
+
require_once dirname( __FILE__ ) . '/inc/admin.php';
|
80 |
+
new Nav_Menu_Images_Admin();
|
81 |
+
}
|
82 |
+
|
83 |
+
// Register AJAX handler
|
84 |
+
add_action( 'wp_ajax_nmi_added_thumbnail', array( &$this, 'ajax_added_thumbnail' ) );
|
85 |
+
|
86 |
+
// Register menu item content filter if needed
|
87 |
+
if ( apply_filters( 'nmi_filter_menu_item_content', true ) ) {
|
88 |
+
add_filter( 'nav_menu_css_class', array( &$this, 'register_menu_item_filter' ), 15, 3 );
|
89 |
+
add_filter( 'walker_nav_menu_start_el', array( &$this, 'deregister_menu_item_filter' ), 15, 2 );
|
90 |
+
}
|
91 |
+
|
92 |
+
// Register plugins action links filter
|
93 |
+
add_filter( 'plugin_action_links_' . $this->plugin_basename, array( $this, 'action_links' ) );
|
94 |
+
add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename, array( $this, 'action_links' ) );
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Load textdomain for internationalization.
|
99 |
+
*
|
100 |
+
* @since 1.0
|
101 |
+
* @access public
|
102 |
+
*
|
103 |
+
* @uses is_textdomain_loaded() To check if translation is loaded.
|
104 |
+
* @uses load_plugin_textdomain() To load translation file.
|
105 |
+
* @uses plugin_basename() To get plugin's file name.
|
106 |
+
*/
|
107 |
+
public function load_textdomain() {
|
108 |
+
/* If translation isn't loaded, load it */
|
109 |
+
if ( ! is_textdomain_loaded( 'nmi' ) )
|
110 |
+
load_plugin_textdomain( 'nmi', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Return thumbnail's HTML after addition.
|
115 |
+
*
|
116 |
+
* @since 1.0
|
117 |
+
* @access public
|
118 |
+
*
|
119 |
+
* @uses absint() To get positive integer.
|
120 |
+
* @uses has_post_thumbnail() To check if item has thumb.
|
121 |
+
* @uses admin_url() To get URL of uploader.
|
122 |
+
* @uses esc_url() To escape URL.
|
123 |
+
* @uses add_query_arg() To append variables to URL.
|
124 |
+
* @uses get_the_post_thumbnail() To get item's thumb.
|
125 |
+
*/
|
126 |
+
public function ajax_added_thumbnail() {
|
127 |
+
// Get submitted values
|
128 |
+
$post_id = isset( $_POST[ 'post_id' ] ) ? absint( $_POST[ 'post_id' ] ) : 0;
|
129 |
+
$thumbnail_id = isset( $_POST[ 'thumbnail_id' ] ) ? absint( $_POST[ 'thumbnail_id' ] ) : 0;
|
130 |
+
|
131 |
+
// If there aren't values, exit
|
132 |
+
if ( 0 == $post_id || 0 == $thumbnail_id )
|
133 |
+
die( '0' );
|
134 |
+
|
135 |
+
// If there isn't featured image, exit
|
136 |
+
if ( ! has_post_thumbnail( $post_id ) )
|
137 |
+
die( '1' );
|
138 |
+
|
139 |
+
// Form upload link
|
140 |
+
$upload_url = admin_url( 'media-upload.php' );
|
141 |
+
$query_args = array(
|
142 |
+
'post_id' => $post_id,
|
143 |
+
'tab' => 'gallery',
|
144 |
+
'TB_iframe' => '1',
|
145 |
+
'width' => '640',
|
146 |
+
'height' => '425'
|
147 |
+
);
|
148 |
+
$upload_url = esc_url( add_query_arg( $query_args, $upload_url ) );
|
149 |
+
|
150 |
+
// Item's featured image
|
151 |
+
$post_thumbnail = get_the_post_thumbnail( $post_id, 'thumb' );
|
152 |
+
|
153 |
+
// Full HTML
|
154 |
+
$return_html = '<a href="' . $upload_url . '" class="thickbox add_media">' . $post_thumbnail . '</a>';
|
155 |
+
|
156 |
+
die( $return_html );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Display an image as menu item content.
|
161 |
+
*
|
162 |
+
* @since 1.0
|
163 |
+
* @access public
|
164 |
+
*
|
165 |
+
* @uses has_post_thumbnail() To check if item has thumb.
|
166 |
+
* @uses apply_filters() Calls 'nmi_menu_item_content' to
|
167 |
+
* filter outputted content.
|
168 |
+
* @uses get_the_post_thumbnail() To get item's thumb.
|
169 |
+
*
|
170 |
+
* @param string $content Item's content
|
171 |
+
* @param int $item_id Item's ID
|
172 |
+
* @return string $content Item's content
|
173 |
+
*/
|
174 |
+
public function menu_item_content( $content, $item_id ) {
|
175 |
+
if ( has_post_thumbnail( $item_id ) )
|
176 |
+
$content = apply_filters( 'nmi_menu_item_content', get_the_post_thumbnail( $item_id, 'full', array( 'alt' => $content, 'title' => $content ) ), $item_id, $content );
|
177 |
+
|
178 |
+
return $content;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Register menu item content filter.
|
183 |
+
*
|
184 |
+
* @since 1.0
|
185 |
+
* @access public
|
186 |
+
*
|
187 |
+
* @uses has_post_thumbnail() To check if item has thumb.
|
188 |
+
* @uses add_filter() To hook filter.
|
189 |
+
*
|
190 |
+
* @param array $item_classes Item's classes
|
191 |
+
* @param object $item Menu item data object.
|
192 |
+
* @param object $args Item's arguments.
|
193 |
+
* @return array $item_classes Item's classes
|
194 |
+
*/
|
195 |
+
public function register_menu_item_filter( $item_classes, $item, $args ) {
|
196 |
+
if ( has_post_thumbnail( $item->ID ) )
|
197 |
+
add_filter( 'the_title', array( &$this, 'menu_item_content' ), 15, 2 );
|
198 |
+
|
199 |
+
return $item_classes;
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Deregister menu item content filter.
|
204 |
+
*
|
205 |
+
* @since 1.0
|
206 |
+
* @access public
|
207 |
+
*
|
208 |
+
* @uses remove_filter() To unhook filter.
|
209 |
+
*
|
210 |
+
* @param string $item_output Item's content
|
211 |
+
* @param object $item Menu item data object.
|
212 |
+
* @return string $item_output Item's content
|
213 |
+
*/
|
214 |
+
public function deregister_menu_item_filter( $item_output, $item ) {
|
215 |
+
remove_filter( 'the_title', array( &$this, 'menu_item_content' ), 15, 3 );
|
216 |
+
|
217 |
+
return $item_output;
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Add action links to plugins page.
|
222 |
+
*
|
223 |
+
* @since 1.0
|
224 |
+
* @access public
|
225 |
+
*
|
226 |
+
* @uses Nav_Menu_Images::load_textdomain() To load translations.
|
227 |
+
*
|
228 |
+
* @param array $link Plugin's action links.
|
229 |
+
* @return array $link Plugin's action links.
|
230 |
+
*/
|
231 |
+
public function action_links( $links ) {
|
232 |
+
// Load translations
|
233 |
+
$this->load_textdomain();
|
234 |
+
|
235 |
+
$links['donate'] = '<a href="http://blog.milandinic.com/donate/">' . __( 'Donate', 'nmi' ) . '</a>';
|
236 |
+
return $links;
|
237 |
+
}
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Initialize a plugin.
|
242 |
+
*
|
243 |
+
* Load class when all plugins are loaded
|
244 |
+
* so that other plugins can overwrite it.
|
245 |
+
*
|
246 |
+
* @since 1.0
|
247 |
+
*
|
248 |
+
* @uses Nav_Menu_Images To initialize plugin.
|
249 |
+
*/
|
250 |
+
function nmi_instantiate() {
|
251 |
+
new Nav_Menu_Images();
|
252 |
+
}
|
253 |
+
add_action( 'plugins_loaded', 'nmi_instantiate', 15 );
|
readme.txt
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Nav Menu Images ===
|
2 |
+
Contributors: dimadin
|
3 |
+
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
|
7 |
+
Stable tag: 1.0
|
8 |
+
|
9 |
+
Display image as a menu item content.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
[Plugin homepage](http://blog.milandinic.com/wordpress/plugins/nav-menu-images/) | [Plugin author](http://blog.milandinic.com/) | [Donate](http://blog.milandinic.com/donate/)
|
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 |
+
Developers can make their own way of displaying images by setting `nmi_filter_menu_item_content` filter to `false`, or by filtering output generated by plugin.
|
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 partially based on a code from now defunct plugin Custom Menu Images by [Anabelle Handdoek
|
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 ==
|
25 |
+
|
26 |
+
Either install the plugin via the WordPress admin panel, or ...
|
27 |
+
|
28 |
+
1. Upload `nav-menu-images` folder to the `/wp-content/plugins/` directory
|
29 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
30 |
+
|
31 |
+
There are no configuration options in this plugin.
|
32 |
+
|
33 |
+
== Screenshots ==
|
34 |
+
|
35 |
+
1. Link to upload form on nav menu item's edit screen
|
36 |
+
2. Uploaded image on nav menu item's edit screen
|