Version Description
- New: Customizer support! props @westonruter!
Download this release
Release Info
Developer | helgatheviking |
Plugin | Nav Menu Roles |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.10.2 to 2.0.0
- dist/js/customize.js +2 -0
- dist/js/customize.js.map +1 -0
- dist/js/roles.js +2 -0
- dist/js/roles.js.map +1 -0
- inc/class-nav-menu-roles-import.php +319 -0
- inc/class-walker-nav-menu-edit-roles-4.5.php +267 -0
- inc/class-walker-nav-menu-edit-roles-4.7.php +71 -0
- inc/class-walker-nav-menu-edit-roles.php +274 -0
- inc/class.Nav_Menu_Roles_Import.php +0 -308
- inc/class.Walker_Nav_Menu_Edit_Roles.php +0 -245
- inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php +0 -248
- inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php +0 -69
- inc/customizer.php +179 -0
- js/nav-menu-roles.js +0 -27
- js/nav-menu-roles.min.js +0 -2
- languages/nav-menu-roles.pot +97 -89
- nav-menu-roles.php +277 -245
- readme.txt +20 -9
dist/js/customize.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
!function(e){var n={};function t(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:i})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(i,o,function(n){return e[n]}.bind(null,o));return i},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n){!function(e){function n(e,n){e.set(Object.assign({},_.clone(e()),{roles:n}))}function t(e){var n=e.setting().roles||"",t=_.isArray(n)?"in":n,i=_.isArray(n)?n:[];e.rolesFieldset.toggle("in"===t),e.authFieldset.find('input[type = radio][value = "'.concat(t,'"]')).prop("checked",!0),e.rolesFieldset.find("input[type=checkbox]").each((function(){this.checked=i.includes(this.value)}))}e.control.bind("add",(function(i){i.extended(e.Menus.MenuItemControl)&&i.deferred.embedded.done((function(){!function(e){e.authFieldset=e.container.find(".nav_menu_role_authentication"),e.rolesFieldset=e.container.find(".nav_menu_roles"),t(e),e.setting.bind((function(){t(e)})),e.authFieldset.find("input").on("click",(function(){n(e.setting,this.value)})),e.rolesFieldset.find("input").on("click",(function(){var t=[];e.rolesFieldset.find(":checked").each((function(){t.push(this.value)})),n(e.setting,0===t.length?"in":t)}))}(i)}))}))}(wp.customize)}]);
|
2 |
+
//# sourceMappingURL=customize.js.map
|
dist/js/customize.js.map
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/js/nav-menu-roles-customize-controls.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","api","setSettingRoles","setting","roles","set","assign","_","clone","updateControlFields","control","radioValue","isArray","checkedRoles","rolesFieldset","toggle","authFieldset","find","prop","each","this","checked","includes","extended","Menus","MenuItemControl","deferred","embedded","done","container","on","push","length","extendControl","wp","customize"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQC,KAAK,KAAMD,IAC9I,OAAOF,GAIRzB,EAAoB6B,EAAI,SAAS1B,GAChC,IAAIS,EAAST,GAAUA,EAAOqB,WAC7B,WAAwB,OAAOrB,EAAgB,SAC/C,WAA8B,OAAOA,GAEtC,OADAH,EAAoBU,EAAEE,EAAQ,IAAKA,GAC5BA,GAIRZ,EAAoBa,EAAI,SAASiB,EAAQC,GAAY,OAAOjB,OAAOkB,UAAUC,eAAe1B,KAAKuB,EAAQC,IAGzG/B,EAAoBkC,EAAI,GAIjBlC,EAAoBA,EAAoBmC,EAAI,G,iBC5ErD,SAAaC,GA8DZ,SAASC,EAAiBC,EAASC,GAClCD,EAAQE,IACP1B,OAAO2B,OACN,GACAC,EAAEC,MAAOL,KACT,CAAEC,WAUL,SAASK,EAAqBC,GAC7B,IAAMN,EAAQM,EAAQP,UAAUC,OAAS,GAEnCO,EAAeJ,EAAEK,QAASR,GAAU,KAAOA,EAC3CS,EAAeN,EAAEK,QAASR,GAAUA,EAAQ,GAElDM,EAAQI,cAAcC,OAAQ,OAASJ,GAErBD,EAAQM,aAAaC,KAArB,uCAA4DN,EAA5D,OAERO,KAAM,WAAW,GAE3BR,EAAQI,cAAcG,KAAM,wBAAyBE,MACpD,WACCC,KAAKC,QAAUR,EAAaS,SAAUF,KAAKlC,UAxF9Ce,EAAIS,QAAQjB,KACX,OACA,SAAEiB,GACIA,EAAQa,SAAUtB,EAAIuB,MAAMC,kBAChCf,EAAQgB,SAASC,SAASC,MAC1B,YAaH,SAAwBlB,GACvBA,EAAQM,aAAgBN,EAAQmB,UAAUZ,KAAM,iCAChDP,EAAQI,cAAgBJ,EAAQmB,UAAUZ,KAAM,mBAGhDR,EAAqBC,GAGrBA,EAAQP,QAAQV,MACf,WACCgB,EAAqBC,MAKvBA,EAAQM,aAAaC,KAAM,SAAUa,GACpC,SACA,WACC5B,EAAiBQ,EAAQP,QAASiB,KAAKlC,UAGzCwB,EAAQI,cAAcG,KAAM,SAAUa,GACrC,SACA,WACC,IAAMjB,EAAe,GACrBH,EAAQI,cAAcG,KAAM,YAAaE,MACxC,WACCN,EAAakB,KAAMX,KAAKlC,UAG1BgB,EAAiBQ,EAAQP,QAAiC,IAAxBU,EAAamB,OAAe,KAAOnB,MA1CpEoB,CAAevB,SATpB,CA+FIwB,GAAGC","file":"customize.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/**\r\n * Customizer scripts.\r\n *\r\n * @package Nav Menu Roles\r\n */\r\n\r\n( function ( api ) {\r\n\r\n\t// Augment each menu item control once it is added and embedded.\r\n\tapi.control.bind(\r\n\t\t'add',\r\n\t\t( control ) => {\r\n\t\t\tif ( control.extended( api.Menus.MenuItemControl ) ) {\r\n\t\t\t\tcontrol.deferred.embedded.done(\r\n\t\t\t\t() => {\r\n\t\t\t\t\textendControl( control );\r\n\t\t\t\t\t}\r\n\t\t\t\t);\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n\r\n\t/**\r\n\t * Extend the control with roles information.\r\n\t *\r\n\t * @param {wp.customize.Menus.MenuItemControl} control\r\n\t */\r\n\tfunction extendControl( control ) {\r\n\t\tcontrol.authFieldset = control.container.find( '.nav_menu_role_authentication' );\r\n\t\tcontrol.rolesFieldset = control.container.find( '.nav_menu_roles' );\r\n\r\n\t\t// Set the initial UI state.\r\n\t\tupdateControlFields( control );\r\n\r\n\t\t// Update the UI state when the setting changes programmatically.\r\n\t\tcontrol.setting.bind(\r\n\t\t\t() => {\r\n\t\t\t\tupdateControlFields( control );\r\n\t\t\t}\r\n\t\t);\r\n\r\n\t\t// Update the setting when the inputs are modified.\r\n\t\tcontrol.authFieldset.find( 'input' ).on(\r\n\t\t\t'click',\r\n\t\t\tfunction () {\r\n\t\t\t\tsetSettingRoles( control.setting, this.value );\r\n\t\t\t}\r\n\t\t);\r\n\t\tcontrol.rolesFieldset.find( 'input' ).on(\r\n\t\t\t'click',\r\n\t\t\tfunction () {\r\n\t\t\t\tconst checkedRoles = [];\r\n\t\t\t\tcontrol.rolesFieldset.find( ':checked' ).each(\r\n\t\t\t\t\tfunction () {\r\n\t\t\t\t\t\tcheckedRoles.push( this.value );\r\n\t\t\t\t\t}\r\n\t\t\t\t);\r\n\t\t\t\tsetSettingRoles( control.setting, checkedRoles.length === 0 ? 'in' : checkedRoles );\r\n\t\t\t}\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Extend the setting with roles information.\r\n\t *\r\n\t * @param {wp.customize.Setting} setting\r\n\t * @param {string|Array} roles\r\n\t */\r\n\tfunction setSettingRoles( setting, roles ) {\r\n\t\tsetting.set(\r\n\t\t\tObject.assign(\r\n\t\t\t\t{},\r\n\t\t\t\t_.clone( setting() ),\r\n\t\t\t\t{ roles }\r\n\t\t\t)\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Apply the control's setting value to the control's fields.\r\n\t *\r\n\t * @param {wp.customize.Menus.MenuItemControl} control\r\n\t */\r\n\tfunction updateControlFields( control ) {\r\n\t\tconst roles = control.setting().roles || '';\r\n\r\n\t\tconst radioValue = _.isArray( roles ) ? 'in' : roles;\r\n\t\tconst checkedRoles = _.isArray( roles ) ? roles : [];\r\n\r\n\t\tcontrol.rolesFieldset.toggle( 'in' === radioValue );\r\n\r\n\t\tconst authRadio = control.authFieldset.find( `input[type = radio][value = \"${ radioValue }\"]` );\r\n\r\n\t\tauthRadio.prop( 'checked', true );\r\n\r\n\t\tcontrol.rolesFieldset.find( 'input[type=checkbox]' ).each(\r\n\t\t\tfunction () {\r\n\t\t\t\tthis.checked = checkedRoles.includes( this.value );\r\n\t\t\t}\r\n\t\t);\r\n\t}\r\n})( wp.customize );\r\n"],"sourceRoot":""}
|
dist/js/roles.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
!function(e){var n={};function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:o})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)t.d(o,r,function(n){return e[n]}.bind(null,r));return o},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=1)}([,function(e,n){var t;(t=jQuery)(".nav_menu_logged_in_out_field").each((function(e){var n=t(this);n.find("input.nav-menu-id").val(),"in"===n.find("input.nav-menu-logged-in-out:checked").val()?n.next(".nav_menu_role_field").show():n.next(".nav_menu_role_field").hide()})),t("#menu-to-edit").on("change","input.nav-menu-logged-in-out",(function(){"in"===t(this).val()?t(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideDown():t(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideUp()}))}]);
|
2 |
+
//# sourceMappingURL=roles.js.map
|
dist/js/roles.js.map
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/js/nav-menu-roles.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","$","jQuery","each","$field","this","find","val","next","show","hide","on","parentsUntil","slideDown","slideUp"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQC,KAAK,KAAMD,IAC9I,OAAOF,GAIRzB,EAAoB6B,EAAI,SAAS1B,GAChC,IAAIS,EAAST,GAAUA,EAAOqB,WAC7B,WAAwB,OAAOrB,EAAgB,SAC/C,WAA8B,OAAOA,GAEtC,OADAH,EAAoBU,EAAEE,EAAQ,IAAKA,GAC5BA,GAIRZ,EAAoBa,EAAI,SAASiB,EAAQC,GAAY,OAAOjB,OAAOkB,UAAUC,eAAe1B,KAAKuB,EAAQC,IAGzG/B,EAAoBkC,EAAI,GAIjBlC,EAAoBA,EAAoBmC,EAAI,G,iBC7ErD,IAAUC,KA+BNC,QA7BA,iCAAkCC,MACpC,SAASlC,GAER,IAAImC,EAASH,EAAGI,MAEPD,EAAOE,KAAM,qBAAsBC,MAGyB,OAAhEH,EAAOE,KAAM,wCAAyCC,MAC1DH,EAAOI,KAAM,wBAAyBC,OAEtCL,EAAOI,KAAM,wBAAyBE,UAMzCT,EAAG,iBAAkBU,GACpB,SACA,gCACA,WAC0B,OAApBV,EAAGI,MAAOE,MACdN,EAAGI,MAAOO,aAAc,2BAA4BJ,KAAM,wBAAyBK,YAEnFZ,EAAGI,MAAOO,aAAc,2BAA4BJ,KAAM,wBAAyBM","file":"roles.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","/**\r\n * Admin menu scripts.\r\n *\r\n * @package Nav Menu Roles\r\n */\r\n(function($) {\r\n\r\n\t$( '.nav_menu_logged_in_out_field' ).each(\r\n\t\tfunction(i) {\r\n\r\n\t\t\tvar $field = $( this );\r\n\r\n\t\t\tvar id = $field.find( 'input.nav-menu-id' ).val();\r\n\r\n\t\t\t// if set to display by role (aka is null) then show the roles list, otherwise hide\r\n\t\t\tif ( $field.find( 'input.nav-menu-logged-in-out:checked' ).val() === 'in' ) {\r\n\t\t\t\t$field.next( '.nav_menu_role_field' ).show();\r\n\t\t\t} else {\r\n\t\t\t\t$field.next( '.nav_menu_role_field' ).hide();\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n\r\n\t// on in/out/role change, hide/show the roles\r\n\t$( '#menu-to-edit' ).on(\r\n\t\t'change',\r\n\t\t'input.nav-menu-logged-in-out',\r\n\t\tfunction() {\r\n\t\t\tif ( $( this ).val() === 'in' ) {\r\n\t\t\t\t$( this ).parentsUntil( '.nav_menu_logged_in_out' ).next( '.nav_menu_role_field' ).slideDown();\r\n\t\t\t} else {\r\n\t\t\t\t$( this ).parentsUntil( '.nav_menu_logged_in_out' ).next( '.nav_menu_role_field' ).slideUp();\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n\r\n})( jQuery );\r\n"],"sourceRoot":""}
|
inc/class-nav-menu-roles-import.php
ADDED
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Nav Menu Roles Importer - import menu item meta
|
4 |
+
*
|
5 |
+
* Create HTML list of nav menu input items.
|
6 |
+
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
|
7 |
+
*
|
8 |
+
* @package Nav Menu Roles\Classes
|
9 |
+
* @since 1.3
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
|
13 |
+
// Exit if accessed directly
|
14 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
15 |
+
exit;
|
16 |
+
}
|
17 |
+
|
18 |
+
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
|
19 |
+
return;
|
20 |
+
}
|
21 |
+
|
22 |
+
/** Display verbose errors */
|
23 |
+
if ( ! defined( 'IMPORT_DEBUG' ) ) {
|
24 |
+
define( 'IMPORT_DEBUG', false );
|
25 |
+
}
|
26 |
+
|
27 |
+
// Load Importer API
|
28 |
+
require_once ABSPATH . 'wp-admin/includes/import.php';
|
29 |
+
|
30 |
+
if ( ! class_exists( 'WP_Importer' ) ) {
|
31 |
+
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
32 |
+
if ( file_exists( $class_wp_importer ) ) {
|
33 |
+
require $class_wp_importer;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Nav Menu Roles Importer class
|
39 |
+
*/
|
40 |
+
if ( class_exists( 'WP_Importer' ) && ! class_exists( 'Nav_Menu_Roles_Import' ) ) {
|
41 |
+
class Nav_Menu_Roles_Import extends WP_Importer {
|
42 |
+
|
43 |
+
var $max_wxr_version = 1.2; // max. supported WXR version
|
44 |
+
|
45 |
+
var $id; // WXR attachment ID
|
46 |
+
|
47 |
+
// information to import from WXR file
|
48 |
+
var $version;
|
49 |
+
var $posts = array();
|
50 |
+
var $base_url = '';
|
51 |
+
|
52 |
+
|
53 |
+
/**
|
54 |
+
* __construct function.
|
55 |
+
*
|
56 |
+
* @access public
|
57 |
+
* @return void
|
58 |
+
*/
|
59 |
+
public function __construct() {
|
60 |
+
$this->import_page = 'woocommerce_tax_rate_csv';
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Registered callback function for the WordPress Importer
|
65 |
+
*
|
66 |
+
* Manages the three separate stages of the WXR import process
|
67 |
+
*/
|
68 |
+
function dispatch() {
|
69 |
+
$this->header();
|
70 |
+
|
71 |
+
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
|
72 |
+
switch ( $step ) {
|
73 |
+
case 0:
|
74 |
+
$this->greet();
|
75 |
+
break;
|
76 |
+
case 1:
|
77 |
+
check_admin_referer( 'import-upload' );
|
78 |
+
if ( $this->handle_upload() ) {
|
79 |
+
$file = get_attached_file( $this->id );
|
80 |
+
set_time_limit( 0 );
|
81 |
+
$this->import( $file );
|
82 |
+
}
|
83 |
+
break;
|
84 |
+
}
|
85 |
+
|
86 |
+
$this->footer();
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* The main controller for the actual import stage.
|
91 |
+
*
|
92 |
+
* @param string $file Path to the WXR file for importing
|
93 |
+
*/
|
94 |
+
function import( $file ) {
|
95 |
+
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
|
96 |
+
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
97 |
+
|
98 |
+
$this->import_start( $file );
|
99 |
+
|
100 |
+
wp_suspend_cache_invalidation( true );
|
101 |
+
$this->process_nav_menu_meta();
|
102 |
+
wp_suspend_cache_invalidation( false );
|
103 |
+
|
104 |
+
$this->import_end();
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Parses the WXR file and prepares us for the task of processing parsed data
|
109 |
+
*
|
110 |
+
* @param string $file Path to the WXR file for importing
|
111 |
+
*/
|
112 |
+
function import_start( $file ) {
|
113 |
+
if ( ! is_file( $file ) ) {
|
114 |
+
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
115 |
+
echo esc_html__( 'The file does not exist, please try again.', 'nav-menu-roles' ) . '</p>';
|
116 |
+
$this->footer();
|
117 |
+
die();
|
118 |
+
}
|
119 |
+
|
120 |
+
$import_data = $this->parse( $file );
|
121 |
+
|
122 |
+
if ( is_wp_error( $import_data ) ) {
|
123 |
+
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
124 |
+
echo esc_html( $import_data->get_error_message() ) . '</p>';
|
125 |
+
$this->footer();
|
126 |
+
die();
|
127 |
+
}
|
128 |
+
|
129 |
+
$this->version = $import_data['version'];
|
130 |
+
$this->posts = $import_data['posts'];
|
131 |
+
$this->base_url = esc_url( $import_data['base_url'] );
|
132 |
+
|
133 |
+
wp_defer_term_counting( true );
|
134 |
+
wp_defer_comment_counting( true );
|
135 |
+
|
136 |
+
do_action( 'import_start' );
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Performs post-import cleanup of files and the cache
|
141 |
+
*/
|
142 |
+
function import_end() {
|
143 |
+
wp_import_cleanup( $this->id );
|
144 |
+
|
145 |
+
wp_cache_flush();
|
146 |
+
foreach ( get_taxonomies() as $tax ) {
|
147 |
+
delete_option( "{$tax}_children" );
|
148 |
+
_get_term_hierarchy( $tax );
|
149 |
+
}
|
150 |
+
|
151 |
+
wp_defer_term_counting( false );
|
152 |
+
wp_defer_comment_counting( false );
|
153 |
+
|
154 |
+
echo '<p>' . esc_html__( 'All done.', 'nav-menu-roles' ) . ' <a href="' . esc_url( admin_url() ) . '">' . esc_html__( 'Have fun!', 'nav-menu-roles' ) . '</a>' . '</p>';
|
155 |
+
|
156 |
+
do_action( 'import_end' );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Handles the WXR upload and initial parsing of the file to prepare for
|
161 |
+
* displaying author import options
|
162 |
+
*
|
163 |
+
* @return bool False if error uploading or invalid file, true otherwise
|
164 |
+
*/
|
165 |
+
function handle_upload() {
|
166 |
+
$file = wp_import_handle_upload();
|
167 |
+
|
168 |
+
if ( isset( $file['error'] ) ) {
|
169 |
+
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
170 |
+
echo esc_html( $file['error'] ) . '</p>';
|
171 |
+
return false;
|
172 |
+
} elseif ( ! file_exists( $file['file'] ) ) {
|
173 |
+
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
174 |
+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
175 |
+
printf( esc_html__( 'The export file could not be found at %s. It is likely that this was caused by a permissions problem.', 'nav-menu-roles' ), '<code>' . esc_html( $file['file'] ) . '</code>' );
|
176 |
+
echo '</p>';
|
177 |
+
return false;
|
178 |
+
}
|
179 |
+
|
180 |
+
$this->id = (int) $file['id'];
|
181 |
+
$import_data = $this->parse( $file['file'] );
|
182 |
+
if ( is_wp_error( $import_data ) ) {
|
183 |
+
echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
184 |
+
echo esc_html( $import_data->get_error_message() ) . '</p>';
|
185 |
+
return false;
|
186 |
+
}
|
187 |
+
|
188 |
+
$this->version = $import_data['version'];
|
189 |
+
if ( $this->version > $this->max_wxr_version ) {
|
190 |
+
echo '<div class="error"><p><strong>';
|
191 |
+
printf( esc_html__( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'nav-menu-roles' ), esc_html( $import_data['version'] ) );
|
192 |
+
echo '</strong></p></div>';
|
193 |
+
}
|
194 |
+
|
195 |
+
return true;
|
196 |
+
}
|
197 |
+
|
198 |
+
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Create new posts based on import information
|
202 |
+
*
|
203 |
+
* Posts marked as having a parent which doesn't exist will become top level items.
|
204 |
+
* Doesn't create a new post if: the post type doesn't exist, the given post ID
|
205 |
+
* is already noted as imported or a post with the same title and date already exists.
|
206 |
+
* Note that new/updated terms, comments and meta are imported for the last of the above.
|
207 |
+
*/
|
208 |
+
function process_nav_menu_meta() {
|
209 |
+
foreach ( $this->posts as $post ) {
|
210 |
+
|
211 |
+
// we only want to deal with the nav_menu_item posts
|
212 |
+
if ( 'nav_menu_item' != $post['post_type'] || ! empty( $post['post_id'] ) ) {
|
213 |
+
continue;
|
214 |
+
}
|
215 |
+
|
216 |
+
// ok we've got a nav_menu_item
|
217 |
+
$post_id = (int) $post['post_id'];
|
218 |
+
|
219 |
+
// add/update post meta
|
220 |
+
if ( isset( $post['postmeta'] ) ) {
|
221 |
+
foreach ( $post['postmeta'] as $meta ) {
|
222 |
+
$key = apply_filters( 'import_post_meta_key', $meta['key'] );
|
223 |
+
$value = false;
|
224 |
+
|
225 |
+
if ( $key ) {
|
226 |
+
// export gets meta straight from the DB so could have a serialized string
|
227 |
+
if ( ! $value ) {
|
228 |
+
$value = maybe_unserialize( $meta['value'] );
|
229 |
+
}
|
230 |
+
|
231 |
+
update_post_meta( $post_id, $key, $value );
|
232 |
+
do_action( 'import_post_meta', $post_id, $key, $value );
|
233 |
+
|
234 |
+
}
|
235 |
+
}
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
unset( $this->posts );
|
240 |
+
}
|
241 |
+
|
242 |
+
|
243 |
+
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Parse a WXR file
|
247 |
+
*
|
248 |
+
* @param string $file Path to WXR file for parsing
|
249 |
+
* @return array Information gathered from the WXR file
|
250 |
+
*/
|
251 |
+
function parse( $file ) {
|
252 |
+
$parser = new WXR_Parser();
|
253 |
+
return $parser->parse( $file );
|
254 |
+
}
|
255 |
+
|
256 |
+
// Display import page title
|
257 |
+
function header() {
|
258 |
+
echo '<div class="wrap">';
|
259 |
+
echo '<h2>' . esc_html__( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
|
260 |
+
|
261 |
+
$updates = get_plugin_updates();
|
262 |
+
$basename = plugin_basename( __FILE__ );
|
263 |
+
if ( isset( $updates[ $basename ] ) ) {
|
264 |
+
$update = $updates[ $basename ];
|
265 |
+
echo '<div class="error"><p><strong>';
|
266 |
+
printf( esc_html__( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'nav-menu-roles' ), esc_html( $update->update->new_version ) );
|
267 |
+
echo '</strong></p></div>';
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
// Close div.wrap
|
272 |
+
function footer() {
|
273 |
+
echo '</div>';
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Display introductory text and file upload form
|
278 |
+
*/
|
279 |
+
function greet() {
|
280 |
+
echo '<div class="narrow">';
|
281 |
+
echo '<p>' . esc_html__( 'Re-Upload your normal WordPress eXtended RSS (WXR) file and we’ll import the Nav Menu Roles and any other missing post meta for the Nav Menu items.', 'nav-menu-roles' ) . '</p>';
|
282 |
+
echo '<p>' . esc_html__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ) . '</p>';
|
283 |
+
wp_import_upload_form( 'admin.php?import=nav_menu_roles&step=1' );
|
284 |
+
echo '</div>';
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Decide if the given meta key maps to information we will want to import
|
289 |
+
*
|
290 |
+
* @param string $key The meta key to check
|
291 |
+
* @return string|bool The key if we do want to import, false if not
|
292 |
+
*/
|
293 |
+
function is_valid_meta_key( $key ) {
|
294 |
+
// skip attachment metadata since we'll regenerate it from scratch
|
295 |
+
// skip _edit_lock as not relevant for import
|
296 |
+
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ), true ) ) {
|
297 |
+
return false;
|
298 |
+
}
|
299 |
+
return $key;
|
300 |
+
}
|
301 |
+
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
305 |
+
* @param int $val
|
306 |
+
* @return int
|
307 |
+
*/
|
308 |
+
public function bump_request_timeout( $val ) {
|
309 |
+
return 60;
|
310 |
+
}
|
311 |
+
|
312 |
+
// return the difference in length between two strings
|
313 |
+
function cmpr_strlen( $a, $b ) {
|
314 |
+
return strlen( $b ) - strlen( $a );
|
315 |
+
}
|
316 |
+
|
317 |
+
|
318 |
+
} // end class
|
319 |
+
} // end if
|
inc/class-walker-nav-menu-edit-roles-4.5.php
ADDED
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// phpcs:ignoreFile
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
|
7 |
+
*
|
8 |
+
* Create HTML list of nav menu input items.
|
9 |
+
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/class-walker-nav-menu-edit.php
|
10 |
+
*
|
11 |
+
* @package nav-menu-roles
|
12 |
+
* @since 1.0
|
13 |
+
* @since WordPress 4.5.0
|
14 |
+
* @uses Walker_Nav_Menu_Edit
|
15 |
+
*/
|
16 |
+
|
17 |
+
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Starts the list before the elements are added.
|
21 |
+
*
|
22 |
+
* @see Walker_Nav_Menu::start_lvl()
|
23 |
+
*
|
24 |
+
* @since 3.0.0
|
25 |
+
*
|
26 |
+
* @param string $output Passed by reference.
|
27 |
+
* @param int $depth Depth of menu item. Used for padding.
|
28 |
+
* @param array $args Not used.
|
29 |
+
*/
|
30 |
+
public function start_lvl( &$output, $depth = 0, $args = array() ) {}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Ends the list of after the elements are added.
|
34 |
+
*
|
35 |
+
* @see Walker_Nav_Menu::end_lvl()
|
36 |
+
*
|
37 |
+
* @since 3.0.0
|
38 |
+
*
|
39 |
+
* @param string $output Passed by reference.
|
40 |
+
* @param int $depth Depth of menu item. Used for padding.
|
41 |
+
* @param array $args Not used.
|
42 |
+
*/
|
43 |
+
public function end_lvl( &$output, $depth = 0, $args = array() ) {}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Start the element output.
|
47 |
+
*
|
48 |
+
* @see Walker_Nav_Menu::start_el()
|
49 |
+
* @since 3.0.0
|
50 |
+
*
|
51 |
+
* @global int $_wp_nav_menu_max_depth
|
52 |
+
*
|
53 |
+
* @param string $output Passed by reference. Used to append additional content.
|
54 |
+
* @param object $item Menu item data object.
|
55 |
+
* @param int $depth Depth of menu item. Used for padding.
|
56 |
+
* @param array $args Not used.
|
57 |
+
* @param int $id Not used.
|
58 |
+
*/
|
59 |
+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
60 |
+
global $_wp_nav_menu_max_depth;
|
61 |
+
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
62 |
+
|
63 |
+
ob_start();
|
64 |
+
$item_id = esc_attr( $item->ID );
|
65 |
+
$removed_args = array(
|
66 |
+
'action',
|
67 |
+
'customlink-tab',
|
68 |
+
'edit-menu-item',
|
69 |
+
'menu-item',
|
70 |
+
'page-tab',
|
71 |
+
'_wpnonce',
|
72 |
+
);
|
73 |
+
|
74 |
+
$original_title = '';
|
75 |
+
if ( 'taxonomy' == $item->type ) {
|
76 |
+
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
77 |
+
if ( is_wp_error( $original_title ) ) {
|
78 |
+
$original_title = false;
|
79 |
+
}
|
80 |
+
} elseif ( 'post_type' == $item->type ) {
|
81 |
+
$original_object = get_post( $item->object_id );
|
82 |
+
$original_title = get_the_title( $original_object->ID );
|
83 |
+
} elseif ( 'post_type_archive' == $item->type ) {
|
84 |
+
$original_object = get_post_type_object( $item->object );
|
85 |
+
if ( $original_object ) {
|
86 |
+
$original_title = $original_object->labels->archives;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
$classes = array(
|
91 |
+
'menu-item menu-item-depth-' . $depth,
|
92 |
+
'menu-item-' . esc_attr( $item->object ),
|
93 |
+
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
94 |
+
);
|
95 |
+
|
96 |
+
$title = $item->title;
|
97 |
+
|
98 |
+
if ( ! empty( $item->_invalid ) ) {
|
99 |
+
$classes[] = 'menu-item-invalid';
|
100 |
+
/* translators: %s: title of menu item which is invalid */
|
101 |
+
$title = sprintf( __( '%s (Invalid)', 'nav-menu-roles' ), $item->title );
|
102 |
+
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
103 |
+
$classes[] = 'pending';
|
104 |
+
/* translators: %s: title of menu item in draft status */
|
105 |
+
$title = sprintf( __( '%s (Pending)', 'nav-menu-roles' ), $item->title );
|
106 |
+
}
|
107 |
+
|
108 |
+
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
109 |
+
|
110 |
+
$submenu_text = '';
|
111 |
+
if ( 0 == $depth ) {
|
112 |
+
$submenu_text = 'style="display: none;"';
|
113 |
+
}
|
114 |
+
|
115 |
+
?>
|
116 |
+
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
|
117 |
+
<div class="menu-item-bar">
|
118 |
+
<div class="menu-item-handle">
|
119 |
+
<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>
|
120 |
+
<span class="item-controls">
|
121 |
+
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
122 |
+
<span class="item-order hide-if-js">
|
123 |
+
<a href="
|
124 |
+
<?php
|
125 |
+
echo wp_nonce_url(
|
126 |
+
add_query_arg(
|
127 |
+
array(
|
128 |
+
'action' => 'move-up-menu-item',
|
129 |
+
'menu-item' => $item_id,
|
130 |
+
),
|
131 |
+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
|
132 |
+
),
|
133 |
+
'move-menu_item'
|
134 |
+
);
|
135 |
+
?>
|
136 |
+
" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'nav-menu-roles' ); ?>">↑</a>
|
137 |
+
|
|
138 |
+
<a href="
|
139 |
+
<?php
|
140 |
+
echo wp_nonce_url(
|
141 |
+
add_query_arg(
|
142 |
+
array(
|
143 |
+
'action' => 'move-down-menu-item',
|
144 |
+
'menu-item' => $item_id,
|
145 |
+
),
|
146 |
+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
|
147 |
+
),
|
148 |
+
'move-menu_item'
|
149 |
+
);
|
150 |
+
?>
|
151 |
+
" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'nav-menu-roles' ); ?>">↓</a>
|
152 |
+
</span>
|
153 |
+
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="
|
154 |
+
<?php
|
155 |
+
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 ) ) );
|
156 |
+
?>
|
157 |
+
" aria-label="<?php esc_attr_e( 'Edit menu item', 'nav-menu-roles' ); ?>"><?php _e( 'Edit', 'nav-menu-roles' ); ?></a>
|
158 |
+
</span>
|
159 |
+
</div>
|
160 |
+
</div>
|
161 |
+
|
162 |
+
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
|
163 |
+
<?php if ( 'custom' == $item->type ) : ?>
|
164 |
+
<p class="field-url description description-wide">
|
165 |
+
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
166 |
+
<?php _e( 'URL', 'nav-menu-roles' ); ?><br />
|
167 |
+
<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 ); ?>" />
|
168 |
+
</label>
|
169 |
+
</p>
|
170 |
+
<?php endif; ?>
|
171 |
+
<p class="description description-wide">
|
172 |
+
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
173 |
+
<?php _e( 'Navigation Label', 'nav-menu-roles' ); ?><br />
|
174 |
+
<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 ); ?>" />
|
175 |
+
</label>
|
176 |
+
</p>
|
177 |
+
<p class="field-title-attribute field-attr-title description description-wide">
|
178 |
+
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
179 |
+
<?php _e( 'Title Attribute', 'nav-menu-roles' ); ?><br />
|
180 |
+
<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 ); ?>" />
|
181 |
+
</label>
|
182 |
+
</p>
|
183 |
+
<p class="field-link-target description">
|
184 |
+
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
185 |
+
<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' ); ?> />
|
186 |
+
<?php _e( 'Open link in a new tab', 'nav-menu-roles' ); ?>
|
187 |
+
</label>
|
188 |
+
</p>
|
189 |
+
<p class="field-css-classes description description-thin">
|
190 |
+
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
191 |
+
<?php _e( 'CSS Classes (optional)', 'nav-menu-roles' ); ?><br />
|
192 |
+
<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 ) ); ?>" />
|
193 |
+
</label>
|
194 |
+
</p>
|
195 |
+
<p class="field-xfn description description-thin">
|
196 |
+
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
197 |
+
<?php _e( 'Link Relationship (XFN)', 'nav-menu-roles' ); ?><br />
|
198 |
+
<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 ); ?>" />
|
199 |
+
</label>
|
200 |
+
</p>
|
201 |
+
<p class="field-description description description-wide">
|
202 |
+
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
203 |
+
<?php _e( 'Description', 'nav-menu-roles' ); ?><br />
|
204 |
+
<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>
|
205 |
+
<span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
|
206 |
+
</label>
|
207 |
+
</p>
|
208 |
+
|
209 |
+
<?php
|
210 |
+
// This is the added section
|
211 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
212 |
+
// end added section
|
213 |
+
?>
|
214 |
+
|
215 |
+
<p class="field-move hide-if-no-js description description-wide">
|
216 |
+
<label>
|
217 |
+
<span><?php _e( 'Move', 'nav-menu-roles' ); ?></span>
|
218 |
+
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'nav-menu-roles' ); ?></a>
|
219 |
+
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'nav-menu-roles' ); ?></a>
|
220 |
+
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
221 |
+
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
222 |
+
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'nav-menu-roles' ); ?></a>
|
223 |
+
</label>
|
224 |
+
</p>
|
225 |
+
|
226 |
+
<div class="menu-item-actions description-wide submitbox">
|
227 |
+
<?php if ( 'custom' !== $item->type && false !== $original_title ) : ?>
|
228 |
+
<p class="link-to-original">
|
229 |
+
<?php printf( __( 'Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
230 |
+
</p>
|
231 |
+
<?php endif; ?>
|
232 |
+
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="
|
233 |
+
<?php
|
234 |
+
echo wp_nonce_url(
|
235 |
+
add_query_arg(
|
236 |
+
array(
|
237 |
+
'action' => 'delete-menu-item',
|
238 |
+
'menu-item' => $item_id,
|
239 |
+
),
|
240 |
+
admin_url( 'nav-menus.php' )
|
241 |
+
),
|
242 |
+
'delete-menu_item_' . $item_id
|
243 |
+
);
|
244 |
+
?>
|
245 |
+
"><?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="
|
246 |
+
<?php
|
247 |
+
echo esc_url( add_query_arg( array(
|
248 |
+
'edit-menu-item' => $item_id,
|
249 |
+
'cancel' => time()
|
250 |
+
), admin_url( 'nav-menus.php' ) ) );
|
251 |
+
?>
|
252 |
+
#menu-item-settings-<?php echo $item_id; ?>"><?php _e( 'Cancel', 'nav-menu-roles' ); ?></a>
|
253 |
+
</div>
|
254 |
+
|
255 |
+
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
256 |
+
<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 ); ?>" />
|
257 |
+
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
258 |
+
<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 ); ?>" />
|
259 |
+
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
260 |
+
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
261 |
+
</div><!-- .menu-item-settings-->
|
262 |
+
<ul class="menu-item-transport"></ul>
|
263 |
+
<?php
|
264 |
+
$output .= ob_get_clean();
|
265 |
+
}
|
266 |
+
|
267 |
+
} // Walker_Nav_Menu_Edit
|
inc/class-walker-nav-menu-edit-roles-4.7.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// phpcs:ignoreFile
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Custom Walker for Nav Menu Editor
|
6 |
+
* Add wp_nav_menu_item_custom_fields hook
|
7 |
+
* Hat tip to @kucrut and Menu Icons for the preg_replace() idea
|
8 |
+
* means I no longer have to translate core strings
|
9 |
+
*
|
10 |
+
* @package Nav Menu Roles
|
11 |
+
* @since 1.8.6
|
12 |
+
* @uses Walker_Nav_Menu_Edit
|
13 |
+
*/
|
14 |
+
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu_Edit {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Start the element output.
|
18 |
+
*
|
19 |
+
* @see Walker_Nav_Menu::start_el()
|
20 |
+
*
|
21 |
+
* @param string $output Passed by reference. Used to append additional content.
|
22 |
+
* @param object $item Menu item data object.
|
23 |
+
* @param int $depth Depth of menu item. Used for padding.
|
24 |
+
* @param array $args Not used.
|
25 |
+
* @param int $id Not used.
|
26 |
+
*/
|
27 |
+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
28 |
+
$item_output = '';
|
29 |
+
$output .= parent::start_el( $item_output, $item, $depth, $args, $id );
|
30 |
+
$output .= preg_replace(
|
31 |
+
// NOTE: Check this regex on major WP version updates!
|
32 |
+
'/(?=<fieldset[^>]+class="[^"]*field-move)/',
|
33 |
+
$this->get_custom_fields( $item, $depth, $args ),
|
34 |
+
$item_output
|
35 |
+
);
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Get custom fields
|
41 |
+
*
|
42 |
+
* @access protected
|
43 |
+
* @since 0.1.0
|
44 |
+
* @uses do_action() Calls 'menu_item_custom_fields' hook
|
45 |
+
*
|
46 |
+
* @param object $item Menu item data object.
|
47 |
+
* @param int $depth Depth of menu item. Used for padding.
|
48 |
+
* @param array $args Menu item args.
|
49 |
+
* @param int $id Nav menu ID.
|
50 |
+
*
|
51 |
+
* @return string Form fields
|
52 |
+
*/
|
53 |
+
protected function get_custom_fields( $item, $depth, $args = array(), $id = 0 ) {
|
54 |
+
ob_start();
|
55 |
+
$item_id = intval( $item->ID );
|
56 |
+
/**
|
57 |
+
* Get menu item custom fields from plugins/themes
|
58 |
+
*
|
59 |
+
* @since 0.1.0
|
60 |
+
*
|
61 |
+
* @param int $item_id post ID of menu
|
62 |
+
* @param object $item Menu item data object.
|
63 |
+
* @param int $depth Depth of menu item. Used for padding.
|
64 |
+
* @param array $args Menu item args.
|
65 |
+
*
|
66 |
+
* @return string Custom fields
|
67 |
+
*/
|
68 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
69 |
+
return ob_get_clean();
|
70 |
+
}
|
71 |
+
} // Walker_Nav_Menu_Edit
|
inc/class-walker-nav-menu-edit-roles.php
ADDED
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
|
4 |
+
*
|
5 |
+
* Create HTML list of nav menu input items.
|
6 |
+
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
|
7 |
+
*
|
8 |
+
* @package Nav Menu Roles\Classes
|
9 |
+
* @since 1.0
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
|
13 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
14 |
+
exit;
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Custom Walker Class
|
19 |
+
*
|
20 |
+
* Create HTML list of nav menu input items.
|
21 |
+
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
|
22 |
+
*
|
23 |
+
* @since 1.0
|
24 |
+
* @uses Walker_Nav_Menu
|
25 |
+
*
|
26 |
+
* @phpcs:disable WordPress.Security.EscapeOutput
|
27 |
+
*/
|
28 |
+
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
|
29 |
+
/**
|
30 |
+
* Starts the list before the elements are added.
|
31 |
+
*
|
32 |
+
* @see Walker_Nav_Menu::start_lvl()
|
33 |
+
*
|
34 |
+
* @since 3.0.0
|
35 |
+
*
|
36 |
+
* @param string $output Passed by reference.
|
37 |
+
* @param int $depth Depth of menu item. Used for padding.
|
38 |
+
* @param array $args Not used.
|
39 |
+
*/
|
40 |
+
public function start_lvl( &$output, $depth = 0, $args = array() ) {}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Ends the list of after the elements are added.
|
44 |
+
*
|
45 |
+
* @see Walker_Nav_Menu::end_lvl()
|
46 |
+
*
|
47 |
+
* @since 3.0.0
|
48 |
+
*
|
49 |
+
* @param string $output Passed by reference.
|
50 |
+
* @param int $depth Depth of menu item. Used for padding.
|
51 |
+
* @param array $args Not used.
|
52 |
+
*/
|
53 |
+
public function end_lvl( &$output, $depth = 0, $args = array() ) {}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Start the element output.
|
57 |
+
*
|
58 |
+
* @see Walker_Nav_Menu::start_el()
|
59 |
+
* @since 3.0.0
|
60 |
+
*
|
61 |
+
* @global int $_wp_nav_menu_max_depth
|
62 |
+
*
|
63 |
+
* @param string $output Passed by reference. Used to append additional content.
|
64 |
+
* @param object $item Menu item data object.
|
65 |
+
* @param int $depth Depth of menu item. Used for padding.
|
66 |
+
* @param array $args Not used.
|
67 |
+
* @param int $id Not used.
|
68 |
+
*/
|
69 |
+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
70 |
+
global $_wp_nav_menu_max_depth;
|
71 |
+
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
72 |
+
|
73 |
+
ob_start();
|
74 |
+
$item_id = esc_attr( $item->ID );
|
75 |
+
$removed_args = array(
|
76 |
+
'action',
|
77 |
+
'customlink-tab',
|
78 |
+
'edit-menu-item',
|
79 |
+
'menu-item',
|
80 |
+
'page-tab',
|
81 |
+
'_wpnonce',
|
82 |
+
);
|
83 |
+
|
84 |
+
$original_title = '';
|
85 |
+
if ( 'taxonomy' == $item->type ) {
|
86 |
+
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
87 |
+
if ( is_wp_error( $original_title ) ) {
|
88 |
+
$original_title = false;
|
89 |
+
}
|
90 |
+
} elseif ( 'post_type' == $item->type ) {
|
91 |
+
$original_object = get_post( $item->object_id );
|
92 |
+
$original_title = get_the_title( $original_object->ID );
|
93 |
+
} elseif ( 'post_type_archive' == $item->type ) {
|
94 |
+
$original_object = get_post_type_object( $item->object );
|
95 |
+
$original_title = $original_object->labels->archives;
|
96 |
+
}
|
97 |
+
|
98 |
+
$classes = array(
|
99 |
+
'menu-item menu-item-depth-' . $depth,
|
100 |
+
'menu-item-' . esc_attr( $item->object ),
|
101 |
+
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
|
102 |
+
);
|
103 |
+
|
104 |
+
$title = $item->title;
|
105 |
+
|
106 |
+
if ( ! empty( $item->_invalid ) ) {
|
107 |
+
$classes[] = 'menu-item-invalid';
|
108 |
+
/* translators: %s: title of menu item which is invalid */
|
109 |
+
$title = sprintf( __( '%s (Invalid)', 'nav-menu-roles' ), $item->title );
|
110 |
+
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
111 |
+
$classes[] = 'pending';
|
112 |
+
/* translators: %s: title of menu item in draft status */
|
113 |
+
$title = sprintf( __( '%s (Pending)', 'nav-menu-roles' ), $item->title );
|
114 |
+
}
|
115 |
+
|
116 |
+
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
117 |
+
|
118 |
+
$submenu_text = '';
|
119 |
+
if ( 0 == $depth ) {
|
120 |
+
$submenu_text = 'style="display: none;"';
|
121 |
+
}
|
122 |
+
|
123 |
+
// phpcs:disable Squiz.PHP.EmbeddedPhp,Generic.WhiteSpace.ScopeIndent
|
124 |
+
?>
|
125 |
+
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
|
126 |
+
<div class="menu-item-bar">
|
127 |
+
<div class="menu-item-handle">
|
128 |
+
<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>
|
129 |
+
<span class="item-controls">
|
130 |
+
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
131 |
+
<span class="item-order hide-if-js">
|
132 |
+
<a href="<?php
|
133 |
+
echo wp_nonce_url(
|
134 |
+
add_query_arg(
|
135 |
+
array(
|
136 |
+
'action' => 'move-up-menu-item',
|
137 |
+
'menu-item' => $item_id,
|
138 |
+
),
|
139 |
+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
|
140 |
+
),
|
141 |
+
'move-menu_item'
|
142 |
+
);
|
143 |
+
?>" class="item-move-up"><abbr title="<?php esc_attr_e( 'Move up', 'nav-menu-roles' ); ?>">↑</abbr></a>
|
144 |
+
|
|
145 |
+
<a href="<?php
|
146 |
+
echo wp_nonce_url(
|
147 |
+
add_query_arg(
|
148 |
+
array(
|
149 |
+
'action' => 'move-down-menu-item',
|
150 |
+
'menu-item' => $item_id,
|
151 |
+
),
|
152 |
+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
|
153 |
+
),
|
154 |
+
'move-menu_item'
|
155 |
+
);
|
156 |
+
?>" class="item-move-down"><abbr title="<?php esc_attr_e( 'Move down', 'nav-menu-roles' ); ?>">↓</abbr></a>
|
157 |
+
</span>
|
158 |
+
<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e( 'Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
|
159 |
+
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 ) ) );
|
160 |
+
?>"><?php _e( 'Edit Menu Item', 'nav-menu-roles' ); ?></a>
|
161 |
+
</span>
|
162 |
+
</div>
|
163 |
+
</div>
|
164 |
+
|
165 |
+
<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
|
166 |
+
<?php if ( 'custom' == $item->type ) : ?>
|
167 |
+
<p class="field-url description description-wide">
|
168 |
+
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
169 |
+
<?php _e( 'URL', 'nav-menu-roles' ); ?><br />
|
170 |
+
<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 ); ?>" />
|
171 |
+
</label>
|
172 |
+
</p>
|
173 |
+
<?php endif; ?>
|
174 |
+
<p class="description description-wide">
|
175 |
+
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
176 |
+
<?php _e( 'Navigation Label', 'nav-menu-roles' ); ?><br />
|
177 |
+
<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 ); ?>" />
|
178 |
+
</label>
|
179 |
+
</p>
|
180 |
+
<p class="field-title-attribute description description-wide">
|
181 |
+
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
182 |
+
<?php _e( 'Title Attribute', 'nav-menu-roles' ); ?><br />
|
183 |
+
<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 ); ?>" />
|
184 |
+
</label>
|
185 |
+
</p>
|
186 |
+
<p class="field-link-target description">
|
187 |
+
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
188 |
+
<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' ); ?> />
|
189 |
+
<?php _e( 'Open link in a new tab', 'nav-menu-roles' ); ?>
|
190 |
+
</label>
|
191 |
+
</p>
|
192 |
+
<p class="field-css-classes description description-thin">
|
193 |
+
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
194 |
+
<?php _e( 'CSS Classes (optional)', 'nav-menu-roles' ); ?><br />
|
195 |
+
<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 ) ); ?>" />
|
196 |
+
</label>
|
197 |
+
</p>
|
198 |
+
<p class="field-xfn description description-thin">
|
199 |
+
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
200 |
+
<?php _e( 'Link Relationship (XFN)', 'nav-menu-roles' ); ?><br />
|
201 |
+
<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 ); ?>" />
|
202 |
+
</label>
|
203 |
+
</p>
|
204 |
+
<p class="field-description description description-wide">
|
205 |
+
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
206 |
+
<?php _e( 'Description', 'nav-menu-roles' ); ?><br />
|
207 |
+
<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>
|
208 |
+
<span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
|
209 |
+
</label>
|
210 |
+
</p>
|
211 |
+
|
212 |
+
<?php
|
213 |
+
// This is the added section
|
214 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
215 |
+
// end added section
|
216 |
+
?>
|
217 |
+
|
218 |
+
<p class="field-move hide-if-no-js description description-wide">
|
219 |
+
<label>
|
220 |
+
<span><?php _e( 'Move', 'nav-menu-roles' ); ?></span>
|
221 |
+
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'nav-menu-roles' ); ?></a>
|
222 |
+
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'nav-menu-roles' ); ?></a>
|
223 |
+
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
224 |
+
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
225 |
+
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'nav-menu-roles' ); ?></a>
|
226 |
+
</label>
|
227 |
+
</p>
|
228 |
+
|
229 |
+
<div class="menu-item-actions description-wide submitbox">
|
230 |
+
<?php if ( 'custom' != $item->type && false !== $original_title ) : ?>
|
231 |
+
<p class="link-to-original">
|
232 |
+
<?php printf( __( 'Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
233 |
+
</p>
|
234 |
+
<?php endif; ?>
|
235 |
+
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>"
|
236 |
+
href="<?php
|
237 |
+
echo wp_nonce_url(
|
238 |
+
add_query_arg(
|
239 |
+
array(
|
240 |
+
'action' => 'delete-menu-item',
|
241 |
+
'menu-item' => $item_id,
|
242 |
+
),
|
243 |
+
admin_url( 'nav-menus.php' )
|
244 |
+
),
|
245 |
+
'delete-menu_item_' . $item_id
|
246 |
+
); ?>"><?php _e( 'Remove', 'nav-menu-roles' ); ?></a>
|
247 |
+
<span class="meta-sep hide-if-no-js"> | </span>
|
248 |
+
<a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>"
|
249 |
+
href="<?php
|
250 |
+
echo esc_url(
|
251 |
+
add_query_arg(
|
252 |
+
array(
|
253 |
+
'edit-menu-item' => $item_id,
|
254 |
+
'cancel' => time(),
|
255 |
+
),
|
256 |
+
admin_url( 'nav-menus.php' )
|
257 |
+
)
|
258 |
+
); ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e( 'Cancel', 'nav-menu-roles' ); ?></a>
|
259 |
+
</div>
|
260 |
+
|
261 |
+
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
262 |
+
<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 ); ?>" />
|
263 |
+
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
264 |
+
<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 ); ?>" />
|
265 |
+
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
266 |
+
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
267 |
+
</div><!-- .menu-item-settings-->
|
268 |
+
<ul class="menu-item-transport"></ul>
|
269 |
+
<?php
|
270 |
+
// phpcs:enable
|
271 |
+
$output .= ob_get_clean();
|
272 |
+
}
|
273 |
+
|
274 |
+
} // Walker_Nav_Menu_Edit
|
inc/class.Nav_Menu_Roles_Import.php
DELETED
@@ -1,308 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Nav Menu Roles Importer - import menu item meta
|
4 |
-
*
|
5 |
-
* @author Kathy Darling
|
6 |
-
* @since 1.3
|
7 |
-
*/
|
8 |
-
|
9 |
-
// Exit if accessed directly
|
10 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
11 |
-
exit;
|
12 |
-
}
|
13 |
-
|
14 |
-
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ){
|
15 |
-
return;
|
16 |
-
}
|
17 |
-
|
18 |
-
/** Display verbose errors */
|
19 |
-
if( ! defined( 'IMPORT_DEBUG' ) ){
|
20 |
-
define( 'IMPORT_DEBUG', false );
|
21 |
-
}
|
22 |
-
|
23 |
-
// Load Importer API
|
24 |
-
require_once ABSPATH . 'wp-admin/includes/import.php';
|
25 |
-
|
26 |
-
if ( ! class_exists( 'WP_Importer' ) ) {
|
27 |
-
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
28 |
-
if ( file_exists( $class_wp_importer ) )
|
29 |
-
require $class_wp_importer;
|
30 |
-
}
|
31 |
-
|
32 |
-
if ( class_exists( 'WP_Importer' ) && ! class_exists( 'Nav_Menu_Roles_Import' ) ) {
|
33 |
-
class Nav_Menu_Roles_Import extends WP_Importer {
|
34 |
-
|
35 |
-
var $max_wxr_version = 1.2; // max. supported WXR version
|
36 |
-
|
37 |
-
var $id; // WXR attachment ID
|
38 |
-
|
39 |
-
// information to import from WXR file
|
40 |
-
var $version;
|
41 |
-
var $posts = array();
|
42 |
-
var $base_url = '';
|
43 |
-
|
44 |
-
|
45 |
-
/**
|
46 |
-
* __construct function.
|
47 |
-
*
|
48 |
-
* @access public
|
49 |
-
* @return void
|
50 |
-
*/
|
51 |
-
public function __construct() {
|
52 |
-
$this->import_page = 'woocommerce_tax_rate_csv';
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Registered callback function for the WordPress Importer
|
57 |
-
*
|
58 |
-
* Manages the three separate stages of the WXR import process
|
59 |
-
*/
|
60 |
-
function dispatch() {
|
61 |
-
$this->header();
|
62 |
-
|
63 |
-
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
|
64 |
-
switch ( $step ) {
|
65 |
-
case 0:
|
66 |
-
$this->greet();
|
67 |
-
break;
|
68 |
-
case 1:
|
69 |
-
check_admin_referer( 'import-upload' );
|
70 |
-
if ( $this->handle_upload() ) {
|
71 |
-
$file = get_attached_file( $this->id );
|
72 |
-
set_time_limit(0);
|
73 |
-
$this->import( $file );
|
74 |
-
}
|
75 |
-
break;
|
76 |
-
}
|
77 |
-
|
78 |
-
$this->footer();
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* The main controller for the actual import stage.
|
83 |
-
*
|
84 |
-
* @param string $file Path to the WXR file for importing
|
85 |
-
*/
|
86 |
-
function import( $file ) {
|
87 |
-
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
|
88 |
-
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
89 |
-
|
90 |
-
$this->import_start( $file );
|
91 |
-
|
92 |
-
wp_suspend_cache_invalidation( true );
|
93 |
-
$this->process_nav_menu_meta();
|
94 |
-
wp_suspend_cache_invalidation( false );
|
95 |
-
|
96 |
-
$this->import_end();
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Parses the WXR file and prepares us for the task of processing parsed data
|
101 |
-
*
|
102 |
-
* @param string $file Path to the WXR file for importing
|
103 |
-
*/
|
104 |
-
function import_start( $file ) {
|
105 |
-
if ( ! is_file($file) ) {
|
106 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
107 |
-
echo __( 'The file does not exist, please try again.', 'nav-menu-roles' ) . '</p>';
|
108 |
-
$this->footer();
|
109 |
-
die();
|
110 |
-
}
|
111 |
-
|
112 |
-
$import_data = $this->parse( $file );
|
113 |
-
|
114 |
-
if ( is_wp_error( $import_data ) ) {
|
115 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
116 |
-
echo esc_html( $import_data->get_error_message() ) . '</p>';
|
117 |
-
$this->footer();
|
118 |
-
die();
|
119 |
-
}
|
120 |
-
|
121 |
-
$this->version = $import_data['version'];
|
122 |
-
$this->posts = $import_data['posts'];
|
123 |
-
$this->base_url = esc_url( $import_data['base_url'] );
|
124 |
-
|
125 |
-
wp_defer_term_counting( true );
|
126 |
-
wp_defer_comment_counting( true );
|
127 |
-
|
128 |
-
do_action( 'import_start' );
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Performs post-import cleanup of files and the cache
|
133 |
-
*/
|
134 |
-
function import_end() {
|
135 |
-
wp_import_cleanup( $this->id );
|
136 |
-
|
137 |
-
wp_cache_flush();
|
138 |
-
foreach ( get_taxonomies() as $tax ) {
|
139 |
-
delete_option( "{$tax}_children" );
|
140 |
-
_get_term_hierarchy( $tax );
|
141 |
-
}
|
142 |
-
|
143 |
-
wp_defer_term_counting( false );
|
144 |
-
wp_defer_comment_counting( false );
|
145 |
-
|
146 |
-
echo '<p>' . __( 'All done.', 'nav-menu-roles' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'nav-menu-roles' ) . '</a>' . '</p>';
|
147 |
-
|
148 |
-
do_action( 'import_end' );
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Handles the WXR upload and initial parsing of the file to prepare for
|
153 |
-
* displaying author import options
|
154 |
-
*
|
155 |
-
* @return bool False if error uploading or invalid file, true otherwise
|
156 |
-
*/
|
157 |
-
function handle_upload() {
|
158 |
-
$file = wp_import_handle_upload();
|
159 |
-
|
160 |
-
if ( isset( $file['error'] ) ) {
|
161 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
162 |
-
echo esc_html( $file['error'] ) . '</p>';
|
163 |
-
return false;
|
164 |
-
} else if ( ! file_exists( $file['file'] ) ) {
|
165 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
166 |
-
printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'nav-menu-roles' ), esc_html( $file['file'] ) );
|
167 |
-
echo '</p>';
|
168 |
-
return false;
|
169 |
-
}
|
170 |
-
|
171 |
-
$this->id = (int) $file['id'];
|
172 |
-
$import_data = $this->parse( $file['file'] );
|
173 |
-
if ( is_wp_error( $import_data ) ) {
|
174 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'nav-menu-roles' ) . '</strong><br />';
|
175 |
-
echo esc_html( $import_data->get_error_message() ) . '</p>';
|
176 |
-
return false;
|
177 |
-
}
|
178 |
-
|
179 |
-
$this->version = $import_data['version'];
|
180 |
-
if ( $this->version > $this->max_wxr_version ) {
|
181 |
-
echo '<div class="error"><p><strong>';
|
182 |
-
printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'nav-menu-roles' ), esc_html($import_data['version']) );
|
183 |
-
echo '</strong></p></div>';
|
184 |
-
}
|
185 |
-
|
186 |
-
return true;
|
187 |
-
}
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
/**
|
192 |
-
* Create new posts based on import information
|
193 |
-
*
|
194 |
-
* Posts marked as having a parent which doesn't exist will become top level items.
|
195 |
-
* Doesn't create a new post if: the post type doesn't exist, the given post ID
|
196 |
-
* is already noted as imported or a post with the same title and date already exists.
|
197 |
-
* Note that new/updated terms, comments and meta are imported for the last of the above.
|
198 |
-
*/
|
199 |
-
function process_nav_menu_meta() {
|
200 |
-
foreach ( $this->posts as $post ) {
|
201 |
-
|
202 |
-
// we only want to deal with the nav_menu_item posts
|
203 |
-
if ( 'nav_menu_item' != $post['post_type'] || ! empty( $post['post_id'] ) )
|
204 |
-
continue;
|
205 |
-
|
206 |
-
// ok we've got a nav_menu_item
|
207 |
-
$post_id = (int) $post['post_id'];
|
208 |
-
|
209 |
-
// add/update post meta
|
210 |
-
if ( isset( $post['postmeta'] ) ) {
|
211 |
-
foreach ( $post['postmeta'] as $meta ) {
|
212 |
-
$key = apply_filters( 'import_post_meta_key', $meta['key'] );
|
213 |
-
$value = false;
|
214 |
-
|
215 |
-
|
216 |
-
if ( $key ) {
|
217 |
-
// export gets meta straight from the DB so could have a serialized string
|
218 |
-
if ( ! $value )
|
219 |
-
$value = maybe_unserialize( $meta['value'] );
|
220 |
-
|
221 |
-
update_post_meta( $post_id, $key, $value );
|
222 |
-
do_action( 'import_post_meta', $post_id, $key, $value );
|
223 |
-
|
224 |
-
}
|
225 |
-
}
|
226 |
-
}
|
227 |
-
}
|
228 |
-
|
229 |
-
unset( $this->posts );
|
230 |
-
}
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
/**
|
236 |
-
* Parse a WXR file
|
237 |
-
*
|
238 |
-
* @param string $file Path to WXR file for parsing
|
239 |
-
* @return array Information gathered from the WXR file
|
240 |
-
*/
|
241 |
-
function parse( $file ) {
|
242 |
-
$parser = new WXR_Parser();
|
243 |
-
return $parser->parse( $file );
|
244 |
-
}
|
245 |
-
|
246 |
-
// Display import page title
|
247 |
-
function header() {
|
248 |
-
echo '<div class="wrap">';
|
249 |
-
echo '<h2>' . __( 'Import Nav Menu Roles', 'nav-menu-roles' ) . '</h2>';
|
250 |
-
|
251 |
-
$updates = get_plugin_updates();
|
252 |
-
$basename = plugin_basename(__FILE__);
|
253 |
-
if ( isset( $updates[$basename] ) ) {
|
254 |
-
$update = $updates[$basename];
|
255 |
-
echo '<div class="error"><p><strong>';
|
256 |
-
printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'nav-menu-roles' ), $update->update->new_version );
|
257 |
-
echo '</strong></p></div>';
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
// Close div.wrap
|
262 |
-
function footer() {
|
263 |
-
echo '</div>';
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Display introductory text and file upload form
|
268 |
-
*/
|
269 |
-
function greet() {
|
270 |
-
echo '<div class="narrow">';
|
271 |
-
echo '<p>'.__( 'Re-Upload your normal WordPress eXtended RSS (WXR) file and we’ll import the Nav Menu Roles and any other missing post meta for the Nav Menu items.', 'nav-menu-roles' ).'</p>';
|
272 |
-
echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'nav-menu-roles' ).'</p>';
|
273 |
-
wp_import_upload_form( 'admin.php?import=nav_menu_roles&step=1' );
|
274 |
-
echo '</div>';
|
275 |
-
}
|
276 |
-
|
277 |
-
/**
|
278 |
-
* Decide if the given meta key maps to information we will want to import
|
279 |
-
*
|
280 |
-
* @param string $key The meta key to check
|
281 |
-
* @return string|bool The key if we do want to import, false if not
|
282 |
-
*/
|
283 |
-
function is_valid_meta_key( $key ) {
|
284 |
-
// skip attachment metadata since we'll regenerate it from scratch
|
285 |
-
// skip _edit_lock as not relevant for import
|
286 |
-
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
|
287 |
-
return false;
|
288 |
-
return $key;
|
289 |
-
}
|
290 |
-
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
294 |
-
* @param int $val
|
295 |
-
* @return int
|
296 |
-
*/
|
297 |
-
public function bump_request_timeout( $val ) {
|
298 |
-
return 60;
|
299 |
-
}
|
300 |
-
|
301 |
-
// return the difference in length between two strings
|
302 |
-
function cmpr_strlen( $a, $b ) {
|
303 |
-
return strlen($b) - strlen($a);
|
304 |
-
}
|
305 |
-
|
306 |
-
|
307 |
-
} // end class
|
308 |
-
} // end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/class.Walker_Nav_Menu_Edit_Roles.php
DELETED
@@ -1,245 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
|
5 |
-
*
|
6 |
-
* Create HTML list of nav menu input items.
|
7 |
-
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/nav-menu.php
|
8 |
-
*
|
9 |
-
* @package nav-menu-roles
|
10 |
-
* @since 1.0
|
11 |
-
* @since WordPress 4.4.0
|
12 |
-
* @uses Walker_Nav_Menu
|
13 |
-
*/
|
14 |
-
|
15 |
-
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
|
16 |
-
/**
|
17 |
-
* Starts the list before the elements are added.
|
18 |
-
*
|
19 |
-
* @see Walker_Nav_Menu::start_lvl()
|
20 |
-
*
|
21 |
-
* @since 3.0.0
|
22 |
-
*
|
23 |
-
* @param string $output Passed by reference.
|
24 |
-
* @param int $depth Depth of menu item. Used for padding.
|
25 |
-
* @param array $args Not used.
|
26 |
-
*/
|
27 |
-
public function start_lvl( &$output, $depth = 0, $args = array() ) {}
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Ends the list of after the elements are added.
|
31 |
-
*
|
32 |
-
* @see Walker_Nav_Menu::end_lvl()
|
33 |
-
*
|
34 |
-
* @since 3.0.0
|
35 |
-
*
|
36 |
-
* @param string $output Passed by reference.
|
37 |
-
* @param int $depth Depth of menu item. Used for padding.
|
38 |
-
* @param array $args Not used.
|
39 |
-
*/
|
40 |
-
public function end_lvl( &$output, $depth = 0, $args = array() ) {}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Start the element output.
|
44 |
-
*
|
45 |
-
* @see Walker_Nav_Menu::start_el()
|
46 |
-
* @since 3.0.0
|
47 |
-
*
|
48 |
-
* @global int $_wp_nav_menu_max_depth
|
49 |
-
*
|
50 |
-
* @param string $output Passed by reference. Used to append additional content.
|
51 |
-
* @param object $item Menu item data object.
|
52 |
-
* @param int $depth Depth of menu item. Used for padding.
|
53 |
-
* @param array $args Not used.
|
54 |
-
* @param int $id Not used.
|
55 |
-
*/
|
56 |
-
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
57 |
-
global $_wp_nav_menu_max_depth;
|
58 |
-
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
59 |
-
|
60 |
-
ob_start();
|
61 |
-
$item_id = esc_attr( $item->ID );
|
62 |
-
$removed_args = array(
|
63 |
-
'action',
|
64 |
-
'customlink-tab',
|
65 |
-
'edit-menu-item',
|
66 |
-
'menu-item',
|
67 |
-
'page-tab',
|
68 |
-
'_wpnonce',
|
69 |
-
);
|
70 |
-
|
71 |
-
$original_title = '';
|
72 |
-
if ( 'taxonomy' == $item->type ) {
|
73 |
-
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
74 |
-
if ( is_wp_error( $original_title ) )
|
75 |
-
$original_title = false;
|
76 |
-
} elseif ( 'post_type' == $item->type ) {
|
77 |
-
$original_object = get_post( $item->object_id );
|
78 |
-
$original_title = get_the_title( $original_object->ID );
|
79 |
-
} elseif ( 'post_type_archive' == $item->type ) {
|
80 |
-
$original_object = get_post_type_object( $item->object );
|
81 |
-
$original_title = $original_object->labels->archives;
|
82 |
-
}
|
83 |
-
|
84 |
-
$classes = array(
|
85 |
-
'menu-item menu-item-depth-' . $depth,
|
86 |
-
'menu-item-' . esc_attr( $item->object ),
|
87 |
-
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
88 |
-
);
|
89 |
-
|
90 |
-
$title = $item->title;
|
91 |
-
|
92 |
-
if ( ! empty( $item->_invalid ) ) {
|
93 |
-
$classes[] = 'menu-item-invalid';
|
94 |
-
/* translators: %s: title of menu item which is invalid */
|
95 |
-
$title = sprintf( __( '%s (Invalid)' , 'nav-menu-roles' ), $item->title );
|
96 |
-
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
97 |
-
$classes[] = 'pending';
|
98 |
-
/* translators: %s: title of menu item in draft status */
|
99 |
-
$title = sprintf( __('%s (Pending)', 'nav-menu-roles' ), $item->title );
|
100 |
-
}
|
101 |
-
|
102 |
-
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
103 |
-
|
104 |
-
$submenu_text = '';
|
105 |
-
if ( 0 == $depth )
|
106 |
-
$submenu_text = 'style="display: none;"';
|
107 |
-
|
108 |
-
?>
|
109 |
-
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
|
110 |
-
<div class="menu-item-bar">
|
111 |
-
<div class="menu-item-handle">
|
112 |
-
<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>
|
113 |
-
<span class="item-controls">
|
114 |
-
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
115 |
-
<span class="item-order hide-if-js">
|
116 |
-
<a href="<?php
|
117 |
-
echo wp_nonce_url(
|
118 |
-
add_query_arg(
|
119 |
-
array(
|
120 |
-
'action' => 'move-up-menu-item',
|
121 |
-
'menu-item' => $item_id,
|
122 |
-
),
|
123 |
-
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
124 |
-
),
|
125 |
-
'move-menu_item'
|
126 |
-
);
|
127 |
-
?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'nav-menu-roles' ); ?>">↑</abbr></a>
|
128 |
-
|
|
129 |
-
<a href="<?php
|
130 |
-
echo wp_nonce_url(
|
131 |
-
add_query_arg(
|
132 |
-
array(
|
133 |
-
'action' => 'move-down-menu-item',
|
134 |
-
'menu-item' => $item_id,
|
135 |
-
),
|
136 |
-
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
137 |
-
),
|
138 |
-
'move-menu_item'
|
139 |
-
);
|
140 |
-
?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'nav-menu-roles' ); ?>">↓</abbr></a>
|
141 |
-
</span>
|
142 |
-
<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item', 'nav-menu-roles' ); ?>" href="<?php
|
143 |
-
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 ) ) );
|
144 |
-
?>"><?php _e( 'Edit Menu Item' , 'nav-menu-roles' ); ?></a>
|
145 |
-
</span>
|
146 |
-
</div>
|
147 |
-
</div>
|
148 |
-
|
149 |
-
<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
|
150 |
-
<?php if ( 'custom' == $item->type ) : ?>
|
151 |
-
<p class="field-url description description-wide">
|
152 |
-
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
153 |
-
<?php _e( 'URL' , 'nav-menu-roles' ); ?><br />
|
154 |
-
<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 ); ?>" />
|
155 |
-
</label>
|
156 |
-
</p>
|
157 |
-
<?php endif; ?>
|
158 |
-
<p class="description description-wide">
|
159 |
-
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
160 |
-
<?php _e( 'Navigation Label' , 'nav-menu-roles' ); ?><br />
|
161 |
-
<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 ); ?>" />
|
162 |
-
</label>
|
163 |
-
</p>
|
164 |
-
<p class="field-title-attribute description description-wide">
|
165 |
-
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
166 |
-
<?php _e( 'Title Attribute' , 'nav-menu-roles' ); ?><br />
|
167 |
-
<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 ); ?>" />
|
168 |
-
</label>
|
169 |
-
</p>
|
170 |
-
<p class="field-link-target description">
|
171 |
-
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
172 |
-
<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' ); ?> />
|
173 |
-
<?php _e( 'Open link in a new tab' , 'nav-menu-roles' ); ?>
|
174 |
-
</label>
|
175 |
-
</p>
|
176 |
-
<p class="field-css-classes description description-thin">
|
177 |
-
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
178 |
-
<?php _e( 'CSS Classes (optional)' , 'nav-menu-roles' ); ?><br />
|
179 |
-
<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 ) ); ?>" />
|
180 |
-
</label>
|
181 |
-
</p>
|
182 |
-
<p class="field-xfn description description-thin">
|
183 |
-
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
184 |
-
<?php _e( 'Link Relationship (XFN)' , 'nav-menu-roles' ); ?><br />
|
185 |
-
<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 ); ?>" />
|
186 |
-
</label>
|
187 |
-
</p>
|
188 |
-
<p class="field-description description description-wide">
|
189 |
-
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
190 |
-
<?php _e( 'Description' , 'nav-menu-roles' ); ?><br />
|
191 |
-
<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>
|
192 |
-
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles' ); ?></span>
|
193 |
-
</label>
|
194 |
-
</p>
|
195 |
-
|
196 |
-
<?php
|
197 |
-
// This is the added section
|
198 |
-
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
199 |
-
// end added section
|
200 |
-
?>
|
201 |
-
|
202 |
-
<p class="field-move hide-if-no-js description description-wide">
|
203 |
-
<label>
|
204 |
-
<span><?php _e( 'Move' , 'nav-menu-roles' ); ?></span>
|
205 |
-
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' , 'nav-menu-roles' ); ?></a>
|
206 |
-
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' , 'nav-menu-roles' ); ?></a>
|
207 |
-
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
208 |
-
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
209 |
-
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' , 'nav-menu-roles' ); ?></a>
|
210 |
-
</label>
|
211 |
-
</p>
|
212 |
-
|
213 |
-
<div class="menu-item-actions description-wide submitbox">
|
214 |
-
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
|
215 |
-
<p class="link-to-original">
|
216 |
-
<?php printf( __('Original: %s', 'nav-menu-roles' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
217 |
-
</p>
|
218 |
-
<?php endif; ?>
|
219 |
-
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
|
220 |
-
echo wp_nonce_url(
|
221 |
-
add_query_arg(
|
222 |
-
array(
|
223 |
-
'action' => 'delete-menu-item',
|
224 |
-
'menu-item' => $item_id,
|
225 |
-
),
|
226 |
-
admin_url( 'nav-menus.php' )
|
227 |
-
),
|
228 |
-
'delete-menu_item_' . $item_id
|
229 |
-
); ?>"><?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' ) ) );
|
230 |
-
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles' ); ?></a>
|
231 |
-
</div>
|
232 |
-
|
233 |
-
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
234 |
-
<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 ); ?>" />
|
235 |
-
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
236 |
-
<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 ); ?>" />
|
237 |
-
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
238 |
-
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
239 |
-
</div><!-- .menu-item-settings-->
|
240 |
-
<ul class="menu-item-transport"></ul>
|
241 |
-
<?php
|
242 |
-
$output .= ob_get_clean();
|
243 |
-
}
|
244 |
-
|
245 |
-
} // Walker_Nav_Menu_Edit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php
DELETED
@@ -1,248 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Navigation Menu API: (Modifed) Walker_Nav_Menu_Edit class
|
5 |
-
*
|
6 |
-
* Create HTML list of nav menu input items.
|
7 |
-
* Copied from Walker_Nav_Menu_Edit class in core /wp-admin/includes/class-walker-nav-menu-edit.php
|
8 |
-
*
|
9 |
-
* @package nav-menu-roles
|
10 |
-
* @since 1.0
|
11 |
-
* @since WordPress 4.5.0
|
12 |
-
* @uses Walker_Nav_Menu_Edit
|
13 |
-
*/
|
14 |
-
|
15 |
-
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Starts the list before the elements are added.
|
19 |
-
*
|
20 |
-
* @see Walker_Nav_Menu::start_lvl()
|
21 |
-
*
|
22 |
-
* @since 3.0.0
|
23 |
-
*
|
24 |
-
* @param string $output Passed by reference.
|
25 |
-
* @param int $depth Depth of menu item. Used for padding.
|
26 |
-
* @param array $args Not used.
|
27 |
-
*/
|
28 |
-
public function start_lvl( &$output, $depth = 0, $args = array() ) {}
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Ends the list of after the elements are added.
|
32 |
-
*
|
33 |
-
* @see Walker_Nav_Menu::end_lvl()
|
34 |
-
*
|
35 |
-
* @since 3.0.0
|
36 |
-
*
|
37 |
-
* @param string $output Passed by reference.
|
38 |
-
* @param int $depth Depth of menu item. Used for padding.
|
39 |
-
* @param array $args Not used.
|
40 |
-
*/
|
41 |
-
public function end_lvl( &$output, $depth = 0, $args = array() ) {}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Start the element output.
|
45 |
-
*
|
46 |
-
* @see Walker_Nav_Menu::start_el()
|
47 |
-
* @since 3.0.0
|
48 |
-
*
|
49 |
-
* @global int $_wp_nav_menu_max_depth
|
50 |
-
*
|
51 |
-
* @param string $output Passed by reference. Used to append additional content.
|
52 |
-
* @param object $item Menu item data object.
|
53 |
-
* @param int $depth Depth of menu item. Used for padding.
|
54 |
-
* @param array $args Not used.
|
55 |
-
* @param int $id Not used.
|
56 |
-
*/
|
57 |
-
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
58 |
-
global $_wp_nav_menu_max_depth;
|
59 |
-
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
60 |
-
|
61 |
-
ob_start();
|
62 |
-
$item_id = esc_attr( $item->ID );
|
63 |
-
$removed_args = array(
|
64 |
-
'action',
|
65 |
-
'customlink-tab',
|
66 |
-
'edit-menu-item',
|
67 |
-
'menu-item',
|
68 |
-
'page-tab',
|
69 |
-
'_wpnonce',
|
70 |
-
);
|
71 |
-
|
72 |
-
$original_title = '';
|
73 |
-
if ( 'taxonomy' == $item->type ) {
|
74 |
-
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
75 |
-
if ( is_wp_error( $original_title ) )
|
76 |
-
$original_title = false;
|
77 |
-
} elseif ( 'post_type' == $item->type ) {
|
78 |
-
$original_object = get_post( $item->object_id );
|
79 |
-
$original_title = get_the_title( $original_object->ID );
|
80 |
-
} elseif ( 'post_type_archive' == $item->type ) {
|
81 |
-
$original_object = get_post_type_object( $item->object );
|
82 |
-
if ( $original_object ) {
|
83 |
-
$original_title = $original_object->labels->archives;
|
84 |
-
}
|
85 |
-
}
|
86 |
-
|
87 |
-
$classes = array(
|
88 |
-
'menu-item menu-item-depth-' . $depth,
|
89 |
-
'menu-item-' . esc_attr( $item->object ),
|
90 |
-
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
91 |
-
);
|
92 |
-
|
93 |
-
$title = $item->title;
|
94 |
-
|
95 |
-
if ( ! empty( $item->_invalid ) ) {
|
96 |
-
$classes[] = 'menu-item-invalid';
|
97 |
-
/* translators: %s: title of menu item which is invalid */
|
98 |
-
$title = sprintf( __( '%s (Invalid)', 'nav-menu-roles' ), $item->title );
|
99 |
-
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
100 |
-
$classes[] = 'pending';
|
101 |
-
/* translators: %s: title of menu item in draft status */
|
102 |
-
$title = sprintf( __('%s (Pending)', 'nav-menu-roles'), $item->title );
|
103 |
-
}
|
104 |
-
|
105 |
-
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
106 |
-
|
107 |
-
$submenu_text = '';
|
108 |
-
if ( 0 == $depth )
|
109 |
-
$submenu_text = 'style="display: none;"';
|
110 |
-
|
111 |
-
?>
|
112 |
-
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
|
113 |
-
<div class="menu-item-bar">
|
114 |
-
<div class="menu-item-handle">
|
115 |
-
<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>
|
116 |
-
<span class="item-controls">
|
117 |
-
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
|
118 |
-
<span class="item-order hide-if-js">
|
119 |
-
<a href="<?php
|
120 |
-
echo wp_nonce_url(
|
121 |
-
add_query_arg(
|
122 |
-
array(
|
123 |
-
'action' => 'move-up-menu-item',
|
124 |
-
'menu-item' => $item_id,
|
125 |
-
),
|
126 |
-
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
127 |
-
),
|
128 |
-
'move-menu_item'
|
129 |
-
);
|
130 |
-
?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'nav-menu-roles' ) ?>">↑</a>
|
131 |
-
|
|
132 |
-
<a href="<?php
|
133 |
-
echo wp_nonce_url(
|
134 |
-
add_query_arg(
|
135 |
-
array(
|
136 |
-
'action' => 'move-down-menu-item',
|
137 |
-
'menu-item' => $item_id,
|
138 |
-
),
|
139 |
-
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
140 |
-
),
|
141 |
-
'move-menu_item'
|
142 |
-
);
|
143 |
-
?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'nav-menu-roles' ) ?>">↓</a>
|
144 |
-
</span>
|
145 |
-
<a class="item-edit" id="edit-<?php echo $item_id; ?>" href="<?php
|
146 |
-
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 ) ) );
|
147 |
-
?>" aria-label="<?php esc_attr_e( 'Edit menu item', 'nav-menu-roles' ); ?>"><?php _e( 'Edit', 'nav-menu-roles' ); ?></a>
|
148 |
-
</span>
|
149 |
-
</div>
|
150 |
-
</div>
|
151 |
-
|
152 |
-
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
|
153 |
-
<?php if ( 'custom' == $item->type ) : ?>
|
154 |
-
<p class="field-url description description-wide">
|
155 |
-
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
|
156 |
-
<?php _e( 'URL', 'nav-menu-roles' ); ?><br />
|
157 |
-
<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 ); ?>" />
|
158 |
-
</label>
|
159 |
-
</p>
|
160 |
-
<?php endif; ?>
|
161 |
-
<p class="description description-wide">
|
162 |
-
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
|
163 |
-
<?php _e( 'Navigation Label', 'nav-menu-roles' ); ?><br />
|
164 |
-
<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 ); ?>" />
|
165 |
-
</label>
|
166 |
-
</p>
|
167 |
-
<p class="field-title-attribute field-attr-title description description-wide">
|
168 |
-
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
|
169 |
-
<?php _e( 'Title Attribute', 'nav-menu-roles' ); ?><br />
|
170 |
-
<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 ); ?>" />
|
171 |
-
</label>
|
172 |
-
</p>
|
173 |
-
<p class="field-link-target description">
|
174 |
-
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
|
175 |
-
<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' ); ?> />
|
176 |
-
<?php _e( 'Open link in a new tab', 'nav-menu-roles' ); ?>
|
177 |
-
</label>
|
178 |
-
</p>
|
179 |
-
<p class="field-css-classes description description-thin">
|
180 |
-
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
181 |
-
<?php _e( 'CSS Classes (optional)', 'nav-menu-roles' ); ?><br />
|
182 |
-
<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 ) ); ?>" />
|
183 |
-
</label>
|
184 |
-
</p>
|
185 |
-
<p class="field-xfn description description-thin">
|
186 |
-
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
|
187 |
-
<?php _e( 'Link Relationship (XFN)', 'nav-menu-roles' ); ?><br />
|
188 |
-
<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 ); ?>" />
|
189 |
-
</label>
|
190 |
-
</p>
|
191 |
-
<p class="field-description description description-wide">
|
192 |
-
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
|
193 |
-
<?php _e( 'Description', 'nav-menu-roles' ); ?><br />
|
194 |
-
<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>
|
195 |
-
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'nav-menu-roles'); ?></span>
|
196 |
-
</label>
|
197 |
-
</p>
|
198 |
-
|
199 |
-
<?php
|
200 |
-
// This is the added section
|
201 |
-
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
202 |
-
// end added section
|
203 |
-
?>
|
204 |
-
|
205 |
-
<p class="field-move hide-if-no-js description description-wide">
|
206 |
-
<label>
|
207 |
-
<span><?php _e( 'Move', 'nav-menu-roles' ); ?></span>
|
208 |
-
<a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'nav-menu-roles' ); ?></a>
|
209 |
-
<a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'nav-menu-roles' ); ?></a>
|
210 |
-
<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
|
211 |
-
<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
|
212 |
-
<a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'nav-menu-roles' ); ?></a>
|
213 |
-
</label>
|
214 |
-
</p>
|
215 |
-
|
216 |
-
<div class="menu-item-actions description-wide submitbox">
|
217 |
-
<?php if ( 'custom' != $item->type && $original_title !== false ) : ?>
|
218 |
-
<p class="link-to-original">
|
219 |
-
<?php printf( __('Original: %s', 'nav-menu-roles'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
220 |
-
</p>
|
221 |
-
<?php endif; ?>
|
222 |
-
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
|
223 |
-
echo wp_nonce_url(
|
224 |
-
add_query_arg(
|
225 |
-
array(
|
226 |
-
'action' => 'delete-menu-item',
|
227 |
-
'menu-item' => $item_id,
|
228 |
-
),
|
229 |
-
admin_url( 'nav-menus.php' )
|
230 |
-
),
|
231 |
-
'delete-menu_item_' . $item_id
|
232 |
-
); ?>"><?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' ) ) );
|
233 |
-
?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel', 'nav-menu-roles'); ?></a>
|
234 |
-
</div>
|
235 |
-
|
236 |
-
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
|
237 |
-
<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 ); ?>" />
|
238 |
-
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
239 |
-
<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 ); ?>" />
|
240 |
-
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
241 |
-
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
242 |
-
</div><!-- .menu-item-settings-->
|
243 |
-
<ul class="menu-item-transport"></ul>
|
244 |
-
<?php
|
245 |
-
$output .= ob_get_clean();
|
246 |
-
}
|
247 |
-
|
248 |
-
} // Walker_Nav_Menu_Edit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Custom Walker for Nav Menu Editor
|
4 |
-
* Add wp_nav_menu_item_custom_fields hook
|
5 |
-
* Hat tip to @kucrut and Menu Icons for the preg_replace() idea
|
6 |
-
* means I no longer have to translate core strings
|
7 |
-
*
|
8 |
-
* @package Nav Menu Roles
|
9 |
-
* @since 1.8.6
|
10 |
-
* @uses Walker_Nav_Menu_Edit
|
11 |
-
*/
|
12 |
-
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu_Edit {
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Start the element output.
|
16 |
-
*
|
17 |
-
* @see Walker_Nav_Menu::start_el()
|
18 |
-
*
|
19 |
-
* @param string $output Passed by reference. Used to append additional content.
|
20 |
-
* @param object $item Menu item data object.
|
21 |
-
* @param int $depth Depth of menu item. Used for padding.
|
22 |
-
* @param array $args Not used.
|
23 |
-
* @param int $id Not used.
|
24 |
-
*/
|
25 |
-
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
26 |
-
$item_output = '';
|
27 |
-
$output .= parent::start_el( $item_output, $item, $depth, $args, $id );
|
28 |
-
$output .= preg_replace(
|
29 |
-
// NOTE: Check this regex on major WP version updates!
|
30 |
-
'/(?=<fieldset[^>]+class="[^"]*field-move)/',
|
31 |
-
$this->get_custom_fields( $item, $depth, $args ),
|
32 |
-
$item_output
|
33 |
-
);
|
34 |
-
}
|
35 |
-
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Get custom fields
|
39 |
-
*
|
40 |
-
* @access protected
|
41 |
-
* @since 0.1.0
|
42 |
-
* @uses do_action() Calls 'menu_item_custom_fields' hook
|
43 |
-
*
|
44 |
-
* @param object $item Menu item data object.
|
45 |
-
* @param int $depth Depth of menu item. Used for padding.
|
46 |
-
* @param array $args Menu item args.
|
47 |
-
* @param int $id Nav menu ID.
|
48 |
-
*
|
49 |
-
* @return string Form fields
|
50 |
-
*/
|
51 |
-
protected function get_custom_fields( $item, $depth, $args = array(), $id = 0 ) {
|
52 |
-
ob_start();
|
53 |
-
$item_id = intval( $item->ID );
|
54 |
-
/**
|
55 |
-
* Get menu item custom fields from plugins/themes
|
56 |
-
*
|
57 |
-
* @since 0.1.0
|
58 |
-
*
|
59 |
-
* @param int $item_id post ID of menu
|
60 |
-
* @param object $item Menu item data object.
|
61 |
-
* @param int $depth Depth of menu item. Used for padding.
|
62 |
-
* @param array $args Menu item args.
|
63 |
-
*
|
64 |
-
* @return string Custom fields
|
65 |
-
*/
|
66 |
-
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
67 |
-
return ob_get_clean();
|
68 |
-
}
|
69 |
-
} // Walker_Nav_Menu_Edit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/customizer.php
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Nav Menu Roles - Customizer
|
4 |
+
*
|
5 |
+
* @since 2.0.0
|
6 |
+
* @package Nav Menu Roles\Includes
|
7 |
+
* @link https://wordpress.stackexchange.com/questions/372493/add-settings-to-menu-items-in-the-customizer
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace Customize_Nav_Menu_Roles;
|
12 |
+
|
13 |
+
use WP_Customize_Manager;
|
14 |
+
use WP_Customize_Nav_Menu_Item_Setting;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Hooks.
|
18 |
+
*/
|
19 |
+
|
20 |
+
// Add new fields in the Customizer.
|
21 |
+
add_action( 'wp_nav_menu_item_custom_fields_customize_template', __NAMESPACE__ . '\customizer_custom_fields' );
|
22 |
+
|
23 |
+
// Add some JS.
|
24 |
+
add_action( 'customize_controls_enqueue_scripts', __NAMESPACE__ . '\customizer_scripts' );
|
25 |
+
|
26 |
+
// Workaround for previewing changes.
|
27 |
+
add_action( 'customize_register', __NAMESPACE__ . '\customizer_preview', 1000 );
|
28 |
+
|
29 |
+
// Workaround for saving changes.
|
30 |
+
add_action( 'customize_save_after', __NAMESPACE__ . '\customizer_save' );
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Display the fields in the Customizer.
|
35 |
+
*/
|
36 |
+
function customizer_custom_fields() {
|
37 |
+
|
38 |
+
global $wp_roles;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Pass the menu item to the filter function.
|
42 |
+
* This change is suggested as it allows the use of information from the menu item (and
|
43 |
+
* by extension the target object) to further customize what filters appear during menu
|
44 |
+
* construction.
|
45 |
+
*/
|
46 |
+
$display_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
|
47 |
+
|
48 |
+
if ( ! $display_roles ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
+
|
52 |
+
?>
|
53 |
+
<fieldset class="nav_menu_role_authentication">
|
54 |
+
<legend class="customize-control-title"><?php esc_html_e( 'Display Mode', 'nav-menu-roles' ); ?></legend>
|
55 |
+
|
56 |
+
<label for="edit-menu-item-role_logged_in-{{ data.menu_item_id }}">
|
57 |
+
<input type="radio" id="edit-menu-item-role_logged_in-{{ data.menu_item_id }}" value="in" name="menu-item-role-{{ data.menu_item_id }}" />
|
58 |
+
<?php esc_html_e( 'Logged In Users', 'nav-menu-roles' ); ?><br/>
|
59 |
+
</label>
|
60 |
+
<label for="edit-menu-item-role_logged_out-{{ data.menu_item_id }}">
|
61 |
+
<input type="radio" id="edit-menu-item-role_logged_out-{{ data.menu_item_id }}" value="out" name="menu-item-role-{{ data.menu_item_id }}" />
|
62 |
+
<?php esc_html_e( 'Logged Out Users', 'nav-menu-roles' ); ?><br/>
|
63 |
+
</label>
|
64 |
+
<label for="edit-menu-item-role_everyone-{{ data.menu_item_id }}">
|
65 |
+
<input type="radio" id="edit-menu-item-role_everyone-{{ data.menu_item_id }}" value="" name="menu-item-role-{{ data.menu_item_id }}" />
|
66 |
+
<?php esc_html_e( 'Everyone', 'nav-menu-roles' ); ?><br/>
|
67 |
+
</label>
|
68 |
+
</fieldset>
|
69 |
+
|
70 |
+
<fieldset class="nav_menu_roles">
|
71 |
+
<legend class="customize-control-title"><?php esc_html_e( 'Restrict menu item to minimum role', 'nav-menu-roles' ); ?></legend>
|
72 |
+
|
73 |
+
<?php foreach ( $display_roles as $role => $name ) : ?>
|
74 |
+
<label for="edit-menu-item-role_<?php echo esc_attr( $role ); ?>-{{ data.menu_item_id }}">
|
75 |
+
<input type="checkbox" id="edit-menu-item-role_<?php echo esc_attr( $role ); ?>-{{ data.menu_item_id }}" class="edit-menu-item-role" value="<?php echo esc_attr( $role ); ?>" />
|
76 |
+
<?php echo esc_html( $name ); ?><br/>
|
77 |
+
</label>
|
78 |
+
<?php endforeach; ?>
|
79 |
+
|
80 |
+
</fieldset>
|
81 |
+
<?php
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Load the customizer scripts which extends nav menu item controls.
|
86 |
+
*/
|
87 |
+
function customizer_scripts() {
|
88 |
+
wp_enqueue_script(
|
89 |
+
'customize-nav-menu-roles',
|
90 |
+
plugins_url( 'dist/js/customize.js', dirname( __FILE__ ) ),
|
91 |
+
array( 'customize-nav-menus' ),
|
92 |
+
\Nav_Menu_Roles::VERSION,
|
93 |
+
true
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Get posted value for a setting's roles.
|
99 |
+
*
|
100 |
+
* @param WP_Customize_Nav_Menu_Item_Setting $setting Setting.
|
101 |
+
*
|
102 |
+
* @return array|string|null Roles value or null if no posted value present.
|
103 |
+
*/
|
104 |
+
function get_roles_post_data( WP_Customize_Nav_Menu_Item_Setting $setting ) {
|
105 |
+
if ( ! $setting->post_value() ) {
|
106 |
+
return null;
|
107 |
+
}
|
108 |
+
|
109 |
+
$unsanitized_post_value = $setting->manager->unsanitized_post_values()[ $setting->id ];
|
110 |
+
return isset( $unsanitized_post_value['roles'] ) ? $unsanitized_post_value['roles'] : '';
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Preview changes to the nav menu item roles.
|
115 |
+
*
|
116 |
+
* Note the unimplemented to-do in the doc block for the setting's preview method.
|
117 |
+
*
|
118 |
+
* @see WP_Customize_Nav_Menu_Item_Setting::preview()
|
119 |
+
*
|
120 |
+
* @param WP_Customize_Nav_Menu_Item_Setting $setting Setting.
|
121 |
+
*/
|
122 |
+
function preview_nav_menu_setting_postmeta( WP_Customize_Nav_Menu_Item_Setting $setting ) {
|
123 |
+
$roles = get_roles_post_data( $setting );
|
124 |
+
if ( null === $roles ) {
|
125 |
+
return;
|
126 |
+
}
|
127 |
+
|
128 |
+
$roles = Nav_Menu_Roles()->sanitize_meta( $roles );
|
129 |
+
|
130 |
+
add_filter(
|
131 |
+
'get_post_metadata',
|
132 |
+
static function ( $value, $object_id, $meta_key ) use ( $setting, $roles ) {
|
133 |
+
if ( $object_id === $setting->post_id && '_nav_menu_role' === $meta_key ) {
|
134 |
+
return array( $roles );
|
135 |
+
}
|
136 |
+
return $value;
|
137 |
+
},
|
138 |
+
10,
|
139 |
+
3
|
140 |
+
);
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Save changes to the nav menu item roles.
|
145 |
+
*
|
146 |
+
* Note the unimplemented to-do in the doc block for the setting's preview method.
|
147 |
+
*
|
148 |
+
* @see WP_Customize_Nav_Menu_Item_Setting::update()
|
149 |
+
*
|
150 |
+
* @param WP_Customize_Nav_Menu_Item_Setting $setting Setting.
|
151 |
+
*/
|
152 |
+
function save_nav_menu_setting_postmeta( WP_Customize_Nav_Menu_Item_Setting $setting ) {
|
153 |
+
$roles = get_roles_post_data( $setting );
|
154 |
+
if ( null !== $roles ) {
|
155 |
+
update_post_meta( $setting->post_id, '_nav_menu_role', $roles );
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
// Set up previewing.
|
160 |
+
function customizer_preview( WP_Customize_Manager $wp_customize ) {
|
161 |
+
if ( $wp_customize->settings_previewed() ) {
|
162 |
+
foreach ( $wp_customize->settings() as $setting ) {
|
163 |
+
if ( $setting instanceof WP_Customize_Nav_Menu_Item_Setting ) {
|
164 |
+
preview_nav_menu_setting_postmeta( $setting );
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Set up saving.
|
172 |
+
*/
|
173 |
+
function customizer_save( WP_Customize_Manager $wp_customize ) {
|
174 |
+
foreach ( $wp_customize->settings() as $setting ) {
|
175 |
+
if ( $setting instanceof WP_Customize_Nav_Menu_Item_Setting && $setting->check_capabilities() ) {
|
176 |
+
save_nav_menu_setting_postmeta( $setting );
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
js/nav-menu-roles.js
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
;(function($) {
|
2 |
-
|
3 |
-
$('.nav_menu_logged_in_out_field').each(function(i){
|
4 |
-
|
5 |
-
var $field = $(this);
|
6 |
-
|
7 |
-
var id = $field.find('input.nav-menu-id').val();
|
8 |
-
|
9 |
-
// if set to display by role (aka is null) then show the roles list, otherwise hide
|
10 |
-
if( $field.find('input.nav-menu-logged-in-out:checked').val() === 'in' ){
|
11 |
-
$field.next('.nav_menu_role_field').show();
|
12 |
-
} else {
|
13 |
-
$field.next('.nav_menu_role_field').hide();
|
14 |
-
}
|
15 |
-
});
|
16 |
-
|
17 |
-
// on in/out/role change, hide/show the roles
|
18 |
-
$('#menu-to-edit').on('change', 'input.nav-menu-logged-in-out', function() {
|
19 |
-
if( $(this).val() === 'in' ){
|
20 |
-
$(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideDown();
|
21 |
-
} else {
|
22 |
-
$(this).parentsUntil('.nav_menu_logged_in_out').next('.nav_menu_role_field').slideUp();
|
23 |
-
}
|
24 |
-
});
|
25 |
-
|
26 |
-
|
27 |
-
})(jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/nav-menu-roles.min.js
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
/*! nav-menu-roles 1.8.6 */
|
2 |
-
!function(a){a(".nav_menu_logged_in_out_field").each(function(b){var c=a(this);c.find("input.nav-menu-id").val();"in"===c.find("input.nav-menu-logged-in-out:checked").val()?c.next(".nav_menu_role_field").show():c.next(".nav_menu_role_field").hide()}),a("#menu-to-edit").on("change","input.nav-menu-logged-in-out",function(){"in"===a(this).val()?a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideDown():a(this).parentsUntil(".nav_menu_logged_in_out").next(".nav_menu_role_field").slideUp()})}(jQuery);
|
|
|
|
languages/nav-menu-roles.pot
CHANGED
@@ -1,227 +1,235 @@
|
|
1 |
-
# Copyright (C)
|
2 |
# This file is distributed under the GPL-3.0.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: Nav Menu Roles
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nav-menu-roles\n"
|
7 |
-
"POT-Creation-Date:
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=utf-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
11 |
-
"PO-Revision-Date:
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
-
"X-Generator: grunt-wp-i18n 0.
|
15 |
|
16 |
-
#: inc/class.
|
17 |
-
#: inc/class.
|
18 |
-
#: inc/class.
|
19 |
-
#: inc/class.
|
20 |
-
#: inc/class.
|
21 |
msgid "Sorry, there has been an error."
|
22 |
msgstr ""
|
23 |
|
24 |
-
#: inc/class.
|
25 |
msgid "The file does not exist, please try again."
|
26 |
msgstr ""
|
27 |
|
28 |
-
#: inc/class.
|
29 |
msgid "All done."
|
30 |
msgstr ""
|
31 |
|
32 |
-
#: inc/class.
|
33 |
msgid "Have fun!"
|
34 |
msgstr ""
|
35 |
|
36 |
-
#: inc/class.
|
37 |
msgid ""
|
38 |
-
"The export file could not be found at
|
39 |
-
"
|
40 |
msgstr ""
|
41 |
|
42 |
-
#: inc/class.
|
43 |
msgid ""
|
44 |
"This WXR file (version %s) may not be supported by this version of the "
|
45 |
"importer. Please consider updating."
|
46 |
msgstr ""
|
47 |
|
48 |
-
#: inc/class.
|
49 |
msgid "Import Nav Menu Roles"
|
50 |
msgstr ""
|
51 |
|
52 |
-
#: inc/class.
|
53 |
msgid ""
|
54 |
"A new version of this importer is available. Please update to version %s to "
|
55 |
"ensure compatibility with newer export files."
|
56 |
msgstr ""
|
57 |
|
58 |
-
#: inc/class.
|
59 |
msgid ""
|
60 |
"Re-Upload your normal WordPress eXtended RSS (WXR) file and we’ll "
|
61 |
"import the Nav Menu Roles and any other missing post meta for the Nav Menu "
|
62 |
"items."
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: inc/class.
|
66 |
msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: inc/class.
|
70 |
-
#: inc/class.
|
71 |
#. translators: %s: title of menu item which is invalid
|
72 |
msgid "%s (Invalid)"
|
73 |
msgstr ""
|
74 |
|
75 |
-
#: inc/class.
|
76 |
-
#: inc/class.
|
77 |
#. translators: %s: title of menu item in draft status
|
78 |
msgid "%s (Pending)"
|
79 |
msgstr ""
|
80 |
|
81 |
-
#: inc/class.
|
82 |
-
#: inc/class.
|
83 |
msgid "sub item"
|
84 |
msgstr ""
|
85 |
|
86 |
-
#: inc/class.
|
87 |
-
#: inc/class.
|
88 |
msgid "Move up"
|
89 |
msgstr ""
|
90 |
|
91 |
-
#: inc/class.
|
92 |
-
#: inc/class.
|
93 |
msgid "Move down"
|
94 |
msgstr ""
|
95 |
|
96 |
-
#: inc/class.
|
97 |
-
|
98 |
-
msgid "Edit Menu Item"
|
99 |
msgstr ""
|
100 |
|
101 |
-
#: inc/class.
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
msgid "URL"
|
104 |
msgstr ""
|
105 |
|
106 |
-
#: inc/class.
|
107 |
-
#: inc/class.
|
108 |
msgid "Navigation Label"
|
109 |
msgstr ""
|
110 |
|
111 |
-
#: inc/class.
|
112 |
-
#: inc/class.
|
113 |
msgid "Title Attribute"
|
114 |
msgstr ""
|
115 |
|
116 |
-
#: inc/class.
|
117 |
-
#: inc/class.
|
118 |
msgid "Open link in a new tab"
|
119 |
msgstr ""
|
120 |
|
121 |
-
#: inc/class.
|
122 |
-
#: inc/class.
|
123 |
msgid "CSS Classes (optional)"
|
124 |
msgstr ""
|
125 |
|
126 |
-
#: inc/class.
|
127 |
-
#: inc/class.
|
128 |
msgid "Link Relationship (XFN)"
|
129 |
msgstr ""
|
130 |
|
131 |
-
#: inc/class.
|
132 |
-
#: inc/class.
|
133 |
msgid "Description"
|
134 |
msgstr ""
|
135 |
|
136 |
-
#: inc/class.
|
137 |
-
#: inc/class.
|
138 |
msgid ""
|
139 |
"The description will be displayed in the menu if the current theme supports "
|
140 |
"it."
|
141 |
msgstr ""
|
142 |
|
143 |
-
#: inc/class.
|
144 |
-
#: inc/class.
|
145 |
msgid "Move"
|
146 |
msgstr ""
|
147 |
|
148 |
-
#: inc/class.
|
149 |
-
#: inc/class.
|
150 |
msgid "Up one"
|
151 |
msgstr ""
|
152 |
|
153 |
-
#: inc/class.
|
154 |
-
#: inc/class.
|
155 |
msgid "Down one"
|
156 |
msgstr ""
|
157 |
|
158 |
-
#: inc/class.
|
159 |
-
#: inc/class.
|
160 |
msgid "To the top"
|
161 |
msgstr ""
|
162 |
|
163 |
-
#: inc/class.
|
164 |
-
#: inc/class.
|
165 |
msgid "Original: %s"
|
166 |
msgstr ""
|
167 |
|
168 |
-
#: inc/class.
|
169 |
-
#: inc/class.
|
170 |
msgid "Remove"
|
171 |
msgstr ""
|
172 |
|
173 |
-
#: inc/class.
|
174 |
-
#: inc/class.
|
175 |
msgid "Cancel"
|
176 |
msgstr ""
|
177 |
|
178 |
-
#: inc/class.
|
179 |
-
|
|
|
180 |
msgstr ""
|
181 |
|
182 |
-
#: inc/
|
183 |
-
msgid "
|
184 |
msgstr ""
|
185 |
|
186 |
-
#:
|
187 |
-
msgid "
|
188 |
msgstr ""
|
189 |
|
190 |
-
|
191 |
-
msgid "
|
192 |
msgstr ""
|
193 |
|
194 |
-
#: nav-menu-roles.php:
|
195 |
-
msgid ""
|
196 |
-
"Import %snav menu roles%s and other menu item meta skipped by the default "
|
197 |
-
"importer"
|
198 |
msgstr ""
|
199 |
|
200 |
-
#:
|
201 |
-
msgid "
|
202 |
msgstr ""
|
203 |
|
204 |
-
#: nav-menu-roles.php:
|
205 |
-
msgid "
|
206 |
msgstr ""
|
207 |
|
208 |
-
#: nav-menu-roles.php:
|
209 |
-
msgid "
|
210 |
msgstr ""
|
211 |
|
212 |
-
|
213 |
-
msgid "
|
214 |
msgstr ""
|
215 |
|
216 |
-
#: nav-menu-roles.php:
|
217 |
-
msgid "
|
|
|
|
|
218 |
msgstr ""
|
219 |
|
220 |
-
#: nav-menu-roles.php:
|
221 |
-
msgid "
|
|
|
|
|
|
|
|
|
222 |
msgstr ""
|
223 |
|
224 |
-
#: nav-menu-roles.php:
|
225 |
msgid "Restrict menu item to a minimum role"
|
226 |
msgstr ""
|
227 |
|
1 |
+
# Copyright (C) 2020 Kathy Darling
|
2 |
# This file is distributed under the GPL-3.0.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: Nav Menu Roles 2.0.0\n"
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nav-menu-roles\n"
|
7 |
+
"POT-Creation-Date: 2020-08-29 16:40:52+00:00\n"
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=utf-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
+
"X-Generator: grunt-wp-i18n 1.0.3\n"
|
15 |
|
16 |
+
#: inc/class-nav-menu-roles-import.php:114
|
17 |
+
#: inc/class-nav-menu-roles-import.php:123
|
18 |
+
#: inc/class-nav-menu-roles-import.php:169
|
19 |
+
#: inc/class-nav-menu-roles-import.php:173
|
20 |
+
#: inc/class-nav-menu-roles-import.php:183
|
21 |
msgid "Sorry, there has been an error."
|
22 |
msgstr ""
|
23 |
|
24 |
+
#: inc/class-nav-menu-roles-import.php:115
|
25 |
msgid "The file does not exist, please try again."
|
26 |
msgstr ""
|
27 |
|
28 |
+
#: inc/class-nav-menu-roles-import.php:154
|
29 |
msgid "All done."
|
30 |
msgstr ""
|
31 |
|
32 |
+
#: inc/class-nav-menu-roles-import.php:154
|
33 |
msgid "Have fun!"
|
34 |
msgstr ""
|
35 |
|
36 |
+
#: inc/class-nav-menu-roles-import.php:175
|
37 |
msgid ""
|
38 |
+
"The export file could not be found at %s. It is likely that this was caused "
|
39 |
+
"by a permissions problem."
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: inc/class-nav-menu-roles-import.php:191
|
43 |
msgid ""
|
44 |
"This WXR file (version %s) may not be supported by this version of the "
|
45 |
"importer. Please consider updating."
|
46 |
msgstr ""
|
47 |
|
48 |
+
#: inc/class-nav-menu-roles-import.php:259
|
49 |
msgid "Import Nav Menu Roles"
|
50 |
msgstr ""
|
51 |
|
52 |
+
#: inc/class-nav-menu-roles-import.php:266
|
53 |
msgid ""
|
54 |
"A new version of this importer is available. Please update to version %s to "
|
55 |
"ensure compatibility with newer export files."
|
56 |
msgstr ""
|
57 |
|
58 |
+
#: inc/class-nav-menu-roles-import.php:281
|
59 |
msgid ""
|
60 |
"Re-Upload your normal WordPress eXtended RSS (WXR) file and we’ll "
|
61 |
"import the Nav Menu Roles and any other missing post meta for the Nav Menu "
|
62 |
"items."
|
63 |
msgstr ""
|
64 |
|
65 |
+
#: inc/class-nav-menu-roles-import.php:282
|
66 |
msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
|
67 |
msgstr ""
|
68 |
|
69 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:101
|
70 |
+
#: inc/class-walker-nav-menu-edit-roles.php:109
|
71 |
#. translators: %s: title of menu item which is invalid
|
72 |
msgid "%s (Invalid)"
|
73 |
msgstr ""
|
74 |
|
75 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:105
|
76 |
+
#: inc/class-walker-nav-menu-edit-roles.php:113
|
77 |
#. translators: %s: title of menu item in draft status
|
78 |
msgid "%s (Pending)"
|
79 |
msgstr ""
|
80 |
|
81 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:119
|
82 |
+
#: inc/class-walker-nav-menu-edit-roles.php:128
|
83 |
msgid "sub item"
|
84 |
msgstr ""
|
85 |
|
86 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:136
|
87 |
+
#: inc/class-walker-nav-menu-edit-roles.php:143
|
88 |
msgid "Move up"
|
89 |
msgstr ""
|
90 |
|
91 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:151
|
92 |
+
#: inc/class-walker-nav-menu-edit-roles.php:156
|
93 |
msgid "Move down"
|
94 |
msgstr ""
|
95 |
|
96 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:157
|
97 |
+
msgid "Edit menu item"
|
|
|
98 |
msgstr ""
|
99 |
|
100 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:157
|
101 |
+
msgid "Edit"
|
102 |
+
msgstr ""
|
103 |
+
|
104 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:166
|
105 |
+
#: inc/class-walker-nav-menu-edit-roles.php:169
|
106 |
msgid "URL"
|
107 |
msgstr ""
|
108 |
|
109 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:173
|
110 |
+
#: inc/class-walker-nav-menu-edit-roles.php:176
|
111 |
msgid "Navigation Label"
|
112 |
msgstr ""
|
113 |
|
114 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:179
|
115 |
+
#: inc/class-walker-nav-menu-edit-roles.php:182
|
116 |
msgid "Title Attribute"
|
117 |
msgstr ""
|
118 |
|
119 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:186
|
120 |
+
#: inc/class-walker-nav-menu-edit-roles.php:189
|
121 |
msgid "Open link in a new tab"
|
122 |
msgstr ""
|
123 |
|
124 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:191
|
125 |
+
#: inc/class-walker-nav-menu-edit-roles.php:194
|
126 |
msgid "CSS Classes (optional)"
|
127 |
msgstr ""
|
128 |
|
129 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:197
|
130 |
+
#: inc/class-walker-nav-menu-edit-roles.php:200
|
131 |
msgid "Link Relationship (XFN)"
|
132 |
msgstr ""
|
133 |
|
134 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:203
|
135 |
+
#: inc/class-walker-nav-menu-edit-roles.php:206
|
136 |
msgid "Description"
|
137 |
msgstr ""
|
138 |
|
139 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:205
|
140 |
+
#: inc/class-walker-nav-menu-edit-roles.php:208
|
141 |
msgid ""
|
142 |
"The description will be displayed in the menu if the current theme supports "
|
143 |
"it."
|
144 |
msgstr ""
|
145 |
|
146 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:217
|
147 |
+
#: inc/class-walker-nav-menu-edit-roles.php:220
|
148 |
msgid "Move"
|
149 |
msgstr ""
|
150 |
|
151 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:218
|
152 |
+
#: inc/class-walker-nav-menu-edit-roles.php:221
|
153 |
msgid "Up one"
|
154 |
msgstr ""
|
155 |
|
156 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:219
|
157 |
+
#: inc/class-walker-nav-menu-edit-roles.php:222
|
158 |
msgid "Down one"
|
159 |
msgstr ""
|
160 |
|
161 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:222
|
162 |
+
#: inc/class-walker-nav-menu-edit-roles.php:225
|
163 |
msgid "To the top"
|
164 |
msgstr ""
|
165 |
|
166 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:229
|
167 |
+
#: inc/class-walker-nav-menu-edit-roles.php:232
|
168 |
msgid "Original: %s"
|
169 |
msgstr ""
|
170 |
|
171 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:245
|
172 |
+
#: inc/class-walker-nav-menu-edit-roles.php:246
|
173 |
msgid "Remove"
|
174 |
msgstr ""
|
175 |
|
176 |
+
#: inc/class-walker-nav-menu-edit-roles-4.5.php:252
|
177 |
+
#: inc/class-walker-nav-menu-edit-roles.php:258
|
178 |
msgid "Cancel"
|
179 |
msgstr ""
|
180 |
|
181 |
+
#: inc/class-walker-nav-menu-edit-roles.php:158
|
182 |
+
#: inc/class-walker-nav-menu-edit-roles.php:160
|
183 |
+
msgid "Edit Menu Item"
|
184 |
msgstr ""
|
185 |
|
186 |
+
#: inc/customizer.php:54 nav-menu-roles.php:368
|
187 |
+
msgid "Display Mode"
|
188 |
msgstr ""
|
189 |
|
190 |
+
#: inc/customizer.php:58 nav-menu-roles.php:374
|
191 |
+
msgid "Logged In Users"
|
192 |
msgstr ""
|
193 |
|
194 |
+
#: inc/customizer.php:62 nav-menu-roles.php:379
|
195 |
+
msgid "Logged Out Users"
|
196 |
msgstr ""
|
197 |
|
198 |
+
#: inc/customizer.php:66 nav-menu-roles.php:384
|
199 |
+
msgid "Everyone"
|
|
|
|
|
200 |
msgstr ""
|
201 |
|
202 |
+
#: inc/customizer.php:71
|
203 |
+
msgid "Restrict menu item to minimum role"
|
204 |
msgstr ""
|
205 |
|
206 |
+
#: nav-menu-roles.php:83
|
207 |
+
msgid "Cloning this object is forbidden."
|
208 |
msgstr ""
|
209 |
|
210 |
+
#: nav-menu-roles.php:92
|
211 |
+
msgid "Unserializing instances of this class is forbidden."
|
212 |
msgstr ""
|
213 |
|
214 |
+
#. Plugin Name of the plugin/theme
|
215 |
+
msgid "Nav Menu Roles"
|
216 |
msgstr ""
|
217 |
|
218 |
+
#: nav-menu-roles.php:174
|
219 |
+
msgid ""
|
220 |
+
"Import <strong>nav menu roles</strong> and other menu item meta skipped by "
|
221 |
+
"the default importer"
|
222 |
msgstr ""
|
223 |
|
224 |
+
#: nav-menu-roles.php:284
|
225 |
+
msgid "FAQ"
|
226 |
+
msgstr ""
|
227 |
+
|
228 |
+
#: nav-menu-roles.php:285
|
229 |
+
msgid "Donate"
|
230 |
msgstr ""
|
231 |
|
232 |
+
#: nav-menu-roles.php:390
|
233 |
msgid "Restrict menu item to a minimum role"
|
234 |
msgstr ""
|
235 |
|
nav-menu-roles.php
CHANGED
@@ -1,30 +1,31 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
Plugin Name: Nav Menu Roles
|
4 |
-
Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
|
5 |
-
Description: Hide custom menu items based on user roles.
|
6 |
-
Version:
|
7 |
-
Author: Kathy Darling
|
8 |
-
Author URI: http://www.kathyisawesome.com
|
9 |
-
License: GPL-3.0
|
10 |
-
Text Domain: nav-menu-roles
|
11 |
-
|
12 |
-
Copyright 2020 Kathy Darling
|
13 |
-
|
14 |
-
This program is free software; you can redistribute it and/or modify
|
15 |
-
it under the terms of the GNU General Public License, version 2, as
|
16 |
-
published by the Free Software Foundation.
|
17 |
-
|
18 |
-
This program is distributed in the hope that it will be useful,
|
19 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
21 |
-
GNU General Public License for more details.
|
22 |
-
|
23 |
-
You should have received a copy of the GNU General Public License
|
24 |
-
along with this program; if not, write to the Free Software
|
25 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
|
26 |
-
|
27 |
-
|
|
|
28 |
|
29 |
// Don't load directly.
|
30 |
if ( ! function_exists( 'is_admin' ) ) {
|
@@ -33,39 +34,39 @@ if ( ! function_exists( 'is_admin' ) ) {
|
|
33 |
exit();
|
34 |
}
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
class Nav_Menu_Roles {
|
40 |
|
41 |
/**
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
protected static $_instance = null;
|
46 |
|
47 |
/**
|
48 |
* @constant string donate url
|
49 |
* @since 1.9.1
|
50 |
*/
|
51 |
-
|
52 |
|
53 |
/**
|
54 |
* @constant string version number
|
55 |
* @since 1.7.0
|
56 |
*/
|
57 |
-
|
58 |
|
59 |
/**
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
public static function instance() {
|
70 |
if ( is_null( self::$_instance ) ) {
|
71 |
self::$_instance = new self();
|
@@ -74,30 +75,32 @@ class Nav_Menu_Roles {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
public function __clone() {
|
82 |
-
_doing_it_wrong( __FUNCTION__,
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
public function __wakeup() {
|
91 |
-
_doing_it_wrong( __FUNCTION__,
|
92 |
}
|
93 |
|
94 |
/**
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
public function __construct(){
|
|
|
|
|
101 |
|
102 |
// Admin functions.
|
103 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
@@ -105,11 +108,14 @@ class Nav_Menu_Roles {
|
|
105 |
// Load the textdomain.
|
106 |
add_action( 'init', array( $this, 'load_text_domain' ) );
|
107 |
|
|
|
|
|
|
|
108 |
// Add FAQ and Donate link to plugin.
|
109 |
add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
|
110 |
|
111 |
// Maybe switch the admin walker.
|
112 |
-
if( ! self::is_wp_gte( '5.4' ) ) {
|
113 |
add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
|
114 |
}
|
115 |
|
@@ -117,10 +123,10 @@ class Nav_Menu_Roles {
|
|
117 |
add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
|
118 |
|
119 |
// Add some JS.
|
120 |
-
add_action( 'admin_enqueue_scripts'
|
121 |
|
122 |
// Save the menu item meta.
|
123 |
-
add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update'), 10, 2 );
|
124 |
|
125 |
// Add meta to menu item.
|
126 |
add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
|
@@ -137,11 +143,11 @@ class Nav_Menu_Roles {
|
|
137 |
}
|
138 |
|
139 |
/**
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
public function admin_init() {
|
146 |
|
147 |
// Register Importer.
|
@@ -151,63 +157,115 @@ class Nav_Menu_Roles {
|
|
151 |
|
152 |
|
153 |
/**
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
public function register_importer(){
|
161 |
// Register the new importer.
|
162 |
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
|
163 |
|
164 |
-
include_once
|
165 |
// Register the custom importer we've created.
|
166 |
$roles_import = new Nav_Menu_Roles_Import();
|
167 |
|
168 |
-
register_importer( 'nav_menu_roles', __( 'Nav Menu Roles', 'nav-menu-roles' ),
|
169 |
|
170 |
}
|
171 |
|
172 |
}
|
173 |
|
174 |
/**
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
public function load_text_domain() {
|
180 |
load_plugin_textdomain( 'nav-menu-roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
181 |
}
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
/**
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
public function admin_notice() {
|
191 |
_deprecated_function( __METHOD__, '1.7.8' );
|
192 |
}
|
193 |
|
194 |
|
195 |
/**
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
public function nag_ignore() {
|
202 |
_deprecated_function( __METHOD__, '1.7.8' );
|
203 |
}
|
204 |
|
205 |
/**
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
public function delete_transient() {
|
212 |
_deprecated_function( __METHOD__, '1.7.8' );
|
213 |
delete_transient( 'nav_menu_roles_conflicts' );
|
@@ -215,14 +273,14 @@ class Nav_Menu_Roles {
|
|
215 |
|
216 |
|
217 |
/**
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
public function add_action_links( $plugin_meta, $plugin_file ) {
|
225 |
-
if(
|
226 |
$plugin_meta[] = sprintf( '<a class="dashicons-before dashicons-welcome-learn-more" href="https://wordpress.org/plugins/nav-menu-roles/faq/#conflict">%s</a>', __( 'FAQ', 'nav-menu-roles' ) );
|
227 |
$plugin_meta[] = '<a class="dashicons-before dashicons-admin-generic" href="' . self::DONATE_URL . '" target="_blank">' . __( 'Donate', 'nav-menu-roles' ) . '</a>';
|
228 |
}
|
@@ -231,32 +289,32 @@ class Nav_Menu_Roles {
|
|
231 |
|
232 |
|
233 |
/**
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
public function edit_nav_menu_walker( $walker ) {
|
239 |
-
if( ! class_exists( 'Walker_Nav_Menu_Edit_Roles' ) ) {
|
240 |
|
241 |
-
|
242 |
-
require_once
|
243 |
-
}
|
244 |
-
require_once
|
245 |
} else {
|
246 |
-
require_once
|
247 |
}
|
248 |
-
|
249 |
return 'Walker_Nav_Menu_Edit_Roles';
|
250 |
}
|
251 |
|
252 |
|
253 |
/**
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
public function custom_fields( $item_id, $item, $depth, $args ) {
|
261 |
global $wp_roles;
|
262 |
|
@@ -277,7 +335,9 @@ class Nav_Menu_Roles {
|
|
277 |
* permissions to the menu from accidentally removing all restrictions from a menu item to
|
278 |
* which they do not have access.
|
279 |
*/
|
280 |
-
if( ! $display_roles )
|
|
|
|
|
281 |
|
282 |
/* Get the roles saved for the post. */
|
283 |
$roles = get_post_meta( $item->ID, '_nav_menu_role', true );
|
@@ -286,9 +346,9 @@ class Nav_Menu_Roles {
|
|
286 |
$logged_in_out = '';
|
287 |
|
288 |
// Specific roles are saved as an array, so "in" or an array equals "in" is checked.
|
289 |
-
if( is_array( $roles ) ||
|
290 |
$logged_in_out = 'in';
|
291 |
-
}
|
292 |
$logged_in_out = 'out';
|
293 |
}
|
294 |
|
@@ -296,137 +356,113 @@ class Nav_Menu_Roles {
|
|
296 |
$checked_roles = is_array( $roles ) ? $roles : false;
|
297 |
|
298 |
// Whether to display the role checkboxes.
|
299 |
-
$hidden =
|
300 |
|
301 |
-
|
302 |
-
|
303 |
-
<input type="hidden" name="nav-menu-role-nonce" value="<?php echo wp_create_nonce( 'nav-menu-nonce-name' ); ?>" />
|
304 |
|
305 |
-
|
306 |
-
<span class="description"><?php _e( "Display Mode", 'nav-menu-roles' ); ?></span>
|
307 |
-
<br />
|
308 |
|
309 |
-
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
<label for="nav_menu_logged_in-for-<?php echo $item->ID ;?>">
|
314 |
-
<?php _e( 'Logged In Users', 'nav-menu-roles'); ?>
|
315 |
-
</label>
|
316 |
-
</div>
|
317 |
|
318 |
-
|
319 |
-
<input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo $item->ID ;?>]" id="nav_menu_logged_out-for-<?php echo $item->ID ;?>" <?php checked( 'out', $logged_in_out ); ?> value="out" />
|
320 |
-
<label for="nav_menu_logged_out-for-<?php echo $item->ID ;?>">
|
321 |
-
<?php _e( 'Logged Out Users', 'nav-menu-roles'); ?>
|
322 |
-
</label>
|
323 |
-
</div>
|
324 |
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
|
|
|
|
|
|
331 |
|
332 |
-
|
|
|
|
|
|
|
333 |
|
334 |
-
|
335 |
-
<span class="description"><?php _e( "Restrict menu item to a minimum role", 'nav-menu-roles' ); ?></span>
|
336 |
-
<br />
|
337 |
|
338 |
-
|
|
|
|
|
339 |
|
340 |
-
|
341 |
|
342 |
-
|
343 |
-
foreach ( $display_roles as $role => $name ) {
|
344 |
|
345 |
-
|
346 |
-
|
347 |
|
348 |
-
|
|
|
|
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
</label>
|
356 |
-
</div>
|
357 |
|
358 |
<?php } ?>
|
359 |
|
360 |
-
</
|
361 |
|
362 |
<?php
|
363 |
}
|
364 |
|
365 |
|
366 |
/**
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
375 |
-
wp_enqueue_script( 'nav-menu-roles', plugins_url( 'js/nav-menu-roles' . $suffix . '.js' , __FILE__ ), array( 'jquery' ), self::VERSION, true );
|
376 |
}
|
377 |
}
|
378 |
|
379 |
/**
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
public function nav_update( $menu_id, $menu_item_db_id ) {
|
386 |
-
global $wp_roles;
|
387 |
-
|
388 |
-
$allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
|
389 |
|
390 |
// Verify this came from our screen and with proper authorization.
|
391 |
-
if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) ){
|
392 |
return;
|
393 |
}
|
394 |
-
|
395 |
-
$saved_data = false;
|
396 |
|
397 |
-
if ( isset( $_POST['nav-menu-logged-in-out'][
|
398 |
-
|
399 |
-
$
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
if ( array_key_exists ( $role, $allowed_roles ) ) {
|
404 |
-
$custom_roles[] = $role;
|
405 |
-
}
|
406 |
-
}
|
407 |
-
if ( ! empty ( $custom_roles ) ) {
|
408 |
-
$saved_data = $custom_roles;
|
409 |
}
|
410 |
-
} else if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && in_array( $_POST['nav-menu-logged-in-out'][$menu_item_db_id], array( 'in', 'out' ) ) ) {
|
411 |
-
$saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
|
412 |
-
}
|
413 |
|
414 |
-
|
415 |
-
|
416 |
} else {
|
417 |
delete_post_meta( $menu_item_db_id, '_nav_menu_role' );
|
418 |
}
|
419 |
}
|
420 |
|
421 |
/**
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
public function setup_nav_item( $menu_item ) {
|
428 |
|
429 |
-
if( is_object( $menu_item ) && isset( $menu_item->ID ) ) {
|
430 |
|
431 |
$roles = get_post_meta( $menu_item->ID, '_nav_menu_role', true );
|
432 |
|
@@ -436,11 +472,11 @@ class Nav_Menu_Roles {
|
|
436 |
// Add the NMR roles as CSS info.
|
437 |
$new_classes = array();
|
438 |
|
439 |
-
switch( $roles ) {
|
440 |
-
case 'in'
|
441 |
$new_classes[] = 'nmr-logged-in';
|
442 |
break;
|
443 |
-
case 'out'
|
444 |
$new_classes[] = 'nmr-logged-out';
|
445 |
break;
|
446 |
default:
|
@@ -453,7 +489,7 @@ class Nav_Menu_Roles {
|
|
453 |
}
|
454 |
|
455 |
// Only apply classes on front-end.
|
456 |
-
if( ! is_admin() ) {
|
457 |
$menu_item->classes = array_unique( array_merge( (array) $menu_item->classes, (array) $new_classes ) );
|
458 |
}
|
459 |
}
|
@@ -477,7 +513,7 @@ class Nav_Menu_Roles {
|
|
477 |
|
478 |
$hide_children_of = array();
|
479 |
|
480 |
-
if( ! empty( $items ) ) {
|
481 |
|
482 |
// Iterate over the items to search and destroy.
|
483 |
foreach ( $items as $key => $item ) {
|
@@ -485,16 +521,16 @@ class Nav_Menu_Roles {
|
|
485 |
$visible = true;
|
486 |
|
487 |
// Hide any item that is the child of a hidden item.
|
488 |
-
if( isset( $item->menu_item_parent ) && in_array( $item->menu_item_parent, $hide_children_of ) ){
|
489 |
$visible = false;
|
490 |
}
|
491 |
|
492 |
// Check any item that has NMR roles set.
|
493 |
-
if( $visible && isset( $item->roles ) ) {
|
494 |
|
495 |
// Check all logged in, all logged out, or role.
|
496 |
-
switch( $item->roles ) {
|
497 |
-
case 'in'
|
498 |
/**
|
499 |
* Multisite compatibility.
|
500 |
*
|
@@ -504,7 +540,7 @@ class Nav_Menu_Roles {
|
|
504 |
*/
|
505 |
$visible = is_user_member_of_blog() || is_super_admin() ? true : false;
|
506 |
break;
|
507 |
-
case 'out'
|
508 |
/**
|
509 |
* Multisite compatibility.
|
510 |
*
|
@@ -529,7 +565,6 @@ class Nav_Menu_Roles {
|
|
529 |
|
530 |
break;
|
531 |
}
|
532 |
-
|
533 |
}
|
534 |
|
535 |
/*
|
@@ -538,19 +573,17 @@ class Nav_Menu_Roles {
|
|
538 |
*
|
539 |
* @param bool $visible
|
540 |
* @param object $item
|
541 |
-
*/
|
542 |
$visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );
|
543 |
|
544 |
// Unset non-visible item.
|
545 |
if ( ! $visible ) {
|
546 |
-
if( isset( $item->ID ) ) {
|
547 |
$hide_children_of[] = $item->ID; // Store ID of item to hide it's children.
|
548 |
}
|
549 |
-
unset( $items[$key] )
|
550 |
}
|
551 |
-
|
552 |
}
|
553 |
-
|
554 |
}
|
555 |
|
556 |
return $items;
|
@@ -558,27 +591,27 @@ class Nav_Menu_Roles {
|
|
558 |
|
559 |
|
560 |
/**
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
public function maybe_upgrade() {
|
567 |
$db_version = get_option( 'nav_menu_roles_db_version', false );
|
568 |
|
569 |
// 1.7.7 upgrade: changed the debug notice so the old transient is invalid.
|
570 |
-
if (
|
571 |
-
|
572 |
}
|
573 |
}
|
574 |
|
575 |
/**
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
public static function is_wp_gte( $version = '5.4' ) {
|
583 |
global $wp_version;
|
584 |
return version_compare( strtolower( $wp_version ), strtolower( $version ), '>=' );
|
@@ -586,19 +619,18 @@ class Nav_Menu_Roles {
|
|
586 |
|
587 |
} // end class
|
588 |
|
589 |
-
endif; // class_exists check
|
590 |
-
|
591 |
-
|
592 |
/**
|
593 |
* Launch the whole plugin
|
594 |
* Returns the main instance of Nav Menu Roles to prevent the need to use globals.
|
595 |
*
|
596 |
* @since 1.5
|
597 |
* @return Nav_Menu_Roles
|
598 |
-
*/
|
599 |
-
function
|
600 |
return Nav_Menu_Roles::instance();
|
601 |
}
|
602 |
|
|
|
|
|
603 |
// Global for backwards compatibility.
|
604 |
-
$GLOBALS['Nav_Menu_Roles'] = Nav_Menu_Roles();
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: Nav Menu Roles
|
4 |
+
* Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
|
5 |
+
* Description: Hide custom menu items based on user roles.
|
6 |
+
* Version: 2.0.0
|
7 |
+
* Author: Kathy Darling
|
8 |
+
* Author URI: http://www.kathyisawesome.com
|
9 |
+
* License: GPL-3.0
|
10 |
+
* Text Domain: nav-menu-roles
|
11 |
+
*
|
12 |
+
* Copyright 2020 Kathy Darling
|
13 |
+
*
|
14 |
+
* This program is free software; you can redistribute it and/or modify
|
15 |
+
* it under the terms of the GNU General Public License, version 2, as
|
16 |
+
* published by the Free Software Foundation.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program; if not, write to the Free Software
|
25 |
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
|
26 |
+
*
|
27 |
+
* @package Nav Menu Roles
|
28 |
+
*/
|
29 |
|
30 |
// Don't load directly.
|
31 |
if ( ! function_exists( 'is_admin' ) ) {
|
34 |
exit();
|
35 |
}
|
36 |
|
37 |
+
/**
|
38 |
+
* Nav Menu Roles class
|
39 |
+
*/
|
40 |
class Nav_Menu_Roles {
|
41 |
|
42 |
/**
|
43 |
+
* @var Nav_Menu_Roles The single instance of the class
|
44 |
+
* @since 1.5
|
45 |
+
*/
|
46 |
protected static $_instance = null;
|
47 |
|
48 |
/**
|
49 |
* @constant string donate url
|
50 |
* @since 1.9.1
|
51 |
*/
|
52 |
+
const DONATE_URL = 'https://www.paypal.com/fundraiser/charity/1451316';
|
53 |
|
54 |
/**
|
55 |
* @constant string version number
|
56 |
* @since 1.7.0
|
57 |
*/
|
58 |
+
const VERSION = '1.10.2';
|
59 |
|
60 |
/**
|
61 |
+
* Main Nav Menu Roles Instance
|
62 |
+
*
|
63 |
+
* Ensures only one instance of Nav Menu Roles is loaded or can be loaded.
|
64 |
+
*
|
65 |
+
* @since 1.5
|
66 |
+
* @static
|
67 |
+
* @see Nav_Menu_Roles()
|
68 |
+
* @return Nav_Menu_Roles - Main instance
|
69 |
+
*/
|
70 |
public static function instance() {
|
71 |
if ( is_null( self::$_instance ) ) {
|
72 |
self::$_instance = new self();
|
75 |
}
|
76 |
|
77 |
/**
|
78 |
+
* Cloning is forbidden.
|
79 |
+
*
|
80 |
+
* @since 1.5
|
81 |
+
*/
|
82 |
public function __clone() {
|
83 |
+
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning this object is forbidden.', 'nav-menu-roles' ), '1.5' );
|
84 |
}
|
85 |
|
86 |
/**
|
87 |
+
* Unserializing instances of this class is forbidden.
|
88 |
+
*
|
89 |
+
* @since 1.5
|
90 |
+
*/
|
91 |
public function __wakeup() {
|
92 |
+
_doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing instances of this class is forbidden.', 'nav-menu-roles' ), '1.5' );
|
93 |
}
|
94 |
|
95 |
/**
|
96 |
+
* Nav_Menu_Roles Constructor.
|
97 |
+
* @access public
|
98 |
+
* @return Nav_Menu_Roles
|
99 |
+
* @since 1.0
|
100 |
+
*/
|
101 |
+
public function __construct() {
|
102 |
+
|
103 |
+
require_once 'inc/customizer.php';
|
104 |
|
105 |
// Admin functions.
|
106 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
108 |
// Load the textdomain.
|
109 |
add_action( 'init', array( $this, 'load_text_domain' ) );
|
110 |
|
111 |
+
// Register the meta key.
|
112 |
+
add_action( 'init', array( $this, 'register_meta' ) );
|
113 |
+
|
114 |
// Add FAQ and Donate link to plugin.
|
115 |
add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
|
116 |
|
117 |
// Maybe switch the admin walker.
|
118 |
+
if ( ! self::is_wp_gte( '5.4' ) ) {
|
119 |
add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
|
120 |
}
|
121 |
|
123 |
add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
|
124 |
|
125 |
// Add some JS.
|
126 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
127 |
|
128 |
// Save the menu item meta.
|
129 |
+
add_action( 'wp_update_nav_menu_item', array( $this, 'nav_update' ), 10, 2 );
|
130 |
|
131 |
// Add meta to menu item.
|
132 |
add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_item' ) );
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
+
* Include the custom admin walker
|
147 |
+
*
|
148 |
+
* @access public
|
149 |
+
* @return void
|
150 |
+
*/
|
151 |
public function admin_init() {
|
152 |
|
153 |
// Register Importer.
|
157 |
|
158 |
|
159 |
/**
|
160 |
+
* Register the Importer
|
161 |
+
* the regular Importer skips post meta for the menu items
|
162 |
+
*
|
163 |
+
* @access private
|
164 |
+
* @return void
|
165 |
+
*/
|
166 |
+
public function register_importer() {
|
167 |
// Register the new importer.
|
168 |
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
|
169 |
|
170 |
+
include_once plugin_dir_path( __FILE__ ) . 'inc/class-nav-menu-roles-import.php';
|
171 |
// Register the custom importer we've created.
|
172 |
$roles_import = new Nav_Menu_Roles_Import();
|
173 |
|
174 |
+
register_importer( 'nav_menu_roles', __( 'Nav Menu Roles', 'nav-menu-roles' ), __( 'Import <strong>nav menu roles</strong> and other menu item meta skipped by the default importer', 'nav-menu-roles' ), array( $roles_import, 'dispatch' ) );
|
175 |
|
176 |
}
|
177 |
|
178 |
}
|
179 |
|
180 |
/**
|
181 |
+
* Make Plugin Translation-ready
|
182 |
+
*
|
183 |
+
* @since 1.0
|
184 |
+
*/
|
185 |
public function load_text_domain() {
|
186 |
load_plugin_textdomain( 'nav-menu-roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
187 |
}
|
188 |
|
189 |
+
/**
|
190 |
+
* Register the meta keys for nav menus.
|
191 |
+
*
|
192 |
+
* @since 2.0
|
193 |
+
*/
|
194 |
+
public function register_meta() {
|
195 |
+
register_meta(
|
196 |
+
'post',
|
197 |
+
'_nav_menu_role',
|
198 |
+
array(
|
199 |
+
'object_subtype' => 'nav_menu_item',
|
200 |
+
'type' => 'mixed',
|
201 |
+
'sanitize_callback' => array( $this, 'sanitize_meta' ),
|
202 |
+
)
|
203 |
+
);
|
204 |
+
}
|
205 |
|
206 |
/**
|
207 |
+
* Sanitize the meta.
|
208 |
+
*
|
209 |
+
* @since 2.0.0
|
210 |
+
*
|
211 |
+
* @param mixed $meta_value The meta value.
|
212 |
+
* @return mixed The meta value.
|
213 |
+
*
|
214 |
+
*/
|
215 |
+
public function sanitize_meta( $meta_value ) {
|
216 |
+
global $wp_roles;
|
217 |
+
|
218 |
+
$clean = '';
|
219 |
+
|
220 |
+
if ( is_array( $meta_value ) ) {
|
221 |
+
|
222 |
+
$clean = array();
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Pass the menu item to the filter function.
|
226 |
+
* This change is suggested as it allows the use of information from the menu item (and
|
227 |
+
* by extension the target object) to further customize what filters appear during menu
|
228 |
+
* construction.
|
229 |
+
*/
|
230 |
+
$allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
|
231 |
+
|
232 |
+
// Only save allowed roles.
|
233 |
+
$clean = array_intersect( $meta_value, array_keys( $allowed_roles ) );
|
234 |
+
|
235 |
+
} elseif ( in_array( $meta_value, array( 'in', 'out' ) ) ) {
|
236 |
+
$clean = $meta_value;
|
237 |
+
}
|
238 |
+
|
239 |
+
return $clean;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Display a Notice if plugin conflicts with another
|
244 |
+
*
|
245 |
+
* @since 1.5
|
246 |
+
* @deprecated will removed in 2.0
|
247 |
+
*/
|
248 |
public function admin_notice() {
|
249 |
_deprecated_function( __METHOD__, '1.7.8' );
|
250 |
}
|
251 |
|
252 |
|
253 |
/**
|
254 |
+
* Allow the notice to be dismissable
|
255 |
+
*
|
256 |
+
* @since 1.6
|
257 |
+
* @deprecated will removed in 2.0
|
258 |
+
*/
|
259 |
public function nag_ignore() {
|
260 |
_deprecated_function( __METHOD__, '1.7.8' );
|
261 |
}
|
262 |
|
263 |
/**
|
264 |
+
* Delete the transient when a plugin is activated or deactivated
|
265 |
+
*
|
266 |
+
* @since 1.5
|
267 |
+
* @deprecated will removed in 2.0
|
268 |
+
*/
|
269 |
public function delete_transient() {
|
270 |
_deprecated_function( __METHOD__, '1.7.8' );
|
271 |
delete_transient( 'nav_menu_roles_conflicts' );
|
273 |
|
274 |
|
275 |
/**
|
276 |
+
* Add docu link
|
277 |
+
*
|
278 |
+
* @since 1.7.3
|
279 |
+
* @param array $plugin_meta
|
280 |
+
* @param string $plugin_file
|
281 |
+
*/
|
282 |
public function add_action_links( $plugin_meta, $plugin_file ) {
|
283 |
+
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
|
284 |
$plugin_meta[] = sprintf( '<a class="dashicons-before dashicons-welcome-learn-more" href="https://wordpress.org/plugins/nav-menu-roles/faq/#conflict">%s</a>', __( 'FAQ', 'nav-menu-roles' ) );
|
285 |
$plugin_meta[] = '<a class="dashicons-before dashicons-admin-generic" href="' . self::DONATE_URL . '" target="_blank">' . __( 'Donate', 'nav-menu-roles' ) . '</a>';
|
286 |
}
|
289 |
|
290 |
|
291 |
/**
|
292 |
+
* Override the Admin Menu Walker
|
293 |
+
*
|
294 |
+
* @since 1.0
|
295 |
+
*/
|
296 |
public function edit_nav_menu_walker( $walker ) {
|
297 |
+
if ( ! class_exists( 'Walker_Nav_Menu_Edit_Roles' ) ) {
|
298 |
|
299 |
+
if ( self::is_wp_gte( '4.7' ) ) {
|
300 |
+
require_once plugin_dir_path( __FILE__ ) . 'inc/class-walker-nav-menu-edit-roles-4.7.php';
|
301 |
+
} elseif ( self::is_wp_gte( '4.5' ) ) {
|
302 |
+
require_once plugin_dir_path( __FILE__ ) . 'inc/class-walker-nav-menu-edit-roles-4.5.php';
|
303 |
} else {
|
304 |
+
require_once plugin_dir_path( __FILE__ ) . 'inc/class-walker-nav-menu-edit-roles.php';
|
305 |
}
|
306 |
+
}
|
307 |
return 'Walker_Nav_Menu_Edit_Roles';
|
308 |
}
|
309 |
|
310 |
|
311 |
/**
|
312 |
+
* Add fields to hook added in Walker
|
313 |
+
* This will allow us to play nicely with any other plugin that is adding the same hook
|
314 |
+
* @params obj $item - the menu item
|
315 |
+
* @params array $args
|
316 |
+
* @since 1.6.0
|
317 |
+
*/
|
318 |
public function custom_fields( $item_id, $item, $depth, $args ) {
|
319 |
global $wp_roles;
|
320 |
|
335 |
* permissions to the menu from accidentally removing all restrictions from a menu item to
|
336 |
* which they do not have access.
|
337 |
*/
|
338 |
+
if ( ! $display_roles ) {
|
339 |
+
return;
|
340 |
+
}
|
341 |
|
342 |
/* Get the roles saved for the post. */
|
343 |
$roles = get_post_meta( $item->ID, '_nav_menu_role', true );
|
346 |
$logged_in_out = '';
|
347 |
|
348 |
// Specific roles are saved as an array, so "in" or an array equals "in" is checked.
|
349 |
+
if ( is_array( $roles ) || 'in' === $roles ) {
|
350 |
$logged_in_out = 'in';
|
351 |
+
} elseif ( 'out' === $roles ) {
|
352 |
$logged_in_out = 'out';
|
353 |
}
|
354 |
|
356 |
$checked_roles = is_array( $roles ) ? $roles : false;
|
357 |
|
358 |
// Whether to display the role checkboxes.
|
359 |
+
$hidden = 'in' === $logged_in_out ? '' : 'display: none;';
|
360 |
|
361 |
+
$float = is_rtl() ? 'float:"right";' : 'float:"left";';
|
|
|
|
|
362 |
|
363 |
+
?>
|
|
|
|
|
364 |
|
365 |
+
<input type="hidden" name="nav-menu-role-nonce" value="<?php echo esc_attr( wp_create_nonce( 'nav-menu-nonce-name' ) ); ?>" />
|
366 |
|
367 |
+
<fieldset class="field-nav_menu_role nav_menu_logged_in_out_field description-wide" style="margin: 5px 0;">
|
368 |
+
<legend class="description"><?php esc_html_e( 'Display Mode', 'nav-menu-roles' ); ?></legend>
|
|
|
|
|
|
|
|
|
369 |
|
370 |
+
<input type="hidden" class="nav-menu-id" value="<?php echo esc_attr( $item->ID ); ?>" />
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
+
<label for="nav_menu_logged_in-for-<?php echo esc_attr( $item->ID ); ?>" style="<?php echo esc_attr( $float ); ?> width: 35%;">
|
373 |
+
<input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo esc_attr( $item->ID ); ?>]" id="nav_menu_logged_in-for-<?php echo esc_attr( $item->ID ); ?>" <?php checked( 'in', $logged_in_out ); ?> value="in" />
|
374 |
+
<?php esc_html_e( 'Logged In Users', 'nav-menu-roles' ); ?>
|
375 |
+
</label>
|
376 |
+
|
377 |
+
<label for="nav_menu_logged_out-for-<?php echo esc_attr( $item->ID ); ?>" style="<?php echo esc_attr( $float ); ?> width: 35%;">
|
378 |
+
<input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo esc_attr( $item->ID ); ?>]" id="nav_menu_logged_out-for-<?php echo esc_attr( $item->ID ); ?>" <?php checked( 'out', $logged_in_out ); ?> value="out" />
|
379 |
+
<?php esc_html_e( 'Logged Out Users', 'nav-menu-roles' ); ?>
|
380 |
+
</label>
|
381 |
|
382 |
+
<label for="nav_menu_by_role-for-<?php echo esc_attr( $item->ID ); ?>" style="<?php echo esc_attr( $float ); ?> width: 30%;">
|
383 |
+
<input type="radio" class="nav-menu-logged-in-out" name="nav-menu-logged-in-out[<?php echo esc_attr( $item->ID ); ?>]" id="nav_menu_by_role-for-<?php echo esc_attr( $item->ID ); ?>" <?php checked( '', $logged_in_out ); ?> value="" />
|
384 |
+
<?php esc_html_e( 'Everyone', 'nav-menu-roles' ); ?>
|
385 |
+
</label>
|
386 |
|
387 |
+
</fieldset>
|
|
|
|
|
388 |
|
389 |
+
<fieldset class="field-nav_menu_role nav_menu_role_field description-wide" style="margin: 5px 0; <?php echo esc_attr( $hidden ); ?>">
|
390 |
+
<legend class="description"><?php esc_html_e( 'Restrict menu item to a minimum role', 'nav-menu-roles' ); ?></legend>
|
391 |
+
<br />
|
392 |
|
393 |
+
<?php
|
394 |
|
395 |
+
$i = 1;
|
|
|
396 |
|
397 |
+
/* Loop through each of the available roles. */
|
398 |
+
foreach ( $display_roles as $role => $name ) {
|
399 |
|
400 |
+
/* If the role has been selected, make sure it's checked. */
|
401 |
+
$checked = checked( true, ( is_array( $checked_roles ) && in_array( $role, $checked_roles ) ), false );
|
402 |
+
?>
|
403 |
|
404 |
+
<label for="nav_menu_role-<?php echo esc_attr( $role ); ?>-for-<?php echo esc_attr( $item->ID ); ?>" style="display: block; margin: 2px 0;">
|
405 |
+
<input type="checkbox" name="nav-menu-role[<?php echo esc_attr( $item->ID ); ?>][<?php echo esc_attr( $i ); ?>]" id="nav_menu_role-<?php echo esc_attr( $role ); ?>-for-<?php echo esc_attr( $item->ID ); ?>" <?php echo esc_attr( $checked ); ?> value="<?php echo esc_attr( $role ); ?>" />
|
406 |
+
<?php echo esc_html( $name ); ?>
|
407 |
+
<?php $i++; ?>
|
408 |
+
</label>
|
|
|
|
|
409 |
|
410 |
<?php } ?>
|
411 |
|
412 |
+
</fieldset>
|
413 |
|
414 |
<?php
|
415 |
}
|
416 |
|
417 |
|
418 |
/**
|
419 |
+
* Load the scripts on the menu page.
|
420 |
+
*
|
421 |
+
* @since 1.4
|
422 |
+
*/
|
423 |
+
public function enqueue_scripts( $hook ) {
|
424 |
+
if ( 'nav-menus.php' === $hook ) {
|
425 |
+
wp_enqueue_script( 'nav-menu-roles', plugins_url( 'dist/js/roles.js', __FILE__ ), array( 'jquery' ), self::VERSION, true );
|
|
|
|
|
426 |
}
|
427 |
}
|
428 |
|
429 |
/**
|
430 |
+
* Save the roles as menu item meta
|
431 |
+
*
|
432 |
+
* @since 1.0
|
433 |
+
* @return string
|
434 |
+
*/
|
435 |
public function nav_update( $menu_id, $menu_item_db_id ) {
|
|
|
|
|
|
|
436 |
|
437 |
// Verify this came from our screen and with proper authorization.
|
438 |
+
if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nav-menu-role-nonce'] ), 'nav-menu-nonce-name' ) ) {
|
439 |
return;
|
440 |
}
|
|
|
|
|
441 |
|
442 |
+
if ( isset( $_POST['nav-menu-logged-in-out'][ $menu_item_db_id ] ) ) {
|
443 |
+
|
444 |
+
if ( 'in' === $_POST['nav-menu-logged-in-out'][ $menu_item_db_id ] && ! empty( $_POST['nav-menu-role'][ $menu_item_db_id ] ) ) {
|
445 |
+
$meta = wp_unslash( $_POST['nav-menu-role'][ $menu_item_db_id ] );
|
446 |
+
} else {
|
447 |
+
$meta = wp_unslash( $_POST['nav-menu-logged-in-out'][ $menu_item_db_id ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
}
|
|
|
|
|
|
|
449 |
|
450 |
+
update_post_meta( $menu_item_db_id, '_nav_menu_role', $meta ); // Sanitization handled by $this->sanitize_meta().
|
451 |
+
|
452 |
} else {
|
453 |
delete_post_meta( $menu_item_db_id, '_nav_menu_role' );
|
454 |
}
|
455 |
}
|
456 |
|
457 |
/**
|
458 |
+
* Adds value of new field to $item object
|
459 |
+
* is be passed to Walker_Nav_Menu_Edit_Custom
|
460 |
+
*
|
461 |
+
* @since 1.0
|
462 |
+
*/
|
463 |
public function setup_nav_item( $menu_item ) {
|
464 |
|
465 |
+
if ( is_object( $menu_item ) && isset( $menu_item->ID ) ) {
|
466 |
|
467 |
$roles = get_post_meta( $menu_item->ID, '_nav_menu_role', true );
|
468 |
|
472 |
// Add the NMR roles as CSS info.
|
473 |
$new_classes = array();
|
474 |
|
475 |
+
switch ( $roles ) {
|
476 |
+
case 'in':
|
477 |
$new_classes[] = 'nmr-logged-in';
|
478 |
break;
|
479 |
+
case 'out':
|
480 |
$new_classes[] = 'nmr-logged-out';
|
481 |
break;
|
482 |
default:
|
489 |
}
|
490 |
|
491 |
// Only apply classes on front-end.
|
492 |
+
if ( ! is_admin() ) {
|
493 |
$menu_item->classes = array_unique( array_merge( (array) $menu_item->classes, (array) $new_classes ) );
|
494 |
}
|
495 |
}
|
513 |
|
514 |
$hide_children_of = array();
|
515 |
|
516 |
+
if ( ! empty( $items ) ) {
|
517 |
|
518 |
// Iterate over the items to search and destroy.
|
519 |
foreach ( $items as $key => $item ) {
|
521 |
$visible = true;
|
522 |
|
523 |
// Hide any item that is the child of a hidden item.
|
524 |
+
if ( isset( $item->menu_item_parent ) && in_array( $item->menu_item_parent, $hide_children_of ) ) {
|
525 |
$visible = false;
|
526 |
}
|
527 |
|
528 |
// Check any item that has NMR roles set.
|
529 |
+
if ( $visible && isset( $item->roles ) ) {
|
530 |
|
531 |
// Check all logged in, all logged out, or role.
|
532 |
+
switch ( $item->roles ) {
|
533 |
+
case 'in':
|
534 |
/**
|
535 |
* Multisite compatibility.
|
536 |
*
|
540 |
*/
|
541 |
$visible = is_user_member_of_blog() || is_super_admin() ? true : false;
|
542 |
break;
|
543 |
+
case 'out':
|
544 |
/**
|
545 |
* Multisite compatibility.
|
546 |
*
|
565 |
|
566 |
break;
|
567 |
}
|
|
|
568 |
}
|
569 |
|
570 |
/*
|
573 |
*
|
574 |
* @param bool $visible
|
575 |
* @param object $item
|
576 |
+
*/
|
577 |
$visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );
|
578 |
|
579 |
// Unset non-visible item.
|
580 |
if ( ! $visible ) {
|
581 |
+
if ( isset( $item->ID ) ) {
|
582 |
$hide_children_of[] = $item->ID; // Store ID of item to hide it's children.
|
583 |
}
|
584 |
+
unset( $items[ $key ] );
|
585 |
}
|
|
|
586 |
}
|
|
|
587 |
}
|
588 |
|
589 |
return $items;
|
591 |
|
592 |
|
593 |
/**
|
594 |
+
* Maybe upgrade
|
595 |
+
*
|
596 |
+
* @access public
|
597 |
+
* @return void
|
598 |
+
*/
|
599 |
public function maybe_upgrade() {
|
600 |
$db_version = get_option( 'nav_menu_roles_db_version', false );
|
601 |
|
602 |
// 1.7.7 upgrade: changed the debug notice so the old transient is invalid.
|
603 |
+
if ( false === $db_version || version_compare( '1.7.7', $db_version, '<' ) ) {
|
604 |
+
update_option( 'nav_menu_roles_db_version', self::VERSION );
|
605 |
}
|
606 |
}
|
607 |
|
608 |
/**
|
609 |
+
* Test WordPress version
|
610 |
+
*
|
611 |
+
* @access public
|
612 |
+
* @param string $version - A WordPress version to compare against current version.
|
613 |
+
* @return boolean
|
614 |
+
*/
|
615 |
public static function is_wp_gte( $version = '5.4' ) {
|
616 |
global $wp_version;
|
617 |
return version_compare( strtolower( $wp_version ), strtolower( $version ), '>=' );
|
619 |
|
620 |
} // end class
|
621 |
|
|
|
|
|
|
|
622 |
/**
|
623 |
* Launch the whole plugin
|
624 |
* Returns the main instance of Nav Menu Roles to prevent the need to use globals.
|
625 |
*
|
626 |
* @since 1.5
|
627 |
* @return Nav_Menu_Roles
|
628 |
+
*/
|
629 |
+
function nav_menu_roles() {
|
630 |
return Nav_Menu_Roles::instance();
|
631 |
}
|
632 |
|
633 |
+
add_action( 'plugins_loaded', 'nav_menu_roles' );
|
634 |
+
|
635 |
// Global for backwards compatibility.
|
636 |
+
$GLOBALS['Nav_Menu_Roles'] = Nav_Menu_Roles();
|
readme.txt
CHANGED
@@ -4,9 +4,9 @@ Contributors: helgatheviking
|
|
4 |
Donate link: https://www.paypal.com/fundraiser/charity/1451316
|
5 |
Tags: menu, menus, nav menu, nav menus
|
6 |
Requires at least: 4.5.0
|
7 |
-
Tested up to: 5.
|
8 |
Requires PHP: 5.3.2
|
9 |
-
Stable tag:
|
10 |
License: GPLv3
|
11 |
|
12 |
Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
|
@@ -49,9 +49,12 @@ Please report any bugs, errors, warnings, code problems to [Github](https://gith
|
|
49 |
|
50 |
= I don't see the Nav Menu Roles options in the admin menu items? =
|
51 |
|
52 |
-
This is
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
WordPress does not have sufficient hooks in this area of the admin and until they do plugins are forced to replace everything via custom admin menu Walker, of which there can be only one. There's a [trac ticket](http://core.trac.wordpress.org/ticket/18584) for this, but it has been around a while.
|
55 |
|
56 |
**A non-exhaustive list of known conflicts:**
|
57 |
|
@@ -70,17 +73,21 @@ WordPress does not have sufficient hooks in this area of the admin and until the
|
|
70 |
= Workaround #1 =
|
71 |
[Shazdeh](https://profiles.wordpress.org/shazdeh/) had the genius idea to not wait for a core hook and simply add the hook ourselves. If all plugin and theme authors use the same hook, we can make our plugins play together.
|
72 |
|
73 |
-
|
74 |
|
75 |
`
|
76 |
<?php
|
77 |
// Place this in your admin nav menu Walker
|
78 |
-
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
79 |
// end added section
|
80 |
?>
|
81 |
`
|
82 |
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
= Instructions for Patching Your Plugin/Theme =
|
86 |
|
@@ -101,7 +108,7 @@ In that file you will eventually see a class method that looks like:
|
|
101 |
}
|
102 |
`
|
103 |
|
104 |
-
3\. Paste
|
105 |
|
106 |
In Nav Menu Roles, I have placed the hook directly after the description, like so:
|
107 |
|
@@ -116,7 +123,7 @@ In Nav Menu Roles, I have placed the hook directly after the description, like s
|
|
116 |
|
117 |
<?php
|
118 |
// Add this directly after the description paragraph in the start_el() method
|
119 |
-
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
|
120 |
// end added section
|
121 |
?>
|
122 |
`
|
@@ -127,6 +134,8 @@ As a workaround, you can switch to a default theme (or disable the conflicting p
|
|
127 |
|
128 |
= Workaround #3 =
|
129 |
|
|
|
|
|
130 |
Download and install this [tiny plugin](https://gist.github.com/helgatheviking/d00f9c033a4b0aab0f69cf50d7dcd89c). Activate it when you need to make the NMR options appear and then disable it when you are done editing.
|
131 |
|
132 |
= I'm using XYZ Membership plugin and I don't see its "levels"? =
|
@@ -239,6 +248,8 @@ Yes, but manually. WPML developers have informed me that the meta data for nav m
|
|
239 |
|
240 |
== Changelog ==
|
241 |
|
|
|
|
|
242 |
|
243 |
= 1.10.2 =
|
244 |
* Fix: Strict array typecasting for nav menu classes.
|
4 |
Donate link: https://www.paypal.com/fundraiser/charity/1451316
|
5 |
Tags: menu, menus, nav menu, nav menus
|
6 |
Requires at least: 4.5.0
|
7 |
+
Tested up to: 5.5.0
|
8 |
Requires PHP: 5.3.2
|
9 |
+
Stable tag: 2.0.0
|
10 |
License: GPLv3
|
11 |
|
12 |
Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
|
49 |
|
50 |
= I don't see the Nav Menu Roles options in the admin menu items? =
|
51 |
|
52 |
+
This is likely due to a conflict with another plugin (or theme).
|
53 |
+
|
54 |
+
As of WordPress 5.4 the `wp_nav_menu_item_custom_fields` hook has been added to WordPress core.
|
55 |
+
|
56 |
+
Nav Menu Roles is therefore attaching directly to this hook without needing to replace the custom Admin Menu Walker, of which there can still be only one. If the Walker is replaced by a theme/plugin and the core hook is not included, then Nav Menu Roles cannot add it's fields.
|
57 |
|
|
|
58 |
|
59 |
**A non-exhaustive list of known conflicts:**
|
60 |
|
73 |
= Workaround #1 =
|
74 |
[Shazdeh](https://profiles.wordpress.org/shazdeh/) had the genius idea to not wait for a core hook and simply add the hook ourselves. If all plugin and theme authors use the same hook, we can make our plugins play together.
|
75 |
|
76 |
+
Prior to WordPress 5.4, I used this idea and modified my admin nav menu Walker to *only* adding the following lines (right after the description input):
|
77 |
|
78 |
`
|
79 |
<?php
|
80 |
// Place this in your admin nav menu Walker
|
81 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args, $id );
|
82 |
// end added section
|
83 |
?>
|
84 |
`
|
85 |
|
86 |
+
Since WordPress 5.4, I no longer replace the Walker at all and would advise other plugins and themes to do the same.
|
87 |
+
|
88 |
+
But for those that still are, they definitely need to include the now-core hook.
|
89 |
+
|
90 |
+
**Ask your conflicting plugin/theme's author to add this code to their plugin or theme and our plugins will become compatible.**
|
91 |
|
92 |
= Instructions for Patching Your Plugin/Theme =
|
93 |
|
108 |
}
|
109 |
`
|
110 |
|
111 |
+
3\. Paste the action hook somewhere in this method!
|
112 |
|
113 |
In Nav Menu Roles, I have placed the hook directly after the description, like so:
|
114 |
|
123 |
|
124 |
<?php
|
125 |
// Add this directly after the description paragraph in the start_el() method
|
126 |
+
do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args, $id );
|
127 |
// end added section
|
128 |
?>
|
129 |
`
|
134 |
|
135 |
= Workaround #3 =
|
136 |
|
137 |
+
Only works with WordPress less than 5.4.
|
138 |
+
|
139 |
Download and install this [tiny plugin](https://gist.github.com/helgatheviking/d00f9c033a4b0aab0f69cf50d7dcd89c). Activate it when you need to make the NMR options appear and then disable it when you are done editing.
|
140 |
|
141 |
= I'm using XYZ Membership plugin and I don't see its "levels"? =
|
248 |
|
249 |
== Changelog ==
|
250 |
|
251 |
+
= 2.0.0 =
|
252 |
+
* New: Customizer support! props @westonruter!
|
253 |
|
254 |
= 1.10.2 =
|
255 |
* Fix: Strict array typecasting for nav menu classes.
|