Version Description
- Removed the error trigger on the FULL HTML OUTPUT usage
- Added the feature to use shortcodes in titles of menu items as well(works with all types of menu items)
- Resolved the PHP Notice, popping up in the error log while adding new shortcodes
Download this release
Release Info
Developer | gagan0123 |
Plugin | Shortcode in Menus |
Version | 3.0 |
Comparing to | |
See all releases |
Code changes from version 2.1 to 3.0
- index.php +348 -290
- js/admin.js +71 -75
- readme.txt +8 -3
index.php
CHANGED
@@ -3,297 +3,355 @@
|
|
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:
|
7 |
-
Author
|
8 |
-
Author: Gagan Deep Singh
|
9 |
*/
|
10 |
|
11 |
-
if (!defined('ABSPATH'))
|
12 |
-
|
13 |
-
|
14 |
-
if (!class_exists('gsShortCodeInMenu')) {
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
}
|
297 |
|
298 |
-
$gs_sim = new gsShortCodeInMenu();
|
299 |
-
$gs_sim_init = $gs_sim->init();
|
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' ) )
|
11 |
+
exit; // Exit if accessed directly
|
12 |
+
|
13 |
+
if ( !class_exists( 'gsShortCodeInMenu' ) ) {
|
14 |
+
|
15 |
+
class gsShortCodeInMenu {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Hooks, filters and registers everything appropriately
|
19 |
+
*/
|
20 |
+
public function init() {
|
21 |
+
|
22 |
+
// register a test shortcode for testing
|
23 |
+
add_shortcode( 'gs_test_shortcode', array( $this, 'shortcode' ) );
|
24 |
+
|
25 |
+
// setup the meta box
|
26 |
+
add_action( 'admin_init', array( $this, 'setup_meta_box' ) );
|
27 |
+
|
28 |
+
// filter the menu item output on frontend
|
29 |
+
add_filter( 'walker_nav_menu_start_el', array( $this, 'start_el' ), 10, 2 );
|
30 |
+
|
31 |
+
// filter the menu item before display in admin
|
32 |
+
add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_item' ), 10, 1 );
|
33 |
+
|
34 |
+
// enqueue custom js
|
35 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
36 |
+
|
37 |
+
// add an ajax hack to save the html content
|
38 |
+
add_action( 'wp_ajax_gs_sim_description_hack', array( $this, 'description_hack' ) );
|
39 |
+
|
40 |
+
// hook to allow saving of shortcode in custom link metabox for legacy support
|
41 |
+
add_action( 'wp_loaded', array( $this, 'security_check' ) );
|
42 |
+
|
43 |
+
// filter the output when shortcode is saved using custom links, for legacy support
|
44 |
+
add_filter( 'clean_url', array( $this, 'display_shortcode' ), 1, 3 );
|
45 |
+
|
46 |
+
add_action( 'wp_ajax_add-menu-item', array( $this, 'ajax_add_menu_item' ), 0 );
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Test shortcode. Output's the developer's url
|
51 |
+
*
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
public function shortcode() {
|
55 |
+
return "http://gagan.pro";
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Gets a new object id,given the current one
|
60 |
+
*
|
61 |
+
* @param int $last_object_id The current/last object id
|
62 |
+
* @return int
|
63 |
+
*/
|
64 |
+
public function new_object_id( $last_object_id ) {
|
65 |
+
|
66 |
+
// make sure it's an integer
|
67 |
+
$object_id = (int) $last_object_id;
|
68 |
+
|
69 |
+
// increment it
|
70 |
+
$object_id++;
|
71 |
+
|
72 |
+
// if object_id was 0 to start off with, make it 1
|
73 |
+
$object_id = ($object_id < 1) ? 1 : $object_id;
|
74 |
+
|
75 |
+
// save into the options table
|
76 |
+
update_option( 'gs_sim_last_object_id', $object_id );
|
77 |
+
|
78 |
+
return $object_id;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Register our custom meta box
|
83 |
+
*/
|
84 |
+
public function setup_meta_box() {
|
85 |
+
add_meta_box( 'add-shortcode-section', __( 'Shortcode' ), array( $this, 'meta_box' ), 'nav-menus', 'side', 'default' );
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Display our custom meta box
|
90 |
+
* @global int $_nav_menu_placeholder A placeholder index for the menu item
|
91 |
+
* @global int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
|
92 |
+
*/
|
93 |
+
public function meta_box() {
|
94 |
+
global $_nav_menu_placeholder, $nav_menu_selected_id;
|
95 |
+
|
96 |
+
$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
|
97 |
+
|
98 |
+
$last_object_id = get_option( 'gs_sim_last_object_id', 0 );
|
99 |
+
$object_id = $this->new_object_id( $last_object_id );
|
100 |
+
?>
|
101 |
+
<div class="gs-sim-div" id="gs-sim-div">
|
102 |
+
<input type="hidden" class="menu-item-db-id" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-db-id]" value="0" />
|
103 |
+
<input type="hidden" class="menu-item-object-id" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-object-id]" value="<?php echo $object_id; ?>" />
|
104 |
+
<input type="hidden" class="menu-item-object" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-object]" value="gs_sim" />
|
105 |
+
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" value="gs_sim" />
|
106 |
+
<input type="hidden" id="gs-sim-description-nonce" value="<?php echo wp_create_nonce( 'gs-sim-description-nonce' ) ?>" />
|
107 |
+
<p id="menu-item-title-wrap">
|
108 |
+
<label for="gs-sim-title"><?php _e( 'Title' ); ?></label>
|
109 |
+
<input id="gs-sim-title" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox" title="<?php esc_attr_e( 'Title' ); ?>" style="width:100%" />
|
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">
|
117 |
+
<span class="add-to-menu">
|
118 |
+
<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-gs-sim-menu-item" id="submit-gs-sim" />
|
119 |
+
<span class="spinner"></span>
|
120 |
+
</span>
|
121 |
+
</p>
|
122 |
+
|
123 |
+
</div>
|
124 |
+
<?php
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Modifies the menu item display on frontend
|
129 |
+
*
|
130 |
+
* @param string $item_output The original html.
|
131 |
+
* @param object $item The menu item being displayed.
|
132 |
+
* @return object
|
133 |
+
*/
|
134 |
+
public function start_el( $item_output, $item ) {
|
135 |
+
// if it isn't our custom object
|
136 |
+
if ( $item->object != 'gs_sim' ) {
|
137 |
+
|
138 |
+
// check the legacy hack
|
139 |
+
if ( $item->post_title == 'FULL HTML OUTPUT' ) {
|
140 |
+
|
141 |
+
// then just process as we used to
|
142 |
+
$item_output = do_shortcode( $item->url );
|
143 |
+
} else {
|
144 |
+
$item_output = do_shortcode( $item_output );
|
145 |
+
}
|
146 |
+
|
147 |
+
// if it is our object
|
148 |
+
} else {
|
149 |
+
// just process it
|
150 |
+
$item_output = do_shortcode( $item->description );
|
151 |
+
}
|
152 |
+
|
153 |
+
return $item_output;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Modify the menu item before display on Menu editor
|
158 |
+
*
|
159 |
+
* @param object $item The menu item
|
160 |
+
* @return object
|
161 |
+
*/
|
162 |
+
public function setup_item( $item ) {
|
163 |
+
if ( !is_object( $item ) )
|
164 |
+
return $item;
|
165 |
+
|
166 |
+
// only if it is our object
|
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;
|
174 |
+
} else {
|
175 |
+
|
176 |
+
// set up the description from the transient
|
177 |
+
$item->description = get_transient( 'gs_sim_description_hack_' . $item->object_id );
|
178 |
+
|
179 |
+
// discard the transient
|
180 |
+
delete_transient( 'gs_sim_description_hack_' . $item->object_id );
|
181 |
+
}
|
182 |
+
}
|
183 |
+
return $item;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Enqueue our custom js
|
188 |
+
*
|
189 |
+
* @param string $hook The current screen
|
190 |
+
* @return null
|
191 |
+
*/
|
192 |
+
public function enqueue( $hook ) {
|
193 |
+
|
194 |
+
// don't enqueue if it isn't the menu editor
|
195 |
+
if ( 'nav-menus.php' != $hook )
|
196 |
+
return;
|
197 |
+
|
198 |
+
// otherwise enqueue with nav-menu.js as a dependency so that our script is loaded after it
|
199 |
+
wp_enqueue_script(
|
200 |
+
'gs-sim-admin', plugins_url( '/js/admin.js', __FILE__ ), array( 'nav-menu' )
|
201 |
+
);
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* An ajax based workaround to save descriptions without using the custom object type
|
206 |
+
*/
|
207 |
+
public function description_hack() {
|
208 |
+
// verify the nonce
|
209 |
+
$nonce = $_POST[ 'description-nonce' ];
|
210 |
+
if ( !wp_verify_nonce( $nonce, 'gs-sim-description-nonce' ) ) {
|
211 |
+
die();
|
212 |
+
}
|
213 |
+
|
214 |
+
// get the menu item
|
215 |
+
$item = $_POST[ 'menu-item' ];
|
216 |
+
|
217 |
+
// save the description in a transient. This is what we'll use in setup_item()
|
218 |
+
set_transient( 'gs_sim_description_hack_' . $item[ 'menu-item-object-id' ], $item[ 'menu-item-description' ] );
|
219 |
+
|
220 |
+
// increment the object id, so it can be used by js
|
221 |
+
$object_id = $this->new_object_id( $item[ 'menu-item-object-id' ] );
|
222 |
+
|
223 |
+
echo $object_id;
|
224 |
+
|
225 |
+
die();
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Legacy method to allow saving of shortcodes in custom_link url
|
230 |
+
*
|
231 |
+
* @deprecated since 2.0
|
232 |
+
*
|
233 |
+
* @param string $url The processed url for displaying/saving
|
234 |
+
* @param string $orig_url The url that was submitted, retreived
|
235 |
+
* @param string $context Whether saving or displaying
|
236 |
+
* @return string
|
237 |
+
*/
|
238 |
+
public function save_shortcode( $url, $orig_url, $context ) {
|
239 |
+
|
240 |
+
if ( $context == 'db' ) {
|
241 |
+
return $orig_url;
|
242 |
+
}
|
243 |
+
return $url;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Allows shortcodes into the custom link url field
|
248 |
+
*
|
249 |
+
* @deprecated since 2.0
|
250 |
+
*/
|
251 |
+
public function security_check() {
|
252 |
+
if ( current_user_can( 'activate_plugins' ) ) {
|
253 |
+
//Conditionally adding the function for database context for
|
254 |
+
add_filter( 'clean_url', array( $this, 'save_shortcode' ), 99, 3 );
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Allows shortcode to be processed and displayed
|
260 |
+
*
|
261 |
+
* @deprecated since 2.0
|
262 |
+
*
|
263 |
+
* @param string $url The processed url for displaying/saving
|
264 |
+
* @param string $orig_url The url that was submitted, retreived
|
265 |
+
* @param string $context Whether saving or displaying
|
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;
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Ajax handler for add menu item request
|
277 |
+
*/
|
278 |
+
public function ajax_add_menu_item() {
|
279 |
+
|
280 |
+
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
|
281 |
+
|
282 |
+
if ( !current_user_can( 'edit_theme_options' ) )
|
283 |
+
wp_die( -1 );
|
284 |
+
|
285 |
+
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
|
286 |
+
|
287 |
+
// For performance reasons, we omit some object properties from the checklist.
|
288 |
+
// The following is a hacky way to restore them when adding non-custom items.
|
289 |
+
|
290 |
+
$menu_items_data = array();
|
291 |
+
foreach ( (array) $_POST[ 'menu-item' ] as $menu_item_data ) {
|
292 |
+
if (
|
293 |
+
!empty( $menu_item_data[ 'menu-item-type' ] ) &&
|
294 |
+
'custom' != $menu_item_data[ 'menu-item-type' ] &&
|
295 |
+
'gs_sim' != $menu_item_data[ 'menu-item-type' ] &&
|
296 |
+
!empty( $menu_item_data[ 'menu-item-object-id' ] )
|
297 |
+
) {
|
298 |
+
switch ( $menu_item_data[ 'menu-item-type' ] ) {
|
299 |
+
case 'post_type' :
|
300 |
+
$_object = get_post( $menu_item_data[ 'menu-item-object-id' ] );
|
301 |
+
break;
|
302 |
+
|
303 |
+
case 'taxonomy' :
|
304 |
+
$_object = get_term( $menu_item_data[ 'menu-item-object-id' ], $menu_item_data[ 'menu-item-object' ] );
|
305 |
+
break;
|
306 |
+
}
|
307 |
+
|
308 |
+
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
|
309 |
+
$_menu_item = reset( $_menu_items );
|
310 |
+
|
311 |
+
// Restore the missing menu item properties
|
312 |
+
$menu_item_data[ 'menu-item-description' ] = $_menu_item->description;
|
313 |
+
}
|
314 |
+
|
315 |
+
$menu_items_data[] = $menu_item_data;
|
316 |
+
}
|
317 |
+
|
318 |
+
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
|
319 |
+
if ( is_wp_error( $item_ids ) )
|
320 |
+
wp_die( 0 );
|
321 |
+
|
322 |
+
$menu_items = array();
|
323 |
+
|
324 |
+
foreach ( (array) $item_ids as $menu_item_id ) {
|
325 |
+
$menu_obj = get_post( $menu_item_id );
|
326 |
+
if ( !empty( $menu_obj->ID ) ) {
|
327 |
+
$menu_obj = wp_setup_nav_menu_item( $menu_obj );
|
328 |
+
$menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
|
329 |
+
$menu_items[] = $menu_obj;
|
330 |
+
}
|
331 |
+
}
|
332 |
+
|
333 |
+
/** This filter is documented in wp-admin/includes/nav-menu.php */
|
334 |
+
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST[ 'menu' ] );
|
335 |
+
|
336 |
+
if ( !class_exists( $walker_class_name ) )
|
337 |
+
wp_die( 0 );
|
338 |
+
|
339 |
+
if ( !empty( $menu_items ) ) {
|
340 |
+
$args = array(
|
341 |
+
'after' => '',
|
342 |
+
'before' => '',
|
343 |
+
'link_after' => '',
|
344 |
+
'link_before' => '',
|
345 |
+
'walker' => new $walker_class_name,
|
346 |
+
);
|
347 |
+
echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
|
348 |
+
}
|
349 |
+
wp_die();
|
350 |
+
}
|
351 |
+
|
352 |
+
}
|
353 |
+
|
354 |
+
$gs_sim = new gsShortCodeInMenu();
|
355 |
+
$gs_sim_init = $gs_sim->init();
|
356 |
}
|
357 |
|
|
|
|
js/admin.js
CHANGED
@@ -1,79 +1,75 @@
|
|
1 |
-
jQuery('document').ready(function() {
|
2 |
-
|
3 |
-
jQuery('#submit-gs-sim').on('click', function(e) {
|
4 |
-
// call registerChange like any add
|
5 |
-
wpNavMenu.registerChange();
|
6 |
-
|
7 |
-
// call our custom function
|
8 |
-
gsSimAddWidgettoMenu();
|
9 |
-
});
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Add our custom Shortcode object to Menu
|
13 |
-
*
|
14 |
-
* @returns {Boolean}
|
15 |
-
*/
|
16 |
-
function gsSimAddWidgettoMenu( ) {
|
17 |
-
|
18 |
-
// get the description
|
19 |
-
description = jQuery('#gs-sim-html').val();
|
20 |
-
|
21 |
-
// initialise object
|
22 |
-
menuItems = {};
|
23 |
-
|
24 |
-
// the usual method for ading menu Item
|
25 |
-
processMethod = wpNavMenu.addMenuItemToBottom;
|
26 |
-
|
27 |
-
var t = jQuery('.gs-sim-div');
|
28 |
-
|
29 |
-
// Show the ajax spinner
|
30 |
-
t.find('.spinner').show();
|
31 |
-
|
32 |
-
// regex to get the index
|
33 |
-
re = /menu-item\[([^\]]*)/;
|
34 |
-
|
35 |
-
m = t.find('.menu-item-db-id');
|
36 |
-
// match and get the index
|
37 |
-
listItemDBIDMatch = re.exec(m.attr('name')),
|
38 |
-
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
39 |
-
|
40 |
-
// assign data
|
41 |
-
menuItems[listItemDBID] = t.getItemData('add-menu-item', listItemDBID);
|
42 |
-
menuItems[listItemDBID]['menu-item-description'] = description;
|
43 |
-
|
44 |
-
if(menuItems[listItemDBID]['menu-item-title'] === ''){
|
45 |
-
menuItems[listItemDBID]['menu-item-title'] = '(Untitled)';
|
46 |
-
}
|
47 |
-
|
48 |
-
// get our custom nonce
|
49 |
-
nonce = jQuery('#gs-sim-description-nonce').val();
|
50 |
-
|
51 |
-
// set up params for our ajax hack
|
52 |
-
params = {
|
53 |
-
'action': 'gs_sim_description_hack',
|
54 |
-
'description-nonce': nonce,
|
55 |
-
'menu-item': menuItems[listItemDBID]
|
56 |
-
};
|
57 |
-
|
58 |
-
// call it
|
59 |
-
jQuery.post(ajaxurl, params, function(objectId) {
|
60 |
-
|
61 |
-
// returns the incremented object id, add to ui
|
62 |
-
jQuery('#gs-sim-div .menu-item-object-id').val(objectId);
|
63 |
-
|
64 |
-
// now call the ususl addItemToMenu
|
65 |
-
wpNavMenu.addItemToMenu(menuItems, processMethod, function() {
|
66 |
-
// Deselect the items and hide the ajax spinner
|
67 |
-
t.find('.spinner').hide();
|
68 |
-
// Set form back to defaults
|
69 |
-
jQuery('#gs-sim-title').val('').blur();
|
70 |
-
jQuery('#gs-sim-html').val('');
|
71 |
-
|
72 |
-
});
|
73 |
-
|
74 |
-
});
|
75 |
|
|
|
|
|
|
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery( 'document' ).ready( function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
jQuery( '#submit-gs-sim' ).on( 'click', function ( e ) {
|
4 |
+
// call registerChange like any add
|
5 |
+
wpNavMenu.registerChange();
|
6 |
|
7 |
+
// call our custom function
|
8 |
+
gsSimAddWidgettoMenu();
|
9 |
+
} );
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Add our custom Shortcode object to Menu
|
13 |
+
*
|
14 |
+
* @returns {Boolean}
|
15 |
+
*/
|
16 |
+
function gsSimAddWidgettoMenu( ) {
|
17 |
+
|
18 |
+
// get the description
|
19 |
+
description = jQuery( '#gs-sim-html' ).val();
|
20 |
+
|
21 |
+
// initialise object
|
22 |
+
menuItems = { };
|
23 |
+
|
24 |
+
// the usual method for ading menu Item
|
25 |
+
processMethod = wpNavMenu.addMenuItemToBottom;
|
26 |
+
|
27 |
+
var t = jQuery( '.gs-sim-div' );
|
28 |
+
|
29 |
+
// Show the ajax spinner
|
30 |
+
t.find( '.spinner' ).show();
|
31 |
+
|
32 |
+
// regex to get the index
|
33 |
+
re = /menu-item\[([^\]]*)/;
|
34 |
+
|
35 |
+
m = t.find( '.menu-item-db-id' );
|
36 |
+
// match and get the index
|
37 |
+
listItemDBIDMatch = re.exec( m.attr( 'name' ) ),
|
38 |
+
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt( listItemDBIDMatch[1], 10 );
|
39 |
+
|
40 |
+
// assign data
|
41 |
+
menuItems[listItemDBID] = t.getItemData( 'add-menu-item', listItemDBID );
|
42 |
+
menuItems[listItemDBID]['menu-item-description'] = description;
|
43 |
+
|
44 |
+
if ( menuItems[listItemDBID]['menu-item-title'] === '' ) {
|
45 |
+
menuItems[listItemDBID]['menu-item-title'] = '(Untitled)';
|
46 |
}
|
47 |
|
48 |
+
// get our custom nonce
|
49 |
+
nonce = jQuery( '#gs-sim-description-nonce' ).val();
|
50 |
+
|
51 |
+
// set up params for our ajax hack
|
52 |
+
params = {
|
53 |
+
'action': 'gs_sim_description_hack',
|
54 |
+
'description-nonce': nonce,
|
55 |
+
'menu-item': menuItems[listItemDBID]
|
56 |
+
};
|
57 |
+
|
58 |
+
// call it
|
59 |
+
jQuery.post( ajaxurl, params, function ( objectId ) {
|
60 |
+
|
61 |
+
// returns the incremented object id, add to ui
|
62 |
+
jQuery( '#gs-sim-div .menu-item-object-id' ).val( objectId );
|
63 |
+
|
64 |
+
// now call the ususl addItemToMenu
|
65 |
+
wpNavMenu.addItemToMenu( menuItems, processMethod, function () {
|
66 |
+
// Deselect the items and hide the ajax spinner
|
67 |
+
t.find( '.spinner' ).hide();
|
68 |
+
// Set form back to defaults
|
69 |
+
jQuery( '#gs-sim-title' ).val( '' ).blur();
|
70 |
+
jQuery( '#gs-sim-html' ).val( '' );
|
71 |
+
|
72 |
+
} );
|
73 |
+
} );
|
74 |
+
}
|
75 |
+
} );
|
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.
|
6 |
-
Stable tag:
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -27,7 +27,7 @@ Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-wor
|
|
27 |
|
28 |
1. Check the screen options, if you don't see the *Shortcode* box.
|
29 |
1. Check the Shortcode option to see the new Shortcode box.
|
30 |
-
1. Add your shortcode/
|
31 |
1. The menu item is saved.
|
32 |
1. The html is displayed.
|
33 |
1. Old Method: In the *Links* box, add your shortcode in the URL field.
|
@@ -65,3 +65,8 @@ Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-wor
|
|
65 |
|
66 |
= 2.1 =
|
67 |
* Bug fix for custom links with ShortCode like structure not being displayed in the nav menus.
|
|
|
|
|
|
|
|
|
|
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 |
|
27 |
|
28 |
1. Check the screen options, if you don't see the *Shortcode* box.
|
29 |
1. Check the Shortcode option to see the new Shortcode box.
|
30 |
+
1. Add your shortcode/HTML to the text area (not a link, in the screenshot). Optionally, add a title.
|
31 |
1. The menu item is saved.
|
32 |
1. The html is displayed.
|
33 |
1. Old Method: In the *Links* box, add your shortcode in the URL field.
|
65 |
|
66 |
= 2.1 =
|
67 |
* Bug fix for custom links with ShortCode like structure not being displayed in the nav menus.
|
68 |
+
|
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
|