Menu Image - Version 2.4

Version Description

  • Fix compatibility with some modules and themes to according to this topic
  • Fix Jetpack Phonon frontend bug
Download this release

Release Info

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

Code changes from version 2.3 to 2.4

Files changed (3) hide show
  1. README.md +10 -3
  2. menu-image.php +77 -8
  3. readme.txt +10 -3
README.md CHANGED
@@ -3,8 +3,8 @@
3
  **Tags:** menu, image, field, hover, wpml
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.3
8
  **License:** GPLv2 or later
9
  **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -44,7 +44,7 @@ To add a new size (or remove an old one) add a function to the `menu_image_defau
44
  add_filter( 'menu_image_default_sizes', function($sizes){
45
 
46
  // remove the default 36x36 size
47
- unset($sizes['menu-36x36'];
48
 
49
  // add a new size
50
  $sizes['menu-50x50'] = array(50,50);
@@ -67,6 +67,10 @@ add_filter( 'menu_image_default_sizes', function($sizes){
67
 
68
  ## Changelog ##
69
 
 
 
 
 
70
  ### 2.3 ###
71
  * WPML menus sync support. Thanx @pabois for [feature request](http://wordpress.org/support/topic/very-good-wpml-compliant)
72
 
@@ -95,6 +99,9 @@ add_filter( 'menu_image_default_sizes', function($sizes){
95
 
96
  ## Upgrade Notice ##
97
 
 
 
 
98
  ### 2.3 ###
99
  If your are using WPML plugin, now when you sync menus, images will synced too.
100
 
3
  **Tags:** menu, image, field, hover, wpml
4
  **Donate link:** http://makeyoulivebetter.org.ua/buy-beer
5
  **Requires at least:** 3.5.1
6
+ **Tested up to:** 4.0
7
+ **Stable tag:** 2.4
8
  **License:** GPLv2 or later
9
  **License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10
 
44
  add_filter( 'menu_image_default_sizes', function($sizes){
45
 
46
  // remove the default 36x36 size
47
+ unset($sizes['menu-36x36']);
48
 
49
  // add a new size
50
  $sizes['menu-50x50'] = array(50,50);
67
 
68
  ## Changelog ##
69
 
70
+ ### 2.4 ###
71
+ * Fix compatibility with some modules and themes to according to [this topic](http://shazdeh.me/2014/06/25/custom-fields-nav-menu-items/)
72
+ * Fix Jetpack Phonon frontend bug
73
+
74
  ### 2.3 ###
75
  * WPML menus sync support. Thanx @pabois for [feature request](http://wordpress.org/support/topic/very-good-wpml-compliant)
76
 
99
 
100
  ## Upgrade Notice ##
101
 
102
+ ### 2.4 ###
103
+ If your are using Jetpack Phonon module now menu icons will be look good.
104
+
105
  ### 2.3 ###
106
  If your are using WPML plugin, now when you sync menus, images will synced too.
107
 
menu-image.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Menu_Image
4
- * @version 2.0
5
  * @licence GPLv2
6
  */
7
 
@@ -10,7 +10,7 @@ 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.3
14
  Author URI: http://makeyoulivebetter.org.ua/
15
  */
16
 
@@ -41,6 +41,14 @@ class Menu_Image_Plugin {
41
  'menu-36x36' => array( 36, 36, false ),
42
  'menu-48x48' => array( 48, 48, false ),
43
  );
 
 
 
 
 
 
 
 
44
  /**
45
  * @var array
46
  */
@@ -51,7 +59,6 @@ class Menu_Image_Plugin {
51
  add_filter( 'manage_nav-menus_columns', array( $this, 'menu_image_nav_menu_manage_columns' ), 11 );
52
  add_action( 'save_post_nav_menu_item', array( $this, 'menu_image_save_post_action' ), 10, 3 );
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' ) );
@@ -61,6 +68,19 @@ class Menu_Image_Plugin {
61
  add_filter( 'file_is_displayable_image', array( $this, 'file_is_displayable_image' ), 10, 2 );
62
  // Add support of WPML menus sync
63
  add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item_action' ), 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
  /**
@@ -235,7 +255,9 @@ class Menu_Image_Plugin {
235
  $image_size = $item->image_size ? $item->image_size : apply_filters( 'menu_image_default_size', 'menu-36x36' );
236
  $position = $item->title_position ? $item->title_position : apply_filters( 'menu_image_default_title_position', 'after' );
237
  $class = "menu-image-title-{$position}";
 
238
  if ( $item->thumbnail_hover_id ) {
 
239
  $hover_image_src = wp_get_attachment_image_src( $item->thumbnail_hover_id, $image_size );
240
  $margin_size = $hover_image_src[1];
241
  $image = "<span class='menu-image-hover-wrapper'>";
@@ -325,7 +347,7 @@ class Menu_Image_Plugin {
325
  * @param int $item_id The post ID or object associated with the thumbnail, defaults to global $post.
326
  * @return string html
327
  */
328
- static public function wp_post_thumbnail_html( $item_id ) {
329
  $default_size = apply_filters( 'menu_image_default_size', 'menu-36x36' );;
330
  $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>';
331
 
@@ -439,12 +461,56 @@ class Menu_Image_Plugin {
439
  }
440
 
441
  if ($success) {
442
- $return = self::wp_post_thumbnail_html( $post_ID );
443
  $json ? wp_send_json_success( $return ) : wp_die( $return );
444
  }
445
 
446
  wp_die( 0 );
447
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  }
449
 
450
  $menu_image = new Menu_Image_Plugin();
@@ -581,9 +647,12 @@ class Menu_Image_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
581
  <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 ); ?>" />
582
  </label>
583
  </p>
584
- <div class="field-image hide-if-no-js wp-media-buttons">
585
- <?php echo Menu_Image_Plugin::wp_post_thumbnail_html( $item_id) ?>
586
- </div>
 
 
 
587
 
588
  <p class="field-description description description-wide">
589
  <label for="edit-menu-item-description-<?php echo $item_id; ?>">
1
  <?php
2
  /**
3
  * @package Menu_Image
4
+ * @version 2.4
5
  * @licence GPLv2
6
  */
7
 
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.4
14
  Author URI: http://makeyoulivebetter.org.ua/
15
  */
16
 
41
  'menu-36x36' => array( 36, 36, false ),
42
  'menu-48x48' => array( 48, 48, false ),
43
  );
44
+ /**
45
+ * List of used attachment ids grouped by size.
46
+ *
47
+ * Need to list all ids to prevent Jetpack Phonon in image_downsize filter.
48
+ *
49
+ * @var array
50
+ */
51
+ private $used_attachments = array();
52
  /**
53
  * @var array
54
  */
59
  add_filter( 'manage_nav-menus_columns', array( $this, 'menu_image_nav_menu_manage_columns' ), 11 );
60
  add_action( 'save_post_nav_menu_item', array( $this, 'menu_image_save_post_action' ), 10, 3 );
61
  add_action( 'admin_head-nav-menus.php', array( $this, 'menu_image_admin_head_nav_menus_action' ) );
 
62
  add_filter( 'wp_setup_nav_menu_item', array( $this, 'menu_image_wp_setup_nav_menu_item' ) );
63
  add_filter( 'walker_nav_menu_start_el', array( $this, 'menu_image_nav_menu_item_filter' ), 10, 4 );
64
  add_action( 'wp_enqueue_scripts', array( $this, 'menu_image_add_inline_style_action' ) );
68
  add_filter( 'file_is_displayable_image', array( $this, 'file_is_displayable_image' ), 10, 2 );
69
  // Add support of WPML menus sync
70
  add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item_action' ), 10, 2 );
71
+ add_action( 'admin_init', array( $this, 'admin_init' ), 99 );
72
+ add_filter( 'jetpack_photon_override_image_downsize', array( $this, 'jetpack_photon_override_image_downsize_filter' ), 10, 2 );
73
+ }
74
+
75
+ /**
76
+ * Admin init action with lowest execution priority
77
+ */
78
+ public function admin_init() {
79
+ // Add custom field for menu edit walker
80
+ if (!has_action('wp_nav_menu_item_custom_fields')) {
81
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'menu_image_edit_nav_menu_walker_filter' ) );
82
+ }
83
+ add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'menu_item_custom_fields' ), 10, 1 );
84
  }
85
 
86
  /**
255
  $image_size = $item->image_size ? $item->image_size : apply_filters( 'menu_image_default_size', 'menu-36x36' );
256
  $position = $item->title_position ? $item->title_position : apply_filters( 'menu_image_default_title_position', 'after' );
257
  $class = "menu-image-title-{$position}";
258
+ $this->setUsedAttachments($image_size, $item->thumbnail_id);
259
  if ( $item->thumbnail_hover_id ) {
260
+ $this->setUsedAttachments($image_size, $item->thumbnail_hover_id);
261
  $hover_image_src = wp_get_attachment_image_src( $item->thumbnail_hover_id, $image_size );
262
  $margin_size = $hover_image_src[1];
263
  $image = "<span class='menu-image-hover-wrapper'>";
347
  * @param int $item_id The post ID or object associated with the thumbnail, defaults to global $post.
348
  * @return string html
349
  */
350
+ public function wp_post_thumbnail_html( $item_id ) {
351
  $default_size = apply_filters( 'menu_image_default_size', 'menu-36x36' );;
352
  $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>';
353
 
461
  }
462
 
463
  if ($success) {
464
+ $return = $this->wp_post_thumbnail_html( $post_ID );
465
  $json ? wp_send_json_success( $return ) : wp_die( $return );
466
  }
467
 
468
  wp_die( 0 );
469
  }
470
+
471
+ /**
472
+ * Add custom fields to menu item as suggest to http://shazdeh.me/2014/06/25/custom-fields-nav-menu-items/
473
+ */
474
+ public function menu_item_custom_fields( $item_id ) { ?>
475
+ <div class="field-image hide-if-no-js wp-media-buttons">
476
+ <?php echo $this->wp_post_thumbnail_html( $item_id) ?>
477
+ </div>
478
+ <?php
479
+ }
480
+
481
+ /**
482
+ * Prevent jetpack Phonon applied for menu item images.
483
+ *
484
+ * @param bool $prevent
485
+ * @param array $data
486
+ *
487
+ * @return bool
488
+ */
489
+ public function jetpack_photon_override_image_downsize_filter( $prevent, $data ) {
490
+ return $this->isAttachmentUsed( $data['size'], $data['attachment_id'] );
491
+ }
492
+
493
+ /**
494
+ * Set used attachment ids.
495
+ *
496
+ * @param string $size
497
+ * @param int $id
498
+ */
499
+ public function setUsedAttachments( $size, $id ) {
500
+ $this->used_attachments[$size][] = $id;
501
+ }
502
+
503
+ /**
504
+ * Check if attachment is used in menu items.
505
+ *
506
+ * @param string $size
507
+ * @param int $id
508
+ *
509
+ * @return bool
510
+ */
511
+ public function isAttachmentUsed( $size, $id ) {
512
+ return isset( $this->used_attachments[$size] ) && in_array( $id, $this->used_attachments[$size] );
513
+ }
514
  }
515
 
516
  $menu_image = new Menu_Image_Plugin();
647
  <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 ); ?>" />
648
  </label>
649
  </p>
650
+
651
+ <?php
652
+ // This is the added section
653
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
654
+ // end added section
655
+ ?>
656
 
657
  <p class="field-description description description-wide">
658
  <label for="edit-menu-item-description-<?php echo $item_id; ?>">
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: zviryatko
3
  Tags: menu, image, field, hover, wpml
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.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -44,7 +44,7 @@ To add a new size (or remove an old one) add a function to the `menu_image_defau
44
  add_filter( 'menu_image_default_sizes', function($sizes){
45
 
46
  // remove the default 36x36 size
47
- unset($sizes['menu-36x36'];
48
 
49
  // add a new size
50
  $sizes['menu-50x50'] = array(50,50);
@@ -63,6 +63,10 @@ add_filter( 'menu_image_default_sizes', function($sizes){
63
 
64
  == Changelog ==
65
 
 
 
 
 
66
  = 2.3 =
67
  * WPML menus sync support. Thanx @pabois for [feature request](http://wordpress.org/support/topic/very-good-wpml-compliant)
68
 
@@ -91,6 +95,9 @@ add_filter( 'menu_image_default_sizes', function($sizes){
91
 
92
  == Upgrade Notice ==
93
 
 
 
 
94
  = 2.3 =
95
  If your are using WPML plugin, now when you sync menus, images will synced too.
96
 
3
  Tags: menu, image, field, hover, wpml
4
  Donate link: http://makeyoulivebetter.org.ua/buy-beer
5
  Requires at least: 3.5.1
6
+ Tested up to: 4.0
7
+ Stable tag: 2.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
44
  add_filter( 'menu_image_default_sizes', function($sizes){
45
 
46
  // remove the default 36x36 size
47
+ unset($sizes['menu-36x36']);
48
 
49
  // add a new size
50
  $sizes['menu-50x50'] = array(50,50);
63
 
64
  == Changelog ==
65
 
66
+ = 2.4 =
67
+ * Fix compatibility with some modules and themes to according to [this topic](http://shazdeh.me/2014/06/25/custom-fields-nav-menu-items/)
68
+ * Fix Jetpack Phonon frontend bug
69
+
70
  = 2.3 =
71
  * WPML menus sync support. Thanx @pabois for [feature request](http://wordpress.org/support/topic/very-good-wpml-compliant)
72
 
95
 
96
  == Upgrade Notice ==
97
 
98
+ = 2.4 =
99
+ If your are using Jetpack Phonon module now menu icons will be look good.
100
+
101
  = 2.3 =
102
  If your are using WPML plugin, now when you sync menus, images will synced too.
103