Version Description
Download this release
Release Info
Developer | jungleplugins |
Plugin | User Menus – Nav Menu Visibility |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- assets/scripts/admin.js +82 -0
- assets/scripts/admin.min.js +1 -0
- assets/styles/admin.css +69 -0
- assets/styles/admin.css.map +1 -0
- assets/styles/admin.min.css +1 -0
- assets/styles/sass/admin.scss +91 -0
- contributors.txt +1 -0
- includes/classes/admin/menu-editor.php +166 -0
- includes/classes/admin/menu-importer.php +52 -0
- includes/classes/admin/menu-settings.php +168 -0
- includes/classes/importer/menu.php +298 -0
- includes/classes/menu/item.php +46 -0
- includes/classes/menu/items.php +179 -0
- includes/classes/site/menus.php +92 -0
- includes/classes/user/codes.php +28 -0
- includes/classes/walker/nav-menu-edit-deprecated.php +220 -0
- includes/classes/walker/nav-menu-edit.php +224 -0
- index.php +2 -0
- languages/user-menus.pot +133 -0
- readme.txt +131 -0
- user-menus.php +215 -0
assets/scripts/admin.js
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function ($, $document) {
|
2 |
+
"use strict";
|
3 |
+
|
4 |
+
function redirect_type() {
|
5 |
+
var $this = $(this),
|
6 |
+
$url = $this.parents('.menu-item').find('.nav_item_options-redirect_url');
|
7 |
+
|
8 |
+
if ($this.val() == 'custom') {
|
9 |
+
$url.show();
|
10 |
+
} else {
|
11 |
+
$url.hide();
|
12 |
+
}
|
13 |
+
}
|
14 |
+
|
15 |
+
function which_users() {
|
16 |
+
var $this = $(this),
|
17 |
+
$item = $this.parents('.menu-item'),
|
18 |
+
$roles = $item.find('.nav_item_options-roles');
|
19 |
+
|
20 |
+
if ($this.val() == 'logged_in') {
|
21 |
+
$roles.show();
|
22 |
+
$item.addClass('show-insert-button');
|
23 |
+
} else {
|
24 |
+
$roles.hide();
|
25 |
+
$item.removeClass('show-insert-button');
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
function toggle_user_codes() {
|
31 |
+
$(this).parent().toggleClass('open');
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
function reset_user_codes(e) {
|
36 |
+
if (e !== undefined && $(e.target).parents('.jpum-user-codes').length) {
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
$('.jpum-user-codes').removeClass('open');
|
41 |
+
}
|
42 |
+
|
43 |
+
function insert_user_code() {
|
44 |
+
var $this = $(this),
|
45 |
+
$input = $this.parents('p').find('input'),
|
46 |
+
val = $input.val();
|
47 |
+
|
48 |
+
$input.val(val + "{" + $this.text() + "}");
|
49 |
+
reset_user_codes();
|
50 |
+
}
|
51 |
+
|
52 |
+
function append_user_codes() {
|
53 |
+
return $('input.edit-menu-item-title').each(function () {
|
54 |
+
var $this = $(this).parents('label'),
|
55 |
+
template = _.template($('#tmpl-jpum-user-codes').html());
|
56 |
+
|
57 |
+
if (!$this.parents('p').find('.jpum-user-codes').length) {
|
58 |
+
$this.after(template());
|
59 |
+
}
|
60 |
+
});
|
61 |
+
}
|
62 |
+
|
63 |
+
function refresh_all_items() {
|
64 |
+
append_user_codes();
|
65 |
+
$(".nav_item_options-redirect_type select").each(redirect_type);
|
66 |
+
$('.nav_item_options-which_users select').each(which_users);
|
67 |
+
}
|
68 |
+
|
69 |
+
$document
|
70 |
+
.on('change', '.nav_item_options-redirect_type select', redirect_type)
|
71 |
+
.on('change', '.nav_item_options-which_users select', which_users)
|
72 |
+
.on('click', '.jpum-user-codes > span', toggle_user_codes)
|
73 |
+
.on('click', '.jpum-user-codes li > span', insert_user_code)
|
74 |
+
.on('click', reset_user_codes)
|
75 |
+
.ready(refresh_all_items);
|
76 |
+
|
77 |
+
// Add click event directly to submit buttons to prevent being prevented by default action.
|
78 |
+
$('.submit-add-to-menu').click(function () {
|
79 |
+
setTimeout(refresh_all_items, 1000);
|
80 |
+
});
|
81 |
+
|
82 |
+
}(jQuery, jQuery(document)));
|
assets/scripts/admin.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
!function(e,t){"use strict";function n(){var t=e(this),n=t.parents(".menu-item").find(".nav_item_options-redirect_url");"custom"==t.val()?n.show():n.hide()}function s(){var t=e(this),n=t.parents(".menu-item"),s=n.find(".nav_item_options-roles");"logged_in"==t.val()?(s.show(),n.addClass("show-insert-button")):(s.hide(),n.removeClass("show-insert-button"))}function i(){e(this).parent().toggleClass("open")}function o(t){void 0!==t&&e(t.target).parents(".jpum-user-codes").length||e(".jpum-user-codes").removeClass("open")}function c(){var t=e(this),n=t.parents("p").find("input"),s=n.val();n.val(s+"{"+t.text()+"}"),o()}function u(){return e("input.edit-menu-item-title").each(function(){var t=e(this).parents("label"),n=_.template(e("#tmpl-jpum-user-codes").html());t.parents("p").find(".jpum-user-codes").length||t.after(n())})}function a(){u(),e(".nav_item_options-redirect_type select").each(n),e(".nav_item_options-which_users select").each(s)}t.on("change",".nav_item_options-redirect_type select",n).on("change",".nav_item_options-which_users select",s).on("click",".jpum-user-codes > span",i).on("click",".jpum-user-codes li > span",c).on("click",o).ready(a),e(".submit-add-to-menu").click(function(){setTimeout(a,1e3)})}(jQuery,jQuery(document));
|
assets/styles/admin.css
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.jpum-user-codes {
|
2 |
+
display: none;
|
3 |
+
position: absolute;
|
4 |
+
right: 2px;
|
5 |
+
bottom: 2px;
|
6 |
+
}
|
7 |
+
|
8 |
+
.jpum-user-codes > span {
|
9 |
+
border: 1px solid;
|
10 |
+
border-radius: 2px;
|
11 |
+
background-color: rgba(0, 0, 0, 0.5);
|
12 |
+
color: #fff;
|
13 |
+
text-align: center;
|
14 |
+
cursor: pointer;
|
15 |
+
font-size: 21px;
|
16 |
+
height: 1em;
|
17 |
+
width: 1em;
|
18 |
+
}
|
19 |
+
|
20 |
+
.jpum-user-codes ul {
|
21 |
+
display: none;
|
22 |
+
position: absolute;
|
23 |
+
top: 1px;
|
24 |
+
left: 22px;
|
25 |
+
background-color: #fff;
|
26 |
+
width: auto;
|
27 |
+
z-index: 999;
|
28 |
+
box-shadow: 1px 1px 5px -1px;
|
29 |
+
border: 1px solid rgba(0, 0, 0, 0.25);
|
30 |
+
}
|
31 |
+
|
32 |
+
.jpum-user-codes ul li {
|
33 |
+
display: block;
|
34 |
+
padding: .5em;
|
35 |
+
border-bottom: 1px dashed rgba(0, 0, 0, 0.25);
|
36 |
+
}
|
37 |
+
|
38 |
+
.jpum-user-codes ul li span {
|
39 |
+
cursor: pointer;
|
40 |
+
display: block;
|
41 |
+
line-height: 1;
|
42 |
+
}
|
43 |
+
|
44 |
+
.jpum-user-codes ul li:last-child {
|
45 |
+
border-bottom: 0;
|
46 |
+
}
|
47 |
+
|
48 |
+
.jpum-user-codes.open ul {
|
49 |
+
display: block;
|
50 |
+
}
|
51 |
+
|
52 |
+
#menu-to-edit .menu-item p.description-wide {
|
53 |
+
position: relative;
|
54 |
+
}
|
55 |
+
|
56 |
+
#menu-to-edit .menu-item .nav_item_options-roles label {
|
57 |
+
width: 33%;
|
58 |
+
display: inline-block;
|
59 |
+
float: left;
|
60 |
+
margin-top: 5px;
|
61 |
+
}
|
62 |
+
|
63 |
+
#menu-to-edit .menu-item.show-insert-button .jpum-user-codes {
|
64 |
+
display: block;
|
65 |
+
}
|
66 |
+
|
67 |
+
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRtaW4uY3NzIiwic291cmNlcyI6WyJhZG1pbi5zY3NzIl0sInNvdXJjZXNDb250ZW50IjpbIi5qcHVtLXVzZXItY29kZXMge1xuXG4gIGRpc3BsYXk6IG5vbmU7XG5cbiAgcG9zaXRpb246IGFic29sdXRlO1xuICByaWdodDogMnB4O1xuICBib3R0b206IDJweDtcblxuICA+IHNwYW4ge1xuXG4gICAgYm9yZGVyOiAxcHggc29saWQ7XG4gICAgYm9yZGVyLXJhZGl1czogMnB4O1xuICAgIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMCwgMCwgMCwgLjUpO1xuICAgIGNvbG9yOiAjZmZmO1xuICAgIHRleHQtYWxpZ246IGNlbnRlcjtcbiAgICBjdXJzb3I6IHBvaW50ZXI7XG5cbiAgICBmb250LXNpemU6IDIxcHg7XG4gICAgaGVpZ2h0OiAxZW07XG4gICAgd2lkdGg6IDFlbTtcblxuICB9XG5cbiAgdWwge1xuICAgIGRpc3BsYXk6IG5vbmU7XG5cbiAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgdG9wOiAxcHg7XG4gICAgbGVmdDogMjJweDtcbiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjZmZmO1xuICAgIHdpZHRoOiBhdXRvO1xuICAgIHotaW5kZXg6IDk5OTtcbiAgICBib3gtc2hhZG93OiAxcHggMXB4IDVweCAtMXB4O1xuICAgIGJvcmRlcjogMXB4IHNvbGlkIHJnYmEoMCwgMCwgMCwgLjI1KTtcblxuICAgIGx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FLEFBWUMsV0FBVyxDQUFDO0VBQ1gsYUFBYSxFQUFFLENBQUU7Q0FDbEI7O0FBakRQLEFBdURTLGdCQXZETyxBQXVEYixLQUFLLENBQUMsRUFBRSxDQUFDO0VBQ1IsT0FBTyxFQUFFLEtBQU07Q0FDaEI7O0FBSUgsQUFJSyxhQUpRLENBRVgsVUFBVSxDQUVSLENBQUMsQUFBQSxpQkFBaUIsQ0FBQztFQUVqQixRQUFRLEVBQUUsUUFBUztDQUVwQjs7QUFSTCxBQVdNLGFBWE8sQ0FFWCxVQUFVLENBUVIsdUJBQXVCLENBQ3JCLEtBQUssQ0FBQztFQUNKLEtBQUssRUFBRSxHQUFJO0VBQ1gsT0FBTyxFQUFFLFlBQWE7RUFDdEIsS0FBSyxFQUFFLElBQUs7RUFDWixVQUFVLEVBQUUsR0FBSTtDQUNqQjs7QUFoQlAsQUFxQk0sYUFyQk8sQ0FFWCxVQUFVLEFBaUJQLG1CQUFtQixDQUVsQixnQkFBZ0IsQ0FBQztFQUNmLE9BQU8sRUFBRSxLQUFNO0NBQ2hCIiwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== */
|
68 |
+
|
69 |
+
/*# sourceMappingURL=admin.css.map */
|
assets/styles/admin.css.map
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"sources":["/source/admin.scss","admin.css"],"names":[],"mappings":"AAAA;EAEE,cAAc;EAEd,mBAAmB;EACnB,WAAW;EACX,YAAY;CAqDb;;AA3DD;EAUI,kBAAkB;EAClB,mBAAmB;EACnB,qCAAsB;EACtB,YAAY;EACZ,mBAAmB;EACnB,gBAAgB;EAEhB,gBAAgB;EAChB,YAAY;EACZ,WAAW;CAEZ;;AArBH;EAwBI,cAAc;EAEd,mBAAmB;EACnB,SAAS;EACT,WAAW;EACX,uBAAuB;EACvB,YAAY;EACZ,aAAa;EACb,6BAA6B;EAC7B,sCAAsB;CAoBvB;;AArDH;EAqCM,eAAe;EACf,cAAc;EACd,8CAA8B;CAY/B;;AAnDL;EA0CQ,gBAAgB;EAChB,eAAe;EACf,eAAe;CAChB;;AA7CP;EAgDQ,iBAAiB;CAClB;;AAjDP;EAwDI,eAAe;CAChB;;AAIH;EAMM,mBAAmB;CAEpB;;AARL;EAYQ,WAAW;EACX,sBAAsB;EACtB,YAAY;EACZ,gBAAgB;CACjB;;AAhBP;EAsBQ,eAAe;CAChB;;AClBP,6lHAA6lH","file":"admin.css","sourcesContent":[".jpum-user-codes {\n\n display: none;\n\n position: absolute;\n right: 2px;\n bottom: 2px;\n\n > span {\n\n border: 1px solid;\n border-radius: 2px;\n background-color: rgba(0, 0, 0, .5);\n color: #fff;\n text-align: center;\n cursor: pointer;\n\n font-size: 21px;\n height: 1em;\n width: 1em;\n\n }\n\n ul {\n display: none;\n\n position: absolute;\n top: 1px;\n left: 22px;\n background-color: #fff;\n width: auto;\n z-index: 999;\n box-shadow: 1px 1px 5px -1px;\n border: 1px solid rgba(0, 0, 0, .25);\n\n li {\n\n display: block;\n padding: .5em;\n border-bottom: 1px dashed rgba(0, 0, 0, .25);\n\n span {\n cursor: pointer;\n display: block;\n line-height: 1;\n }\n\n &:last-child {\n border-bottom: 0;\n }\n\n }\n\n }\n\n &.open ul {\n display: block;\n }\n\n}\n\n#menu-to-edit {\n\n .menu-item {\n\n p.description-wide {\n\n position: relative;\n\n }\n\n .nav_item_options-roles {\n label {\n width: 33%;\n display: inline-block;\n float: left;\n margin-top: 5px;\n }\n }\n\n &.show-insert-button {\n\n .jpum-user-codes {\n display: block;\n }\n\n }\n\n }\n\n}\n",".jpum-user-codes {\n display: none;\n position: absolute;\n right: 2px;\n bottom: 2px;\n}\n\n.jpum-user-codes > span {\n border: 1px solid;\n border-radius: 2px;\n background-color: rgba(0, 0, 0, 0.5);\n color: #fff;\n text-align: center;\n cursor: pointer;\n font-size: 21px;\n height: 1em;\n width: 1em;\n}\n\n.jpum-user-codes ul {\n display: none;\n position: absolute;\n top: 1px;\n left: 22px;\n background-color: #fff;\n width: auto;\n z-index: 999;\n box-shadow: 1px 1px 5px -1px;\n border: 1px solid rgba(0, 0, 0, 0.25);\n}\n\n.jpum-user-codes ul li {\n display: block;\n padding: .5em;\n border-bottom: 1px dashed rgba(0, 0, 0, 0.25);\n}\n\n.jpum-user-codes ul li span {\n cursor: pointer;\n display: block;\n line-height: 1;\n}\n\n.jpum-user-codes ul li:last-child {\n border-bottom: 0;\n}\n\n.jpum-user-codes.open ul {\n display: block;\n}\n\n#menu-to-edit .menu-item p.description-wide {\n position: relative;\n}\n\n#menu-to-edit .menu-item .nav_item_options-roles label {\n width: 33%;\n display: inline-block;\n float: left;\n margin-top: 5px;\n}\n\n#menu-to-edit .menu-item.show-insert-button .jpum-user-codes {\n display: block;\n}\n\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRtaW4uY3NzIiwic291cmNlcyI6WyJhZG1pbi5zY3NzIl0sInNvdXJjZXNDb250ZW50IjpbIi5qcHVtLXVzZXItY29kZXMge1xuXG4gIGRpc3BsYXk6IG5vbmU7XG5cbiAgcG9zaXRpb246IGFic29sdXRlO1xuICByaWdodDogMnB4O1xuICBib3R0b206IDJweDtcblxuICA+IHNwYW4ge1xuXG4gICAgYm9yZGVyOiAxcHggc29saWQ7XG4gICAgYm9yZGVyLXJhZGl1czogMnB4O1xuICAgIGJhY2tncm91bmQtY29sb3I6IHJnYmEoMCwgMCwgMCwgLjUpO1xuICAgIGNvbG9yOiAjZmZmO1xuICAgIHRleHQtYWxpZ246IGNlbnRlcjtcbiAgICBjdXJzb3I6IHBvaW50ZXI7XG5cbiAgICBmb250LXNpemU6IDIxcHg7XG4gICAgaGVpZ2h0OiAxZW07XG4gICAgd2lkdGg6IDFlbTtcblxuICB9XG5cbiAgdWwge1xuICAgIGRpc3BsYXk6IG5vbmU7XG5cbiAgICBwb3NpdGlvbjogYWJzb2x1dGU7XG4gICAgdG9wOiAxcHg7XG4gICAgbGVmdDogMjJweD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LENBdUJkLEVBQUUsQ0FZQSxFQUFFLENBTUEsSUFBSSxDQUFDO0VBQ0gsTUFBTSxFQUFFLE9BQVE7RUFDaEIsT0FBTyxFQUFFLEtBQU07RUFDZixXQUFXLEVBQUUsQ0FBRTtDQUNoQjs7QUE3Q1AsQUFtQ0ksZ0JBbkNZLENBdUJkLEVBQUUsQ0FZQSxFQUFFLEFBWUMsV0FBVyxDQUFDO0VBQ1gsYUFBYSxFQUFFLENBQUU7Q0FDbEI7O0FBakRQLEFBdURTLGdCQXZETyxBQXVEYixLQUFLLENBQUMsRUFBRSxDQUFDO0VBQ1IsT0FBTyxFQUFFLEtBQU07Q0FDaEI7O0FBSUgsQUFJSyxhQUpRLENBRVgsVUFBVSxDQUVSLENBQUMsQUFBQSxpQkFBaUIsQ0FBQztFQUVqQixRQUFRLEVBQUUsUUFBUztDQUVwQjs7QUFSTCxBQVdNLGFBWE8sQ0FFWCxVQUFVLENBUVIsdUJBQXVCLENBQ3JCLEtBQUssQ0FBQztFQUNKLEtBQUssRUFBRSxHQUFJO0VBQ1gsT0FBTyxFQUFFLFlBQWE7RUFDdEIsS0FBSyxFQUFFLElBQUs7RUFDWixVQUFVLEVBQUUsR0FBSTtDQUNqQjs7QUFoQlAsQUFxQk0sYUFyQk8sQ0FFWCxVQUFVLEFBaUJQLG1CQUFtQixDQUVsQixnQkFBZ0IsQ0FBQztFQUNmLE9BQU8sRUFBRSxLQUFNO0NBQ2hCIiwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== */\n"],"sourceRoot":"/source/"}
|
assets/styles/admin.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.jpum-user-codes{display:none;position:absolute;right:2px;bottom:2px}.jpum-user-codes>span{border:1px solid;border-radius:2px;background-color:rgba(0,0,0,.5);color:#fff;text-align:center;cursor:pointer;font-size:21px;height:1em;width:1em}.jpum-user-codes ul{display:none;position:absolute;top:1px;left:22px;background-color:#fff;width:auto;z-index:999;box-shadow:1px 1px 5px -1px;border:1px solid rgba(0,0,0,.25)}.jpum-user-codes ul li{display:block;padding:.5em;border-bottom:1px dashed rgba(0,0,0,.25)}.jpum-user-codes ul li span{cursor:pointer;display:block;line-height:1}.jpum-user-codes ul li:last-child{border-bottom:0}#menu-to-edit .menu-item.show-insert-button .jpum-user-codes,.jpum-user-codes.open ul{display:block}#menu-to-edit .menu-item p.description-wide{position:relative}#menu-to-edit .menu-item .nav_item_options-roles label{width:33%;display:inline-block;float:left;margin-top:5px}
|
assets/styles/sass/admin.scss
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.jpum-user-codes {
|
2 |
+
|
3 |
+
display: none;
|
4 |
+
|
5 |
+
position: absolute;
|
6 |
+
right: 2px;
|
7 |
+
bottom: 2px;
|
8 |
+
|
9 |
+
> span {
|
10 |
+
|
11 |
+
border: 1px solid;
|
12 |
+
border-radius: 2px;
|
13 |
+
background-color: rgba(0, 0, 0, .5);
|
14 |
+
color: #fff;
|
15 |
+
text-align: center;
|
16 |
+
cursor: pointer;
|
17 |
+
|
18 |
+
font-size: 21px;
|
19 |
+
height: 1em;
|
20 |
+
width: 1em;
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
ul {
|
25 |
+
display: none;
|
26 |
+
|
27 |
+
position: absolute;
|
28 |
+
top: 1px;
|
29 |
+
left: 22px;
|
30 |
+
background-color: #fff;
|
31 |
+
width: auto;
|
32 |
+
z-index: 999;
|
33 |
+
box-shadow: 1px 1px 5px -1px;
|
34 |
+
border: 1px solid rgba(0, 0, 0, .25);
|
35 |
+
|
36 |
+
li {
|
37 |
+
|
38 |
+
display: block;
|
39 |
+
padding: .5em;
|
40 |
+
border-bottom: 1px dashed rgba(0, 0, 0, .25);
|
41 |
+
|
42 |
+
span {
|
43 |
+
cursor: pointer;
|
44 |
+
display: block;
|
45 |
+
line-height: 1;
|
46 |
+
}
|
47 |
+
|
48 |
+
&:last-child {
|
49 |
+
border-bottom: 0;
|
50 |
+
}
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
&.open ul {
|
57 |
+
display: block;
|
58 |
+
}
|
59 |
+
|
60 |
+
}
|
61 |
+
|
62 |
+
#menu-to-edit {
|
63 |
+
|
64 |
+
.menu-item {
|
65 |
+
|
66 |
+
p.description-wide {
|
67 |
+
|
68 |
+
position: relative;
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
.nav_item_options-roles {
|
73 |
+
label {
|
74 |
+
width: 33%;
|
75 |
+
display: inline-block;
|
76 |
+
float: left;
|
77 |
+
margin-top: 5px;
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
&.show-insert-button {
|
82 |
+
|
83 |
+
.jpum-user-codes {
|
84 |
+
display: block;
|
85 |
+
}
|
86 |
+
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
contributors.txt
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jungleplugins, danieliser
|
includes/classes/admin/menu-editor.php
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Admin;
|
4 |
+
|
5 |
+
use JP\UM\User\Codes;
|
6 |
+
|
7 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
+
exit;
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class JP\UM\Admin\Menu_Editor
|
13 |
+
*/
|
14 |
+
class Menu_Editor {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Init
|
18 |
+
*/
|
19 |
+
public static function init() {
|
20 |
+
add_filter( 'wp_edit_nav_menu_walker', array( __CLASS__, 'nav_menu_walker' ) );
|
21 |
+
add_action( 'admin_head-nav-menus.php', array( __CLASS__, 'register_metaboxes' ) );
|
22 |
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
23 |
+
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Override the Admin Menu Walker
|
27 |
+
*/
|
28 |
+
public static function nav_menu_walker( $walker ) {
|
29 |
+
global $wp_version;
|
30 |
+
|
31 |
+
if ( version_compare( $wp_version, '4.5.0', '>=' ) ) {
|
32 |
+
require_once \JP_User_Menus::$DIR . 'includes/classes/walker/nav-menu-edit.php';
|
33 |
+
|
34 |
+
return '\JP\UM\Walker\Nav_Menu_Edit';
|
35 |
+
} else {
|
36 |
+
require_once \JP_User_Menus::$DIR . 'includes/classes/walker/nav-menu-edit-deprecated.php';
|
37 |
+
|
38 |
+
return '\JP\UM\Walker\Nav_Menu_Edit_Deprecated';
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
/**
|
44 |
+
*
|
45 |
+
*/
|
46 |
+
public static function register_metaboxes() {
|
47 |
+
add_meta_box( 'jp_user_menus', __( 'User Links', 'user-menus' ), array( __CLASS__, 'nav_menu_metabox', ), 'nav-menus', 'side', 'default' );
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @param $object
|
52 |
+
*/
|
53 |
+
public static function nav_menu_metabox( $object ) {
|
54 |
+
global $_nav_menu_placeholder, $nav_menu_selected_id;
|
55 |
+
|
56 |
+
$link_types = array(
|
57 |
+
array(
|
58 |
+
'object' => 'login',
|
59 |
+
'title' => __( 'Login', 'user-menus' ),
|
60 |
+
),
|
61 |
+
array(
|
62 |
+
'object' => 'logout',
|
63 |
+
'title' => __( 'Logout', 'user-menus' ),
|
64 |
+
),
|
65 |
+
);
|
66 |
+
|
67 |
+
foreach ( $link_types as $key => $link ) {
|
68 |
+
|
69 |
+
$i = isset( $i ) ? $i + 1 : 1;
|
70 |
+
|
71 |
+
$link_types[ $key ] = (object) array_replace_recursive( array(
|
72 |
+
'type' => '',
|
73 |
+
'object' => '',
|
74 |
+
'title' => '',
|
75 |
+
'ID' => $i,
|
76 |
+
'object_id' => $i,
|
77 |
+
'db_id' => 0,
|
78 |
+
'post_parent' => 0,
|
79 |
+
'menu_item_parent' => 0,
|
80 |
+
'url' => '',
|
81 |
+
'target' => '',
|
82 |
+
'attr_title' => '',
|
83 |
+
'description' => '',
|
84 |
+
'classes' => array(),
|
85 |
+
'xfn' => '',
|
86 |
+
), $link );
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
$walker = new \Walker_Nav_Menu_Checklist;
|
91 |
+
|
92 |
+
$removed_args = array(
|
93 |
+
'action',
|
94 |
+
'customlink-tab',
|
95 |
+
'edit-menu-item',
|
96 |
+
'menu-item',
|
97 |
+
'page-tab',
|
98 |
+
'_wpnonce',
|
99 |
+
);
|
100 |
+
|
101 |
+
?>
|
102 |
+
|
103 |
+
<div id="user-menus-div" class="user-menus">
|
104 |
+
<div id="tabs-panel-user-menus-all" class="tabs-panel tabs-panel-active">
|
105 |
+
<ul id="user-menus-checklist-all" class="categorychecklist form-no-clear">
|
106 |
+
<?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $link_types ), 0, (object) array( 'walker' => $walker ) ); ?>
|
107 |
+
</ul>
|
108 |
+
|
109 |
+
<p class="button-controls">
|
110 |
+
<span class="list-controls">
|
111 |
+
<a href="<?php
|
112 |
+
echo esc_url( add_query_arg( array(
|
113 |
+
'user-menus-all' => 'all',
|
114 |
+
'selectall' => 1,
|
115 |
+
), remove_query_arg( $removed_args ) ) );
|
116 |
+
?>#user-menus-div" class="select-all"><?php _e( 'Select All' ); ?></a>
|
117 |
+
</span>
|
118 |
+
|
119 |
+
<span class="add-to-menu">
|
120 |
+
<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-user-menus-menu-item" id="submit-user-menus-div" />
|
121 |
+
<span class="spinner"></span>
|
122 |
+
</span>
|
123 |
+
</p>
|
124 |
+
</div>
|
125 |
+
</div>
|
126 |
+
|
127 |
+
<?php
|
128 |
+
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* @param $hook
|
133 |
+
*/
|
134 |
+
public static function enqueue_scripts( $hook ) {
|
135 |
+
if ( $hook != 'nav-menus.php' ) {
|
136 |
+
return;
|
137 |
+
}
|
138 |
+
|
139 |
+
add_action( 'admin_footer', array( __CLASS__, 'media_templates' ) );
|
140 |
+
|
141 |
+
// Use minified libraries if SCRIPT_DEBUG is turned off
|
142 |
+
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
143 |
+
|
144 |
+
wp_enqueue_script( 'jpum-scripts', \JP_User_Menus::$URL . 'assets/scripts/admin' . $suffix . '.js', array( 'jquery', 'underscore' ), \JP_User_Menus::$VER, true );
|
145 |
+
wp_enqueue_style( 'jpum-styles', \JP_User_Menus::$URL . 'assets/styles/admin' . $suffix . '.css', array( 'dashicons' ), \JP_User_Menus::$VER );
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
*
|
150 |
+
*/
|
151 |
+
public static function media_templates() { ?>
|
152 |
+
<script type="text/html" id="tmpl-jpum-user-codes">
|
153 |
+
<div class="jpum-user-codes">
|
154 |
+
<span class="dashicons dashicons-arrow-left" title="<?php _e( 'Insert User Menu Codes', 'user-menus' ); ?>"></span>
|
155 |
+
<ul>
|
156 |
+
<?php foreach( Codes::valid_codes() as $code ) : ?>
|
157 |
+
<li><span><?php echo $code; ?></span></li>
|
158 |
+
<?php endforeach; ?>
|
159 |
+
</ul>
|
160 |
+
</div>
|
161 |
+
</script>
|
162 |
+
<?php
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
Menu_Editor::init();
|
includes/classes/admin/menu-importer.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Admin;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Class JP\UM\Admin\Menu_Importer
|
12 |
+
*/
|
13 |
+
class Menu_Importer {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Init
|
17 |
+
*/
|
18 |
+
public static function init() {
|
19 |
+
add_action( 'admin_init', array( __CLASS__, 'register_importer' ) );
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Register a new menu importer.
|
24 |
+
*
|
25 |
+
* The WordPress Core Importer skips post meta for the menu items.
|
26 |
+
*
|
27 |
+
* @access private
|
28 |
+
* @return void
|
29 |
+
*/
|
30 |
+
public static function register_importer() {
|
31 |
+
|
32 |
+
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
|
33 |
+
|
34 |
+
if ( ! class_exists( 'JP\UM\Importer\Menu' ) ) {
|
35 |
+
require_once \JP_User_Menus::$DIR . 'includes/classes/importer/menu.php';
|
36 |
+
}
|
37 |
+
|
38 |
+
$importer = new \JP\UM\Importer\Menu();
|
39 |
+
|
40 |
+
register_importer(
|
41 |
+
'jpum_nav_menu_importer',
|
42 |
+
__( 'WP Nav Menus', 'user-menus' ),
|
43 |
+
__( 'Import nav menus and other menu item meta skipped by the default importer', 'user-menus' ),
|
44 |
+
array( $importer, 'dispatch' )
|
45 |
+
);
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
Menu_Importer::init();
|
includes/classes/admin/menu-settings.php
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Admin;
|
4 |
+
|
5 |
+
use JP\UM\Menu\Item;
|
6 |
+
|
7 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
+
exit;
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class JP\UM\Admin\Menu_Settings
|
13 |
+
*/
|
14 |
+
class Menu_Settings {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Init
|
18 |
+
*/
|
19 |
+
public static function init() {
|
20 |
+
add_action( 'wp_nav_menu_item_custom_fields', array( __CLASS__, 'fields' ), 10, 4 );
|
21 |
+
add_action( 'wp_update_nav_menu_item', array( __CLASS__, 'save' ), 10, 2 );
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @param $item_id
|
26 |
+
* @param $item
|
27 |
+
* @param $depth
|
28 |
+
* @param $args
|
29 |
+
*/
|
30 |
+
public static function fields( $item_id, $item, $depth, $args ) {
|
31 |
+
|
32 |
+
$allowed_user_roles = static::allowed_user_roles();
|
33 |
+
|
34 |
+
wp_nonce_field( 'jpum-menu-editor-nonce', 'jpum-menu-editor-nonce' );
|
35 |
+
|
36 |
+
if ( in_array( $item->object, array( 'login', 'logout' ) ) ) :
|
37 |
+
|
38 |
+
$redirect_types = array(
|
39 |
+
'current' => __( 'Current Page', 'user-menus' ),
|
40 |
+
'home' => __( 'Home Page', 'user-menus' ),
|
41 |
+
'custom' => __( 'Custom URL', 'user-menus' ),
|
42 |
+
); ?>
|
43 |
+
|
44 |
+
<p class="nav_item_options-redirect_type description description-wide">
|
45 |
+
|
46 |
+
<label for="jp_nav_item_options-redirect_type-<?php echo $item->ID; ?>">
|
47 |
+
|
48 |
+
<?php _e( 'Where should users be taken afterwards?', 'user-menus' ); ?><br/>
|
49 |
+
|
50 |
+
<select name="jp_nav_item_options[<?php echo $item->ID; ?>][redirect_type]" id="jp_nav_item_options-redirect_type-<?php echo $item->ID; ?>" class="widefat">
|
51 |
+
<?php foreach ( $redirect_types as $option => $label ) : ?>
|
52 |
+
<option value="<?php echo $option; ?>" <?php selected( $option, $item->redirect_type ); ?>>
|
53 |
+
<?php echo esc_html( $label ); ?>
|
54 |
+
</option>
|
55 |
+
<?php endforeach; ?>
|
56 |
+
</select>
|
57 |
+
|
58 |
+
</label>
|
59 |
+
|
60 |
+
</p>
|
61 |
+
|
62 |
+
<p class="nav_item_options-redirect_url description description-wide">
|
63 |
+
|
64 |
+
<label for="jp_nav_item_options-redirect_url-<?php echo $item->ID; ?>">
|
65 |
+
|
66 |
+
<?php _e( 'Enter a url user should be redirected to', 'user-menus' ); ?><br/>
|
67 |
+
|
68 |
+
<input type="text" name="jp_nav_item_options[<?php echo $item->ID; ?>][redirect_url]" id="jp_nav_item_options-redirect_url-<?php echo $item->ID; ?>" value="<?php esc_attr_e( $item->redirect_url ); ?>" class="widefat code" />
|
69 |
+
|
70 |
+
</label>
|
71 |
+
|
72 |
+
</p>
|
73 |
+
|
74 |
+
<?php else:
|
75 |
+
|
76 |
+
$which_users_options = array(
|
77 |
+
'' => __( 'Everyone', 'user-menus' ),
|
78 |
+
'logged_out' => __( 'Logged Out Users', 'user-menus' ),
|
79 |
+
'logged_in' => __( 'Logged In Users', 'user-menus' ),
|
80 |
+
); ?>
|
81 |
+
|
82 |
+
<p class="nav_item_options-which_users description description-wide">
|
83 |
+
|
84 |
+
<label for="jp_nav_item_options-which_users-<?php echo $item->ID; ?>">
|
85 |
+
|
86 |
+
<?php _e( 'Who can see this link?', 'user-menus' ); ?><br/>
|
87 |
+
|
88 |
+
<select name="jp_nav_item_options[<?php echo $item->ID; ?>][which_users]" id="jp_nav_item_options-which_users-<?php echo $item->ID; ?>" class="widefat">
|
89 |
+
<?php foreach ( $which_users_options as $option => $label ) : ?>
|
90 |
+
<option value="<?php echo $option; ?>" <?php selected( $option, $item->which_users ); ?>>
|
91 |
+
<?php echo esc_html( $label ); ?>
|
92 |
+
</option>
|
93 |
+
<?php endforeach; ?>
|
94 |
+
</select>
|
95 |
+
|
96 |
+
</label>
|
97 |
+
|
98 |
+
</p>
|
99 |
+
|
100 |
+
<p class="nav_item_options-roles description description-wide">
|
101 |
+
|
102 |
+
<?php _e( 'Choose which roles can see this link', 'user-menus' ); ?><br/>
|
103 |
+
|
104 |
+
<?php foreach ( $allowed_user_roles as $option => $label ) : ?>
|
105 |
+
<label>
|
106 |
+
<input type="checkbox" name="jp_nav_item_options[<?php echo $item->ID; ?>][roles][]" value="<?php echo $option; ?>" <?php checked( in_array( $option, $item->roles ), true ); ?>/>
|
107 |
+
<?php echo esc_html( $label ); ?>
|
108 |
+
</label>
|
109 |
+
<?php endforeach; ?>
|
110 |
+
|
111 |
+
</p>
|
112 |
+
|
113 |
+
<?php endif;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* @return array|mixed|void
|
118 |
+
*/
|
119 |
+
public static function allowed_user_roles() {
|
120 |
+
global $wp_roles;
|
121 |
+
|
122 |
+
static $roles;
|
123 |
+
|
124 |
+
if ( ! isset( $roles ) ) {
|
125 |
+
$roles = apply_filters( 'jpum_user_roles', $wp_roles->role_names );
|
126 |
+
|
127 |
+
if ( ! is_array( $roles ) || empty( $roles ) ) {
|
128 |
+
$roles = array();
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
return $roles;
|
133 |
+
}
|
134 |
+
|
135 |
+
public static function save( $menu_id, $item_id ) {
|
136 |
+
|
137 |
+
$allowed_roles = static::allowed_user_roles();
|
138 |
+
|
139 |
+
if ( empty( $_POST['jp_nav_item_options'][ $item_id ] ) || ! isset( $_POST['jpum-menu-editor-nonce'] ) || ! wp_verify_nonce( $_POST['jpum-menu-editor-nonce'], 'jpum-menu-editor-nonce' ) ) {
|
140 |
+
return;
|
141 |
+
}
|
142 |
+
|
143 |
+
$item_options = Item::parse_options( $_POST['jp_nav_item_options'][ $item_id ] );
|
144 |
+
|
145 |
+
if ( $item_options['which_users'] == 'logged_in' ) {
|
146 |
+
// Validate chosen roles and remove non-allowed roles.
|
147 |
+
foreach ( (array) $item_options['roles'] as $key => $role ) {
|
148 |
+
if ( ! array_key_exists( $role, $allowed_roles ) ) {
|
149 |
+
unset( $item_options['roles'][ $key ] );
|
150 |
+
}
|
151 |
+
}
|
152 |
+
} else {
|
153 |
+
unset( $item_options['roles'] );
|
154 |
+
}
|
155 |
+
|
156 |
+
// Remove empty options to save space.
|
157 |
+
$item_options = array_filter( $item_options );
|
158 |
+
|
159 |
+
if ( ! empty( $item_options ) ) {
|
160 |
+
update_post_meta( $item_id, '_jp_nav_item_options', $item_options );
|
161 |
+
} else {
|
162 |
+
delete_post_meta( $item_id, '_jp_nav_item_options' );
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
Menu_Settings::init();
|
includes/classes/importer/menu.php
ADDED
@@ -0,0 +1,298 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Importer;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
10 |
+
return;
|
11 |
+
}
|
12 |
+
|
13 |
+
/** Display verbose errors */
|
14 |
+
if ( ! defined( 'IMPORT_DEBUG' ) ) {
|
15 |
+
/**
|
16 |
+
*
|
17 |
+
*/
|
18 |
+
define( 'IMPORT_DEBUG', false );
|
19 |
+
}
|
20 |
+
|
21 |
+
// Load Importer API
|
22 |
+
require_once ABSPATH . 'wp-admin/includes/import.php';
|
23 |
+
|
24 |
+
if ( ! class_exists( 'WP_Importer' ) ) {
|
25 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Class JP\UM\Importer\Menu
|
31 |
+
*/
|
32 |
+
class Menu extends \WP_Importer {
|
33 |
+
|
34 |
+
/**
|
35 |
+
* @var float max. supported WXR version
|
36 |
+
*/
|
37 |
+
public $max_wxr_version = 1.2;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @var integer WXR attachment ID
|
41 |
+
*/
|
42 |
+
public $id;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @var string WXR File Version
|
46 |
+
*/
|
47 |
+
public $version;
|
48 |
+
/**
|
49 |
+
* @var array
|
50 |
+
*/
|
51 |
+
public $posts = array();
|
52 |
+
/**
|
53 |
+
* @var string
|
54 |
+
*/
|
55 |
+
public $base_url = '';
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @var array
|
59 |
+
*/
|
60 |
+
public $invalid_meta_keys = array(
|
61 |
+
'_wp_attached_file',
|
62 |
+
'_wp_attachment_metadata',
|
63 |
+
'_edit_lock',
|
64 |
+
);
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Registered callback function for the WordPress Importer
|
68 |
+
*
|
69 |
+
* Manages the three separate stages of the WXR import process
|
70 |
+
*/
|
71 |
+
public function dispatch() {
|
72 |
+
$this->header();
|
73 |
+
|
74 |
+
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
|
75 |
+
switch ( $step ) {
|
76 |
+
case 0:
|
77 |
+
$this->greet();
|
78 |
+
break;
|
79 |
+
case 1:
|
80 |
+
check_admin_referer( 'import-upload' );
|
81 |
+
if ( $this->handle_upload() ) {
|
82 |
+
$file = get_attached_file( $this->id );
|
83 |
+
set_time_limit( 0 );
|
84 |
+
$this->import( $file );
|
85 |
+
}
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
|
89 |
+
$this->footer();
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Page header.
|
94 |
+
*/
|
95 |
+
public function header() {
|
96 |
+
echo '<div class="wrap">';
|
97 |
+
echo '<h2>' . __( 'Import Nav Menus', 'user-menus' ) . '</h2>';
|
98 |
+
|
99 |
+
$updates = get_plugin_updates();
|
100 |
+
$basename = plugin_basename( __FILE__ );
|
101 |
+
if ( isset( $updates[ $basename ] ) ) {
|
102 |
+
$update = $updates[ $basename ];
|
103 |
+
echo '<div class="error"><p><strong>';
|
104 |
+
printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'user-menus' ), $update->update->new_version );
|
105 |
+
echo '</strong></p></div>';
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Display introductory text and file upload form
|
111 |
+
*/
|
112 |
+
public function greet() {
|
113 |
+
echo '<div class="narrow">';
|
114 |
+
echo '<p>' . __( 'Upload your WordPress export (WXR) file and import the Nav Menus and any meta for the Nav Menu items.', 'user-menus' ) . '</p>';
|
115 |
+
echo '<p>' . __( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'user-menus' ) . '</p>';
|
116 |
+
wp_import_upload_form( 'admin.php?import=jpum_nav_menu_importer&step=1' );
|
117 |
+
echo '</div>';
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Handles the WXR upload and initial parsing of the file to prepare for
|
122 |
+
* displaying author import options
|
123 |
+
*
|
124 |
+
* @return bool False if error uploading or invalid file, true otherwise
|
125 |
+
*/
|
126 |
+
public function handle_upload() {
|
127 |
+
$file = wp_import_handle_upload();
|
128 |
+
|
129 |
+
if ( isset( $file['error'] ) ) {
|
130 |
+
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'user-menus' ) . '</strong><br />';
|
131 |
+
echo esc_html( $file['error'] ) . '</p>';
|
132 |
+
|
133 |
+
return false;
|
134 |
+
} else if ( ! file_exists( $file['file'] ) ) {
|
135 |
+
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'user-menus' ) . '</strong><br />';
|
136 |
+
printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'user-menus' ), esc_html( $file['file'] ) );
|
137 |
+
echo '</p>';
|
138 |
+
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
|
142 |
+
$this->id = (int) $file['id'];
|
143 |
+
$import_data = $this->parse( $file['file'] );
|
144 |
+
if ( is_wp_error( $import_data ) ) {
|
145 |
+
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'user-menus' ) . '</strong><br />';
|
146 |
+
echo esc_html( $import_data->get_error_message() ) . '</p>';
|
147 |
+
|
148 |
+
return false;
|
149 |
+
}
|
150 |
+
|
151 |
+
$this->version = $import_data['version'];
|
152 |
+
if ( $this->version > $this->max_wxr_version ) {
|
153 |
+
echo '<div class="error"><p><strong>';
|
154 |
+
printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'user-menus' ), esc_html( $import_data['version'] ) );
|
155 |
+
echo '</strong></p></div>';
|
156 |
+
}
|
157 |
+
|
158 |
+
return true;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* The main controller for the actual import stage.
|
163 |
+
*
|
164 |
+
* @param string $file Path to the WXR file for importing
|
165 |
+
*/
|
166 |
+
public function import( $file ) {
|
167 |
+
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
|
168 |
+
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
169 |
+
|
170 |
+
$this->import_start( $file );
|
171 |
+
|
172 |
+
wp_suspend_cache_invalidation( true );
|
173 |
+
$this->process_nav_menu_meta();
|
174 |
+
wp_suspend_cache_invalidation( false );
|
175 |
+
|
176 |
+
$this->import_end();
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Render the page footer.
|
181 |
+
*/
|
182 |
+
public function footer() {
|
183 |
+
echo '</div>';
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Parse a WXR file
|
188 |
+
*
|
189 |
+
* @param string $file Path to WXR file for parsing
|
190 |
+
*
|
191 |
+
* @return array Information gathered from the WXR file
|
192 |
+
*/
|
193 |
+
public function parse( $file ) {
|
194 |
+
$parser = new \WXR_Parser();
|
195 |
+
|
196 |
+
return $parser->parse( $file );
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Parses the WXR file and prepares us for the task of processing parsed data
|
201 |
+
*
|
202 |
+
* @param string $file Path to the WXR file for importing
|
203 |
+
*/
|
204 |
+
public function import_start( $file ) {
|
205 |
+
if ( ! is_file( $file ) ) {
|
206 |
+
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'user-menus' ) . '</strong><br />';
|
207 |
+
echo __( 'The file does not exist, please try again.', 'user-menus' );
|
208 |
+
echo '</p>';
|
209 |
+
|
210 |
+
$this->footer();
|
211 |
+
die();
|
212 |
+
}
|
213 |
+
|
214 |
+
$import_data = $this->parse( $file );
|
215 |
+
|
216 |
+
if ( is_wp_error( $import_data ) ) {
|
217 |
+
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'user-menus' ) . '</strong><br />';
|
218 |
+
echo esc_html( $import_data->get_error_message() );;
|
219 |
+
echo '</p>';
|
220 |
+
|
221 |
+
$this->footer();
|
222 |
+
die();
|
223 |
+
}
|
224 |
+
|
225 |
+
$this->version = $import_data['version'];
|
226 |
+
$this->posts = $import_data['posts'];
|
227 |
+
$this->base_url = esc_url( $import_data['base_url'] );
|
228 |
+
|
229 |
+
do_action( 'import_start' );
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Create new menu items based on import information
|
234 |
+
*/
|
235 |
+
public function process_nav_menu_meta() {
|
236 |
+
foreach ( $this->posts as $post ) {
|
237 |
+
|
238 |
+
// Exclude other post types.
|
239 |
+
if ( 'nav_menu_item' != $post['post_type'] || ! empty( $post['post_id'] ) ) {
|
240 |
+
continue;
|
241 |
+
}
|
242 |
+
|
243 |
+
$post_id = (int) $post['post_id'];
|
244 |
+
|
245 |
+
if ( isset( $post['postmeta'] ) ) {
|
246 |
+
|
247 |
+
foreach ( $post['postmeta'] as $meta ) {
|
248 |
+
|
249 |
+
$key = apply_filters( 'import_post_meta_key', $meta['key'] );
|
250 |
+
$value = false;
|
251 |
+
|
252 |
+
|
253 |
+
if ( $key ) {
|
254 |
+
// export gets meta straight from the DB so could have a serialized string
|
255 |
+
if ( ! $value ) {
|
256 |
+
$value = maybe_unserialize( $meta['value'] );
|
257 |
+
}
|
258 |
+
|
259 |
+
update_post_meta( $post_id, $key, $value );
|
260 |
+
do_action( 'import_post_meta', $post_id, $key, $value );
|
261 |
+
|
262 |
+
}
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
unset( $this->posts );
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Performs post-import cleanup of files and the cache
|
272 |
+
*/
|
273 |
+
public function import_end() {
|
274 |
+
wp_import_cleanup( $this->id );
|
275 |
+
|
276 |
+
wp_cache_flush();
|
277 |
+
|
278 |
+
echo '<p>' . __( 'All done.', 'user-menus' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'user-menus' ) . '</a>' . '</p>';
|
279 |
+
|
280 |
+
do_action( 'import_end' );
|
281 |
+
}
|
282 |
+
|
283 |
+
/**
|
284 |
+
* Decide if the given meta key maps to information we will want to import
|
285 |
+
*
|
286 |
+
* @param string $key The meta key to check
|
287 |
+
*
|
288 |
+
* @return string|bool The key if we do want to import, false if not
|
289 |
+
*/
|
290 |
+
public function is_valid_meta_key( $key ) {
|
291 |
+
if ( in_array( $key, $this->invalid_meta_keys ) ) {
|
292 |
+
return false;
|
293 |
+
}
|
294 |
+
|
295 |
+
return $key;
|
296 |
+
}
|
297 |
+
|
298 |
+
}
|
includes/classes/menu/item.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Menu;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class JP\UM\Menu\Item
|
11 |
+
*/
|
12 |
+
class Item {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @param int $item_id
|
16 |
+
*
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
+
public static function get_options( $item_id = 0 ) {
|
20 |
+
|
21 |
+
// Fetch all rules for this menu item.
|
22 |
+
$item_options = get_post_meta( $item_id, '_jp_nav_item_options', true );
|
23 |
+
|
24 |
+
return static::parse_options( $item_options );
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @param array $options
|
29 |
+
*
|
30 |
+
* @return array
|
31 |
+
*/
|
32 |
+
public static function parse_options( $options = array() ) {
|
33 |
+
|
34 |
+
if ( ! is_array( $options ) ) {
|
35 |
+
$options = array();
|
36 |
+
}
|
37 |
+
|
38 |
+
return wp_parse_args( $options, array(
|
39 |
+
'redirect_type' => 'current',
|
40 |
+
'redirect_url' => '',
|
41 |
+
'which_users' => '',
|
42 |
+
'roles' => array(),
|
43 |
+
) );
|
44 |
+
}
|
45 |
+
|
46 |
+
}
|
includes/classes/menu/items.php
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Menu;
|
4 |
+
|
5 |
+
use JP\UM\User\Codes;
|
6 |
+
|
7 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
+
exit;
|
9 |
+
}
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class JP\UM\Menu\Items
|
13 |
+
*/
|
14 |
+
class Items {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Init
|
18 |
+
*/
|
19 |
+
public static function init() {
|
20 |
+
add_filter( 'wp_setup_nav_menu_item', array( __CLASS__, 'merge_item_data' ) );
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Merge Item data into the $item object.
|
25 |
+
*
|
26 |
+
* @param $item
|
27 |
+
*
|
28 |
+
* @return mixed
|
29 |
+
*/
|
30 |
+
public static function merge_item_data( $item ) {
|
31 |
+
|
32 |
+
// Merge Rules.
|
33 |
+
foreach ( Item::get_options( $item->ID ) as $key => $value ) {
|
34 |
+
$item->$key = $value;
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( in_array( $item->object, array( 'login', 'logout' ) ) ) {
|
38 |
+
|
39 |
+
$item->type_label = __( 'User Link', 'user-menus' );
|
40 |
+
|
41 |
+
switch ( $item->redirect_type ) {
|
42 |
+
case 'current':
|
43 |
+
$redirect = static::current_url();
|
44 |
+
break;
|
45 |
+
|
46 |
+
case 'home':
|
47 |
+
$redirect = home_url();
|
48 |
+
break;
|
49 |
+
|
50 |
+
case 'custom':
|
51 |
+
$redirect = $item->redirect_url;
|
52 |
+
break;
|
53 |
+
|
54 |
+
default:
|
55 |
+
$redirect = '';
|
56 |
+
break;
|
57 |
+
}
|
58 |
+
|
59 |
+
$item->url = $item->object == 'logout' ? wp_logout_url( $redirect ) : wp_login_url( $redirect );
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
// User text replacement.
|
64 |
+
if ( ! is_admin() ) {
|
65 |
+
$item->title = static::user_titles( $item->title );
|
66 |
+
}
|
67 |
+
|
68 |
+
|
69 |
+
return $item;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @return string
|
74 |
+
*/
|
75 |
+
public static function current_url() {
|
76 |
+
$protocol = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
|
77 |
+
|
78 |
+
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* @param string $title
|
83 |
+
*
|
84 |
+
* @return mixed|string
|
85 |
+
*/
|
86 |
+
public static function user_titles( $title = '' ) {
|
87 |
+
|
88 |
+
preg_match_all( '/{(.*?)}/', $title, $found );
|
89 |
+
|
90 |
+
if ( count( $found[1] ) ) {
|
91 |
+
|
92 |
+
foreach ( $found[1] as $key => $match ) {
|
93 |
+
|
94 |
+
$title = static::text_replace( $title, $match );
|
95 |
+
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
return $title;
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* @param string $title
|
105 |
+
* @param string $match
|
106 |
+
*
|
107 |
+
* @return mixed|string
|
108 |
+
*/
|
109 |
+
public static function text_replace( $title = '', $match = '' ) {
|
110 |
+
|
111 |
+
if ( empty( $match ) ) {
|
112 |
+
return $title;
|
113 |
+
}
|
114 |
+
|
115 |
+
if ( strpos( $match, '||' ) !== false ) {
|
116 |
+
$matches = explode( '||', $match );
|
117 |
+
} else {
|
118 |
+
$matches = array( $match );
|
119 |
+
}
|
120 |
+
|
121 |
+
$current_user = wp_get_current_user();
|
122 |
+
|
123 |
+
$replace = '';
|
124 |
+
|
125 |
+
foreach ( $matches as $string ) {
|
126 |
+
|
127 |
+
if ( $current_user->ID == 0 && in_array( $string, Codes::valid_codes() ) ) {
|
128 |
+
|
129 |
+
$replace = '';
|
130 |
+
|
131 |
+
} else {
|
132 |
+
|
133 |
+
switch ( $string ) {
|
134 |
+
|
135 |
+
case 'first_name':
|
136 |
+
$replace = $current_user->user_firstname;
|
137 |
+
break;
|
138 |
+
|
139 |
+
case 'last_name':
|
140 |
+
$replace = $current_user->user_lastname;
|
141 |
+
break;
|
142 |
+
|
143 |
+
case 'username':
|
144 |
+
$replace = $current_user->user_login;
|
145 |
+
break;
|
146 |
+
|
147 |
+
case 'display_name':
|
148 |
+
$replace = $current_user->display_name;
|
149 |
+
break;
|
150 |
+
|
151 |
+
case 'nickname':
|
152 |
+
$replace = $current_user->nickname;
|
153 |
+
break;
|
154 |
+
|
155 |
+
case 'email':
|
156 |
+
$replace = $current_user->user_email;
|
157 |
+
break;
|
158 |
+
|
159 |
+
default:
|
160 |
+
$replace = $string;
|
161 |
+
break;
|
162 |
+
|
163 |
+
}
|
164 |
+
|
165 |
+
}
|
166 |
+
|
167 |
+
// If we found a replacement stop the loop.
|
168 |
+
if ( ! empty( $replace ) ) {
|
169 |
+
break;
|
170 |
+
}
|
171 |
+
|
172 |
+
}
|
173 |
+
|
174 |
+
return str_replace( '{' . $match . '}', $replace, $title );
|
175 |
+
}
|
176 |
+
|
177 |
+
}
|
178 |
+
|
179 |
+
Items::init();
|
includes/classes/site/menus.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Site;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class JP\UM\Site\Menus
|
11 |
+
*/
|
12 |
+
class Menus {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Init
|
16 |
+
*/
|
17 |
+
public static function init() {
|
18 |
+
add_filter( 'wp_get_nav_menu_items', array( __CLASS__, 'exclude_menu_items' ) );
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Exclude menu items via wp_get_nav_menu_items filter.
|
23 |
+
*
|
24 |
+
* Guarantees compatibility with nearly any theme.
|
25 |
+
*/
|
26 |
+
public static function exclude_menu_items( $items = array() ) {
|
27 |
+
|
28 |
+
if ( empty( $items ) ) {
|
29 |
+
return $items;
|
30 |
+
}
|
31 |
+
|
32 |
+
$logged_in = is_user_logged_in();
|
33 |
+
|
34 |
+
$excluded = array();
|
35 |
+
|
36 |
+
foreach ( $items as $key => $item ) {
|
37 |
+
|
38 |
+
$exclude = in_array( $item->menu_item_parent, $excluded );
|
39 |
+
|
40 |
+
if ( $item->object == 'logout' ) {
|
41 |
+
$exclude = ! $logged_in;
|
42 |
+
} elseif ( $item->object == 'login' ) {
|
43 |
+
$exclude = $logged_in;
|
44 |
+
} else {
|
45 |
+
|
46 |
+
switch ( $item->which_users ) {
|
47 |
+
|
48 |
+
case 'logged_in':
|
49 |
+
if ( ! $logged_in ) {
|
50 |
+
$exclude = true;
|
51 |
+
} elseif ( ! empty( $item->roles ) ) {
|
52 |
+
|
53 |
+
// Checks all roles, should not exclude if any are active.
|
54 |
+
$valid_role = false;
|
55 |
+
|
56 |
+
foreach ( $item->roles as $role ) {
|
57 |
+
if ( current_user_can( $role ) ) {
|
58 |
+
$valid_role = true;
|
59 |
+
break;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
if ( ! $valid_role ) {
|
64 |
+
$exclude = true;
|
65 |
+
}
|
66 |
+
}
|
67 |
+
break;
|
68 |
+
|
69 |
+
case 'logged_out':
|
70 |
+
$exclude = $logged_in;
|
71 |
+
break;
|
72 |
+
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
76 |
+
|
77 |
+
$exclude = apply_filters( 'jpum_should_exclude_item', $exclude, $item );
|
78 |
+
|
79 |
+
// unset non-visible item
|
80 |
+
if ( $exclude ) {
|
81 |
+
$excluded[] = $item->ID; // store ID of item
|
82 |
+
unset( $items[ $key ] );
|
83 |
+
}
|
84 |
+
|
85 |
+
}
|
86 |
+
|
87 |
+
return $items;
|
88 |
+
}
|
89 |
+
|
90 |
+
}
|
91 |
+
|
92 |
+
Menus::init();
|
includes/classes/user/codes.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\User;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class JP\UM\User\Codes
|
11 |
+
*/
|
12 |
+
class Codes {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @return array
|
16 |
+
*/
|
17 |
+
public static function valid_codes() {
|
18 |
+
return array(
|
19 |
+
'first_name',
|
20 |
+
'last_name',
|
21 |
+
'username',
|
22 |
+
'display_name',
|
23 |
+
'nickname',
|
24 |
+
'email',
|
25 |
+
);
|
26 |
+
}
|
27 |
+
|
28 |
+
}
|
includes/classes/walker/nav-menu-edit-deprecated.php
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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av_Menu_Edit class in core /wp-admin/includes/nav-menu.php
|
13 |
+
*
|
14 |
+
* @since WordPress 4.4.0
|
15 |
+
*/
|
16 |
+
class Nav_Menu_Edit_Deprecated extends \Walker_Nav_Menu {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Start the element output.
|
20 |
+
*
|
21 |
+
* @see Walker_Nav_Menu::start_el()
|
22 |
+
* @since 3.0.0
|
23 |
+
*
|
24 |
+
* @global int $_wp_nav_menu_max_depth
|
25 |
+
*
|
26 |
+
* @param string $output Passed by reference. Used to append additional content.
|
27 |
+
* @param object $item Menu item data object.
|
28 |
+
* @param int $depth Depth of menu item. Used for padding.
|
29 |
+
* @param array $args Not used.
|
30 |
+
* @param int $id Not used.
|
31 |
+
*/
|
32 |
+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
33 |
+
global $_wp_nav_menu_max_depth;
|
34 |
+
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
35 |
+
|
36 |
+
ob_start();
|
37 |
+
$item_id = esc_attr( $item->ID );
|
38 |
+
$removed_args = array(
|
39 |
+
'action',
|
40 |
+
'customlink-tab',
|
41 |
+
'edit-menu-item',
|
42 |
+
'menu-item',
|
43 |
+
'page-tab',
|
44 |
+
'_wpnonce',
|
45 |
+
);
|
46 |
+
|
47 |
+
$original_title = '';
|
48 |
+
if ( 'taxonomy' == $item->type ) {
|
49 |
+
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
50 |
+
if ( is_wp_error( $original_title ) )
|
51 |
+
$original_title = false;
|
52 |
+
} elseif ( 'post_type' == $item->type ) {
|
53 |
+
$original_object = get_post( $item->object_id );
|
54 |
+
$original_title = get_the_title( $original_object->ID );
|
55 |
+
} elseif ( 'post_type_archive' == $item->type ) {
|
56 |
+
$original_object = get_post_type_object( $item->object );
|
57 |
+
$original_title = $original_object->labels->archives;
|
58 |
+
}
|
59 |
+
|
60 |
+
$classes = array(
|
61 |
+
'menu-item menu-item-depth-' . $depth,
|
62 |
+
'menu-item-' . esc_attr( $item->object ),
|
63 |
+
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
64 |
+
);
|
65 |
+
|
66 |
+
$title = $item->title;
|
67 |
+
|
68 |
+
if ( ! empty( $item->_invalid ) ) {
|
69 |
+
$classes[] = 'menu-item-invalid';
|
70 |
+
/* translators: %s: title of menu item which is invalid */
|
71 |
+
$title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
|
72 |
+
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
73 |
+
$classes[] = 'pending';
|
74 |
+
/* translators: %s: title of menu item in draft status */
|
75 |
+
$title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
|
76 |
+
}
|
77 |
+
|
78 |
+
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
79 |
+
|
80 |
+
$submenu_text = '';
|
81 |
+
if ( 0 == $depth )
|
82 |
+
$submenu_text = 'style="display: none;"';
|
83 |
+
|
84 |
+
?>
|
85 |
+
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
|
86 |
+
<div class="menu-item-bar">
|
87 |
+
<div class="menu-item-handle">
|
88 |
+
<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' , 'nav-menu-roles' ); ?></span></span>
|
89 |
+
<span class="item-controls">
|
90 |
+
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
91 |
+
<span class="item-order hide-if-js">
|
92 |
+
<a href="<?php
|
93 |
+
echo wp_nonce_url(
|
94 |
+
add_query_arg(
|
95 |
+
array(
|
96 |
+
'action' => 'move-up-menu-item',
|
97 |
+
'menu-item' => $item_id,
|
98 |
+
),
|
99 |
+
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
100 |
+
),
|
101 |
+
'move-menu_item'
|
102 |
+
);
|
103 |
+
?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">↑</abbr></a>
|
104 |
+
|
|
105 |
+
<a href="<?php
|
106 |
+
echo wp_nonce_url(
|
107 |
+
add_query_arg(
|
108 |
+
array(
|
109 |
+
'action' => 'move-down-menu-item',
|
110 |
+
'menu-item' => $item_id,
|
111 |
+
),
|
112 |
+
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
113 |
+
),
|
114 |
+
'move-menu_item'
|
115 |
+
);
|
116 |
+
?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">↓</abbr></a>
|
117 |
+
</span>
|
118 |
+
<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
|
119 |
+
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
|
120 |
+
?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
|
121 |
+
</span>
|
122 |
+
</div>
|
123 |
+
</div>
|
124 |
+
|
125 |
+
<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
|
126 |
+
<?php if ( 'custom' == $item->type ) : ?>
|
127 |
+
<p class="field-url description description-wide">
|
128 |
+
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
129 |
+
<?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
|
130 |
+
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
|
131 |
+
</label>
|
132 |
+
</p>
|
133 |
+
<?php endif; ?>
|
134 |
+
<p class="description description-wide">
|
135 |
+
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
136 |
+
<?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
|
137 |
+
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
|
138 |
+
</label>
|
139 |
+
</p>
|
140 |
+
<p class="field-title-attribute description description-wide">
|
141 |
+
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
142 |
+
<?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
|
143 |
+
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
|
144 |
+
</label>
|
145 |
+
</p>
|
146 |
+
<p class="field-link-target description">
|
147 |
+
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
148 |
+
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
|
149 |
+
<?php _e( 'Open link in a new tab' , 'nav-menu-roles' ); ?>
|
150 |
+
</label>
|
151 |
+
</p>
|
152 |
+
<p class="field-css-classes description description-thin">
|
153 |
+
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
154 |
+
<?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
|
155 |
+
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
|
156 |
+
</label>
|
157 |
+
</p>
|
158 |
+
<p class="field-xfn description description-thin">
|
159 |
+
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
160 |
+
<?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
|
161 |
+
<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 ); ?>" />
|
162 |
+
</label>
|
163 |
+
</p>
|
164 |
+
<p class="field-description description description-wide">
|
165 |
+
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
166 |
+
<?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
|
167 |
+
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
|
168 |
+
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
|
169 |
+
</label>
|
170 |
+
</p>
|
171 |
+
|
172 |
+
<?php
|
173 |
+
/**
|
174 |
+
* This action allows easily extending the admin menu walker class in a useful manner without conflicting with others.
|
175 |
+
*/
|
176 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args ); ?>
|
177 |
+
|
178 |
+
<p class="field-move hide-if-no-js description description-wide">
|
179 |
+
<label>
|
180 |
+
<span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
|
181 |
+
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
|
182 |
+
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
|
183 |
+
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
184 |
+
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
185 |
+
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
|
186 |
+
</label>
|
187 |
+
</p>
|
188 |
+
|
189 |
+
<div class="menu-item-actions description-wide submitbox">
|
190 |
+
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
|
191 |
+
<p class="link-to-original">
|
192 |
+
<?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
193 |
+
</p>
|
194 |
+
<?php endif; ?>
|
195 |
+
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
|
196 |
+
echo wp_nonce_url(
|
197 |
+
add_query_arg(
|
198 |
+
array(
|
199 |
+
'action' => 'delete-menu-item',
|
200 |
+
'menu-item' => $item_id,
|
201 |
+
),
|
202 |
+
admin_url( 'nav-menus.php' )
|
203 |
+
),
|
204 |
+
'delete-menu_item_' . $item_id
|
205 |
+
); ?>"><?php _e( 'Remove' , 'nav-menu-roles' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
|
206 |
+
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
|
207 |
+
</div>
|
208 |
+
|
209 |
+
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
210 |
+
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
|
211 |
+
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
212 |
+
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
|
213 |
+
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
214 |
+
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
215 |
+
</div><!-- .menu-item-settings-->
|
216 |
+
<ul class="menu-item-transport"></ul>
|
217 |
+
<?php
|
218 |
+
$output .= ob_get_clean();
|
219 |
+
}
|
220 |
+
}
|
includes/classes/walker/nav-menu-edit.php
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace JP\UM\Walker;
|
4 |
+
|
5 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
6 |
+
exit;
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
|
11 |
+
*
|
12 |
+
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/class-walker-nav-menu-edit.php
|
13 |
+
*
|
14 |
+
* @since WordPress 4.5.0
|
15 |
+
*/
|
16 |
+
class Nav_Menu_Edit extends \Walker_Nav_Menu_Edit {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Start the element output.
|
20 |
+
*
|
21 |
+
* @see Walker_Nav_Menu::start_el()
|
22 |
+
* @since 3.0.0
|
23 |
+
*
|
24 |
+
* @global int $_wp_nav_menu_max_depth
|
25 |
+
*
|
26 |
+
* @param string $output Passed by reference. Used to append additional content.
|
27 |
+
* @param object $item Menu item data object.
|
28 |
+
* @param int $depth Depth of menu item. Used for padding.
|
29 |
+
* @param array $args Not used.
|
30 |
+
* @param int $id Not used.
|
31 |
+
*/
|
32 |
+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
33 |
+
global $_wp_nav_menu_max_depth;
|
34 |
+
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
35 |
+
|
36 |
+
ob_start();
|
37 |
+
$item_id = esc_attr( $item->ID );
|
38 |
+
$removed_args = array(
|
39 |
+
'action',
|
40 |
+
'customlink-tab',
|
41 |
+
'edit-menu-item',
|
42 |
+
'menu-item',
|
43 |
+
'page-tab',
|
44 |
+
'_wpnonce',
|
45 |
+
);
|
46 |
+
|
47 |
+
$original_title = '';
|
48 |
+
if ( 'taxonomy' == $item->type ) {
|
49 |
+
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
50 |
+
if ( is_wp_error( $original_title ) )
|
51 |
+
$original_title = false;
|
52 |
+
} elseif ( 'post_type' == $item->type ) {
|
53 |
+
$original_object = get_post( $item->object_id );
|
54 |
+
$original_title = get_the_title( $original_object->ID );
|
55 |
+
} elseif ( 'post_type_archive' == $item->type ) {
|
56 |
+
$original_object = get_post_type_object( $item->object );
|
57 |
+
if ( $original_object ) {
|
58 |
+
$original_title = $original_object->labels->archives;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
$classes = array(
|
63 |
+
'menu-item menu-item-depth-' . $depth,
|
64 |
+
'menu-item-' . esc_attr( $item->object ),
|
65 |
+
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
66 |
+
);
|
67 |
+
|
68 |
+
$title = $item->title;
|
69 |
+
|
70 |
+
if ( ! empty( $item->_invalid ) ) {
|
71 |
+
$classes[] = 'menu-item-invalid';
|
72 |
+
/* translators: %s: title of menu item which is invalid */
|
73 |
+
$title = sprintf( __( '%s (Invalid)' ), $item->title );
|
74 |
+
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
75 |
+
$classes[] = 'pending';
|
76 |
+
/* translators: %s: title of menu item in draft status */
|
77 |
+
$title = sprintf( __('%s (Pending)'), $item->title );
|
78 |
+
}
|
79 |
+
|
80 |
+
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
81 |
+
|
82 |
+
$submenu_text = '';
|
83 |
+
if ( 0 == $depth )
|
84 |
+
$submenu_text = 'style="display: none;"';
|
85 |
+
|
86 |
+
?>
|
87 |
+
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
|
88 |
+
<div class="menu-item-bar">
|
89 |
+
<div class="menu-item-handle">
|
90 |
+
<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
|
91 |
+
<span class="item-controls">
|
92 |
+
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
93 |
+
<span class="item-order hide-if-js">
|
94 |
+
<a href="<?php
|
95 |
+
echo wp_nonce_url(
|
96 |
+
add_query_arg(
|
97 |
+
array(
|
98 |
+
'action' => 'move-up-menu-item',
|
99 |
+
'menu-item' => $item_id,
|
100 |
+
),
|
101 |
+
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
102 |
+
),
|
103 |
+
'move-menu_item'
|
104 |
+
);
|
105 |
+
?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up' ) ?>">↑</a>
|
106 |
+
|
|
107 |
+
<a href="<?php
|
108 |
+
echo wp_nonce_url(
|
109 |
+
add_query_arg(
|
110 |
+
array(
|
111 |
+
'action' => 'move-down-menu-item',
|
112 |
+
'menu-item' => $item_id,
|
113 |
+
),
|
114 |
+
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
115 |
+
),
|
116 |
+
'move-menu_item'
|
117 |
+
);
|
118 |
+
?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down' ) ?>">↓</a>
|
119 |
+
</span>
|
120 |
+
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
|
121 |
+
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
|
122 |
+
?>" aria-label="<?php esc_attr_e( 'Edit menu item' ); ?>"><?php _e( 'Edit' ); ?></a>
|
123 |
+
</span>
|
124 |
+
</div>
|
125 |
+
</div>
|
126 |
+
|
127 |
+
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
|
128 |
+
<?php if ( 'custom' == $item->type ) : ?>
|
129 |
+
<p class="field-url description description-wide">
|
130 |
+
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
131 |
+
<?php _e( 'URL' ); ?><br />
|
132 |
+
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
|
133 |
+
</label>
|
134 |
+
</p>
|
135 |
+
<?php endif; ?>
|
136 |
+
<p class="description description-wide">
|
137 |
+
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
138 |
+
<?php _e( 'Navigation Label' ); ?><br />
|
139 |
+
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
|
140 |
+
</label>
|
141 |
+
</p>
|
142 |
+
|
143 |
+
<?php
|
144 |
+
/**
|
145 |
+
* This action allows easily extending the admin menu walker class in a useful manner without conflicting with others.
|
146 |
+
*/
|
147 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args ); ?>
|
148 |
+
|
149 |
+
<p class="field-title-attribute field-attr-title description description-wide">
|
150 |
+
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
151 |
+
<?php _e( 'Title Attribute' ); ?><br />
|
152 |
+
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
|
153 |
+
</label>
|
154 |
+
</p>
|
155 |
+
<p class="field-link-target description">
|
156 |
+
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
157 |
+
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
|
158 |
+
<?php _e( 'Open link in a new tab' ); ?>
|
159 |
+
</label>
|
160 |
+
</p>
|
161 |
+
<p class="field-css-classes description description-thin">
|
162 |
+
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
163 |
+
<?php _e( 'CSS Classes (optional)' ); ?><br />
|
164 |
+
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
|
165 |
+
</label>
|
166 |
+
</p>
|
167 |
+
<p class="field-xfn description description-thin">
|
168 |
+
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
169 |
+
<?php _e( 'Link Relationship (XFN)' ); ?><br />
|
170 |
+
<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 ); ?>" />
|
171 |
+
</label>
|
172 |
+
</p>
|
173 |
+
<p class="field-description description description-wide">
|
174 |
+
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
175 |
+
<?php _e( 'Description' ); ?><br />
|
176 |
+
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
|
177 |
+
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
|
178 |
+
</label>
|
179 |
+
</p>
|
180 |
+
|
181 |
+
<p class="field-move hide-if-no-js description description-wide">
|
182 |
+
<label>
|
183 |
+
<span><?php _e( 'Move' ); ?></span>
|
184 |
+
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a>
|
185 |
+
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a>
|
186 |
+
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
187 |
+
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
188 |
+
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a>
|
189 |
+
</label>
|
190 |
+
</p>
|
191 |
+
|
192 |
+
<div class="menu-item-actions description-wide submitbox">
|
193 |
+
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
|
194 |
+
<p class="link-to-original">
|
195 |
+
<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
196 |
+
</p>
|
197 |
+
<?php endif; ?>
|
198 |
+
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
|
199 |
+
echo wp_nonce_url(
|
200 |
+
add_query_arg(
|
201 |
+
array(
|
202 |
+
'action' => 'delete-menu-item',
|
203 |
+
'menu-item' => $item_id,
|
204 |
+
),
|
205 |
+
admin_url( 'nav-menus.php' )
|
206 |
+
),
|
207 |
+
'delete-menu_item_' . $item_id
|
208 |
+
); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
|
209 |
+
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
|
210 |
+
</div>
|
211 |
+
|
212 |
+
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
213 |
+
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
|
214 |
+
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
215 |
+
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
|
216 |
+
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
217 |
+
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
218 |
+
</div><!-- .menu-item-settings-->
|
219 |
+
<ul class="menu-item-transport"></ul>
|
220 |
+
<?php
|
221 |
+
$output .= ob_get_clean();
|
222 |
+
}
|
223 |
+
|
224 |
+
}
|
index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
languages/user-menus.pot
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2016 user-menus
|
2 |
+
# This file is distributed under the same license as the user-menus package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: user-menus\n"
|
6 |
+
"Report-Msgid-Bugs-To: danieliser@wizardinternetsolutions.com\n"
|
7 |
+
"MIME-Version: 1.0\n"
|
8 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
9 |
+
"Content-Transfer-Encoding: 8bit\n"
|
10 |
+
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
|
11 |
+
"Language-Team: Daniel Iser <danieliser@wizardinternetsolutions.com>\n"
|
12 |
+
"X-Poedit-Basepath: ..\n"
|
13 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
14 |
+
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
|
15 |
+
"X-Poedit-SearchPath-0: .\n"
|
16 |
+
"X-Poedit-SearchPathExcluded-0: *.js\n"
|
17 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n\n"
|
18 |
+
|
19 |
+
#: includes/classes/admin/menu-editor.php:47
|
20 |
+
msgid "User Links"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: includes/classes/admin/menu-editor.php:59
|
24 |
+
msgid "Login"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#: includes/classes/admin/menu-editor.php:63
|
28 |
+
msgid "Logout"
|
29 |
+
msgstr ""
|
30 |
+
|
31 |
+
#: includes/classes/admin/menu-editor.php:154
|
32 |
+
msgid "Insert User Menu Codes"
|
33 |
+
msgstr ""
|
34 |
+
|
35 |
+
#: includes/classes/admin/menu-importer.php:42
|
36 |
+
msgid "WP Nav Menus"
|
37 |
+
msgstr ""
|
38 |
+
|
39 |
+
#: includes/classes/admin/menu-importer.php:43
|
40 |
+
msgid "Import nav menus and other menu item meta skipped by the default importer"
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
#: includes/classes/admin/menu-settings.php:39
|
44 |
+
msgid "Current Page"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: includes/classes/admin/menu-settings.php:40
|
48 |
+
msgid "Home Page"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: includes/classes/admin/menu-settings.php:41
|
52 |
+
msgid "Custom URL"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: includes/classes/admin/menu-settings.php:48
|
56 |
+
msgid "Where should users be taken afterwards?"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: includes/classes/admin/menu-settings.php:66
|
60 |
+
msgid "Enter a url user should be redirected to"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: includes/classes/admin/menu-settings.php:77
|
64 |
+
msgid "Everyone"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: includes/classes/admin/menu-settings.php:78
|
68 |
+
msgid "Logged Out Users"
|
69 |
+
msgstr ""
|
70 |
+
|
71 |
+
#: includes/classes/admin/menu-settings.php:79
|
72 |
+
msgid "Logged In Users"
|
73 |
+
msgstr ""
|
74 |
+
|
75 |
+
#: includes/classes/admin/menu-settings.php:86
|
76 |
+
msgid "Who can see this link?"
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#: includes/classes/admin/menu-settings.php:102
|
80 |
+
msgid "Choose which roles can see this link"
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#: includes/classes/importer/menu.php:97
|
84 |
+
msgid "Import Nav Menus"
|
85 |
+
msgstr ""
|
86 |
+
|
87 |
+
#: includes/classes/importer/menu.php:104
|
88 |
+
msgid "A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files."
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: includes/classes/importer/menu.php:114
|
92 |
+
msgid "Upload your WordPress export (WXR) file and import the Nav Menus and any meta for the Nav Menu items."
|
93 |
+
msgstr ""
|
94 |
+
|
95 |
+
#: includes/classes/importer/menu.php:115
|
96 |
+
msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
|
97 |
+
msgstr ""
|
98 |
+
|
99 |
+
#: includes/classes/importer/menu.php:130, includes/classes/importer/menu.php:135, includes/classes/importer/menu.php:145, includes/classes/importer/menu.php:206, includes/classes/importer/menu.php:217
|
100 |
+
msgid "Sorry, there has been an error."
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
#: includes/classes/importer/menu.php:136
|
104 |
+
msgid "The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem."
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#: includes/classes/importer/menu.php:154
|
108 |
+
msgid "This WXR file (version %s) may not be supported by this version of the importer. Please consider updating."
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#: includes/classes/importer/menu.php:207
|
112 |
+
msgid "The file does not exist, please try again."
|
113 |
+
msgstr ""
|
114 |
+
|
115 |
+
#: includes/classes/importer/menu.php:278
|
116 |
+
msgid "All done."
|
117 |
+
msgstr ""
|
118 |
+
|
119 |
+
#: includes/classes/importer/menu.php:278
|
120 |
+
msgid "Have fun!"
|
121 |
+
msgstr ""
|
122 |
+
|
123 |
+
#: includes/classes/menu/items.php:39
|
124 |
+
msgid "User Link"
|
125 |
+
msgstr ""
|
126 |
+
|
127 |
+
#: user-menus.php:171
|
128 |
+
msgid "The %4$s %1$s %5$s plugin requires %2$s version %3$s or greater."
|
129 |
+
msgstr ""
|
130 |
+
|
131 |
+
#: user-menus.php:173
|
132 |
+
msgid "Plugin Activation Error"
|
133 |
+
msgstr ""
|
readme.txt
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== User Menus ===
|
2 |
+
Contributors: jungleplugins, danieliser
|
3 |
+
Author URI: http://jungleplugins.com/
|
4 |
+
Plugin URI: https://wordpress.org/plugins/user-menus/
|
5 |
+
Donate link: http://jungleplugins.com/donate/
|
6 |
+
Tags: menu, menus, user-menu, logout, nav-menu, nav-menus, user, user-role, user-roles
|
7 |
+
Requires at least: 3.6
|
8 |
+
Tested up to: 4.6
|
9 |
+
Stable tag: 1.0.0
|
10 |
+
Minimum PHP: 5.3
|
11 |
+
License: GNU Version 3 or Any Later Version
|
12 |
+
|
13 |
+
Show/hide menu items to logged in users, logged out users or specific user roles. Display logged in user details in menu. Add a logout link to menu.
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
== Description ==
|
20 |
+
|
21 |
+
User Menus by [Jungle Plugins][jungleplugins] is the perfect plugin for websites which have logged in users.
|
22 |
+
|
23 |
+
The plugin gives you more control over your nav menu by allowing you to apply visibility controls to menu items e.g who can see each menu item (everyone, logged out users, logged in users, specific user roles).
|
24 |
+
|
25 |
+
It also enables you to display logged in user information in the navigation menu e.g “Hello, John Doe”.
|
26 |
+
|
27 |
+
Lastly, the plugin allows you to add a login and logout link to your menu.
|
28 |
+
|
29 |
+
= Full Feature List =
|
30 |
+
|
31 |
+
User Menus allows you to do the following:
|
32 |
+
|
33 |
+
* Display menu items to everyone
|
34 |
+
* Display menu items to only logged out users
|
35 |
+
* Display menu items to only logged in users
|
36 |
+
* Display menu item to specific user roles
|
37 |
+
* Show a logged in user’s {username} in a menu item
|
38 |
+
* Show a logged in user’s {first_name} in a menu item
|
39 |
+
* Show a logged in user’s {last_name} in a menu item
|
40 |
+
* Show a logged in user’s {display_name} in a menu item
|
41 |
+
* Show a logged in user’s nickname} in a menu item
|
42 |
+
* Show a logged in user’s {email} in a menu item
|
43 |
+
* Add a logout link to menu (optional redirect settings)
|
44 |
+
* Add a login link to menu (optional redirect settings)
|
45 |
+
|
46 |
+
= Created by Jungle Plugins =
|
47 |
+
|
48 |
+
User Menus is built by the [Jungle Plugins][jungleplugins] team. Our mission is to make building membership & community websites easy with WordPress.
|
49 |
+
|
50 |
+
Whilst User Menus is currently our only plugin, we will be releasing several free & paid plugins over the coming months which will provide the following functionality:
|
51 |
+
|
52 |
+
* Forums
|
53 |
+
* Front-end Posting
|
54 |
+
* User Role Creation and Editing
|
55 |
+
* Content Restriction
|
56 |
+
|
57 |
+
If you’d like to get updates on our plugin development work you can [subscribe to our mailing list][jungleplugins subscribe] and/or follow us on [Twitter][jungleplugins twitter].
|
58 |
+
|
59 |
+
**Requires WordPress 3.6 and PHP 5.3**
|
60 |
+
|
61 |
+
[jungleplugins]: https://jungleplugins.com/ "Jungle Plugins - WordPress User Communities Made Easy"
|
62 |
+
|
63 |
+
[jungleplugins subscribe]: https://jungleplugins.com/subscribe/ "Jungle Plugins Newsletter"
|
64 |
+
|
65 |
+
[jungleplugins twitter]: https://twitter.com/jungleplugins/ "Jungle Plugins on Twitter"
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
== Installation ==
|
72 |
+
|
73 |
+
= Minimum Requirements =
|
74 |
+
|
75 |
+
* WordPress 3.6 or greater
|
76 |
+
* PHP version 5.3 or greater
|
77 |
+
|
78 |
+
= Installation =
|
79 |
+
|
80 |
+
* Install User Menus either via the WordPress.org plugin repository or by uploading the files to your server.
|
81 |
+
* Activate User Menus.
|
82 |
+
* Go to wp-admin > Appearance > Menus and edit your menu
|
83 |
+
|
84 |
+
If you need help getting started with User Menus please see [FAQs][faq page] which explains how to use the plugin.
|
85 |
+
|
86 |
+
|
87 |
+
[faq page]: https://wordpress.org/plugins/user-menus/faq/ "User Menus FAQ"
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
== Frequently Asked Questions ==
|
93 |
+
|
94 |
+
= How do I setup this plugin? =
|
95 |
+
|
96 |
+
* To setup the plugin, go to wp-admin > appearance > menu
|
97 |
+
* Once a menu item has been added to the menu, expand the menu item and select which user group (everyone (default option), logged out users, logged in users (all logged in users or select specific user roles) can see the menu item
|
98 |
+
* To show a logged in user’s information in a menu item, make a menu item only visible to logged in users and then click the grey arrow button to add a user tag (username, first_name, last_name, nickname, display_name, email) to the menu item label.
|
99 |
+
* To add a logout/login link to menu, expand the "User Links" menu item type and then add the logout and/or login link to the menu.
|
100 |
+
|
101 |
+
= Where can I get support? =
|
102 |
+
|
103 |
+
If you get stuck, you can ask for help in the [User Menu Plugin Forum][support forum].
|
104 |
+
|
105 |
+
= Where can I report bugs or contribute to the project? =
|
106 |
+
|
107 |
+
Bugs can be reported either in our support forum or preferably on the [User Menu GitHub][github issues] repository (link to GitHub repo).
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
[github issues]: https://github.com/jungleplugins/user-menus/issues "GitHub Issue tracker for User Menus by Jungle Plugins"
|
112 |
+
|
113 |
+
[support forum]: http://wordpress.org/support/plugin/user-menus "User Menu Plugin Forum"
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
== Screenshots ==
|
120 |
+
|
121 |
+
1. Limit menu item visibility based on logged in status, user role etc.
|
122 |
+
2. Display user information such as username, first name etc in your menu text.
|
123 |
+
3. Quickly insert login/logout links & choose where users will be taken afterwards.
|
124 |
+
|
125 |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I: https://wordpress.org/plugins/user-menus/
|
5 |
+
* Description: Quickly customize & extend your menus with user based functionality.
|
6 |
+
* Version: 1.0.0
|
7 |
+
* Author: Jungle Plugins
|
8 |
+
* Author URI: https://jungleplugins.com/
|
9 |
+
* Text Domain: user-menus
|
10 |
+
*
|
11 |
+
* Minimum PHP: 5.3
|
12 |
+
* Minimum WP: 3.6
|
13 |
+
*
|
14 |
+
* @author Daniel Iser
|
15 |
+
* @copyright Copyright (c) 2016, Jungle Plugins
|
16 |
+
* @since 1.0.0
|
17 |
+
*
|
18 |
+
* Prior Work Credits. Big thanks to the following:
|
19 |
+
* - No Conflict Nav Menu Walker (Modified) - Nav Menu Roles @helgatheviking
|
20 |
+
* - Menu Importer (Modified) - Kathy Darling
|
21 |
+
*/
|
22 |
+
|
23 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
24 |
+
exit;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Class JP_User_Menus
|
29 |
+
*/
|
30 |
+
class JP_User_Menus {
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
public static $NAME = 'User Menus';
|
36 |
+
|
37 |
+
/**
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
public static $VER = '1.0.0';
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @var string
|
44 |
+
*/
|
45 |
+
public static $MIN_PHP_VER = '5.3';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var string
|
49 |
+
*/
|
50 |
+
public static $MIN_WP_VER = '3.6';
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var string
|
54 |
+
*/
|
55 |
+
public static $URL = '';
|
56 |
+
/**
|
57 |
+
* @var string
|
58 |
+
*/
|
59 |
+
public static $DIR = '';
|
60 |
+
/**
|
61 |
+
* @var string
|
62 |
+
*/
|
63 |
+
public static $FILE = '';
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @var string
|
67 |
+
*/
|
68 |
+
public static $TEMPLATE_PATH = 'jp/user-menus/';
|
69 |
+
|
70 |
+
/**
|
71 |
+
* @var string
|
72 |
+
*/
|
73 |
+
public static $TD = 'user-menus';
|
74 |
+
/**
|
75 |
+
* @var JP_User_Menus $instance The one true JP_User_Menus
|
76 |
+
* @since 1.0.0
|
77 |
+
*/
|
78 |
+
private static $instance;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Get active instance
|
82 |
+
*
|
83 |
+
* @access public
|
84 |
+
* @since 1.0.0
|
85 |
+
* @return object self::$instance The one true JP_User_Menus
|
86 |
+
*/
|
87 |
+
public static function instance() {
|
88 |
+
if ( ! self::$instance ) {
|
89 |
+
self::$instance = new static;
|
90 |
+
self::$instance->setup_constants();
|
91 |
+
|
92 |
+
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
|
93 |
+
|
94 |
+
self::$instance->includes();
|
95 |
+
}
|
96 |
+
|
97 |
+
return self::$instance;
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Setup plugin constants
|
102 |
+
*
|
103 |
+
* @access private
|
104 |
+
* @since 1.0.0
|
105 |
+
* @return void
|
106 |
+
*/
|
107 |
+
private function setup_constants() {
|
108 |
+
static::$DIR = self::$instance->plugin_path();
|
109 |
+
static::$URL = self::$instance->plugin_url();
|
110 |
+
static::$FILE = __FILE__;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Include necessary files
|
115 |
+
*
|
116 |
+
* @access private
|
117 |
+
* @since 1.0.0
|
118 |
+
* @return void
|
119 |
+
*/
|
120 |
+
private function includes() {
|
121 |
+
// Menu Items
|
122 |
+
require_once static::$DIR . 'includes/classes/menu/item.php';
|
123 |
+
require_once static::$DIR . 'includes/classes/menu/items.php';
|
124 |
+
require_once static::$DIR . 'includes/classes/user/codes.php';
|
125 |
+
if ( is_admin() ) {
|
126 |
+
// Admin Menu Editor
|
127 |
+
require_once static::$DIR . 'includes/classes/admin/menu-editor.php';
|
128 |
+
require_once static::$DIR . 'includes/classes/admin/menu-settings.php';
|
129 |
+
require_once static::$DIR . 'includes/classes/admin/menu-importer.php';
|
130 |
+
} else {
|
131 |
+
// Site Menu Filter
|
132 |
+
require_once static::$DIR . 'includes/classes/site/menus.php';
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Get the plugin path.
|
138 |
+
* @return string
|
139 |
+
*/
|
140 |
+
public function plugin_path() {
|
141 |
+
return plugin_dir_path( __FILE__ );
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Get the plugin url.
|
146 |
+
* @return string
|
147 |
+
*/
|
148 |
+
public function plugin_url() {
|
149 |
+
return plugins_url( '/', __FILE__ );
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Plugin Activation hook function to check for Minimum PHP and WordPress versions
|
154 |
+
*/
|
155 |
+
public static function activation_check() {
|
156 |
+
global $wp_version;
|
157 |
+
|
158 |
+
if ( version_compare( PHP_VERSION, static::$MIN_PHP_VER, '<' ) ) {
|
159 |
+
$flag = 'PHP';
|
160 |
+
} elseif ( version_compare( $wp_version, static::$MIN_WP_VER, '<' ) ) {
|
161 |
+
$flag = 'WordPress';
|
162 |
+
} else {
|
163 |
+
return;
|
164 |
+
}
|
165 |
+
|
166 |
+
$version = 'PHP' == $flag ? static::$MIN_PHP_VER : static::$MIN_WP_VER;
|
167 |
+
|
168 |
+
// Deactivate automatically due to insufficient PHP or WP Version.
|
169 |
+
deactivate_plugins( basename( __FILE__ ) );
|
170 |
+
|
171 |
+
$notice = sprintf( __( 'The %4$s %1$s %5$s plugin requires %2$s version %3$s or greater.', 'user-menus' ), static::$NAME, $flag, $version, "<strong>", "</strong>" );
|
172 |
+
|
173 |
+
wp_die( "<p>$notice</p>", __( 'Plugin Activation Error', 'user-menus' ), array( 'response' => 200, 'back_link' => true, ) );
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Internationalization
|
178 |
+
*
|
179 |
+
* @access public
|
180 |
+
* @since 1.0.0
|
181 |
+
* @return void
|
182 |
+
*/
|
183 |
+
public function load_textdomain() {
|
184 |
+
load_plugin_textdomain( 'user-menus' );
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Get the template path.
|
189 |
+
* @return string
|
190 |
+
*/
|
191 |
+
public function template_path() {
|
192 |
+
return apply_filters( 'jpum_template_path', static::$TEMPLATE_PATH );
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Get Ajax URL.
|
197 |
+
* @return string
|
198 |
+
*/
|
199 |
+
public function ajax_url() {
|
200 |
+
return admin_url( 'admin-ajax.php', 'relative' );
|
201 |
+
}
|
202 |
+
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* @return object
|
207 |
+
*/
|
208 |
+
function jp_user_menus() {
|
209 |
+
return JP_User_Menus::instance();
|
210 |
+
}
|
211 |
+
|
212 |
+
jp_user_menus();
|
213 |
+
|
214 |
+
// Ensure plugin & environment compatibility.
|
215 |
+
register_activation_hook( __FILE__, array( 'JP_User_Menus', 'activation_check' ) );
|