Version Description
- Fixed a compatibility issue with Twenty Fifteen theme.
- Minified JS.
- Conditional loading of admin class for performance improvement.
- Some more code refactoring.
- Testing with WordPress 4.8.1
- Changed minimum required WordPress version from 3.5 to 3.6
Download this release
Release Info
Developer | gagan0123 |
Plugin | Shortcode in Menus |
Version | 3.3 |
Comparing to | |
See all releases |
Code changes from version 3.2 to 3.3
- admin/class-shortcode-in-menus-admin.php +329 -0
- {public → admin/js}/index.php +0 -0
- public/js/admin.js → admin/js/shortcode-in-menus.js +0 -0
- admin/js/shortcode-in-menus.min.js +2 -0
- admin/js/shortcode-in-menus.min.js.map +1 -0
- includes/class-shortcode-in-menus.php +78 -272
- js/admin.js +0 -75
- js/admin.min.js +0 -1
- languages/shortcode-in-menus.pot +58 -0
- public/js/index.php +0 -3
- readme.txt +39 -31
- shortcode-in-menus.php +38 -13
admin/class-shortcode-in-menus-admin.php
ADDED
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// If this file is called directly, abort.
|
3 |
+
if ( !defined( 'ABSPATH' ) ) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
if ( !class_exists( 'Shortcode_In_Menus_Admin' ) && class_exists( 'Shortcode_In_Menus' ) ) {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Handles admin side interactions of Shortcode in Menus plugin with WordPress.
|
11 |
+
*
|
12 |
+
* @since 3.3
|
13 |
+
*/
|
14 |
+
class Shortcode_In_Menus_Admin extends Shortcode_In_Menus {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Current instance of the class object.
|
18 |
+
*
|
19 |
+
* @since 3.3
|
20 |
+
* @access protected
|
21 |
+
* @static
|
22 |
+
*
|
23 |
+
* @var Shortcode_In_Menus_Admin
|
24 |
+
*/
|
25 |
+
protected static $instance = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Admin side hooks, filters and registers everything appropriately.
|
29 |
+
*
|
30 |
+
* @since 3.3
|
31 |
+
* @access public
|
32 |
+
*/
|
33 |
+
public function __construct() {
|
34 |
+
|
35 |
+
//Calling parent class' constructor.
|
36 |
+
parent::__construct();
|
37 |
+
|
38 |
+
// Setup the meta box.
|
39 |
+
add_action( 'admin_init', array( $this, 'setup_meta_box' ) );
|
40 |
+
|
41 |
+
// Enqueue custom JS.
|
42 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
43 |
+
|
44 |
+
// Add an ajax hack to save the html content.
|
45 |
+
add_action( 'wp_ajax_gs_sim_description_hack', array( $this, 'description_hack' ) );
|
46 |
+
|
47 |
+
// Hook to allow saving of shortcode in custom link metabox for legacy support
|
48 |
+
add_action( 'wp_loaded', array( $this, 'security_check' ) );
|
49 |
+
|
50 |
+
// Hijack the ajax_add_menu_item function in order to save Shortcode menu item properly.
|
51 |
+
add_action( 'wp_ajax_add-menu-item', array( $this, 'ajax_add_menu_item' ), 0 );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Returns the current instance of the class Shortcode_In_Menus_Admin.
|
56 |
+
*
|
57 |
+
* @since 3.3
|
58 |
+
* @access public
|
59 |
+
* @static
|
60 |
+
*
|
61 |
+
* @return Shortcode_In_Menus_Admin Returns the current instance of the
|
62 |
+
* class object.
|
63 |
+
*/
|
64 |
+
public static function get_instance() {
|
65 |
+
|
66 |
+
// If the single instance hasn't been set, set it now.
|
67 |
+
if ( null == self::$instance ) {
|
68 |
+
self::$instance = new self;
|
69 |
+
}
|
70 |
+
|
71 |
+
return self::$instance;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Register our custom meta box.
|
76 |
+
*
|
77 |
+
* @since 2.0
|
78 |
+
* @access public
|
79 |
+
*
|
80 |
+
* @return void
|
81 |
+
*/
|
82 |
+
public function setup_meta_box() {
|
83 |
+
add_meta_box( 'add-shortcode-section', __( 'Shortcode', 'shortcode-in-menus' ), array( $this, 'meta_box' ), 'nav-menus', 'side', 'default' );
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Enqueue our custom JS.
|
88 |
+
*
|
89 |
+
* @since 2.0
|
90 |
+
* @access public
|
91 |
+
*
|
92 |
+
* @param string $hook The current screen.
|
93 |
+
*
|
94 |
+
* @return void
|
95 |
+
*/
|
96 |
+
public function enqueue( $hook ) {
|
97 |
+
|
98 |
+
// Don't enqueue if it isn't the menu editor.
|
99 |
+
if ( 'nav-menus.php' != $hook ) {
|
100 |
+
return;
|
101 |
+
}
|
102 |
+
|
103 |
+
wp_enqueue_script( 'gs-sim-admin', GS_SIM_URL . 'admin/js/shortcode-in-menus.min.js', array( 'nav-menu' ) );
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* An AJAX based workaround to save descriptions without using the
|
108 |
+
* custom object type.
|
109 |
+
*
|
110 |
+
* @since 2.0
|
111 |
+
* @access public
|
112 |
+
*
|
113 |
+
* @return void
|
114 |
+
*/
|
115 |
+
public function description_hack() {
|
116 |
+
// Verify the nonce.
|
117 |
+
$nonce = filter_input( INPUT_POST, 'description-nonce' );
|
118 |
+
if ( !wp_verify_nonce( $nonce, 'gs-sim-description-nonce' ) ) {
|
119 |
+
wp_die();
|
120 |
+
}
|
121 |
+
|
122 |
+
// Get the menu item.
|
123 |
+
$item = filter_input( INPUT_POST, 'menu-item', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
124 |
+
|
125 |
+
// Save the description in a transient. This is what we'll use in setup_item().
|
126 |
+
set_transient( 'gs_sim_description_hack_' . $item[ 'menu-item-object-id' ], $item[ 'menu-item-description' ] );
|
127 |
+
|
128 |
+
// Increment the object id, so it can be used by JS.
|
129 |
+
$object_id = $this->new_object_id( $item[ 'menu-item-object-id' ] );
|
130 |
+
|
131 |
+
echo $object_id;
|
132 |
+
|
133 |
+
wp_die();
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Allows shortcodes into the custom link URL field.
|
138 |
+
*
|
139 |
+
* @since 1.0
|
140 |
+
*
|
141 |
+
* @return void
|
142 |
+
*/
|
143 |
+
public function security_check() {
|
144 |
+
if ( current_user_can( 'activate_plugins' ) ) {
|
145 |
+
//Conditionally adding the function for database context for
|
146 |
+
add_filter( 'clean_url', array( $this, 'save_shortcode' ), 99, 3 );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Ajax handler for add menu item request.
|
152 |
+
*
|
153 |
+
* This method is hijacked from WordPress default ajax_add_menu_item
|
154 |
+
* so need to be updated accordingly.
|
155 |
+
*
|
156 |
+
* @since 2.0
|
157 |
+
*
|
158 |
+
* @return void
|
159 |
+
*/
|
160 |
+
public function ajax_add_menu_item() {
|
161 |
+
|
162 |
+
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
|
163 |
+
|
164 |
+
if ( !current_user_can( 'edit_theme_options' ) ) {
|
165 |
+
wp_die( -1 );
|
166 |
+
}
|
167 |
+
|
168 |
+
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
|
169 |
+
|
170 |
+
// For performance reasons, we omit some object properties from the checklist.
|
171 |
+
// The following is a hacky way to restore them when adding non-custom items.
|
172 |
+
|
173 |
+
$menu_items_data = array();
|
174 |
+
foreach ( (array) $_POST[ 'menu-item' ] as $menu_item_data ) {
|
175 |
+
if (
|
176 |
+
!empty( $menu_item_data[ 'menu-item-type' ] ) &&
|
177 |
+
'custom' != $menu_item_data[ 'menu-item-type' ] &&
|
178 |
+
'gs_sim' != $menu_item_data[ 'menu-item-type' ] &&
|
179 |
+
!empty( $menu_item_data[ 'menu-item-object-id' ] )
|
180 |
+
) {
|
181 |
+
switch ( $menu_item_data[ 'menu-item-type' ] ) {
|
182 |
+
case 'post_type' :
|
183 |
+
$_object = get_post( $menu_item_data[ 'menu-item-object-id' ] );
|
184 |
+
break;
|
185 |
+
|
186 |
+
case 'taxonomy' :
|
187 |
+
$_object = get_term( $menu_item_data[ 'menu-item-object-id' ], $menu_item_data[ 'menu-item-object' ] );
|
188 |
+
break;
|
189 |
+
}
|
190 |
+
|
191 |
+
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
|
192 |
+
$_menu_item = reset( $_menu_items );
|
193 |
+
|
194 |
+
// Restore the missing menu item properties.
|
195 |
+
$menu_item_data[ 'menu-item-description' ] = $_menu_item->description;
|
196 |
+
}
|
197 |
+
|
198 |
+
$menu_items_data[] = $menu_item_data;
|
199 |
+
}
|
200 |
+
|
201 |
+
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
|
202 |
+
if ( is_wp_error( $item_ids ) ) {
|
203 |
+
wp_die( 0 );
|
204 |
+
}
|
205 |
+
|
206 |
+
$menu_items = array();
|
207 |
+
|
208 |
+
foreach ( (array) $item_ids as $menu_item_id ) {
|
209 |
+
$menu_obj = get_post( $menu_item_id );
|
210 |
+
if ( !empty( $menu_obj->ID ) ) {
|
211 |
+
$menu_obj = wp_setup_nav_menu_item( $menu_obj );
|
212 |
+
$menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
|
213 |
+
$menu_items[] = $menu_obj;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
/** This filter is documented in wp-admin/includes/nav-menu.php */
|
218 |
+
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST[ 'menu' ] );
|
219 |
+
|
220 |
+
if ( !class_exists( $walker_class_name ) )
|
221 |
+
wp_die( 0 );
|
222 |
+
|
223 |
+
if ( !empty( $menu_items ) ) {
|
224 |
+
$args = array(
|
225 |
+
'after' => '',
|
226 |
+
'before' => '',
|
227 |
+
'link_after' => '',
|
228 |
+
'link_before' => '',
|
229 |
+
'walker' => new $walker_class_name,
|
230 |
+
);
|
231 |
+
echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
|
232 |
+
}
|
233 |
+
wp_die();
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Method to allow saving of shortcodes in custom_link URL.
|
238 |
+
*
|
239 |
+
* @since 1.0
|
240 |
+
*
|
241 |
+
* @param string $url The processed URL for displaying/saving.
|
242 |
+
* @param string $orig_url The URL that was submitted, retreived.
|
243 |
+
* @param string $context Whether saving or displaying.
|
244 |
+
*
|
245 |
+
* @return string String containing the shortcode.
|
246 |
+
*/
|
247 |
+
public function save_shortcode( $url, $orig_url, $context ) {
|
248 |
+
|
249 |
+
if ( $context == 'db' && $this->has_shortcode( $orig_url ) ) {
|
250 |
+
return $orig_url;
|
251 |
+
}
|
252 |
+
return $url;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Gets a new object ID, given the current one
|
257 |
+
*
|
258 |
+
* @since 2.0
|
259 |
+
* @access public
|
260 |
+
*
|
261 |
+
* @param int $last_object_id The current/last object id
|
262 |
+
*
|
263 |
+
* @return int Returns new object ID.
|
264 |
+
*/
|
265 |
+
public function new_object_id( $last_object_id ) {
|
266 |
+
|
267 |
+
// make sure it's an integer
|
268 |
+
$object_id = (int) $last_object_id;
|
269 |
+
|
270 |
+
// increment it
|
271 |
+
$object_id++;
|
272 |
+
|
273 |
+
// if object_id was 0 to start off with, make it 1
|
274 |
+
$object_id = ($object_id < 1) ? 1 : $object_id;
|
275 |
+
|
276 |
+
// save into the options table
|
277 |
+
update_option( 'gs_sim_last_object_id', $object_id );
|
278 |
+
|
279 |
+
return $object_id;
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Display our custom meta box.
|
284 |
+
*
|
285 |
+
* @since 2.0
|
286 |
+
* @access public
|
287 |
+
*
|
288 |
+
* @global int $_nav_menu_placeholder A placeholder index for the menu item.
|
289 |
+
* @global int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu.
|
290 |
+
*
|
291 |
+
* @return void
|
292 |
+
*/
|
293 |
+
public function meta_box() {
|
294 |
+
global $_nav_menu_placeholder, $nav_menu_selected_id;
|
295 |
+
|
296 |
+
$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
|
297 |
+
|
298 |
+
$last_object_id = get_option( 'gs_sim_last_object_id', 0 );
|
299 |
+
$object_id = $this->new_object_id( $last_object_id );
|
300 |
+
?>
|
301 |
+
<div class="gs-sim-div" id="gs-sim-div">
|
302 |
+
<input type="hidden" class="menu-item-db-id" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-db-id]" value="0" />
|
303 |
+
<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; ?>" />
|
304 |
+
<input type="hidden" class="menu-item-object" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-object]" value="gs_sim" />
|
305 |
+
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" value="gs_sim" />
|
306 |
+
<input type="hidden" id="gs-sim-description-nonce" value="<?php echo wp_create_nonce( 'gs-sim-description-nonce' ) ?>" />
|
307 |
+
<p id="menu-item-title-wrap">
|
308 |
+
<label for="gs-sim-title"><?php _e( 'Title' ); ?></label>
|
309 |
+
<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', 'shortcode-in-menus' ); ?>" style="width:100%" />
|
310 |
+
</p>
|
311 |
+
|
312 |
+
<p id="menu-item-html-wrap">
|
313 |
+
<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>
|
314 |
+
</p>
|
315 |
+
|
316 |
+
<p class="button-controls">
|
317 |
+
<span class="add-to-menu">
|
318 |
+
<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', 'shortcode-in-menus' ); ?>" name="add-gs-sim-menu-item" id="submit-gs-sim" />
|
319 |
+
<span class="spinner"></span>
|
320 |
+
</span>
|
321 |
+
</p>
|
322 |
+
|
323 |
+
</div>
|
324 |
+
<?php
|
325 |
+
}
|
326 |
+
|
327 |
+
}
|
328 |
+
|
329 |
+
}
|
{public → admin/js}/index.php
RENAMED
File without changes
|
public/js/admin.js → admin/js/shortcode-in-menus.js
RENAMED
File without changes
|
admin/js/shortcode-in-menus.min.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
jQuery("document").ready(function(){function e(){description=jQuery("#gs-sim-html").val(),menuItems={},processMethod=wpNavMenu.addMenuItemToBottom;var e=jQuery(".gs-sim-div");e.find(".spinner").show(),re=/menu-item\[([^\]]*)/,m=e.find(".menu-item-db-id"),listItemDBIDMatch=re.exec(m.attr("name")),listItemDBID=void 0===listItemDBIDMatch[1]?0:parseInt(listItemDBIDMatch[1],10),menuItems[listItemDBID]=e.getItemData("add-menu-item",listItemDBID),menuItems[listItemDBID]["menu-item-description"]=description,""===menuItems[listItemDBID]["menu-item-title"]&&(menuItems[listItemDBID]["menu-item-title"]="(Untitled)"),nonce=jQuery("#gs-sim-description-nonce").val(),params={action:"gs_sim_description_hack","description-nonce":nonce,"menu-item":menuItems[listItemDBID]},jQuery.post(ajaxurl,params,function(t){jQuery("#gs-sim-div .menu-item-object-id").val(t),wpNavMenu.addItemToMenu(menuItems,processMethod,function(){e.find(".spinner").hide(),jQuery("#gs-sim-title").val("").blur(),jQuery("#gs-sim-html").val("")})})}jQuery("#submit-gs-sim").on("click",function(t){wpNavMenu.registerChange(),e()})});
|
2 |
+
//# sourceMappingURL=shortcode-in-menus.min.js.map
|
admin/js/shortcode-in-menus.min.js.map
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"sources":["shortcode-in-menus.js"],"names":["jQuery","ready","gsSimAddWidgettoMenu","description","val","menuItems","processMethod","wpNavMenu","addMenuItemToBottom","t","find","show","re","m","listItemDBIDMatch","exec","attr","listItemDBID","parseInt","getItemData","nonce","params","action","description-nonce","menu-item","post","ajaxurl","objectId","addItemToMenu","hide","blur","on","e","registerChange"],"mappings":"AAAAA,OAAQ,YAAaC,MAAO,WAe3B,SAASC,IAGRC,YAAcH,OAAQ,gBAAiBI,MAGvCC,aAGAC,cAAgBC,UAAUC,oBAE1B,IAAIC,EAAIT,OAAQ,eAGhBS,EAAEC,KAAM,YAAaC,OAGrBC,GAAK,sBAELC,EAAIJ,EAAEC,KAAM,oBAEZI,kBAAoBF,GAAGG,KAAMF,EAAEG,KAAM,SACpCC,kBAAe,IAAsBH,kBAAkB,GAAK,EAAII,SAAUJ,kBAAkB,GAAI,IAGjGT,UAAUY,cAAgBR,EAAEU,YAAa,gBAAiBF,cAC1DZ,UAAUY,cAAc,yBAA2Bd,YAEC,KAA/CE,UAAUY,cAAc,qBAC5BZ,UAAUY,cAAc,mBAAqB,cAI9CG,MAAQpB,OAAQ,6BAA8BI,MAG9CiB,QACCC,OAAU,0BACVC,oBAAqBH,MACrBI,YAAanB,UAAUY,eAIxBjB,OAAOyB,KAAMC,QAASL,OAAQ,SAAWM,GAGxC3B,OAAQ,oCAAqCI,IAAKuB,GAGlDpB,UAAUqB,cAAevB,UAAWC,cAAe,WAElDG,EAAEC,KAAM,YAAamB,OAErB7B,OAAQ,iBAAkBI,IAAK,IAAK0B,OACpC9B,OAAQ,gBAAiBI,IAAK,QAnEjCJ,OAAQ,kBAAmB+B,GAAI,QAAS,SAAWC,GAElDzB,UAAU0B,iBAGV/B","file":"shortcode-in-menus.min.js"}
|
includes/class-shortcode-in-menus.php
CHANGED
@@ -1,17 +1,38 @@
|
|
1 |
<?php
|
2 |
-
// If this file is called directly, abort.
|
3 |
-
if ( !defined( 'ABSPATH' ) )
|
4 |
-
exit; // Exit if accessed directly
|
5 |
|
|
|
|
|
|
|
|
|
6 |
|
7 |
if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
class Shortcode_In_Menus {
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
protected static $instance = null;
|
12 |
|
13 |
/**
|
14 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
*/
|
16 |
public static function get_instance() {
|
17 |
|
@@ -24,123 +45,50 @@ if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
|
24 |
}
|
25 |
|
26 |
/**
|
27 |
-
* Hooks, filters and registers everything appropriately
|
|
|
|
|
|
|
28 |
*/
|
29 |
public function __construct() {
|
30 |
|
31 |
// register a test shortcode for testing
|
32 |
add_shortcode( 'gs_test_shortcode', array( $this, 'shortcode' ) );
|
33 |
|
34 |
-
// setup the meta box
|
35 |
-
add_action( 'admin_init', array( $this, 'setup_meta_box' ) );
|
36 |
-
|
37 |
// filter the menu item output on frontend
|
38 |
-
add_filter( 'walker_nav_menu_start_el', array( $this, 'start_el' ),
|
39 |
-
|
40 |
-
// filter the menu item before display in admin
|
41 |
-
add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_item' ), 10, 1 );
|
42 |
-
|
43 |
-
// enqueue custom js
|
44 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
45 |
-
|
46 |
-
// add an ajax hack to save the html content
|
47 |
-
add_action( 'wp_ajax_gs_sim_description_hack', array( $this, 'description_hack' ) );
|
48 |
-
|
49 |
-
// hook to allow saving of shortcode in custom link metabox for legacy support
|
50 |
-
add_action( 'wp_loaded', array( $this, 'security_check' ) );
|
51 |
|
52 |
// filter the output when shortcode is saved using custom links, for legacy support
|
53 |
add_filter( 'clean_url', array( $this, 'display_shortcode' ), 1, 3 );
|
54 |
|
55 |
-
|
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
* Test shortcode. Output's
|
|
|
|
|
|
|
60 |
*
|
61 |
-
* @return string
|
62 |
*/
|
63 |
public function shortcode() {
|
64 |
-
return
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
-
*
|
|
|
69 |
*
|
70 |
-
* @
|
71 |
-
* @
|
72 |
-
*/
|
73 |
-
public function new_object_id( $last_object_id ) {
|
74 |
-
|
75 |
-
// make sure it's an integer
|
76 |
-
$object_id = (int) $last_object_id;
|
77 |
-
|
78 |
-
// increment it
|
79 |
-
$object_id++;
|
80 |
-
|
81 |
-
// if object_id was 0 to start off with, make it 1
|
82 |
-
$object_id = ($object_id < 1) ? 1 : $object_id;
|
83 |
-
|
84 |
-
// save into the options table
|
85 |
-
update_option( 'gs_sim_last_object_id', $object_id );
|
86 |
-
|
87 |
-
return $object_id;
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Register our custom meta box
|
92 |
-
*/
|
93 |
-
public function setup_meta_box() {
|
94 |
-
add_meta_box( 'add-shortcode-section', __( 'Shortcode' ), array( $this, 'meta_box' ), 'nav-menus', 'side', 'default' );
|
95 |
-
}
|
96 |
-
|
97 |
-
/**
|
98 |
-
* Display our custom meta box
|
99 |
-
* @global int $_nav_menu_placeholder A placeholder index for the menu item
|
100 |
-
* @global int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
|
101 |
-
*/
|
102 |
-
public function meta_box() {
|
103 |
-
global $_nav_menu_placeholder, $nav_menu_selected_id;
|
104 |
-
|
105 |
-
$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
|
106 |
-
|
107 |
-
$last_object_id = get_option( 'gs_sim_last_object_id', 0 );
|
108 |
-
$object_id = $this->new_object_id( $last_object_id );
|
109 |
-
?>
|
110 |
-
<div class="gs-sim-div" id="gs-sim-div">
|
111 |
-
<input type="hidden" class="menu-item-db-id" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-db-id]" value="0" />
|
112 |
-
<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; ?>" />
|
113 |
-
<input type="hidden" class="menu-item-object" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-object]" value="gs_sim" />
|
114 |
-
<input type="hidden" class="menu-item-type" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" value="gs_sim" />
|
115 |
-
<input type="hidden" id="gs-sim-description-nonce" value="<?php echo wp_create_nonce( 'gs-sim-description-nonce' ) ?>" />
|
116 |
-
<p id="menu-item-title-wrap">
|
117 |
-
<label for="gs-sim-title"><?php _e( 'Title' ); ?></label>
|
118 |
-
<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%" />
|
119 |
-
</p>
|
120 |
-
|
121 |
-
<p id="menu-item-html-wrap">
|
122 |
-
<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>
|
123 |
-
</p>
|
124 |
-
|
125 |
-
<p class="button-controls">
|
126 |
-
<span class="add-to-menu">
|
127 |
-
<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" />
|
128 |
-
<span class="spinner"></span>
|
129 |
-
</span>
|
130 |
-
</p>
|
131 |
-
|
132 |
-
</div>
|
133 |
-
<?php
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Check if the passed content has any shortcode. Inspired from the core's has_shortcode
|
138 |
*
|
139 |
-
* @param string $content The content to check for shortcode
|
140 |
-
*
|
141 |
-
* @
|
142 |
*/
|
143 |
-
function has_shortcode( $content ) {
|
144 |
|
145 |
if ( false !== strpos( $content, '[' ) ) {
|
146 |
|
@@ -154,11 +102,14 @@ if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
|
154 |
}
|
155 |
|
156 |
/**
|
157 |
-
* Modifies the menu item display on frontend
|
|
|
|
|
158 |
*
|
159 |
* @param string $item_output The original html.
|
160 |
* @param object $item The menu item being displayed.
|
161 |
-
*
|
|
|
162 |
*/
|
163 |
public function start_el( $item_output, $item ) {
|
164 |
// if it isn't our custom object
|
@@ -183,14 +134,37 @@ if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
|
183 |
}
|
184 |
|
185 |
/**
|
186 |
-
*
|
|
|
|
|
187 |
*
|
188 |
-
* @param
|
189 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
*/
|
191 |
public function setup_item( $item ) {
|
192 |
-
if ( !is_object( $item ) )
|
193 |
return $item;
|
|
|
194 |
|
195 |
// only if it is our object
|
196 |
if ( $item->object == 'gs_sim' ) {
|
@@ -212,174 +186,6 @@ if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
|
212 |
return $item;
|
213 |
}
|
214 |
|
215 |
-
/**
|
216 |
-
* Enqueue our custom js
|
217 |
-
*
|
218 |
-
* @param string $hook The current screen
|
219 |
-
* @return null
|
220 |
-
*/
|
221 |
-
public function enqueue( $hook ) {
|
222 |
-
|
223 |
-
// don't enqueue if it isn't the menu editor
|
224 |
-
if ( 'nav-menus.php' != $hook )
|
225 |
-
return;
|
226 |
-
|
227 |
-
// otherwise enqueue with nav-menu.js as a dependency so that our script is loaded after it
|
228 |
-
wp_enqueue_script(
|
229 |
-
'gs-sim-admin', GS_SIM_URL . 'public/js/admin.js', array( 'nav-menu' )
|
230 |
-
);
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* An ajax based workaround to save descriptions without using the custom object type
|
235 |
-
*/
|
236 |
-
public function description_hack() {
|
237 |
-
// verify the nonce
|
238 |
-
$nonce = $_POST[ 'description-nonce' ];
|
239 |
-
if ( !wp_verify_nonce( $nonce, 'gs-sim-description-nonce' ) ) {
|
240 |
-
die();
|
241 |
-
}
|
242 |
-
|
243 |
-
// get the menu item
|
244 |
-
$item = $_POST[ 'menu-item' ];
|
245 |
-
|
246 |
-
// save the description in a transient. This is what we'll use in setup_item()
|
247 |
-
set_transient( 'gs_sim_description_hack_' . $item[ 'menu-item-object-id' ], $item[ 'menu-item-description' ] );
|
248 |
-
|
249 |
-
// increment the object id, so it can be used by js
|
250 |
-
$object_id = $this->new_object_id( $item[ 'menu-item-object-id' ] );
|
251 |
-
|
252 |
-
echo $object_id;
|
253 |
-
|
254 |
-
die();
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* Legacy method to allow saving of shortcodes in custom_link url
|
259 |
-
*
|
260 |
-
* @deprecated since 2.0
|
261 |
-
*
|
262 |
-
* @param string $url The processed url for displaying/saving
|
263 |
-
* @param string $orig_url The url that was submitted, retreived
|
264 |
-
* @param string $context Whether saving or displaying
|
265 |
-
* @return string
|
266 |
-
*/
|
267 |
-
public function save_shortcode( $url, $orig_url, $context ) {
|
268 |
-
|
269 |
-
if ( $context == 'db' && $this->has_shortcode( $orig_url ) ) {
|
270 |
-
return $orig_url;
|
271 |
-
}
|
272 |
-
return $url;
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Allows shortcodes into the custom link url field
|
277 |
-
*
|
278 |
-
* @deprecated since 2.0
|
279 |
-
*/
|
280 |
-
public function security_check() {
|
281 |
-
if ( current_user_can( 'activate_plugins' ) ) {
|
282 |
-
//Conditionally adding the function for database context for
|
283 |
-
add_filter( 'clean_url', array( $this, 'save_shortcode' ), 99, 3 );
|
284 |
-
}
|
285 |
-
}
|
286 |
-
|
287 |
-
/**
|
288 |
-
* Allows shortcode to be processed and displayed
|
289 |
-
*
|
290 |
-
* @deprecated since 2.0
|
291 |
-
*
|
292 |
-
* @param string $url The processed url for displaying/saving
|
293 |
-
* @param string $orig_url The url that was submitted, retreived
|
294 |
-
* @param string $context Whether saving or displaying
|
295 |
-
* @return string
|
296 |
-
*/
|
297 |
-
public function display_shortcode( $url, $orig_url, $context ) {
|
298 |
-
if ( $context == 'display' && $this->has_shortcode( $orig_url ) ) {
|
299 |
-
return do_shortcode( $orig_url );
|
300 |
-
}
|
301 |
-
return $url;
|
302 |
-
}
|
303 |
-
|
304 |
-
/**
|
305 |
-
* Ajax handler for add menu item request
|
306 |
-
*/
|
307 |
-
public function ajax_add_menu_item() {
|
308 |
-
|
309 |
-
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
|
310 |
-
|
311 |
-
if ( !current_user_can( 'edit_theme_options' ) ) {
|
312 |
-
wp_die( -1 );
|
313 |
-
}
|
314 |
-
|
315 |
-
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
|
316 |
-
|
317 |
-
// For performance reasons, we omit some object properties from the checklist.
|
318 |
-
// The following is a hacky way to restore them when adding non-custom items.
|
319 |
-
|
320 |
-
$menu_items_data = array();
|
321 |
-
foreach ( (array) $_POST[ 'menu-item' ] as $menu_item_data ) {
|
322 |
-
if (
|
323 |
-
!empty( $menu_item_data[ 'menu-item-type' ] ) &&
|
324 |
-
'custom' != $menu_item_data[ 'menu-item-type' ] &&
|
325 |
-
'gs_sim' != $menu_item_data[ 'menu-item-type' ] &&
|
326 |
-
!empty( $menu_item_data[ 'menu-item-object-id' ] )
|
327 |
-
) {
|
328 |
-
switch ( $menu_item_data[ 'menu-item-type' ] ) {
|
329 |
-
case 'post_type' :
|
330 |
-
$_object = get_post( $menu_item_data[ 'menu-item-object-id' ] );
|
331 |
-
break;
|
332 |
-
|
333 |
-
case 'taxonomy' :
|
334 |
-
$_object = get_term( $menu_item_data[ 'menu-item-object-id' ], $menu_item_data[ 'menu-item-object' ] );
|
335 |
-
break;
|
336 |
-
}
|
337 |
-
|
338 |
-
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
|
339 |
-
$_menu_item = reset( $_menu_items );
|
340 |
-
|
341 |
-
// Restore the missing menu item properties
|
342 |
-
$menu_item_data[ 'menu-item-description' ] = $_menu_item->description;
|
343 |
-
}
|
344 |
-
|
345 |
-
$menu_items_data[] = $menu_item_data;
|
346 |
-
}
|
347 |
-
|
348 |
-
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
|
349 |
-
if ( is_wp_error( $item_ids ) )
|
350 |
-
wp_die( 0 );
|
351 |
-
|
352 |
-
$menu_items = array();
|
353 |
-
|
354 |
-
foreach ( (array) $item_ids as $menu_item_id ) {
|
355 |
-
$menu_obj = get_post( $menu_item_id );
|
356 |
-
if ( !empty( $menu_obj->ID ) ) {
|
357 |
-
$menu_obj = wp_setup_nav_menu_item( $menu_obj );
|
358 |
-
$menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
|
359 |
-
$menu_items[] = $menu_obj;
|
360 |
-
}
|
361 |
-
}
|
362 |
-
|
363 |
-
/** This filter is documented in wp-admin/includes/nav-menu.php */
|
364 |
-
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST[ 'menu' ] );
|
365 |
-
|
366 |
-
if ( !class_exists( $walker_class_name ) )
|
367 |
-
wp_die( 0 );
|
368 |
-
|
369 |
-
if ( !empty( $menu_items ) ) {
|
370 |
-
$args = array(
|
371 |
-
'after' => '',
|
372 |
-
'before' => '',
|
373 |
-
'link_after' => '',
|
374 |
-
'link_before' => '',
|
375 |
-
'walker' => new $walker_class_name,
|
376 |
-
);
|
377 |
-
echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
|
378 |
-
}
|
379 |
-
wp_die();
|
380 |
-
}
|
381 |
-
|
382 |
}
|
383 |
|
384 |
-
Shortcode_In_Menus::get_instance();
|
385 |
}
|
1 |
<?php
|
|
|
|
|
|
|
2 |
|
3 |
+
// If this file is called directly, abort.
|
4 |
+
if ( !defined( 'ABSPATH' ) ) {
|
5 |
+
exit;
|
6 |
+
}
|
7 |
|
8 |
if ( !class_exists( 'Shortcode_In_Menus' ) ) {
|
9 |
|
10 |
+
/**
|
11 |
+
* Handles Shortcode in Menus plugin interactions with WordPress.
|
12 |
+
*
|
13 |
+
* @since 3.2
|
14 |
+
*/
|
15 |
class Shortcode_In_Menus {
|
16 |
|
17 |
+
/**
|
18 |
+
* Current instance of the class object.
|
19 |
+
*
|
20 |
+
* @since 3.2
|
21 |
+
* @access protected
|
22 |
+
* @static
|
23 |
+
*
|
24 |
+
* @var Shortcode_In_Menus
|
25 |
+
*/
|
26 |
protected static $instance = null;
|
27 |
|
28 |
/**
|
29 |
+
* Returns the current instance of the class Shortcode_In_Menus.
|
30 |
+
*
|
31 |
+
* @since 3.2
|
32 |
+
* @access public
|
33 |
+
* @static
|
34 |
+
*
|
35 |
+
* @return Shortcode_In_Menus Returns the current instance of the class object.
|
36 |
*/
|
37 |
public static function get_instance() {
|
38 |
|
45 |
}
|
46 |
|
47 |
/**
|
48 |
+
* Hooks, filters and registers everything appropriately.
|
49 |
+
*
|
50 |
+
* @since 3.2
|
51 |
+
* @access public
|
52 |
*/
|
53 |
public function __construct() {
|
54 |
|
55 |
// register a test shortcode for testing
|
56 |
add_shortcode( 'gs_test_shortcode', array( $this, 'shortcode' ) );
|
57 |
|
|
|
|
|
|
|
58 |
// filter the menu item output on frontend
|
59 |
+
add_filter( 'walker_nav_menu_start_el', array( $this, 'start_el' ), 20, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
// filter the output when shortcode is saved using custom links, for legacy support
|
62 |
add_filter( 'clean_url', array( $this, 'display_shortcode' ), 1, 3 );
|
63 |
|
64 |
+
// filter the menu item before display in admin and in frontend
|
65 |
+
add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_item' ), 10, 1 );
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
+
* Test shortcode. Output's WordPress.org URL.
|
70 |
+
*
|
71 |
+
* @since 1.2
|
72 |
+
* @access public
|
73 |
*
|
74 |
+
* @return string Returns WordPress.org URL.
|
75 |
*/
|
76 |
public function shortcode() {
|
77 |
+
return __( 'https://wordpress.org', 'shortcode-in-menus' );
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
+
* Check if the passed content has any shortcode. Inspired from the
|
82 |
+
* core's has_shortcode.
|
83 |
*
|
84 |
+
* @since 2.0
|
85 |
+
* @access public
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
*
|
87 |
+
* @param string $content The content to check for shortcode.
|
88 |
+
*
|
89 |
+
* @return boolean Returns true if the $content has shortcode, false otherwise.
|
90 |
*/
|
91 |
+
public function has_shortcode( $content ) {
|
92 |
|
93 |
if ( false !== strpos( $content, '[' ) ) {
|
94 |
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
+
* Modifies the menu item display on frontend.
|
106 |
+
*
|
107 |
+
* @since 2.0
|
108 |
*
|
109 |
* @param string $item_output The original html.
|
110 |
* @param object $item The menu item being displayed.
|
111 |
+
*
|
112 |
+
* @return string Modified menu item to display.
|
113 |
*/
|
114 |
public function start_el( $item_output, $item ) {
|
115 |
// if it isn't our custom object
|
134 |
}
|
135 |
|
136 |
/**
|
137 |
+
* Allows shortcode to be processed and displayed.
|
138 |
+
*
|
139 |
+
* @since 1.0
|
140 |
*
|
141 |
+
* @param string $url The processed URL for displaying/saving.
|
142 |
+
* @param string $orig_url The URL that was submitted, retrieved.
|
143 |
+
* @param string $context Whether saving or displaying.
|
144 |
+
*
|
145 |
+
* @return string Output string after shortcode has been executed.
|
146 |
+
*/
|
147 |
+
public function display_shortcode( $url, $orig_url, $context ) {
|
148 |
+
if ( $context == 'display' && $this->has_shortcode( $orig_url ) ) {
|
149 |
+
return do_shortcode( $orig_url );
|
150 |
+
}
|
151 |
+
return $url;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Modify the menu item before display on Menu editor and in frontend.
|
156 |
+
*
|
157 |
+
* @since 2.0
|
158 |
+
* @access public
|
159 |
+
*
|
160 |
+
* @param object $item The menu item.
|
161 |
+
*
|
162 |
+
* @return object Modified menu item object.
|
163 |
*/
|
164 |
public function setup_item( $item ) {
|
165 |
+
if ( !is_object( $item ) ) {
|
166 |
return $item;
|
167 |
+
}
|
168 |
|
169 |
// only if it is our object
|
170 |
if ( $item->object == 'gs_sim' ) {
|
186 |
return $item;
|
187 |
}
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
}
|
190 |
|
|
|
191 |
}
|
js/admin.js
DELETED
@@ -1,75 +0,0 @@
|
|
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 |
-
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/admin.min.js
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
jQuery("document").ready(function(){jQuery("#submit-gs-sim").on("click",function(b){wpNavMenu.registerChange();a()});function a(){description=jQuery("#gs-sim-html").val();menuItems={};processMethod=wpNavMenu.addMenuItemToBottom;var b=jQuery(".gs-sim-div");b.find(".spinner").show();re=/menu-item\[([^\]]*)/;m=b.find(".menu-item-db-id");listItemDBIDMatch=re.exec(m.attr("name")),listItemDBID="undefined"==typeof listItemDBIDMatch[1]?0:parseInt(listItemDBIDMatch[1],10);menuItems[listItemDBID]=b.getItemData("add-menu-item",listItemDBID);menuItems[listItemDBID]["menu-item-description"]=description;if(menuItems[listItemDBID]["menu-item-title"]===""){menuItems[listItemDBID]["menu-item-title"]="(Untitled)"}nonce=jQuery("#gs-sim-description-nonce").val();params={action:"gs_sim_description_hack","description-nonce":nonce,"menu-item":menuItems[listItemDBID]};jQuery.post(ajaxurl,params,function(c){jQuery("#gs-sim-div .menu-item-object-id").val(c);wpNavMenu.addItemToMenu(menuItems,processMethod,function(){b.find(".spinner").hide();jQuery("#gs-sim-title").val("").blur();jQuery("#gs-sim-html").val("")})})}});
|
|
languages/shortcode-in-menus.pot
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2017 Gagan Deep Singh and Saurabh Shukla
|
2 |
+
# This file is distributed under the same license as the Shortcodes in Menus package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Shortcodes in Menus 3.3\n"
|
6 |
+
"Report-Msgid-Bugs-To: "
|
7 |
+
"https://wordpress.org/support/plugin/shortcode-in-menus\n"
|
8 |
+
"POT-Creation-Date: 2017-08-31 10:32:15+00:00\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
|
13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
+
"Poedit: \n"
|
16 |
+
"X-Generator: grunt-wp-i18n1.0.0\n"
|
17 |
+
|
18 |
+
#: admin/class-shortcode-in-menus-admin.php:83
|
19 |
+
#: includes/class-shortcode-in-menus.php:173
|
20 |
+
msgid "Shortcode"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: admin/class-shortcode-in-menus-admin.php:308
|
24 |
+
#: admin/class-shortcode-in-menus-admin.php:309
|
25 |
+
msgid "Title"
|
26 |
+
msgstr ""
|
27 |
+
|
28 |
+
#: admin/class-shortcode-in-menus-admin.php:313
|
29 |
+
msgid "Text/HTML/shortcode here!"
|
30 |
+
msgstr ""
|
31 |
+
|
32 |
+
#: admin/class-shortcode-in-menus-admin.php:318
|
33 |
+
msgid "Add to Menu"
|
34 |
+
msgstr ""
|
35 |
+
|
36 |
+
#: includes/class-shortcode-in-menus.php:77
|
37 |
+
msgid "https://wordpress.org"
|
38 |
+
msgstr ""
|
39 |
+
|
40 |
+
#. Plugin Name of the plugin/theme
|
41 |
+
msgid "Shortcodes in Menus"
|
42 |
+
msgstr ""
|
43 |
+
|
44 |
+
#. Plugin URI of the plugin/theme
|
45 |
+
msgid "http://wordpress.org/plugins/shortcode-in-menus/"
|
46 |
+
msgstr ""
|
47 |
+
|
48 |
+
#. Description of the plugin/theme
|
49 |
+
msgid "Allows you to add shortcodes in WordPress Navigation Menus"
|
50 |
+
msgstr ""
|
51 |
+
|
52 |
+
#. Author of the plugin/theme
|
53 |
+
msgid "Gagan Deep Singh and Saurabh Shukla"
|
54 |
+
msgstr ""
|
55 |
+
|
56 |
+
#. Author URI of the plugin/theme
|
57 |
+
msgid "https://gagan0123.com"
|
58 |
+
msgstr ""
|
public/js/index.php
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
//Silence is golden
|
|
|
|
|
|
readme.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
=== Shortcodes in Menus ===
|
2 |
Contributors: gagan0123, saurabhshukla
|
3 |
Tags: Shortcode, Menus, Custom Link
|
4 |
-
Requires at least: 3.
|
5 |
-
Tested up to: 4.
|
6 |
-
Stable tag: 3.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
-
Allows you to add shortcodes in WordPress Navigation Menus
|
11 |
|
12 |
== Description ==
|
13 |
|
14 |
-
Allows you to add shortcodes in WordPress Navigation Menus so that you can generate links dynamically. Also allows you to add full fledged
|
15 |
|
16 |
|
17 |
**Usage**
|
18 |
|
19 |
-
See the [screenshots](
|
20 |
|
21 |
Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-work-24/page/2/#post-4987738) by Aurovrata Venet
|
22 |
|
@@ -41,43 +41,51 @@ Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-wor
|
|
41 |
1. Add the plugin's folder in the WordPress' plugin directory.
|
42 |
1. Activate the plugin.
|
43 |
1. You can now add ShortCodes in the custom links of the menus.
|
44 |
-
1. To test this, you can add a custom link with a ShortCode [gs_test_shortcode] as link, if it points to
|
45 |
1. If you want to use a ShortCode that outputs not just the url, but complete HTML sections, please make use of the title 'FULL HTML OUTPUT' for that link and it will output the complete HTML without breaking your site.
|
46 |
|
47 |
== Changelog ==
|
48 |
|
49 |
-
=
|
50 |
-
*
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
=
|
53 |
-
*
|
|
|
|
|
54 |
|
55 |
-
=
|
56 |
-
*
|
|
|
57 |
|
58 |
-
=
|
59 |
-
*
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
= 2.0 =
|
62 |
-
* Added new Shortcode box to Menu Editor
|
63 |
* Added html support.
|
64 |
* Deprecated Links box basis.
|
65 |
-
* Added screenshots
|
66 |
-
* Updated readme and instructions
|
67 |
|
68 |
-
= 2
|
69 |
-
*
|
70 |
|
71 |
-
=
|
72 |
-
*
|
73 |
-
* Added the feature to use shortcodes in titles of menu items as well(works with all types of menu items)
|
74 |
-
* Resolved the PHP Notice, popping up in the error log while adding new shortcodes
|
75 |
|
76 |
-
=
|
77 |
-
*
|
78 |
-
* Made the code translation ready.
|
79 |
|
80 |
-
=
|
81 |
-
*
|
82 |
-
* Changed tested upto
|
83 |
-
* Corrected links in description
|
1 |
=== Shortcodes in Menus ===
|
2 |
Contributors: gagan0123, saurabhshukla
|
3 |
Tags: Shortcode, Menus, Custom Link
|
4 |
+
Requires at least: 3.6
|
5 |
+
Tested up to: 4.8.1
|
6 |
+
Stable tag: 3.3
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
+
Allows you to add shortcodes in WordPress Navigation Menus.
|
11 |
|
12 |
== Description ==
|
13 |
|
14 |
+
Allows you to add shortcodes in WordPress Navigation Menus so that you can generate links dynamically. Also allows you to add full fledged HTML sections to navigation menus.
|
15 |
|
16 |
|
17 |
**Usage**
|
18 |
|
19 |
+
See the [screenshots](#screenshots).
|
20 |
|
21 |
Also, see a [great tutorial](https://wordpress.org/support/topic/how-does-it-work-24/page/2/#post-4987738) by Aurovrata Venet
|
22 |
|
41 |
1. Add the plugin's folder in the WordPress' plugin directory.
|
42 |
1. Activate the plugin.
|
43 |
1. You can now add ShortCodes in the custom links of the menus.
|
44 |
+
1. To test this, you can add a custom link with a ShortCode [gs_test_shortcode] as link, if it points to https://wordpress.org, plugin is working
|
45 |
1. If you want to use a ShortCode that outputs not just the url, but complete HTML sections, please make use of the title 'FULL HTML OUTPUT' for that link and it will output the complete HTML without breaking your site.
|
46 |
|
47 |
== Changelog ==
|
48 |
|
49 |
+
= 3.3 =
|
50 |
+
* Fixed a compatibility issue with Twenty Fifteen theme.
|
51 |
+
* Minified JS.
|
52 |
+
* Conditional loading of admin class for performance improvement.
|
53 |
+
* Some more code refactoring.
|
54 |
+
* Testing with WordPress 4.8.1
|
55 |
+
* Changed minimum required WordPress version from 3.5 to 3.6
|
56 |
|
57 |
+
= 3.2 =
|
58 |
+
* Code Refactoring.
|
59 |
+
* Changed tested upto.
|
60 |
+
* Corrected links in description.
|
61 |
|
62 |
+
= 3.1 =
|
63 |
+
* 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)
|
64 |
+
* Made the code translation ready.
|
65 |
|
66 |
+
= 3.0 =
|
67 |
+
* Removed the error trigger on the FULL HTML OUTPUT usage.
|
68 |
+
* Added the feature to use shortcodes in titles of menu items as well(works with all types of menu items).
|
69 |
+
* Resolved the PHP Notice, popping up in the error log while adding new shortcodes.
|
70 |
+
|
71 |
+
= 2.1 =
|
72 |
+
* Bug fix for custom links with ShortCode like structure not being displayed in the nav menus.
|
73 |
|
74 |
= 2.0 =
|
75 |
+
* Added new Shortcode box to Menu Editor.
|
76 |
* Added html support.
|
77 |
* Deprecated Links box basis.
|
78 |
+
* Added screenshots.
|
79 |
+
* Updated readme and instructions.
|
80 |
|
81 |
+
= 1.2 =
|
82 |
+
* Added ability to echo complete HTML output instead of just URL by using ShortCode.
|
83 |
|
84 |
+
= 1.1 =
|
85 |
+
* Tested with WordPress 4.0
|
|
|
|
|
86 |
|
87 |
+
= 1.0 =
|
88 |
+
* Added prefix to function which was conflicting with another plugin.
|
|
|
89 |
|
90 |
+
= 0.1 =
|
91 |
+
* Initial Plugin uploaded.
|
|
|
|
shortcode-in-menus.php
CHANGED
@@ -1,23 +1,48 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
*/
|
11 |
-
|
12 |
// If this file is called directly, abort.
|
13 |
-
if ( !defined( 'ABSPATH' ) )
|
14 |
-
exit;
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
/**
|
21 |
* The core plugin class
|
22 |
*/
|
23 |
require_once GS_SIM_PATH . 'includes/class-shortcode-in-menus.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
/**
|
4 |
+
* Plugin Name: Shortcodes in Menus
|
5 |
+
* Description: Allows you to add shortcodes in WordPress Navigation Menus
|
6 |
+
* Plugin URI: http://wordpress.org/plugins/shortcode-in-menus/
|
7 |
+
* Version: 3.3
|
8 |
+
* Author: Gagan Deep Singh and Saurabh Shukla
|
9 |
+
* Author URI: https://gagan0123.com
|
10 |
+
* Text Domain: shortcode-in-menus
|
11 |
+
* Domain Path: /languages
|
12 |
*/
|
|
|
13 |
// If this file is called directly, abort.
|
14 |
+
if ( !defined( 'ABSPATH' ) ) {
|
15 |
+
exit;
|
16 |
+
}
|
17 |
|
18 |
+
if ( !defined( 'GS_SIM_PATH' ) ) {
|
19 |
+
/**
|
20 |
+
* Path to the plugin directory.
|
21 |
+
*
|
22 |
+
* @since 3.2
|
23 |
+
*/
|
24 |
+
define( 'GS_SIM_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
25 |
+
}
|
26 |
+
if ( !defined( 'GS_SIM_URL' ) ) {
|
27 |
+
/**
|
28 |
+
* URL to the plugin directory.
|
29 |
+
*
|
30 |
+
* @since 3.2
|
31 |
+
*/
|
32 |
+
define( 'GS_SIM_URL', trailingslashit( plugins_url( '', __FILE__ ) ) );
|
33 |
+
}
|
34 |
|
35 |
/**
|
36 |
* The core plugin class
|
37 |
*/
|
38 |
require_once GS_SIM_PATH . 'includes/class-shortcode-in-menus.php';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Load the admin class if its the admin dashboard
|
42 |
+
*/
|
43 |
+
if ( is_admin() ) {
|
44 |
+
require_once GS_SIM_PATH . 'admin/class-shortcode-in-menus-admin.php';
|
45 |
+
Shortcode_In_Menus_Admin::get_instance();
|
46 |
+
} else {
|
47 |
+
Shortcode_In_Menus::get_instance();
|
48 |
+
}
|