Shortcode in Menus - Version 3.1

Version Description

  • Fixed the bug with clean_url filters as reported by Lee Willis
  • Made the code translation ready.
Download this release

Release Info

Developer gagan0123
Plugin Icon 128x128 Shortcode in Menus
Version 3.1
Comparing to
See all releases

Code changes from version 3.0 to 3.1

Files changed (2) hide show
  1. index.php +26 -5
  2. readme.txt +12 -3
index.php CHANGED
@@ -3,8 +3,9 @@
3
  Plugin Name: Shortcodes in Menus
4
  Description: Allows you to add shortcodes in WordPress Navigation Menus
5
  Plugin URI: http://wordpress.org/plugins/shortcode-in-menus/
6
- Version: 3.0
7
  Author: <a href="http://gagan.pro">Gagan Deep Singh</a> and <a href="http://hookrefineandtinker.com">Saurabh Shukla</a>
 
8
  */
9
 
10
  if ( !defined( 'ABSPATH' ) )
@@ -110,7 +111,7 @@ if ( !class_exists( 'gsShortCodeInMenu' ) ) {
110
  </p>
111
 
112
  <p id="menu-item-html-wrap">
113
- <textarea style="width:100%;" rows="9" id="gs-sim-html" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-description]" class="code menu-item-textbox" title="<?php esc_attr_e( 'Text/html/shortcode here!' ); ?>"></textarea>
114
  </p>
115
 
116
  <p class="button-controls">
@@ -124,6 +125,26 @@ if ( !class_exists( 'gsShortCodeInMenu' ) ) {
124
  <?php
125
  }
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  /**
128
  * Modifies the menu item display on frontend
129
  *
@@ -167,7 +188,7 @@ if ( !class_exists( 'gsShortCodeInMenu' ) ) {
167
  if ( $item->object == 'gs_sim' ) {
168
 
169
  // setup our label
170
- $item->type_label = __( 'Shortcode', 'gs_sim' );
171
 
172
  if ( $item->post_content != '' ) {
173
  $item->description = $item->post_content;
@@ -237,7 +258,7 @@ if ( !class_exists( 'gsShortCodeInMenu' ) ) {
237
  */
238
  public function save_shortcode( $url, $orig_url, $context ) {
239
 
240
- if ( $context == 'db' ) {
241
  return $orig_url;
242
  }
243
  return $url;
@@ -266,7 +287,7 @@ if ( !class_exists( 'gsShortCodeInMenu' ) ) {
266
  * @return string
267
  */
268
  public function display_shortcode( $url, $orig_url, $context ) {
269
- if ( $context == 'display' ) {
270
  return do_shortcode( $orig_url );
271
  }
272
  return $url;
3
  Plugin Name: Shortcodes in Menus
4
  Description: Allows you to add shortcodes in WordPress Navigation Menus
5
  Plugin URI: http://wordpress.org/plugins/shortcode-in-menus/
6
+ Version: 3.1
7
  Author: <a href="http://gagan.pro">Gagan Deep Singh</a> and <a href="http://hookrefineandtinker.com">Saurabh Shukla</a>
8
+ Text Domain: shortcode-in-menus
9
  */
10
 
11
  if ( !defined( 'ABSPATH' ) )
111
  </p>
112
 
113
  <p id="menu-item-html-wrap">
114
+ <textarea style="width:100%;" rows="9" id="gs-sim-html" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-description]" class="code menu-item-textbox" title="<?php esc_attr_e( 'Text/HTML/shortcode here!' , 'shortcode-in-menus'); ?>"></textarea>
115
  </p>
116
 
117
  <p class="button-controls">
125
  <?php
126
  }
127
 
128
+ /**
129
+ * Check if the passed content has any shortcode. Inspired from the core's has_shortcode
130
+ *
131
+ * @param string $content The content to check for shortcode
132
+ * @return boolean
133
+ * @author Saurabh Shukla
134
+ */
135
+ function has_shortcode( $content ) {
136
+
137
+ if ( false !== strpos( $content, '[' ) ) {
138
+
139
+ preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
140
+
141
+ if ( !empty( $matches ) ) {
142
+ return true;
143
+ }
144
+ }
145
+ return false;
146
+ }
147
+
148
  /**
149
  * Modifies the menu item display on frontend
150
  *
188
  if ( $item->object == 'gs_sim' ) {
189
 
190
  // setup our label
191
+ $item->type_label = __( 'Shortcode' );
192
 
193
  if ( $item->post_content != '' ) {
194
  $item->description = $item->post_content;
258
  */
259
  public function save_shortcode( $url, $orig_url, $context ) {
260
 
261
+ if ( $context == 'db' && $this->has_shortcode( $orig_url) ) {
262
  return $orig_url;
263
  }
264
  return $url;
287
  * @return string
288
  */
289
  public function display_shortcode( $url, $orig_url, $context ) {
290
+ if ( $context == 'display' && $this->has_shortcode( $orig_url ) ) {
291
  return do_shortcode( $orig_url );
292
  }
293
  return $url;
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: gagan0123, saurabhshukla
3
  Tags: Shortcode, Menus, Custom Link
4
  Requires at least: 3.5
5
- Tested up to: 4.4.2
6
- Stable tag: 3.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -23,6 +23,11 @@ See the [screenshots](https://wordpress.org/plugins/shortcode-in-menus/).
23
 
24
  Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-work-24?replies=22#post-6160111) by Aurovrata Venet
25
 
 
 
 
 
 
26
  == Screenshots ==
27
 
28
  1. Check the screen options, if you don't see the *Shortcode* box.
@@ -69,4 +74,8 @@ Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-wor
69
  = 3.0 =
70
  * Removed the error trigger on the FULL HTML OUTPUT usage
71
  * Added the feature to use shortcodes in titles of menu items as well(works with all types of menu items)
72
- * Resolved the PHP Notice, popping up in the error log while adding new shortcodes
 
 
 
 
2
  Contributors: gagan0123, saurabhshukla
3
  Tags: Shortcode, Menus, Custom Link
4
  Requires at least: 3.5
5
+ Tested up to: 4.3.1
6
+ Stable tag: 3.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
23
 
24
  Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-work-24?replies=22#post-6160111) by Aurovrata Venet
25
 
26
+ **Special Thanks To**
27
+
28
+ * [Aurovrata Venet](https://wordpress.org/support/profile/aurovrata) for [this great tutorial](https://wordpress.org/support/topic/how-does-it-work-24?replies=22#post-6160111).
29
+ * [Lee Willis](https://wordpress.org/support/profile/leewillis77) for finding out and helping in resolving [this bug](https://wordpress.org/support/topic/causes-urls-to-be-amended-in-undesired-ways).
30
+
31
  == Screenshots ==
32
 
33
  1. Check the screen options, if you don't see the *Shortcode* box.
74
  = 3.0 =
75
  * Removed the error trigger on the FULL HTML OUTPUT usage
76
  * Added the feature to use shortcodes in titles of menu items as well(works with all types of menu items)
77
+ * Resolved the PHP Notice, popping up in the error log while adding new shortcodes
78
+
79
+ = 3.1 =
80
+ * Fixed [the bug](https://wordpress.org/support/topic/causes-urls-to-be-amended-in-undesired-ways) with clean_url filters as reported by [Lee Willis](https://wordpress.org/support/profile/leewillis77)
81
+ * Made the code translation ready.