WPFront User Role Editor - Version 3.0.0

Version Description

  • Major update. Please test before upgrading.
  • Advanced extended permissions.
  • User post permissions.
  • Denied capabilities.
  • New menu editor.
  • Post Types UI.
  • Taxonomies UI.
  • And more...
Download this release

Release Info

Developer syammohanm
Plugin Icon 128x128 WPFront User Role Editor
Version 3.0.0
Comparing to
See all releases

Code changes from version 2.14.4 to 3.0.0

Files changed (114) hide show
  1. assets/css/admin.css +19 -0
  2. assets/css/chosen/chosen-sprite.png +0 -0
  3. assets/css/chosen/chosen-sprite@2x.png +0 -0
  4. assets/css/chosen/chosen.min.css +11 -0
  5. {classes/base/images → assets/css}/index.php +0 -0
  6. {css → assets/css}/nav-menu.css +0 -0
  7. assets/css/roles.css +640 -0
  8. {css → assets/css}/widget-permissions.css +5 -0
  9. {classes/base → assets/images}/index.php +0 -0
  10. {images → assets/images}/loading.gif +0 -0
  11. {classes/entities → assets}/index.php +0 -0
  12. assets/js/chosen/chosen.jquery.min.js +3 -0
  13. {classes → assets/js}/index.php +0 -0
  14. {js → assets/js}/nav-menu.js +0 -0
  15. assets/js/widget-permissions.js +29 -0
  16. classes/base/class-wpfront-base-menu.php +0 -260
  17. classes/base/class-wpfront-base.php +0 -245
  18. classes/base/class-wpfront-entity-base.php +0 -402
  19. classes/base/class-wpfront-options-base.php +0 -159
  20. classes/base/class-wpfront-static.php +0 -78
  21. classes/base/images/wpfront_menu.png +0 -0
  22. classes/class-wpfront-user-role-editor-add-edit.php +0 -425
  23. classes/class-wpfront-user-role-editor-add-remove-capability.php +0 -186
  24. classes/class-wpfront-user-role-editor-assign-roles.php +0 -490
  25. classes/class-wpfront-user-role-editor-attachment-permissions.php +0 -88
  26. classes/class-wpfront-user-role-editor-controller-base.php +0 -188
  27. classes/class-wpfront-user-role-editor-delete.php +0 -138
  28. classes/class-wpfront-user-role-editor-entity-base.php +0 -30
  29. classes/class-wpfront-user-role-editor-go-pro.php +0 -449
  30. classes/class-wpfront-user-role-editor-list.php +0 -523
  31. classes/class-wpfront-user-role-editor-login-redirect-list-table.php +0 -189
  32. classes/class-wpfront-user-role-editor-login-redirect.php +0 -542
  33. classes/class-wpfront-user-role-editor-nav-menu.php +0 -269
  34. classes/class-wpfront-user-role-editor-options.php +0 -432
  35. classes/class-wpfront-user-role-editor-restore.php +0 -190
  36. classes/class-wpfront-user-role-editor-user-permissions.php +0 -133
  37. classes/class-wpfront-user-role-editor-widget-permissions.php +0 -176
  38. classes/class-wpfront-user-role-editor.php +0 -738
  39. classes/entities/class-wpfront-user-role-editor-entity-login-redirect.php +0 -150
  40. classes/entities/class-wpfront-user-role-editor-entity-options.php +0 -63
  41. css/admin-style.css +0 -3
  42. css/options.css +0 -3
  43. css/style.css +0 -170
  44. images/check-icon.png +0 -0
  45. images/copy16x16.png +0 -0
  46. images/green_dot_64x64.png +0 -0
  47. images/help.png +0 -0
  48. images/orange_dot_64x64.png +0 -0
  49. images/roles_menu.png +0 -0
  50. images/settings32x32.png +0 -0
  51. includes/add-remove-cap/class-add-remove-cap.php +322 -0
  52. {classes/integration → includes/add-remove-cap}/index.php +0 -0
  53. includes/add-remove-cap/template-add-remove-cap.php +283 -0
  54. includes/bulk-edit/class-bulk-edit-utils.php +359 -0
  55. includes/bulk-edit/class-bulk-edit.php +196 -0
  56. {classes/integration/plugins/duplicator → includes/bulk-edit}/index.php +0 -0
  57. includes/bulk-edit/template-bulk-edit.php +84 -0
  58. includes/class-cache.php +115 -0
  59. includes/class-controller.php +298 -0
  60. includes/class-entity.php +194 -0
  61. includes/class-roles-helper.php +888 -0
  62. includes/class-uninstall.php +160 -0
  63. includes/class-utils.php +152 -0
  64. includes/globals.php +10 -0
  65. includes/go-pro/class-go-pro.php +125 -0
  66. {classes/integration/plugins → includes/go-pro}/index.php +0 -0
  67. includes/go-pro/template-go-pro.php +269 -0
  68. {css → includes}/index.php +0 -0
  69. {images → includes/integration}/index.php +0 -0
  70. includes/integration/plugins/bbPress/class-bbPress.php +85 -0
  71. {classes → includes}/integration/plugins/class-wpfront-user-role-editor-plugin-integration.php +80 -75
  72. {classes → includes}/integration/plugins/duplicator/class-wpfront-user-role-editor-plugin-duplicator.php +66 -64
  73. {js → includes/integration/plugins/duplicator}/index.php +0 -0
  74. {languages → includes/integration/plugins}/index.php +0 -0
  75. includes/login-redirect/class-login-redirect-list-table.php +247 -0
  76. includes/login-redirect/class-login-redirect.php +643 -0
  77. includes/login-redirect/entity-login-redirect.php +368 -0
  78. {templates → includes/login-redirect}/index.php +0 -0
  79. includes/login-redirect/template-add-edit.php +370 -0
  80. includes/login-redirect/template-delete.php +87 -0
  81. includes/login-redirect/template-login-redirect.php +91 -0
  82. includes/media/class-media-permissions.php +126 -0
  83. includes/media/index.php +2 -0
  84. includes/nav-menu/class-nav-menu-permissions.php +460 -0
  85. classes/class-wpfront-user-role-editor-nav-menu-walker.php → includes/nav-menu/class-nav-menu-walker.php +97 -93
  86. includes/nav-menu/index.php +2 -0
  87. includes/post-type/class-abstract-post-type-custom-cap.php +332 -0
  88. includes/post-type/class-post-type-list-table.php +317 -0
  89. includes/post-type/class-post-type.php +1361 -0
  90. includes/post-type/custom-caps/class-create-posts-capability.php +83 -0
  91. includes/post-type/custom-caps/class-read-others-capability.php +84 -0
  92. includes/post-type/entity-post-type.php +363 -0
  93. includes/post-type/template-add-edit.php +1249 -0
  94. includes/post-type/template-delete.php +113 -0
  95. includes/post-type/template-post-type.php +138 -0
  96. includes/restore/class-restore.php +308 -0
  97. includes/restore/index.php +2 -0
  98. includes/restore/template-restore.php +153 -0
  99. includes/roles/class-role-add-edit.php +536 -0
  100. includes/roles/class-role-delete.php +232 -0
  101. includes/roles/class-roles-list.php +669 -0
  102. includes/roles/index.php +2 -0
  103. includes/roles/template-role-add-edit.php +721 -0
  104. includes/roles/template-role-delete.php +113 -0
  105. includes/roles/template-roles-list.php +435 -0
  106. includes/settings/class-options.php +302 -0
  107. includes/settings/entity-options.php +224 -0
  108. includes/settings/index.php +2 -0
  109. includes/settings/template-options.php +119 -0
  110. classes/class-wpfront-user-role-editor-shortcodes.php → includes/shortcodes/class-shortcodes.php +29 -13
  111. includes/taxonomies/class-taxonomies-list-table.php +317 -0
  112. includes/taxonomies/class-taxonomies.php +1210 -0
  113. includes/taxonomies/entity-taxonomies.php +363 -0
  114. includes/taxonomies/template-add-edit.php +916 -0
assets/css/admin.css ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #adminmenu ul.wp-submenu li a span.wpfront-go-pro {
2
+ color: #F18500;
3
+ }
4
+
5
+ /* user profile start */
6
+ tr.user-secondary-role-wrap div.role-container, /* user profile */
7
+ div#wpbody div.wrap form[action='options.php'] div.role-container { /* settings general */
8
+ min-width:200px;
9
+ width:25%;
10
+ float:left;
11
+ }
12
+ /* user profile end */
13
+
14
+ /* user list start */
15
+ table.wp-list-table.users .column-user_role {
16
+ width: 15%;
17
+ }
18
+ /* user list end */
19
+
assets/css/chosen/chosen-sprite.png ADDED
Binary file
assets/css/chosen/chosen-sprite@2x.png ADDED
Binary file
assets/css/chosen/chosen.min.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ Chosen, a Select Box Enhancer for jQuery and Prototype
3
+ by Patrick Filler for Harvest, http://getharvest.com
4
+
5
+ Version 1.8.7
6
+ Full source at https://github.com/harvesthq/chosen
7
+ Copyright (c) 2011-2018 Harvest http://getharvest.com
8
+
9
+ MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
10
+ This file is generated by `grunt build`, do not edit it by hand.
11
+ */.chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.chosen-container *{-webkit-box-sizing:border-box;box-sizing:border-box}.chosen-container .chosen-drop{position:absolute;top:100%;z-index:1010;width:100%;border:1px solid #aaa;border-top:0;background:#fff;-webkit-box-shadow:0 4px 5px rgba(0,0,0,.15);box-shadow:0 4px 5px rgba(0,0,0,.15);clip:rect(0,0,0,0);-webkit-clip-path:inset(100% 100%);clip-path:inset(100% 100%)}.chosen-container.chosen-with-drop .chosen-drop{clip:auto;-webkit-clip-path:none;clip-path:none}.chosen-container a{cursor:pointer}.chosen-container .chosen-single .group-name,.chosen-container .search-choice .group-name{margin-right:4px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-weight:400;color:#999}.chosen-container .chosen-single .group-name:after,.chosen-container .search-choice .group-name:after{content:":";padding-left:2px;vertical-align:top}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:25px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,left top,left bottom,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),to(#f4f4f4));background:linear-gradient(#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;-webkit-box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:24px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(chosen-sprite.png) no-repeat 0 2px}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:url(chosen-sprite.png) no-repeat 100% -20px;font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;clip:rect(0,0,0,0);-webkit-clip-path:inset(100% 100%);clip-path:inset(100% 100%)}.chosen-container .chosen-results{color:#444;position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px;word-wrap:break-word;-webkit-touch-callout:none}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:-webkit-gradient(linear,left top,left bottom,color-stop(20%,#3875d7),color-stop(90%,#2a62bc));background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{color:#777;display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;margin:0;padding:0 5px;width:100%;height:auto;border:1px solid #aaa;background-color:#fff;background-image:-webkit-gradient(linear,left top,left bottom,color-stop(1%,#eee),color-stop(15%,#fff));background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:0;height:25px;outline:0;border:0!important;background:0 0!important;-webkit-box-shadow:none;box-shadow:none;color:#999;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0;width:25px}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 5px 3px 0;padding:3px 20px 3px 5px;border:1px solid #aaa;max-width:100%;border-radius:3px;background-color:#eee;background-image:-webkit-gradient(linear,left top,left bottom,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),to(#eee));background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-size:100% 19px;background-repeat:repeat-x;background-clip:padding-box;-webkit-box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice span{word-wrap:break-word}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:-webkit-gradient(linear,left top,left bottom,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),to(#eee));background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;-webkit-box-shadow:0 0 5px rgba(0,0,0,.3);box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;border-bottom-right-radius:0;border-bottom-left-radius:0;background-image:-webkit-gradient(linear,left top,left bottom,color-stop(20%,#eee),color-stop(80%,#fff));background-image:linear-gradient(#eee 20%,#fff 80%);-webkit-box-shadow:0 1px 0 #fff inset;box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:none;background:0 0}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;-webkit-box-shadow:0 0 5px rgba(0,0,0,.3);box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#222!important}.chosen-disabled{opacity:.5!important;cursor:default}.chosen-disabled .chosen-single{cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:none}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:url(chosen-sprite.png) no-repeat -30px -20px;direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-resolution:144dpi),only screen and (min-resolution:1.5dppx){.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span,.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container-single .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-rtl .chosen-search input[type=text]{background-image:url(chosen-sprite@2x.png)!important;background-size:52px 37px!important;background-repeat:no-repeat!important}}
{classes/base/images → assets/css}/index.php RENAMED
File without changes
{css → assets/css}/nav-menu.css RENAMED
File without changes
assets/css/roles.css ADDED
@@ -0,0 +1,640 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ WPFront User Role Editor Plugin
3
+ Copyright (C) 2014, WPFront.com
4
+ Website: wpfront.com
5
+ Contact: syam@wpfront.com
6
+
7
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
8
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
9
+ St, Fifth Floor, Boston, MA 02110, USA
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
12
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
15
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
17
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
+ */
22
+
23
+ /* go pro admin menu link */
24
+ #adminmenu ul.wp-submenu li.current a.current span.wpfront-go-pro {
25
+ color: inherit;
26
+ }
27
+ /* go pro admin menu link */
28
+
29
+ /* list roles start */
30
+ div.list-roles table div.row-actions {
31
+ /*white-space: nowrap;*/
32
+ }
33
+
34
+ @media screen and (max-width:782px) {
35
+ div.list-roles table .column-roletype,
36
+ div.list-roles table .column-userdefault,
37
+ div.list-roles table .column-usercount,
38
+ div.list-roles table .column-capscount,
39
+ div.list-roles table .column-edited_menu_column_key {
40
+ display: none;
41
+ }
42
+ }
43
+ /* list roles end */
44
+
45
+ /* add edit roles start */
46
+ div.role-add-new form#createuser table.sub-head {
47
+ width: 100%;
48
+ }
49
+
50
+ div.role-add-new form#createuser table.sub-head th.sub-head {
51
+ text-align: left;
52
+ padding: 0px;
53
+ }
54
+
55
+ div.role-add-new form#createuser table.sub-head th.sub-head h3 {
56
+ }
57
+
58
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls {
59
+ text-align: right;
60
+ padding: 0px;
61
+ }
62
+
63
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls div {
64
+ display: inline-block;
65
+ vertical-align: top;
66
+ }
67
+
68
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls div.spacer {
69
+ width: 10px;
70
+ height: 0px;
71
+ }
72
+
73
+ div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-all, div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-none {
74
+ width: 100px;
75
+ }
76
+
77
+ #wpbody-content div.role-add-new div.metabox-holder {
78
+ padding-top: 0px;
79
+ }
80
+
81
+ div.role-add-new div.metabox-holder div.postbox {
82
+ margin-bottom: 8px;
83
+ }
84
+
85
+ div.role-add-new div.metabox-holder .deprecated {
86
+ filter: alpha(opacity=80);
87
+ opacity: 0.8;
88
+ }
89
+
90
+ div.role-add-new div.metabox-holder div.postbox h3.hndle {
91
+
92
+ }
93
+
94
+ div.role-add-new div.metabox-holder div.postbox div.inside div.main div {
95
+ padding: 2px 0px;
96
+ display: inline-block;
97
+ width: 250px;
98
+ white-space: nowrap;
99
+ }
100
+
101
+ div.role-add-new div.metabox-holder div.postbox div.inside div.main div.no-capability {
102
+ width: auto;
103
+ }
104
+
105
+ div.role-add-new div.metabox-holder div.postbox label {
106
+ vertical-align: top;
107
+ max-width: 500px;
108
+ overflow: hidden;
109
+ display: inline-block;
110
+ white-space: nowrap;
111
+ text-overflow: ellipsis;
112
+ }
113
+
114
+ div.role-add-new div.metabox-holder div.postbox label.denied {
115
+ text-decoration: line-through;
116
+ }
117
+
118
+ div.role-add-new div.metabox-holder div.postbox label.disabled {
119
+ color: #f77;
120
+ }
121
+
122
+ div.role-add-new div.metabox-holder div.postbox input.hidden {
123
+ display: none;
124
+ }
125
+
126
+ div.role-add-new div.metabox-holder div.postbox h3.hndle label {
127
+ max-width: 85%;
128
+ }
129
+
130
+ div.role-add-new div.metabox-holder div.postbox div.main i.fa-question-circle-o {
131
+ opacity: 0.8;
132
+ color: grey;
133
+ font-size: 0.8em;
134
+ }
135
+
136
+ div.role-add-new div.footer {
137
+ text-align: center;
138
+ }
139
+
140
+ /* add edit roles end */
141
+
142
+ /* restore roles start */
143
+ div.role-restore table.form-table td div.restore-role-button-container,
144
+ div.role-restore table.form-table td div.restore-role-loader,
145
+ div.role-restore table.form-table td div.restore-role-success {
146
+ display: none;
147
+ }
148
+ /* restore roles end */
149
+
150
+ /* login redirect start */
151
+ div.wrap.login-redirect table.wp-list-table .column-priority,
152
+ div.wrap.login-redirect table.wp-list-table .column-deny_wpadmin,
153
+ div.wrap.login-redirect table.wp-list-table .column-disable_toolbar {
154
+ width: 10%;
155
+ text-align: center;
156
+ }
157
+
158
+ div.wrap.login-redirect table.wp-list-table .column-url,
159
+ div.wrap.login-redirect table.wp-list-table .column-logout_url{
160
+ width: 50%;
161
+ }
162
+ /* login redirect end */
163
+
164
+ /* settings start */
165
+ #wpfront-user-role-editor-options table div.options-list {
166
+ float: left;
167
+ width: 200px;
168
+ }
169
+ /* settings end */
170
+
171
+ /* go pro start */
172
+ div.wrap.go-pro div.container:before,
173
+ div.wrap.go-pro div.container:after {
174
+ content:"";
175
+ display:table;
176
+ }
177
+ div.wrap.go-pro div.container:after {
178
+ clear:both;
179
+ }
180
+ div.wrap.go-pro div.container {
181
+ zoom:1; /* For IE 6/7 (trigger hasLayout) */
182
+ margin-top: 1em;
183
+ }
184
+
185
+ div.wrap.go-pro {
186
+ /* text-align: center;*/
187
+ /* background: #FFF;*/
188
+ /* padding-top: 1%;
189
+ padding-bottom: 1%;*/
190
+ }
191
+
192
+ div.wrap.go-pro div.container {
193
+ text-align: center;
194
+ /* display: inline-block; */
195
+ }
196
+
197
+ div.wrap.go-pro div.container div.col {
198
+ float: left;
199
+ width: 200px;
200
+ background-color: #FFF;
201
+ /* box-shadow: 1px 1px 15px 0px rgba(50, 50, 50, 0.75);*/
202
+ margin-right: 1px;
203
+ }
204
+
205
+ div.wrap.go-pro div.container div.cell {
206
+ height: 40px;
207
+ padding: 10px 10px 0px 10px;
208
+ text-align: center;
209
+ border: 1px solid #fafafa;
210
+ }
211
+
212
+ div.wrap.go-pro div.container div.header.cell {
213
+ background-color: #2ea2cc;
214
+ height: auto;
215
+ padding-top: 5px;
216
+ padding-bottom: 5px;
217
+ border-radius: 3px 3px 0px 0px;
218
+ border: 0px;
219
+ }
220
+
221
+ div.wrap.go-pro div.container div.header.cell h3 {
222
+ color: #FFF;
223
+ }
224
+
225
+ div.wrap.go-pro div.license-container {
226
+ margin-bottom: 25px;
227
+ }
228
+
229
+ div.wrap.go-pro div.license-container table.form-table td.invalid,
230
+ div.wrap.go-pro div.license-container table.form-table td.expired {
231
+ color: red;
232
+ }
233
+ /* go pro end */
234
+
235
+ /* assign roles start */
236
+ div.wrap.assign-roles div.role-list div.role-list-item,
237
+ div.wrap.migrate-users div.role-list div.role-list-item {
238
+ padding-bottom: 5px;
239
+ }
240
+ /* assign roles end */
241
+
242
+ /* import roles start */
243
+ div.wrap.import-roles table label.override, div.wrap.import-roles p.override {
244
+ color: red;
245
+ }
246
+
247
+ div.wrap.import-roles table label sup {
248
+ display: none;
249
+ }
250
+
251
+ div.wrap.import-roles table label.override sup {
252
+ display: inline-block;
253
+ }
254
+ /* import roles end */
255
+
256
+ /* admin menu editor start */
257
+ div.wrap.menu-editor div.spacer {
258
+ display: inline-block;
259
+ width: 10px;
260
+ }
261
+
262
+ div.wrap.menu-editor input.button.select-all,
263
+ div.wrap.menu-editor input.button.select-none {
264
+ width: 100px;
265
+ }
266
+
267
+ div.wrap.menu-editor div.left-parent-menus,
268
+ div.wrap.menu-editor div.right-sub-menus {
269
+ position: relative;
270
+ float: left;
271
+ min-width: 160px;
272
+ width: 50%;
273
+ max-width: 250px;
274
+ }
275
+
276
+ div.wrap.menu-editor div.left-parent-menus div.menu-item,
277
+ div.wrap.menu-editor div.right-sub-menus div.menu-item {
278
+ position: relative;
279
+ height: 34px;
280
+ font-size: 14px;
281
+ line-height: 18px;
282
+ padding: 0px;
283
+ border: 1px solid #888888;
284
+ border-bottom: 0;
285
+ margin: 0;
286
+ padding: 0;
287
+ }
288
+
289
+ div.wrap.menu-editor div.left-parent-menus div.menu-item.last,
290
+ div.wrap.menu-editor div.right-sub-menus div.menu-item.last {
291
+ border-bottom: 1px solid #888888;
292
+ }
293
+
294
+ div.wrap.menu-editor div.right-sub-menus div.menu-item {
295
+ border-left: 0;
296
+ }
297
+
298
+ div.wrap.menu-editor div.left-parent-menus div.menu-item,
299
+ div.wrap.menu-editor div.right-sub-menus div.menu-item {
300
+ cursor: pointer;
301
+ background: rgb(255,255,255); /* Old browsers */
302
+ background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(246,246,246,1) 47%, rgba(237,237,237,1) 100%); /* FF3.6-15 */
303
+ background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(246,246,246,1) 47%,rgba(237,237,237,1) 100%); /* Chrome10-25,Safari5.1-6 */
304
+ background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(246,246,246,1) 47%,rgba(237,237,237,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
305
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); /* IE6-9 */
306
+ }
307
+
308
+ div.wrap.menu-editor div.left-parent-menus div.menu-item.selected {
309
+ background: rgb(238,238,238); /* Old browsers */
310
+ background: -moz-linear-gradient(top, rgba(238,238,238,1) 0%, rgba(204,204,204,1) 100%); /* FF3.6-15 */
311
+ background: -webkit-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* Chrome10-25,Safari5.1-6 */
312
+ background: linear-gradient(to bottom, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
313
+ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cccccc',GradientType=0 ); /* IE6-9 */
314
+ }
315
+
316
+ div.wrap.menu-editor div.right-sub-menus div.submenu-container {
317
+ position: absolute;
318
+ width: 100%;
319
+ border: 0;
320
+ margin: 0;
321
+ padding: 0;
322
+ visibility: hidden;
323
+ }
324
+
325
+ div.wrap.menu-editor div.right-sub-menus div.submenu-container.selected {
326
+ visibility: visible;
327
+ }
328
+
329
+ div.wrap.menu-editor div.right-sub-menus div.menu-item {
330
+ cursor: default;
331
+ }
332
+
333
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.current-menu-indicator,
334
+ div.wrap.menu-editor div.menu-item div.menu-info {
335
+ position: absolute;
336
+ right: 0;
337
+ top: 0;
338
+ padding: 7px;
339
+ display: none;
340
+ }
341
+
342
+ div.wrap.menu-editor div.menu-item div.menu-info {
343
+ display: inline-block;
344
+ }
345
+
346
+ div.wrap.menu-editor div.menu-item div.menu-info i {
347
+ cursor: pointer;
348
+ }
349
+
350
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-info {
351
+ right: 15px;
352
+ }
353
+
354
+ div.wrap.menu-editor div.left-parent-menus div.menu-item.selected div.current-menu-indicator {
355
+ display: inline-block;
356
+ }
357
+
358
+ div.wrap.menu-editor div.left-parent-menus div.menu-item input.select,
359
+ div.wrap.menu-editor div.right-sub-menus div.menu-item input.select {
360
+ float: left;
361
+ margin: 9px;
362
+ }
363
+
364
+ div.wrap.menu-editor div.left-parent-menus div.menu-item input.select {
365
+ margin-right: 0px;
366
+ }
367
+
368
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-image {
369
+ float: left;
370
+ width: 36px;
371
+ height: 34px;
372
+ margin: 0;
373
+ text-align: center;
374
+ opacity: 0.8;
375
+ }
376
+
377
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-image img {
378
+ padding: 9px 0 0;
379
+ }
380
+
381
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-image::before {
382
+ color: inherit;
383
+ }
384
+
385
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-name,
386
+ div.wrap.menu-editor div.right-sub-menus div.menu-item div.menu-name {
387
+ padding: 7px 0;
388
+ font-weight: 600;
389
+ }
390
+
391
+ div.wrap.menu-editor div.right-sub-menus div.menu-item div.menu-name {
392
+ font-weight: 500;
393
+ }
394
+
395
+ div.wrap.menu-editor div.left-parent-menus div.menu-item div.menu-name span.count-0 {
396
+ display: none;
397
+ }
398
+
399
+ div.wrap.menu-editor div.submit-botton {
400
+ clear: both;
401
+ padding-top: 1px;
402
+ }
403
+
404
+ /* admin menu editor end */
405
+
406
+
407
+ /* extended permissions start */
408
+
409
+ div.wpfront-user-role-editor-post-type-extended-permission {
410
+ display: flex;
411
+ margin-top: 8px;
412
+ width: 100%;
413
+ max-width: 1100px;
414
+ }
415
+
416
+ div.wpfront-user-role-editor-post-type-extended-permission table {
417
+ width: 100%;
418
+ }
419
+
420
+ div.wpfront-user-role-editor-post-type-extended-permission table th,
421
+ div.wpfront-user-role-editor-post-type-extended-permission table td {
422
+ text-align: center;
423
+ font-weight: normal;
424
+ }
425
+
426
+ div.wpfront-user-role-editor-post-type-extended-permission table thead th,
427
+ div.wpfront-user-role-editor-post-type-extended-permission table tbody th {
428
+ font-weight: bold;
429
+ }
430
+
431
+ div.wpfront-user-role-editor-post-type-extended-permission table th.role {
432
+ text-align: left;
433
+ width: 15%;
434
+ }
435
+
436
+ div.wpfront-user-role-editor-post-type-extended-permission table th.view,
437
+ div.wpfront-user-role-editor-post-type-extended-permission table th.edit,
438
+ div.wpfront-user-role-editor-post-type-extended-permission table th.delete {
439
+ width: 3%;
440
+ }
441
+
442
+ div.wpfront-user-role-editor-post-type-extended-permission table th.view-deny-action {
443
+ text-align: left;
444
+ padding-left: 1%;
445
+ }
446
+
447
+ div.wpfront-user-role-editor-post-type-extended-permission table td.view-deny-action.four-O-four {
448
+ text-align: left;
449
+ width: 7%;
450
+ padding-left: 1%;
451
+ }
452
+
453
+ div.wpfront-user-role-editor-post-type-extended-permission table th.redirect,
454
+ div.wpfront-user-role-editor-post-type-extended-permission table td.redirect {
455
+ text-align: left;
456
+ width: 50%;
457
+ }
458
+
459
+ div.wpfront-user-role-editor-post-type-extended-permission table td.redirect input.url {
460
+ width: 70%;
461
+ max-width: 30em;
462
+ }
463
+
464
+ #wpfront-user-role-editor-role-permissions-state td,
465
+ #wpfront-user-role-editor-role-permissions-requires-login td {
466
+ padding-left: 30px;
467
+ }
468
+
469
+ #wpfront-user-role-editor-role-permissions-requires-login th {
470
+ text-align: left;
471
+ }
472
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.view,
473
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.edit,
474
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.delete,
475
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.view-deny-action {
476
+ border-left: 1px solid #ededed;
477
+ }
478
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.view,
479
+ div.wpfront-user-role-editor-post-type-extended-permission table colgroup.delete {
480
+ background-color: #fbfbfb;
481
+ }
482
+ div.wpfront-user-role-editor-post-type-extended-permission table {
483
+ border-collapse: collapse;
484
+ }
485
+
486
+ div.wpfront-user-role-editor-post-type-extended-permission-legend {
487
+ font-style: italic;
488
+ margin-top: 10px;
489
+ opacity: 0.8;
490
+ }
491
+
492
+ /* extended permissions end */
493
+
494
+
495
+
496
+ /* bulk edit start */
497
+
498
+ div.wrap.bulk-edit div.options p {
499
+ font-weight: bold;
500
+ }
501
+
502
+ /* bulk edit end */
503
+
504
+ /* bulk edit extended permissions start */
505
+
506
+ div.wrap.bulk-edit-extended-permissions p.loading-image {
507
+ text-align: center;
508
+ }
509
+
510
+ div.wrap.bulk-edit-extended-permissions div.bulkactions,
511
+ div.wrap.bulk-edit-extended-permissions div.row-actions {
512
+ display: none;
513
+ }
514
+
515
+ div.wrap.bulk-edit-extended-permissions div#poststuff {
516
+ max-width:1200px;
517
+ }
518
+
519
+ div.wrap.bulk-edit-container div.update-info-line span {
520
+ margin-left: 10px;
521
+ }
522
+
523
+ div.wrap.bulk-edit-container div.update-info-line i {
524
+ width: 13px;
525
+ }
526
+
527
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody td,
528
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody th{
529
+ text-align: center;
530
+ padding: 3px 20px 3px 0px;
531
+ }
532
+
533
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody td.redirect
534
+ {
535
+ text-align: left;
536
+ width: 69.5%;
537
+ }
538
+
539
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody td.four-o-four
540
+ {
541
+ text-align: left;
542
+ width:10%;
543
+ }
544
+
545
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody th.view-deny-action
546
+ {
547
+ text-align: left;
548
+
549
+ }
550
+
551
+ div.wrap.bulk-edit-extended-permissions div#single-role table tbody td input.url
552
+ {
553
+ width: 25em;
554
+ }
555
+ /* bulk edit extended permissions end */
556
+
557
+ /* bulk edit user post permissions start */
558
+
559
+ div.wrap.bulk-edit-user-post-permissions p.loading-image {
560
+ text-align: center;
561
+ }
562
+
563
+ /* bulk edit user post permissions end */
564
+
565
+ /* bulk edit extended permissions to user post permissions start */
566
+
567
+ div.wrap.bulk-edit-extended-permissions-to-user-post-permissions p.loading-image {
568
+ text-align: center;
569
+ }
570
+
571
+ /* bulk edit extended permissions to user post permissions end */
572
+
573
+ /* multisite sync start */
574
+
575
+ div.wrap.ms-sync table.sites th.column-id,
576
+ div.wrap.ms-sync table.sites td.column-id {
577
+ display: none;
578
+ }
579
+
580
+ div.wrap.ms-sync table.sites tr.selected {
581
+ background-color: #ffd;
582
+ }
583
+
584
+ div.wrap.ms-sync div#sync-container div.sync-info-line {
585
+ padding: 3px 5px;
586
+ }
587
+
588
+ div.wrap.ms-sync div#sync-container div.sync-info-line span,
589
+ div.wrap.ms-sync div#sync-container div.sync-info-line a {
590
+ margin-left: 10px;
591
+ }
592
+
593
+ /* multisite sync end */
594
+
595
+ /* post type screen start */
596
+
597
+ div.wrap.post-type table.wp-list-table.post-type .column-edited,
598
+ div.wrap.post-type table.wp-list-table.post-type .column-status {
599
+ text-align: center;
600
+ }
601
+
602
+ div.wrap.post-type-add-edit ul.chosen-choices {
603
+ display: flex;
604
+ align-items: center;
605
+ flex-wrap: wrap;
606
+ }
607
+
608
+ /* post type screen start */
609
+
610
+ /* taxonomies screen start */
611
+
612
+ div.wrap.taxonomy table.wp-list-table.taxonomies .column-edited,
613
+ div.wrap.taxonomy table.wp-list-table.taxonomies .column-status {
614
+ text-align: center;
615
+ }
616
+
617
+ div.wrap.taxonomy-add-edit ul.chosen-choices {
618
+ display: flex;
619
+ align-items: center;
620
+ flex-wrap: wrap;
621
+ }
622
+
623
+ /* taxonomies screen start */
624
+
625
+ .ui-tooltip {
626
+ background: #ffffff;
627
+ border: 1px solid #888;
628
+ }
629
+ .ui-tooltip {
630
+ padding: 10px 20px;
631
+ color: black;
632
+ border-radius: 5px;
633
+ box-shadow: 0 0 7px #888888;
634
+ max-width:350px;
635
+ }
636
+
637
+ div.thickbox p.error {
638
+ color: red;
639
+ }
640
+
{css → assets/css}/widget-permissions.css RENAMED
@@ -16,4 +16,9 @@ p span.user-restriction-container span.roles-container {
16
 
17
  p span.user-restriction-container span.roles-container.hidden {
18
  display: none;
 
 
 
 
 
19
  }
16
 
17
  p span.user-restriction-container span.roles-container.hidden {
18
  display: none;
19
+ }
20
+
21
+ div.widget-title h3 span.in-title-access-type {
22
+ font-style: italic;
23
+ opacity: 0.6;
24
  }
{classes/base → assets/images}/index.php RENAMED
File without changes
{images → assets/images}/loading.gif RENAMED
File without changes
{classes/entities → assets}/index.php RENAMED
File without changes
assets/js/chosen/chosen.jquery.min.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ /* Chosen v1.8.7 | (c) 2011-2018 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */
2
+
3
+ (function(){var t,e,s,i,n=function(t,e){return function(){return t.apply(e,arguments)}},r=function(t,e){function s(){this.constructor=t}for(var i in e)o.call(e,i)&&(t[i]=e[i]);return s.prototype=e.prototype,t.prototype=new s,t.__super__=e.prototype,t},o={}.hasOwnProperty;(i=function(){function t(){this.options_index=0,this.parsed=[]}return t.prototype.add_node=function(t){return"OPTGROUP"===t.nodeName.toUpperCase()?this.add_group(t):this.add_option(t)},t.prototype.add_group=function(t){var e,s,i,n,r,o;for(e=this.parsed.length,this.parsed.push({array_index:e,group:!0,label:t.label,title:t.title?t.title:void 0,children:0,disabled:t.disabled,classes:t.className}),o=[],s=0,i=(r=t.childNodes).length;s<i;s++)n=r[s],o.push(this.add_option(n,e,t.disabled));return o},t.prototype.add_option=function(t,e,s){if("OPTION"===t.nodeName.toUpperCase())return""!==t.text?(null!=e&&(this.parsed[e].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:t.value,text:t.text,html:t.innerHTML,title:t.title?t.title:void 0,selected:t.selected,disabled:!0===s?s:t.disabled,group_array_index:e,group_label:null!=e?this.parsed[e].label:null,classes:t.className,style:t.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1},t}()).select_to_array=function(t){var e,s,n,r,o;for(r=new i,s=0,n=(o=t.childNodes).length;s<n;s++)e=o[s],r.add_node(e);return r.parsed},e=function(){function t(e,s){this.form_field=e,this.options=null!=s?s:{},this.label_click_handler=n(this.label_click_handler,this),t.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers(),this.on_ready())}return t.prototype.set_default_values=function(){return this.click_test_action=function(t){return function(e){return t.test_active_click(e)}}(this),this.activate_action=function(t){return function(e){return t.activate_field(e)}}(this),this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.is_rtl=this.options.rtl||/\bchosen-rtl\b/.test(this.form_field.className),this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text&&this.options.allow_single_deselect,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null==this.options.enable_split_word_search||this.options.enable_split_word_search,this.group_search=null==this.options.group_search||this.options.group_search,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null==this.options.single_backstroke_delete||this.options.single_backstroke_delete,this.max_selected_options=this.options.max_selected_options||Infinity,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null==this.options.display_selected_options||this.options.display_selected_options,this.display_disabled_options=null==this.options.display_disabled_options||this.options.display_disabled_options,this.include_group_label_in_selected=this.options.include_group_label_in_selected||!1,this.max_shown_results=this.options.max_shown_results||Number.POSITIVE_INFINITY,this.case_sensitive_search=this.options.case_sensitive_search||!1,this.hide_results_on_select=null==this.options.hide_results_on_select||this.options.hide_results_on_select},t.prototype.set_default_text=function(){return this.form_field.getAttribute("data-placeholder")?this.default_text=this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.default_text=this.options.placeholder_text_multiple||this.options.placeholder_text||t.default_multiple_text:this.default_text=this.options.placeholder_text_single||this.options.placeholder_text||t.default_single_text,this.default_text=this.escape_html(this.default_text),this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||t.default_no_result_text},t.prototype.choice_label=function(t){return this.include_group_label_in_selected&&null!=t.group_label?"<b class='group-name'>"+this.escape_html(t.group_label)+"</b>"+t.html:t.html},t.prototype.mouse_enter=function(){return this.mouse_on_container=!0},t.prototype.mouse_leave=function(){return this.mouse_on_container=!1},t.prototype.input_focus=function(t){if(this.is_multiple){if(!this.active_field)return setTimeout(function(t){return function(){return t.container_mousedown()}}(this),50)}else if(!this.active_field)return this.activate_field()},t.prototype.input_blur=function(t){if(!this.mouse_on_container)return this.active_field=!1,setTimeout(function(t){return function(){return t.blur_test()}}(this),100)},t.prototype.label_click_handler=function(t){return this.is_multiple?this.container_mousedown(t):this.activate_field()},t.prototype.results_option_build=function(t){var e,s,i,n,r,o,h;for(e="",h=0,n=0,r=(o=this.results_data).length;n<r&&(s=o[n],i="",""!==(i=s.group?this.result_add_group(s):this.result_add_option(s))&&(h++,e+=i),(null!=t?t.first:void 0)&&(s.selected&&this.is_multiple?this.choice_build(s):s.selected&&!this.is_multiple&&this.single_set_selected_text(this.choice_label(s))),!(h>=this.max_shown_results));n++);return e},t.prototype.result_add_option=function(t){var e,s;return t.search_match&&this.include_option_in_results(t)?(e=[],t.disabled||t.selected&&this.is_multiple||e.push("active-result"),!t.disabled||t.selected&&this.is_multiple||e.push("disabled-result"),t.selected&&e.push("result-selected"),null!=t.group_array_index&&e.push("group-option"),""!==t.classes&&e.push(t.classes),s=document.createElement("li"),s.className=e.join(" "),t.style&&(s.style.cssText=t.style),s.setAttribute("data-option-array-index",t.array_index),s.innerHTML=t.highlighted_html||t.html,t.title&&(s.title=t.title),this.outerHTML(s)):""},t.prototype.result_add_group=function(t){var e,s;return(t.search_match||t.group_match)&&t.active_options>0?((e=[]).push("group-result"),t.classes&&e.push(t.classes),s=document.createElement("li"),s.className=e.join(" "),s.innerHTML=t.highlighted_html||this.escape_html(t.label),t.title&&(s.title=t.title),this.outerHTML(s)):""},t.prototype.results_update_field=function(){if(this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing)return this.winnow_results()},t.prototype.reset_single_select_options=function(){var t,e,s,i,n;for(n=[],t=0,e=(s=this.results_data).length;t<e;t++)(i=s[t]).selected?n.push(i.selected=!1):n.push(void 0);return n},t.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},t.prototype.results_search=function(t){return this.results_showing?this.winnow_results():this.results_show()},t.prototype.winnow_results=function(t){var e,s,i,n,r,o,h,l,c,_,a,u,d,p,f;for(this.no_results_clear(),_=0,e=(h=this.get_search_text()).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),c=this.get_search_regex(e),i=0,n=(l=this.results_data).length;i<n;i++)(r=l[i]).search_match=!1,a=null,u=null,r.highlighted_html="",this.include_option_in_results(r)&&(r.group&&(r.group_match=!1,r.active_options=0),null!=r.group_array_index&&this.results_data[r.group_array_index]&&(0===(a=this.results_data[r.group_array_index]).active_options&&a.search_match&&(_+=1),a.active_options+=1),f=r.group?r.label:r.text,r.group&&!this.group_search||(u=this.search_string_match(f,c),r.search_match=null!=u,r.search_match&&!r.group&&(_+=1),r.search_match?(h.length&&(d=u.index,o=f.slice(0,d),s=f.slice(d,d+h.length),p=f.slice(d+h.length),r.highlighted_html=this.escape_html(o)+"<em>"+this.escape_html(s)+"</em>"+this.escape_html(p)),null!=a&&(a.group_match=!0)):null!=r.group_array_index&&this.results_data[r.group_array_index].search_match&&(r.search_match=!0)));return this.result_clear_highlight(),_<1&&h.length?(this.update_results_content(""),this.no_results(h)):(this.update_results_content(this.results_option_build()),(null!=t?t.skip_highlight:void 0)?void 0:this.winnow_results_set_highlight())},t.prototype.get_search_regex=function(t){var e,s;return s=this.search_contains?t:"(^|\\s|\\b)"+t+"[^\\s]*",this.enable_split_word_search||this.search_contains||(s="^"+s),e=this.case_sensitive_search?"":"i",new RegExp(s,e)},t.prototype.search_string_match=function(t,e){var s;return s=e.exec(t),!this.search_contains&&(null!=s?s[1]:void 0)&&(s.index+=1),s},t.prototype.choices_count=function(){var t,e,s;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,t=0,e=(s=this.form_field.options).length;t<e;t++)s[t].selected&&(this.selected_option_count+=1);return this.selected_option_count},t.prototype.choices_click=function(t){if(t.preventDefault(),this.activate_field(),!this.results_showing&&!this.is_disabled)return this.results_show()},t.prototype.keydown_checker=function(t){var e,s;switch(s=null!=(e=t.which)?e:t.keyCode,this.search_field_scale(),8!==s&&this.pending_backstroke&&this.clear_backstroke(),s){case 8:this.backstroke_length=this.get_search_field_value().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(t),this.mouse_on_container=!1;break;case 13:case 27:this.results_showing&&t.preventDefault();break;case 32:this.disable_search&&t.preventDefault();break;case 38:t.preventDefault(),this.keyup_arrow();break;case 40:t.preventDefault(),this.keydown_arrow()}},t.prototype.keyup_checker=function(t){var e,s;switch(s=null!=(e=t.which)?e:t.keyCode,this.search_field_scale(),s){case 8:this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0?this.keydown_backstroke():this.pending_backstroke||(this.result_clear_highlight(),this.results_search());break;case 13:t.preventDefault(),this.results_showing&&this.result_select(t);break;case 27:this.results_showing&&this.results_hide();break;case 9:case 16:case 17:case 18:case 38:case 40:case 91:break;default:this.results_search()}},t.prototype.clipboard_event_checker=function(t){if(!this.is_disabled)return setTimeout(function(t){return function(){return t.results_search()}}(this),50)},t.prototype.container_width=function(){return null!=this.options.width?this.options.width:this.form_field.offsetWidth+"px"},t.prototype.include_option_in_results=function(t){return!(this.is_multiple&&!this.display_selected_options&&t.selected)&&(!(!this.display_disabled_options&&t.disabled)&&!t.empty)},t.prototype.search_results_touchstart=function(t){return this.touch_started=!0,this.search_results_mouseover(t)},t.prototype.search_results_touchmove=function(t){return this.touch_started=!1,this.search_results_mouseout(t)},t.prototype.search_results_touchend=function(t){if(this.touch_started)return this.search_results_mouseup(t)},t.prototype.outerHTML=function(t){var e;return t.outerHTML?t.outerHTML:((e=document.createElement("div")).appendChild(t),e.innerHTML)},t.prototype.get_single_html=function(){return'<a class="chosen-single chosen-default">\n <span>'+this.default_text+'</span>\n <div><b></b></div>\n</a>\n<div class="chosen-drop">\n <div class="chosen-search">\n <input class="chosen-search-input" type="text" autocomplete="off" />\n </div>\n <ul class="chosen-results"></ul>\n</div>'},t.prototype.get_multi_html=function(){return'<ul class="chosen-choices">\n <li class="search-field">\n <input class="chosen-search-input" type="text" autocomplete="off" value="'+this.default_text+'" />\n </li>\n</ul>\n<div class="chosen-drop">\n <ul class="chosen-results"></ul>\n</div>'},t.prototype.get_no_results_html=function(t){return'<li class="no-results">\n '+this.results_none_found+" <span>"+this.escape_html(t)+"</span>\n</li>"},t.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:!(/iP(od|hone)/i.test(window.navigator.userAgent)||/IEMobile/i.test(window.navigator.userAgent)||/Windows Phone/i.test(window.navigator.userAgent)||/BlackBerry/i.test(window.navigator.userAgent)||/BB10/i.test(window.navigator.userAgent)||/Android.*Mobile/i.test(window.navigator.userAgent))},t.default_multiple_text="Select Some Options",t.default_single_text="Select an Option",t.default_no_result_text="No results match",t}(),(t=jQuery).fn.extend({chosen:function(i){return e.browser_is_supported()?this.each(function(e){var n,r;r=(n=t(this)).data("chosen"),"destroy"!==i?r instanceof s||n.data("chosen",new s(this,i)):r instanceof s&&r.destroy()}):this}}),s=function(s){function n(){return n.__super__.constructor.apply(this,arguments)}return r(n,e),n.prototype.setup=function(){return this.form_field_jq=t(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex},n.prototype.set_up_html=function(){var e,s;return(e=["chosen-container"]).push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&e.push(this.form_field.className),this.is_rtl&&e.push("chosen-rtl"),s={"class":e.join(" "),title:this.form_field.title},this.form_field.id.length&&(s.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=t("<div />",s),this.container.width(this.container_width()),this.is_multiple?this.container.html(this.get_multi_html()):this.container.html(this.get_single_html()),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior()},n.prototype.on_ready=function(){return this.form_field_jq.trigger("chosen:ready",{chosen:this})},n.prototype.register_observers=function(){return this.container.on("touchstart.chosen",function(t){return function(e){t.container_mousedown(e)}}(this)),this.container.on("touchend.chosen",function(t){return function(e){t.container_mouseup(e)}}(this)),this.container.on("mousedown.chosen",function(t){return function(e){t.container_mousedown(e)}}(this)),this.container.on("mouseup.chosen",function(t){return function(e){t.container_mouseup(e)}}(this)),this.container.on("mouseenter.chosen",function(t){return function(e){t.mouse_enter(e)}}(this)),this.container.on("mouseleave.chosen",function(t){return function(e){t.mouse_leave(e)}}(this)),this.search_results.on("mouseup.chosen",function(t){return function(e){t.search_results_mouseup(e)}}(this)),this.search_results.on("mouseover.chosen",function(t){return function(e){t.search_results_mouseover(e)}}(this)),this.search_results.on("mouseout.chosen",function(t){return function(e){t.search_results_mouseout(e)}}(this)),this.search_results.on("mousewheel.chosen DOMMouseScroll.chosen",function(t){return function(e){t.search_results_mousewheel(e)}}(this)),this.search_results.on("touchstart.chosen",function(t){return function(e){t.search_results_touchstart(e)}}(this)),this.search_results.on("touchmove.chosen",function(t){return function(e){t.search_results_touchmove(e)}}(this)),this.search_results.on("touchend.chosen",function(t){return function(e){t.search_results_touchend(e)}}(this)),this.form_field_jq.on("chosen:updated.chosen",function(t){return function(e){t.results_update_field(e)}}(this)),this.form_field_jq.on("chosen:activate.chosen",function(t){return function(e){t.activate_field(e)}}(this)),this.form_field_jq.on("chosen:open.chosen",function(t){return function(e){t.container_mousedown(e)}}(this)),this.form_field_jq.on("chosen:close.chosen",function(t){return function(e){t.close_field(e)}}(this)),this.search_field.on("blur.chosen",function(t){return function(e){t.input_blur(e)}}(this)),this.search_field.on("keyup.chosen",function(t){return function(e){t.keyup_checker(e)}}(this)),this.search_field.on("keydown.chosen",function(t){return function(e){t.keydown_checker(e)}}(this)),this.search_field.on("focus.chosen",function(t){return function(e){t.input_focus(e)}}(this)),this.search_field.on("cut.chosen",function(t){return function(e){t.clipboard_event_checker(e)}}(this)),this.search_field.on("paste.chosen",function(t){return function(e){t.clipboard_event_checker(e)}}(this)),this.is_multiple?this.search_choices.on("click.chosen",function(t){return function(e){t.choices_click(e)}}(this)):this.container.on("click.chosen",function(t){t.preventDefault()})},n.prototype.destroy=function(){return t(this.container[0].ownerDocument).off("click.chosen",this.click_test_action),this.form_field_label.length>0&&this.form_field_label.off("click.chosen"),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},n.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field.disabled||this.form_field_jq.parents("fieldset").is(":disabled"),this.container.toggleClass("chosen-disabled",this.is_disabled),this.search_field[0].disabled=this.is_disabled,this.is_multiple||this.selected_item.off("focus.chosen",this.activate_field),this.is_disabled?this.close_field():this.is_multiple?void 0:this.selected_item.on("focus.chosen",this.activate_field)},n.prototype.container_mousedown=function(e){var s;if(!this.is_disabled)return!e||"mousedown"!==(s=e.type)&&"touchstart"!==s||this.results_showing||e.preventDefault(),null!=e&&t(e.target).hasClass("search-choice-close")?void 0:(this.active_field?this.is_multiple||!e||t(e.target)[0]!==this.selected_item[0]&&!t(e.target).parents("a.chosen-single").length||(e.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),t(this.container[0].ownerDocument).on("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},n.prototype.container_mouseup=function(t){if("ABBR"===t.target.nodeName&&!this.is_disabled)return this.results_reset(t)},n.prototype.search_results_mousewheel=function(t){var e;if(t.originalEvent&&(e=t.originalEvent.deltaY||-t.originalEvent.wheelDelta||t.originalEvent.detail),null!=e)return t.preventDefault(),"DOMMouseScroll"===t.type&&(e*=40),this.search_results.scrollTop(e+this.search_results.scrollTop())},n.prototype.blur_test=function(t){if(!this.active_field&&this.container.hasClass("chosen-container-active"))return this.close_field()},n.prototype.close_field=function(){return t(this.container[0].ownerDocument).off("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale(),this.search_field.blur()},n.prototype.activate_field=function(){if(!this.is_disabled)return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},n.prototype.test_active_click=function(e){var s;return(s=t(e.target).closest(".chosen-container")).length&&this.container[0]===s[0]?this.active_field=!0:this.close_field()},n.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=i.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},n.prototype.result_do_highlight=function(t){var e,s,i,n,r;if(t.length){if(this.result_clear_highlight(),this.result_highlight=t,this.result_highlight.addClass("highlighted"),i=parseInt(this.search_results.css("maxHeight"),10),r=this.search_results.scrollTop(),n=i+r,s=this.result_highlight.position().top+this.search_results.scrollTop(),(e=s+this.result_highlight.outerHeight())>=n)return this.search_results.scrollTop(e-i>0?e-i:0);if(s<r)return this.search_results.scrollTop(s)}},n.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},n.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.get_search_field_value()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},n.prototype.update_results_content=function(t){return this.search_results.html(t)},n.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},n.prototype.set_tab_index=function(t){var e;if(this.form_field.tabIndex)return e=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=e},n.prototype.set_label_behavior=function(){if(this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=t("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0)return this.form_field_label.on("click.chosen",this.label_click_handler)},n.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},n.prototype.search_results_mouseup=function(e){var s;if((s=t(e.target).hasClass("active-result")?t(e.target):t(e.target).parents(".active-result").first()).length)return this.result_highlight=s,this.result_select(e),this.search_field.focus()},n.prototype.search_results_mouseover=function(e){var s;if(s=t(e.target).hasClass("active-result")?t(e.target):t(e.target).parents(".active-result").first())return this.result_do_highlight(s)},n.prototype.search_results_mouseout=function(e){if(t(e.target).hasClass("active-result")||t(e.target).parents(".active-result").first())return this.result_clear_highlight()},n.prototype.choice_build=function(e){var s,i;return s=t("<li />",{"class":"search-choice"}).html("<span>"+this.choice_label(e)+"</span>"),e.disabled?s.addClass("search-choice-disabled"):((i=t("<a />",{"class":"search-choice-close","data-option-array-index":e.array_index})).on("click.chosen",function(t){return function(e){return t.choice_destroy_link_click(e)}}(this)),s.append(i)),this.search_container.before(s)},n.prototype.choice_destroy_link_click=function(e){if(e.preventDefault(),e.stopPropagation(),!this.is_disabled)return this.choice_destroy(t(e.target))},n.prototype.choice_destroy=function(t){if(this.result_deselect(t[0].getAttribute("data-option-array-index")))return this.active_field?this.search_field.focus():this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.get_search_field_value().length<1&&this.results_hide(),t.parents("li").first().remove(),this.search_field_scale()},n.prototype.results_reset=function(){if(this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.trigger_form_field_change(),this.active_field)return this.results_hide()},n.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},n.prototype.result_select=function(t){var e,s;if(this.result_highlight)return e=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?e.removeClass("active-result"):this.reset_single_select_options(),e.addClass("result-selected"),s=this.results_data[e[0].getAttribute("data-option-array-index")],s.selected=!0,this.form_field.options[s.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(s):this.single_set_selected_text(this.choice_label(s)),this.is_multiple&&(!this.hide_results_on_select||t.metaKey||t.ctrlKey)?t.metaKey||t.ctrlKey?this.winnow_results({skip_highlight:!0}):(this.search_field.val(""),this.winnow_results()):(this.results_hide(),this.show_search_field_default()),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.trigger_form_field_change({selected:this.form_field.options[s.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,t.preventDefault(),this.search_field_scale())},n.prototype.single_set_selected_text=function(t){return null==t&&(t=this.default_text),t===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").html(t)},n.prototype.result_deselect=function(t){var e;return e=this.results_data[t],!this.form_field.options[e.options_index].disabled&&(e.selected=!1,this.form_field.options[e.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.trigger_form_field_change({deselected:this.form_field.options[e.options_index].value}),this.search_field_scale(),!0)},n.prototype.single_deselect_control_build=function(){if(this.allow_single_deselect)return this.selected_item.find("abbr").length||this.selected_item.find("span").first().after('<abbr class="search-choice-close"></abbr>'),this.selected_item.addClass("chosen-single-with-deselect")},n.prototype.get_search_field_value=function(){return this.search_field.val()},n.prototype.get_search_text=function(){return t.trim(this.get_search_field_value())},n.prototype.escape_html=function(e){return t("<div/>").text(e).html()},n.prototype.winnow_results_set_highlight=function(){var t,e;if(e=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),null!=(t=e.length?e.first():this.search_results.find(".active-result").first()))return this.result_do_highlight(t)},n.prototype.no_results=function(t){var e;return e=this.get_no_results_html(t),this.search_results.append(e),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},n.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},n.prototype.keydown_arrow=function(){var t;return this.results_showing&&this.result_highlight?(t=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(t):void 0:this.results_show()},n.prototype.keyup_arrow=function(){var t;return this.results_showing||this.is_multiple?this.result_highlight?(t=this.result_highlight.prevAll("li.active-result")).length?this.result_do_highlight(t.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight()):void 0:this.results_show()},n.prototype.keydown_backstroke=function(){var t;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(t=this.search_container.siblings("li.search-choice").last()).length&&!t.hasClass("search-choice-disabled")?(this.pending_backstroke=t,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0},n.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},n.prototype.search_field_scale=function(){var e,s,i,n,r,o,h;if(this.is_multiple){for(r={position:"absolute",left:"-1000px",top:"-1000px",display:"none",whiteSpace:"pre"},s=0,i=(o=["fontSize","fontStyle","fontWeight","fontFamily","lineHeight","textTransform","letterSpacing"]).length;s<i;s++)r[n=o[s]]=this.search_field.css(n);return(e=t("<div />").css(r)).text(this.get_search_field_value()),t("body").append(e),h=e.width()+25,e.remove(),this.container.is(":visible")&&(h=Math.min(this.container.outerWidth()-10,h)),this.search_field.width(h)}},n.prototype.trigger_form_field_change=function(t){return this.form_field_jq.trigger("input",t),this.form_field_jq.trigger("change",t)},n}()}).call(this);
{classes → assets/js}/index.php RENAMED
File without changes
{js → assets/js}/nav-menu.js RENAMED
File without changes
assets/js/widget-permissions.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function wpfront_ure_widget_permissions_update_widget_title(id) {
2
+ var $ = jQuery;
3
+
4
+ var $span = $('#' + id);
5
+ $span.removeAttr('id').removeClass('hidden');
6
+
7
+ var $h3 = $span.closest('div.widget-inside').prev().find('h3');
8
+ $h3.find('span.in-title-access-type').remove();
9
+
10
+ $h3.append($span);
11
+ }
12
+
13
+ (function ($) {
14
+ var ROLES_USERS = 4;
15
+
16
+ $(function () {
17
+ var $widgets_holder = $('.widget-liquid-right');
18
+
19
+ $widgets_holder.on('change', 'input.user-restriction-type', function () {
20
+ var $this = $(this);
21
+ if ($this.val() == ROLES_USERS) {
22
+ $this.closest('span.user-restriction-container').find('span.roles-container').removeClass('hidden');
23
+ } else {
24
+ $this.closest('span.user-restriction-container').find('span.roles-container').addClass('hidden');
25
+ }
26
+ });
27
+ });
28
+ })(jQuery);
29
+
classes/base/class-wpfront-base-menu.php DELETED
@@ -1,260 +0,0 @@
1
- <?php
2
- /*
3
- WPFront Plugins Base Menu
4
- Copyright (C) 2013, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront Plugins are distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- if (!class_exists('WPFront_Base_Menu')) {
29
-
30
- class WPFront_Base_Menu {
31
-
32
- const MENU_SLUG = 'wpfront-plugins';
33
-
34
- private static $wpfrontBase = NULL;
35
- private static $wpfrontBaseMenu = NULL;
36
-
37
- function __construct($wpfrontBase) {
38
- if (self::$wpfrontBase == NULL) {
39
- self::$wpfrontBase = $wpfrontBase;
40
- self::$wpfrontBaseMenu = $this;
41
- } else {
42
- if (version_compare($this->version(), self::$wpfrontBaseMenu->version()) > 0) {
43
- self::$wpfrontBase = $wpfrontBase;
44
- self::$wpfrontBaseMenu = $this;
45
- }
46
- }
47
- }
48
-
49
- protected function version() {
50
- return '1.0';
51
- }
52
-
53
- protected function print_column_headers($tag = 'thead') {
54
- echo '<' . $tag . '><tr>'
55
- . '<th class="check-column"></th>'
56
- . '<th scope="col" id="name" class="manage-column column-name">' . $this->__('Name') . '</th>'
57
- . '<th scope="col" id="version" class="manage-column column-version">' . $this->__('Version') . '</th>'
58
- . '<th scope="col" id="rating" class="manage-column column-rating">' . $this->__('Rating') . '</th>'
59
- . '<th scope="col" id="description" class="manage-column column-description">' . $this->__('Description') . '</th>'
60
- . '</tr></' . $tag . '>';
61
- }
62
-
63
- protected function print_column_footers() {
64
- $this->print_column_headers('tfoot');
65
- }
66
-
67
- protected function wp_star_rating($args) {
68
- if (function_exists('wp_star_rating')) {
69
- echo wp_star_rating($args);
70
- return;
71
- }
72
-
73
- echo '<div class="star-holder" title="' . sprintf($this->__('based on %s rating(s)'), number_format_i18n($args['number'])) . '">'
74
- . '<div class="star star-rating" style="width:' . esc_attr(str_replace(',', '.', $args['rating'])) . 'px"></div>'
75
- . '</div>';
76
- }
77
-
78
- protected function create_plugin_list() {
79
- if (isset($_GET['action'])) {
80
- if ($_GET['action'] == 'activate') {
81
- if (isset($_GET['plugin'])) {
82
- activate_plugin($_GET['plugin'] . '/' . $_GET['plugin'] . '.php');
83
- // echo '<script type="text/javascript">window.location="' . WPFront_Static_URE::self_admin_url('admin.php?page=' . self::MENU_SLUG) . '";</script>';
84
- // wp_die();
85
- // return;
86
- }
87
- }
88
- }
89
-
90
- $plugins_allowedtags = array(
91
- 'a' => array('href' => array(), 'title' => array(), 'target' => array()),
92
- 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
93
- 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
94
- 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array()
95
- );
96
-
97
- if (!function_exists('plugins_api'))
98
- require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
99
- add_thickbox();
100
-
101
- $args = array();
102
- $args['page'] = 1;
103
- $args['per_page'] = 30;
104
- $args['author'] = 'syammohanm';
105
-
106
- $api = plugins_api('query_plugins', $args);
107
-
108
- if (is_wp_error($api)) {
109
- wp_die($this->__('Unable to communicate with WordPress.org'));
110
- return;
111
- }
112
- ?>
113
- <style type="text/css">
114
- div.wpfront-container table.plugins {
115
- margin-top: 16px;
116
- margin-bottom: 16px;
117
- }
118
- div.wpfront-container table.plugins th.check-column {
119
- width: 0px;
120
- }
121
- div.wpfront-container div.footer {
122
- text-align: center;
123
- }
124
- </style>
125
- <?php
126
- echo '<div class="wrap wpfront-container">';
127
- echo '<h2>' . $this->__('WPFront Plugins') . '</h2>';
128
- echo '<table class="wp-list-table widefat plugins plugin-install">';
129
- $this->print_column_headers();
130
-
131
- foreach ((array) $api->plugins as $plugin) {
132
- if (is_object($plugin))
133
- $plugin = (array) $plugin;
134
-
135
- $title = wp_kses($plugin['name'], $plugins_allowedtags);
136
- $description = strip_tags($plugin['description']);
137
- if (strlen($description) > 400)
138
- $description = mb_substr($description, 0, 400) . '&#8230;';
139
- //remove any trailing entities
140
- $description = preg_replace('/&[^;\s]{0,6}$/', '', $description);
141
- //strip leading/trailing & multiple consecutive lines
142
- $description = trim($description);
143
- $description = preg_replace("|(\r?\n)+|", "\n", $description);
144
- //\n => <br>
145
- $description = nl2br($description);
146
- $version = wp_kses($plugin['version'], $plugins_allowedtags);
147
-
148
- $name = strip_tags($title . ' ' . $version);
149
- $author = $plugin['author'];
150
- if (!empty($plugin['author']))
151
- $author = ' <cite>' . sprintf($this->__('By %s'), $author) . '.</cite>';
152
-
153
- $author = wp_kses($author, $plugins_allowedtags);
154
-
155
- $action_links = array();
156
- $action_links[] = '<a href="' . WPFront_Static_URE::self_admin_url('plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
157
- '&amp;TB_iframe=true&amp;width=600&amp;height=550') . '" class="thickbox" title="' .
158
- esc_attr(sprintf($this->__('More information about %s'), $name)) . '">' . $this->__('Details') . '</a>';
159
-
160
- $class = 'inactive';
161
- if (current_user_can('install_plugins') || current_user_can('update_plugins')) {
162
- $status = install_plugin_install_status($plugin);
163
-
164
- switch ($status['status']) {
165
- case 'install':
166
- if ($status['url'])
167
- $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr(sprintf($this->__('Install %s'), $name)) . '">' . $this->__('Install Now') . '</a>';
168
- $class = 'active';
169
- break;
170
- case 'update_available':
171
- if ($status['url'])
172
- $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr(sprintf($this->__('Update to version %s'), $status['version'])) . '">' . sprintf($this->__('Update Now'), $status['version']) . '</a>';
173
- $class = 'active update';
174
- break;
175
- case 'latest_installed':
176
- case 'newer_installed':
177
- $action_links[] = '<span title="' . esc_attr__($this->__('This plugin is already installed and is up to date')) . ' ">' . $this->__('Installed') . '</span>';
178
- if (is_plugin_active($plugin['slug'] . '/' . $plugin['slug'] . '.php'))
179
- $action_links[] = '<a href="' . WPFront_Static_URE::self_admin_url('admin.php?page=' . $plugin['slug']) . '">' . $this->__('Settings') . '</a>';
180
- else
181
- $action_links[] = '<a href="' . WPFront_Static_URE::self_admin_url('admin.php?page=' . self::MENU_SLUG . '&action=activate&plugin=' . $plugin['slug']) . '">' . $this->__('Activate') . '</a>';
182
- break;
183
- }
184
- }
185
- $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
186
- ?>
187
- <tr class="<?php echo $class; ?>">
188
- <th class="check-column"></th>
189
- <td class="name column-name"><strong><?php echo $title; ?></strong>
190
- <div class="action-links"><?php if (!empty($action_links)) echo implode(' | ', $action_links); ?></div>
191
- </td>
192
- <td class="vers column-version"><?php echo $version; ?></td>
193
- <td class="vers column-rating">
194
- <?php $this->wp_star_rating(array('rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'])); ?>
195
- </td>
196
- <td class="desc column-description"><?php echo $description, $author; ?></td>
197
- </tr>
198
- <?php
199
- }
200
-
201
- $this->print_column_footers();
202
- echo '</table>';
203
- echo '<div class="footer"><a href="http://wpfront.com/contact" target="_blank">' . $this->__('Feedback') . '</a> | <a href="http://wpfront.com" target="_blank">wpfront.com</a></div>';
204
- echo '</div>';
205
- }
206
-
207
- public static function plugin_list() {
208
- self::$wpfrontBaseMenu->create_plugin_list();
209
- }
210
-
211
- protected function __($key) {
212
- return self::$wpfrontBase->__($key);
213
- }
214
-
215
- protected function create_admin_menu($menu_data) {
216
- $menu_slug = self::MENU_SLUG;
217
-
218
- global $admin_page_hooks, $submenu;
219
- if (!isset($admin_page_hooks[$menu_slug])) {
220
- add_menu_page($this->__('WPFront'), $this->__('WPFront'), 'manage_options', $menu_slug, null, self::$wpfrontBase->pluginURL() . 'classes/base/images/wpfront_menu.png');
221
- add_submenu_page($menu_slug, $this->__('WPFront Plugins'), $this->__('All Plugins'), 'manage_options', $menu_slug, array('WPFront_Base_Menu', 'plugin_list'));
222
- }
223
-
224
- if (empty($submenu[$menu_slug])) {
225
- return;
226
- }
227
-
228
- //$extra_menu = array_pop($submenu[$menu_slug]);
229
-
230
- foreach ($menu_data as $value) {
231
- $flag = FALSE;
232
-
233
- foreach ($submenu[$menu_slug] as $s) {
234
- if ($s[2] == $value['slug']) {
235
- $flag = TRUE;
236
- break;
237
- }
238
- }
239
-
240
- if ($flag == TRUE)
241
- continue;
242
-
243
- $page_hook_suffix = add_submenu_page($menu_slug, $value['title'], $value['link'], 'manage_options', $value['slug'], array($value['this'], 'options_page'));
244
-
245
- add_action('admin_print_scripts-' . $page_hook_suffix, array($value['this'], 'enqueue_options_scripts'));
246
- add_action('admin_print_styles-' . $page_hook_suffix, array($value['this'], 'enqueue_options_styles'));
247
- }
248
-
249
- //usort($submenu[$menu_slug], array('WPFront_Base', 'submenu_compare'));
250
- //$submenu[$menu_slug][] = $extra_menu;
251
- }
252
-
253
- public static function admin_menu($menu_data) {
254
- self::$wpfrontBaseMenu->create_admin_menu($menu_data);
255
- }
256
-
257
- }
258
-
259
- }
260
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/base/class-wpfront-base.php DELETED
@@ -1,245 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront Plugins Base
5
- Copyright (C) 2013, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront Plugins are distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-static.php");
30
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-base-menu.php");
31
-
32
- if (!class_exists('WPFront_Base_URE')) {
33
-
34
- /**
35
- * Plugin framework base class
36
- *
37
- * @author Syam Mohan <syam@wpfront.com>
38
- * @copyright 2013 WPFront.com
39
- */
40
- class WPFront_Base_URE {
41
-
42
- const ADMINISTRATOR_ROLE_KEY = 'administrator';
43
- const EDITOR_ROLE_KEY = 'editor';
44
- const AUTHOR_ROLE_KEY = 'author';
45
- const CONTRIBUTOR_ROLE_KEY = 'contributor';
46
- const SUBSCRIBER_ROLE_KEY = 'subscriber';
47
-
48
- private $plugin_slug;
49
- private $options_page_slug;
50
- protected $pluginURLRoot;
51
- protected $pluginDIRRoot;
52
- private static $menu_data = array();
53
-
54
- function __construct($file, $pluginSlug, $wpfrontBaseMenu = NULL) {
55
- $this->plugin_slug = $pluginSlug;
56
- $this->options_page_slug = $this->plugin_slug;
57
- if ($wpfrontBaseMenu == NULL)
58
- $wpfrontBaseMenu = new WPFront_Base_Menu($this);
59
-
60
- $this->pluginDIRRoot = dirname($file) . '/../';
61
- $this->pluginURLRoot = plugins_url() . '/' . $this->plugin_slug . $this->plugin_dir_suffix() . '/';
62
-
63
- add_action('init', array(&$this, 'init'));
64
- add_action('plugins_loaded', array(&$this, 'plugins_loaded_base'));
65
-
66
- //register actions
67
- if (is_admin()) {
68
- add_action('admin_init', array(&$this, 'admin_init'));
69
- add_action('admin_menu', array(&$this, 'admin_menu'));
70
- add_filter('plugin_action_links', array(&$this, 'action_links'), 10, 2);
71
- add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_styles'));
72
- add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
73
- } else {
74
- add_action('wp_enqueue_scripts', array(&$this, 'enqueue_styles'));
75
- add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
76
- }
77
- add_action('wp_before_admin_bar_render', array($this, 'admin_bar'));
78
- }
79
-
80
- protected function plugin_dir_suffix() {
81
- return '';
82
- }
83
-
84
- protected function add_menu($title, $link) {
85
- self::$menu_data[] = array(
86
- 'title' => $title,
87
- 'link' => $link,
88
- 'this' => $this,
89
- 'slug' => $this->options_page_slug
90
- );
91
- }
92
-
93
- public function init() {
94
-
95
- }
96
-
97
- public function plugins_loaded_base() {
98
- //for localization
99
- load_plugin_textdomain($this->plugin_slug, FALSE, $this->plugin_slug . $this->plugin_dir_suffix() . '/languages/');
100
-
101
- $this->plugins_loaded();
102
- }
103
-
104
- public function plugins_loaded() {
105
-
106
- }
107
-
108
- public function admin_init() {
109
-
110
- }
111
-
112
- public function admin_menu() {
113
- WPFront_Base_Menu::admin_menu(self::$menu_data);
114
- }
115
-
116
- public function admin_bar() {
117
-
118
- }
119
-
120
- public static function submenu_compare($a, $b) {
121
- return strcmp($a[0], $b[0]);
122
- }
123
-
124
- public function action_links($links, $file) {
125
- if ($file == $this->plugin_action_links_file()) {
126
- $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=' . $this->options_page_slug . '">' . $this->__('Settings') . '</a>';
127
- array_unshift($links, $settings_link);
128
- }
129
- return $links;
130
- }
131
-
132
- protected function plugin_action_links_file() {
133
- return $this->plugin_slug . $this->plugin_dir_suffix() . '/' . $this->plugin_slug . '.php';
134
- }
135
-
136
- public function enqueue_styles() {
137
-
138
- }
139
-
140
- public function enqueue_scripts() {
141
-
142
- }
143
-
144
- public function admin_enqueue_styles() {
145
-
146
- }
147
-
148
- public function admin_enqueue_scripts() {
149
-
150
- }
151
-
152
- public function enqueue_options_styles() {
153
-
154
- }
155
-
156
- public function enqueue_options_scripts() {
157
-
158
- }
159
-
160
- //creates options page
161
- public function options_page() {
162
- if (!current_user_can('manage_options')) {
163
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
164
- return;
165
- }
166
-
167
- include($this->pluginDIRRoot . 'templates/options-template.php');
168
- }
169
-
170
- protected function options_page_header($title, $optionsGroupName) {
171
- echo '<div class="wrap">';
172
- //@screen_icon($this->options_page_slug);
173
- echo '<h2>' . $title . '</h2>';
174
- echo '<div id="' . $this->options_page_slug . '-options" class="inside">';
175
- echo '<form method="post" action="options.php">';
176
- //@settings_fields($optionsGroupName);
177
- @do_settings_sections($this->options_page_slug);
178
-
179
- if ((isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') || (isset($_GET['updated']) && $_GET['updated'] == 'true')) {
180
- echo '
181
- <div class="updated">
182
- <p>
183
- <strong>' . $this->__('If you have a caching plugin, clear the cache for the new settings to take effect.') . '</strong>
184
- </p>
185
- </div>
186
- ';
187
- }
188
- }
189
-
190
- protected function options_page_footer($settingsLink, $FAQLink, $extraLinks = NULL) {
191
- @$this->submit_button();
192
-
193
- // if ($extraLinks != NULL) {
194
- // foreach ($extraLinks as $value) {
195
- // echo '<a href="' . $value['href'] . '" target="' . $value['target'] . '">' . $value['text'] . '</a>';
196
- // echo ' | ';
197
- // }
198
- // }
199
- //
200
- // echo '
201
- // <a href="http://wpfront.com/' . $settingsLink . '" target="_blank">' . $this->__('Settings Description') . '</a>
202
- // |
203
- // <a href="http://wpfront.com/' . $FAQLink . '" target="_blank">' . $this->__('Plugin FAQ') . '</a>
204
- // |
205
- // <a href="http://wpfront.com/contact/" target="_blank">' . $this->__('Feature Request') . '</a>
206
- // |
207
- // <a href="http://wpfront.com/contact/" target="_blank">' . $this->__('Report Bug') . '</a>
208
- // |
209
- // <a href="http://wordpress.org/support/view/plugin-reviews/' . $this->plugin_slug . '" target="_blank">' . $this->__('Write Review') . '</a>
210
- // |
211
- // <a href="http://wpfront.com/contact/" target="_blank">' . $this->__('Contact Me') . '</a>
212
- // |
213
- // <a href="http://wpfront.com/donate/" target="_blank">' . $this->__('Buy me a Beer or Coffee') . '</a>
214
- // ';
215
- echo '</form>';
216
- echo '</div>';
217
- echo '</div>';
218
- }
219
-
220
- //returns localized string
221
- public function __($key) {
222
- return __($key, $this->plugin_slug);
223
- }
224
-
225
- //for compatibility
226
- public function submit_button() {
227
- if (function_exists('submit_button')) {
228
- submit_button();
229
- } else {
230
- echo '<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="' . $this->__('Save Changes') . '" /></p>';
231
- }
232
- }
233
-
234
- public function pluginURL() {
235
- return $this->pluginURLRoot;
236
- }
237
-
238
- public function pluginDIR() {
239
- return $this->pluginDIRRoot;
240
- }
241
-
242
- }
243
-
244
- }
245
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/base/class-wpfront-entity-base.php DELETED
@@ -1,402 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront Plugins Entity Base
5
- Copyright (C) 2013, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront Plugins are distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-static.php");
30
-
31
- if (!class_exists('WPFront_Entity_Base')) {
32
-
33
- /**
34
- * Plugin entity framework base class
35
- *
36
- * @author Syam Mohan <syam@wpfront.com>
37
- * @copyright 2013 WPFront.com
38
- */
39
- abstract class WPFront_Entity_Base {
40
-
41
- private static $DB_STATUS = array();
42
- protected static $UNINSTALL = FALSE;
43
- private $slug;
44
- private $version;
45
- private $options;
46
- private $tablename;
47
- private $func_data = array();
48
- protected $db_data;
49
-
50
- public function __construct($slug, $version, $options, $tablename) {
51
- $this->slug = $slug;
52
- $this->version = $version;
53
- $this->options = $options;
54
- $this->tablename = $tablename;
55
-
56
- if (!self::$UNINSTALL) {
57
- $this->prepare_db_data();
58
- $this->db_delta();
59
- }
60
- }
61
-
62
- private function sql_type($type) {
63
- switch ($type) {
64
- case 'bit':
65
- return 'tinyint(1)';
66
- default:
67
- return $type;
68
- }
69
- }
70
-
71
- private function prepare_db_data() {
72
- $obj = (OBJECT) array(
73
- 'key' => 'id',
74
- 'type' => 'bigint(20)',
75
- 'sql' => 'id bigint(20) NOT NULL AUTO_INCREMENT',
76
- 'data' => 0
77
- );
78
- $this->db_data = array(
79
- 'id' => $obj
80
- );
81
- $this->func_data["get_id"] = (OBJECT) array(
82
- 'type' => 'get',
83
- 'data' => $obj
84
- );
85
- $this->func_data["get_by_id"] = (OBJECT) array(
86
- 'data' => $obj
87
- );
88
-
89
- foreach ($this->_db_data() as $value) {
90
- $key = $value->name;
91
- $obj = (OBJECT) array(
92
- 'key' => $key,
93
- 'type' => strtolower($value->type),
94
- 'default' => (isset($value->default) ? $value->default : NULL)
95
- );
96
- $obj->sql = "$key {$this->sql_type($obj->type)} " . ($obj->default === NULL ? "DEFAULT NULL" : "DEFAULT $obj->default NOT NULL");
97
- $obj->data = $obj->default;
98
- $this->db_data[$key] = $obj;
99
-
100
- $this->func_data["get_$key"] = (OBJECT) array(
101
- 'data' => $obj
102
- );
103
- $this->func_data["set_$key"] = (OBJECT) array(
104
- 'data' => $obj
105
- );
106
-
107
- $this->func_data["get_by_$key"] = (OBJECT) array(
108
- 'data' => $obj
109
- );
110
- $this->func_data["get_all_by_$key"] = (OBJECT) array(
111
- 'data' => $obj
112
- );
113
- $this->func_data["delete_by_$key"] = (OBJECT) array(
114
- 'data' => $obj
115
- );
116
- }
117
- }
118
-
119
- public function table_name() {
120
- global $wpdb;
121
-
122
- return $wpdb->prefix . 'wpfront_' . $this->tablename;
123
- }
124
-
125
- private function db_delta() {
126
- $table_name = $this->table_name();
127
- if (isset(self::$DB_STATUS[$table_name]))
128
- return;
129
-
130
- self::$DB_STATUS[$table_name] = TRUE;
131
-
132
- $option_key = $this->get_db_version_option_name();
133
- $db_version = get_option($option_key);
134
- if ($db_version === FALSE)
135
- $db_version = '0.0';
136
-
137
- $table_key = $table_name . '-db-version';
138
-
139
- if (version_compare($db_version, $this->version, '>=')) {
140
- $db_version = $this->options->get_option($table_key);
141
- if ($db_version === NULL)
142
- $db_version = '0.0';
143
-
144
- if (version_compare($db_version, $this->version, '>='))
145
- return;
146
- }
147
-
148
- global $wpdb;
149
-
150
- $sql = "CREATE TABLE $table_name (";
151
-
152
- foreach ($this->db_data as $key => $value) {
153
- $sql .= "$value->sql, \n";
154
- }
155
-
156
- $sql .= "UNIQUE KEY id (id)\n);";
157
-
158
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
159
-
160
- dbDelta($sql);
161
-
162
- update_option($option_key, $this->version);
163
- $this->options->update_option($table_key, $this->version);
164
- }
165
-
166
- abstract protected function _db_data();
167
-
168
- protected function db_data_field($name, $type) {
169
- return (OBJECT) array(
170
- 'name' => $name,
171
- 'type' => $type
172
- );
173
- }
174
-
175
- public function __call($name, array $args) {
176
- if (!array_key_exists($name, $this->func_data)) {
177
- throw new Exception("$name function not found");
178
- }
179
-
180
- return call_user_func_array(array($this, preg_replace('/_' . $this->func_data[$name]->data->key . '$/', '', $name)), array($this->func_data[$name]->data, $args));
181
- }
182
-
183
- private function format($data) {
184
- $format = array(
185
- 'int' => '%d',
186
- 'bigint' => '%d',
187
- 'varchar' => '%s',
188
- 'longtext' => '%s',
189
- 'tinytext' => '%s',
190
- 'datetime' => '%s',
191
- 'bit' => '%d'
192
- );
193
-
194
- foreach ($format as $key => $value) {
195
- if (strpos($data->type, $key) === 0) {
196
- return $value;
197
- }
198
- }
199
-
200
- throw new Exception("$data->type format not specified");
201
- }
202
-
203
- private function convert($data) {
204
- switch ($data->type) {
205
- case 'bit':
206
- return (BOOL) $data->data;
207
- case 'int':
208
- case 'bigint':
209
- return intval($data->data);
210
- default:
211
- return strval($data->data);
212
- }
213
- }
214
-
215
- private function get($data) {
216
- return $this->convert($data);
217
- }
218
-
219
- private function set($data, $args) {
220
- $data->data = $args[0];
221
- }
222
-
223
- protected function get_object($result) {
224
- $class = get_class($this);
225
- $class = new $class();
226
-
227
- foreach ($class->db_data as $key => $value) {
228
- $value->data = $result[$key];
229
- }
230
-
231
- return $class;
232
- }
233
-
234
- private function get_by($data, $args) {
235
- global $wpdb;
236
-
237
- $table_name = $this->table_name();
238
-
239
- $result = $wpdb->get_row(
240
- $wpdb->prepare(
241
- "SELECT * FROM $table_name "
242
- . "WHERE $data->key = " . $this->format($data), $args[0]
243
- ), ARRAY_A
244
- );
245
-
246
- if ($result === NULL)
247
- return NULL;
248
-
249
- return $this->get_object($result);
250
- }
251
-
252
- private function get_all_by($data, $args) {
253
- global $wpdb;
254
-
255
- $table_name = $this->table_name();
256
-
257
- $result = $wpdb->get_results(
258
- $wpdb->prepare(
259
- "SELECT * FROM $table_name "
260
- . "WHERE $data->key = " . $this->format($data), $args[0]
261
- ), ARRAY_A
262
- );
263
-
264
- $data = array();
265
- $class = get_class($this);
266
-
267
- foreach ($result as $row) {
268
- $data[] = $this->get_object($row);
269
- }
270
-
271
- return $data;
272
- }
273
-
274
- protected function get_all($orderby = array(), $page_index = -1, $per_page = -1, $search = '') {
275
- global $wpdb;
276
-
277
- $table_name = $this->table_name();
278
-
279
- $sql = "SELECT * FROM $table_name";
280
-
281
- if(!empty($search)) {
282
- $sql .= " WHERE $search";
283
- }
284
-
285
- if (!empty($orderby)) {
286
- $sql .= ' ORDER BY ';
287
- foreach ($orderby as $key => $value) {
288
- $sql .= $key;
289
- if ($value)
290
- $sql .= ' DESC';
291
- $sql .= ', ';
292
- }
293
- }
294
- $sql = trim($sql, ", ");
295
-
296
- if($page_index > -1) {
297
- $start = $page_index * $per_page;
298
-
299
- $sql .= " LIMIT $start, $per_page";
300
- }
301
-
302
- $result = $wpdb->get_results($sql, ARRAY_A);
303
-
304
- $data = array();
305
- $class = get_class($this);
306
-
307
- foreach ($result as $row) {
308
- $data[] = $this->get_object($row);
309
- }
310
-
311
- return $data;
312
- }
313
-
314
- protected function count($where = '') {
315
- global $wpdb;
316
-
317
- $table_name = $this->table_name();
318
-
319
- $sql = "SELECT COUNT(*) FROM $table_name";
320
-
321
- if(!empty($where)) {
322
- $sql .= " WHERE $where";
323
- }
324
-
325
- $result = $wpdb->get_var($sql);
326
-
327
- return intval($result);
328
- }
329
-
330
- public function add() {
331
- $values = array();
332
- $format = array();
333
-
334
- foreach ($this->db_data as $key => $value) {
335
- if ($key === 'id')
336
- continue;
337
- $values[$key] = $value->data;
338
- $format[] = $this->format($value);
339
- }
340
-
341
- global $wpdb;
342
-
343
- $wpdb->insert($this->table_name(), $values, $format);
344
- $this->db_data['id']->data = $wpdb->insert_id;
345
-
346
- return $wpdb->insert_id;
347
- }
348
-
349
- public function update() {
350
- $values = array();
351
- $format = array();
352
-
353
- foreach ($this->db_data as $key => $value) {
354
- if ($key === 'id')
355
- continue;
356
- $values[$key] = $value->data;
357
- $format[] = $this->format($value);
358
- }
359
-
360
- global $wpdb;
361
-
362
- $wpdb->update($this->table_name(), $values, array('id' => $this->db_data['id']->data), $format, array('%d'));
363
- return $this->db_data['id']->data;
364
- }
365
-
366
- public function save() {
367
- if ($this->db_data['id']->data === 0)
368
- return $this->add();
369
- else
370
- return $this->update();
371
- }
372
-
373
- public function delete() {
374
- if ($this->db_data['id']->data === 0)
375
- return;
376
-
377
- global $wpdb;
378
- $wpdb->delete($this->table_name(), array('id' => $this->db_data['id']->data), array('%d'));
379
- }
380
-
381
- public function delete_by($data) {
382
- global $wpdb;
383
- $wpdb->delete($this->table_name(), array($data->key => $data->data), $this->format($data));
384
- }
385
-
386
- private function get_db_version_option_name() {
387
- return $this->slug . '-db-version';
388
- }
389
-
390
- protected function uninstall_action() {
391
- delete_option($this->get_db_version_option_name());
392
-
393
- global $wpdb;
394
- $table_name = $this->table_name();
395
-
396
- $sql = "DROP TABLE IF EXISTS $table_name;";
397
- $wpdb->query($sql);
398
- }
399
-
400
- }
401
-
402
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/base/class-wpfront-options-base.php DELETED
@@ -1,159 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront Plugins Options Base
5
- Copyright (C) 2013, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront Plugins are distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_Options_Base')) {
30
-
31
- /**
32
- * Options framework base class
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2013 WPFront.com
36
- */
37
- class WPFront_Options_Base {
38
-
39
- //variables to hold options data
40
- public $__data = array();
41
- public $__optionName;
42
- public $__localizeSlug;
43
- public $__options;
44
- private $lastOptionName;
45
- private $optionNames;
46
-
47
- function __construct($optionName, $localizeSlug) {
48
- $this->__optionName = $optionName;
49
- $this->__localizeSlug = $localizeSlug;
50
-
51
- $this->__options = get_option($this->__optionName);
52
-
53
- if (!is_array($this->__options)) {
54
- $this->__options = array();
55
- }
56
-
57
- $this->optionNames = array();
58
- }
59
-
60
- //defines option with data
61
- protected function addOption($name, $type, $default, $validate = NULL) {
62
- if (isset($this->__data[$name])) {
63
- echo 'Duplicate option ' . $name;
64
- return $this;
65
- }
66
- $this->__data[$name]['name'] = $name;
67
- $this->__data[$name]['type'] = $type;
68
- $this->__data[$name]['default'] = $default;
69
- $this->__data[$name]['validate'] = isset($validate) ? $validate : array(&$this, 'validate_default');
70
-
71
- //dynamic function returning option value
72
- $this->__data[$name]['func'] = create_function('$self, $data', '
73
- $value = NULL;
74
- if(array_key_exists($data["name"], $self->__options))
75
- $value = $self->__options[$data["name"]];
76
- return $self->get_value($data["type"], $value, $data["default"], $data["validate"]);
77
- ');
78
-
79
- $this->__data[$name . '_name'] = $this->__data[$name];
80
- //dynamic function returning option name for settings page
81
- $this->__data[$name . '_name']['func'] = create_function('$self, $data', '
82
- return $self->__optionName . "[" . $data["name"] . "]";
83
- ');
84
-
85
- $this->__data[$name . '_label'] = $this->__data[$name];
86
-
87
- //dynamic function returning option label for settings page
88
- $this->__data[$name . '_label']['func'] = create_function('$self, $data', '
89
- return __($data["label"], $self->__localizeSlug);
90
- ');
91
-
92
- $this->lastOptionName = $name;
93
- array_push($this->optionNames, $name);
94
-
95
- return $this;
96
- }
97
-
98
- //default validation function
99
- private function validate_default($arg) {
100
- return $arg;
101
- }
102
-
103
- //validates a zero or positive number
104
- protected function validate_zero_positive($arg) {
105
- if ($arg < 0) {
106
- return 0;
107
- }
108
-
109
- return $arg;
110
- }
111
-
112
- //sets the label of the option, for POEDIT compatibility
113
- protected function __($label) {
114
- $this->__data[$this->lastOptionName . '_label']['label'] = $label;
115
- }
116
-
117
- //returns the value of option
118
- public function get_value($type, $value, $default, $validate) {
119
- if (!isset($value)) {
120
- return $default;
121
- }
122
-
123
- switch ($type) {
124
- case 'bool':
125
- return (bool) $value;
126
- case 'int':
127
- return call_user_func($validate, intval($value));
128
- case 'float':
129
- return call_user_func($validate, floatval($value));
130
- case 'string':
131
- return call_user_func($validate, strval($value));
132
- }
133
- return $value;
134
- }
135
-
136
- //returns optons array
137
- public function get_options() {
138
- $options = array();
139
- foreach ($this->optionNames as $val) {
140
- $options[$val] = $this->$val();
141
- }
142
- return $options;
143
- }
144
-
145
- //PHP magic function to call dynamic methods
146
- public function __call($name, array $args) {
147
- if (!array_key_exists($name, $this->__data)) {
148
- echo '"' . $name . '" option not yet added';
149
- return;
150
- }
151
-
152
- array_unshift($args, $this->__data[$name]);
153
- array_unshift($args, $this);
154
- return call_user_func_array($this->__data[$name]['func'], $args);
155
- }
156
-
157
- }
158
-
159
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/base/class-wpfront-static.php DELETED
@@ -1,78 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront Plugins Static Helpers
5
- Copyright (C) 2013, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront Plugins are distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_Static_URE')) {
30
-
31
- /**
32
- * Plugin framework static helpers
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2013 WPFront.com
36
- */
37
- class WPFront_Static_URE {
38
-
39
- public static function is_admin_bar_showing() {
40
- if (function_exists('is_admin_bar_showing')) {
41
- return is_admin_bar_showing();
42
- }
43
-
44
- return FALSE;
45
- }
46
-
47
- public static function self_admin_url($path = '', $scheme = 'admin') {
48
- if (function_exists('self_admin_url'))
49
- return self_admin_url($path, $scheme);
50
-
51
- return admin_url($path, $scheme);
52
- }
53
-
54
- public static function doing_ajax() {
55
- if (defined('DOING_AJAX') && DOING_AJAX) {
56
- return TRUE;
57
- }
58
-
59
- if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
60
- return TRUE;
61
- }
62
-
63
- if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
64
- return TRUE;
65
- }
66
-
67
- return FALSE;
68
- }
69
-
70
- public static function WP_Version($version) {
71
- global $wp_version;
72
-
73
- return version_compare($wp_version, $version, '>=');
74
- }
75
-
76
- }
77
-
78
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/base/images/wpfront_menu.png DELETED
Binary file
classes/class-wpfront-user-role-editor-add-edit.php DELETED
@@ -1,425 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- if (!class_exists('WPFront_User_Role_Editor_Add_Edit')) {
29
-
30
- /**
31
- * Add or Edit Role
32
- *
33
- * @author Syam Mohan <syam@wpfront.com>
34
- * @copyright 2014 WPFront.com
35
- */
36
- class WPFront_User_Role_Editor_Add_Edit extends WPFront_User_Role_Editor_Controller_Base {
37
-
38
- const MENU_SLUG = 'wpfront-user-role-editor-add-new';
39
-
40
- protected static $copy_capabilities_action = NULL;
41
- protected $role = null;
42
- protected $is_editable = FALSE;
43
- protected $role_exists = FALSE;
44
- protected $error = FALSE;
45
-
46
- function __construct($main) {
47
- parent::__construct($main);
48
-
49
- $this->ajax_register('wp_ajax_wpfront_user_role_editor_copy_capabilities', array($this, 'copy_capabilities_callback'));
50
- }
51
-
52
- public function add_edit_role($role_name) {
53
- global $wp_roles;
54
- $roles = $wp_roles->role_names;
55
-
56
- if (array_key_exists($role_name, $roles)) {
57
- $this->role = get_role($role_name);
58
- }
59
-
60
- if ($this->role === NULL) {
61
- if (!$this->can_create()) {
62
- $this->main->permission_denied();
63
- return;
64
- }
65
- } else {
66
- if (!$this->can_edit()) {
67
- $this->main->permission_denied();
68
- return;
69
- }
70
- }
71
-
72
- if ($this->role == NULL) {
73
- $this->is_editable = TRUE;
74
- } else if ($role_name != self::ADMINISTRATOR_ROLE_KEY) {
75
- $editable_roles = get_editable_roles();
76
- if ($this->main->override_edit_permissions())
77
- $editable_roles = $wp_roles->get_names();
78
- $this->is_editable = array_key_exists($role_name, $editable_roles);
79
- }
80
-
81
- $success = FALSE;
82
- if (!empty($_POST['createrole'])) {
83
- while (TRUE) {
84
- $this->main->verify_nonce();
85
-
86
- if (!$this->is_editable)
87
- break;
88
-
89
- if (!$this->is_display_name_valid())
90
- break;
91
- if ($this->role == NULL && !$this->is_role_name_valid())
92
- break;
93
-
94
- $capabilities = array();
95
- if (!empty($_POST['capabilities'])) {
96
- foreach ($_POST['capabilities'] as $key => $value) {
97
- $capabilities[$key] = TRUE;
98
- }
99
- }
100
-
101
- if ($this->role == NULL) {
102
- $role_name = $this->get_role_name();
103
- if (array_key_exists($role_name, $roles)) {
104
- $this->role_exists = TRUE;
105
- break;
106
- }
107
- $error = add_role($role_name, $this->get_display_name(), $capabilities);
108
- if ($error == NULL) {
109
- $this->error = TRUE;
110
- break;
111
- }
112
- } else {
113
- // global $wp_roles;
114
- // $wp_roles->roles[$this->role->name] = array(
115
- // 'name' => $this->get_display_name(),
116
- // 'capabilities' => $capabilities
117
- // );
118
- // update_option($wp_roles->role_key, $wp_roles->roles);
119
- // $wp_roles->role_objects[$this->role->name] = new WP_Role($this->role->name, $capabilities);
120
- // $wp_roles->role_names[$this->role->name] = $this->get_display_name();
121
-
122
- self::update_role($this->role->name, $this->get_display_name(), $capabilities);
123
- }
124
-
125
- $success = TRUE;
126
- break;
127
- }
128
- }
129
-
130
- if ($success) {
131
- printf('<script type="text/javascript">window.location.replace("%s");</script>', $this->list_url());
132
- } else {
133
- $this->include_template();
134
- }
135
- }
136
-
137
- protected function include_template() {
138
- include($this->main->pluginDIR() . 'templates/add-edit-role.php');
139
- }
140
-
141
- protected function is_display_name_valid() {
142
- if (empty($_POST['createrole']))
143
- return TRUE;
144
-
145
- if ($this->get_display_name() == '')
146
- return FALSE;
147
-
148
- return TRUE;
149
- }
150
-
151
- protected function is_display_name_disabled() {
152
- return !$this->is_editable;
153
- }
154
-
155
- protected function get_display_name() {
156
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
157
- if (empty($_POST['display_name']))
158
- return '';
159
-
160
- return esc_html(trim($_POST['display_name']));
161
- }
162
-
163
- if ($this->role == NULL)
164
- return '';
165
- global $wp_roles;
166
- return $wp_roles->role_names[$this->role->name];
167
- }
168
-
169
- protected function is_role_name_valid() {
170
- if (empty($_POST['createrole']))
171
- return TRUE;
172
-
173
- if ($this->get_role_name() == '')
174
- return FALSE;
175
-
176
- return TRUE;
177
- }
178
-
179
- protected function is_role_name_disabled() {
180
- if ($this->role != NULL)
181
- return TRUE;
182
- if (!$this->is_editable)
183
- return TRUE;
184
- return FALSE;
185
- }
186
-
187
- protected function get_role_name() {
188
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
189
- if (empty($_POST['role_name']))
190
- return '';
191
-
192
- return preg_replace('/\W/', '', preg_replace('/ /', '_', trim($_POST['role_name'])));
193
- }
194
-
195
- if ($this->role == NULL)
196
- return '';
197
- return $this->role->name;
198
- }
199
-
200
- protected function is_submit_disabled() {
201
- if (!$this->is_editable)
202
- return TRUE;
203
- return FALSE;
204
- }
205
-
206
- protected function exclude_custom_post_types() {
207
- return FALSE;
208
- }
209
-
210
- protected function get_capability_groups() {
211
- $caps_group = array();
212
-
213
- foreach ($this->main->get_capabilities($this->exclude_custom_post_types()) as $key => $value) {
214
- $deprecated = array_key_exists($key, WPFront_User_Role_Editor::$DEPRECATED_CAPABILITIES);
215
- $other = array_key_exists($key, WPFront_User_Role_Editor::$OTHER_CAPABILITIES);
216
-
217
- //network caps check
218
- $caps = array();
219
- foreach ($value as $cap) {
220
- if(strpos($cap, 'manage_network_') === 0) {
221
- continue;
222
- }
223
-
224
- $caps[] = $cap;
225
- }
226
-
227
- $caps_group[$key] = (OBJECT) array(
228
- 'caps' => $caps,
229
- 'display_name' => $this->__($key),
230
- 'deprecated' => $deprecated,
231
- 'disabled' => !$this->is_editable, //!$this->is_editable || $deprecated, - to enable levels; for author drop down
232
- 'hidden' => $deprecated && !$this->main->display_deprecated(),
233
- 'key' => str_replace(' ', '-', $key),
234
- 'has_help' => !$other
235
- );
236
- }
237
-
238
- foreach (WPFront_User_Role_Editor::$CUSTOM_POST_TYPES_DEFAULTED as $key => $value) {
239
- $caps_group[$key] = (OBJECT) array(
240
- 'caps' => 'defaulted',
241
- 'display_name' => $this->__($key),
242
- 'deprecated' => FALSE,
243
- 'disabled' => TRUE,
244
- 'hidden' => FALSE,
245
- 'key' => str_replace(' ', '-', $key),
246
- 'has_help' => FALSE
247
- );
248
- }
249
-
250
- return $caps_group;
251
- }
252
-
253
- protected function get_copy_from() {
254
- if (!$this->is_editable)
255
- return array();
256
-
257
- global $wp_roles;
258
- $roles = $wp_roles->role_names;
259
- asort($roles);
260
- return $roles;
261
- }
262
-
263
- protected function is_role_exists() {
264
- return $this->role_exists;
265
- }
266
-
267
- protected function is_error() {
268
- return $this->error;
269
- }
270
-
271
- public function copy_capabilities_callback() {
272
- if (self::$copy_capabilities_action !== NULL) {
273
- call_user_func(self::$copy_capabilities_action);
274
- die();
275
- }
276
-
277
- check_ajax_referer($_POST['referer'], 'nonce');
278
-
279
- if (empty($_POST['role'])) {
280
- echo '{}';
281
- die();
282
- return;
283
- }
284
-
285
- $role = get_role($_POST['role']);
286
- if ($role == NULL) {
287
- echo '{}';
288
- die();
289
- return;
290
- }
291
-
292
- echo json_encode($role->capabilities);
293
- die();
294
- }
295
-
296
- protected function capability_checked($cap) {
297
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
298
- if (empty($_POST['capabilities']))
299
- return FALSE;
300
-
301
- return array_key_exists($cap, $_POST['capabilities']);
302
- }
303
-
304
- if ($this->role != NULL) {
305
- if (array_key_exists($cap, $this->role->capabilities))
306
- return $this->role->capabilities[$cap];
307
- }
308
-
309
- return FALSE;
310
- }
311
-
312
- protected function get_help_url($cap) {
313
- if (isset(WPFront_User_Role_Editor::$DYNAMIC_CAPS[$cap]))
314
- return NULL;
315
-
316
- return 'http://wpfront.com/wordpress-capabilities/#' . $cap;
317
- }
318
-
319
- public static function update_role($name, $display_name, $capabilities) {
320
- global $wp_roles;
321
- $wp_roles->roles[$name] = array(
322
- 'name' => $display_name,
323
- 'capabilities' => $capabilities
324
- );
325
- update_option($wp_roles->role_key, $wp_roles->roles);
326
- $wp_roles->role_objects[$name] = new WP_Role($name, $capabilities);
327
- $wp_roles->role_names[$name] = $display_name;
328
- }
329
-
330
- protected function add_help_tab() {
331
- return array(
332
- array(
333
- 'id' => 'overview',
334
- 'title' => $this->__('Overview'),
335
- 'content' => '<p>'
336
- . $this->__('This screen allows you to add a new role within your site.')
337
- . '</p>'
338
- . '<p>'
339
- . $this->__('You can copy capabilities from existing roles using the Copy from drop down list. Select the role you want to copy from, then click Apply to copy the capabilities. You can select or deselect capabilities even after you copy.')
340
- . '</p>'
341
- ),
342
- array(
343
- 'id' => 'displayname',
344
- 'title' => $this->__('Display Name'),
345
- 'content' => '<p>'
346
- . $this->__('Use the Display Name field to set the display name for the new role. WordPress uses display name to display this role within your site. This field is required.')
347
- . '</p>'
348
- ),
349
- array(
350
- 'id' => 'rolename',
351
- 'title' => $this->__('Role Name'),
352
- 'content' => '<p>'
353
- . $this->__('Use the Role Name field to set the role name for the new role. WordPress uses role name to identify this role within your site. Once set role name cannot be changed. This field is required. This plugin will auto populate role name from the display name you have given, but you can change it.')
354
- . '</p>'
355
- ),
356
- array(
357
- 'id' => 'capabilities',
358
- 'title' => $this->__('Capabilities'),
359
- 'content' => '<p>'
360
- . $this->__('Capabilities are displayed as different groups for easy access. The Roles section displays capabilities created by this plugin. The Other Capabilities section displays non-standard capabilities within your site. These are usually created by plugins and themes. Use the check boxes to select the capabilities required for this new role.')
361
- . '</p>'
362
- )
363
- );
364
- }
365
-
366
- protected function set_help_sidebar() {
367
- return array(
368
- array(
369
- $this->__('Documentation on Add New Role'),
370
- 'add-role/'
371
- )
372
- );
373
- }
374
-
375
- protected function postbox_title($value) {
376
- return '<label class="' . ($value->deprecated ? 'deprecated' : 'active') . '"><input id="' . $value->key . '" type="checkbox" class="select-all" ' . ($value->disabled ? 'disabled' : '') . ' />' . $value->display_name . '</label>';
377
- }
378
-
379
- public function postbox_render($context, $args) {
380
- $value = $args['args'];
381
- ?>
382
- <div class="main <?php echo $value->deprecated ? 'deprecated' : 'active'; echo ' '; echo $value->hidden ? 'hidden' : 'visible'; ?>">
383
- <?php
384
- if ($value->caps === 'defaulted') {
385
- ?>
386
- <div class="no-capability">
387
- <?php
388
- echo $this->__("Uses 'Posts' capabilities.");
389
- $upgrade_message = sprintf($this->__("%s to customize capabilities."), '<a href="https://wpfront.com/ureaddedit" target="_blank">' . $this->__('Upgrade to Pro') . '</a>');
390
- $upgrade_message = apply_filters('wpfront_ure_custom_post_type_upgrade_message', $upgrade_message);
391
- echo ' ' . $upgrade_message;
392
- ?>
393
- </div>
394
- <?php
395
- } else {
396
- foreach ($value->caps as $cap) {
397
- $cap = esc_html($cap);
398
- ?>
399
- <div>
400
- <input type="checkbox" id="<?php echo $cap; ?>" name="capabilities[<?php echo $cap; ?>]" <?php echo $value->disabled ? 'disabled' : '' ?> <?php echo $this->capability_checked($cap) ? 'checked' : '' ?> />
401
- <label for="<?php echo $cap; ?>" title="<?php echo $cap; ?>"><?php echo $cap; ?></label>
402
- <?php
403
- if ($value->has_help) {
404
- $help_url = $this->get_help_url($cap);
405
- if ($help_url !== NULL) {
406
- ?>
407
- <a target="_blank" href="<?php echo $help_url; ?>">
408
- <img class="help" src="<?php echo $this->image_url() . 'help.png'; ?>" />
409
- </a>
410
- <?php
411
- }
412
- }
413
- ?>
414
- </div>
415
- <?php
416
- }
417
- }
418
- ?>
419
- </div>
420
- <?php
421
- }
422
-
423
- }
424
-
425
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-add-remove-capability.php DELETED
@@ -1,186 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Add_Remove_Capability')) {
30
-
31
- /**
32
- * Add or Remove Capability
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Add_Remove_Capability extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- const MENU_SLUG = 'wpfront-user-role-editor-add-remove-capability';
40
-
41
- private $action;
42
- private $capability;
43
- private $roles_type;
44
- private $roles;
45
- private $message;
46
- private $error;
47
-
48
- public function add_remove_capability() {
49
-
50
- if (!$this->can_edit()) {
51
- $this->main->permission_denied();
52
- return;
53
- }
54
-
55
- $this->action = 'add';
56
- $this->capability = '';
57
- $this->roles_type = 'all';
58
- $this->roles = array();
59
- $this->message = NULL;
60
- $this->error = NULL;
61
-
62
- if (!empty($_POST['add-remove-capability'])) {
63
- $this->main->verify_nonce();
64
-
65
- $this->action = $_POST['action_type'];
66
- $this->capability = trim($_POST['capability']);
67
- if (empty($this->capability))
68
- $this->capability = NULL;
69
- $this->roles_type = $_POST['roles_type'];
70
- if ($this->roles_type === 'selected' && !empty($_POST['selected-roles']))
71
- $this->roles = $_POST['selected-roles'];
72
-
73
- if (!empty($this->capability)) {
74
- $roles = array();
75
- switch ($this->roles_type) {
76
- case 'all':
77
- global $wp_roles;
78
- $roles = $wp_roles->role_names;
79
- break;
80
- case 'selected':
81
- $roles = $this->roles;
82
- break;
83
- }
84
-
85
- $func = NULL;
86
- switch ($this->action) {
87
- case 'add':
88
- //network caps check
89
- if(strpos($this->capability, 'manage_network_') === 0) {
90
- $this->error = $this->__('This capability is reserved for Super Admins and can not be added to site roles.');
91
- break;
92
- }
93
-
94
- $func = 'add_cap';
95
- if (!isset($roles[self::ADMINISTRATOR_ROLE_KEY])) {
96
- $roles[self::ADMINISTRATOR_ROLE_KEY] = TRUE;
97
- }
98
- break;
99
- case 'remove':
100
- $func = 'remove_cap';
101
- if ($this->roles_type === 'all') {
102
- $roles[self::ADMINISTRATOR_ROLE_KEY] = TRUE;
103
- } else {
104
- unset($roles[self::ADMINISTRATOR_ROLE_KEY]);
105
- }
106
- break;
107
- }
108
-
109
- if(!empty($func) && empty($this->error)) {
110
- foreach ($roles as $key => $value) {
111
- $role = get_role($key);
112
- if (!empty($role)) {
113
- $role->$func($this->capability);
114
- }
115
- }
116
-
117
- $this->message = $this->__('Roles updated.');
118
- }
119
- }
120
- }
121
-
122
- include($this->main->pluginDIR() . 'templates/add-remove-capability.php');
123
- }
124
-
125
- private function get_roles() {
126
- global $wp_roles;
127
- $roles = $wp_roles->role_names;
128
-
129
- unset($roles[self::ADMINISTRATOR_ROLE_KEY]);
130
-
131
- return $roles;
132
- }
133
-
134
- protected function add_help_tab() {
135
- return array(
136
- array(
137
- 'id' => 'overview',
138
- 'title' => $this->__('Overview'),
139
- 'content' => '<p>'
140
- . $this->__('This screen allows you to add a capability to roles or remove a capability from roles within your site.')
141
- . '</p>'
142
- ),
143
- array(
144
- 'id' => 'action',
145
- 'title' => $this->__('Action'),
146
- 'content' => '<p>'
147
- . $this->__('Select "Add Capability" to add a capability to roles.')
148
- . '</p>'
149
- . '<p>'
150
- . $this->__('Select "Remove Capability" to remove a capability from roles.')
151
- . '</p>'
152
- ),
153
- array(
154
- 'id' => 'capability',
155
- 'title' => $this->__('Capability'),
156
- 'content' => '<p>'
157
- . $this->__('Use the Capability field to name the capability to be added or removed.')
158
- . '</p>'
159
- ),
160
- array(
161
- 'id' => 'roles',
162
- 'title' => $this->__('Roles'),
163
- 'content' => '<p><strong>'
164
- . $this->__('All Roles')
165
- . '</strong>: '. $this->__('Select "All Roles", if you want the current action to be applied to all roles within your site.')
166
- . '</p>'
167
- . '<p><strong>'
168
- . $this->__('Selected Roles')
169
- . '</strong>: '. $this->__('Select "Selected Roles", if you want to individually select the roles. When this option is selected, "Administrator" role is included by default on "Add Capability" action and excluded by default on "Remove Capability" action.')
170
- . '</p>'
171
- )
172
- );
173
- }
174
-
175
- protected function set_help_sidebar() {
176
- return array(
177
- array(
178
- $this->__('Documentation on Add/Remove Capability'),
179
- 'add-remove-capability/'
180
- )
181
- );
182
- }
183
-
184
- }
185
-
186
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-assign-roles.php DELETED
@@ -1,490 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- if (!class_exists('WPFront_User_Role_Editor_Assign_Roles')) {
29
-
30
- /**
31
- * Assign Roles
32
- *
33
- * @author Syam Mohan <syam@wpfront.com>
34
- * @copyright 2014 WPFront.com
35
- */
36
- class WPFront_User_Role_Editor_Assign_Roles extends WPFront_User_Role_Editor_Controller_Base {
37
-
38
- const MENU_SLUG = 'wpfront-user-role-editor-assign-roles';
39
- const SECONDARY_ROLE_COLUMN_KEY = 'secondary_roles';
40
-
41
- private $user = NULL;
42
- private $userPrimaryRole = '';
43
- private $userSecondaryRoles = array();
44
- private $users;
45
- private $migrateFromPrimaryRole = NULL;
46
- private $migrateToPrimaryRole = NULL;
47
- private $migrateToSecondaryRoles = array();
48
- private $primary_roles;
49
- private $secondary_roles;
50
- private $result = NULL;
51
-
52
- function __construct($main) {
53
- parent::__construct($main);
54
-
55
- add_filter('manage_users_columns', array($this, 'manage_users_columns'), 10, 1);
56
- add_filter('manage_users_custom_column', array($this, 'manage_users_columns_content'), 10, 3);
57
-
58
- add_filter('user_row_actions', array($this, 'user_row_actions'), 10, 2);
59
-
60
- add_action('edit_user_profile', array($this, 'edit_user_profile'), 10, 1);
61
- add_action('user_new_form', array($this, 'user_new_form'), 10, 1);
62
- //add_action('edit_user_profile_update', array($this, 'edit_user_profile_update'), 1000, 1);
63
- add_action('profile_update', array($this, 'edit_user_profile_update'), 1000, 1);
64
- add_action('edit_user_created_user', array($this, 'edit_user_created_user'), 1000, 1);
65
- }
66
-
67
- public function manage_users_columns($columns) {
68
- if (!WPFront_Static_URE::WP_Version('4.4')) {
69
- $columns[self::SECONDARY_ROLE_COLUMN_KEY] = $this->__('Secondary Roles');
70
- }
71
-
72
- return $columns;
73
- }
74
-
75
- public function manage_users_columns_content($value, $column_name, $user_id) {
76
- if ($column_name == self::SECONDARY_ROLE_COLUMN_KEY) {
77
- $user = get_userdata($user_id);
78
- return $this->get_secondary_role_list($user->roles);
79
- }
80
- return $value;
81
- }
82
-
83
- public function user_row_actions($actions, $user_object) {
84
- if ($this->can_assign_roles() && $user_object->ID !== wp_get_current_user()->ID && current_user_can('promote_user', $user_object->ID))
85
- $actions['assign_roles'] = sprintf('<a href="%s">%s</a>', $this->get_assign_role_url($user_object), $this->__('Assign Roles'));
86
- return $actions;
87
- }
88
-
89
- public function edit_user_profile($user) {
90
- if (is_multisite() && is_network_admin())
91
- return;
92
-
93
- if (!$this->can_assign_roles())
94
- return;
95
-
96
- //TODO: remove for Administrator.
97
- if ($user->ID === wp_get_current_user()->ID)
98
- return;
99
-
100
- if (!current_user_can('promote_user', $user->ID))
101
- return;
102
-
103
- $this->populate_roles_array();
104
- $roles = array_values($user->roles);
105
- array_shift($roles);
106
-
107
- $this->secondary_roles = apply_filters('wpfront_ure_edit_user_profile_secondary_roles', $this->secondary_roles, $user);
108
-
109
- //echo "<h3>{$this->__('Secondary Roles')}</h3>";
110
- echo '<table class="form-table">';
111
- echo '<tbody>';
112
- echo '<tr>';
113
- echo "<th scope='row'>{$this->__('Secondary Roles')}</th>";
114
- echo '<td>';
115
- if(empty($this->secondary_roles)) {
116
- echo $this->__('No roles for this site.');
117
- } else {
118
- foreach ($this->secondary_roles as $key => $value) {
119
- echo '<div style="min-width:200px;width:25%;float:left;">';
120
- printf('<label><input type="checkbox" name="wpfront-secondary-roles[%s]" %s />%s</label>', $key, in_array($key, $roles) ? 'checked' : '', $value);
121
- echo '</div>';
122
- }
123
- }
124
- echo '</td>';
125
- echo '</tr>';
126
- echo '</tbody>';
127
- echo '</table>';
128
- }
129
-
130
- public function user_new_form() {
131
- if (is_multisite() && is_network_admin())
132
- return;
133
-
134
- if (!$this->can_assign_roles())
135
- return;
136
-
137
- $this->populate_roles_array();
138
-
139
- $this->secondary_roles = apply_filters('wpfront_ure_add_user_profile_secondary_roles', $this->secondary_roles);
140
-
141
- //echo "<h3>{$this->__('Secondary Roles')}</h3>";
142
- echo '<table class="form-table">';
143
- echo '<tbody>';
144
- echo '<tr>';
145
- echo "<th scope='row'>{$this->__('Secondary Roles')}</th>";
146
- echo '<td>';
147
- if(empty($this->secondary_roles)) {
148
- echo $this->__('No roles for this site.');
149
- } else {
150
- foreach ($this->secondary_roles as $key => $value) {
151
- echo '<div style="min-width:200px;width:25%;float:left;">';
152
- printf('<label><input type="checkbox" name="wpfront-secondary-roles[%s]" />%s</label>', $key, $value);
153
- echo '</div>';
154
- }
155
- }
156
- echo '</td>';
157
- echo '</tr>';
158
- echo '</tbody>';
159
- echo '</table>';
160
- }
161
-
162
- public function edit_user_profile_update($user_id) {
163
- if (is_multisite() && is_network_admin())
164
- return;
165
-
166
- if (!$this->can_assign_roles())
167
- return;
168
-
169
- if ($user_id === wp_get_current_user()->ID)
170
- return;
171
-
172
- if (!current_user_can('promote_user', $user_id))
173
- return;
174
-
175
- //$user = get_user_to_edit($user_id); //fatal error - function not defined.
176
- $user = get_userdata($user_id);
177
- if (empty($user))
178
- return;
179
-
180
- $this->populate_roles_array();
181
- foreach ($this->secondary_roles as $key => $value) {
182
- if (!empty($_POST["wpfront-secondary-roles"][$key]))
183
- $user->add_role($key);
184
- }
185
- }
186
-
187
- public function edit_user_created_user($user_id) {
188
- if (is_multisite() && is_network_admin())
189
- return;
190
-
191
- if (!$this->can_assign_roles())
192
- return;
193
-
194
- $user = get_userdata($user_id);
195
- if (empty($user))
196
- return;
197
-
198
- $this->populate_roles_array();
199
- foreach ($this->secondary_roles as $key => $value) {
200
- if (!empty($_POST["wpfront-secondary-roles"][$key]))
201
- $user->add_role($key);
202
- }
203
- }
204
-
205
- private function get_assign_role_url($user_object = NULL) {
206
- if ($user_object == NULL) {
207
- if (is_multisite() && is_network_admin()) {
208
- $site_id = 1;
209
- if (!empty($_GET['id']))
210
- $site_id = $_GET['id'];
211
- return get_admin_url($site_id, 'users.php') . '?page=' . self::MENU_SLUG . '&assign_roles=';
212
- } else
213
- return admin_url('users.php') . '?page=' . self::MENU_SLUG . '&assign_roles=';
214
- }
215
- return $this->get_assign_role_url() . $user_object->ID;
216
- }
217
-
218
- private function get_secondary_role_list($roles) {
219
- $names = array();
220
-
221
- global $wp_roles;
222
-
223
- foreach ($roles as $value) {
224
- if (array_key_exists($value, $wp_roles->role_names)) {
225
- $names[] = $wp_roles->role_names[$value];
226
- }
227
- }
228
-
229
- array_shift($names);
230
- return implode(', ', $names);
231
- }
232
-
233
- private function populate_roles_array() {
234
- global $wp_roles;
235
- $roles_names = $wp_roles->get_names();
236
- $assignable_roles = $this->main->get_assignable_roles();
237
-
238
- $roles = array();
239
- foreach ($assignable_roles as $key => $value) {
240
- $roles[$key] = $roles_names[$key];
241
- }
242
-
243
- $this->primary_roles = $roles;
244
- $this->primary_roles[''] = '&mdash;' . $this->__('No role for this site') . '&mdash;';
245
-
246
- $this->secondary_roles = array();
247
- foreach ($roles as $key => $value) {
248
- if ($key != self::ADMINISTRATOR_ROLE_KEY)
249
- $this->secondary_roles[$key] = $value;
250
- }
251
- }
252
-
253
- public function assign_roles() {
254
- if (!$this->can_assign_roles()) {
255
- $this->main->permission_denied();
256
- return;
257
- }
258
-
259
- $this->users = get_users(array('exclude' => array(wp_get_current_user()->ID)));
260
- $this->users = array_filter($this->users, array($this, 'array_filter_user'));
261
- $this->populate_roles_array();
262
-
263
- if (!empty($_POST['assignroles']) && !empty($_POST['assign-user'])) {
264
- $this->main->verify_nonce();
265
-
266
- $this->result = (OBJECT) array("success" => FALSE);
267
-
268
- $this->user = get_userdata($_POST['assign-user']);
269
- if ($this->user === FALSE || $this->user->ID === wp_get_current_user()->ID) {
270
- $this->user = NULL;
271
- $this->result->message = $this->__('Invalid user.');
272
- }
273
-
274
- if ($this->user != NULL) {
275
- if (!current_user_can('promote_user', $this->user->ID)) {
276
- $this->user = NULL;
277
- $this->result->message = $this->__('Permission denied.');
278
- }
279
- }
280
-
281
- if ($this->user != NULL) {
282
- $primary_role = NULL;
283
- if (isset($_POST['assign-primary-role'])) {
284
- $primary_role = $_POST['assign-primary-role'];
285
- if (!array_key_exists($primary_role, $this->primary_roles))
286
- $primary_role = NULL;
287
- }
288
-
289
- if ($primary_role !== NULL) {
290
- $secondary_roles = array();
291
- if (!empty($_POST['assign-secondary-roles'])) {
292
- $secondary_roles = $_POST['assign-secondary-roles'];
293
- }
294
- if (is_array($secondary_roles))
295
- $secondary_roles = array_keys($secondary_roles);
296
- else
297
- $secondary_roles = array();
298
-
299
- $this->user->set_role($primary_role);
300
-
301
- foreach ($secondary_roles as $role) {
302
- $this->user->add_role($role);
303
- }
304
-
305
- $this->result->success = TRUE;
306
- $this->result->message = $this->__('Roles updated successfully.');
307
- } else {
308
- $this->result->message = $this->__('Invalid primary role specified.');
309
- }
310
- }
311
- }
312
-
313
- if (!empty($_POST['migrateroles'])) {
314
- $this->main->verify_nonce();
315
-
316
- $this->result = (OBJECT) array("success" => FALSE);
317
-
318
- if (isset($_POST['migrate-from-primary-role'])) {
319
- $this->migrateFromPrimaryRole = $_POST['migrate-from-primary-role'];
320
- if (!array_key_exists($this->migrateFromPrimaryRole, $this->primary_roles)) {
321
- $this->migrateFromPrimaryRole = NULL;
322
- }
323
- }
324
-
325
- if ($this->migrateFromPrimaryRole === NULL) {
326
- $this->result->message = $this->__('Invalid primary role.');
327
- } else {
328
- if (isset($_POST['migrate-primary-role'])) {
329
- $this->migrateToPrimaryRole = $_POST['migrate-primary-role'];
330
- if (!array_key_exists($this->migrateToPrimaryRole, $this->primary_roles)) {
331
- $this->migrateToPrimaryRole = NULL;
332
- }
333
- }
334
-
335
- if ($this->migrateToPrimaryRole === NULL) {
336
- $this->result->message = $this->__('Invalid primary role.');
337
- } else {
338
- if (!empty($_POST['migrate-secondary-roles'])) {
339
- $this->migrateToSecondaryRoles = $_POST['migrate-secondary-roles'];
340
- if (is_array($this->migrateToSecondaryRoles))
341
- $this->migrateToSecondaryRoles = array_keys($this->migrateToSecondaryRoles);
342
- else
343
- $this->migrateToSecondaryRoles = array();
344
- }
345
-
346
- $users = get_users(array('exclude' => array(wp_get_current_user()->ID), 'role' => $this->migrateFromPrimaryRole));
347
- $users = array_filter($users, array($this, 'array_migrate_filter_user'));
348
-
349
- foreach ($users as $user) {
350
- $user->set_role($this->migrateToPrimaryRole);
351
-
352
- foreach ($this->migrateToSecondaryRoles as $role) {
353
- $user->add_role($role);
354
- }
355
- }
356
-
357
- $this->result->success = TRUE;
358
- $this->result->message = sprintf($this->__('%d user(s) migrated.'), count($users));
359
- }
360
- }
361
- }
362
-
363
- if ($this->user == NULL && !empty($_GET['assign_roles'])) {
364
- $this->user = get_userdata($_GET['assign_roles']);
365
- if ($this->user === FALSE || $this->user->ID === wp_get_current_user()->ID || !current_user_can('promote_user', $this->user->ID))
366
- $this->user = NULL;
367
- }
368
-
369
- if ($this->user == NULL) {
370
- if (!empty($this->users))
371
- $this->user = $this->users[0];
372
- }
373
-
374
- if ($this->user != NULL) {
375
- $roles = $this->user->roles;
376
- $this->userPrimaryRole = array_shift($roles);
377
- if ($this->userPrimaryRole === NULL)
378
- $this->userPrimaryRole = '';
379
- $this->userSecondaryRoles = $roles;
380
- }
381
-
382
- include($this->main->pluginDIR() . 'templates/assign-roles.php');
383
- }
384
-
385
- private function array_filter_user($user) {
386
- return current_user_can('promote_user', $user->ID);
387
- }
388
-
389
- private function array_migrate_filter_user($user) {
390
- if ($this->migrateFromPrimaryRole === '') {
391
- if (empty($user->roles))
392
- return TRUE;
393
- }
394
-
395
- if (empty($user->roles))
396
- return FALSE;
397
-
398
- if (!current_user_can('promote_user', $user->ID))
399
- return FALSE;
400
-
401
- $roles = $user->roles;
402
- $role = array_shift($roles);
403
- return $role === $this->migrateFromPrimaryRole;
404
- }
405
-
406
- private function primary_secondary_section($prefix, $selectPrimaryRole = NULL, $selectSecondaryRoles = array()) {
407
- ?>
408
- <tr>
409
- <th scope="row">
410
- <?php echo $this->__('Primary Role'); ?>
411
- </th>
412
- <td>
413
- <select id="<?php echo $prefix; ?>_roles_list" name="<?php echo $prefix; ?>-primary-role">
414
- <?php
415
- foreach ($this->primary_roles as $key => $role) {
416
- ?>
417
- <option value="<?php echo $key; ?>" <?php echo $selectPrimaryRole === $key ? 'selected' : ''; ?>>
418
- <?php echo $role; ?>
419
- </option>
420
- <?php
421
- }
422
- ?>
423
- </select>
424
- </td>
425
- </tr>
426
- <tr>
427
- <th scope="row">
428
- <?php echo $this->__('Secondary Roles'); ?>
429
- </th>
430
- <td>
431
- <div class="role-list">
432
- <?php
433
- foreach ($this->secondary_roles as $key => $role) {
434
- ?>
435
- <div class="role-list-item">
436
- <label>
437
- <input type="checkbox" name="<?php echo $prefix; ?>-secondary-roles[<?php echo $key; ?>]" <?php echo in_array($key, $selectSecondaryRoles) ? 'checked' : ''; ?> />
438
- <?php echo $role; ?>
439
- </label>
440
- </div>
441
- <?php
442
- }
443
- ?>
444
- </div>
445
- </td>
446
- </tr>
447
- <?php
448
- }
449
-
450
- protected function add_help_tab() {
451
- return array(
452
- array(
453
- 'id' => 'overview',
454
- 'title' => $this->__('Overview'),
455
- 'content' => '<p>'
456
- . $this->__('This screen allows you to assign multiple roles to a user and also allows you to migrate users from a role to another role.')
457
- . '</p>'
458
- ),
459
- array(
460
- 'id' => 'assignroles',
461
- 'title' => $this->__('Assign Roles'),
462
- 'content' => '<p>'
463
- . $this->__('To assign multiple roles to a user, select that user within the User drop down list and select the primary role you want for that user using the Primary Role drop down list. Select the secondary roles using the check boxes below, then click Assign Roles.')
464
- . '</p>'
465
- ),
466
- array(
467
- 'id' => 'migrateusers',
468
- 'title' => $this->__('Migrate Users'),
469
- 'content' => '<p>'
470
- . $this->__('To migrate users from one role to another role or to add secondary roles to users belonging to a particular primary role, use the migrate users functionality.')
471
- . '</p>'
472
- . '<p>'
473
- . $this->__('Select the users using the From Primary Role drop down, to primary role using the Primary Role drop down and secondary roles using the check boxes then click Migrate Users.')
474
- . '</p>'
475
- )
476
- );
477
- }
478
-
479
- protected function set_help_sidebar() {
480
- return array(
481
- array(
482
- $this->__('Documentation on Assign / Migrate Users'),
483
- 'assign-migrate-users/'
484
- )
485
- );
486
- }
487
-
488
- }
489
-
490
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-attachment-permissions.php DELETED
@@ -1,88 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Attachment_Permissions')) {
30
-
31
- /**
32
- * Attachment Permissions
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Attachment_Permissions extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- private static $attachment_capabilities = array('edit_attachments', 'delete_attachments', 'read_others_attachments', 'edit_others_attachments', 'delete_others_attachments');
40
-
41
- public function __construct($main) {
42
- parent::__construct($main);
43
-
44
- $media = WPFront_User_Role_Editor::$STANDARD_CAPABILITIES['Media'];
45
- foreach (self::$attachment_capabilities as $value) {
46
- $media[$value] = $media['upload_files'];
47
- }
48
- WPFront_User_Role_Editor::$STANDARD_CAPABILITIES['Media'] = $media;
49
-
50
- add_filter('user_has_cap', array($this, 'user_has_cap'), 10, 3);
51
- add_filter('posts_where', array($this, 'posts_where'), 10, 2);
52
-
53
- add_action('admin_init', array($this, 'admin_init'));
54
- }
55
-
56
- public function user_has_cap($allcaps, $caps, $args) {
57
- return $allcaps;
58
- }
59
-
60
- public function posts_where($where, $query) {
61
- return $where;
62
- }
63
-
64
- public function admin_init() {
65
- $option_key = 'attachment_capabilities_processed';
66
- $entity = new WPFront_User_Role_Editor_Entity_Options();
67
-
68
- $processed = $entity->get_option($option_key);
69
- if (!empty($processed))
70
- return;
71
-
72
- global $wp_roles;
73
-
74
- foreach ($wp_roles->role_objects as $key => $role) {
75
- if ($role->has_cap('upload_files')) {
76
- foreach (self::$attachment_capabilities as $cap) {
77
- $role->add_cap($cap);
78
- }
79
- }
80
- }
81
-
82
- $entity->update_option($option_key, TRUE);
83
- }
84
-
85
- }
86
-
87
- }
88
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-controller-base.php DELETED
@@ -1,188 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Controller_Base')) {
30
-
31
- /**
32
- * Base class of WPFront User Role Editor Controllers
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Controller_Base {
38
-
39
- const ADMINISTRATOR_ROLE_KEY = WPFront_User_Role_Editor::ADMINISTRATOR_ROLE_KEY;
40
-
41
- protected $main;
42
- protected $page_hook;
43
- protected $multisite = FALSE;
44
- private static $ajax_handlers = array();
45
-
46
- public function __construct($main) {
47
- $this->main = $main;
48
-
49
- add_action('admin_init', array($this, 'check_multisite'));
50
- }
51
-
52
- public function set_page_hook($page_hook) {
53
- $this->page_hook = $page_hook;
54
- add_action("load-{$this->page_hook}", array($this, 'set_help_tab'));
55
- }
56
-
57
- public static function register_ajax_handlers() {
58
- foreach (self::$ajax_handlers as $key => $value) {
59
- add_action($key, $value);
60
- }
61
- }
62
-
63
- protected function ajax_register($key, $func) {
64
- self::$ajax_handlers[$key] = $func;
65
- }
66
-
67
- public function check_multisite() {
68
- $this->multisite = is_network_admin();
69
- }
70
-
71
- public function set_multisite($multisite) {
72
- $this->multisite = $multisite;
73
- }
74
-
75
- public function set_help_tab() {
76
- $screen = get_current_screen();
77
-
78
- $tabs = $this->add_help_tab();
79
- if ($tabs !== NULL) {
80
- foreach ($tabs as $value) {
81
- $screen->add_help_tab($value);
82
- }
83
- }
84
-
85
- $sidebar = $this->set_help_sidebar();
86
- if ($sidebar !== NULL) {
87
- $s = '<p><strong>' . $this->__('Links:') . '</strong></p>';
88
-
89
- foreach ($sidebar as $value) {
90
- $s .= '<p><a target="_blank" href="http://wpfront.com/user-role-editor-pro/' . $value[1] . '">' . $value[0] . '</a></p>';
91
- }
92
-
93
- $s .= '<p><a target="_blank" href="http://wpfront.com/user-role-editor-pro/faq/">' . $this->__('FAQ') . '</a></p>';
94
- $s .= '<p><a target="_blank" href="http://wpfront.com/support/">' . $this->__('Support') . '</a></p>';
95
- $s .= '<p><a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/wpfront-user-role-editor">' . $this->__('Review') . '</a></p>';
96
- $s .= '<p><a target="_blank" href="http://wpfront.com/contact/">' . $this->__('Contact') . '</a></p>';
97
-
98
-
99
-
100
- $screen->set_help_sidebar($s);
101
- }
102
- }
103
-
104
- protected function add_help_tab() {
105
- return NULL;
106
- }
107
-
108
- protected function set_help_sidebar() {
109
- return NULL;
110
- }
111
-
112
- public function can_list() {
113
- return $this->main->current_user_can('list_roles');
114
- }
115
-
116
- public function can_create() {
117
- return $this->main->current_user_can('create_roles');
118
- }
119
-
120
- public function can_edit() {
121
- return $this->main->current_user_can('edit_roles');
122
- }
123
-
124
- public function can_delete() {
125
- return $this->main->current_user_can('delete_roles');
126
- }
127
-
128
- public function can_assign_roles() {
129
- return current_user_can('promote_users') && current_user_can('list_users');
130
- }
131
-
132
- public function __($s) {
133
- return $this->main->__($s);
134
- }
135
-
136
- public function image_url() {
137
- return $this->main->pluginURL() . 'images/';
138
- }
139
-
140
- protected function footer() {
141
- $this->main->footer();
142
- }
143
-
144
- public function list_url() {
145
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG;
146
- }
147
-
148
- public function add_new_url() {
149
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_Add_Edit::MENU_SLUG;
150
- }
151
-
152
- public function edit_url() {
153
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&edit_role=';
154
- }
155
-
156
- public function delete_url() {
157
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&delete_role=';
158
- }
159
-
160
- public function set_default_url() {
161
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_List::MENU_SLUG . '&nonce=' . wp_create_nonce($this->list_url()) . '&set_default_role=';
162
- }
163
-
164
- public function settings_url() {
165
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_Options::MENU_SLUG;
166
- }
167
-
168
- public function login_redirect_url() {
169
- return admin_url('admin.php') . '?page=' . WPFront_User_Role_Editor_Login_Redirect::MENU_SLUG;
170
- }
171
-
172
- public function cache_add($key, $data) {
173
- wp_cache_set($key, $data, WPFront_User_Role_Editor::PLUGIN_SLUG);
174
- }
175
-
176
- public function cache_get($key) {
177
- $data = wp_cache_get($key, WPFront_User_Role_Editor::PLUGIN_SLUG);
178
- if ($data === FALSE)
179
- return NULL;
180
-
181
- return $data;
182
- }
183
-
184
- }
185
-
186
- add_action('admin_init', 'WPFront_User_Role_Editor_Controller_Base::register_ajax_handlers', 1001);
187
- wp_cache_add_non_persistent_groups(WPFront_User_Role_Editor::PLUGIN_SLUG);
188
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-delete.php DELETED
@@ -1,138 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Delete')) {
30
-
31
- /**
32
- * WPFront User Role Editor Plugin Delete Role
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Delete extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- protected $roles;
40
-
41
- function __construct($main) {
42
- parent::__construct($main);
43
- }
44
-
45
- public function delete_role($delete_roles) {
46
- if (!$this->can_delete()) {
47
- $this->main->permission_denied();
48
- return;
49
- }
50
-
51
- $this->prepare_data($delete_roles);
52
-
53
- if (!empty($_POST['confirm-delete'])) {
54
- $this->main->verify_nonce();
55
- $this->delete();
56
- printf('<script type="text/javascript">window.location.replace("%s");</script>', $this->list_url());
57
- return;
58
- }
59
-
60
- $this->include_template();
61
- }
62
-
63
- protected function include_template() {
64
- include($this->main->pluginDIR() . 'templates/delete-role.php');
65
- }
66
-
67
- protected function prepare_data($delete_roles) {
68
- $this->roles = array();
69
-
70
- $editable_roles = get_editable_roles();
71
- global $wp_roles;
72
- $override = $this->main->override_edit_permissions();
73
- if ($override)
74
- $editable_roles = $wp_roles->get_names();
75
-
76
- foreach ($delete_roles as $value) {
77
- if (array_key_exists($value, $wp_roles->role_names)) {
78
- $status_message = '';
79
- $is_deletable = TRUE;
80
- if (!array_key_exists($value, $editable_roles)) {
81
- $status_message = 'This role cannot be deleted: Permission denied.';
82
- $is_deletable = FALSE;
83
- } else if ($value == self::ADMINISTRATOR_ROLE_KEY) {
84
- $status_message = '\'administrator\' role cannot be deleted.';
85
- $is_deletable = FALSE;
86
- } else {
87
- global $user_ID;
88
- $user = new WP_User($user_ID);
89
- if (!$override && in_array($value, $user->roles)) {
90
- $status_message = 'Current user\'s role cannot be deleted.';
91
- $is_deletable = FALSE;
92
- }
93
- }
94
- $this->roles[$value] = (OBJECT) array(
95
- 'name' => $value,
96
- 'display_name' => $wp_roles->role_names[$value],
97
- 'is_deletable' => $is_deletable,
98
- 'status_message' => $status_message
99
- );
100
- }
101
- }
102
- }
103
-
104
- protected function delete() {
105
- if (!$this->can_delete())
106
- return;
107
-
108
- foreach ($this->roles as $key => $value) {
109
- if ($value->is_deletable) {
110
- remove_role($key);
111
- }
112
- }
113
- }
114
-
115
- public function is_pending_action() {
116
- if (!empty($_POST['confirm-delete']) && !empty($_POST['delete-roles'])) {
117
- $this->delete_role(array_keys($_POST['delete-roles']));
118
- return TRUE;
119
- }
120
- return FALSE;
121
- }
122
-
123
- private function get_deleting_roles() {
124
- return $this->roles;
125
- }
126
-
127
- private function is_submit_allowed() {
128
- foreach ($this->roles as $key => $value) {
129
- if ($value->is_deletable)
130
- return TRUE;
131
- }
132
-
133
- return FALSE;
134
- }
135
-
136
- }
137
-
138
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-entity-base.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit();
5
- }
6
-
7
- require_once(plugin_dir_path(__FILE__) . "base/class-wpfront-entity-base.php");
8
-
9
- if (!class_exists('WPFront_User_Role_Editor_Entity_Base')) {
10
-
11
- /**
12
- * User Role Editor Entity Base
13
- *
14
- * @author Syam Mohan <syam@wpfront.com>
15
- * @copyright 2014 WPFront.com
16
- */
17
- abstract class WPFront_User_Role_Editor_Entity_Base extends WPFront_Entity_Base {
18
-
19
- public function __construct($table_name) {
20
- parent::__construct(
21
- WPFront_User_Role_Editor::PLUGIN_SLUG,
22
- WPFront_User_Role_Editor::VERSION,
23
- $this instanceof WPFront_User_Role_Editor_Entity_Options ? $this : new WPFront_User_Role_Editor_Entity_Options(),
24
- 'ure_' . $table_name
25
- );
26
- }
27
-
28
- }
29
-
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-go-pro.php DELETED
@@ -1,449 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Go_Pro')) {
30
-
31
- /**
32
- * Go Pro
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Go_Pro extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- const MENU_SLUG = 'wpfront-user-role-editor-go-pro';
40
-
41
- private static $go_pro_html_url = 'https://wpfront.com/syam/wordpress-plugins/wpfront-user-role-editor/pro/comparison/';
42
- private static $store_url = 'https://edd.wpfront.com/';
43
- private $pro_html = '';
44
- private $has_license = FALSE;
45
- private $need_license = FALSE;
46
- private $license_status = NULL;
47
- private $license_key = NULL;
48
- private $license_key_k = NULL;
49
- private $license_expires = NULL;
50
- private $download_id = NULL;
51
- private $license_expired = FALSE;
52
- private $product = NULL;
53
- private $slug = NULL;
54
- private $error = NULL;
55
- private $plugin_updater = NULL;
56
- private $mail_objects = array();
57
- private $renew_url = NULL;
58
- private $license_home_url = NULL;
59
-
60
- public function __construct($main) {
61
- parent::__construct($main);
62
-
63
- $this->ajax_register('wp_ajax_wpfront_user_role_editor_license_functions', array($this, 'license_functions'));
64
- add_action('shutdown', array($this, 'plugins_loaded'));
65
- }
66
-
67
- public function go_pro() {
68
- $this->main->verify_nonce();
69
-
70
- if (!current_user_can('manage_options')) {
71
- $this->main->permission_denied();
72
- return;
73
- }
74
-
75
- if (!empty($_POST['license_key']) && !empty($_POST['activate'])) {
76
- $this->activate_license($_POST['license_key']);
77
- }
78
-
79
- if (!empty($_POST['deactivate'])) {
80
- $this->deactivate_license();
81
- }
82
-
83
- $options = new WPFront_User_Role_Editor_Entity_Options();
84
-
85
- $time_key = self::MENU_SLUG . '-html-last-update';
86
- $html_key = self::MENU_SLUG . '-html';
87
-
88
- $time = $options->get_option($time_key);
89
-
90
- if ($time === NULL || $time < time() - 24 * 3600) {
91
- $options->update_option($time_key, time());
92
- $result = WPFront_User_Role_Editor::wp_remote_get(self::$go_pro_html_url);
93
- if (!is_wp_error($result) && wp_remote_retrieve_response_code($result) == 200) {
94
- $this->pro_html = wp_remote_retrieve_body($result);
95
- $options->update_option($html_key, $this->pro_html);
96
- }
97
- }
98
-
99
- if ($this->pro_html === '') {
100
- $key = self::MENU_SLUG . '-html';
101
- $this->pro_html = $options->get_option($key);
102
- if ($this->pro_html === NULL)
103
- $this->pro_html = '';
104
- }
105
-
106
- if ($this->pro_html === '') {
107
- $this->pro_html = file_get_contents($this->main->pluginDIR() . 'templates/go-pro-table');
108
- }
109
-
110
- include($this->main->pluginDIR() . 'templates/go-pro.php');
111
- }
112
-
113
- public function set_license($key = NULL, $product = NULL) {
114
- if ($key === NULL && $this->license_key_k === NULL)
115
- return;
116
-
117
- if ($key !== NULL) {
118
- $this->slug = $key;
119
- $this->need_license = TRUE;
120
- $this->license_key_k = $key . '-license-key';
121
- $this->product = $product;
122
- }
123
-
124
- if (is_multisite()) {
125
- $options = new WPFront_User_Role_Editor_Options($this->main);
126
- switch_to_blog($options->ms_options_blog_id());
127
- }
128
-
129
- $entity = new WPFront_User_Role_Editor_Entity_Options();
130
- $this->license_key = $entity->get_option($this->license_key_k);
131
- if ($this->license_key !== NULL) {
132
- $invalid_count = $entity->get_option($this->license_key_k . '-invalid-count');
133
- if (empty($invalid_count)) {
134
- $invalid_count = 0;
135
- }
136
-
137
- $last_checked = $entity->get_option($this->license_key_k . '-last-checked');
138
- if (($invalid_count > 0 || is_admin()) && !WPFront_Static_URE::doing_ajax() && $last_checked < time() - 24 * 3600) {
139
- $entity->update_option($this->license_key_k . '-last-checked', time());
140
- $result = $this->remote_get('check_license', $this->license_key);
141
- $api_params = $result[1];
142
- $result = $result[0];
143
- if (!empty($result)) {
144
- if (($result->activations_left === 'unlimited' || $result->activations_left >= 0) && ($result->license === 'valid' || $result->license === 'expired')) {
145
- $entity->update_option($this->license_key_k . '-status', $result->license);
146
- $entity->update_option($this->license_key_k . '-expires', $result->expires);
147
- $entity->update_option($this->license_key_k . '-download-id', $result->download_id);
148
- $entity->update_option($this->license_key_k . '-invalid-count', 0);
149
- } else {
150
- $invalid_count = $invalid_count + 1;
151
- $entity->update_option($this->license_key_k . '-invalid-count', $invalid_count);
152
- $entity->update_option($this->license_key_k . '-home-url', $api_params['url']);
153
- $this->license_status = 'invalid';
154
- if ($invalid_count === 1) {
155
- $this->send_mail('invalid', $result, 'wpfront.com', $api_params);
156
- } else if ($invalid_count > 7) {
157
- $this->deactivate_license(TRUE);
158
- $this->send_mail('deactivated', $result, 'wpfront.com');
159
- return;
160
- }
161
- }
162
- }
163
- }
164
-
165
- $this->has_license = TRUE;
166
- $this->license_expired = $entity->get_option($this->license_key_k . '-status') === 'expired';
167
- $this->license_expires = date('F d, Y', strtotime($entity->get_option($this->license_key_k . '-expires')));
168
- $this->download_id = $entity->get_option($this->license_key_k . '-download-id');
169
- if (!empty($this->download_id)) {
170
- $this->renew_url = sprintf('https://wpfront.com/checkout/?edd_license_key=%s&download_id=%d', $this->license_key, $this->download_id);
171
- }
172
-
173
- //$invalid_count = $entity->get_option($this->license_key_k . '-invalid-count');
174
- if ($invalid_count > 0) {
175
- $this->license_status = 'invalid';
176
- $this->license_home_url = $entity->get_option($this->license_key_k . '-home-url');
177
- }
178
-
179
- if ($this->license_status === NULL) {
180
- if ($this->license_expired) {
181
- $this->license_status = 'expired';
182
- } else {
183
- $this->license_status = 'valid';
184
- }
185
- }
186
-
187
- $this->license_key = str_repeat('X', strlen($this->license_key) - 4) . substr($this->license_key, strlen($this->license_key) - 4, 4);
188
-
189
- add_action('admin_notices', array($this, 'license_admin_notice'));
190
-
191
- //Software licensing change
192
- $this->edd_plugin_update();
193
- //add_action('admin_init', array($this, 'edd_plugin_update'));
194
- } else {
195
- $this->license_key = '';
196
- $this->has_license = FALSE;
197
- $this->license_expires = NULL;
198
- }
199
-
200
- if (is_multisite()) {
201
- restore_current_blog();
202
- }
203
- }
204
-
205
- private function activate_license($license) {
206
- if ($this->license_key_k === NULL)
207
- return;
208
-
209
- $license = trim($license);
210
-
211
- $this->license_key = $license;
212
-
213
- $result = $this->remote_get('activate_license', $license);
214
- if ($result === NULL)
215
- return;
216
-
217
- $result = $result[0];
218
-
219
- $entity = new WPFront_User_Role_Editor_Entity_Options();
220
- $entity->delete_option($this->license_key_k);
221
- $entity->delete_option($this->license_key_k . '-expires');
222
- $entity->delete_option($this->license_key_k . '-last-checked');
223
-
224
- if ($result->license === 'valid' || $result->error === 'expired') {
225
- $entity->update_option($this->license_key_k, $license);
226
- $entity->update_option($this->license_key_k . '-status', $result->license === 'valid' ? 'valid' : 'expired');
227
- $entity->update_option($this->license_key_k . '-expires', $result->expires);
228
- $entity->update_option($this->license_key_k . '-last-checked', 0);
229
- $entity->update_option($this->license_key_k . '-invalid-count', 0);
230
-
231
- $this->send_mail('activate', $result, 'user');
232
- $this->set_license();
233
- } elseif ($result->error === 'no_activations_left') {
234
- $this->error = $this->__('ERROR') . ': ' . $this->__('License key activation limit reached.') . ' ' . sprintf('<a href="%s" target="_blank">%s</a>', 'https://wpfront.com/user-role-editor-pro/faq/#activation-limit', $this->__('More information'));
235
- } else {
236
- $this->error = $this->__('ERROR') . ': ' . $this->__('Invalid license key');
237
- }
238
- }
239
-
240
- private function deactivate_license($forced = FALSE) {
241
- if ($this->license_key_k === NULL)
242
- return;
243
-
244
- $entity = new WPFront_User_Role_Editor_Entity_Options();
245
- $this->license_key = $entity->get_option($this->license_key_k);
246
-
247
- if (empty($this->license_key))
248
- return;
249
-
250
- $result = $this->remote_get('deactivate_license', $this->license_key);
251
- if ($result === NULL)
252
- return;
253
-
254
- $result = $result[0];
255
-
256
- if ($result->license === 'deactivated' || $forced) {
257
- $entity->delete_option($this->license_key_k);
258
- $entity->delete_option($this->license_key_k . '-expires');
259
- $entity->delete_option($this->license_key_k . '-last-checked');
260
-
261
- if (!$forced) {
262
- $this->send_mail('deactivate', $result, 'user');
263
- }
264
- } else {
265
- $this->error = $this->__('ERROR') . ': ' . $this->__('Unable to deactivate');
266
- }
267
-
268
- $this->set_license();
269
- }
270
-
271
- private function recheck_license() {
272
- $entity = new WPFront_User_Role_Editor_Entity_Options();
273
- $entity->update_option($this->license_key_k . '-last-checked', 0);
274
- $this->plugin_updater->recheck();
275
- }
276
-
277
- private function remote_get($action, $license) {
278
- if ($this->product === NULL)
279
- return NULL;
280
-
281
- $url = home_url();
282
- $url = explode('?', $url);
283
- $url = $url[0];
284
-
285
- $api_params = array(
286
- 'edd_action' => $action,
287
- 'license' => urlencode($license),
288
- 'item_name' => urlencode($this->product),
289
- 'url' => urlencode($url),
290
- 'plugin_version' => WPFront_User_Role_Editor::VERSION
291
- );
292
-
293
- $response = WPFront_User_Role_Editor::wp_remote_get(self::$store_url, array('body' => $api_params));
294
- if (is_wp_error($response)) {
295
- $this->error = $this->__('ERROR') . ': ' . $this->__('Unable to contact wpfront.com')
296
- . '<br />'
297
- . $this->__('Details') . ': ' . $response->get_error_message();
298
- return NULL;
299
- }
300
-
301
- $result = json_decode(wp_remote_retrieve_body($response));
302
-
303
- if (!is_object($result)) {
304
- $this->error = $this->__('ERROR') . ': ' . $this->__('Unable to parse response');
305
- return NULL;
306
- }
307
-
308
- $api_params['license'] = urldecode($api_params['license']);
309
- $api_params['item_name'] = urldecode($api_params['item_name']);
310
- $api_params['url'] = urldecode($api_params['url']);
311
-
312
- return array($result, $api_params);
313
- }
314
-
315
- public function edd_plugin_update() {
316
- $entity = new WPFront_User_Role_Editor_Entity_Options();
317
-
318
- $this->plugin_updater = new WPFront_User_Role_Editor_Plugin_Updater(self::$store_url, WPFRONT_USER_ROLE_EDITOR_PLUGIN_FILE, array(
319
- 'version' => WPFront_User_Role_Editor::VERSION,
320
- 'license' => $entity->get_option($this->license_key_k),
321
- 'item_name' => $this->product,
322
- 'author' => 'Syam Mohan'
323
- ), $this->slug);
324
- }
325
-
326
- public function license_functions() {
327
- if (!wp_verify_nonce($_POST['_wpnonce'], $_POST['_wp_http_referer'])) {
328
- echo 'true';
329
- die();
330
- }
331
-
332
- if (!current_user_can('manage_options')) {
333
- echo 'true';
334
- die();
335
- }
336
-
337
- if (!empty($_POST['license_key']) && !empty($_POST['activate'])) {
338
- $this->activate_license($_POST['license_key']);
339
- }
340
-
341
- if (!empty($_POST['deactivate'])) {
342
- $this->deactivate_license();
343
- }
344
-
345
- if (!empty($_POST['recheck'])) {
346
- $this->recheck_license();
347
- }
348
-
349
- if ($this->error === NULL)
350
- echo 'true';
351
- else
352
- echo 'false';
353
- die();
354
- }
355
-
356
- public function has_license() {
357
- if ($this->need_license)
358
- return $this->has_license;
359
-
360
- return TRUE;
361
- }
362
-
363
- private function send_mail($action, $result, $source, $params = NULL) {
364
- $admin_email = get_site_option('admin_email');
365
- $blog_name = is_multisite() ? get_site_option('site_name') : get_option('blogname');
366
-
367
- if (function_exists('wp_get_current_user'))
368
- $current_user = wp_get_current_user();
369
-
370
- $to = array($admin_email);
371
- if (!empty($result) && !empty($result->customer_email) && $to[0] !== $result->customer_email) {
372
- $to[] = $result->customer_email;
373
- }
374
-
375
- $body = '<tr><td>' . $this->__('Site') . ':</td><td>' . get_site_option('siteurl') . '</td></tr>';
376
- $body .= '<tr><td>' . $this->__('Product') . ':</td><td>' . $this->__($this->product) . '</td></tr>';
377
-
378
- switch ($action) {
379
- case 'activate':
380
- $message = $this->__('Your WPFront User Role Editor Pro license was activated on the following site.');
381
- $subject = '[' . $blog_name . '] ' . $this->__('WPFront User Role Editor Pro License Activated');
382
- if ($source === 'user') {
383
- $body .= '<tr><td>' . $this->__('Activated By') . ':</td><td>' . $current_user->user_firstname . ' ' . $current_user->user_lastname . ' [' . $current_user->user_login . ']' . '</td></tr>';
384
- $body .= '<tr><td>' . $this->__('Activated On') . ':</td><td>' . gmdate("Y-m-d H:i:s") . ' GMT </td></tr>';
385
- }
386
- break;
387
- case 'deactivate':
388
- $message = $this->__('Your WPFront User Role Editor Pro license was deactivated on the following site.');
389
- $subject = '[' . $blog_name . '] ' . $this->__('WPFront User Role Editor Pro License Deactivated');
390
- if ($source === 'user') {
391
- $body .= '<tr><td>' . $this->__('Deactivated By') . ':</td><td>' . $current_user->user_firstname . ' ' . $current_user->user_lastname . ' [' . $current_user->user_login . ']' . '</td></tr>';
392
- $body .= '<tr><td>' . $this->__('Deactivated On') . ':</td><td>' . gmdate("Y-m-d H:i:s") . ' GMT </td></tr>';
393
- }
394
- break;
395
- case 'invalid':
396
- $message = $this->__('Your WPFront User Role Editor Pro license is invalid on the following site. Please activate a valid license immediately for the plugin to continue working.');
397
- $subject = '[' . $blog_name . '] ' . $this->__('WPFront User Role Editor Pro Invalid License');
398
- $body .= '<tr><td>' . $this->__('Invalid URL') . ':</td><td>' . $params['url'] . '</td></tr>';
399
- break;
400
- case 'deactivated':
401
- $message = $this->__('Your invalid WPFront User Role Editor Pro license was deactivated on the following site. Please activate a valid license immediately for the plugin to continue working.');
402
- $subject = '[' . $blog_name . '] ' . $this->__('WPFront User Role Editor Pro License Deactivated');
403
- $body .= '<tr><td>' . $this->__('Deactivated On') . ':</td><td>' . gmdate("Y-m-d H:i:s") . ' GMT </td></tr>';
404
- break;
405
- }
406
-
407
- $body = $message
408
- . '<br /><br />'
409
- . '<table>'
410
- . $body
411
- . '</table>';
412
-
413
- if (function_exists('wp_mail')) {
414
- wp_mail($to, $subject, $body, array('Content-Type: text/html; charset=UTF-8'));
415
- } else {
416
- $this->mail_objects[] = (OBJECT) array(
417
- 'to' => $to,
418
- 'subject' => $subject,
419
- 'body' => $body
420
- );
421
- }
422
- }
423
-
424
- public function plugins_loaded() {
425
- foreach ($this->mail_objects as $value) {
426
- wp_mail($value->to, $value->subject, $value->body, array('Content-Type: text/html; charset=UTF-8'));
427
- }
428
- }
429
-
430
- public function license_admin_notice() {
431
- $class = 'notice notice-error is-dismissible';
432
-
433
- if($this->license_status == 'invalid') {
434
- $message = sprintf($this->__('Your %s license is invalid.'), $this->product);
435
- printf( '<div class="%1$s"><p><strong>%2$s</strong></p></div>', $class, $message);
436
- } elseif($this->license_status == 'expired') {
437
- if(current_user_can('manage_options') || current_user_can('activate_plugins') || current_user_can('install_plugins')) {
438
- $renew = $this->__('Renew now');
439
- if(!empty($this->renew_url)) {
440
- $renew = sprintf('<a target="_blank" href="%s">%s</a>', $this->renew_url, $renew);
441
- }
442
- $message = sprintf($this->__('Your %s license is expired. %s to receive automatic updates.'), $this->product, $renew);
443
- printf( '<div class="%1$s"><p><strong>%2$s</strong></p></div>', $class, $message);
444
- }
445
- }
446
- }
447
- }
448
-
449
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-list.php DELETED
@@ -1,523 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-add-edit.php");
29
-
30
- if (!class_exists('WPFront_User_Role_Editor_List')) {
31
-
32
- /**
33
- * Lists Roles
34
- *
35
- * @author Syam Mohan <syam@wpfront.com>
36
- * @copyright 2014 WPFront.com
37
- */
38
- class WPFront_User_Role_Editor_List extends WPFront_User_Role_Editor_Controller_Base {
39
-
40
- const MENU_SLUG = 'wpfront-user-role-editor-all-roles';
41
-
42
- private $role_data = NULL;
43
- private $custom_columns = NULL;
44
-
45
- function __construct($main) {
46
- parent::__construct($main);
47
- }
48
-
49
- private function get_mode() {
50
- if (!empty($_GET['edit_role'])) {
51
- return array('EDIT', trim($_GET['edit_role']));
52
- }
53
-
54
- if (!empty($_GET['delete_role'])) {
55
- return array('DELETE', array(trim($_GET['delete_role'])));
56
- }
57
-
58
- if (!empty($_GET['set_default_role'])) {
59
- return array('DEFAULT_ROLE', $_GET['set_default_role']);
60
- }
61
-
62
- $action = '';
63
- if (!empty($_POST['doaction_top']) && !empty($_POST['action_top'])) {
64
- $action = $_POST['action_top'];
65
- } else if (!empty($_POST['doaction_bottom']) && !empty($_POST['action_bottom'])) {
66
- $action = $_POST['action_bottom'];
67
- }
68
-
69
- if ($action == 'delete') {
70
- if (!empty($_POST['selected-roles'])) {
71
- return array('DELETE', array_keys($_POST['selected-roles']));
72
- }
73
- }
74
-
75
- return array('LIST');
76
- }
77
-
78
- public function list_roles() {
79
- if (!$this->can_list())
80
- $this->main->permission_denied();
81
-
82
- $mode = $this->get_mode();
83
- switch ($mode[0]) {
84
- case 'EDIT':
85
- $obj = new WPFront_User_Role_Editor_Add_Edit($this->main);
86
- $obj->add_edit_role($mode[1]);
87
- return;
88
- case 'DELETE':
89
- $obj = new WPFront_User_Role_Editor_Delete($this->main);
90
- $obj->delete_role($mode[1]);
91
- return;
92
- case 'DEFAULT_ROLE':
93
- $this->set_default_role($mode[1]);
94
- printf('<script type="text/javascript">window.location.replace("%s");</script>', $this->list_url());
95
- return;
96
- }
97
-
98
- $obj = new WPFront_User_Role_Editor_Delete($this->main);
99
- if ($obj->is_pending_action()) {
100
- return;
101
- }
102
-
103
- include($this->main->pluginDIR() . 'templates/list-roles.php');
104
- }
105
-
106
- private function set_default_role($default_role) {
107
- if (empty($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], $this->list_url())) {
108
- $this->main->permission_denied();
109
- return;
110
- }
111
-
112
- if (!current_user_can('manage_options')) {
113
- $this->main->permission_denied();
114
- return;
115
- }
116
-
117
- update_option('default_role', $default_role);
118
- }
119
-
120
- private function get_roles() {
121
- if ($this->role_data != NULL)
122
- return $this->role_data;
123
-
124
- $this->role_data = array();
125
-
126
- global $wp_roles;
127
- $roles = $wp_roles->role_names;
128
- asort($roles, SORT_STRING);
129
-
130
- $editable_roles = get_editable_roles();
131
- if ($this->main->override_edit_permissions())
132
- $editable_roles = $wp_roles->get_names();
133
-
134
- $user_default = get_option('default_role');
135
-
136
- $count_users = count_users();
137
- $count_users = $count_users['avail_roles'];
138
-
139
- foreach ($roles as $key => $value) {
140
- $this->role_data[$key] = array(
141
- 'role_name' => $key,
142
- 'display_name' => $value,
143
- 'is_default' => in_array($key, WPFront_User_Role_Editor::$DEFAULT_ROLES),
144
- 'user_count' => isset($count_users[$key]) ? $count_users[$key] : 0, //count(get_users(array('role' => $key))),
145
- 'caps_count' => count(array_filter($wp_roles->roles[$key]['capabilities'])),
146
- 'user_default' => $key == $user_default
147
- );
148
-
149
- if ($this->can_edit()) {
150
- $this->role_data[$key]['edit_url'] = $this->edit_url() . $key;
151
-
152
- if ($key === self::ADMINISTRATOR_ROLE_KEY)
153
- $this->role_data[$key]['is_editable'] = FALSE;
154
- else {
155
- $this->role_data[$key]['is_editable'] = array_key_exists($key, $editable_roles);
156
- }
157
- }
158
-
159
- if ($this->can_delete()) {
160
- $this->role_data[$key]['delete_url'] = $this->delete_url() . $key;
161
-
162
- if ($key === self::ADMINISTRATOR_ROLE_KEY)
163
- $this->role_data[$key]['is_deletable'] = FALSE;
164
- else {
165
- $this->role_data[$key]['is_deletable'] = array_key_exists($key, $editable_roles);
166
- }
167
- }
168
-
169
- if ($key != $user_default && current_user_can('manage_options')) {
170
- $this->role_data[$key]['set_default_url'] = $this->set_default_url() . $key;
171
- }
172
- }
173
-
174
- switch ($this->get_current_list_filter()) {
175
- case 'all':
176
- break;
177
- case 'haveusers':
178
- foreach ($this->role_data as $key => $value) {
179
- if ($this->role_data[$key]['user_count'] == 0)
180
- unset($this->role_data[$key]);
181
- }
182
- break;
183
- case 'nousers':
184
- foreach ($this->role_data as $key => $value) {
185
- if (!$this->role_data[$key]['user_count'] == 0)
186
- unset($this->role_data[$key]);
187
- }
188
- break;
189
- case 'builtin':
190
- foreach ($this->role_data as $key => $value) {
191
- if (!$this->role_data[$key]['is_default'])
192
- unset($this->role_data[$key]);
193
- }
194
- break;
195
- case 'custom':
196
- foreach ($this->role_data as $key => $value) {
197
- if ($this->role_data[$key]['is_default'])
198
- unset($this->role_data[$key]);
199
- }
200
- break;
201
- }
202
-
203
- $search = $this->get_search_term();
204
- $search = strtolower(trim($search));
205
- if ($search !== '') {
206
- foreach ($this->role_data as $key => $value) {
207
- if (strpos(strtolower($value['display_name']), $search) === FALSE)
208
- unset($this->role_data[$key]);
209
- }
210
- }
211
-
212
- return $this->role_data;
213
- }
214
-
215
- private function table_header() {
216
- if ($this->custom_columns === NULL)
217
- $this->custom_columns = apply_filters('manage_roles_columns', array());
218
- ?>
219
- <tr>
220
- <th scope="col" id="cb" class="manage-column column-cb check-column">
221
- <label class="screen-reader-text" for="cb-select-all-1"><?php echo $this->__('Select All'); ?></label>
222
- <input id="cb-select-all-1" type="checkbox" />
223
- </th>
224
- <th scope="col" id="displayname" class="manage-column column-displayname">
225
- <a><span><?php echo $this->__('Display Name'); ?></span></a>
226
- </th>
227
- <th scope="col" id="rolename" class="manage-column column-rolename">
228
- <a><span><?php echo $this->__('Role Name'); ?></span></a>
229
- </th>
230
- <th scope="col" id="roletype" class="manage-column column-roletype">
231
- <a><span><?php echo $this->__('Type'); ?></span></a>
232
- </th>
233
- <th scope="col" id="userdefault" class="manage-column column-userdefault num">
234
- <a><span><?php echo $this->__('User Default'); ?></span></a>
235
- </th>
236
- <th scope="col" id="usercount" class="manage-column column-usercount num">
237
- <a><span><?php echo $this->__('Users'); ?></span></a>
238
- </th>
239
- <th scope="col" id="capscount" class="manage-column column-capscount num">
240
- <a><span><?php echo $this->__('Capabilities'); ?></span></a>
241
- </th>
242
- <?php
243
- foreach ($this->custom_columns as $key => $value) {
244
- echo "<th scope='col' id='$key' class='manage-column column-$key num'>"
245
- . "<a><span>$value</span></a>"
246
- . "</th>";
247
- }
248
- ?>
249
- </tr>
250
- <?php
251
- }
252
-
253
- private function bulk_actions($position) {
254
- ?>
255
- <div class="tablenav <?php echo $position; ?>">
256
- <div class="alignleft actions bulkactions">
257
- <select name="action_<?php echo $position; ?>">
258
- <option value="" selected="selected"><?php echo $this->__('Bulk Actions'); ?></option>
259
- <?php if ($this->can_delete()) { ?>
260
- <option value="delete"><?php echo $this->__('Delete'); ?></option>
261
- <?php } ?>
262
- </select>
263
- <input type="submit" name="doaction_<?php echo $position; ?>" class="button bulk action" value="<?php echo $this->__('Apply'); ?>">
264
- </div>
265
- <div class="tablenav-pages one-page"><span class="displaying-num"><?php echo sprintf($this->__('%s item(s)'), count($this->get_roles())); ?></span>
266
- <br class="clear">
267
- </div>
268
- </div>
269
- <?php
270
- }
271
-
272
- private function get_search_term() {
273
- if (empty($_POST['s']))
274
- return '';
275
-
276
- return esc_html($_POST['s']);
277
- }
278
-
279
- private function get_list_filters() {
280
- $filter_data = array();
281
-
282
- global $wp_roles;
283
- $role_data = $wp_roles->role_names;
284
-
285
- $page = admin_url('admin.php') . '?page=' . self::MENU_SLUG;
286
-
287
- $filter_data['all'] = array(
288
- 'display' => $this->__('All'),
289
- 'url' => $page,
290
- 'count' => count($role_data)
291
- );
292
-
293
- $count_users = count_users();
294
- $count_users = $count_users['avail_roles'];
295
-
296
- $count = 0;
297
- foreach ($role_data as $key => $value) {
298
- if(isset($count_users[$key]) && $count_users[$key] > 0) //if (count(get_users(array('role' => $key))) > 0)
299
- $count++;
300
- }
301
- $filter_data['haveusers'] = array(
302
- 'display' => $this->__('Having Users'),
303
- 'url' => $page . '&list=haveusers',
304
- 'count' => $count
305
- );
306
-
307
- $filter_data['nousers'] = array(
308
- 'display' => $this->__('No Users'),
309
- 'url' => $page . '&list=nousers',
310
- 'count' => count($role_data) - $count
311
- );
312
-
313
- $count = 0;
314
- foreach ($role_data as $key => $value) {
315
- if (in_array($key, WPFront_User_Role_Editor::$DEFAULT_ROLES))
316
- $count++;
317
- }
318
- $filter_data['builtin'] = array(
319
- 'display' => $this->__('Built-In'),
320
- 'url' => $page . '&list=builtin',
321
- 'count' => $count
322
- );
323
-
324
- $filter_data['custom'] = array(
325
- 'display' => $this->__('Custom'),
326
- 'url' => $page . '&list=custom',
327
- 'count' => count($role_data) - $count
328
- );
329
-
330
- return $filter_data;
331
- }
332
-
333
- private function get_current_list_filter() {
334
- if (empty($_GET['list']))
335
- return 'all';
336
-
337
- $list = $_GET['list'];
338
-
339
- switch ($list) {
340
- case 'all':
341
- case 'haveusers':
342
- case 'nousers':
343
- case 'builtin':
344
- case 'custom':
345
- break;
346
- default:
347
- $list = 'all';
348
- break;
349
- }
350
-
351
- return $list;
352
- }
353
-
354
- protected function add_help_tab() {
355
- $mode = $this->get_mode();
356
- switch ($mode[0]) {
357
- case 'EDIT':
358
- return array(
359
- array(
360
- 'id' => 'overview',
361
- 'title' => $this->__('Overview'),
362
- 'content' => '<p>'
363
- . $this->__('This screen allows you to edit a role within your site.')
364
- . '</p>'
365
- . '<p>'
366
- . $this->__('You can copy capabilities from existing roles using the Copy from drop down list. Select the role you want to copy from, then click Apply to copy the capabilities. You can select or deselect capabilities even after you copy.')
367
- . '</p>'
368
- ),
369
- array(
370
- 'id' => 'displayname',
371
- 'title' => $this->__('Display Name'),
372
- 'content' => '<p>'
373
- . $this->__('Use the Display Name field to edit display name of the role. WordPress uses display name to display this role within your site. This field is required.')
374
- . '</p>'
375
- ),
376
- array(
377
- 'id' => 'rolename',
378
- 'title' => $this->__('Role Name'),
379
- 'content' => '<p>'
380
- . $this->__('Role Name is read only. WordPress uses role name to identify this role within your site.')
381
- . '</p>'
382
- ),
383
- array(
384
- 'id' => 'capabilities',
385
- 'title' => $this->__('Capabilities'),
386
- 'content' => '<p>'
387
- . $this->__('Capabilities are displayed as different groups for easy access. The Roles section displays capabilities created by this plugin. The Other Capabilities section displays non-standard capabilities within your site. These are usually created by plugins and themes. Use the check boxes to select the capabilities required.')
388
- . '</p>'
389
- )
390
- );
391
- case 'DELETE':
392
- return array(
393
- array(
394
- 'id' => 'overview',
395
- 'title' => $this->__('Overview'),
396
- 'content' => '<p>'
397
- . $this->__('This screen allows you to delete roles from your WordPress site.')
398
- . '</p>'
399
- . '<p>'
400
- . $this->__('Use the Roles List screen to select the roles you want to delete. You can delete individual roles using the Delete row action link or delete multiple roles at the same time using the bulk action.')
401
- . '</p>'
402
- . '<p>'
403
- . $this->__('You cannot delete administrator role, current user’s role and roles you do not have permission to.')
404
- . '</p>'
405
- )
406
- );
407
- }
408
-
409
- return array(
410
- array(
411
- 'id' => 'overview',
412
- 'title' => $this->__('Overview'),
413
- 'content' => '<p>'
414
- . $this->__('This screen lists all the existing roles within your site.')
415
- . '</p>'
416
- . '<p>'
417
- . $this->__('To add a new role, click the Add New button at the top of the screen or Add New in the Roles menu section.')
418
- . '</p>'
419
- ),
420
- array(
421
- 'id' => 'columns',
422
- 'title' => $this->__('Columns'),
423
- 'content' => '<p><strong>'
424
- . $this->__('Display Name')
425
- . '</strong>: '
426
- . $this->__('Used to display this role within this site.')
427
- . '</p>'
428
- . '<p><strong>'
429
- . $this->__('Role Name')
430
- . '</strong>: '
431
- . $this->__('Is used by WordPress to identify this role.')
432
- . '</p>'
433
- . '<p><strong>'
434
- . $this->__('Type')
435
- . '</strong>: '
436
- . $this->__('Says whether the role is a WordPress built-in role or not. There are five built-in roles.')
437
- . '</p>'
438
- . '<p><strong>'
439
- . $this->__('User Default')
440
- . '</strong>: '
441
- . $this->__('Displays whether a role is the default role of a new user.')
442
- . '</p>'
443
- . '<p><strong>'
444
- . $this->__('Users')
445
- . '</strong>: '
446
- . $this->__('Number of users in that role.')
447
- . '</p>'
448
- . '<p><strong>'
449
- . $this->__('Capabilities')
450
- . '</strong>: '
451
- . $this->__('Number of capabilities that role have.')
452
- . '</p>'
453
- . '<p><strong>'
454
- . $this->__('Menu Edited')
455
- . '</strong>: '
456
- . $this->__('Displays whether the menu has been edited for this role. This is a pro feature.')
457
- . '</p>'
458
- ),
459
- array(
460
- 'id' => 'actions',
461
- 'title' => $this->__('Actions'),
462
- 'content' => '<p>'
463
- . $this->__('Hovering over a row in the roles list will display action links that allow you to manage roles. You can perform the following actions:')
464
- . '</p>'
465
- . '<p><strong>'
466
- . $this->__('View')
467
- . '</strong>: '
468
- . $this->__('Display details about the role. You can see the capabilities assigned for that role. View link will only appear when you do not have permission to edit that role.')
469
- . '</p>'
470
- . '<p><strong>'
471
- . $this->__('Edit')
472
- . '</strong>: '
473
- . $this->__('Allows you to edit that role. You can see the capabilities assigned for that role and also edit them. Edit link will only appear when you have permission to edit that role.')
474
- . '</p>'
475
- . '<p><strong>'
476
- . $this->__('Delete')
477
- . '</strong>: '
478
- . $this->__('Allows you to delete that role. Delete action will not appear if you do not have permission to delete that role.')
479
- . '</p>'
480
- . '<p><strong>'
481
- . $this->__('Default')
482
- . '</strong>: '
483
- . $this->__('Allows you to set that role as the default role for new user registration.')
484
- . '</p>'
485
- . '<p><strong>'
486
- . $this->__('Edit Menu')
487
- . '</strong>: '
488
- . $this->__('Takes you to the menu editor screen for that role. You need "edit_role_menus" capability for this link to appear. This is a pro feature.')
489
- . '</p>'
490
- )
491
- );
492
- }
493
-
494
- protected function set_help_sidebar() {
495
- $mode = $this->get_mode();
496
- switch ($mode[0]) {
497
- case 'EDIT':
498
- return array(
499
- array(
500
- $this->__('Documentation on Edit Role'),
501
- 'edit-role/'
502
- )
503
- );
504
- case 'DELETE':
505
- return array(
506
- array(
507
- $this->__('Documentation on Delete Roles'),
508
- 'delete-role/'
509
- )
510
- );
511
- }
512
-
513
- return array(
514
- array(
515
- $this->__('Documentation on Roles'),
516
- 'list-roles/'
517
- )
518
- );
519
- }
520
-
521
- }
522
-
523
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-login-redirect-list-table.php DELETED
@@ -1,189 +0,0 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit();
4
- }
5
-
6
- if (!class_exists('WP_List_Table')) {
7
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
8
- }
9
-
10
- if (!class_exists('WPFront_User_Role_Editor_Login_Redirect_List_Table')) {
11
-
12
- /**
13
- * Login Redirect List Table
14
- *
15
- * @author Syam Mohan <syam@wpfront.com>
16
- * @copyright 2015 WPFront.com
17
- */
18
- class WPFront_User_Role_Editor_Login_Redirect_List_Table extends WP_List_Table {
19
-
20
- private $main;
21
-
22
- public function __construct($main) {
23
- parent::__construct(array('screen' => 'login-redirect'));
24
- $this->main = $main;
25
- }
26
-
27
- function ajax_user_can() {
28
- return $this->main->can_edit_login_redirect();
29
- }
30
-
31
- function prepare_items() {
32
- $search = NULL;
33
- if (function_exists('wp_unslash'))
34
- $search = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
35
- else
36
- $search = isset($_REQUEST['s']) ? trim($_REQUEST['s']) : '';
37
-
38
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
39
-
40
- $per_page = PHP_INT_MAX;
41
- $count = $entity->count($search);
42
-
43
- $page = isset($_GET['paged']) ? $_GET['paged'] : '1';
44
- $page = (int) $page;
45
- if ($page <= 0)
46
- $page = 1;
47
-
48
- if ($page > ceil($count / $per_page))
49
- $page = ceil($count / $per_page);
50
-
51
- $this->items = $entity->get_all_login_redirect($search);
52
-
53
- $this->set_pagination_args(array(
54
- 'total_items' => $count,
55
- 'per_page' => $per_page,
56
- ));
57
- }
58
-
59
- function get_bulk_actions() {
60
- $actions = array();
61
- if ($this->main->can_delete_login_redirect())
62
- $actions['delete'] = $this->main->__('Delete');
63
-
64
- return $actions;
65
- }
66
-
67
- function no_items() {
68
- echo $this->main->__('No login redirects found.');
69
- }
70
-
71
- function get_views() {
72
- $role_links = array();
73
-
74
- return $role_links;
75
- }
76
-
77
- function pagination($which) {
78
- parent::pagination($which);
79
- }
80
-
81
- function get_columns() {
82
- $columns = array(
83
- 'cb' => '<input type="checkbox" />',
84
- 'role' => $this->main->__('Role'),
85
- 'priority' => $this->main->__('Priority'),
86
- 'url' => $this->main->__('Login Redirect URL'),
87
- 'logout_url' => $this->main->__('Logout Redirect URL'),
88
- 'deny_wpadmin' => $this->main->__('WP-ADMIN'),
89
- 'disable_toolbar' => $this->main->__('Toolbar')
90
- );
91
-
92
- return $columns;
93
- }
94
-
95
- function get_sortable_columns() {
96
- return array(
97
- );
98
- }
99
-
100
- function display_rows() {
101
- $alt = '';
102
-
103
- foreach ($this->items as $entity) {
104
- $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
105
- ?>
106
- <tr class="<?php echo $alt; ?>">
107
- <?php
108
- list( $columns, $hidden ) = $this->get_column_info();
109
-
110
- foreach ($columns as $column_name => $column_display_name) :
111
- $class = "class='$column_name column-$column_name'";
112
-
113
- $style = '';
114
- if (in_array($column_name, $hidden))
115
- $style = ' style="display:none;"';
116
-
117
- $attributes = "$class$style";
118
-
119
- switch ($column_name) {
120
- case 'cb':
121
- ?>
122
- <th scope="row" class="check-column">
123
- <label class="screen-reader-text" for="role_<?php echo $entity->get_role(); ?>"><?php echo sprintf($this->main->__('Select %s'), $entity->get_role()); ?></label>
124
- <input type="checkbox" id="code_<?php echo $entity->get_role(); ?>" name="role[]" value="<?php echo esc_attr($entity->get_role()); ?>" />
125
- </th>
126
- <?php
127
- break;
128
-
129
- case 'role':
130
- $role = $this->main->get_role_display_name($entity->get_role());
131
- echo "<td $attributes>";
132
- $edit_link = $this->main->login_redirect_edit_url($entity->get_role());
133
- if ($this->main->can_edit_login_redirect()) {
134
- ?>
135
- <strong>
136
- <a href="<?php echo $edit_link; ?>" class="edit">
137
- <?php echo $role; ?>
138
- </a>
139
- </strong>
140
- <?php
141
- } else {
142
- echo $role;
143
- }
144
- ?>
145
- <br/>
146
- <?php
147
- $actions = array();
148
- if ($this->main->can_edit_login_redirect()) {
149
- $actions['edit'] = '<a href="' . $edit_link . '">' . $this->main->__('Edit') . '</a>';
150
- }
151
- if ($this->main->can_delete_login_redirect()) {
152
- $actions['delete'] = '<a href="' . $this->main->login_redirect_delete_url($entity->get_role()) . '">' . $this->main->__('Delete') . '</a>';
153
- }
154
- echo $this->row_actions($actions);
155
- ?>
156
- </td>
157
- <?php
158
- break;
159
-
160
- case 'priority':
161
- echo "<td $attributes>" . $entity->get_priority() . "</td>";
162
- break;
163
-
164
- case 'url':
165
- echo "<td $attributes>" . $this->main->format_url($entity->get_url()) . "</td>";
166
- break;
167
-
168
- case 'logout_url':
169
- echo "<td $attributes>" . $this->main->format_url($entity->get_logout_url()) . "</td>";
170
- break;
171
-
172
- case 'deny_wpadmin':
173
- echo "<td $attributes>" . ($entity->get_deny_wpadmin() ? '<i class="fa fa-times"></i>' : '<i class="fa fa-check"></i>') . "</td>";
174
- break;
175
-
176
- case 'disable_toolbar':
177
- echo "<td $attributes>" . ($entity->get_disable_toolbar() ? '<i class="fa fa-times"></i>' : '<i class="fa fa-check"></i>') . "</td>";
178
- break;
179
- }
180
- endforeach
181
- ?>
182
- </tr>
183
- <?php
184
- }
185
- }
186
-
187
- }
188
-
189
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-login-redirect.php DELETED
@@ -1,542 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- require_once(plugin_dir_path(__FILE__) . "entities/class-wpfront-user-role-editor-entity-login-redirect.php");
30
-
31
- if (!class_exists('WPFront_User_Role_Editor_Login_Redirect')) {
32
-
33
- /**
34
- * Login Redirect Controller
35
- *
36
- * @author Syam Mohan <syam@wpfront.com>
37
- * @copyright 2015 WPFront.com
38
- */
39
- class WPFront_User_Role_Editor_Login_Redirect extends WPFront_User_Role_Editor_Controller_Base {
40
-
41
- const MENU_SLUG = 'wpfront-user-role-editor-login-redirect';
42
-
43
- private $MODE = NULL;
44
- private $role = '';
45
- private $priority = '';
46
- private $url = '';
47
- private $logout_url = '';
48
- private $deny_wpadmin = FALSE;
49
- private $disable_toolbar = FALSE;
50
- private $valid_role = TRUE;
51
- private $valid_priority = TRUE;
52
- private $valid_url = TRUE;
53
- private $success_message = NULL;
54
- private $error_message = NULL;
55
-
56
- public function __construct($main) {
57
- parent::__construct($main);
58
-
59
- add_filter('login_redirect', array($this, 'login_redirect_callback'), 99999, 3);
60
- add_filter('logout_redirect', array($this, 'logout_redirect_callback'), 99999, 3);
61
- add_action('admin_init', array($this, 'admin_init'));
62
- add_filter('show_admin_bar', array($this, 'show_toolbar'), 10, 1);
63
- }
64
-
65
- public function login_redirect_callback($redirect_to, $request_from = '', $obj_user = NULL) {
66
- if (empty($obj_user) || is_wp_error($obj_user)) {
67
- $obj_user = wp_get_current_user();
68
- }
69
-
70
- if (empty($obj_user) || is_wp_error($obj_user)) {
71
- return $redirect_to;
72
- }
73
-
74
- if (empty($obj_user->roles) || !is_array($obj_user->roles))
75
- return $redirect_to;
76
-
77
- $roles = $obj_user->roles;
78
- if (in_array(self::ADMINISTRATOR_ROLE_KEY, $roles))
79
- return $redirect_to;
80
-
81
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
82
- $data = $entity->get_all_login_redirect();
83
-
84
- foreach ($data as $value) {
85
- $role = $value->get_role();
86
- if (!$this->role_supported($role))
87
- continue;
88
-
89
- if (in_array($role, $roles))
90
- return $this->format_url($value->get_url());
91
- }
92
-
93
- return $redirect_to;
94
- }
95
-
96
- public function logout_redirect_callback($redirect_to, $request_from = '', $obj_user = NULL) {
97
- if (empty($obj_user) || is_wp_error($obj_user)) {
98
- $obj_user = wp_get_current_user();
99
- }
100
-
101
- if (empty($obj_user) || is_wp_error($obj_user)) {
102
- return $redirect_to;
103
- }
104
-
105
- if (empty($obj_user->roles) || !is_array($obj_user->roles))
106
- return $redirect_to;
107
-
108
- $roles = $obj_user->roles;
109
- if (in_array(self::ADMINISTRATOR_ROLE_KEY, $roles))
110
- return $redirect_to;
111
-
112
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
113
- $data = $entity->get_all_login_redirect();
114
-
115
- foreach ($data as $value) {
116
- $role = $value->get_role();
117
- if (!$this->role_supported($role))
118
- continue;
119
-
120
- if (in_array($role, $roles)) {
121
- $url = $this->format_url($value->get_logout_url());
122
- if(!empty($url))
123
- return $url;
124
- }
125
- }
126
-
127
- return $redirect_to;
128
- }
129
-
130
- public function admin_init() {
131
- if (defined('DOING_AJAX') && DOING_AJAX) {
132
- return;
133
- }
134
-
135
- if (!empty($_SERVER['PHP_SELF']) && $_SERVER['PHP_SELF'] === '/wp-admin/admin-ajax.php') {
136
- return;
137
- }
138
-
139
- if (!empty($_SERVER['DOING_AJAX']) && $_SERVER['DOING_AJAX'] === '/wp-admin/admin-ajax.php') {
140
- return;
141
- }
142
-
143
- $obj_user = wp_get_current_user();
144
- if (empty($obj_user) || is_wp_error($obj_user)) {
145
- return;
146
- }
147
-
148
- if (empty($obj_user->roles) || !is_array($obj_user->roles))
149
- return;
150
-
151
- $roles = $obj_user->roles;
152
- if (in_array(self::ADMINISTRATOR_ROLE_KEY, $roles))
153
- return;
154
-
155
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
156
- $data = $entity->get_all_login_redirect();
157
-
158
- foreach ($data as $value) {
159
- $role = $value->get_role();
160
- if (!$this->role_supported($role))
161
- continue;
162
-
163
- if (in_array($role, $roles)) {
164
- if ($value->get_deny_wpadmin()) {
165
- wp_redirect($this->format_url($value->get_url()));
166
- }
167
-
168
- return;
169
- }
170
- }
171
- }
172
-
173
- public function show_toolbar($show) {
174
- $obj_user = wp_get_current_user();
175
- if (empty($obj_user) || is_wp_error($obj_user)) {
176
- return $show;
177
- }
178
-
179
- if (empty($obj_user->roles) || !is_array($obj_user->roles))
180
- return $show;
181
-
182
- $roles = $obj_user->roles;
183
- if (in_array(self::ADMINISTRATOR_ROLE_KEY, $roles))
184
- return $show;
185
-
186
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
187
- $data = $entity->get_all_login_redirect();
188
-
189
- foreach ($data as $value) {
190
- $role = $value->get_role();
191
- if (!$this->role_supported($role))
192
- continue;
193
-
194
- if (in_array($role, $roles)) {
195
- if ($value->get_disable_toolbar()) {
196
- return FALSE;
197
- }
198
-
199
- return $show;
200
- }
201
- }
202
-
203
- return $show;
204
- }
205
-
206
- public function login_redirect() {
207
- $this->main->verify_nonce('_login_redirect');
208
-
209
- if (!$this->can_edit_login_redirect()) {
210
- $this->main->permission_denied();
211
- return;
212
- }
213
-
214
- if ($this->get_mode() === 'DELETE' || $this->get_mode() === 'CONFIRM-DELETE') {
215
- if (!$this->can_delete_login_redirect()) {
216
- $this->main->permission_denied();
217
- return;
218
- }
219
- }
220
-
221
- if ($this->get_mode() === 'CONFIRM-DELETE') {
222
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
223
- foreach ($this->role as $value) {
224
- $entity = $entity->get_by_role($value);
225
- $entity->delete();
226
- }
227
-
228
- $this->MODE = 'LIST';
229
- }
230
-
231
- if ($this->get_mode() === 'ADD') {
232
- $this->priority = $this->get_next_priority();
233
- }
234
-
235
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && $this->validate()) {
236
- switch ($this->get_mode()) {
237
- case 'ADD':
238
- case 'EDIT':
239
- if ($this->role_supported($this->role)) {
240
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
241
- $entity->set_role($this->role);
242
- if ($this->get_mode() === 'EDIT') {
243
- $entity = $entity->get_by_role($this->role);
244
- }
245
- $entity->set_priority($this->priority);
246
- $entity->set_url($this->url);
247
- $entity->set_logout_url($this->logout_url);
248
- $entity->set_deny_wpadmin($this->deny_wpadmin);
249
- $entity->set_disable_toolbar($this->disable_toolbar);
250
- $entity->save();
251
-
252
- if ($this->get_mode() === 'ADD') {
253
- $this->success_message = $this->__('Login redirect added.');
254
- $this->MODE = 'EDIT';
255
- } else {
256
- $this->success_message = $this->__('Login redirect updated.');
257
- }
258
- } else {
259
- $this->error_message = $this->__('This role is not supported.');
260
- }
261
- break;
262
-
263
- default:
264
- break;
265
- }
266
- }
267
-
268
- if ($this->get_mode() === 'EDIT') {
269
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
270
- $entity = $entity->get_by_role($this->role);
271
-
272
- $this->priority = $entity->get_priority();
273
- $this->url = $entity->get_url();
274
- $this->logout_url = $entity->get_logout_url();
275
- $this->deny_wpadmin = $entity->get_deny_wpadmin();
276
- $this->disable_toolbar = $entity->get_disable_toolbar();
277
- }
278
-
279
- include($this->main->pluginDIR() . 'templates/login-redirect.php');
280
- }
281
-
282
- private function validate() {
283
- $valid = TRUE;
284
-
285
- switch ($this->get_mode()) {
286
- case 'ADD':
287
- case 'EDIT':
288
- if (empty($_POST['role'])) {
289
- $this->valid_role = FALSE;
290
- $valid = FALSE;
291
- } else {
292
- $this->role = $_POST['role'];
293
- }
294
-
295
- if (empty($_POST['priority'])) {
296
- $this->valid_priority = FALSE;
297
- $valid = FALSE;
298
- } else {
299
- $this->priority = intval($_POST['priority']);
300
- if ($this->priority <= 0) {
301
- $this->priority = '';
302
- $this->valid_priority = FALSE;
303
- $valid = FALSE;
304
- }
305
- }
306
-
307
- if (empty($_POST['url'])) {
308
- $this->valid_url = FALSE;
309
- $valid = FALSE;
310
- } else {
311
- $this->url = $_POST['url'];
312
- }
313
-
314
- if (!empty($_POST['logout_url']))
315
- $this->logout_url = $_POST['logout_url'];
316
-
317
- if (!empty($_POST['deny_wpadmin']))
318
- $this->deny_wpadmin = TRUE;
319
-
320
- if (!empty($_POST['disable_toolbar']))
321
- $this->disable_toolbar = TRUE;
322
- break;
323
- }
324
-
325
- return $valid;
326
- }
327
-
328
- private function get_mode() {
329
- if (empty($this->MODE)) {
330
- if (!empty($_POST['mode'])) {
331
- $this->MODE = $_POST['mode'];
332
- if ($this->MODE === 'BULK-DELETE') {
333
- $this->MODE = NULL;
334
- if ($_POST['action'] === 'delete' || $_POST['action2'] === 'delete') {
335
- if (!empty($_POST['role'])) {
336
- $this->MODE = 'DELETE';
337
- $this->role = $_POST['role'];
338
- }
339
- }
340
- } else {
341
- $this->role = $_POST['role'];
342
- }
343
- } elseif (!empty($_GET['mode'])) {
344
- switch ($_GET['mode']) {
345
- case 'add-new':
346
- $this->MODE = 'ADD';
347
- break;
348
-
349
- case 'edit':
350
- $this->MODE = 'EDIT';
351
- $this->role = $_GET['role'];
352
- break;
353
-
354
- case 'delete':
355
- $this->MODE = 'DELETE';
356
- $this->role = array($_GET['role']);
357
- break;
358
- }
359
- }
360
-
361
- if (empty($this->MODE))
362
- $this->MODE = 'LIST';
363
- }
364
-
365
- return $this->MODE;
366
- }
367
-
368
- private function get_roles() {
369
- global $wp_roles;
370
- $roles = $wp_roles->get_names();
371
- unset($roles[self::ADMINISTRATOR_ROLE_KEY]);
372
-
373
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
374
- $data = $entity->get_all_login_redirect();
375
- foreach ($data as $value) {
376
- if (isset($roles[$value->get_role()])) {
377
- unset($roles[$value->get_role()]);
378
- }
379
- }
380
-
381
- return $roles;
382
- }
383
-
384
- protected function role_supported($role, $extend = FALSE) {
385
- if ($role === self::ADMINISTRATOR_ROLE_KEY)
386
- return FALSE;
387
-
388
- global $wp_roles;
389
- $roles = $wp_roles->get_names();
390
- if (!isset($roles[$role]))
391
- return FALSE;
392
-
393
- if ($extend || in_array($role, WPFront_User_Role_Editor::$DEFAULT_ROLES))
394
- return TRUE;
395
-
396
- return FALSE;
397
- }
398
-
399
- public function login_redirect_add_new_url() {
400
- return parent::login_redirect_url() . '&mode=add-new';
401
- }
402
-
403
- public function login_redirect_edit_url($role) {
404
- return parent::login_redirect_url() . '&mode=edit&role=' . $role;
405
- }
406
-
407
- public function login_redirect_delete_url($role) {
408
- return parent::login_redirect_url() . '&mode=delete&role=' . $role;
409
- }
410
-
411
- public function can_edit_login_redirect() {
412
- return current_user_can('edit_login_redirects');
413
- }
414
-
415
- public function can_delete_login_redirect() {
416
- return current_user_can('delete_login_redirects');
417
- }
418
-
419
- public function get_role_display_name($role) {
420
- global $wp_roles;
421
- $roles = $wp_roles->get_names();
422
-
423
- if (isset($roles[$role]))
424
- return $roles[$role];
425
-
426
- return $role;
427
- }
428
-
429
- public function format_url($url) {
430
- if(empty($url))
431
- return '';
432
-
433
- $url = strtolower($url);
434
-
435
- if (strpos($url, '://') > -1)
436
- return $url;
437
-
438
- return home_url($url);
439
- }
440
-
441
- private function get_next_priority() {
442
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
443
- return $entity->get_next_priority();
444
- }
445
-
446
- protected function add_help_tab() {
447
- if ($this->get_mode() === 'LIST' || $this->get_mode() === 'CONFIRM-DELETE') {
448
- return array(
449
- array(
450
- 'id' => 'overview',
451
- 'title' => $this->__('Overview'),
452
- 'content' => '<p>'
453
- . $this->__('Use this functionality to redirect a user to a specific page after they login based on their role.')
454
- . '</p>'
455
- . '<p>'
456
- . $this->__('In addition, you can also deny the user access to WP-ADMIN and remove the toolbar (admin bar) from the front end.')
457
- . '</p>'
458
- ),
459
- array(
460
- 'id' => 'columns',
461
- 'title' => $this->__('Columns'),
462
- 'content' => '<p>'
463
- . $this->__('<b>Role</b>: The role of the user to qualify for this redirect.')
464
- . '</p>'
465
- . '<p>'
466
- . $this->__('<b>Priority</b>: When a user has multiple roles, the role configuration with the highest priority will be selected.')
467
- . '</p>'
468
- . '<p>'
469
- . $this->__('<b>Login Redirect URL</b>: The URL where the user will be redirected after login or on WP-ADMIN access if denied.')
470
- . '</p>'
471
- . '<p>'
472
- . $this->__('<b>Logout Redirect URL</b>: The URL where the user will be redirected after logout.')
473
- . '</p>'
474
- . '<p>'
475
- . $this->__('<b>WP-ADMIN</b>: Displays whether user has access to WP-ADMIN.')
476
- . '</p>'
477
- . '<p>'
478
- . $this->__('<b>Toolbar</b>: Displays whether user will see toolbar on front end.')
479
- . '</p>'
480
- )
481
- );
482
- }
483
-
484
- if ($this->get_mode() === 'ADD' || $this->get_mode() === 'EDIT') {
485
- return array(
486
- array(
487
- 'id' => 'overview',
488
- 'title' => $this->__('Overview'),
489
- 'content' => '<p>'
490
- . $this->__('Add/Edit a new login redirect.')
491
- . '</p>'
492
- ),
493
- array(
494
- 'id' => 'fields',
495
- 'title' => $this->__('Fields'),
496
- 'content' => '<p>'
497
- . $this->__('<b>Role</b>: The role of the user to qualify for this redirect.')
498
- . '</p>'
499
- . '<p>'
500
- . $this->__('<b>Priority</b>: When a user has multiple roles, the role configuration with the highest priority will be selected.')
501
- . '</p>'
502
- . '<p>'
503
- . $this->__('<b>Login Redirect URL</b>: The URL where the user will be redirected after login or on WP-ADMIN access if denied.')
504
- . '</p>'
505
- . '<p>'
506
- . $this->__('<b>Logout Redirect URL</b>: The URL where the user will be redirected after logout.')
507
- . '</p>'
508
- . '<p>'
509
- . $this->__('<b>Deny WP-ADMIN</b>: If enabled user will be redirected to URL on WP-ADMIN access.')
510
- . '</p>'
511
- . '<p>'
512
- . $this->__('<b>Disable Toolbar</b>: If enabled user will not see toolbar on front end.')
513
- . '</p>'
514
- )
515
- );
516
- }
517
-
518
- if ($this->get_mode() === 'DELETE') {
519
- return array(
520
- array(
521
- 'id' => 'overview',
522
- 'title' => $this->__('Overview'),
523
- 'content' => '<p>'
524
- . $this->__('Click "Confirm Delete" to delete displayed configurations.')
525
- . '</p>'
526
- )
527
- );
528
- }
529
- }
530
-
531
- protected function set_help_sidebar() {
532
- return array(
533
- array(
534
- $this->__('Documentation on Login Redirect'),
535
- 'login-redirect/'
536
- )
537
- );
538
- }
539
-
540
- }
541
-
542
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-nav-menu.php DELETED
@@ -1,269 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- require_once plugin_dir_path(__FILE__) . 'class-wpfront-user-role-editor-nav-menu-walker.php';
29
-
30
- if (!class_exists('WPFront_User_Role_Editor_Nav_Menu')) {
31
-
32
- /**
33
- * Navigation Menu Controller
34
- *
35
- * @author Syam Mohan <syam@wpfront.com>
36
- * @copyright 2015 WPFront.com
37
- */
38
- class WPFront_User_Role_Editor_Nav_Menu extends WPFront_User_Role_Editor_Controller_Base {
39
-
40
- protected static $ALL_USERS = 1;
41
- protected static $LOGGEDIN_USERS = 2;
42
- protected static $GUEST_USERS = 3;
43
- protected static $ROLE_USERS = 4;
44
- protected static $META_DATA_KEY = 'wpfront-user-role-editor-nav-menu-data';
45
-
46
- public function __construct($main) {
47
- parent::__construct($main);
48
-
49
- if ($this->main->disable_navigation_menu_permissions())
50
- return;
51
-
52
- add_action('init', array($this, 'wp_init'), 9999);
53
- add_action('wp_nav_menu_item_custom_fields', array($this, 'menu_item_custom_fields'), 10, 4);
54
- add_action('wp_nav_menu_item_title_user_restriction_type', array($this, 'menu_item_title_user_restriction_type'), 10, 4);
55
- add_action('wp_nav_menu_item_custom_fields_roles_list', array($this, 'menu_item_custom_fields_roles_list'), 10, 4);
56
-
57
- add_action('wp_update_nav_menu_item', array($this, 'update_nav_menu_item'), 10, 3);
58
- add_filter('wp_get_nav_menu_items', array($this, 'override_nav_menu_items'), 10, 3);
59
-
60
- add_action('admin_print_scripts-nav-menus.php', array($this, 'enqueue_menu_scripts'));
61
- add_action('admin_print_styles-nav-menus.php', array($this, 'enqueue_menu_styles'));
62
- add_action('load-nav-menus.php', array($this, 'menu_walker_override_notice_action'));
63
- }
64
-
65
- public function nav_menu_help_url() {
66
- return 'https://wpfront.com/user-role-editor-pro/navigation-menu-permissions/';
67
- }
68
-
69
- public function wp_init() {
70
- add_filter('wp_edit_nav_menu_walker', array($this, 'override_edit_nav_menu_walker'), 999999);
71
- }
72
-
73
- public function menu_walker_override_notice_action() {
74
- add_action('admin_notices', array($this, 'menu_walker_override_warning'));
75
- }
76
-
77
- public function override_edit_nav_menu_walker($current = 'Walker_Nav_Menu_Edit') {
78
- if ($current !== 'Walker_Nav_Menu_Edit' && !$this->main->override_navigation_menu_permissions())
79
- return $current;
80
-
81
- return 'WPFront_User_Role_Editor_Nav_Menu_Walker';
82
- }
83
-
84
- public function menu_walker_override_warning() {
85
- if ($this->main->disable_navigation_menu_permissions() === FALSE) {
86
- $menu_walker = apply_filters('wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', 0);
87
- if ($menu_walker !== $this->override_edit_nav_menu_walker()) {
88
- printf(
89
- '<div class="notice notice-error is-dismissible"><p>%s</p></div>',
90
- sprintf(
91
- $this->__('Menu walker class is overriden by a theme/plugin. Current value = %s. Navigation menu permissions may still work. %s'),
92
- $menu_walker,
93
- '<a target="_blank" href="' . $this->nav_menu_help_url() . '#navigation-menu-permission-warning">' . $this->__('More information') . '</a>'
94
- )
95
- );
96
-
97
- }
98
- }
99
- }
100
-
101
- public function menu_item_title_user_restriction_type($item_id, $item, $depth, $args) {
102
- if (!current_user_can('edit_nav_menu_permissions'))
103
- return;
104
-
105
- $data = $this->get_meta_data($item_id);
106
- $text = $this->__('All Users');
107
-
108
- switch ($data->type) {
109
- case self::$LOGGEDIN_USERS:
110
- $text = $this->__('Logged in Users');
111
- break;
112
- case self::$GUEST_USERS:
113
- $text = $this->__('Guest Users');
114
- break;
115
- case self::$ROLE_USERS:
116
- $text = $this->__('Users by Role');
117
- break;
118
- }
119
- ?>
120
- <span class="is-submenu">
121
- <?php echo '(' . $text . ')'; ?>
122
- </span>
123
- <?php
124
- }
125
-
126
- public function menu_item_custom_fields_roles_list($item_id, $item, $depth, $args) {
127
- printf($this->__('%s to limit based on roles.'), '<a target="_blank" href="https://wpfront.com/navmenu">' . $this->__('Upgrade to Pro') . '</a>');
128
- }
129
-
130
- public function menu_item_custom_fields($item_id, $item, $depth, $args) {
131
- if (!current_user_can('edit_nav_menu_permissions'))
132
- return;
133
-
134
- $data = $this->get_meta_data($item_id);
135
- $this->main->create_nonce($item_id);
136
- ?>
137
- <p class="description description-wide"></p>
138
- <p class="description description-wide">
139
- <label><?php echo $this->__('User Restrictions'); ?></label>
140
- <span class="user-restriction-container">
141
- <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$ALL_USERS; ?>" <?php echo $data->type === self::$ALL_USERS ? 'checked' : ''; ?> /><?php echo $this->__('All Users'); ?></label>
142
- <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$LOGGEDIN_USERS; ?>" <?php echo $data->type === self::$LOGGEDIN_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Logged in Users'); ?></label>
143
- <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$GUEST_USERS; ?>" <?php echo $data->type === self::$GUEST_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Guest Users'); ?></label>
144
- <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$ROLE_USERS; ?>" <?php echo $data->type === self::$ROLE_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Users by Role'); ?></label>
145
- <span class="roles-container <?php echo $data->type === self::$ROLE_USERS ? '' : 'hidden'; ?>">
146
- <?php do_action('wp_nav_menu_item_custom_fields_roles_list', $item_id, $item, $depth, $args); ?>
147
- </span>
148
- </span>
149
- </p>
150
- <?php
151
- }
152
-
153
- protected function update_nav_menu_item_sub($menu_id, $menu_item_db_id, $args, $data) {
154
- return $data;
155
- }
156
-
157
- public function update_nav_menu_item($menu_id, $menu_item_db_id, $args) {
158
- if (!current_user_can('edit_nav_menu_permissions'))
159
- return;
160
-
161
- $data = $this->get_meta_data($menu_item_db_id);
162
-
163
- if (!empty($_POST['user-restriction-type-' . $menu_item_db_id])) {
164
- $this->main->verify_nonce($menu_item_db_id);
165
-
166
- $data->type = intval($_POST['user-restriction-type-' . $menu_item_db_id]);
167
-
168
- $data = $this->update_nav_menu_item_sub($menu_id, $menu_item_db_id, $args, $data);
169
- }
170
-
171
- update_post_meta($menu_item_db_id, self::$META_DATA_KEY, $data);
172
- }
173
-
174
- protected function override_nav_menu_items_sub($item, $data) {
175
- return FALSE;
176
- }
177
-
178
- public function override_nav_menu_items($items, $menu, $args) {
179
- if (is_admin()) {
180
- return $items;
181
- }
182
-
183
- $remove_parent = array();
184
-
185
- foreach ($items as $key => $item) {
186
- $data = $this->get_meta_data($item->db_id);
187
-
188
- $remove = FALSE;
189
-
190
- switch ($data->type) {
191
- case self::$LOGGEDIN_USERS:
192
- $remove = !is_user_logged_in();
193
- break;
194
- case self::$GUEST_USERS:
195
- $remove = is_user_logged_in();
196
- break;
197
- case self::$ROLE_USERS:
198
- $remove = $this->override_nav_menu_items_sub($item, $data);
199
- default:
200
- break;
201
- }
202
-
203
- if ($remove) {
204
- $remove_parent[] = $item->ID;
205
- unset($items[$key]);
206
- }
207
- }
208
-
209
- while (!empty($remove_parent)) {
210
- $continue = FALSE;
211
-
212
- foreach ($items as $key => $item) {
213
- if (empty($item)) {
214
- continue;
215
- }
216
-
217
- if (intval($item->menu_item_parent) === intval($remove_parent[0])) {
218
- $remove_parent[] = $item->ID;
219
- unset($items[$key]);
220
- $continue = TRUE;
221
- }
222
- }
223
-
224
- if ($continue)
225
- continue;
226
-
227
- array_shift($remove_parent);
228
- }
229
-
230
- return array_values($items);
231
- }
232
-
233
- protected function get_meta_data($menu_item_db_id) {
234
- $data = get_post_meta($menu_item_db_id, self::$META_DATA_KEY, true);
235
-
236
- if (empty($data)) {
237
- $data = (OBJECT) array('type' => self::$ALL_USERS);
238
- }
239
-
240
- switch (intval($data->type)) {
241
- case self::$LOGGEDIN_USERS:
242
- case self::$GUEST_USERS:
243
- case self::$ROLE_USERS:
244
- $data->type = intval($data->type);
245
- break;
246
- default:
247
- $data->type = self::$ALL_USERS;
248
- break;
249
- }
250
-
251
- return $data;
252
- }
253
-
254
- public function enqueue_menu_scripts() {
255
- wp_enqueue_script('jquery');
256
- wp_enqueue_script('wpfront-user-role-editor-nav-menu-js', $this->main->pluginURL() . 'js/nav-menu.js', array('jquery'), WPFront_User_Role_Editor::VERSION);
257
- }
258
-
259
- public function enqueue_menu_styles() {
260
- wp_enqueue_style('wpfront-user-role-editor-nav-menu-css', $this->main->pluginURL() . 'css/nav-menu.css', array(), WPFront_User_Role_Editor::VERSION);
261
- }
262
-
263
- public static function uninstall() {
264
- delete_post_meta_by_key(self::$META_DATA_KEY);
265
- }
266
-
267
- }
268
-
269
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-options.php DELETED
@@ -1,432 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2013, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- require_once(plugin_dir_path(__FILE__) . "entities/class-wpfront-user-role-editor-entity-options.php");
30
-
31
- if (!class_exists('WPFront_User_Role_Editor_Options')) {
32
-
33
- /**
34
- * Options class for WPFront User Role Editor Plugin
35
- *
36
- * @author Syam Mohan <syam@wpfront.com>
37
- * @copyright 2014 WPFront.com
38
- */
39
- class WPFront_User_Role_Editor_Options extends WPFront_User_Role_Editor_Controller_Base {
40
-
41
- const MENU_SLUG = WPFront_User_Role_Editor::PLUGIN_SLUG;
42
-
43
- function __construct($main) {
44
- parent::__construct($main);
45
-
46
- $this->ajax_register('wp_ajax_wpfront_user_role_editor_update_options', array($this, 'update_options_callback'));
47
-
48
- add_filter('wpfront_ure_custom_post_type_enable_custom_permission', array($this, 'custom_post_type_enable_custom_permission'), 10, 1);
49
- }
50
-
51
- public function settings() {
52
- include($this->main->pluginDIR() . 'templates/options-template.php');
53
- }
54
-
55
- private function get_custom_post_type_list() {
56
- $post_types = apply_filters('wpfront_ure_custom_post_type_permission_settings_list', array());
57
- $customize = $this->customize_permission_custom_post_types();
58
-
59
- foreach ($post_types as $key => $value) {
60
- $post_types[$key] = (OBJECT) array('label' => $value, 'enabled' => in_array($key, $customize));
61
- }
62
-
63
- return $post_types;
64
- }
65
-
66
- private function get_extendable_post_types() {
67
- $types = $this->main->get_extendable_post_types();
68
- $post_types = get_post_types(NULL, 'objects');
69
- $disable = $this->disable_extended_permission_post_types();
70
-
71
- $names = array();
72
- foreach ($types as $value) {
73
- $names[$value] = (OBJECT) array('label' => $post_types[$value]->label, 'enabled' => in_array($value, $disable));
74
- }
75
-
76
- return $names;
77
- }
78
-
79
- public function update_options_callback() {
80
- check_ajax_referer($_POST['referer'], 'nonce');
81
-
82
- if (isset($_POST['multisite']))
83
- $this->multisite = TRUE;
84
-
85
- $this->update_option_boolean('display_deprecated');
86
- $this->update_option_boolean('remove_nonstandard_capabilities_restore');
87
- $this->update_option_boolean('override_edit_permissions');
88
- $this->update_option_boolean('disable_navigation_menu_permissions');
89
- $this->update_option_boolean('override_navigation_menu_permissions');
90
-
91
- if ($this->multisite && wp_is_large_network()) {
92
- $this->update_option_boolean('enable_large_network_functionalities');
93
- }
94
- if ($this->main->enable_multisite_only_options($this->multisite)) {
95
- $this->update_option_boolean('remove_data_on_uninstall', TRUE);
96
- }
97
-
98
- if (isset($_POST['custom-post-types'])) {
99
- $custom_post_types = $_POST['custom-post-types'];
100
- if (is_array($custom_post_types)) {
101
- $post_type_values = $this->customize_permission_custom_post_types();
102
- foreach ($custom_post_types as $key => $value) {
103
- if ($value === 'true') {
104
- if (!in_array($key, $post_type_values))
105
- $post_type_values[] = $key;
106
- } else {
107
- if (in_array($key, $post_type_values))
108
- $post_type_values = array_diff($post_type_values, array($key));
109
- }
110
- }
111
-
112
- do_action('wpfront_ure_update_customize_permission_custom_post_types', $post_type_values, $this->customize_permission_custom_post_types());
113
- $this->update_option('customize_permission_custom_post_types', implode(',', $post_type_values));
114
- }
115
- }
116
-
117
- if (isset($_POST['extendable-post-types'])) {
118
- $extendable_post_types = $_POST['extendable-post-types'];
119
- if (is_array($extendable_post_types)) {
120
- $post_type_values = $this->disable_extended_permission_post_types();
121
- foreach ($extendable_post_types as $key => $value) {
122
- if ($value === 'true') {
123
- if (!in_array($key, $post_type_values))
124
- $post_type_values[] = $key;
125
- } else {
126
- if (in_array($key, $post_type_values))
127
- $post_type_values = array_diff($post_type_values, array($key));
128
- }
129
- }
130
-
131
- $this->update_option('disable_extended_permission_post_types', implode(',', $post_type_values));
132
- }
133
- }
134
-
135
- if ($this->multisite)
136
- echo network_admin_url('admin.php?page=' . self::MENU_SLUG . '&settings-updated=true');
137
- else
138
- echo admin_url('admin.php?page=' . self::MENU_SLUG . '&settings-updated=true');
139
- die();
140
- }
141
-
142
- public function custom_post_type_enable_custom_permission($post_type) {
143
- $post_types = apply_filters('wpfront_ure_custom_post_type_permission_settings_list', array());
144
-
145
- if (empty($post_types[$post_type]))
146
- return FALSE;
147
-
148
- $post_type_values = $this->customize_permission_custom_post_types();
149
- if (!in_array($post_type, $post_type_values))
150
- $post_type_values[] = $post_type;
151
-
152
- do_action('wpfront_ure_update_customize_permission_custom_post_types', $post_type_values, $this->customize_permission_custom_post_types());
153
- $this->update_option('customize_permission_custom_post_types', implode(',', $post_type_values));
154
-
155
- return TRUE;
156
- }
157
-
158
- private function update_option_boolean($key, $clone = FALSE) {
159
- if (!empty($_POST[$key])) {
160
- $value = $_POST[$key];
161
- if ($value === 'true') {
162
- $value = 1;
163
- } else if ($value === 'false') {
164
- $value = 0;
165
- }
166
-
167
- $this->update_option($key, $value, $clone);
168
- }
169
- }
170
-
171
- private function update_option($key, $value, $clone = FALSE) {
172
- $prefix = '';
173
- if ($this->multisite) {
174
- $prefix = 'ms_';
175
- switch_to_blog($this->ms_options_blog_id());
176
- }
177
-
178
- $entity = new WPFront_User_Role_Editor_Entity_Options();
179
- $entity->update_option($prefix . $key, $value);
180
- if ($clone)
181
- $entity->update_option($key, $value);
182
-
183
- if ($this->multisite)
184
- restore_current_blog();
185
- }
186
-
187
- public function enable_role_capabilities() {
188
- return TRUE;
189
- }
190
-
191
- private function get_boolean_option($key, $ms = FALSE) {
192
- $value = $this->get_option($key, $ms);
193
- return $value === '1' ? TRUE : FALSE;
194
- }
195
-
196
- private function get_option($key, $ms = FALSE) {
197
- $prefix = '';
198
- if ($ms) {
199
- $prefix = 'ms_';
200
- switch_to_blog($this->ms_options_blog_id());
201
- }
202
-
203
- $entity = new WPFront_User_Role_Editor_Entity_Options();
204
- $value = $entity->get_option($prefix . $key);
205
- if ($value === NULL) {
206
- if ($ms === FALSE && is_multisite()) {
207
- return $this->get_option($key, TRUE);
208
- }
209
- }
210
-
211
- if ($ms)
212
- restore_current_blog();
213
-
214
- return $value;
215
- }
216
-
217
- public function display_deprecated() {
218
- if ($this->multisite)
219
- return $this->ms_display_deprecated();
220
-
221
- return $this->get_boolean_option('display_deprecated');
222
- }
223
-
224
- public function remove_nonstandard_capabilities_restore() {
225
- if ($this->multisite)
226
- return $this->ms_remove_nonstandard_capabilities_restore();
227
-
228
- return $this->get_boolean_option('remove_nonstandard_capabilities_restore');
229
- }
230
-
231
- public function override_edit_permissions() {
232
- if ($this->multisite)
233
- return $this->ms_override_edit_permissions();
234
-
235
- return $this->get_boolean_option('override_edit_permissions');
236
- }
237
-
238
- public function disable_navigation_menu_permissions() {
239
- if ($this->multisite)
240
- return $this->ms_disable_navigation_menu_permissions();
241
-
242
- return $this->get_boolean_option('disable_navigation_menu_permissions');
243
- }
244
-
245
- public function override_navigation_menu_permissions() {
246
- if ($this->multisite)
247
- return $this->ms_override_navigation_menu_permissions();
248
-
249
- return $this->get_boolean_option('override_navigation_menu_permissions');
250
- }
251
-
252
- public function remove_data_on_uninstall() {
253
- if ($this->multisite)
254
- return $this->ms_remove_data_on_uninstall();
255
-
256
- return $this->get_boolean_option('remove_data_on_uninstall');
257
- }
258
-
259
- public function customize_permission_custom_post_types() {
260
- $value = $this->get_option('customize_permission_custom_post_types');
261
- if ($value === NULL || $value === '')
262
- return array();
263
-
264
- return explode(',', $value);
265
- }
266
-
267
- public function disable_extended_permission_post_types() {
268
- $value = $this->get_option('disable_extended_permission_post_types');
269
- if ($value === NULL || $value === '')
270
- return array();
271
-
272
- return explode(',', $value);
273
- }
274
-
275
- public static function get_ms_options_blog_id() {
276
- if (!is_multisite()) {
277
- throw new Exception('Invalid call');
278
- }
279
-
280
- $blog_id = 1;
281
- if (defined('BLOG_ID_CURRENT_SITE')) {
282
- $blog_id = BLOG_ID_CURRENT_SITE;
283
- }
284
- return $blog_id;
285
- }
286
-
287
- public function ms_options_blog_id() {
288
- return self::get_ms_options_blog_id();
289
- }
290
-
291
- public function ms_display_deprecated() {
292
- return $this->get_boolean_option('display_deprecated', TRUE);
293
- }
294
-
295
- public function ms_remove_nonstandard_capabilities_restore() {
296
- return $this->get_boolean_option('remove_nonstandard_capabilities_restore', TRUE);
297
- }
298
-
299
- public function ms_enable_large_network_functionalities() {
300
- return $this->get_boolean_option('enable_large_network_functionalities', TRUE);
301
- }
302
-
303
- public function ms_override_edit_permissions() {
304
- return $this->get_boolean_option('override_edit_permissions', TRUE);
305
- }
306
-
307
- public function ms_disable_navigation_menu_permissions() {
308
- return $this->get_boolean_option('disable_navigation_menu_permissions', TRUE);
309
- }
310
-
311
- public function ms_override_navigation_menu_permissions() {
312
- return $this->get_boolean_option('override_navigation_menu_permissions', TRUE);
313
- }
314
-
315
- public function ms_remove_data_on_uninstall() {
316
- return $this->get_boolean_option('remove_data_on_uninstall', TRUE);
317
- }
318
-
319
- protected function add_help_tab() {
320
- if ($this->multisite) {
321
- return array(
322
- array(
323
- 'id' => 'overview',
324
- 'title' => $this->__('Overview'),
325
- 'content' => '<p>'
326
- . $this->__('These settings are applicable for the network admin dashboard. Also these settings will propagate to the individual sites unless its overridden within that site’s settings.')
327
- . '</p>'
328
- ),
329
- array(
330
- 'id' => 'settings',
331
- 'title' => $this->__('Settings'),
332
- 'content' => '<p><strong>'
333
- . $this->__('Enable Large Network Functionalities')
334
- . '</strong>: '
335
- . $this->__('This setting is only visible when you have a large network.')
336
- . ' <a href="http://wpfront.com/user-role-editor-pro/multisite-settings/" target="_blank">'
337
- . $this->__('More details')
338
- . '</a>'
339
- . '</p>'
340
- . '<p><strong>'
341
- . $this->__('Display Deprecated Capabilities')
342
- . '</strong>: '
343
- . $this->__('If enabled, deprecated capabilities will be displayed within the add/edit screens.')
344
- . '</p>'
345
- . '<p><strong>'
346
- . $this->__('Remove Non-Standard Capabilities on Restore')
347
- . '</strong>: '
348
- . $this->__('If enabled, while restoring WordPress built-in capabilities non-standard capabilities will be removed.')
349
- . '</p>'
350
- . '<p><strong>'
351
- . $this->__('Override Edit Permissions')
352
- . '</strong>: '
353
- . $this->__('If enabled, ignores the check to the function get_editable_roles.')
354
- . '</p>'
355
- . '<p><strong>'
356
- . $this->__('Disable Navigation Menu Permissions')
357
- . '</strong>: '
358
- . $this->__('If enabled, disables navigation menu permissions functionality.')
359
- . '</p>'
360
- . '<p><strong>'
361
- . $this->__('Override Navigation Menu Permissions')
362
- . '</strong>: '
363
- . $this->__('If enabled, tries to reset navigation menu permissions UI.')
364
- . '</p>'
365
- . '<p><strong>'
366
- . $this->__('Remove Data on Uninstall')
367
- . '</strong>: '
368
- . $this->__('If enabled, removes all data related to this plugin from database (except roles data) including license information if any. This will not deactivate the license automatically.')
369
- . '</p>'
370
- )
371
- );
372
- } else {
373
- return array(
374
- array(
375
- 'id' => 'overview',
376
- 'title' => $this->__('Overview'),
377
- 'content' => '<p><strong>'
378
- . $this->__('Display Deprecated Capabilities')
379
- . '</strong>: '
380
- . $this->__('If enabled, deprecated capabilities will be displayed within the add/edit screens.')
381
- . '</p>'
382
- . '<p><strong>'
383
- . $this->__('Remove Non-Standard Capabilities on Restore')
384
- . '</strong>: '
385
- . $this->__('If enabled, while restoring WordPress built-in capabilities non-standard capabilities will be removed.')
386
- . '</p>'
387
- . '<p><strong>'
388
- . $this->__('Override Edit Permissions')
389
- . '</strong>: '
390
- . $this->__('If enabled, ignores the check to the function get_editable_roles.')
391
- . '</p>'
392
- . '<p><strong>'
393
- . $this->__('Disable Navigation Menu Permissions')
394
- . '</strong>: '
395
- . $this->__('If enabled, disables navigation menu permissions functionality.')
396
- . '</p>'
397
- . '<p><strong>'
398
- . $this->__('Override Navigation Menu Permissions')
399
- . '</strong>: '
400
- . $this->__('If enabled, tries to reset navigation menu permissions UI.')
401
- . '</p>'
402
- . '<p><strong>'
403
- . $this->__('Remove Data on Uninstall')
404
- . '</strong>: '
405
- . $this->__('If enabled, removes all data related to this plugin from database (except roles data) including license information if any. This will not deactivate the license automatically.')
406
- . '</p>'
407
- )
408
- );
409
- }
410
- }
411
-
412
- protected function set_help_sidebar() {
413
- if ($this->multisite) {
414
- return array(
415
- array(
416
- $this->__('Documentation on Multisite Settings'),
417
- 'multisite-settings/'
418
- )
419
- );
420
- } else {
421
- return array(
422
- array(
423
- $this->__('Documentation on Settings'),
424
- 'settings/'
425
- )
426
- );
427
- }
428
- }
429
-
430
- }
431
-
432
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-restore.php DELETED
@@ -1,190 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Restore')) {
30
-
31
- /**
32
- * Restore Role
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_Restore extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- const MENU_SLUG = 'wpfront-user-role-editor-restore';
40
-
41
- static protected $restore_action = NULL;
42
- protected $roles;
43
-
44
- function __construct($main) {
45
- parent::__construct($main);
46
-
47
- $this->ajax_register('wp_ajax_wpfront_user_role_editor_restore_role', array($this, 'restore_role_callback'));
48
- }
49
-
50
- public function restore_role() {
51
- if (!$this->can_edit()) {
52
- $this->main->permission_denied();
53
- return;
54
- }
55
-
56
- $this->prepare_data(FALSE);
57
- $this->include_template();
58
- }
59
-
60
- protected function prepare_data($usename) {
61
- global $wp_roles;
62
- $site_roles = $wp_roles->role_names;
63
-
64
- foreach (WPFront_User_Role_Editor::$DEFAULT_ROLES as $value) {
65
- $text = $this->__(ucfirst($value));
66
- if (!$usename && array_key_exists($value, $site_roles))
67
- $text = $site_roles[$value];
68
-
69
- $this->roles[$value] = $text;
70
- }
71
- }
72
-
73
- protected function include_template() {
74
- include($this->main->pluginDIR() . 'templates/restore-role.php');
75
- }
76
-
77
- public function restore_role_callback() {
78
- if (self::$restore_action !== NULL) {
79
- call_user_func(self::$restore_action);
80
- die();
81
- }
82
-
83
- check_ajax_referer($_POST['referer'], 'nonce');
84
-
85
- $result = $this->action_restore();
86
-
87
- echo sprintf('{ "result": %s, "message": "%s" }', $result[0] ? 'true' : 'false', $this->__('ERROR') . ': ' . $this->__($result[1]));
88
- die();
89
- }
90
-
91
- protected function action_restore() {
92
- $result = FALSE;
93
- $message = 'Unexpected error while restoring role.';
94
-
95
- if (empty($_POST['role'])) {
96
- $message = 'Role not found.';
97
- } elseif (!$this->can_edit()) {
98
- $message = 'Permission denied.';
99
- } else {
100
- $role_name = $_POST['role'];
101
- if (!in_array($role_name, WPFront_User_Role_Editor::$DEFAULT_ROLES)) {
102
- $message = 'Role not found.';
103
- } else {
104
- $role = get_role($role_name);
105
- if ($role == NULL)
106
- $role = add_role($role_name, $this->__(ucfirst($role_name)));
107
- if ($role != NULL) {
108
-
109
- foreach (WPFront_User_Role_Editor::$STANDARD_CAPABILITIES as $group => $caps) {
110
- foreach ($caps as $cap => $roles) {
111
- if (in_array($role->name, $roles))
112
- $role->add_cap($cap);
113
- else
114
- $role->remove_cap($cap);
115
- }
116
- }
117
-
118
- foreach (WPFront_User_Role_Editor::$DEPRECATED_CAPABILITIES as $group => $caps) {
119
- foreach ($caps as $cap => $roles) {
120
- if (in_array($role->name, $roles))
121
- $role->add_cap($cap);
122
- else
123
- $role->remove_cap($cap);
124
- }
125
- }
126
-
127
- if ($this->main->remove_nonstandard_capabilities_restore()) {
128
- foreach (WPFront_User_Role_Editor::$ROLE_CAPS as $value) {
129
- $role->remove_cap($value);
130
- }
131
-
132
- $this->main->get_capabilities();
133
- foreach (WPFront_User_Role_Editor::$OTHER_CAPABILITIES as $group => $caps) {
134
- foreach ($caps as $cap) {
135
- $role->remove_cap($cap);
136
- }
137
- }
138
- } else {
139
- if ($role->name == self::ADMINISTRATOR_ROLE_KEY) {
140
- $this->main->get_capabilities();
141
- foreach (WPFront_User_Role_Editor::$OTHER_CAPABILITIES as $group => $caps) {
142
- foreach ($caps as $cap) {
143
- $role->add_cap($cap);
144
- }
145
- }
146
- }
147
- }
148
-
149
- if ($role->name == self::ADMINISTRATOR_ROLE_KEY && $this->main->enable_role_capabilities()) {
150
- foreach (WPFront_User_Role_Editor::$ROLE_CAPS as $value) {
151
- $role->add_cap($value);
152
- }
153
- }
154
-
155
- $result = TRUE;
156
- $message = '';
157
- }
158
- }
159
- }
160
-
161
- return array($result, $message);
162
- }
163
-
164
- protected function add_help_tab() {
165
- return array(
166
- array(
167
- 'id' => 'overview',
168
- 'title' => $this->__('Overview'),
169
- 'content' => '<p>'
170
- . $this->__('This screen allows you to restore WordPress built-in roles to its standard capability settings.')
171
- . '</p>'
172
- . '<p>'
173
- . $this->__('To restore a role, click the Restore button then Confirm.')
174
- . '</p>'
175
- )
176
- );
177
- }
178
-
179
- protected function set_help_sidebar() {
180
- return array(
181
- array(
182
- $this->__('Documentation on Restore'),
183
- 'restore-role/'
184
- )
185
- );
186
- }
187
-
188
- }
189
-
190
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-user-permissions.php DELETED
@@ -1,133 +0,0 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_User_Permissions')) {
30
-
31
- /**
32
- * User Permissions
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2015 WPFront.com
36
- */
37
- class WPFront_User_Role_Editor_User_Permissions extends WPFront_User_Role_Editor_Controller_Base {
38
-
39
- private static $user_capabilities = array(
40
- 'edit_users_higher_level' => 'edit_users',
41
- 'delete_users_higher_level' => 'delete_users',
42
- 'promote_users_higher_level' => 'promote_users',
43
- 'promote_users_to_higher_level' => 'promote_users'
44
- );
45
-
46
- public function __construct($main) {
47
- parent::__construct($main);
48
-
49
- $users = WPFront_User_Role_Editor::$STANDARD_CAPABILITIES['Users'];
50
- foreach (self::$user_capabilities as $key => $value) {
51
- $users[$key] = $users[$value];
52
- }
53
- WPFront_User_Role_Editor::$STANDARD_CAPABILITIES['Users'] = $users;
54
-
55
- add_filter('user_has_cap', array($this, 'user_has_cap'), 10, 3);
56
- add_filter('editable_roles', array($this, 'assignable_roles'));
57
-
58
- add_action('admin_init', array($this, 'admin_init'));
59
- }
60
-
61
- public function assignable_roles($all_roles) {
62
- return $all_roles;
63
- }
64
-
65
- public function user_has_cap($allcaps, $caps, $args) {
66
- if (!empty($args) && count($args) === 3) {
67
- switch ($args[0]) {
68
- case 'edit_user':
69
- if (!$this->can_edit_user($args[1], $args[2])) {
70
- foreach ($caps as $value) {
71
- unset($allcaps[$value]);
72
- }
73
- }
74
- break;
75
-
76
- case 'delete_user':
77
- if (!$this->can_delete_user($args[1], $args[2])) {
78
- foreach ($caps as $value) {
79
- unset($allcaps[$value]);
80
- }
81
- }
82
- break;
83
-
84
- case 'promote_user':
85
- if (!$this->can_promote_user($args[1], $args[2])) {
86
- foreach ($caps as $value) {
87
- unset($allcaps[$value]);
88
- }
89
- }
90
- break;
91
- }
92
- }
93
-
94
- return $allcaps;
95
- }
96
-
97
- protected function can_edit_user($user_id, $edit_user_id) {
98
- return TRUE;
99
- }
100
-
101
- protected function can_delete_user($user_id, $edit_user_id) {
102
- return TRUE;
103
- }
104
-
105
- protected function can_promote_user($user_id, $edit_user_id) {
106
- return TRUE;
107
- }
108
-
109
- public function admin_init() {
110
- $option_key = 'user_permission_capabilities_processed';
111
- $entity = new WPFront_User_Role_Editor_Entity_Options();
112
-
113
- $processed = $entity->get_option($option_key);
114
- if (!empty($processed))
115
- return;
116
-
117
- global $wp_roles;
118
-
119
- foreach ($wp_roles->role_objects as $key => $role) {
120
- foreach (self::$user_capabilities as $u_cap => $cap) {
121
- if ($role->has_cap($cap)) {
122
- $role->add_cap($u_cap);
123
- }
124
- }
125
- }
126
-
127
- $entity->update_option($option_key, TRUE);
128
- }
129
-
130
- }
131
-
132
- }
133
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor-widget-permissions.php DELETED
@@ -1,176 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- if (!class_exists('WPFront_User_Role_Editor_Widget_Permissions')) {
29
-
30
- /**
31
- * Widget Permissions Controller
32
- *
33
- * @author Syam Mohan <syam@wpfront.com>
34
- * @copyright 2015 WPFront.com
35
- */
36
- class WPFront_User_Role_Editor_Widget_Permissions extends WPFront_User_Role_Editor_Controller_Base {
37
-
38
- protected static $ALL_USERS = 1;
39
- protected static $LOGGEDIN_USERS = 2;
40
- protected static $GUEST_USERS = 3;
41
- protected static $ROLE_USERS = 4;
42
- protected static $META_DATA_KEY = 'wpfront-user-role-editor-widget-permissions-data';
43
-
44
- public function __construct($main) {
45
- parent::__construct($main);
46
-
47
- add_action('in_widget_form', array($this, 'in_widget_form'), 10, 3);
48
- add_filter('widget_update_callback', array($this, 'widget_update_callback'), 10, 4);
49
- add_filter('widget_display_callback', array($this, 'widget_display_callback'), 10, 3);
50
-
51
- add_action('wp_widget_permissions_custom_fields_roles_list', array($this, 'widget_permissions_custom_fields_roles_list'), 10, 3);
52
-
53
- add_action('admin_print_scripts-widgets.php', array($this, 'enqueue_widget_scripts'));
54
- add_action('admin_print_styles-widgets.php', array($this, 'enqueue_widget_styles'));
55
- }
56
-
57
- protected function get_meta_data($instance) {
58
- if (empty($instance) || empty($instance[self::$META_DATA_KEY])) {
59
- $data = (OBJECT) array('type' => self::$ALL_USERS);
60
- } else {
61
- $data = $instance[self::$META_DATA_KEY];
62
- }
63
-
64
- $data->type = intval($data->type);
65
-
66
- switch ($data->type) {
67
- case self::$ALL_USERS:
68
- case self::$LOGGEDIN_USERS:
69
- case self::$GUEST_USERS:
70
- case self::$ROLE_USERS:
71
- break;
72
-
73
- default:
74
- $data->type = self::$ALL_USERS;
75
- break;
76
- }
77
-
78
- return $data;
79
- }
80
-
81
- public function in_widget_form($widget, $return, $instance) {
82
- if (!current_user_can('edit_widget_permissions'))
83
- return;
84
-
85
- $data = $this->get_meta_data($instance);
86
- ?>
87
- <p>
88
- <label><?php echo $this->__('User Restrictions'); ?></label>
89
- <span class="user-restriction-container">
90
- <label><input class="user-restriction-type" type="radio" name="<?php echo $widget->get_field_name('user-restriction-type'); ?>" value="<?php echo self::$ALL_USERS; ?>" <?php echo $data->type === self::$ALL_USERS ? 'checked' : ''; ?> /><?php echo $this->__('All Users'); ?></label>
91
- <label><input class="user-restriction-type" type="radio" name="<?php echo $widget->get_field_name('user-restriction-type'); ?>" value="<?php echo self::$LOGGEDIN_USERS; ?>" <?php echo $data->type === self::$LOGGEDIN_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Logged in Users'); ?></label>
92
- <label><input class="user-restriction-type" type="radio" name="<?php echo $widget->get_field_name('user-restriction-type'); ?>" value="<?php echo self::$GUEST_USERS; ?>" <?php echo $data->type === self::$GUEST_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Guest Users'); ?></label>
93
- <label><input class="user-restriction-type" type="radio" name="<?php echo $widget->get_field_name('user-restriction-type'); ?>" value="<?php echo self::$ROLE_USERS; ?>" <?php echo $data->type === self::$ROLE_USERS ? 'checked' : ''; ?> /><?php echo $this->__('Users by Role'); ?></label>
94
- <span class="roles-container <?php echo $data->type === self::$ROLE_USERS ? '' : 'hidden'; ?>">
95
- <?php do_action('wp_widget_permissions_custom_fields_roles_list', $widget, $return, $instance); ?>
96
- </span>
97
- </span>
98
- </p>
99
- <?php
100
- }
101
-
102
- public function widget_update_callback($instance, $new_instance, $old_instance, $widget) {
103
- if (!current_user_can('edit_widget_permissions')) {
104
- if (empty($old_instance[self::$META_DATA_KEY]))
105
- $instance[self::$META_DATA_KEY] = (OBJECT) array('type' => self::$ALL_USERS);
106
- else
107
- $instance[self::$META_DATA_KEY] = $old_instance[self::$META_DATA_KEY];
108
- return $instance;
109
- }
110
-
111
- if (empty($new_instance['user-restriction-type'])) {
112
- $instance[self::$META_DATA_KEY] = (OBJECT) array('type' => self::$ALL_USERS);
113
- } else {
114
- $instance[self::$META_DATA_KEY] = (OBJECT) array('type' => intval($new_instance['user-restriction-type']));
115
- }
116
- return $instance;
117
- }
118
-
119
- public function widget_display_callback($instance, $widget, $args) {
120
- $data = $this->get_meta_data($instance);
121
-
122
- switch ($data->type) {
123
- case self::$LOGGEDIN_USERS:
124
- if (is_user_logged_in())
125
- return $instance;
126
-
127
- return FALSE;
128
-
129
- case self::$GUEST_USERS:
130
- if (!is_user_logged_in())
131
- return $instance;
132
-
133
- return FALSE;
134
-
135
- default:
136
- break;
137
- }
138
-
139
- return $instance;
140
- }
141
-
142
- public function widget_permissions_custom_fields_roles_list($widget, $return, $instance) {
143
- printf($this->__('%s to limit based on roles.'), '<a target="_blank" href="https://wpfront.com/widgets">' . $this->__('Upgrade to Pro') . '</a>');
144
- }
145
-
146
- public function enqueue_widget_scripts() {
147
- wp_enqueue_script('jquery');
148
- wp_enqueue_script('wpfront-user-role-editor-widget-permissions-js', $this->main->pluginURL() . 'js/widget-permissions.js', array('jquery'), WPFront_User_Role_Editor::VERSION);
149
- }
150
-
151
- public function enqueue_widget_styles() {
152
- wp_enqueue_style('wpfront-user-role-editor-widget-permissions-css', $this->main->pluginURL() . 'css/widget-permissions.css', array(), WPFront_User_Role_Editor::VERSION);
153
- }
154
-
155
- public static function uninstall() {
156
- global $wp_registered_widgets;
157
-
158
- foreach ($wp_registered_widgets as $widget) {
159
- $index = -1;
160
- if (isset($widget['params'][0]['number']))
161
- $index = $widget['params'][0]['number'];
162
-
163
- if ($index > -1) {
164
- $option_name = $widget['callback'][0]->option_name;
165
- $option = get_option($option_name);
166
- if (isset($option[$index][self::$META_DATA_KEY])) {
167
- unset($option[$index][self::$META_DATA_KEY]);
168
- update_option($option_name, $option);
169
- }
170
- }
171
- }
172
- }
173
-
174
- }
175
-
176
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-wpfront-user-role-editor.php DELETED
@@ -1,738 +0,0 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- require_once(plugin_dir_path(__FILE__) . "base/class-wpfront-base.php");
29
-
30
- if (!class_exists('WPFront_User_Role_Editor')) {
31
-
32
- /**
33
- * Main class of WPFront User Role Editor Plugin
34
- *
35
- * @author Syam Mohan <syam@wpfront.com>
36
- * @copyright 2014 WPFront.com
37
- */
38
- class WPFront_User_Role_Editor extends WPFront_Base_URE {
39
-
40
- //Constants
41
- const VERSION = '2.14.4';
42
- const OPTIONS_GROUP_NAME = 'wpfront-user-role-editor-options-group';
43
- const OPTION_NAME = 'wpfront-user-role-editor-options';
44
- const PLUGIN_SLUG = 'wpfront-user-role-editor';
45
-
46
- public static $DYNAMIC_CAPS = array();
47
- public static $ROLE_CAPS = array(
48
- 'list_roles',
49
- 'create_roles',
50
- 'edit_roles',
51
- 'delete_roles',
52
- 'edit_role_menus',
53
- 'edit_posts_role_permissions',
54
- 'edit_pages_role_permissions',
55
- 'edit_nav_menu_permissions',
56
- 'edit_content_shortcodes',
57
- 'delete_content_shortcodes',
58
- 'edit_login_redirects',
59
- 'delete_login_redirects',
60
- 'bulk_edit_roles',
61
- 'edit_widget_permissions'
62
- );
63
-
64
- public static $DEFAULT_ROLES = array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY);
65
- public static $STANDARD_CAPABILITIES = array(
66
- 'Dashboard' => array(
67
- 'read' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY),
68
- 'edit_dashboard' => array(self::ADMINISTRATOR_ROLE_KEY)
69
- ),
70
- 'Posts' => array(
71
- 'publish_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
72
- 'edit_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
73
- 'delete_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
74
- 'edit_published_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
75
- 'delete_published_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
76
- 'edit_others_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
77
- 'delete_others_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
78
- 'read_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
79
- 'edit_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
80
- 'delete_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
81
- 'manage_categories' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
82
- ),
83
- 'Media' => array(
84
- 'upload_files' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
85
- 'unfiltered_upload' => array(self::ADMINISTRATOR_ROLE_KEY)
86
- ),
87
- 'Pages' => array(
88
- 'publish_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
89
- 'edit_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
90
- 'delete_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
91
- 'edit_published_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
92
- 'delete_published_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
93
- 'edit_others_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
94
- 'delete_others_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
95
- 'read_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
96
- 'edit_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
97
- 'delete_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
98
- ),
99
- 'Comments' => array(
100
- 'edit_comment' => array(),
101
- 'moderate_comments' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
102
- ),
103
- 'Themes' => array(
104
- 'switch_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
105
- 'edit_theme_options' => array(self::ADMINISTRATOR_ROLE_KEY),
106
- 'edit_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
107
- 'delete_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
108
- 'install_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
109
- 'update_themes' => array(self::ADMINISTRATOR_ROLE_KEY)
110
- ),
111
- 'Plugins' => array(
112
- 'activate_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
113
- 'edit_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
114
- 'install_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
115
- 'update_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
116
- 'delete_plugins' => array(self::ADMINISTRATOR_ROLE_KEY)
117
- ),
118
- 'Users' => array(
119
- 'list_users' => array(self::ADMINISTRATOR_ROLE_KEY),
120
- 'create_users' => array(self::ADMINISTRATOR_ROLE_KEY),
121
- 'edit_users' => array(self::ADMINISTRATOR_ROLE_KEY),
122
- 'delete_users' => array(self::ADMINISTRATOR_ROLE_KEY),
123
- 'promote_users' => array(self::ADMINISTRATOR_ROLE_KEY),
124
- 'add_users' => array(self::ADMINISTRATOR_ROLE_KEY),
125
- 'remove_users' => array(self::ADMINISTRATOR_ROLE_KEY)
126
- ),
127
- 'Tools' => array(
128
- 'import' => array(self::ADMINISTRATOR_ROLE_KEY),
129
- 'export' => array(self::ADMINISTRATOR_ROLE_KEY)
130
- ),
131
- 'Admin' => array(
132
- 'manage_options' => array(self::ADMINISTRATOR_ROLE_KEY),
133
- 'update_core' => array(self::ADMINISTRATOR_ROLE_KEY),
134
- 'unfiltered_html' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
135
- ),
136
- 'Links' => array(
137
- 'manage_links' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
138
- )
139
- );
140
- public static $DEPRECATED_CAPABILITIES = array(
141
- 'Deprecated' => array(
142
- 'edit_files' => array(self::ADMINISTRATOR_ROLE_KEY),
143
- 'level_0' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY),
144
- 'level_1' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
145
- 'level_2' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
146
- 'level_3' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
147
- 'level_4' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
148
- 'level_5' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
149
- 'level_6' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
150
- 'level_7' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
151
- 'level_8' => array(self::ADMINISTRATOR_ROLE_KEY),
152
- 'level_9' => array(self::ADMINISTRATOR_ROLE_KEY),
153
- 'level_10' => array(self::ADMINISTRATOR_ROLE_KEY)
154
- )
155
- );
156
- public static $OTHER_CAPABILITIES = array(
157
- 'Other Capabilities' => array(
158
- )
159
- );
160
- public static $CUSTOM_POST_TYPES_DEFAULTED = array();
161
- private static $CAPABILITIES = NULL;
162
- //Variables
163
- protected $admin_menu = array();
164
- protected $remove_admin_menu = array();
165
- protected $options;
166
- protected $objList;
167
- protected $objAddEdit;
168
- protected $objRestore;
169
- protected $objAddRemoveCap;
170
- protected $objAssignUsers;
171
- protected $objGoPro;
172
- protected $objNavMenu = NULL;
173
- protected $objLoginRedirect = NULL;
174
- protected $objAttachmentPermissions = NULL;
175
- protected $objUserPermissions = NULL;
176
- protected $objWidgetPermissions = NULL;
177
- protected $objShortcodes = NULL;
178
-
179
- function __construct() {
180
- parent::__construct(__FILE__, self::PLUGIN_SLUG);
181
-
182
- //$this->add_menu($this->__('WPFront User Role Editor'), $this->__('User Role Editor'));
183
-
184
- $this->options = new WPFront_User_Role_Editor_Options($this);
185
- $this->objGoPro = new WPFront_User_Role_Editor_Go_Pro($this);
186
-
187
- if ($this->objGoPro->has_license()) {
188
- $this->objList = new WPFront_User_Role_Editor_List($this);
189
- $this->objAddEdit = new WPFront_User_Role_Editor_Add_Edit($this);
190
- $this->objRestore = new WPFront_User_Role_Editor_Restore($this);
191
- $this->objAddRemoveCap = new WPFront_User_Role_Editor_Add_Remove_Capability($this);
192
- $this->objAssignUsers = new WPFront_User_Role_Editor_Assign_Roles($this);
193
- if ($this->objNavMenu === NULL)
194
- $this->objNavMenu = new WPFront_User_Role_Editor_Nav_Menu($this);
195
- if ($this->objLoginRedirect === NULL)
196
- $this->objLoginRedirect = new WPFront_User_Role_Editor_Login_Redirect($this);
197
- if ($this->objAttachmentPermissions === NULL)
198
- $this->objAttachmentPermissions = new WPFront_User_Role_Editor_Attachment_Permissions($this);
199
- if ($this->objUserPermissions === NULL)
200
- $this->objUserPermissions = new WPFront_User_Role_Editor_User_Permissions($this);
201
- if ($this->objWidgetPermissions === NULL)
202
- $this->objWidgetPermissions = new WPFront_User_Role_Editor_Widget_Permissions($this);
203
- if ($this->objShortcodes === NULL)
204
- $this->objShortcodes = new WPFront_User_Role_Editor_Shortcodes($this);
205
- }
206
- }
207
-
208
- public function plugins_loaded() {
209
- //gravity forms
210
- if (!function_exists('members_get_capabilities')) {
211
-
212
- function members_get_capabilities() {
213
-
214
- }
215
-
216
- }
217
- }
218
-
219
- public function admin_init() {
220
- register_setting(self::OPTIONS_GROUP_NAME, self::OPTION_NAME);
221
-
222
- $this->rename_role_capabilities();
223
- }
224
-
225
- protected function add_submenu_page($position, $title, $name, $capability, $slug, $func, $scripts = NULL, $styles = NULL, $controller = NULL, $admin_bar_parent = NULL, $admin_bar_title = NULL) {
226
- if ($scripts === NULL)
227
- $scripts = 'enqueue_role_scripts';
228
- if ($styles === NULL)
229
- $styles = 'enqueue_role_styles';
230
-
231
- $this->admin_menu[$position] = array($title, $name, $capability, $slug, $func, $scripts, $styles, $controller, $admin_bar_parent, $admin_bar_title);
232
- }
233
-
234
- protected function remove_submenu_page($position) {
235
- $this->remove_admin_menu[$position] = TRUE;
236
- }
237
-
238
- public function get_submenu_page_item($position) {
239
- return $this->admin_menu[$position];
240
- }
241
-
242
- protected function add_pro_page() {
243
- if (isset($this->admin_menu[1000]))
244
- return;
245
-
246
- if (current_user_can('manage_options'))
247
- $this->add_submenu_page(1000, $this->__('Go Pro'), '<span class="wpfront-go-pro">' . $this->__('Go Pro') . '</span>', 'manage_options', WPFront_User_Role_Editor_Go_Pro::MENU_SLUG, array($this->objGoPro, 'go_pro'));
248
- }
249
-
250
- public function admin_menu() {
251
- //parent::admin_menu();
252
-
253
- $this->add_pro_page();
254
-
255
- if ($this->objGoPro->has_license())
256
- $menu_slug = WPFront_User_Role_Editor_List::MENU_SLUG;
257
- else
258
- $menu_slug = WPFront_User_Role_Editor_Go_Pro::MENU_SLUG;
259
-
260
- if ($this->objGoPro->has_license()) {
261
- $this->add_submenu_page(10, $this->__('Roles'), $this->__('All Roles'), $this->get_capability_string('list'), WPFront_User_Role_Editor_List::MENU_SLUG, array($this->objList, 'list_roles'), NULL, NULL, $this->objList);
262
- $this->add_submenu_page(20, $this->__('Add New Role'), $this->__('Add New'), $this->get_capability_string('create'), WPFront_User_Role_Editor_Add_Edit::MENU_SLUG, array($this->objAddEdit, 'add_edit_role'), NULL, NULL, $this->objAddEdit, 'new-content', $this->__('Role'));
263
- $this->add_submenu_page(30, $this->__('Restore Role'), $this->__('Restore'), $this->get_capability_string('edit'), WPFront_User_Role_Editor_Restore::MENU_SLUG, array($this->objRestore, 'restore_role'), NULL, NULL, $this->objRestore);
264
- $this->add_submenu_page(35, $this->__('Add/Remove Capability'), $this->__('Add/Remove Cap'), $this->get_capability_string('edit'), WPFront_User_Role_Editor_Add_Remove_Capability::MENU_SLUG, array($this->objAddRemoveCap, 'add_remove_capability'), NULL, NULL, $this->objAddRemoveCap);
265
- $this->add_submenu_page(37, $this->__('Login Redirect'), $this->__('Login Redirect'), 'edit_login_redirects', WPFront_User_Role_Editor_Login_Redirect::MENU_SLUG, array($this->objLoginRedirect, 'login_redirect'), NULL, NULL, $this->objLoginRedirect);
266
- $this->add_submenu_page(100, $this->__('Settings'), $this->__('Settings'), 'manage_options', WPFront_User_Role_Editor_Options::MENU_SLUG, array($this->options, 'settings'), NULL, NULL, $this->options);
267
- }
268
-
269
- ksort($this->admin_menu);
270
-
271
- if (!empty($this->admin_menu)) {
272
- $menu_capability = reset($this->admin_menu);
273
- $menu_capability = $menu_capability[2];
274
- add_menu_page($this->__('Roles'), $this->__('Roles'), $menu_capability, $menu_slug, null, $this->pluginURL() . 'images/roles_menu.png', '69.999999');
275
- }
276
-
277
- foreach ($this->admin_menu as $key => $value) {
278
- if (!empty($this->remove_admin_menu[$key])) {
279
- continue;
280
- }
281
-
282
- $page_hook_suffix = add_submenu_page($menu_slug, $value[0], $value[1], $value[2], $value[3], $value[4]);
283
- add_action('admin_print_scripts-' . $page_hook_suffix, array($this, $value[5]));
284
- add_action('admin_print_styles-' . $page_hook_suffix, array($this, $value[6]));
285
- if ($value[7] !== NULL)
286
- $value[7]->set_page_hook($page_hook_suffix);
287
- }
288
-
289
- if ($this->objGoPro->has_license()) {
290
- $page_hook_suffix = add_users_page($this->__('Assign Roles | Migrate Users'), $this->__('Assign / Migrate'), 'promote_users', WPFront_User_Role_Editor_Assign_Roles::MENU_SLUG, array($this->objAssignUsers, 'assign_roles'));
291
- $this->objAssignUsers->set_page_hook($page_hook_suffix);
292
- add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'enqueue_role_scripts'));
293
- add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'enqueue_role_styles'));
294
- }
295
- }
296
-
297
- public function admin_bar() {
298
- global $wp_admin_bar;
299
-
300
- foreach ($this->admin_menu as $key => $value) {
301
- if (!empty($value[8])) {
302
- if (current_user_can($value[2])) {
303
- $wp_admin_bar->add_menu(array(
304
- 'parent' => $value[8],
305
- 'id' => $value[3],
306
- 'title' => $value[9],
307
- 'href' => admin_url('admin.php?page=' . $value[3]),
308
- )
309
- );
310
- }
311
- }
312
- }
313
- }
314
-
315
- //add scripts
316
- public function enqueue_role_scripts() {
317
- // $jsRoot = $this->pluginURLRoot . 'js/';
318
-
319
- wp_enqueue_script('jquery');
320
- wp_enqueue_script('postbox');
321
- wp_enqueue_script('jquery-ui-draggable');
322
- }
323
-
324
- //add styles
325
- public function enqueue_role_styles() {
326
- wp_enqueue_style('font-awesome-410', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0');
327
- $styleRoot = $this->pluginURLRoot . 'css/';
328
- wp_enqueue_style('wpfront-user-role-editor-styles', $styleRoot . 'style.css', array(), self::VERSION);
329
- }
330
-
331
- //options page scripts
332
- public function enqueue_options_scripts() {
333
- $this->enqueue_role_scripts();
334
- }
335
-
336
- //options page styles
337
- public function enqueue_options_styles() {
338
- $this->enqueue_role_styles();
339
-
340
- $styleRoot = $this->pluginURLRoot . 'css/';
341
- wp_enqueue_style('wpfront-user-role-editor-options', $styleRoot . 'options.css', array(), self::VERSION);
342
- }
343
-
344
- public function admin_enqueue_styles() {
345
- $styleRoot = $this->pluginURLRoot . 'css/';
346
- wp_enqueue_style('wpfront-user-role-editor-admin-css', $styleRoot . 'admin-style.css', array(), self::VERSION);
347
- }
348
-
349
- public function get_capability_string($capability) {
350
- if ($this->enable_role_capabilities())
351
- return $capability . '_roles';
352
-
353
- return $capability . '_users';
354
- }
355
-
356
- public function permission_denied() {
357
- wp_die($this->__('You do not have sufficient permissions to access this page.'));
358
- }
359
-
360
- public function current_user_can($capability) {
361
- switch ($capability) {
362
- case 'list_roles':
363
- return current_user_can($this->get_capability_string('list'));
364
- case 'edit_roles':
365
- return current_user_can($this->get_capability_string('edit'));
366
- case 'delete_roles':
367
- return current_user_can($this->get_capability_string('delete'));
368
- case 'create_roles':
369
- return current_user_can($this->get_capability_string('create'));
370
- default :
371
- return current_user_can($capability);
372
- }
373
- }
374
-
375
- public function create_nonce($id = '') {
376
- if (empty($_SERVER['REQUEST_URI'])) {
377
- $this->permission_denied();
378
- exit;
379
- return;
380
- }
381
- $referer = $_SERVER['REQUEST_URI'];
382
- echo '<input type = "hidden" name = "_wpnonce' . $id . '" value = "' . wp_create_nonce($referer . $id) . '" />';
383
- echo '<input type = "hidden" name = "_wp_http_referer' . $id . '" value = "' . esc_html($referer) . '" />';
384
- }
385
-
386
- public function verify_nonce($id = '') {
387
- if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
388
- $flag = TRUE;
389
- if (empty($_POST['_wpnonce' . $id])) {
390
- $flag = FALSE;
391
- } else if (empty($_POST['_wp_http_referer' . $id])) {
392
- $flag = FALSE;
393
- } else if (!wp_verify_nonce($_POST['_wpnonce' . $id], $_POST['_wp_http_referer' . $id] . $id)) {
394
- $flag = FALSE;
395
- }
396
-
397
- if (!$flag) {
398
- $this->permission_denied();
399
- exit;
400
- }
401
- }
402
- }
403
-
404
- public function footer() {
405
- return;
406
- ?>
407
- <div class="footer">
408
- <a target="_blank" href="http://wpfront.com/contact/"><?php echo $this->__('Feedback'); ?></a>
409
- |
410
- <a target="_blank" href="http://wpfront.com/donate/"><?php echo $this->__('Buy me a Beer'); ?></a>
411
- </div>
412
- <?php
413
- }
414
-
415
- public function options_page_header($title, $optionsGroupName = self::OPTIONS_GROUP_NAME) {
416
- parent::options_page_header($title, $optionsGroupName);
417
- }
418
-
419
- public function options_page_footer($settingsLink, $FAQLink, $extraLinks = NULL) {
420
- parent::options_page_footer($settingsLink, $FAQLink, $extraLinks);
421
- }
422
-
423
- public function get_capabilities($exclude_custom_post_types = FALSE) {
424
- if (self::$CAPABILITIES != NULL)
425
- return self::$CAPABILITIES;
426
-
427
- self::$CAPABILITIES = array();
428
-
429
- foreach (self::$STANDARD_CAPABILITIES as $key => $value) {
430
- self::$CAPABILITIES[$key] = array();
431
- foreach ($value as $cap => $roles) {
432
- self::$CAPABILITIES[$key][] = $cap;
433
- }
434
- }
435
-
436
- foreach (self::$DEPRECATED_CAPABILITIES as $key => $value) {
437
- self::$CAPABILITIES[$key] = array();
438
- foreach ($value as $cap => $roles) {
439
- self::$CAPABILITIES[$key][] = $cap;
440
- }
441
- }
442
-
443
- reset(self::$OTHER_CAPABILITIES);
444
- $other_key = key(self::$OTHER_CAPABILITIES);
445
-
446
- if ($exclude_custom_post_types) {
447
- foreach (self::$DYNAMIC_CAPS as $cap) {
448
- self::$ROLE_CAPS = array_diff(self::$ROLE_CAPS, array($cap));
449
- self::$OTHER_CAPABILITIES[$other_key][] = $cap;
450
- }
451
- }
452
-
453
- if ($this->enable_role_capabilities())
454
- self::$CAPABILITIES['Roles (WPFront)'] = self::$ROLE_CAPS;
455
-
456
- //gravity forms
457
- self::$OTHER_CAPABILITIES[$other_key] = apply_filters('members_get_capabilities', self::$OTHER_CAPABILITIES[$other_key]);
458
-
459
- global $wp_roles;
460
- if (isset($wp_roles->roles) && is_array($wp_roles->roles)) {
461
- foreach ($wp_roles->roles as $key => $role) {
462
- foreach ($role['capabilities'] as $cap => $value) {
463
- $found = FALSE;
464
- foreach (self::$CAPABILITIES as $g => $wcaps) {
465
- if (in_array($cap, $wcaps)) {
466
- $found = TRUE;
467
- break;
468
- }
469
- }
470
- if (!$found && !in_array($cap, self::$OTHER_CAPABILITIES[$other_key])) {
471
- self::$OTHER_CAPABILITIES[$other_key][] = $cap;
472
- }
473
- }
474
- }
475
- }
476
-
477
- if (!$exclude_custom_post_types) {
478
- $post_types = get_post_types(array(
479
- '_builtin' => FALSE
480
- ));
481
-
482
- $other_caps = self::$OTHER_CAPABILITIES[$other_key];
483
- unset(self::$OTHER_CAPABILITIES[$other_key]);
484
-
485
- foreach ($post_types as $key => $value) {
486
- $post_type_object = get_post_type_object($key);
487
- $caps = $post_type_object->cap;
488
-
489
- if ($post_type_object->capability_type === 'post') {
490
- if ($post_type_object->show_ui)
491
- self::$CUSTOM_POST_TYPES_DEFAULTED[$this->get_custom_post_type_label($post_type_object)] = array();
492
- } else {
493
- $caps = (OBJECT) $this->remove_meta_capabilities((ARRAY) $caps, $other_caps);
494
- $custom_caps = array();
495
- foreach (self::$STANDARD_CAPABILITIES['Posts'] as $key => $value) {
496
- if (isset($caps->$key)) {
497
- $custom_caps[] = $caps->$key;
498
- unset($caps->$key);
499
- } elseif (isset($post_type_object->cap->$key)) {
500
- $custom_caps[] = $post_type_object->cap->$key;
501
- }
502
- }
503
- foreach ($caps as $key => $value) {
504
- if (isset($caps->$key)) {
505
- $custom_caps[] = $caps->$key;
506
- unset($caps->$key);
507
- }
508
- }
509
- self::$OTHER_CAPABILITIES[$this->get_custom_post_type_label($post_type_object)] = $custom_caps;
510
- }
511
- }
512
-
513
- self::$OTHER_CAPABILITIES[$other_key] = $other_caps;
514
- }
515
-
516
- self::$OTHER_CAPABILITIES[$other_key] = array_unique(self::$OTHER_CAPABILITIES[$other_key]);
517
-
518
- foreach (self::$OTHER_CAPABILITIES as $key => $value) {
519
- if (count($value) === 0)
520
- continue;
521
-
522
- //self::$CAPABILITIES[$key] = $value;
523
- self::$CAPABILITIES[$key] = self::$OTHER_CAPABILITIES[$key];
524
-
525
- if ($key != $other_key) {
526
- foreach ($value as $cap) {
527
- self::$OTHER_CAPABILITIES[$other_key] = array_values(array_diff(self::$OTHER_CAPABILITIES[$other_key], array($cap)));
528
- }
529
- }
530
- }
531
-
532
- return self::$CAPABILITIES;
533
- }
534
-
535
- public function add_role_capability($cap) {
536
- self::$ROLE_CAPS[] = $cap;
537
- $this->add_dynamic_capability($cap);
538
- }
539
-
540
- public function add_dynamic_capability($cap) {
541
- self::$DYNAMIC_CAPS[$cap] = $cap;
542
- }
543
-
544
- private function get_custom_post_type_label($post_type_object) {
545
- return $post_type_object->labels->name . ' (' . $post_type_object->name . ')';
546
- }
547
-
548
- private function remove_meta_capabilities($caps, $other_caps) {
549
- foreach ($caps as $key => $value) {
550
- if ($key === 'read') {
551
- unset($caps[$key]);
552
- continue;
553
- }
554
-
555
- if (!in_array($value, $other_caps))
556
- unset($caps[$key]);
557
- }
558
-
559
- if (array_key_exists('create_posts', $caps) && array_key_exists('edit_posts', $caps)) {
560
- if ($caps['create_posts'] === $caps['edit_posts'])
561
- unset($caps['create_posts']);
562
- }
563
-
564
- return $caps;
565
- }
566
-
567
- public function reset_capabilities() {
568
- self::$CAPABILITIES = NULL;
569
-
570
- foreach (self::$OTHER_CAPABILITIES as $key => $value) {
571
- self::$OTHER_CAPABILITIES[$key] = array();
572
- }
573
- }
574
-
575
- public function display_deprecated() {
576
- return $this->options->display_deprecated();
577
- }
578
-
579
- public function enable_role_capabilities() {
580
- return TRUE;
581
- }
582
-
583
- public function remove_nonstandard_capabilities_restore() {
584
- return $this->options->remove_nonstandard_capabilities_restore();
585
- }
586
-
587
- public function override_edit_permissions() {
588
- return $this->options->override_edit_permissions();
589
- }
590
-
591
- public function disable_navigation_menu_permissions() {
592
- return $this->options->disable_navigation_menu_permissions();
593
- }
594
-
595
- public function override_navigation_menu_permissions() {
596
- return $this->options->override_navigation_menu_permissions();
597
- }
598
-
599
- public function customize_permission_custom_post_types() {
600
- return $this->options->customize_permission_custom_post_types();
601
- }
602
-
603
- public function disable_extended_permission_post_types() {
604
- return $this->options->disable_extended_permission_post_types();
605
- }
606
-
607
- public function enable_multisite_only_options($multisite) {
608
- return TRUE;
609
- }
610
-
611
- public function enable_pro_only_options() {
612
- return FALSE;
613
- }
614
-
615
- public function get_assignable_roles($roles = NULL) {
616
- if ($roles === NULL) {
617
- global $wp_roles;
618
- $roles = $wp_roles->roles;
619
- }
620
-
621
- $roles = $this->objUserPermissions->assignable_roles($roles);
622
- $all_roles = array();
623
-
624
- foreach ($roles as $key => $value) {
625
- $all_roles[$key] = get_role($key);
626
- }
627
-
628
- return $all_roles;
629
- }
630
-
631
- public function menu_walker_override_warning() {
632
- $this->objNavMenu->menu_walker_override_warning();
633
- }
634
-
635
- public function get_extendable_post_types() {
636
- return array();
637
- }
638
-
639
- private function rename_role_capabilities() {
640
- global $wp_roles;
641
-
642
- //removed in v2.5 but in wrong place.
643
- // foreach ($wp_roles->role_objects as $key => $role) {
644
- // foreach (self::$ROLE_CAPS as $value) {
645
- // if ($role->has_cap('wpfront_' . $value)) {
646
- // $role->add_cap($value);
647
- // $role->remove_cap('wpfront_' . $value);
648
- // }
649
- // }
650
- // }
651
-
652
- $role_admin = $wp_roles->role_objects[self::ADMINISTRATOR_ROLE_KEY];
653
- foreach (self::$ROLE_CAPS as $value) {
654
- $role_admin->add_cap($value);
655
- }
656
- }
657
-
658
- public static function Instanciate($file) {
659
- if (defined('WPFRONT_USER_ROLE_EDITOR_PLUGIN_FILE'))
660
- return;
661
-
662
- $f = 'wpfront-user-role-editor.php';
663
- $current_folder = strtolower(basename(dirname($file)));
664
-
665
- $folder = 'wpfront-user-role-editor-business-pro';
666
- if ($current_folder === $folder) {
667
- define('WPFRONT_USER_ROLE_EDITOR_PLUGIN_FILE', $file);
668
- new WPFront_User_Role_Editor_Business_Pro_Base();
669
- return;
670
- }
671
-
672
- if (!function_exists('is_plugin_active'))
673
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
674
-
675
- if (is_plugin_active($folder . '/' . $f))
676
- return;
677
-
678
- $folder = 'wpfront-user-role-editor-personal-pro';
679
- if ($current_folder === $folder) {
680
- define('WPFRONT_USER_ROLE_EDITOR_PLUGIN_FILE', $file);
681
- new WPFront_User_Role_Editor_Personal_Pro_Base();
682
- return;
683
- }
684
-
685
- if (is_plugin_active($folder . '/' . $f))
686
- return;
687
-
688
- define('WPFRONT_USER_ROLE_EDITOR_PLUGIN_FILE', $file);
689
- new WPFront_User_Role_Editor();
690
- }
691
-
692
- public static function wp_remote_get($url, $params = NULL) {
693
- if ($params === NULL) {
694
- $params = array('timeout' => 10);
695
- } else {
696
- $params = array_merge(array('timeout' => 10), $params);
697
- }
698
-
699
- $params['sslverify'] = FALSE;
700
-
701
- $result = wp_remote_post($url, $params);
702
-
703
- if (is_wp_error($result) || wp_remote_retrieve_response_code($result) !== 200) {
704
- $params['sslverify'] = TRUE;
705
- $result = wp_remote_post($url, $params);
706
- }
707
-
708
- return $result;
709
- }
710
-
711
- }
712
-
713
- }
714
-
715
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-controller-base.php");
716
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-options.php");
717
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-list.php");
718
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-add-edit.php");
719
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-delete.php");
720
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-restore.php");
721
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-add-remove-capability.php");
722
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-assign-roles.php");
723
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-go-pro.php");
724
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-nav-menu.php");
725
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-login-redirect.php");
726
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-attachment-permissions.php");
727
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-user-permissions.php");
728
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-widget-permissions.php");
729
- require_once(plugin_dir_path(__FILE__) . "class-wpfront-user-role-editor-shortcodes.php");
730
- require_once(plugin_dir_path(__FILE__) . "integration/plugins/class-wpfront-user-role-editor-plugin-integration.php");
731
-
732
-
733
-
734
- if (file_exists(plugin_dir_path(__FILE__) . "personal-pro/class-wpfront-user-role-editor-personal-pro.php"))
735
- require_once(plugin_dir_path(__FILE__) . "personal-pro/class-wpfront-user-role-editor-personal-pro.php");
736
-
737
- if (file_exists(plugin_dir_path(__FILE__) . "business-pro/class-wpfront-user-role-editor-business-pro.php"))
738
- require_once(plugin_dir_path(__FILE__) . "business-pro/class-wpfront-user-role-editor-business-pro.php");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/entities/class-wpfront-user-role-editor-entity-login-redirect.php DELETED
@@ -1,150 +0,0 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit();
5
- }
6
-
7
- require_once(plugin_dir_path(__FILE__) . "../class-wpfront-user-role-editor-entity-base.php");
8
-
9
- if (!class_exists('WPFront_User_Role_Editor_Entity_Login_Redirect')) {
10
-
11
- /**
12
- * Login Redirect Entity
13
- *
14
- * @author Syam Mohan <syam@wpfront.com>
15
- * @copyright 2015 WPFront.com
16
- */
17
- class WPFront_User_Role_Editor_Entity_Login_Redirect extends WPFront_User_Role_Editor_Entity_Base {
18
-
19
- public function __construct() {
20
- parent::__construct('login_redirect');
21
- }
22
-
23
- protected function _db_data() {
24
- $logout_url = $this->db_data_field('logout_url', 'varchar(2000)');
25
- $logout_url->default = "''";
26
-
27
- return array(
28
- $this->db_data_field('role', 'varchar(250)'),
29
- $this->db_data_field('priority', 'int'),
30
- $this->db_data_field('url', 'varchar(2000)'),
31
- $this->db_data_field('deny_wpadmin', 'bit'),
32
- $this->db_data_field('disable_toolbar', 'bit'),
33
- $logout_url
34
- );
35
- }
36
-
37
- public function count($search = '') {
38
- if (empty($search))
39
- return parent::count();
40
-
41
- global $wpdb;
42
-
43
- $sql = $wpdb->prepare("role LIKE %s OR url LIKE %s", "%$search%", "%$search%");
44
- return parent::count($sql);
45
- }
46
-
47
- public function get_all_login_redirect($search = '') {
48
- if (!empty($search)) {
49
- global $wpdb;
50
- $search = $wpdb->prepare("role LIKE %s OR url LIKE %s", "%$search%", "%$search%");
51
- }
52
-
53
- $data = parent::get_all(array('priority' => FALSE), -1, -1, $search);
54
-
55
- global $wp_roles;
56
- $roles = $wp_roles->get_names();
57
- $entities = array();
58
-
59
- foreach ($data as $value) {
60
- if (isset($roles[$value->get_role()])) {
61
- $entities[] = $value;
62
- }
63
- }
64
-
65
- return $entities;
66
- }
67
-
68
- public function get_next_priority() {
69
- $sql = "SELECT MAX(priority) FROM " . $this->table_name();
70
-
71
- global $wpdb;
72
- $result = $wpdb->get_var($sql);
73
-
74
- return intval($result) + 1;
75
- }
76
-
77
- public function add() {
78
- $priority = $this->get_next_priority();
79
- if ($this->get_priority() > $priority)
80
- $this->set_priority($priority);
81
-
82
- if ($this->get_priority() < 1)
83
- $this->set_priority(1);
84
-
85
- $sql = "UPDATE " . $this->table_name() . " "
86
- . "SET priority = priority + 1 "
87
- . "WHERE priority >= " . $this->get_priority();
88
- global $wpdb;
89
- $wpdb->query($sql);
90
-
91
- parent::add();
92
- }
93
-
94
- public function update() {
95
- $priority = $this->get_next_priority() - 1;
96
- if ($this->get_priority() > $priority)
97
- $this->set_priority($priority);
98
-
99
- if ($this->get_priority() < 1)
100
- $this->set_priority(1);
101
-
102
- $sql = "SELECT priority "
103
- . "FROM " . $this->table_name() . " "
104
- . "WHERE id = " . $this->get_id();
105
- global $wpdb;
106
- $current_priority = $wpdb->get_var($sql);
107
- $new_priority = $this->get_priority();
108
-
109
- if ($current_priority < $new_priority) {
110
- $sql = "UPDATE " . $this->table_name() . " "
111
- . "SET priority = priority - 1 "
112
- . "WHERE priority > $current_priority AND priority <= $new_priority";
113
- $wpdb->query($sql);
114
- }
115
-
116
- if ($current_priority > $new_priority) {
117
- $sql = "UPDATE " . $this->table_name() . " "
118
- . "SET priority = priority + 1 "
119
- . "WHERE priority >= $new_priority AND priority < $current_priority";
120
- $wpdb->query($sql);
121
- }
122
-
123
- parent::update();
124
- }
125
-
126
- public function delete() {
127
- $sql = "SELECT priority "
128
- . "FROM " . $this->table_name() . " "
129
- . "WHERE id = " . $this->get_id();
130
- global $wpdb;
131
- $current_priority = $wpdb->get_var($sql);
132
-
133
- $sql = "UPDATE " . $this->table_name() . " "
134
- . "SET priority = priority - 1 "
135
- . "WHERE priority > $current_priority";
136
- $wpdb->query($sql);
137
-
138
- parent::delete();
139
- }
140
-
141
- public static function uninstall() {
142
- self::$UNINSTALL = TRUE;
143
-
144
- $entity = new WPFront_User_Role_Editor_Entity_Login_Redirect();
145
- $entity->uninstall_action();
146
- }
147
-
148
- }
149
-
150
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/entities/class-wpfront-user-role-editor-entity-options.php DELETED
@@ -1,63 +0,0 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit();
5
- }
6
-
7
- require_once(plugin_dir_path(__FILE__) . "../class-wpfront-user-role-editor-entity-base.php");
8
-
9
- if (!class_exists('WPFront_User_Role_Editor_Entity_Options')) {
10
-
11
- /**
12
- * Options Entity
13
- *
14
- * @author Syam Mohan <syam@wpfront.com>
15
- * @copyright 2014 WPFront.com
16
- */
17
- class WPFront_User_Role_Editor_Entity_Options extends WPFront_User_Role_Editor_Entity_Base {
18
-
19
- public function __construct() {
20
- parent::__construct('options');
21
- }
22
-
23
- protected function _db_data() {
24
- return array(
25
- $this->db_data_field('option_name', 'varchar(250)'),
26
- $this->db_data_field('option_value', 'longtext')
27
- );
28
- }
29
-
30
- public function get_option($key) {
31
- $entity = $this->get_by_option_name($key);
32
- if($entity === NULL)
33
- return NULL;
34
-
35
- return $entity->get_option_value();
36
- }
37
-
38
- public function update_option($key, $value) {
39
- $entity = $this->get_by_option_name($key);
40
- if($entity === NULL) {
41
- $entity = new WPFront_User_Role_Editor_Entity_Options();
42
- $entity->set_option_name($key);
43
- }
44
- $entity->set_option_value($value);
45
- $entity->save();
46
- }
47
-
48
- public function delete_option($key) {
49
- $entity = $this->get_by_option_name($key);
50
- if($entity !== NULL)
51
- $entity->delete();
52
- }
53
-
54
- public static function uninstall() {
55
- self::$UNINSTALL = TRUE;
56
-
57
- $entity = new WPFront_User_Role_Editor_Entity_Options();
58
- $entity->uninstall_action();
59
- }
60
-
61
- }
62
-
63
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/admin-style.css DELETED
@@ -1,3 +0,0 @@
1
- #adminmenu ul.wp-submenu li a span.wpfront-go-pro {
2
- color: #F18500;
3
- }
 
 
 
css/options.css DELETED
@@ -1,3 +0,0 @@
1
- #icon-wpfront-user-role-editor {
2
- background: url("../images/settings32x32.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
3
- }
 
 
 
css/style.css DELETED
@@ -1,170 +0,0 @@
1
- /*
2
- WPFront User Role Editor Plugin
3
- Copyright (C) 2014, WPFront.com
4
- Website: wpfront.com
5
- Contact: syam@wpfront.com
6
-
7
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
8
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
9
- St, Fifth Floor, Boston, MA 02110, USA
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
12
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
15
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
17
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
- */
22
-
23
- #adminmenu ul.wp-submenu li.current a.current span.wpfront-go-pro {
24
- color: inherit;
25
- }
26
-
27
- div.wrap div.footer {
28
- text-align: center;
29
- }
30
-
31
- #wpfront-user-role-editor-options table div.options-list {
32
- float: left;
33
- width: 200px;
34
- }
35
-
36
- div.list-roles img.user-default {
37
- width: 16px;
38
- height: 16px;
39
- }
40
-
41
- div.list-roles table div.row-actions {
42
- /*white-space: nowrap;*/
43
- }
44
-
45
- @media screen and (max-width:782px) {
46
- div.list-roles table .column-roletype,
47
- div.list-roles table .column-userdefault,
48
- div.list-roles table .column-usercount,
49
- div.list-roles table .column-capscount,
50
- div.list-roles table .column-edited_menu_column_key {
51
- display: none;
52
- }
53
- }
54
-
55
- div.role-add-new form#createuser table.sub-head {
56
- width: 100%;
57
- }
58
-
59
- div.role-add-new form#createuser table.sub-head th.sub-head {
60
- text-align: left;
61
- padding: 0px;
62
- }
63
-
64
- div.role-add-new form#createuser table.sub-head th.sub-head h3 {
65
- }
66
-
67
- div.role-add-new form#createuser table.sub-head td.sub-head-controls {
68
- text-align: right;
69
- padding: 0px;
70
- }
71
-
72
- div.role-add-new form#createuser table.sub-head td.sub-head-controls div {
73
- display: inline-block;
74
- vertical-align: top;
75
- }
76
-
77
- div.role-add-new form#createuser table.sub-head td.sub-head-controls div.spacer {
78
- width: 10px;
79
- height: 0px;
80
- }
81
-
82
- div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-all, div.role-add-new form#createuser table.sub-head td.sub-head-controls input.select-none {
83
- width: 100px;
84
- }
85
-
86
- #wpbody-content div.role-add-new div.metabox-holder {
87
- padding-top: 0px;
88
- }
89
-
90
- div.role-add-new div.metabox-holder div.postbox {
91
- margin-bottom: 8px;
92
- }
93
-
94
- div.role-add-new div.metabox-holder .deprecated {
95
- filter: alpha(opacity=80);
96
- opacity: 0.8;
97
- }
98
-
99
- div.role-add-new div.metabox-holder div.postbox h3.hndle {
100
-
101
- }
102
-
103
- div.role-add-new div.metabox-holder div.postbox div.inside div.main div {
104
- padding: 2px 0px;
105
- display: inline-block;
106
- width: 250px;
107
- }
108
-
109
- div.role-add-new div.metabox-holder div.postbox div.inside div.main div.no-capability {
110
- width: auto;
111
- }
112
-
113
- div.role-add-new div.metabox-holder div.postbox label {
114
- vertical-align: top;
115
- max-width: 205px;
116
- overflow: hidden;
117
- display: inline-block;
118
- white-space: nowrap;
119
- text-overflow: ellipsis;
120
- }
121
-
122
- div.role-add-new div.metabox-holder div.postbox h3.hndle label {
123
- max-width: 85%;
124
- }
125
-
126
- div.role-add-new div.metabox-holder div.postbox div.main img.help {
127
- width: 12px;
128
- height: 12px;
129
- opacity: 0.8;
130
- }
131
-
132
- div.role-add-new div.footer {
133
- text-align: center;
134
- }
135
-
136
- div.role-restore table.form-table td div.restore-role-button-container,
137
- div.role-restore table.form-table td div.restore-role-loader,
138
- div.role-restore table.form-table td div.restore-role-success {
139
- display: none;
140
- }
141
-
142
- div.wrap.assign-roles div.role-list div.role-list-item {
143
- padding-bottom: 5px;
144
- }
145
-
146
- div.wrap.go-pro div.license-container {
147
- margin-bottom: 25px;
148
- }
149
-
150
- div.wrap.go-pro #license_key {
151
- padding-top: 5px;
152
- padding-bottom: 5px;
153
- }
154
-
155
- div.wrap.go-pro div.license-container table.form-table td.invalid,
156
- div.wrap.go-pro div.license-container table.form-table td.expired {
157
- color: red;
158
- }
159
-
160
- div.wrap.login-redirect table.wp-list-table .column-priority,
161
- div.wrap.login-redirect table.wp-list-table .column-deny_wpadmin,
162
- div.wrap.login-redirect table.wp-list-table .column-disable_toolbar {
163
- width: 10%;
164
- text-align: center;
165
- }
166
-
167
- div.wrap.login-redirect table.wp-list-table .column-url,
168
- div.wrap.login-redirect table.wp-list-table .column-logout_url{
169
- width: 50%;
170
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
images/check-icon.png DELETED
Binary file
images/copy16x16.png DELETED
Binary file
images/green_dot_64x64.png DELETED
Binary file
images/help.png DELETED
Binary file
images/orange_dot_64x64.png DELETED
Binary file
images/roles_menu.png DELETED
Binary file
images/settings32x32.png DELETED
Binary file
includes/add-remove-cap/class-add-remove-cap.php ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Controller for WPFront User Role Editor Add Edit Capability
27
+ *
28
+ * @author Syam Mohan <syam@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Bulk_Edit;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
40
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
41
+ use WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit as BulkEdit;
42
+
43
+ require_once dirname(__FILE__) . '/template-add-remove-cap.php';
44
+
45
+ if (!class_exists('\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Add_Remove_Cap')) {
46
+
47
+ /**
48
+ * Restore Role
49
+ *
50
+ * @author Syam Mohan <syam@wpfront.com>
51
+ * @copyright 2014 WPFront.com
52
+ */
53
+ class WPFront_User_Role_Editor_Add_Remove_Cap extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller implements iWPFront_URE_Bulk_Edit_Controller {
54
+
55
+ const CAP = 'edit_roles';
56
+
57
+ protected $RolesList;
58
+ private $error = null;
59
+
60
+ protected function setUp() {
61
+ $this->_setUp('edit_roles', '');
62
+
63
+ $this->RolesList = \WPFront\URE\Roles\WPFront_User_Role_Editor_Roles_List::instance();
64
+ }
65
+
66
+ protected function initialize() {
67
+
68
+ }
69
+
70
+ /**
71
+ * Hooks into wpfront_ure_bulk_edit_controllers.
72
+ */
73
+ public static function register($controllers) {
74
+ return static::instance()->_register($controllers);
75
+ }
76
+
77
+ protected function _register($controllers) {
78
+ if (!$this->in_admin_ui()) {
79
+ return $controllers;
80
+ }
81
+
82
+ if (current_user_can($this->get_cap())) {
83
+ $controllers[] = static::instance();
84
+ }
85
+
86
+ return $controllers;
87
+ }
88
+
89
+ /**
90
+ * Called from Bulk Edit screen. Add/Remove cap logic.
91
+ *
92
+ * @return void
93
+ */
94
+ public function load_view() {
95
+ if (!parent::load_view()) {
96
+ return;
97
+ }
98
+
99
+ add_filter('editable_roles', array($this, 'editable_roles_filter_callback'), PHP_INT_MAX, 1);
100
+
101
+ $this->set_help_tab();
102
+
103
+ if (!empty($_POST['submit'])) {
104
+ check_admin_referer('add-remove-capability');
105
+
106
+ if (empty($_POST['action_type'])) {
107
+ return;
108
+ }
109
+ $action_type = $_POST['action_type'];
110
+ if (!in_array($action_type, array('add', 'remove'))) {
111
+ return;
112
+ }
113
+
114
+ if (!isset($_POST['capability'])) {
115
+ return;
116
+ }
117
+ $capability = trim($_POST['capability']);
118
+
119
+ if ($capability == '') {
120
+ $this->error = __('Invalid capability.', 'wpfront-user-role-editor');
121
+ return;
122
+ }
123
+
124
+ if ($action_type == 'add' && !$this->RolesHelperClass::is_super_admin()) {
125
+ //network caps check
126
+ if ($this->RolesHelperClass::is_network_capability($capability)) {
127
+ $this->error = __('You must be a Super Admin to add this capability.', 'wpfront-user-role-editor');
128
+ return;
129
+ }
130
+ }
131
+
132
+ $denied_cap = !empty($_POST['denied_cap']);
133
+
134
+ if (empty($_POST['roles_type'])) {
135
+ return;
136
+ }
137
+ $roles_type = $_POST['roles_type'];
138
+ if (!in_array($roles_type, array('all', 'selected'))) {
139
+ return;
140
+ }
141
+
142
+ if ($roles_type == 'selected') {
143
+ if (empty($_POST['selected-roles'])) {
144
+ $_POST['selected-roles'] = array();
145
+ }
146
+
147
+ if (!is_array($_POST['selected-roles'])) {
148
+ return;
149
+ }
150
+
151
+ $selected_roles = $_POST['selected-roles'];
152
+
153
+ unset($selected_roles[RolesHelper::ADMINISTRATOR_ROLE_KEY]);
154
+
155
+ $selected_roles = array_keys($selected_roles);
156
+ $selected_roles = array_intersect($selected_roles, array_keys($this->get_editable_roles()));
157
+ } else {
158
+ $selected_roles = array_keys($this->get_editable_roles());
159
+ }
160
+
161
+ $count = 0;
162
+
163
+ foreach ($selected_roles as $role) {
164
+ $role_object = get_role($role);
165
+ if (empty($role_object)) {
166
+ continue;
167
+ }
168
+
169
+ if ($action_type == 'add') {
170
+ if ($role == RolesHelper::ADMINISTRATOR_ROLE_KEY) {
171
+ $role_object->add_cap($capability);
172
+ } else {
173
+ $role_object->add_cap($capability, !$denied_cap);
174
+ }
175
+ } else {
176
+ $role_object->remove_cap($capability);
177
+ }
178
+
179
+ $count++;
180
+ }
181
+
182
+ if ($action_type == 'add' && !in_array(RolesHelper::ADMINISTRATOR_ROLE_KEY, $selected_roles)) {
183
+ $role_object = get_role(RolesHelper::ADMINISTRATOR_ROLE_KEY);
184
+ if (!empty($role_object)) {
185
+ $role_object->add_cap($capability);
186
+ $count++;
187
+ }
188
+ }
189
+
190
+ $url = BulkEdit::instance()->get_screen_url($this) . '&changes-saved=' . $count;
191
+ wp_safe_redirect($url);
192
+ exit();
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Displays the add/edit role view.
198
+ */
199
+ public function view() {
200
+ if (!parent::view()) {
201
+ return;
202
+ }
203
+
204
+ $objView = new WPFront_User_Role_Editor_Add_Remove_Cap_View();
205
+ $objView->view($this->error);
206
+ }
207
+
208
+ /**
209
+ * Hooks into editable_roles WordPress filter.
210
+ * @param array $roles
211
+ * @return array
212
+ */
213
+ public function editable_roles_filter_callback($roles) {
214
+ if ($this->RolesHelperClass::is_super_admin()) {
215
+ return wp_roles()->roles;
216
+ }
217
+
218
+ if ($this->RolesList->override_edit_permissions()) {
219
+ $roles = wp_roles()->roles;
220
+ }
221
+
222
+ return $roles;
223
+ }
224
+
225
+ /**
226
+ * Returns roles with their display names.
227
+ *
228
+ * @return string[] Associative (name=>display).
229
+ */
230
+ public function get_editable_roles() {
231
+ $roles = RolesHelper::get_names();
232
+ if (!$this->RolesList->override_edit_permissions()) {
233
+ unset($roles[RolesHelper::ADMINISTRATOR_ROLE_KEY]);
234
+ }
235
+
236
+ $editable_roles = get_editable_roles();
237
+
238
+ return array_intersect_key($roles, $editable_roles);
239
+ }
240
+
241
+ /**
242
+ * Sets the help tab
243
+ */
244
+ protected function set_help_tab() {
245
+ $tabs = array(
246
+ array(
247
+ 'id' => 'overview',
248
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
249
+ 'content' => '<p>'
250
+ . __('This screen allows you to add a capability to roles or remove a capability from roles within your site.', 'wpfront-user-role-editor')
251
+ . '</p>'
252
+ ),
253
+ array(
254
+ 'id' => 'action',
255
+ 'title' => __('Action', 'wpfront-user-role-editor'),
256
+ 'content' => '<p>'
257
+ . __('Select "Add Capability" to add a capability to roles.', 'wpfront-user-role-editor')
258
+ . '</p>'
259
+ . '<p>'
260
+ . __('Select "Remove Capability" to remove a capability from roles.', 'wpfront-user-role-editor')
261
+ . '</p>'
262
+ ),
263
+ array(
264
+ 'id' => 'capability',
265
+ 'title' => __('Capability', 'wpfront-user-role-editor'),
266
+ 'content' => '<p>'
267
+ . __('Use the Capability field to name the capability to be added or removed.', 'wpfront-user-role-editor')
268
+ . '</p>'
269
+ ),
270
+ array(
271
+ 'id' => 'denied-capability',
272
+ 'title' => __('Denied Capability', 'wpfront-user-role-editor'),
273
+ 'content' => '<p>'
274
+ . __('If checked, this capability will be denied for the selected roles. Except "Administrator" role, which will have this capability enabled.', 'wpfront-user-role-editor')
275
+ . '</p>'
276
+ ),
277
+ array(
278
+ 'id' => 'roles',
279
+ 'title' => __('Roles', 'wpfront-user-role-editor'),
280
+ 'content' => '<p><strong>'
281
+ . __('All Roles', 'wpfront-user-role-editor')
282
+ . '</strong>: ' . __('Select "All Roles", if you want the current action to be applied to all roles within your site.', 'wpfront-user-role-editor')
283
+ . '</p>'
284
+ . '<p><strong>'
285
+ . __('Selected Roles', 'wpfront-user-role-editor')
286
+ . '</strong>: ' . __('Select "Selected Roles", if you want to individually select the roles. When this option is selected, "Administrator" role is included by default on "Add Capability" action and excluded by default on "Remove Capability" action.', 'wpfront-user-role-editor')
287
+ . '</p>'
288
+ )
289
+ );
290
+
291
+ $sidebar = array(
292
+ array(
293
+ __('Documentation on Add/Remove Capability', 'wpfront-user-role-editor'),
294
+ 'add-remove-capability/'
295
+ )
296
+ );
297
+
298
+ Utils::set_help_tab($tabs, $sidebar);
299
+ }
300
+
301
+ /**
302
+ * Bulk edit screen key.
303
+ *
304
+ * @return string
305
+ */
306
+ public function get_key() {
307
+ return 'add-remove-cap';
308
+ }
309
+
310
+ /**
311
+ * Called from Bulk Edit. Text displayed on bulk edit selection.
312
+ *
313
+ * @return string
314
+ */
315
+ public function get_option_text() {
316
+ return __('Add or Remove Capability', 'wpfront-user-role-editor');
317
+ }
318
+
319
+ }
320
+
321
+ add_filter('wpfront_ure_bulk_edit_controllers', '\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Add_Remove_Cap::register', 1);
322
+ }
{classes/integration → includes/add-remove-cap}/index.php RENAMED
File without changes
includes/add-remove-cap/template-add-remove-cap.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Add or Remove Cap
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Bulk_Edit;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Add_Remove_Cap as Add_Remove_Cap;
40
+ use WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit as Bulk_Edit;
41
+
42
+ if(!class_exists('WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Add_Remove_Cap_View')) {
43
+
44
+ class WPFront_User_Role_Editor_Add_Remove_Cap_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
45
+
46
+ private $error = null;
47
+
48
+ public function view($error) {
49
+ $this->error = $error;
50
+ ?>
51
+ <div class="wrap add-remove-capability">
52
+ <?php $this->title(); ?>
53
+ <form method="post" class="validate" action="<?php echo Bulk_Edit::instance()->get_screen_url(Add_Remove_Cap::instance()); ?>">
54
+ <table class="form-table">
55
+ <tbody>
56
+ <?php $this->action_row(); ?>
57
+ <?php $this->capability_row(); ?>
58
+ <?php $this->denied_cap_row(); ?>
59
+ <?php $this->roles_row(); ?>
60
+ </tbody>
61
+ </table>
62
+ <?php wp_nonce_field('add-remove-capability'); ?>
63
+ <?php submit_button(); ?>
64
+ </form>
65
+ </div>
66
+ <?php $this->scripts(); ?>
67
+ <?php
68
+ }
69
+
70
+ protected function title($title = '', $add_new = array(), $search = null) {
71
+ ?>
72
+ <h2><?php echo __('Add/Remove Capability', 'wpfront-user-role-editor'); ?></h2>
73
+ <?php $this->display_notices(); ?>
74
+ <p>
75
+ <?php echo __('Add/Remove a capability to/from roles within this site.', 'wpfront-user-role-editor'); ?>
76
+ </p>
77
+ <?php
78
+ }
79
+
80
+ protected function display_notices() {
81
+ if(!empty($this->error)) {
82
+ Utils::notice_error($this->error);
83
+ } elseif(isset($_GET['changes-saved'])) {
84
+ Utils::notice_updated($_GET['changes-saved'] . ' ' . __('role(s) updated.', 'wpfront-user-role-editor'));
85
+ }
86
+ }
87
+
88
+ protected function action_row() {
89
+ ?>
90
+ <tr>
91
+ <th scope="row">
92
+ <label>
93
+ <?php echo __('Action', 'wpfront-user-role-editor'); ?>
94
+ </label>
95
+ </th>
96
+ <td>
97
+ <fieldset>
98
+ <label><input name="action_type" type="radio" value="add" <?php echo $this->get_current_action() === 'add' ? 'checked' : ''; ?> /><?php echo __('Add Capability', 'wpfront-user-role-editor'); ?></label>
99
+ <br />
100
+ <label><input name="action_type" type="radio" value="remove" <?php echo $this->get_current_action() === 'remove' ? 'checked' : ''; ?> /><?php echo __('Remove Capability', 'wpfront-user-role-editor'); ?></label>
101
+ </fieldset>
102
+ </td>
103
+ </tr>
104
+ <?php
105
+ }
106
+
107
+ protected function capability_row() {
108
+ ?>
109
+ <tr class="form-required <?php echo $this->is_capability_field_invalid() ? 'form-invalid' : ''; ?>">
110
+ <th scope="row">
111
+ <label for="capability">
112
+ <?php echo __('Capability', 'wpfront-user-role-editor'); ?> <span class="description">(<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
113
+ </label>
114
+ </th>
115
+ <td>
116
+ <input class="regular-text" name="capability" type="text" id="capability" value="<?php echo $this->get_current_capability(); ?>" aria-required="true" />
117
+ </td>
118
+ </tr>
119
+ <?php
120
+ }
121
+
122
+ protected function denied_cap_row() {
123
+ ?>
124
+ <tr>
125
+ <th scope="row">
126
+ <label for="denied_cap">
127
+ <?php echo __('Add as "Denied Capability"', 'wpfront-user-role-editor'); ?>
128
+ </label>
129
+ </th>
130
+ <td>
131
+ <input id="denied_cap" name="denied_cap" type="checkbox" value="add" <?php echo $this->get_current_denied_cap() ? 'checked' : ''; ?> <?php echo $this->get_current_action() === 'remove' ? 'disabled' : ''; ?> />
132
+ </td>
133
+ </tr>
134
+ <?php
135
+ }
136
+
137
+ protected function roles_row() {
138
+ ?>
139
+ <tr>
140
+ <th scope="row">
141
+ <label>
142
+ <?php echo __('Roles', 'wpfront-user-role-editor'); ?>
143
+ </label>
144
+ </th>
145
+ <td>
146
+ <fieldset>
147
+ <label><input name="roles_type" type="radio" value="all" <?php echo $this->get_current_roles_type() === 'all' ? 'checked' : ''; ?> /><?php echo __('All Roles', 'wpfront-user-role-editor'); ?></label>
148
+ <br />
149
+ <label><input name="roles_type" type="radio" value="selected" <?php echo $this->get_current_roles_type() === 'selected' ? 'checked' : ''; ?> /><?php echo __('Selected Roles', 'wpfront-user-role-editor'); ?></label>
150
+ <div class="<?php echo $this->get_current_roles_type() === 'all' ? 'hidden' : ''; ?>">
151
+ <?php
152
+ $admin_role = $this->RolesHelperClass::get_display_name($this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY);
153
+ if(!empty($admin_role)) {
154
+ ?>
155
+ <label><input id="chk_admin" type="checkbox" disabled="true" <?php echo $this->get_current_action() === 'add' ? 'checked' : ''; ?> /><?php echo $admin_role; ?></label>
156
+ <br />
157
+ <?php
158
+ }
159
+
160
+ $roles = $this->get_roles();
161
+ $selected_roles = $this->get_current_selected_roles();
162
+ foreach ($roles as $role_name => $role_display) {
163
+ ?>
164
+ <label><input type="checkbox" name="selected-roles[<?php echo $role_name; ?>]" <?php echo array_key_exists($role_name, $selected_roles) ? 'checked' : ''; ?> /><?php echo $role_display; ?></label>
165
+ <br />
166
+ <?php
167
+ }
168
+ ?>
169
+ </div>
170
+ </fieldset>
171
+ </td>
172
+ </tr>
173
+ <?php
174
+ }
175
+
176
+ protected function get_roles() {
177
+ $roles = Add_Remove_Cap::instance()->get_editable_roles();
178
+ unset($roles[$this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY]);
179
+ return $roles;
180
+ }
181
+
182
+ protected function get_current_action() {
183
+ if(!empty($_POST['action_type'])) {
184
+ if($_POST['action_type'] === 'remove') {
185
+ return 'remove';
186
+ }
187
+ }
188
+
189
+ return 'add';
190
+ }
191
+
192
+ protected function get_current_capability() {
193
+ if(!empty($_POST['capability'])) {
194
+ return $_POST['capability'];
195
+ }
196
+
197
+ return '';
198
+ }
199
+
200
+ protected function get_current_denied_cap() {
201
+ return !empty($_POST['denied_cap']);
202
+ }
203
+
204
+ protected function get_current_roles_type() {
205
+ if(!empty($_POST['roles_type'])) {
206
+ if($_POST['roles_type'] === 'selected') {
207
+ return 'selected';
208
+ }
209
+ }
210
+
211
+ return 'all';
212
+ }
213
+
214
+ protected function get_current_selected_roles() {
215
+ if(!empty($_POST['selected-roles'])) {
216
+ if($_POST['selected-roles']) {
217
+ return $_POST['selected-roles'];
218
+ }
219
+ }
220
+
221
+ return array();
222
+ }
223
+
224
+ protected function is_capability_field_invalid() {
225
+ if(!empty($_POST['submit'])) {
226
+ return empty($_POST['capability']);
227
+ }
228
+
229
+ return false;
230
+ }
231
+
232
+ protected function scripts() {
233
+ ?>
234
+ <script type="text/javascript">
235
+
236
+ (function ($) {
237
+
238
+ var $container = $('div.wrap.add-remove-capability');
239
+
240
+ $container.find('input[name="action_type"]').change(function () {
241
+ if ($(this).val() === 'add') {
242
+ $container.find("#denied_cap").prop('disabled', false);
243
+ $container.find("#chk_admin").prop('checked', true);
244
+ } else {
245
+ $container.find("#denied_cap").prop('disabled', true);
246
+ $container.find("#chk_admin").prop('checked', false);
247
+ }
248
+ });
249
+
250
+ $container.find("#capability").blur(function() {
251
+ var $this = $(this);
252
+
253
+ if($.trim($this.val()) !== "") {
254
+ $this.closest("tr").removeClass("form-invalid");
255
+ }
256
+ });
257
+
258
+ $container.find('input[name="roles_type"]').change(function () {
259
+ if ($(this).val() === 'all') {
260
+ $(this).closest('fieldset').find('div').addClass('hidden');
261
+ } else {
262
+ $(this).closest('fieldset').find('div').removeClass('hidden');
263
+ }
264
+ });
265
+
266
+ $container.find("form").submit(function() {
267
+ var $capability = $container.find("#capability");
268
+ if($.trim($capability.val()) === "") {
269
+ $capability.closest("tr").addClass("form-invalid");
270
+ return false;
271
+ }
272
+ });
273
+
274
+ })(jQuery);
275
+
276
+ </script>
277
+ <?php
278
+ }
279
+
280
+ }
281
+
282
+ }
283
+
includes/bulk-edit/class-bulk-edit-utils.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Utilities for Bulk Edit
26
+ *
27
+ * @author Jinu Varghese
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Bulk_Edit;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+
39
+ if (!class_exists('\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit_Utils')) {
40
+
41
+ /**
42
+ * Bulk Edit Utils class
43
+ *
44
+ * @author Jinu Varghese
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Bulk_Edit_Utils {
48
+
49
+ public static function users_list_view() {
50
+ ?>
51
+ <p>
52
+ <label><input name="select-users" type="radio" value="all" checked="checked" /><?php echo __('All Users', 'wpfront-user-role-editor'); ?></label>
53
+ </p>
54
+ <p>
55
+ <label><input name="select-users" type="radio" value="selected" /><?php echo __('Selected Users', 'wpfront-user-role-editor'); ?></label>
56
+ </p>
57
+ <p class="hidden loading-image">
58
+ <img src="<?php echo URE::instance()->get_asset_url('images/loading.gif'); ?>" />
59
+ </p>
60
+ <p id="users-container" class="hidden"></p>
61
+ <input type="hidden" name="selected-users" />
62
+ <input type="hidden" id="current-user-id" value="<?php echo get_current_user_id() ?>"/>
63
+ <script type="text/javascript">
64
+ (function ($) {
65
+ var $container = $('#users-container');
66
+ $container.closest('form').prop('id', 'users-filter');
67
+
68
+ $("input[name='select-users']").on('change', function () {
69
+ var $this = $(this);
70
+ if ($this.val() === "selected") {
71
+ $container.removeClass("hidden");
72
+ } else {
73
+ $container.addClass("hidden");
74
+ }
75
+ });
76
+
77
+ $container.on('click', "td.column-username a", function (e) {
78
+ e.preventDefault();
79
+ e.stopImmediatePropagation();
80
+
81
+ var $this = $(this);
82
+ var $checkbox = $this.closest('td').prev().find('[type=checkbox]');
83
+ $checkbox.prop("checked", !$checkbox.prop("checked"));
84
+
85
+ setSelectedUsers();
86
+
87
+ return false;
88
+ });
89
+
90
+ $container.on('change', "#cb-select-all-1, #cb-select-all-2, tbody th:first-child input[type='checkbox']", function () {
91
+ setSelectedUsers();
92
+ });
93
+
94
+ function setSelectedUsers() {
95
+ var $current = $container.next().val();
96
+ if ($current === "") {
97
+ $current = ",";
98
+ }
99
+
100
+ $container.find("tbody th:first-child input[type='checkbox']").each(function () {
101
+ var $this = $(this);
102
+ if ($this.prop("checked")) {
103
+ if ($current.indexOf("," + $this.val() + ",") === -1) {
104
+ $current = $current + $this.val() + ",";
105
+ }
106
+ } else {
107
+ $current = $current.replace("," + $this.val() + ",", ",");
108
+ }
109
+ });
110
+
111
+ $container.next().val($.trim($current));
112
+ }
113
+
114
+ function getParam(href, name) {
115
+ href = href.split('?')
116
+ if (href.length > 1) {
117
+ href = href[1];
118
+ var parts = href.split('&');
119
+ for (var i = 0; i < parts.length; i++) {
120
+ var s = parts[i].split('=');
121
+ if (s[0] === name) {
122
+ return s[1];
123
+ }
124
+ }
125
+ }
126
+
127
+ return '';
128
+ }
129
+
130
+ var role = '';
131
+ var search = '';
132
+ var orderby = '';
133
+ var order = '';
134
+ var paged = '';
135
+
136
+ $container.on('click', 'a, #search-submit', function (e) {
137
+ e.preventDefault();
138
+
139
+ var $this = $(this);
140
+ var href = $this.prop('href');
141
+
142
+ if ($this.is('ul.subsubsub a')) {
143
+ role = getParam(href, 'role');
144
+ search = '';
145
+ orderby = '';
146
+ order = '';
147
+ paged = '';
148
+ }
149
+
150
+ if ($this.is('th.column-username a')) {
151
+ orderby = getParam(href, 'orderby');
152
+ order = getParam(href, 'order');
153
+ paged = '';
154
+ }
155
+
156
+ if ($this.is('.pagination-links a')) {
157
+ paged = getParam(href, 'paged');
158
+ }
159
+
160
+ if ($this.is('#search-submit')) {
161
+ search = $('#user-search-input').val();
162
+ paged = '';
163
+ }
164
+
165
+ load_users();
166
+ return false;
167
+ });
168
+
169
+
170
+ function load_users() {
171
+ $container.html("").append($container.prev().clone().removeClass('hidden'));
172
+
173
+ var data = {
174
+ 'role': role,
175
+ 's': search,
176
+ 'orderby': orderby,
177
+ 'order': order,
178
+ 'paged': paged
179
+ };
180
+
181
+ for (var m in data) {
182
+ if (data[m] === '') {
183
+ delete data[m];
184
+ }
185
+ }
186
+
187
+ $.extend(data, {
188
+ "action": "wpfront_ure_bulk_edit_user_post_permissions_users_table",
189
+ "nonce": "<?php echo wp_create_nonce('users-table'); ?>"
190
+ });
191
+
192
+ $.post(ajaxurl, data, function (response) {
193
+ $container.html(response);
194
+
195
+ var current_user_id = $("#current-user-id").val();
196
+ $container.find("input[type='checkbox'][value='" + current_user_id + "']").remove();
197
+
198
+ $container.find("td.column-username a").prop("href", "#");
199
+ $container.find("div.actions").remove();
200
+ $container.find("td.email.column-email > a").contents().unwrap();
201
+ $container.find("th.column-email > a").contents().unwrap();
202
+ $container.find("td.column-posts > a").contents().unwrap();
203
+
204
+ $container.find("tbody th:first-child input[type='checkbox']").each(function () {
205
+ var $this = $(this);
206
+ var $current = "," + $container.next().val() + ",";
207
+ $this.prop("checked", $current.indexOf("," + $this.val() + ",") !== -1);
208
+ });
209
+ });
210
+ }
211
+
212
+ load_users();
213
+
214
+ })(jQuery);
215
+ </script>
216
+ <?php
217
+ }
218
+
219
+ /**
220
+ * Returns an array of user ids
221
+ *
222
+ * @return int[]
223
+ */
224
+ public static function get_user_ids($index, $process_records, $include_current_user = false) {
225
+ $query = array();
226
+
227
+ if(!$include_current_user){
228
+ $current_user_id = get_current_user_id();
229
+ $query['exclude'] = $current_user_id;
230
+ }
231
+
232
+ $query['orderby'] = 'ID';
233
+ $query['order'] = 'ASC';
234
+ $query['offset'] = $index;
235
+ $query['number'] = $process_records;
236
+ $query['fields'] = 'ID';
237
+
238
+ $wp_query = new \WP_User_Query($query);
239
+ $users = $wp_query->get_results();
240
+
241
+ if (empty($users)) {
242
+ return [];
243
+ }
244
+
245
+ return $users;
246
+ }
247
+
248
+ public static function get_post_ids($post_type, $post_id_index, $process_records) {
249
+ $query = array();
250
+
251
+ $query['orderby'] = 'ID';
252
+
253
+ if ($post_id_index !== null) {
254
+ $query['offset'] = $post_id_index;
255
+ } else {
256
+ $query['posts_per_page'] = -1;
257
+ }
258
+
259
+ if ($process_records !== null) {
260
+ $query['posts_per_page'] = $process_records;
261
+ }
262
+
263
+ $query['fields'] = 'ids';
264
+ $query['post_type'] = $post_type;
265
+ $query['post_status'] = 'any';
266
+
267
+ $wp_query = new \WP_Query($query);
268
+ $post_ids = $wp_query->posts;
269
+
270
+ return $post_ids;
271
+ }
272
+
273
+
274
+ /**
275
+ * Returns the user ids to edit.
276
+ *
277
+ * @return string[] all|array
278
+ */
279
+ public static function get_current_selected_users() {
280
+ if (empty($_POST['select-users'])) {
281
+ return null;
282
+ }
283
+ $select_users = $_POST['select-users'];
284
+
285
+ if ($select_users === 'all') {
286
+ return 'all';
287
+ } else {
288
+ if (empty($_POST['selected-users'])) {
289
+ return null;
290
+ }
291
+ $selected_users = $_POST['selected-users'];
292
+ $selected_users = trim($selected_users);
293
+ $selected_users = trim($selected_users, ',');
294
+ if (empty($selected_users)) {
295
+ return null;
296
+ }
297
+
298
+ return explode(',', $selected_users);
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Returns current selected users count.
304
+ *
305
+ * @return int
306
+ */
307
+ public static function get_current_selected_users_count() {
308
+ $selected_users = self::get_current_selected_users();
309
+
310
+ if ($selected_users === 'all') {
311
+ $count = count_users();
312
+ return $count['total_users'] - 1;
313
+ }
314
+
315
+ return count($selected_users);
316
+ }
317
+
318
+ /**
319
+ * Returns the user table on selected users.
320
+ */
321
+ public static function users_table_callback() {
322
+ check_ajax_referer('users-table', 'nonce');
323
+
324
+ $GLOBALS['hook_suffix'] = '';
325
+
326
+ $screen = \WP_Screen::get();
327
+ $screen->id = 'users';
328
+ \WP_Screen::get($screen)->set_current_screen();
329
+
330
+ add_filter('user_row_actions', array(WPFront_User_Role_Editor_Bulk_Edit_Utils::class ,'users_table_row_actions'), PHP_INT_MAX);
331
+ add_filter('bulk_actions-users', array(WPFront_User_Role_Editor_Bulk_Edit_Utils::class, 'users_table_bulk_actions'), PHP_INT_MAX);
332
+
333
+ if (isset($_POST['orderby'])) {
334
+ $_GET['orderby'] = $_POST['orderby'];
335
+ }
336
+
337
+ if (isset($_POST['order'])) {
338
+ $_GET['order'] = $_POST['order'];
339
+ }
340
+
341
+ $wp_list_table = _get_list_table('WP_Users_List_Table');
342
+ $wp_list_table->prepare_items();
343
+ $wp_list_table->views();
344
+ $wp_list_table->search_box(__('Search Users'), 'user');
345
+ $wp_list_table->display();
346
+
347
+ die();
348
+ }
349
+
350
+ public static function users_table_bulk_actions() {
351
+ return array();
352
+ }
353
+
354
+ public static function users_table_row_actions() {
355
+ return array();
356
+ }
357
+ }
358
+
359
+ }
includes/bulk-edit/class-bulk-edit.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Bulk Edit
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Bulk_Edit;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
40
+
41
+ require_once dirname(__FILE__) . '/template-bulk-edit.php';
42
+ require_once dirname(__FILE__) . '/class-bulk-edit-utils.php';
43
+
44
+ if (!class_exists('\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit')) {
45
+
46
+ /**
47
+ * Bulk Edit class
48
+ *
49
+ * @author Syam Mohan <syam@wpfront.com>
50
+ * @copyright 2014 WPFront.com
51
+ */
52
+ class WPFront_User_Role_Editor_Bulk_Edit extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
53
+ const MENU_SLUG = 'wpfront-user-role-editor-bulk-edit';
54
+ const CAP = 'bulk_edit_roles';
55
+
56
+ /**
57
+ *
58
+ * @var iWPFront_URE_Bulk_Edit_Controller[]
59
+ */
60
+ protected $controllers = null;
61
+
62
+ /**
63
+ *
64
+ * @var iWPFront_URE_Bulk_Edit_Controller
65
+ */
66
+ protected $current_controller = null;
67
+
68
+
69
+ protected function setUp() {
70
+ $this->_setUp('bulk_edit_roles', 'wpfront-user-role-editor-bulk-edit');
71
+ }
72
+
73
+ protected function initialize() {
74
+ if(!is_admin()) {
75
+ return;
76
+ }
77
+
78
+ $controllers = self::instance()->get_controllers();
79
+ if(empty($controllers)) {
80
+ return;
81
+ }
82
+
83
+ $this->set_admin_menu(__('Bulk Edit', 'wpfront-user-role-editor'), __('Bulk Edit', 'wpfront-user-role-editor'), 70);
84
+ }
85
+
86
+ /**
87
+ * Allow controllers to completely init from wpfront_ure_init.
88
+ */
89
+ public static function add_hook() {
90
+ add_action('wp_loaded', '\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit::init');
91
+ }
92
+
93
+ /**
94
+ * Apply filter to find controllers and returns.
95
+ *
96
+ * @return iWPFront_URE_Bulk_Edit_Controller[]
97
+ */
98
+ public function get_controllers() {
99
+ if($this->controllers === null) {
100
+ $this->controllers = apply_filters('wpfront_ure_bulk_edit_controllers', array());
101
+
102
+ $controllers = array();
103
+ foreach ($this->controllers as $ctrl) {
104
+ $cap = $ctrl->get_cap();
105
+
106
+ if(current_user_can($cap)) {
107
+ $controllers[] = $ctrl;
108
+ }
109
+ }
110
+
111
+ $this->controllers = $controllers;
112
+ }
113
+
114
+ return $this->controllers;
115
+ }
116
+
117
+ public function admin_print_styles() {
118
+ if(!empty($this->current_controller)) {
119
+ $this->current_controller->admin_print_styles();
120
+ } else {
121
+ wp_enqueue_style('wpfront-user-role-editor-styles', WPFURE::instance()->get_asset_url('css/roles.css'), array(), WPFURE::VERSION);
122
+ }
123
+ }
124
+
125
+ public function admin_print_scripts() {
126
+ if(!empty($this->current_controller)) {
127
+ $this->current_controller->admin_print_scripts();
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Hooks on 'load-view' and sets the current controller.
133
+ */
134
+ public function load_view() {
135
+ if(!parent::load_view()) {
136
+ return;
137
+ }
138
+
139
+ if(isset($_GET['screen'])) {
140
+ $screen = $_GET['screen'];
141
+ $controllers = $this->get_controllers();
142
+ foreach ($controllers as $ctrl) {
143
+ if($ctrl->get_key() === $screen) {
144
+ $this->current_controller = $ctrl;
145
+ break;
146
+ }
147
+ }
148
+ }
149
+
150
+ if(!empty($this->current_controller)) {
151
+ $this->current_controller->load_view();
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Displays the bulk edit view.
157
+ */
158
+ public function view() {
159
+ if(!parent::view()) {
160
+ return;
161
+ }
162
+
163
+ if(!empty($this->current_controller)) {
164
+ $this->current_controller->view();
165
+ return;
166
+ }
167
+
168
+ $objView = new WPFront_User_Role_Editor_Bulk_Edit_View();
169
+ $objView->view();
170
+ }
171
+
172
+ /**
173
+ * Returns the bulk edit screen URL for a controller.
174
+ *
175
+ * @param iWPFront_URE_Bulk_Edit_Controller $controller
176
+ * @return string
177
+ */
178
+ public function get_screen_url($controller) {
179
+ return $this->get_self_url(['screen' => $controller->get_key()]);
180
+ }
181
+
182
+ }
183
+
184
+ add_action('wpfront_ure_init', '\WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit::add_hook');
185
+
186
+ interface iWPFront_URE_Bulk_Edit_Controller {
187
+ public function get_cap();
188
+ public function get_key();
189
+ public function get_option_text();
190
+ public function load_view();
191
+ public function view();
192
+ public function admin_print_styles();
193
+ public function admin_print_scripts();
194
+ }
195
+
196
+ }
{classes/integration/plugins/duplicator → includes/bulk-edit}/index.php RENAMED
File without changes
includes/bulk-edit/template-bulk-edit.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Bulk Edit
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Bulk_Edit;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit as Bulk_Edit;
39
+
40
+ if(!class_exists('WPFront\URE\Bulk_Edit\WPFront_User_Role_Editor_Bulk_Edit_View')) {
41
+
42
+ class WPFront_User_Role_Editor_Bulk_Edit_View {
43
+
44
+ public function view() {
45
+ ?>
46
+ <div class="wrap bulk-edit">
47
+ <?php $this->title(); ?>
48
+ <form method="get">
49
+ <input type="hidden" name="page" value="<?php echo Bulk_Edit::MENU_SLUG; ?>" />
50
+ <div class="options">
51
+ <?php $this->display_options(); ?>
52
+ </div>
53
+ <?php submit_button(__('Next Step', 'wpfront-user-role-editor')); ?>
54
+ </form>
55
+ </div>
56
+ <?php
57
+ }
58
+
59
+ protected function title() {
60
+ ?>
61
+ <h2><?php echo __('Bulk Edit', 'wpfront-user-role-editor'); ?></h2>
62
+ <p>
63
+ <?php echo __('Select an option from below then click next step.', 'wpfront-user-role-editor'); ?>
64
+ </p>
65
+ <?php
66
+ }
67
+
68
+ protected function display_options() {
69
+ $controllers = Bulk_Edit::instance()->get_controllers();
70
+ $select = true;
71
+ foreach ($controllers as $ctlr) {
72
+ ?>
73
+ <p>
74
+ <label><input type="radio" name="screen" value="<?php echo $ctlr->get_key(); ?>" <?php echo $select ? 'checked' : '' ?> /><?php echo $ctlr->get_option_text(); ?></label>
75
+ </p>
76
+ <?php
77
+ $select = false;
78
+ }
79
+ }
80
+
81
+ }
82
+
83
+ }
84
+
includes/class-cache.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Cache for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Cache')) {
38
+
39
+ /**
40
+ * Cache class
41
+ *
42
+ * @author Syam Mohan <syam@wpfront.com>
43
+ * @copyright 2014 WPFront.com
44
+ */
45
+ abstract class WPFront_User_Role_Editor_Cache {
46
+
47
+ private $global_group = null;
48
+ private $group = null;
49
+
50
+ protected function __construct($group, $persist = true) {
51
+ $this->group = 'wpfront_ure_' . $group . '_' . \WPFront\URE\WPFront_User_Role_Editor::VERSION;
52
+
53
+ if(!$persist) {
54
+ wp_cache_add_non_persistent_groups($this->group);
55
+ }
56
+ }
57
+
58
+ protected function cache_set($key, $data) {
59
+ if(defined('WPFURE_DISABLE_OBJECT_CACHE') && WPFURE_DISABLE_OBJECT_CACHE) {
60
+ return;
61
+ }
62
+
63
+ wp_cache_set($key, $data, $this->group);
64
+ }
65
+
66
+ protected function cache_get($key, &$found = null) {
67
+ if(defined('WPFURE_DISABLE_OBJECT_CACHE') && WPFURE_DISABLE_OBJECT_CACHE) {
68
+ return false;
69
+ }
70
+
71
+ return wp_cache_get($key, $this->group, false, $found);
72
+ }
73
+
74
+ protected function cache_delete($key) {
75
+ wp_cache_delete($key, $this->group);
76
+ }
77
+
78
+ protected function cache_global_set($key, $data) {
79
+ if(defined('WPFURE_DISABLE_OBJECT_CACHE') && WPFURE_DISABLE_OBJECT_CACHE) {
80
+ return;
81
+ }
82
+
83
+ if(empty($this->global_group)) {
84
+ $this->global_group = 'global_' . $this->group;
85
+ wp_cache_add_global_groups($this->global_group);
86
+ }
87
+
88
+ wp_cache_set($key, $data, $this->global_group);
89
+ }
90
+
91
+ protected function cache_global_get($key, &$found = null) {
92
+ if(defined('WPFURE_DISABLE_OBJECT_CACHE') && WPFURE_DISABLE_OBJECT_CACHE) {
93
+ $found = false;
94
+ return false;
95
+ }
96
+
97
+ if(empty($this->global_group)) {
98
+ $found = false;
99
+ return false;
100
+ }
101
+
102
+ return wp_cache_get($key, $this->global_group, false, $found);
103
+ }
104
+
105
+ protected function cache_global_delete($key) {
106
+ if(empty($this->global_group)) {
107
+ return;
108
+ }
109
+
110
+ wp_cache_delete($key, $this->global_group);
111
+ }
112
+
113
+ }
114
+
115
+ }
includes/class-controller.php ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controllers for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Controller')) {
38
+
39
+ /**
40
+ * Controller class
41
+ *
42
+ * @author Syam Mohan <syam@wpfront.com>
43
+ * @copyright 2014 WPFront.com
44
+ */
45
+ abstract class WPFront_User_Role_Editor_Controller extends WPFront_User_Role_Editor_Cache {
46
+
47
+ abstract protected function setUp();
48
+ abstract protected function initialize();
49
+
50
+ protected static $keys = array();
51
+ protected static $instances = array();
52
+
53
+ protected $WPFURE;
54
+ protected $Options;
55
+ protected $UtilsClass;
56
+ protected $RolesHelperClass;
57
+
58
+ protected $cap;
59
+
60
+ protected function __construct() {
61
+ parent::__construct(static::class);
62
+
63
+ $this->setUp();
64
+ }
65
+
66
+ protected function _setUp($cap) {
67
+ $this->cap = $cap;
68
+
69
+ if(static::class === \WPFront\URE\WPFront_User_Role_Editor::class) {
70
+ $this->WPFURE = $this;
71
+ } else {
72
+ $this->WPFURE = \WPFront\URE\WPFront_User_Role_Editor::instance();
73
+ }
74
+
75
+ if(static::class === \WPFront\URE\Options\WPFront_User_Role_Editor_Options::class) {
76
+ $this->Options = $this;
77
+ } else {
78
+ $this->Options = \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance();
79
+ }
80
+
81
+ $this->UtilsClass = \WPFront\URE\WPFront_User_Role_Editor_Utils::class;
82
+ $this->RolesHelperClass = \WPFront\URE\WPFront_User_Role_Editor_Roles_Helper::class;
83
+ }
84
+
85
+ public static function instance() {
86
+ $key = static::class;
87
+
88
+ if(isset(self::$keys[$key])) {
89
+ $key = self::$keys[$key];
90
+ }
91
+
92
+ if(isset(self::$instances[$key])) {
93
+ return self::$instances[$key];
94
+ }
95
+
96
+ $obj = new static();
97
+ self::$instances[$key] = $obj;
98
+
99
+ return $obj;
100
+ }
101
+
102
+ public static function init() {
103
+ static::instance()->initialize();
104
+ }
105
+
106
+ public static function load($network_admin_only = false) {
107
+ if($network_admin_only) {
108
+ if(!is_network_admin() && !WPFront_User_Role_Editor_Utils::doing_network_ajax()) {
109
+ return;
110
+ }
111
+ }
112
+
113
+ $key = static::class;
114
+
115
+ $firstLevel = true;
116
+ while(true) {
117
+ $parent = get_parent_class($key);
118
+ $refClass = new \ReflectionClass($parent);
119
+ if($refClass->isAbstract()) {
120
+ break;
121
+ }
122
+ $key = $parent;
123
+ $firstLevel = false;
124
+ }
125
+
126
+ if($firstLevel) {
127
+ add_action('wpfront_ure_init', [static::class, 'init']);
128
+ }
129
+
130
+ self::$keys[static::class] = $key;
131
+
132
+ self::$instances[$key] = new static();
133
+ }
134
+
135
+ protected function in_admin_ui() {
136
+ if($this->UtilsClass::doing_ajax()) {
137
+ return false;
138
+ }
139
+
140
+ if(!is_admin()) {
141
+ return false;
142
+ }
143
+
144
+ return true;
145
+ }
146
+
147
+ public function get_cap() {
148
+ return $this->cap;
149
+ }
150
+
151
+ protected function set_cap($cap) {
152
+ $this->cap = $cap;
153
+ }
154
+
155
+ }
156
+
157
+ }
158
+
159
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_View_Controller')) {
160
+
161
+ /**
162
+ * View Controller class
163
+ *
164
+ * @author Syam Mohan <syam@wpfront.com>
165
+ * @copyright 2014 WPFront.com
166
+ */
167
+ abstract class WPFront_User_Role_Editor_View_Controller extends WPFront_User_Role_Editor_Controller {
168
+
169
+ protected $ViewClass;
170
+ protected $EntityClass;
171
+
172
+ protected $menu_slug;
173
+
174
+ protected $menu_title;
175
+ protected $menu_link;
176
+
177
+ protected function _setUp($cap, $menu_slug = '') {
178
+ parent::_setUp($cap);
179
+
180
+ $this->menu_slug = $menu_slug;
181
+ }
182
+
183
+ public function get_menu_slug() {
184
+ return $this->menu_slug;
185
+ }
186
+
187
+ protected function set_admin_menu($title, $link, $priority = 10) {
188
+ $this->menu_title = $title;
189
+ $this->menu_link = $link;
190
+
191
+ add_action('admin_menu', array($this, 'admin_menu'), $priority);
192
+ }
193
+
194
+ protected function set_network_admin_menu($title, $link, $priority = 10) {
195
+ $this->menu_title = $title;
196
+ $this->menu_link = $link;
197
+
198
+ add_action('network_admin_menu', array($this, 'admin_menu'), $priority);
199
+ }
200
+
201
+ public function admin_menu() {
202
+ $page_hook_suffix = add_submenu_page($this->WPFURE->get_parent_menu_slug($this->get_menu_slug(), $this->get_cap()), $this->menu_title, $this->menu_link, $this->get_cap(), $this->get_menu_slug(), array($this, 'view'));
203
+
204
+ $this->add_menu_hooks($page_hook_suffix);
205
+ }
206
+
207
+ protected function add_menu_hooks($page_hook_suffix) {
208
+ add_action('admin_print_styles-' . $page_hook_suffix, array($this, 'admin_print_styles'));
209
+ add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'admin_print_scripts'));
210
+ add_action('load-' . $page_hook_suffix, array($this, 'load_view'));
211
+ }
212
+
213
+ public function load_view() {
214
+ if(!current_user_can($this->get_cap())) {
215
+ $this->WPFURE->permission_denied();
216
+ return false;
217
+ }
218
+
219
+ return true;
220
+ }
221
+
222
+ public function view() {
223
+ if(!current_user_can($this->get_cap())) {
224
+ $this->WPFURE->permission_denied();
225
+ return false;
226
+ }
227
+
228
+ return true;
229
+ }
230
+
231
+ public function admin_print_styles() {
232
+ $this->UtilsClass::enqueue_font_awesome_styles();
233
+ wp_enqueue_style('wpfront-user-role-editor-styles', $this->WPFURE->get_asset_url('css/roles.css'), array(), $this->WPFURE::VERSION);
234
+ }
235
+
236
+ public function admin_print_scripts() {
237
+ wp_enqueue_script('jquery');
238
+ }
239
+
240
+ public function get_self_url($params = array()) {
241
+ $url = menu_page_url($this->get_menu_slug(), false);
242
+ if(!empty($params)) {
243
+ foreach ($params as $key => $value) {
244
+ $url = $url . "&$key=$value";
245
+ }
246
+ }
247
+
248
+ return $url;
249
+ }
250
+
251
+ }
252
+
253
+ }
254
+
255
+
256
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_View')) {
257
+
258
+ /**
259
+ * View base
260
+ *
261
+ * @author Syam Mohan <syam@wpfront.com>
262
+ * @copyright 2014 WPFront.com
263
+ */
264
+ abstract class WPFront_User_Role_Editor_View {
265
+
266
+ protected $WPFURE;
267
+ protected $UtilsClass;
268
+ protected $RolesHelperClass;
269
+
270
+ public function __construct() {
271
+ $this->WPFURE = \WPFront\URE\WPFront_User_Role_Editor::instance();
272
+ $this->UtilsClass = \WPFront\URE\WPFront_User_Role_Editor_Utils::class;
273
+ $this->RolesHelperClass = \WPFront\URE\WPFront_User_Role_Editor_Roles_Helper::class;
274
+ }
275
+
276
+ protected function title($title, $add_new = array(), $search = null) {
277
+ ?>
278
+ <h2>
279
+ <?php echo $title; ?>
280
+ <?php
281
+ if (!empty($add_new)) {
282
+ ?>
283
+ <a href="<?php echo $add_new[1]; ?>" class="add-new-h2"><?php echo $add_new[0]; ?></a>
284
+ <?php
285
+ }
286
+ if (!empty($search)) {
287
+ ?>
288
+ <span class="subtitle"><?php echo sprintf(__('Search results for "%s"', 'wpfront-user-role-editor'), $search); ?></span>
289
+ <?php
290
+ }
291
+ ?>
292
+ </h2>
293
+ <?php
294
+ }
295
+
296
+ }
297
+
298
+ }
includes/class-entity.php ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Entity base for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Entity_Base')) {
38
+
39
+ /**
40
+ * Entity base class
41
+ *
42
+ * @author Syam Mohan <syam@wpfront.com>
43
+ * @copyright 2014 WPFront.com
44
+ */
45
+ abstract class WPFront_User_Role_Editor_Entity_Base extends \WPFront\URE\WPFront_User_Role_Editor_Cache {
46
+
47
+ const DB_VERSION_OPTION_KEY = 'wpfront-user-role-editor-db-version';
48
+
49
+ private $table_name;
50
+
51
+ protected abstract function table_name_suffix();
52
+ protected abstract function table_create_sql();
53
+
54
+ public function __construct() {
55
+ $table_name_suffix = $this->table_name_suffix();
56
+ $this->table_name = 'wpfront_ure_' . $table_name_suffix;
57
+ parent::__construct($table_name_suffix);
58
+
59
+ $table_version_key = $this->db_version_key();
60
+ if(empty($this->cache_get("entity-$table_version_key"))) {
61
+ if($this->dbDelta()) {
62
+ $this->cache_set("entity-$table_version_key", true);
63
+ }
64
+ }
65
+ }
66
+
67
+ protected function table_name() {
68
+ global $wpdb;
69
+ return $wpdb->prefix . $this->table_name;
70
+ }
71
+
72
+ protected function dbDelta() {
73
+ if (defined('WP_UNINSTALL_PLUGIN')) {
74
+ return false;
75
+ }
76
+
77
+ $table_version_key = $this->db_version_key();
78
+
79
+ $db_version = $this->get_db_version($table_version_key);
80
+ if (empty($db_version)) {
81
+ $db_version = '0.0';
82
+ }
83
+
84
+ if (version_compare($db_version, \WPFront\URE\WPFront_User_Role_Editor::VERSION, '>=')) {
85
+ return true;
86
+ }
87
+
88
+ $this->pre_custom_upgrade_script();
89
+
90
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
91
+ $sql = $this->table_create_sql();
92
+
93
+ dbDelta($sql);
94
+
95
+ global $wpdb;
96
+ $table_name = $this->table_name();
97
+
98
+ $sql = "SHOW TABLE STATUS where name like '$table_name'";
99
+ $status = $wpdb->get_row($sql);
100
+ if(empty($status)) {
101
+ return false;
102
+ }
103
+
104
+ $length = strlen('utf8mb4_unicode');
105
+ if(substr($status->Collation, 0, $length) !== 'utf8mb4_unicode') {
106
+ $sql = "ALTER TABLE $table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;";
107
+ $result = $wpdb->query($sql);
108
+ if($result === false) {
109
+ error_log("Unable to set collation for table $table_name. Error - {$wpdb->last_error}");
110
+ }
111
+ }
112
+
113
+ $this->drop_index_id();
114
+ $this->custom_upgrade_script();
115
+
116
+ $this->set_db_version($table_version_key, \WPFront\URE\WPFront_User_Role_Editor::VERSION);
117
+
118
+ return true;
119
+ }
120
+
121
+ protected function drop_index_id() {
122
+ $table_version_key = $this->db_version_key();
123
+ $db_version = $this->get_db_version($table_version_key);
124
+
125
+ if(empty($db_version)) { //new install
126
+ return;
127
+ }
128
+
129
+ global $wpdb;
130
+ $table_name = $this->table_name();
131
+ $sql = "SHOW INDEX FROM $table_name WHERE Key_name='id'";
132
+ $result = $wpdb->get_row($sql);
133
+
134
+ if (!empty($result)) {
135
+ $wpdb->query("ALTER TABLE {$this->table_name()} DROP INDEX id;");
136
+ }
137
+ }
138
+
139
+ protected function custom_upgrade_script() {
140
+ }
141
+
142
+ protected function pre_custom_upgrade_script() {
143
+ }
144
+
145
+ private function db_version_key() {
146
+ if(static::class === \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity::class) {
147
+ return self::DB_VERSION_OPTION_KEY;
148
+ }
149
+
150
+ return $this->table_name() . '-db-version';
151
+ }
152
+
153
+ private function get_db_version($key) {
154
+ if(static::class === \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity::class) {
155
+ return get_option($key);
156
+ }
157
+
158
+ return \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->get_option($key);
159
+ }
160
+
161
+ private function set_db_version($key, $value) {
162
+ if(static::class === \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity::class) {
163
+ update_option($key, $value);
164
+ return;
165
+ }
166
+
167
+ \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->set_option($key, $value);
168
+ }
169
+
170
+ private function delete_db_version($key) {
171
+ if(static::class === \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity::class) {
172
+ delete_option($key);
173
+ }
174
+ //happens only on uninstall doesn't need.
175
+ //\WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->delete_option($key);
176
+ }
177
+
178
+ public function uninstall() {
179
+ $this->delete_db_version($this->db_version_key());
180
+
181
+ global $wpdb;
182
+ $table_name = $this->table_name();
183
+
184
+ $sql = "DROP TABLE IF EXISTS $table_name";
185
+ $wpdb->query($sql);
186
+ }
187
+
188
+ public function register() {
189
+ WPFront_User_Role_Editor_Uninstall::register_entity($this);
190
+ }
191
+
192
+ }
193
+
194
+ }
includes/class-roles-helper.php ADDED
@@ -0,0 +1,888 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Helper class for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies;
38
+ use WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type;
39
+
40
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Roles_Helper')) {
41
+
42
+ /**
43
+ * Roles helper class
44
+ *
45
+ * @author Syam Mohan <syam@wpfront.com>
46
+ * @copyright 2014 WPFront.com
47
+ */
48
+ class WPFront_User_Role_Editor_Roles_Helper {
49
+
50
+ const ADMINISTRATOR_ROLE_KEY = 'administrator';
51
+ const EDITOR_ROLE_KEY = 'editor';
52
+ const AUTHOR_ROLE_KEY = 'author';
53
+ const CONTRIBUTOR_ROLE_KEY = 'contributor';
54
+ const SUBSCRIBER_ROLE_KEY = 'subscriber';
55
+
56
+ protected static $DEFAULT_ROLES = array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY);
57
+
58
+ protected static $STANDARD_CAPABILITIES = array(
59
+ 'dashboard' => array(
60
+ 'read' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY),
61
+ 'edit_dashboard' => array(self::ADMINISTRATOR_ROLE_KEY)
62
+ ),
63
+ 'posts' => array(
64
+ 'publish_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
65
+ 'edit_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
66
+ 'delete_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
67
+ 'edit_published_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
68
+ 'delete_published_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
69
+ 'edit_others_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
70
+ 'delete_others_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
71
+ 'read_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
72
+ 'edit_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
73
+ 'delete_private_posts' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
74
+ 'manage_categories' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
75
+ ),
76
+ 'media' => array(
77
+ 'upload_files' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
78
+ 'unfiltered_upload' => array(self::ADMINISTRATOR_ROLE_KEY)
79
+ ),
80
+ 'pages' => array(
81
+ 'publish_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
82
+ 'edit_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
83
+ 'delete_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
84
+ 'edit_published_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
85
+ 'delete_published_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
86
+ 'edit_others_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
87
+ 'delete_others_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
88
+ 'read_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
89
+ 'edit_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
90
+ 'delete_private_pages' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
91
+ ),
92
+ 'comments' => array(
93
+ 'moderate_comments' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
94
+ ),
95
+ 'themes' => array(
96
+ 'switch_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
97
+ 'edit_theme_options' => array(self::ADMINISTRATOR_ROLE_KEY),
98
+ 'edit_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
99
+ 'delete_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
100
+ 'install_themes' => array(self::ADMINISTRATOR_ROLE_KEY),
101
+ 'update_themes' => array(self::ADMINISTRATOR_ROLE_KEY)
102
+ ),
103
+ 'plugins' => array(
104
+ 'activate_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
105
+ 'edit_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
106
+ 'install_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
107
+ 'update_plugins' => array(self::ADMINISTRATOR_ROLE_KEY),
108
+ 'delete_plugins' => array(self::ADMINISTRATOR_ROLE_KEY)
109
+ ),
110
+ 'users' => array(
111
+ 'list_users' => array(self::ADMINISTRATOR_ROLE_KEY),
112
+ 'create_users' => array(self::ADMINISTRATOR_ROLE_KEY),
113
+ 'edit_users' => array(self::ADMINISTRATOR_ROLE_KEY),
114
+ 'delete_users' => array(self::ADMINISTRATOR_ROLE_KEY),
115
+ 'promote_users' => array(self::ADMINISTRATOR_ROLE_KEY),
116
+ //'add_users' => array(self::ADMINISTRATOR_ROLE_KEY),
117
+ 'remove_users' => array(self::ADMINISTRATOR_ROLE_KEY)
118
+ ),
119
+ 'tools' => array(
120
+ 'import' => array(self::ADMINISTRATOR_ROLE_KEY),
121
+ 'export' => array(self::ADMINISTRATOR_ROLE_KEY)
122
+ ),
123
+ 'admin' => array(
124
+ 'manage_options' => array(self::ADMINISTRATOR_ROLE_KEY),
125
+ 'update_core' => array(self::ADMINISTRATOR_ROLE_KEY),
126
+ 'unfiltered_html' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
127
+ ),
128
+ 'links' => array(
129
+ 'manage_links' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY)
130
+ ),
131
+ 'deprecated' => array(
132
+ 'edit_files' => array(self::ADMINISTRATOR_ROLE_KEY),
133
+ 'level_0' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY, self::SUBSCRIBER_ROLE_KEY),
134
+ 'level_1' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY, self::CONTRIBUTOR_ROLE_KEY),
135
+ 'level_2' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY, self::AUTHOR_ROLE_KEY),
136
+ 'level_3' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
137
+ 'level_4' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
138
+ 'level_5' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
139
+ 'level_6' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
140
+ 'level_7' => array(self::ADMINISTRATOR_ROLE_KEY, self::EDITOR_ROLE_KEY),
141
+ 'level_8' => array(self::ADMINISTRATOR_ROLE_KEY),
142
+ 'level_9' => array(self::ADMINISTRATOR_ROLE_KEY),
143
+ 'level_10' => array(self::ADMINISTRATOR_ROLE_KEY)
144
+ ),
145
+ 'network' => array(
146
+ 'manage_network' => array(),
147
+ 'manage_sites' => array(),
148
+ 'create_sites' => array(),
149
+ 'delete_sites' => array(),
150
+ 'manage_network_roles' => array(),
151
+ 'manage_network_users' => array(),
152
+ 'manage_network_themes' => array(),
153
+ 'manage_network_plugins' => array(),
154
+ 'manage_network_options' => array(),
155
+ 'upgrade_network' => array()
156
+ )
157
+ );
158
+
159
+ protected static $ROLE_CAPS = array(
160
+ 'list_roles',
161
+ 'create_roles',
162
+ 'edit_roles',
163
+ 'delete_roles',
164
+ 'edit_role_menus',
165
+ 'edit_nav_menu_permissions',
166
+ 'edit_content_shortcodes',
167
+ 'delete_content_shortcodes',
168
+ 'edit_login_redirects',
169
+ 'delete_login_redirects',
170
+ 'bulk_edit_roles',
171
+ 'edit_widget_permissions',
172
+ 'create_posttypes',
173
+ 'edit_posttypes',
174
+ 'delete_posttypes',
175
+ 'create_taxonomies',
176
+ 'edit_taxonomies',
177
+ 'delete_taxonomies'
178
+ );
179
+ protected static $capability_group_names = null;
180
+ protected static $custom_capability_groups = array();
181
+ protected static $group_capabilities_cache = array();
182
+
183
+ /**
184
+ * Checks whether given role is a WP default role.
185
+ *
186
+ * @param string $role_name
187
+ * @return bool
188
+ */
189
+ public static function is_default_role($role_name) {
190
+ return in_array($role_name, self::$DEFAULT_ROLES);
191
+ }
192
+
193
+ /**
194
+ * Check whether given role exists within the system.
195
+ *
196
+ * @param string $role_name
197
+ * @return bool
198
+ */
199
+ public static function is_role($role_name) {
200
+ if (empty($role_name)) {
201
+ return false;
202
+ }
203
+
204
+ return wp_roles()->is_role($role_name);
205
+ }
206
+
207
+ /**
208
+ * Returns the display name of the given role.
209
+ *
210
+ * @param string $role_name
211
+ * @return string
212
+ */
213
+ public static function get_display_name($role_name, $default = false) {
214
+ if (self::is_role($role_name)) {
215
+ $names = wp_roles()->get_names();
216
+ return $names[$role_name];
217
+ }
218
+
219
+ if ($default) {
220
+ $display_name = ucfirst($role_name);
221
+ $display_name = translate_user_role($display_name);
222
+ return $display_name;
223
+ }
224
+
225
+ return null;
226
+ }
227
+
228
+ /**
229
+ * Returns role with its display names.
230
+ *
231
+ * @return string[] Associative (name=>display).
232
+ */
233
+ public static function get_names() {
234
+ $roles = wp_roles()->get_names();
235
+
236
+ $admin_name = null;
237
+ if (isset($roles[self::ADMINISTRATOR_ROLE_KEY])) {
238
+ $admin_name = $roles[self::ADMINISTRATOR_ROLE_KEY];
239
+ unset($roles[self::ADMINISTRATOR_ROLE_KEY]);
240
+ }
241
+
242
+ asort($roles);
243
+ if (!empty($admin_name)) {
244
+ $roles = array(self::ADMINISTRATOR_ROLE_KEY => $admin_name) + $roles;
245
+ }
246
+
247
+ return $roles;
248
+ }
249
+
250
+ /**
251
+ * Returns the roles.
252
+ *
253
+ * @return string[] List of role names.
254
+ */
255
+ public static function get_roles() {
256
+ return array_keys(wp_roles()->role_names);
257
+ }
258
+
259
+ /**
260
+ * Returns role object or null.
261
+ *
262
+ * @param string $role_name
263
+ * @return \WP_Role
264
+ */
265
+ public static function get_role($role_name) {
266
+ return wp_roles()->get_role($role_name);
267
+ }
268
+
269
+ /**
270
+ * Returns role capabilities.
271
+ *
272
+ * @param string $role_name
273
+ * @return bool[]|null Associative (cap=>grant)
274
+ */
275
+ public static function get_capabilities($role_name) {
276
+ if (self::is_role($role_name)) {
277
+ return wp_roles()->role_objects[$role_name]->capabilities;
278
+ }
279
+
280
+ return null;
281
+ }
282
+
283
+ /**
284
+ * Returns default role names.
285
+ *
286
+ * @return array
287
+ */
288
+ public static function get_default_rolenames() {
289
+ return self::$DEFAULT_ROLES;
290
+ }
291
+
292
+ /**
293
+ * Adds a new role to the system.
294
+ *
295
+ * @param string $role
296
+ * @param string $display_name
297
+ * @param array $capabilities
298
+ * @return \WP_Role
299
+ */
300
+ public static function add_role($role, $display_name, $capabilities) {
301
+ return wp_roles()->add_role($role, $display_name, $capabilities);
302
+ }
303
+
304
+ /**
305
+ * Updates an existing role in the system.
306
+ *
307
+ * @param string $role
308
+ * @param string $display_name
309
+ * @param array $capabilities
310
+ * @return \WP_Role
311
+ */
312
+ public static function update_role($role, $display_name, $capabilities) {
313
+ if (self::is_role($role)) {
314
+ if (!self::can_set_network_capability()) {
315
+ foreach ($capabilities as $cap => $value) {
316
+ if (self::is_network_capability($cap)) {
317
+ unset($capabilities[$cap]);
318
+ }
319
+ }
320
+
321
+ $caps_existing = self::get_capabilities($role);
322
+ $network_caps = array();
323
+ foreach ($caps_existing as $cap => $value) {
324
+ if (self::is_network_capability($cap)) {
325
+ $network_caps[$cap] = $value;
326
+ }
327
+ }
328
+ $capabilities = array_merge($capabilities, $network_caps);
329
+ }
330
+
331
+ wp_roles()->remove_role($role);
332
+ return wp_roles()->add_role($role, $display_name, $capabilities);
333
+ }
334
+
335
+ return null;
336
+ }
337
+
338
+ /**
339
+ * Removes a role from system.
340
+ *
341
+ * @param string $role
342
+ */
343
+ public static function remove_role($role) {
344
+ wp_roles()->remove_role($role);
345
+ }
346
+
347
+ /**
348
+ * Remove roles from system.
349
+ *
350
+ * @param string[] $roles
351
+ */
352
+ public static function remove_roles($roles) {
353
+ if (empty($roles)) {
354
+ return;
355
+ }
356
+
357
+ $roles_obj = wp_roles();
358
+ $roles_obj->use_db = false;
359
+ foreach ($roles as $role) {
360
+ $roles_obj->remove_role($role);
361
+ }
362
+
363
+ $role = reset($roles);
364
+ $roles_obj->role_objects[$role] = true;
365
+ $roles_obj->use_db = true;
366
+ $roles_obj->remove_role($role);
367
+ }
368
+
369
+ /**
370
+ * Adds a capability to role.
371
+ *
372
+ * @param string $role_name
373
+ * @param string $cap
374
+ * @param boolean $grant
375
+ * @return boolean
376
+ */
377
+ public static function add_capability_to_role($role_name, $cap, $grant = true) {
378
+ $role = self::get_role($role_name);
379
+ if (!empty($role)) {
380
+ $role->add_cap($cap, $grant);
381
+ return true;
382
+ }
383
+
384
+ return false;
385
+ }
386
+
387
+ /**
388
+ * Add capabilities to role.
389
+ *
390
+ * @param string $role_name
391
+ * @param bool[] $caps cap => grant
392
+ * @return boolean
393
+ */
394
+ public static function add_capabilities_to_role($role_name, $caps) {
395
+ $role = self::get_role($role_name);
396
+ if (empty($role)) {
397
+ return false;
398
+ }
399
+
400
+ $role_objects = wp_roles();
401
+ $role_objects->use_db = false;
402
+ foreach ($caps as $cap => $grant) {
403
+ $role->add_cap($cap, $grant);
404
+ }
405
+
406
+ $role_objects->use_db = true;
407
+ foreach ($caps as $cap => $grant) {
408
+ $role->add_cap($cap, $grant);
409
+ break;
410
+ }
411
+
412
+ return true;
413
+ }
414
+
415
+ /**
416
+ * Remove capabilities from role.
417
+ *
418
+ * @param string $role_name
419
+ * @param string[] $caps
420
+ * @return boolean
421
+ */
422
+ public static function remove_capabilities_from_role($role_name, $caps) {
423
+ $role = self::get_role($role_name);
424
+ if (empty($role)) {
425
+ return false;
426
+ }
427
+
428
+ $role_objects = wp_roles();
429
+ $role_objects->use_db = false;
430
+ foreach ($caps as $cap) {
431
+ $role->remove_cap($cap);
432
+ }
433
+
434
+ $role_objects->use_db = true;
435
+ foreach ($caps as $cap) {
436
+ $role->remove_cap($cap);
437
+ break;
438
+ }
439
+
440
+ return true;
441
+ }
442
+
443
+ /**
444
+ * Returns capability groups with their display names.
445
+ *
446
+ * @return array string => object
447
+ */
448
+ public static function get_capabilty_groups() {
449
+ if (self::$capability_group_names !== null) {
450
+ return self::$capability_group_names;
451
+ }
452
+
453
+ self::$capability_group_names = array(
454
+ 'dashboard' => (object) array('key' => 'dashboard', 'label' => __('Dashboard', 'wpfront-user-role-editor'), 'type' => 'default'),
455
+ 'posts' => (object) array('key' => 'posts', 'label' => __('Posts', 'wpfront-user-role-editor'), 'type' => 'default'),
456
+ 'media' => (object) array('key' => 'media', 'label' => __('Media', 'wpfront-user-role-editor'), 'type' => 'default'),
457
+ 'pages' => (object) array('key' => 'pages', 'label' => __('Pages', 'wpfront-user-role-editor'), 'type' => 'default'),
458
+ 'comments' => (object) array('key' => 'comments', 'label' => __('Comments', 'wpfront-user-role-editor'), 'type' => 'default'),
459
+ 'themes' => (object) array('key' => 'themes', 'label' => __('Themes', 'wpfront-user-role-editor'), 'type' => 'default'),
460
+ 'plugins' => (object) array('key' => 'plugins', 'label' => __('Plugins', 'wpfront-user-role-editor'), 'type' => 'default'),
461
+ 'users' => (object) array('key' => 'users', 'label' => __('Users', 'wpfront-user-role-editor'), 'type' => 'default'),
462
+ 'roles' => (object) array('key' => 'roles', 'label' => __('Roles (WPFront)', 'wpfront-user-role-editor'), 'type' => 'wpfront'),
463
+ 'tools' => (object) array('key' => 'tools', 'label' => __('Tools', 'wpfront-user-role-editor'), 'type' => 'default'),
464
+ 'admin' => (object) array('key' => 'admin', 'label' => __('Admin', 'wpfront-user-role-editor'), 'type' => 'default'),
465
+ 'links' => (object) array('key' => 'links', 'label' => __('Links', 'wpfront-user-role-editor'), 'type' => 'default'),
466
+ 'deprecated' => (object) array('key' => 'deprecated', 'label' => __('Deprecated', 'wpfront-user-role-editor'), 'type' => 'default')
467
+ );
468
+
469
+ $post_types = WPFront_User_Role_Editor_Post_Type::instance()->get_user_visible_cpt();
470
+ foreach ($post_types as $name => $data) {
471
+ self::$capability_group_names["cpt_$name"] = (object) array(
472
+ 'key' => $name,
473
+ 'label' => $data->label . ' (' . __('Post Type', 'wpfront-user-role-editor') . ')',
474
+ 'type' => 'custom_post',
475
+ 'data' => $data
476
+ );
477
+ }
478
+
479
+ $taxonomies = WPFront_User_Role_Editor_Taxonomies::instance()->get_all_taxonomies_data();
480
+ foreach ($taxonomies as $name => $data) {
481
+ if (!is_taxonomy_viewable($name)) {
482
+ continue;
483
+ }
484
+
485
+ self::$capability_group_names["tax_$name"] = (object) array(
486
+ 'key' => $name,
487
+ 'label' => $data->label . ' (' . __('Taxonomy', 'wpfront-user-role-editor') . ')',
488
+ 'type' => 'taxonomy',
489
+ 'data' => $data
490
+ );
491
+ }
492
+
493
+ foreach (self::$custom_capability_groups as $group => $data) {
494
+ if (!isset(self::$capability_group_names[$group])) {
495
+ self::$capability_group_names[$group] = (object) array('key' => $data->key, 'label' => $data->label, 'type' => $data->type);
496
+ }
497
+ }
498
+
499
+ self::$capability_group_names['other'] = (object) array('key' => 'other', 'label' => __('Other Capabilities', 'wpfront-user-role-editor'), 'type' => 'other');
500
+
501
+ self::$capability_group_names = apply_filters('wpfront_ure_capability_groups', self::$capability_group_names);
502
+
503
+ return self::$capability_group_names;
504
+ }
505
+
506
+ /**
507
+ * Returns capabilities against a group.
508
+ *
509
+ * @param object $group
510
+ * @return string[]
511
+ */
512
+ public static function get_group_capabilities($group) {
513
+ $group_key = $group->key;
514
+ $group_cache_key = $group->key . '_' . $group->type;
515
+
516
+ if (array_key_exists($group_cache_key, self::$group_capabilities_cache)) {
517
+ return self::$group_capabilities_cache[$group_cache_key];
518
+ }
519
+
520
+ $group_caps = array();
521
+
522
+ switch ($group->type) {
523
+ case 'default':
524
+ if (array_key_exists($group_key, self::$STANDARD_CAPABILITIES)) {
525
+ $group_caps = array_keys(self::$STANDARD_CAPABILITIES[$group_key]);
526
+ }
527
+
528
+ if ($group_key === 'posts' || $group_key === 'pages') {
529
+ $group_caps = array();
530
+ $post_type = $group_key === 'posts' ? 'post' : 'page';
531
+ $group_caps = array_merge($group_caps, self::get_post_type_caps(get_post_type_object($post_type), $group_key === 'posts'));
532
+ $group_caps = array_values(array_unique($group_caps));
533
+ }
534
+
535
+ if ($group_key === 'network') {
536
+ $roles = self::get_roles();
537
+ foreach ($roles as $role) {
538
+ $caps = self::get_capabilities($role);
539
+
540
+ foreach ($caps as $cap => $allow) {
541
+ if (strpos($cap, 'manage_network') === 0) {
542
+ $group_caps[] = $cap;
543
+ }
544
+ }
545
+ }
546
+
547
+ $group_caps = array_unique($group_caps);
548
+ }
549
+
550
+ break;
551
+
552
+ case 'custom_post':
553
+ $post_type_object = get_post_type_object($group_key);
554
+
555
+ if ($post_type_object->capability_type === 'post' || $post_type_object->capability_type === 'page' || $post_type_object->capability_type === 'attachment') {
556
+ return 'defaulted';
557
+ }
558
+
559
+ $group_caps = self::get_post_type_caps($post_type_object);
560
+ break;
561
+
562
+ case 'taxonomy':
563
+ $tax_obj = get_taxonomy($group_key);
564
+ $caps = $tax_obj->cap;
565
+ if ($caps->manage_terms === 'manage_categories' || $caps->manage_terms === 'manage_post_tags') {
566
+ return 'defaulted';
567
+ }
568
+
569
+ $caps = (array) $caps;
570
+ $group_caps = array_values($caps);
571
+ break;
572
+
573
+ case 'wpfront':
574
+ $group_caps = self::$ROLE_CAPS;
575
+ break;
576
+
577
+ case 'other':
578
+ $other_caps = array();
579
+
580
+ $roles = self::get_roles();
581
+ foreach ($roles as $role) {
582
+ $caps = self::get_capabilities($role);
583
+
584
+ foreach ($caps as $cap => $allow) {
585
+ $other_caps[$cap] = $cap;
586
+ }
587
+ }
588
+
589
+ $groups = self::get_capabilty_groups();
590
+ foreach ($groups as $name => $group) {
591
+ if ($group->type === 'other') {
592
+ continue;
593
+ }
594
+
595
+ $caps = self::get_group_capabilities($group);
596
+
597
+ if (!is_array($caps)) {
598
+ continue;
599
+ }
600
+
601
+ foreach ($caps as $cap) {
602
+ unset($other_caps[$cap]);
603
+ }
604
+ }
605
+
606
+ $group_caps = array_keys($other_caps);
607
+ break;
608
+ }
609
+
610
+ if (array_key_exists($group_key, self::$custom_capability_groups)) {
611
+ $custom_caps = self::$custom_capability_groups[$group_key]->caps;
612
+
613
+ foreach ($custom_caps as $cap => $value) {
614
+ $group_caps[] = $cap;
615
+ }
616
+ }
617
+
618
+ $group_caps = apply_filters('wpfront_ure_role_group_capabilities', $group_caps, $group);
619
+
620
+ self::$group_capabilities_cache[$group_cache_key] = $group_caps;
621
+ return $group_caps;
622
+ }
623
+
624
+ /**
625
+ * Returns caps from post type object.
626
+ *
627
+ * @param \WP_Post_Type $post_type_object
628
+ * @return string[]
629
+ */
630
+ private static function get_post_type_caps($post_type_object, $add_missing_std_caps = false) {
631
+ $caps = array();
632
+ $meta_caps = array('read', 'read_post', 'edit_post', 'delete_post');
633
+
634
+ $posttype_caps = $post_type_object->cap;
635
+ if ($posttype_caps->create_posts === $posttype_caps->edit_posts) {
636
+ $meta_caps[] = 'create_posts';
637
+ }
638
+
639
+ foreach ($posttype_caps as $post_cap => $cap) {
640
+ if (!in_array($post_cap, $meta_caps)) {
641
+ $caps[$post_cap] = $cap;
642
+ }
643
+ }
644
+
645
+ $post_caps = array_keys(self::$STANDARD_CAPABILITIES['posts']);
646
+ $post_caps_existing = array();
647
+
648
+ $caps_order = array();
649
+ foreach ($post_caps as $cap) {
650
+ if (isset($caps[$cap])) {
651
+ $caps_order[] = $caps[$cap];
652
+ unset($caps[$cap]);
653
+ $post_caps_existing[] = $cap;
654
+ }
655
+ }
656
+
657
+ if($add_missing_std_caps) {
658
+ $caps_order = array_merge($caps_order, array_diff($post_caps, $post_caps_existing));
659
+ }
660
+
661
+ $caps_order = array_merge($caps_order, array_values($caps));
662
+ return array_values($caps_order);
663
+ }
664
+
665
+ /**
666
+ * Returns standard capabilities against a role.
667
+ *
668
+ * @param string $role_name
669
+ * @return bool[] Associative (cap=>enabled).
670
+ */
671
+ public static function get_standard_capabilities($role_name) {
672
+ $std_caps = array();
673
+
674
+ foreach (self::$STANDARD_CAPABILITIES as $group => $caps) {
675
+ foreach ($caps as $cap => $roles) {
676
+ $std_caps[$cap] = in_array($role_name, $roles);
677
+ }
678
+ }
679
+
680
+ return $std_caps;
681
+ }
682
+
683
+ /**
684
+ * Adds a capability group to group capabilities.
685
+ *
686
+ * @param string $key Group identifier
687
+ * @param string $display Group name displayed
688
+ */
689
+ public static function add_capability_group($key, $display) {
690
+ $key = strtolower($key);
691
+
692
+ if (array_key_exists($key, self::$custom_capability_groups)) {
693
+ return;
694
+ }
695
+
696
+ self::$custom_capability_groups[$key] = (object) array('key' => $key, 'label' => $display, 'type' => 'custom', 'caps' => array());
697
+ }
698
+
699
+ /**
700
+ * Adds a new custom capability to group.
701
+ *
702
+ * @param string $group_key
703
+ * @param string $cap
704
+ * @return boolean
705
+ */
706
+ public static function add_new_capability_to_group($group_key, $cap) {
707
+ $group_key = strtolower($group_key);
708
+
709
+ if (!array_key_exists($group_key, self::$custom_capability_groups)) {
710
+ return false;
711
+ }
712
+
713
+ self::$custom_capability_groups[$group_key]->caps[$cap] = true;
714
+
715
+ return true;
716
+ }
717
+
718
+ /**
719
+ * Returns Posts standard capabilities.
720
+ *
721
+ * @return string[]
722
+ */
723
+ public static function get_standard_posts_capabilities() {
724
+ return array_keys(self::$STANDARD_CAPABILITIES['posts']);
725
+ }
726
+
727
+ public static function get_standard_network_capabilities() {
728
+ return array_keys(self::$STANDARD_CAPABILITIES['network']);
729
+ }
730
+
731
+ /**
732
+ * Hooks into wpfront_ure_capability_ui_help_link to return cap help link.
733
+ *
734
+ * @param string $cap
735
+ * @param object $group
736
+ * @return string
737
+ */
738
+ public static function cap_help_link($help_link, $cap, $group) {
739
+ $has_help = false;
740
+
741
+ switch ($group->type) {
742
+ case 'default':
743
+ $group_key = $group->key;
744
+ if (array_key_exists($group_key, self::$STANDARD_CAPABILITIES)) {
745
+ $has_help = array_key_exists($cap, self::$STANDARD_CAPABILITIES[$group_key]);
746
+ } else {
747
+ $has_help = false;
748
+ }
749
+ break;
750
+
751
+ case 'wpfront':
752
+ $has_help = in_array($cap, self::$ROLE_CAPS);
753
+ }
754
+
755
+ if ($has_help) {
756
+ $help_link = self::get_wpfront_help_link($cap);
757
+ }
758
+
759
+ return $help_link;
760
+ }
761
+
762
+ /**
763
+ * wpfront.com cap help link.
764
+ *
765
+ * @param string $cap
766
+ * @return string
767
+ */
768
+ public static function get_wpfront_help_link($cap) {
769
+ return 'https://wpfront.com/wordpress-capabilities/#' . $cap;
770
+ }
771
+
772
+ /**
773
+ *
774
+ * @var boolean
775
+ */
776
+ private static $user_is_admin = null;
777
+
778
+ /**
779
+ * Hooks into user_has_cap and handles Administrator role caps.
780
+ *
781
+ * @param string[] $allcaps
782
+ * @param string[] $caps
783
+ * @param string[] $args
784
+ * @return string[]
785
+ */
786
+ public static function user_has_cap_administrator($allcaps, $caps, $args) {
787
+ if (self::$user_is_admin === null) {
788
+ if (!self::is_role(self::ADMINISTRATOR_ROLE_KEY)) {
789
+ self::$user_is_admin = false;
790
+ return $allcaps;
791
+ }
792
+
793
+ $user_id = intval($args[1]);
794
+ $user = get_userdata($user_id);
795
+ if (empty($user)) {
796
+ return $allcaps;
797
+ }
798
+
799
+ if (empty($user->roles)) {
800
+ self::$user_is_admin = false;
801
+ return $allcaps;
802
+ }
803
+
804
+ self::$user_is_admin = in_array(self::ADMINISTRATOR_ROLE_KEY, $user->roles);
805
+ }
806
+
807
+ if (self::$user_is_admin) {
808
+ foreach ($caps as $cap) {
809
+ $allcaps[$cap] = true;
810
+ }
811
+ }
812
+
813
+ return $allcaps;
814
+ }
815
+
816
+ public static function restore_role_custom_caps($custom_caps) {
817
+ foreach (self::$ROLE_CAPS as $cap) {
818
+ $custom_caps[$cap] = 'manage_options';
819
+ }
820
+
821
+ return $custom_caps;
822
+ }
823
+
824
+ public static function add_wpfront_caps_to_roles() {
825
+ $role = self::get_role(self::ADMINISTRATOR_ROLE_KEY);
826
+ if (!empty($role)) {
827
+ $key = 'role_capabilities_processed';
828
+ $processed = \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->get_option($key);
829
+ if (version_compare($processed, \WPFront\URE\WPFront_User_Role_Editor::VERSION, '>=')) {
830
+ return;
831
+ }
832
+
833
+ if (!is_multisite()) {
834
+ foreach (self::$ROLE_CAPS as $cap) {
835
+ $role->add_cap($cap);
836
+ }
837
+ }
838
+
839
+ \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->set_option($key, \WPFront\URE\WPFront_User_Role_Editor::VERSION);
840
+ }
841
+ }
842
+
843
+ public static function is_super_admin() {
844
+ return is_multisite() && is_super_admin();
845
+ }
846
+
847
+ public static function can_set_network_capability() {
848
+ return self::is_super_admin();
849
+ }
850
+
851
+ public static function is_network_capability($cap) {
852
+ $std_caps = self::$STANDARD_CAPABILITIES['network'];
853
+ if (isset($std_caps[$cap])) {
854
+ return true;
855
+ }
856
+
857
+ if (substr($cap, 0, 14) === 'manage_network') {
858
+ return true;
859
+ }
860
+
861
+ return false;
862
+ }
863
+
864
+ public static function init() {
865
+ //switch_blog
866
+ add_action('admin_init', '\WPFront\URE\WPFront_User_Role_Editor_Roles_Helper::add_wpfront_caps_to_roles', 1);
867
+
868
+ add_filter('wpfront_ure_restore_role_custom_caps', '\WPFront\URE\WPFront_User_Role_Editor_Roles_Helper::restore_role_custom_caps');
869
+
870
+ add_filter('wpfront_ure_capability_ui_help_link', '\WPFront\URE\WPFront_User_Role_Editor_Roles_Helper::cap_help_link', 10, 3);
871
+
872
+ self::add_wpfront_caps_to_roles();
873
+ }
874
+
875
+ public static function clear_cache() {
876
+ self::$capability_group_names = null;
877
+ self::$group_capabilities_cache = array();
878
+
879
+ //not a cache, do not clear
880
+ //self::$custom_capability_groups = array();
881
+ }
882
+
883
+ }
884
+
885
+ add_action('wpfront_ure_init', array(WPFront_User_Role_Editor_Roles_Helper::class, 'init'), 1);
886
+
887
+ add_action('switch_blog', array(WPFront_User_Role_Editor_Roles_Helper::class, 'clear_cache'), 1);
888
+ }
includes/class-uninstall.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Cache for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Uninstall')) {
38
+
39
+ /**
40
+ * Uninstall class
41
+ *
42
+ * @author Syam Mohan <syam@wpfront.com>
43
+ * @copyright 2014 WPFront.com
44
+ */
45
+ class WPFront_User_Role_Editor_Uninstall {
46
+
47
+ private static $entities = array();
48
+ private static $callbacks = array();
49
+
50
+ public static function register_entity($entity) {
51
+ if($entity instanceof \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity) {
52
+ return;
53
+ }
54
+
55
+ self::$entities[] = $entity;
56
+ }
57
+
58
+ public static function register_callback($fnc) {
59
+ self::$callbacks[] = $fnc;
60
+ }
61
+
62
+ public static function uninstall() {
63
+ if(!self::remove_data()) {
64
+ return;
65
+ }
66
+
67
+ if(is_multisite()) {
68
+ $blog_ids = get_sites(array('fields' => 'ids'));
69
+ foreach ($blog_ids as $blogid) {
70
+ switch_to_blog($blogid);
71
+ self::uninstall_action();
72
+ restore_current_blog();
73
+ }
74
+
75
+ } else {
76
+ self::uninstall_action();
77
+ }
78
+
79
+ wp_cache_flush();
80
+ }
81
+
82
+ private static function uninstall_action() {
83
+ foreach (self::$callbacks as $callback) {
84
+ call_user_func($callback);
85
+ }
86
+
87
+ foreach (self::$entities as $entity) {
88
+ $entity->uninstall();
89
+ }
90
+
91
+ $options = new \WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity();
92
+ $options->uninstall();
93
+ }
94
+
95
+ private static function remove_data() {
96
+ $obj = new WPFront_User_Role_Editor_Uninstall();
97
+ return $obj->get_option('remove_data_on_uninstall');
98
+ }
99
+
100
+ protected function __construct() {
101
+ }
102
+
103
+ public static function init() {
104
+ $obj = new WPFront_User_Role_Editor_Uninstall();
105
+ add_filter('wpfront_ure_options_register_ui_field', array($obj, 'register_ui_field'), PHP_INT_MAX, 1);
106
+
107
+ add_action('wpfront_ure_options_ui_field_remove_data_on_uninstall_label', array($obj, 'options_ui_label'));
108
+ add_action('wpfront_ure_options_ui_field_remove_data_on_uninstall', array($obj, 'options_ui_field'));
109
+ add_action('wpfront_ure_options_ui_field_remove_data_on_uninstall_update', array($obj, 'options_ui_update'));
110
+ add_action('wpfront_ure_options_ui_field_remove_data_on_uninstall_help', array($obj, 'options_ui_help'));
111
+ }
112
+
113
+ public function register_ui_field($option_keys) {
114
+ $option_keys['remove_data_on_uninstall'] = '';
115
+
116
+ return $option_keys;
117
+ }
118
+
119
+ public function options_ui_label() {
120
+ echo __('Remove Data on Uninstall', 'wpfront-user-role-editor');
121
+ }
122
+
123
+ public function options_ui_field() {
124
+ $key = 'remove_data_on_uninstall';
125
+
126
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
127
+ $checked = !empty($_POST[$key]);
128
+ } else {
129
+ $checked = $this->get_option($key);
130
+ }
131
+
132
+ $checked = $checked ? 'checked' : '';
133
+
134
+ echo "<input type='checkbox' name='$key' $checked />";
135
+ }
136
+
137
+ public function options_ui_update() {
138
+ $key = 'remove_data_on_uninstall';
139
+ $value = !empty($_POST[$key]);
140
+
141
+ $this->set_option($key, $value, false);
142
+ }
143
+
144
+ public function options_ui_help() {
145
+ return '<strong>' . __('Remove Data on Uninstall', 'wpfront-user-role-editor') . '</strong>: ' . __('If enabled, removes all data related to this plugin from database(except roles data) including license information if any, while deleting the plugin. This will not deactivate the license automatically.', 'wpfront-user-role-editor');
146
+ }
147
+
148
+ protected function get_option($key) {
149
+ return \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->get_network_option_boolean($key, '');
150
+ }
151
+
152
+ protected function set_option($key, $value, $auto_load = true) {
153
+ \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance()->set_network_option($key, $value, '', $auto_load);
154
+ }
155
+
156
+ }
157
+
158
+ add_action('wpfront_ure_init', '\WPFront\URE\WPFront_User_Role_Editor_Uninstall::init');
159
+
160
+ }
includes/class-utils.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Utilities for WPFront User Role Editor
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/globals.php';
38
+
39
+ if (!class_exists('\WPFront\URE\WPFront_User_Role_Editor_Utils')) {
40
+
41
+ /**
42
+ * Utils class
43
+ *
44
+ * @author Syam Mohan <syam@wpfront.com>
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Utils {
48
+
49
+ /**
50
+ * Enqueues font-awesome css.
51
+ */
52
+ public static function enqueue_font_awesome_styles() {
53
+ wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(), '4.7.0');
54
+ }
55
+
56
+ /**
57
+ * Sets the help tab of current screen. Returns whether it was successful.
58
+ *
59
+ * @param array $tabs
60
+ * @param array $sidebar
61
+ * @return boolean
62
+ */
63
+ public static function set_help_tab($tabs, $sidebar) {
64
+ $screen = get_current_screen();
65
+
66
+ if(empty($screen)) {
67
+ return false;
68
+ }
69
+
70
+ if(!empty($tabs)) {
71
+ foreach ($tabs as $value) {
72
+ $screen->add_help_tab($value);
73
+ }
74
+ }
75
+
76
+ if (!empty($sidebar)) {
77
+ $s = '<p><strong>' . __('Links:', 'wpfront-user-role-editor') . '</strong></p>';
78
+
79
+ foreach ($sidebar as $value) {
80
+ $s .= '<p><a target="_blank" href="https://wpfront.com/user-role-editor-pro/' . $value[1] . '">' . $value[0] . '</a></p>';
81
+ }
82
+
83
+ $s .= '<p><a target="_blank" href="https://wpfront.com/user-role-editor-pro/faq/">' . __('FAQ', 'wpfront-user-role-editor') . '</a></p>';
84
+ $s .= '<p><a target="_blank" href="https://wpfront.com/support/">' . __('Support', 'wpfront-user-role-editor') . '</a></p>';
85
+ $s .= '<p><a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/wpfront-user-role-editor">' . __('Review', 'wpfront-user-role-editor') . '</a></p>';
86
+ $s .= '<p><a target="_blank" href="https://wpfront.com/contact/">' . __('Contact', 'wpfront-user-role-editor') . '</a></p>';
87
+
88
+ $screen->set_help_sidebar($s);
89
+ }
90
+
91
+ return true;
92
+ }
93
+
94
+ /**
95
+ * Returns whether current action is AJAX.
96
+ *
97
+ * @return boolean
98
+ */
99
+ public static function doing_ajax() {
100
+ if (defined('DOING_AJAX') && DOING_AJAX) {
101
+ return true;
102
+ }
103
+
104
+ if (!empty($_SERVER['PHP_SELF']) && $_SERVER['PHP_SELF'] === '/wp-admin/admin-ajax.php') {
105
+ return true;
106
+ }
107
+
108
+ if (!empty($_SERVER['DOING_AJAX']) && $_SERVER['DOING_AJAX'] === '/wp-admin/admin-ajax.php') {
109
+ return true;
110
+ }
111
+
112
+ if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
113
+ return true;
114
+ }
115
+
116
+ // if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
117
+ // return true;
118
+ // }
119
+
120
+ return false;
121
+ }
122
+
123
+ public static function network_ajax_url() {
124
+ return admin_url('admin-ajax.php?network=1');
125
+ }
126
+
127
+ public static function doing_network_ajax() {
128
+ return self::doing_ajax() && !empty($_GET['network']);
129
+ }
130
+
131
+ public static function notice_error($message) {
132
+ ?>
133
+ <div class="error notice is-dismissible">
134
+ <p>
135
+ <strong><?php echo $message; ?></strong>
136
+ </p>
137
+ </div>
138
+ <?php
139
+ }
140
+
141
+ public static function notice_updated($message) {
142
+ ?>
143
+ <div class="updated notice is-dismissible">
144
+ <p>
145
+ <strong><?php echo $message; ?></strong>
146
+ </p>
147
+ </div>
148
+ <?php
149
+ }
150
+ }
151
+
152
+ }
includes/globals.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if(!function_exists('wpfront_safe_redirect')) {
4
+
5
+ function wpfront_safe_redirect($location) {
6
+ wp_safe_redirect($location);
7
+ exit();
8
+ }
9
+
10
+ }
includes/go-pro/class-go-pro.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Go Pro
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Go_Pro;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit(); //@codeCoverageIgnore
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/template-go-pro.php';
38
+
39
+ if (!class_exists('\WPFront\URE\Go_Pro\WPFront_User_Role_Editor_Go_Pro')) {
40
+
41
+ /**
42
+ * Go Pro class
43
+ *
44
+ * @author Syam Mohan <syam@wpfront.com>
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Go_Pro extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
48
+
49
+ const MENU_SLUG = 'wpfront-user-role-editor-go-pro';
50
+
51
+ protected static $CAP = 'manage_options';
52
+
53
+ protected $product;
54
+
55
+ protected function setUp() {
56
+ $this->_setUp('manage_options', 'wpfront-user-role-editor-go-pro');
57
+
58
+ $this->product = 'WPFront User Role Editor Pro';
59
+
60
+ $this->ViewClass = WPFront_User_Role_Editor_Go_Pro_View::class;
61
+ }
62
+
63
+
64
+ protected function initialize() {
65
+ do_action('wpfront_ure_init');
66
+
67
+ if(!$this->in_admin_ui()) {
68
+ return;
69
+ }
70
+
71
+ $this->plugin_license_active();
72
+ }
73
+
74
+ /**
75
+ * Setup hooks when plugin license is active.
76
+ */
77
+ protected function plugin_license_active() {
78
+ $this->set_admin_menu($this->get_page_title(), $this->get_menu_label(), 1000);
79
+
80
+ add_filter('plugin_action_links_' . $this->WPFURE->get_plugin_basename(), array($this, 'plugin_action_links'), PHP_INT_MAX);
81
+ add_filter('network_admin_plugin_action_links_' . $this->WPFURE->get_plugin_basename(), array($this, 'plugin_action_links'), PHP_INT_MAX);
82
+ }
83
+
84
+ /**
85
+ * Adds the 'Upgrade' plugin action link.
86
+ *
87
+ * @param string[] $links
88
+ * @return string[]
89
+ */
90
+ public function plugin_action_links($links) {
91
+ $url = 'https://wpfront.com/user-role-editor-pro/';
92
+ $text = __('Upgrade', 'wpfront-user-role-editor');
93
+ $a = sprintf('<a style="color:red;" target="_blank" href="%s">%s</a>', $url, $text);
94
+ array_unshift($links, $a);
95
+
96
+ return $links;
97
+ }
98
+
99
+ /**
100
+ * Displays the go pro view.
101
+ */
102
+ public function view() {
103
+ if(parent::view()) {
104
+ $objView = new $this->ViewClass();
105
+ $objView->view($this->product);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Returns the label used in admin menu.
111
+ *
112
+ * @return string
113
+ */
114
+ protected function get_menu_label() {
115
+ return '<span class="wpfront-go-pro">' . __('Go Pro', 'wpfront-user-role-editor') . '</span>' ;
116
+ }
117
+
118
+ protected function get_page_title() {
119
+ return __('Go Pro', 'wpfront-user-role-editor');
120
+ }
121
+ }
122
+
123
+ add_action('plugins_loaded', array(WPFront_User_Role_Editor_Go_Pro::class, 'init'));
124
+
125
+ }
{classes/integration/plugins → includes/go-pro}/index.php RENAMED
File without changes
includes/go-pro/template-go-pro.php ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Go Pro
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Go_Pro;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit(); //@codeCoverageIgnore
35
+ }
36
+
37
+ if(!class_exists('WPFront\URE\Go_Pro\WPFront_User_Role_Editor_Go_Pro_View')) {
38
+
39
+ class WPFront_User_Role_Editor_Go_Pro_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
40
+
41
+ public function view($title) {
42
+ ?>
43
+ <div class="wrap go-pro">
44
+ <?php $this->title($title); ?>
45
+ <?php do_action('wpfront_ure_internal_go_pro_template'); ?>
46
+ <?php $this->go_pro_html(); ?>
47
+ <?php $this->mailchimp_signup(); ?>
48
+ </div>
49
+ <?php
50
+ }
51
+
52
+ protected function go_pro_html() {
53
+ if(!apply_filters('wpfront_ure_internal_go_pro_template_show_comparison', true)) {
54
+ return;
55
+ }
56
+ ?>
57
+ <div class="container">
58
+ <div class="col col1">
59
+ <div class="cell header">
60
+ <h3>Free Version</h3>
61
+ </div>
62
+ <div class="cell">
63
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/add-role/">Add/Edit/Delete</a>
64
+ </div>
65
+ <div class="cell">
66
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/restore-role/">Restore Roles</a>
67
+ </div>
68
+ <div class="cell">
69
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/assign-migrate-users/">Assign/Migrate Users</a>
70
+ </div>
71
+ <div class="cell">
72
+ <i class="fa fa-times"></i>
73
+ </div>
74
+ <div class="cell">
75
+ <i class="fa fa-times"></i>
76
+ </div>
77
+ <div class="cell">
78
+ <i class="fa fa-times"></i>
79
+ </div>
80
+ <div class="cell">
81
+ <i class="fa fa-times"></i>
82
+ </div>
83
+ <div class="cell">
84
+ <i class="fa fa-times"></i>
85
+ </div>
86
+ <div class="cell">
87
+ <i class="fa fa-times"></i>
88
+ </div>
89
+ <div class="cell">
90
+ <i class="fa fa-times"></i>
91
+ </div>
92
+ <div class="cell">
93
+ <i class="fa fa-times"></i>
94
+ </div>
95
+ <div class="cell">
96
+ <i class="fa fa-times"></i>
97
+ </div>
98
+ <div class="cell">
99
+ <i class="fa fa-times"></i>
100
+ </div>
101
+ <div class="cell">
102
+ <i class="fa fa-times"></i>
103
+ </div>
104
+ <div class="cell">
105
+ <i class="fa fa-times"></i>
106
+ </div>
107
+ <div class="cell">
108
+ &nbsp;
109
+ </div>
110
+ </div>
111
+ <div class="col col2">
112
+ <div class="cell header">
113
+ <h3>Personal Pro</h3>
114
+ </div>
115
+ <div class="cell">
116
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/add-role/">Add/Edit/Delete</a>
117
+ </div>
118
+ <div class="cell">
119
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/restore-role/">Restore Roles</a>
120
+ </div>
121
+ <div class="cell">
122
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/assign-migrate-users/">Assign/Migrate Users</a>
123
+ </div>
124
+ <div class="cell">
125
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/navigation-menu-permissions/">Navigation Menu Permissions Advanced</a>
126
+ </div>
127
+ <div class="cell">
128
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/widget-permissions/">Widget Permissions Advanced</a>
129
+ </div>
130
+ <div class="cell">
131
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/login-redirect/">Login Redirect Advanced</a>
132
+ </div>
133
+ <div class="cell">
134
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/menu-editor/">Admin Menu Editor</a>
135
+ </div>
136
+ <div class="cell">
137
+ <a target="_blank" href="https://wpfront.com/media-attachment-file-permissions/">Media Library Permissions</a>
138
+ </div>
139
+ <div class="cell">
140
+ <a target="_blank" href="https://wpfront.com/user-level-permissions/">User Level Permissions</a>
141
+ </div>
142
+ <div class="cell">
143
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/content-restriction-shortcodes/">Content Restriction Shortcodes</a>
144
+ </div>
145
+ <div class="cell">
146
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/posts-pages-extended-permissions/">Posts/Pages Extended Permissions</a>
147
+ </div>
148
+ <div class="cell">
149
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/custom-post-type-permissions/">Custom Post Type Permissions</a>
150
+ </div>
151
+ <div class="cell">
152
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/export-roles/">Import/Export</a>
153
+ </div>
154
+ <div class="cell">
155
+ <i class="fa fa-times"></i>
156
+ </div>
157
+ <div class="cell">
158
+ <a target="_blank" href="https://wpfront.com/support/forum/user-role-editor-pro-2/">Private Forums & Updates for One Year</a>
159
+ </div>
160
+ <div class="cell footer">
161
+ <a class="button-primary" href="https://wpfront.com/ppro" target="_blank">
162
+ <i class="fa fa-shopping-cart"></i>
163
+ Buy Now
164
+ </a>
165
+ </div>
166
+ </div>
167
+ <div class="col col3">
168
+ <div class="cell header">
169
+ <h3>Business Pro</h3>
170
+ </div>
171
+ <div class="cell">
172
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/add-role/">Add/Edit/Delete</a>
173
+ </div>
174
+ <div class="cell">
175
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/restore-role/">Restore Roles</a>
176
+ </div>
177
+ <div class="cell">
178
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/assign-migrate-users/">Assign/Migrate Users</a>
179
+ </div>
180
+ <div class="cell">
181
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/navigation-menu-permissions/">Navigation Menu Permissions Advanced</a>
182
+ </div>
183
+ <div class="cell">
184
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/widget-permissions/">Widget Permissions Advanced</a>
185
+ </div>
186
+ <div class="cell">
187
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/login-redirect/">Login Redirect Advanced</a>
188
+ </div>
189
+ <div class="cell">
190
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/menu-editor/">Admin Menu Editor</a>
191
+ </div>
192
+ <div class="cell">
193
+ <a target="_blank" href="https://wpfront.com/media-attachment-file-permissions/">Media Library Permissions</a>
194
+ </div>
195
+ <div class="cell">
196
+ <a target="_blank" href="https://wpfront.com/user-level-permissions/">User Level Permissions</a>
197
+ </div>
198
+ <div class="cell">
199
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/content-restriction-shortcodes/">Content Restriction Shortcodes</a>
200
+ </div>
201
+ <div class="cell">
202
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/posts-pages-extended-permissions/">Posts/Pages Extended Permissions</a>
203
+ </div>
204
+ <div class="cell">
205
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/custom-post-type-permissions/">Custom Post Type Permissions</a>
206
+ </div>
207
+ <div class="cell">
208
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/export-roles/">Import/Export</a>
209
+ </div>
210
+ <div class="cell">
211
+ <a target="_blank" href="https://wpfront.com/user-role-editor-pro/multisite-sync-roles/">Multisite Support</a>
212
+ </div>
213
+ <div class="cell">
214
+ <a target="_blank" href="https://wpfront.com/support/forum/user-role-editor-pro-2/">Private Forums & Updates for One Year</a>
215
+ </div>
216
+ <div class="cell footer">
217
+ <a class="button-primary" href="https://wpfront.com/bpro" target="_blank">
218
+ <i class="fa fa-shopping-cart"></i>
219
+ Buy Now
220
+ </a>
221
+ </div>
222
+ </div>
223
+ </div>
224
+ <?php
225
+ }
226
+
227
+ protected function mailchimp_signup() {
228
+ ?>
229
+ <!-- Begin MailChimp Signup Form -->
230
+ <link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
231
+ <style type="text/css">
232
+ #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
233
+ </style>
234
+ <div id="mc_embed_signup" style="max-width:602px;margin-top:5px;">
235
+ <form action="//wpfront.us10.list-manage.com/subscribe/post?u=025ec8aba76cfe3dcb048824b&amp;id=40d9eecd94" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
236
+ <div id="mc_embed_signup_scroll">
237
+ <h2>Get notified on new features and releases</h2>
238
+ <div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
239
+ <div class="mc-field-group">
240
+ <label for="mce-EMAIL">Email Address <span class="asterisk">*</span>
241
+ </label>
242
+ <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
243
+ </div>
244
+ <div class="mc-field-group">
245
+ <label for="mce-FNAME">First Name </label>
246
+ <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
247
+ </div>
248
+ <div class="mc-field-group">
249
+ <label for="mce-LNAME">Last Name </label>
250
+ <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
251
+ </div>
252
+ <div id="mce-responses" class="clear">
253
+ <div class="response" id="mce-error-response" style="display:none"></div>
254
+ <div class="response" id="mce-success-response" style="display:none"></div>
255
+ </div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
256
+ <div style="position: absolute; left: -5000px;"><input type="text" name="b_025ec8aba76cfe3dcb048824b_40d9eecd94" tabindex="-1" value=""></div>
257
+ <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" style="background-color:#00a0d2;"></div>
258
+ </div>
259
+ </form>
260
+ </div>
261
+ <script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
262
+ <!--End mc_embed_signup-->
263
+ <?php
264
+ }
265
+
266
+ }
267
+
268
+ }
269
+
{css → includes}/index.php RENAMED
File without changes
{images → includes/integration}/index.php RENAMED
File without changes
includes/integration/plugins/bbPress/class-bbPress.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ namespace WPFront\URE\Integration;
26
+
27
+ if (!defined('ABSPATH')) {
28
+ exit();
29
+ }
30
+
31
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
32
+
33
+ if (!class_exists('\WPFront\URE\Integration\WPFront_User_Role_Editor_bbPress_Integration')) {
34
+
35
+ /**
36
+ * bbPress Integration
37
+ *
38
+ * @author Syam Mohan <syam@wpfront.com>
39
+ * @copyright 2014 WPFront.com
40
+ */
41
+ class WPFront_User_Role_Editor_bbPress_Integration {
42
+
43
+ protected static $caps_mapping = array(
44
+ 'create_forums' => 'edit_forums',
45
+ 'read_others_forums' => 'spectate',
46
+ 'create_topics' => 'edit_topics',
47
+ 'read_others_topics' => 'spectate',
48
+ 'create_replies' => 'edit_replies',
49
+ 'read_others_replies' => 'spectate'
50
+ );
51
+
52
+ protected function __construct() {
53
+
54
+ }
55
+
56
+
57
+ public static function init() {
58
+ $instance = new WPFront_User_Role_Editor_bbPress_Integration();
59
+
60
+ add_filter('bbp_get_caps_for_role', array($instance, 'bbp_get_caps_for_role'), 10, 2);
61
+ }
62
+
63
+ /**
64
+ *
65
+ * @param (string|bool)[] $caps
66
+ * @param string $role
67
+ * @return string[]
68
+ */
69
+ public function bbp_get_caps_for_role($caps, $role) {
70
+ foreach (self::$caps_mapping as $cap => $check) {
71
+ if(isset($caps[$check])) {
72
+ $caps[$cap] = $caps[$check];
73
+ }
74
+ }
75
+
76
+ return $caps;
77
+ }
78
+
79
+ }
80
+
81
+ WPFront_User_Role_Editor_bbPress_Integration::init();
82
+
83
+ }
84
+
85
+
{classes → includes}/integration/plugins/class-wpfront-user-role-editor-plugin-integration.php RENAMED
@@ -1,75 +1,80 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- if (!class_exists('WPFront_User_Role_Editor_Plugin_Integration')) {
30
-
31
- /**
32
- * Base class of Plugin Integration
33
- *
34
- * @author Syam Mohan <syam@wpfront.com>
35
- * @copyright 2014 WPFront.com
36
- */
37
- abstract class WPFront_User_Role_Editor_Plugin_Integration {
38
-
39
- const ADMINISTRATOR_ROLE_KEY = WPFront_User_Role_Editor::ADMINISTRATOR_ROLE_KEY;
40
-
41
- private $initialized = FALSE;
42
-
43
- protected abstract function init($params);
44
-
45
- protected abstract function translate_capability($capability);
46
-
47
- public function __construct($slug) {
48
- add_action("wpfront_user_role_editor_{$slug}_init", array($this, '_init'));
49
-
50
- add_filter("wpfront_user_role_editor_{$slug}_integration_ready", array($this, '_integration_ready'));
51
- add_filter("wpfront_user_role_editor_{$slug}_translate_capability", array($this, '_translate_capability'));
52
- }
53
-
54
- public function _init($params) {
55
- $this->initialized = TRUE;
56
- $this->init($params);
57
- }
58
-
59
- public function _integration_ready() {
60
- return TRUE;
61
- }
62
-
63
- public function _translate_capability($capability) {
64
- if (!$this->initialized)
65
- return $capability;
66
-
67
- return $this->translate_capability($capability);
68
- }
69
-
70
- }
71
-
72
- }
73
-
74
- require_once(plugin_dir_path(__FILE__) . "duplicator/class-wpfront-user-role-editor-plugin-duplicator.php");
75
-
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ namespace WPFront\URE\Integration;
26
+
27
+ if (!defined('ABSPATH')) {
28
+ exit();
29
+ }
30
+
31
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
32
+
33
+ if (!class_exists('\WPFront\URE\Integration\WPFront_User_Role_Editor_Plugin_Integration')) {
34
+
35
+ /**
36
+ * Base class of Plugin Integration
37
+ *
38
+ * @author Syam Mohan <syam@wpfront.com>
39
+ * @copyright 2014 WPFront.com
40
+ */
41
+ abstract class WPFront_User_Role_Editor_Plugin_Integration {
42
+
43
+ const ADMINISTRATOR_ROLE_KEY = RolesHelper::ADMINISTRATOR_ROLE_KEY;
44
+
45
+ private $initialized = FALSE;
46
+
47
+ protected abstract function init($params);
48
+
49
+ protected abstract function translate_capability($capability);
50
+
51
+ public function __construct($slug) {
52
+ add_action("wpfront_user_role_editor_{$slug}_init", array($this, '_init'));
53
+
54
+ add_filter("wpfront_user_role_editor_{$slug}_integration_ready", array($this, '_integration_ready'));
55
+ add_filter("wpfront_user_role_editor_{$slug}_translate_capability", array($this, '_translate_capability'));
56
+ }
57
+
58
+ public function _init($params) {
59
+ $this->initialized = TRUE;
60
+ $this->init($params);
61
+ }
62
+
63
+ public function _integration_ready() {
64
+ return TRUE;
65
+ }
66
+
67
+ public function _translate_capability($capability) {
68
+ if (!$this->initialized)
69
+ return $capability;
70
+
71
+ return $this->translate_capability($capability);
72
+ }
73
+
74
+ }
75
+
76
+ }
77
+
78
+ require_once(plugin_dir_path(__FILE__) . "duplicator/class-wpfront-user-role-editor-plugin-duplicator.php");
79
+ require_once(plugin_dir_path(__FILE__) . "bbPress/class-bbPress.php");
80
+
{classes → includes}/integration/plugins/duplicator/class-wpfront-user-role-editor-plugin-duplicator.php RENAMED
@@ -1,64 +1,66 @@
1
- <?php
2
- /*
3
- WPFront User Role Editor Plugin
4
- Copyright (C) 2014, WPFront.com
5
- Website: wpfront.com
6
- Contact: syam@wpfront.com
7
-
8
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
- St, Fifth Floor, Boston, MA 02110, USA
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
- */
23
-
24
- if (!defined('ABSPATH')) {
25
- exit();
26
- }
27
-
28
- if (!class_exists('WPFront_User_Role_Editor_Plugin_Duplicator')) {
29
-
30
- /**
31
- * Main class of Duplicator Integration
32
- *
33
- * @author Syam Mohan <syam@wpfront.com>
34
- * @copyright 2014 WPFront.com
35
- */
36
- class WPFront_User_Role_Editor_Plugin_Duplicator extends WPFront_User_Role_Editor_Plugin_Integration {
37
-
38
- private static $slug = 'duplicator';
39
-
40
- public function __construct() {
41
- parent::__construct(self::$slug);
42
- }
43
-
44
- protected function init($params) {
45
- $admin_role = get_role(self::ADMINISTRATOR_ROLE_KEY);
46
- $caps = array();
47
- foreach($params as $value) {
48
- $cap = $this->translate_capability($value);
49
- $caps[$cap] = TRUE;
50
- $admin_role->add_cap($cap);
51
- }
52
-
53
- add_role(self::$slug, 'Duplicator', $caps);
54
- }
55
-
56
- protected function translate_capability($capability) {
57
- return self::$slug . '_' . $capability;
58
- }
59
-
60
- }
61
-
62
- new WPFront_User_Role_Editor_Plugin_Duplicator();
63
- }
64
-
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ namespace WPFront\URE\Integration;
25
+
26
+ if (!defined('ABSPATH')) {
27
+ exit();
28
+ }
29
+
30
+ if (!class_exists('\WPFront\URE\Integration\WPFront_User_Role_Editor_Plugin_Duplicator')) {
31
+
32
+ /**
33
+ * Main class of Duplicator Integration
34
+ *
35
+ * @author Syam Mohan <syam@wpfront.com>
36
+ * @copyright 2014 WPFront.com
37
+ */
38
+ class WPFront_User_Role_Editor_Plugin_Duplicator extends WPFront_User_Role_Editor_Plugin_Integration {
39
+
40
+ private static $slug = 'duplicator';
41
+
42
+ public function __construct() {
43
+ parent::__construct(self::$slug);
44
+ }
45
+
46
+ protected function init($params) {
47
+ $admin_role = get_role(self::ADMINISTRATOR_ROLE_KEY);
48
+ $caps = array();
49
+ foreach($params as $value) {
50
+ $cap = $this->translate_capability($value);
51
+ $caps[$cap] = TRUE;
52
+ $admin_role->add_cap($cap);
53
+ }
54
+
55
+ add_role(self::$slug, 'Duplicator', $caps);
56
+ }
57
+
58
+ protected function translate_capability($capability) {
59
+ return self::$slug . '_' . $capability;
60
+ }
61
+
62
+ }
63
+
64
+ new WPFront_User_Role_Editor_Plugin_Duplicator();
65
+ }
66
+
{js → includes/integration/plugins/duplicator}/index.php RENAMED
File without changes
{languages → includes/integration/plugins}/index.php RENAMED
File without changes
includes/login-redirect/class-login-redirect-list-table.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * WPFront User Role Editor Login Redirect List Table
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect as LoginRedirect;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
39
+
40
+ if (!class_exists('\WP_List_Table')) {
41
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
42
+ }
43
+
44
+ if (!class_exists('\WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_List_Table')) {
45
+
46
+ /**
47
+ * Login Redirect List Table
48
+ *
49
+ * @author Syam Mohan <syam@wpfront.com>
50
+ * @copyright 2015 WPFront.com
51
+ */
52
+ class WPFront_User_Role_Editor_Login_Redirect_List_Table extends \WP_List_Table {
53
+
54
+ /**
55
+ *
56
+ * @var string[] Associative (name=>display)
57
+ */
58
+ protected $allowed_roles;
59
+
60
+ public function __construct() {
61
+ parent::__construct(array('screen' => 'login-redirect'));
62
+ }
63
+
64
+ function ajax_user_can() {
65
+ return current_user_can('edit_login_redirects');
66
+ }
67
+
68
+ function prepare_items() {
69
+ $search = '';
70
+ if(!empty($_GET['s'])) {
71
+ $search = $_GET['s'];
72
+ }
73
+
74
+ $this->items = LoginRedirect::instance()->get_login_redirects($search);
75
+
76
+ $this->set_pagination_args(array(
77
+ 'total_items' => count($this->items),
78
+ 'per_page' => PHP_INT_MAX,
79
+ ));
80
+ }
81
+
82
+ function get_bulk_actions() {
83
+ $actions = array();
84
+
85
+ if (current_user_can('delete_login_redirects')) {
86
+ $actions['delete'] = __('Delete', 'wpfront-user-role-editor');
87
+ }
88
+
89
+ return $actions;
90
+ }
91
+
92
+ function no_items() {
93
+ echo __('No login redirects found.', 'wpfront-user-role-editor');
94
+ }
95
+
96
+ function get_views() {
97
+ $role_links = array();
98
+
99
+ return $role_links;
100
+ }
101
+
102
+ function pagination($which) {
103
+ parent::pagination($which);
104
+ }
105
+
106
+ function get_columns() {
107
+ $columns = array(
108
+ 'cb' => '<input type="checkbox" />',
109
+ 'role' => __('Role', 'wpfront-user-role-editor'),
110
+ 'priority' => __('Priority', 'wpfront-user-role-editor'),
111
+ 'url' => __('Login Redirect URL', 'wpfront-user-role-editor'),
112
+ 'logout_url' => __('Logout Redirect URL', 'wpfront-user-role-editor'),
113
+ 'deny_wpadmin' => __('WP-ADMIN', 'wpfront-user-role-editor'),
114
+ 'disable_toolbar' => __('Toolbar', 'wpfront-user-role-editor')
115
+ );
116
+
117
+ return $columns;
118
+ }
119
+
120
+ function get_sortable_columns() {
121
+ return array();
122
+ }
123
+
124
+ function display_rows() {
125
+ foreach ($this->items as $item) {
126
+ $alt = empty($alt) ? 'alternate' : '';
127
+ $item->role_display = $this->get_role_display($item->role);
128
+ ?>
129
+ <tr class="<?php echo $alt; ?>">
130
+ <?php
131
+ list( $columns, $hidden ) = $this->get_column_info();
132
+
133
+ foreach ($columns as $column_name => $column_display_name) {
134
+ $class = "class='$column_name column-$column_name'";
135
+
136
+ $style = '';
137
+ if (in_array($column_name, $hidden))
138
+ $style = ' style="display:none;"';
139
+
140
+ $attributes = "$class$style";
141
+
142
+ switch ($column_name) {
143
+ case 'cb':
144
+ $this->cb_cell($item);
145
+ break;
146
+
147
+ case 'role':
148
+ $this->role_cell($item, $attributes);
149
+ break;
150
+
151
+ case 'priority':
152
+ echo "<td $attributes>" . $item->priority . "</td>";
153
+ break;
154
+
155
+ case 'url':
156
+ echo "<td $attributes>" . $this->format_url($item->url) . "</td>";
157
+ break;
158
+
159
+ case 'logout_url':
160
+ echo "<td $attributes>" . $this->format_url($item->logout_url) . "</td>";
161
+ break;
162
+
163
+ case 'deny_wpadmin':
164
+ echo "<td $attributes>" . ($item->deny_wpadmin ? '<i class="fa fa-times"></i>' : '<i class="fa fa-check"></i>') . "</td>";
165
+ break;
166
+
167
+ case 'disable_toolbar':
168
+ echo "<td $attributes>" . ($item->disable_toolbar ? '<i class="fa fa-times"></i>' : '<i class="fa fa-check"></i>') . "</td>";
169
+ break;
170
+ }
171
+ }
172
+ ?>
173
+ </tr>
174
+ <?php
175
+ }
176
+ }
177
+
178
+ protected function cb_cell($item) {
179
+ ?>
180
+ <th scope="row" class="check-column">
181
+ <label class="screen-reader-text" for="role_<?php echo $item->role; ?>"><?php echo sprintf(__('Select %s', 'wpfront-user-role-editor'), $item->role_display); ?></label>
182
+ <input type="checkbox" id="role_<?php echo $item->role; ?>" name="roles[]" value="<?php echo esc_attr($item->role); ?>" />
183
+ </th>
184
+ <?php
185
+ }
186
+
187
+ protected function role_cell($item, $attributes) {
188
+ $can_edit = current_user_can('edit_login_redirects');
189
+ if($can_edit) {
190
+ $allowed_roles = $this->get_allowed_roles();
191
+ $can_edit = isset($allowed_roles[$item->role]);
192
+ }
193
+ ?>
194
+ <td <?php echo $attributes; ?>>
195
+ <?php
196
+ if($can_edit) {
197
+ $edit_link = LoginRedirect::instance()->get_edit_url($item->role);
198
+ ?>
199
+ <strong>
200
+ <a href="<?php echo $edit_link; ?>" class="edit">
201
+ <?php echo $item->role_display; ?>
202
+ </a>
203
+ </strong>
204
+ <?php
205
+ } else {
206
+ ?>
207
+ <strong>
208
+ <?php echo $item->role_display; ?>
209
+ </strong>
210
+ <?php
211
+ }
212
+ $actions = array();
213
+ if ($can_edit) {
214
+ $edit_link = LoginRedirect::instance()->get_edit_url($item->role);
215
+ $display = __('Edit', 'wpfront-user-role-editor');
216
+ $actions['edit'] = "<a href='$edit_link'>$display</a>";
217
+ }
218
+ if (current_user_can('delete_login_redirects')) {
219
+ $delete_link = LoginRedirect::instance()->get_delete_url($item->role);
220
+ $display = __('Delete', 'wpfront-user-role-editor');
221
+ $actions['delete'] = "<a href='$delete_link'>$display</a>";
222
+ }
223
+ echo $this->row_actions($actions);
224
+ ?>
225
+ </td>
226
+ <?php
227
+ }
228
+
229
+ protected function get_role_display($role_name) {
230
+ return LoginRedirect::instance()->get_role_display($role_name);
231
+ }
232
+
233
+ protected function format_url($url) {
234
+ return LoginRedirect::instance()->format_url($url);
235
+ }
236
+
237
+ protected function get_allowed_roles() {
238
+ if(!empty($this->allowed_roles)) {
239
+ return $this->allowed_roles;
240
+ }
241
+ $this->allowed_roles = LoginRedirect::instance()->get_allowed_roles();
242
+ return $this->allowed_roles;
243
+ }
244
+
245
+ }
246
+
247
+ }
includes/login-redirect/class-login-redirect.php ADDED
@@ -0,0 +1,643 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Login Redirect
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
38
+
39
+ require_once dirname(__FILE__) . '/entity-login-redirect.php';
40
+ require_once dirname(__FILE__) . '/template-login-redirect.php';
41
+ require_once dirname(__FILE__) . '/template-add-edit.php';
42
+ require_once dirname(__FILE__) . '/template-delete.php';
43
+
44
+ if (!class_exists('\WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect')) {
45
+
46
+ /**
47
+ * Login Redirect class
48
+ *
49
+ * @author Syam Mohan <syam@wpfront.com>
50
+ * @copyright 2014 WPFront.com
51
+ */
52
+ class WPFront_User_Role_Editor_Login_Redirect extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
53
+ const MENU_SLUG = 'wpfront-user-role-editor-login-redirect';
54
+ const CAP = 'edit_login_redirects';
55
+
56
+ protected function setUp() {
57
+ $this->_setUp('edit_login_redirects', 'wpfront-user-role-editor-login-redirect');
58
+
59
+ $this->ViewClass = WPFront_User_Role_Editor_Login_Redirect_View::class;
60
+ }
61
+
62
+ protected function initialize() {
63
+ add_filter('login_redirect', array($this, 'login_redirect_callback'), PHP_INT_MAX, 3);
64
+ add_filter('logout_redirect', array($this, 'logout_redirect_callback'), PHP_INT_MAX, 3);
65
+ add_filter('show_admin_bar', array($this, 'show_toolbar'), PHP_INT_MAX, 1);
66
+
67
+ if(!$this->in_admin_ui()) {
68
+ return;
69
+ }
70
+
71
+ $this->set_admin_menu(__('Login Redirect', 'wpfront-user-role-editor'), __('Login Redirect', 'wpfront-user-role-editor'));
72
+
73
+ add_action('admin_init', array($this, 'admin_init'), 1);
74
+ }
75
+
76
+ /**
77
+ * Hooks into login redirect filter.
78
+ *
79
+ * @param string $redirect_to
80
+ * @param string $request_from
81
+ * @param WP_User $obj_user
82
+ * @return string
83
+ */
84
+ public function login_redirect_callback($redirect_to, $request_from = '', $obj_user = NULL) {
85
+ $entity = $this->get_current_user_role_entity($obj_user);
86
+
87
+ if(empty($entity)) {
88
+ return $redirect_to;
89
+ } else {
90
+ return $this->format_url($entity->url);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Hooks into logout redirect filter.
96
+ *
97
+ * @param string $redirect_to
98
+ * @param string $request_from
99
+ * @param WP_User $obj_user
100
+ * @return string
101
+ */
102
+ public function logout_redirect_callback($redirect_to, $request_from = '', $obj_user = NULL) {
103
+ $entity = $this->get_current_user_role_entity($obj_user);
104
+
105
+ if(empty($entity)) {
106
+ return $redirect_to;
107
+ } else {
108
+ if(empty($entity->logout_url)) {
109
+ return $redirect_to;
110
+ }
111
+
112
+ return $this->format_url($entity->logout_url);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Hooks into admin_init to handle deny wp-admin functionality.
118
+ */
119
+ public function admin_init() {
120
+ if($this->UtilsClass::doing_ajax()) {
121
+ return;
122
+ }
123
+
124
+ $entity = $this->get_current_user_role_entity(null);
125
+ if(empty($entity)) {
126
+ return;
127
+ }
128
+
129
+ if($entity->deny_wpadmin) {
130
+ wp_redirect($this->format_url($entity->url));
131
+ exit();
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Hooks into show_admin_bar filter and does disable toolbar functionality.
137
+ *
138
+ * @param boolean $show
139
+ * @return boolean
140
+ */
141
+ public function show_toolbar($show) {
142
+ $entity = $this->get_current_user_role_entity(null);
143
+ if(!empty($entity) && $entity->disable_toolbar) {
144
+ return false;
145
+ }
146
+
147
+ return $show;
148
+ }
149
+
150
+ /**
151
+ * Returns the entity object which corresponds to currently logged in user.
152
+ *
153
+ * @param WP_User $obj_user
154
+ * @return WPFront_User_Role_Editor_Login_Redirect_Entity
155
+ */
156
+ private function get_current_user_role_entity($obj_user) {
157
+ if (empty($obj_user) || is_wp_error($obj_user)) {
158
+ $obj_user = wp_get_current_user();
159
+ }
160
+
161
+ if (empty($obj_user) || is_wp_error($obj_user)) {
162
+ return null;
163
+ }
164
+
165
+ if (empty($obj_user->roles) || !is_array($obj_user->roles)) {
166
+ return null;
167
+ }
168
+
169
+ $roles = $obj_user->roles;
170
+ if (in_array(RolesHelper::ADMINISTRATOR_ROLE_KEY, $roles)) {
171
+ return null;
172
+ }
173
+
174
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
175
+ $data = $entity->get_all_login_redirects();
176
+
177
+ $allowed_roles = $this->get_allowed_roles();
178
+
179
+ foreach($data as $priority => $login_redirect) {
180
+ if(!isset($allowed_roles[$login_redirect->role])) {
181
+ continue;
182
+ }
183
+
184
+ if(in_array($login_redirect->role, $roles)) {
185
+ return $login_redirect;
186
+ }
187
+ }
188
+
189
+ return null;
190
+ }
191
+
192
+ public function load_view() {
193
+ if(!parent::load_view()) {
194
+ return;
195
+ }
196
+
197
+ if(isset($_GET['screen']) && $_GET['screen'] === 'edit') {
198
+ if(!empty($_GET['role'])) {
199
+ $role = $_GET['role'];
200
+ $allowed_roles = $this->get_allowed_roles();
201
+ if(!isset($allowed_roles[$role])) {
202
+ wp_safe_redirect($this->get_list_url());
203
+ exit();
204
+ }
205
+ }
206
+ }
207
+
208
+ if(!empty($_POST['submit']) && !empty($_POST['bulk-delete'])) {
209
+ if(!current_user_can('delete_login_redirects')) {
210
+ $this->WPFURE->permission_denied();
211
+ return;
212
+ }
213
+
214
+ check_admin_referer('delete-login-redirect');
215
+
216
+ $roles = array_keys($_POST['bulk-delete']);
217
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
218
+ foreach ($roles as $role) {
219
+ $entity->delete($role);
220
+ }
221
+
222
+ wp_safe_redirect($this->get_list_url(). '&deleted=true');
223
+ exit();
224
+ }
225
+
226
+ if(!empty($_POST['submit']) && isset($_GET['screen'])) {
227
+ check_admin_referer('add-edit-login-redirect');
228
+
229
+ if(empty($_POST['priority'])) {
230
+ return;
231
+ }
232
+
233
+ $priority = intval($_POST['priority']);
234
+ if($priority < 1) {
235
+ return;
236
+ }
237
+
238
+ if(empty($_POST['url'])) {
239
+ return;
240
+ }
241
+ $url = $_POST['url'];
242
+
243
+ $logout_url = '';
244
+ if(!empty($_POST['logout_url'])) {
245
+ $logout_url = $_POST['logout_url'];
246
+ }
247
+
248
+ $deny_wpadmin = !empty($_POST['deny_wpadmin']);
249
+ $disable_toolbar = !empty($_POST['disable_toolbar']);
250
+
251
+ if($_GET['screen'] === 'add-new') {
252
+ if(empty($_POST['role'])) {
253
+ return;
254
+ }
255
+ $role = $_POST['role'];
256
+ $allowed_roles = $this->get_allowed_roles();
257
+ if(!isset($allowed_roles[$role])) {
258
+ return;
259
+ }
260
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
261
+ $entity->role = $role;
262
+ } elseif($_GET['screen'] === 'edit') {
263
+ $role = $_GET['role'];
264
+ $entity = $this->get_login_redirect($role);
265
+ if(empty($entity)) {
266
+ wp_safe_redirect($this->get_list_url());
267
+ exit();
268
+ }
269
+ }
270
+
271
+ $entity->priority = $priority;
272
+ $entity->url = $url;
273
+ $entity->logout_url = $logout_url;
274
+ $entity->deny_wpadmin = $deny_wpadmin;
275
+ $entity->disable_toolbar = $disable_toolbar;
276
+
277
+ if($_GET['screen'] === 'add-new') {
278
+ $entity->add();
279
+ } elseif($_GET['screen'] === 'edit') {
280
+ $entity->update();
281
+ }
282
+
283
+ wp_safe_redirect($this->get_edit_url($role). '&changes-saved=true');
284
+ exit();
285
+ }
286
+
287
+ $screen = 'list';
288
+
289
+ if(!empty($_GET['screen'])) {
290
+ $screen = $_GET['screen'];
291
+ } else {
292
+ if((!empty($_POST['action']) && $_POST['action'] === 'delete') || (!empty($_POST['action2']) && $_POST['action2'] === 'delete')) {
293
+ $screen = 'delete';
294
+ }
295
+ }
296
+
297
+ $this->set_help_tab($screen);
298
+ }
299
+
300
+ /**
301
+ * Displays the login redirect view.
302
+ */
303
+ public function view() {
304
+ if(!parent::view()) {
305
+ return;
306
+ }
307
+
308
+ if(!empty($_GET['screen'])) {
309
+ $screen = $_GET['screen'];
310
+
311
+ switch ($screen) {
312
+ case 'add-new':
313
+ $objView = new WPFront_User_Role_Editor_Login_Redirect_Add_Edit_View();
314
+ $objView->view();
315
+ return;
316
+
317
+ case 'edit':
318
+ $role = $_GET['role'];
319
+ $objView = new WPFront_User_Role_Editor_Login_Redirect_Add_Edit_View($this->get_login_redirect($role));
320
+ $objView->view();
321
+ return;
322
+
323
+ case 'delete':
324
+ if(!current_user_can('delete_login_redirects')) {
325
+ $this->WPFURE->permission_denied();
326
+ return;
327
+ }
328
+
329
+ $role = $_GET['role'];
330
+ $objView = new WPFront_User_Role_Editor_Login_Redirect_Delete_View(array($role));
331
+ $objView->view();
332
+ return;
333
+ }
334
+ }
335
+
336
+ if((!empty($_POST['action']) && $_POST['action'] === 'delete') || (!empty($_POST['action2']) && $_POST['action2'] === 'delete')) {
337
+ if(!empty($_POST['roles'])) {
338
+ if(!current_user_can('delete_login_redirects')) {
339
+ $this->WPFURE->permission_denied();
340
+ return;
341
+ }
342
+
343
+ $objView = new WPFront_User_Role_Editor_Login_Redirect_Delete_View($_POST['roles']);
344
+ $objView->view();
345
+ return;
346
+ }
347
+ }
348
+
349
+ $objView = new WPFront_User_Role_Editor_Login_Redirect_View();
350
+ $objView->view();
351
+ }
352
+
353
+ /**
354
+ * Returns allowed login redirects.
355
+ *
356
+ * @param string $search
357
+ * @return WPFront_User_Role_Editor_Login_Redirect_Entity[] Associative(priority=>entity)
358
+ */
359
+ public function get_login_redirects($search = null) {
360
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
361
+ $lists = $entity->get_all_login_redirects();
362
+
363
+ if(empty($search)) {
364
+ return $lists;
365
+ }
366
+
367
+ foreach($lists as $priority => $entity) {
368
+ $role_display = $this->get_role_display($entity->role);
369
+ if(strpos($role_display, $search) !== false) {
370
+ continue;
371
+ }
372
+
373
+ $url = $this->format_url($entity->url);
374
+ if(strpos($url, $search) !== false) {
375
+ continue;
376
+ }
377
+
378
+ $logout_url = $this->format_url($entity->logout_url);
379
+ if(strpos($logout_url, $search) !== false) {
380
+ continue;
381
+ }
382
+
383
+ unset($lists[$priority]);
384
+ }
385
+
386
+ return $lists;
387
+ }
388
+
389
+ /**
390
+ * Returns the entity against role name.
391
+ *
392
+ * @param string $role_name
393
+ * @return WPFront_User_Role_Editor_Login_Redirect_Entity|null
394
+ */
395
+ public function get_login_redirect($role_name) {
396
+ $lists = $this->get_login_redirects();
397
+ foreach ($lists as $priority => $entity) {
398
+ if($entity->role === $role_name) {
399
+ return $entity;
400
+ }
401
+ }
402
+
403
+ return null;
404
+ }
405
+
406
+ /**
407
+ * Returns allowed roles for login redirect.
408
+ *
409
+ * @return string[] Associative (name=>display)
410
+ */
411
+ public function get_allowed_roles() {
412
+ $roles = RolesHelper::get_names();
413
+ $std_roles = RolesHelper::get_default_rolenames();
414
+
415
+ foreach ($roles as $name => $display) {
416
+ if(!in_array($name, $std_roles)) {
417
+ unset($roles[$name]);
418
+ }
419
+ }
420
+
421
+ return $roles;
422
+ }
423
+
424
+ /**
425
+ * Returns roles info for new login redirects.
426
+ *
427
+ * @return array Array(role_name => (object)[(string)display_name, (bool)allowed]
428
+ */
429
+ public function get_roles_info_for_new() {
430
+ $roles = RolesHelper::get_names();
431
+ unset($roles[RolesHelper::ADMINISTRATOR_ROLE_KEY]);
432
+
433
+ $login_redirects = $this->get_login_redirects(null);
434
+
435
+ $existing = array();
436
+ foreach ($login_redirects as $priority => $entity) {
437
+ $existing[$entity->role] = true;
438
+ }
439
+
440
+ $allowed = $this->get_allowed_roles();
441
+
442
+ $roles_info = array();
443
+ foreach ($roles as $role_name => $display) {
444
+ if(isset($existing[$role_name])) {
445
+ continue;
446
+ }
447
+
448
+ $roles_info[$role_name] = (object)array('display_name' => $display, 'allowed' => isset($allowed[$role_name]));
449
+ }
450
+
451
+ return $roles_info;
452
+ }
453
+
454
+ /**
455
+ * Returns the next priority for add.
456
+ *
457
+ * @return int
458
+ */
459
+ public function get_next_priority() {
460
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
461
+ return $entity->get_next_priority();
462
+ }
463
+
464
+ /**
465
+ * Returns the display text for a role.
466
+ *
467
+ * @param string $role_name
468
+ * @return string
469
+ */
470
+ public function get_role_display($role_name) {
471
+ $names = RolesHelper::get_names();
472
+ if(isset($names[$role_name])) {
473
+ return $names[$role_name];
474
+ }
475
+
476
+ return $role_name;
477
+ }
478
+
479
+ /**
480
+ * Formats the url based on home url.
481
+ *
482
+ * @param string $url
483
+ * @return string
484
+ */
485
+ public function format_url($url) {
486
+ if(empty($url))
487
+ return '';
488
+
489
+ $url = strtolower($url);
490
+
491
+ if (strpos($url, '://') > -1)
492
+ return $url;
493
+
494
+ return home_url($url);
495
+ }
496
+
497
+ /**
498
+ * Return login redirect list url.
499
+ *
500
+ * @return string
501
+ */
502
+ public function get_list_url() {
503
+ return $this->get_self_url();
504
+ }
505
+
506
+ /**
507
+ * Returns the add new login redirect URL.
508
+ *
509
+ * @return string
510
+ */
511
+ public function get_add_new_url() {
512
+ return $this->get_self_url(['screen' => 'add-new']);
513
+ }
514
+
515
+ /**
516
+ * Returns the edit login redirect URL for a role.
517
+ *
518
+ * @param string $role
519
+ * @return string
520
+ */
521
+ public function get_edit_url($role) {
522
+ return $this->get_self_url(['screen' => 'edit', 'role' => $role]);
523
+ }
524
+
525
+ /**
526
+ * Returns the delete login redirect URL for a role.
527
+ *
528
+ * @param string $role
529
+ * @return string
530
+ */
531
+ public function get_delete_url($role) {
532
+ return $this->get_self_url(['screen' => 'delete', 'role' => $role]);
533
+ }
534
+
535
+ /**
536
+ * Sets the help tab
537
+ *
538
+ * @param string $screen
539
+ */
540
+ protected function set_help_tab($screen) {
541
+ switch($screen) {
542
+ case 'list':
543
+ $tabs = array(
544
+ array(
545
+ 'id' => 'overview',
546
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
547
+ 'content' => '<p>'
548
+ . __('Use this functionality to redirect a user to a specific page after they login based on their role.', 'wpfront-user-role-editor')
549
+ . '</p>'
550
+ . '<p>'
551
+ . __('In addition, you can also deny the user access to WP-ADMIN and remove the toolbar (admin bar) from the front end.', 'wpfront-user-role-editor')
552
+ . '</p>'
553
+ ),
554
+ array(
555
+ 'id' => 'columns',
556
+ 'title' => __('Columns', 'wpfront-user-role-editor'),
557
+ 'content' => '<p>'
558
+ . sprintf('<b>%s</b>: %s', __('Role', 'wpfront-user-role-editor'), __('The role of the user to qualify for this redirect.', 'wpfront-user-role-editor'))
559
+ . '</p>'
560
+ . '<p>'
561
+ . sprintf('<b>%s</b>: %s', __('Priority', 'wpfront-user-role-editor'), __('When a user has multiple roles, the role configuration with the highest priority will be selected.', 'wpfront-user-role-editor'))
562
+ . '</p>'
563
+ . '<p>'
564
+ . sprintf('<b>%s</b>: %s', __('Login Redirect URL', 'wpfront-user-role-editor'), __('The URL where the user will be redirected after login or on WP-ADMIN access if denied.', 'wpfront-user-role-editor'))
565
+ . '</p>'
566
+ . '<p>'
567
+ . sprintf('<b>%s</b>: %s', __('Logout Redirect URL', 'wpfront-user-role-editor'), __('The URL where the user will be redirected after logout.', 'wpfront-user-role-editor'))
568
+ . '</p>'
569
+ . '<p>'
570
+ . sprintf('<b>%s</b>: %s', __('WP-ADMIN', 'wpfront-user-role-editor'), __('Displays whether user has access to WP-ADMIN.', 'wpfront-user-role-editor'))
571
+ . '</p>'
572
+ . '<p>'
573
+ . sprintf('<b>%s</b>: %s', __('Toolbar', 'wpfront-user-role-editor'), __('Displays whether user will see toolbar on front end.', 'wpfront-user-role-editor'))
574
+ . '</p>'
575
+ )
576
+ );
577
+ break;
578
+
579
+ case 'add-new':
580
+ case 'edit':
581
+ $tabs = array(
582
+ array(
583
+ 'id' => 'overview',
584
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
585
+ 'content' => '<p>'
586
+ . __('Add/Edit a new login redirect.', 'wpfront-user-role-editor')
587
+ . '</p>'
588
+ ),
589
+ array(
590
+ 'id' => 'fields',
591
+ 'title' => __('Fields', 'wpfront-user-role-editor'),
592
+ 'content' => '<p>'
593
+ . sprintf('<b>%s</b>: %s', __('Role', 'wpfront-user-role-editor'), __('The role of the user to qualify for this redirect.', 'wpfront-user-role-editor'))
594
+ . '</p>'
595
+ . '<p>'
596
+ . sprintf('<b>%s</b>: %s', __('Priority', 'wpfront-user-role-editor'), __('When a user has multiple roles, the role configuration with the highest priority will be selected.', 'wpfront-user-role-editor'))
597
+ . '</p>'
598
+ . '<p>'
599
+ . sprintf('<b>%s</b>: %s', __('Login Redirect URL', 'wpfront-user-role-editor'), __('The URL where the user will be redirected after login or on WP-ADMIN access if denied.', 'wpfront-user-role-editor'))
600
+ . '</p>'
601
+ . '<p>'
602
+ . sprintf('<b>%s</b>: %s', __('Logout Redirect URL', 'wpfront-user-role-editor'), __('The URL where the user will be redirected after logout.', 'wpfront-user-role-editor'))
603
+ . '</p>'
604
+ . '<p>'
605
+ . sprintf('<b>%s</b>: %s', __('Deny WP-ADMIN', 'wpfront-user-role-editor'), __('If enabled user will be redirected to URL on WP-ADMIN access.', 'wpfront-user-role-editor'))
606
+ . '</p>'
607
+ . '<p>'
608
+ . sprintf('<b>%s</b>: %s', __('Disable Toolbar', 'wpfront-user-role-editor'), __('If enabled user will not see toolbar on front end.', 'wpfront-user-role-editor'))
609
+ . '</p>'
610
+ )
611
+ );
612
+ break;
613
+
614
+ case 'delete':
615
+ $tabs = array(
616
+ array(
617
+ 'id' => 'overview',
618
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
619
+ 'content' => '<p>'
620
+ . __('Click "Confirm Delete" to delete displayed configurations.', 'wpfront-user-role-editor')
621
+ . '</p>'
622
+ )
623
+ );
624
+ break;
625
+ }
626
+
627
+
628
+
629
+ $sidebar = array(
630
+ array(
631
+ __('Documentation on Login Redirect', 'wpfront-user-role-editor'),
632
+ 'login-redirect/'
633
+ )
634
+ );
635
+
636
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
637
+ }
638
+
639
+ }
640
+
641
+ WPFront_User_Role_Editor_Login_Redirect::load();
642
+
643
+ }
includes/login-redirect/entity-login-redirect.php ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Entity for WPFront User Role Editor Login Redirect
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
38
+ use WPFront\URE\Options\WPFront_User_Role_Editor_Options as Options;
39
+
40
+ require_once dirname(dirname(__FILE__)) . '/settings/entity-options.php';
41
+
42
+ if (!class_exists('WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_Entity')) {
43
+
44
+ /**
45
+ * Login Redirect Entity
46
+ *
47
+ * @author Syam Mohan <syam@wpfront.com>
48
+ * @copyright 2014 WPFront.com
49
+ */
50
+ class WPFront_User_Role_Editor_Login_Redirect_Entity extends \WPFront\URE\WPFront_User_Role_Editor_Entity_Base {
51
+
52
+ /**
53
+ * Primary key.
54
+ *
55
+ * @var int
56
+ */
57
+ public $id;
58
+
59
+ /**
60
+ * WP role name
61
+ *
62
+ * @var string
63
+ */
64
+ public $role;
65
+
66
+ /**
67
+ * Role priority.
68
+ *
69
+ * @var int
70
+ */
71
+ public $priority;
72
+
73
+ /**
74
+ * Login redirect URL.
75
+ *
76
+ * @var string
77
+ */
78
+ public $url;
79
+
80
+ /**
81
+ * Logout redirect URL.
82
+ *
83
+ * @var string|null
84
+ */
85
+ public $logout_url;
86
+
87
+ /**
88
+ * Deny WP-ADMIN access.
89
+ *
90
+ * @var bool
91
+ */
92
+ public $deny_wpadmin;
93
+
94
+ /**
95
+ * Disable site tool bar.
96
+ *
97
+ * @var bool
98
+ */
99
+ public $disable_toolbar;
100
+
101
+
102
+ protected function table_name_suffix() {
103
+ return 'login_redirect';
104
+ }
105
+
106
+ protected function table_create_sql() {
107
+ $table_name = $this->table_name();
108
+
109
+ global $wpdb;
110
+ $charset_collate = $wpdb->get_charset_collate();
111
+
112
+ $sql = "CREATE TABLE $table_name (\n"
113
+ . "id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n"
114
+ . "role varchar(250) DEFAULT NULL,\n"
115
+ . "priority int DEFAULT NULL,\n"
116
+ . "url varchar(2000) DEFAULT NULL,\n"
117
+ . "deny_wpadmin bit DEFAULT NULL,\n"
118
+ . "disable_toolbar bit DEFAULT NULL,\n"
119
+ . "logout_url varchar(2000) DEFAULT '',\n"
120
+ . "PRIMARY KEY (id),\n"
121
+ . "KEY priority (priority),\n"
122
+ . "KEY role (role)\n"
123
+ . ") $charset_collate;";
124
+
125
+ return $sql;
126
+ }
127
+
128
+ /**
129
+ * Adds a new login redirect.
130
+ *
131
+ * @global \wpdb $wpdb
132
+ * @return boolean Success|Fail
133
+ */
134
+ public function add() {
135
+ $this->priority = intval($this->priority);
136
+ $this->deny_wpadmin = !empty($this->deny_wpadmin);
137
+ $this->disable_toolbar = !empty($this->disable_toolbar);
138
+
139
+ global $wpdb;
140
+ $tablename = $this->table_name();
141
+
142
+ if($this->priority < 1) {
143
+ $this->priority = 1;
144
+ } else {
145
+ $priority = $this->get_next_priority();
146
+ if($this->priority > $priority) {
147
+ $this->priority = $priority;
148
+ }
149
+ }
150
+
151
+ $sql = "UPDATE $tablename "
152
+ . "SET priority = priority + 1 "
153
+ . "WHERE priority >= " . $this->priority;
154
+ $wpdb->query($sql);
155
+
156
+ $result = $wpdb->insert(
157
+ $tablename,
158
+ array(
159
+ 'role' => $this->role,
160
+ 'priority' => $this->priority,
161
+ 'url' => $this->url,
162
+ 'deny_wpadmin' => $this->deny_wpadmin,
163
+ 'disable_toolbar' => $this->disable_toolbar,
164
+ 'logout_url' => $this->logout_url
165
+ ),
166
+ array(
167
+ '%s',
168
+ '%d',
169
+ '%s',
170
+ '%d',
171
+ '%d',
172
+ '%s'
173
+ )
174
+ );
175
+
176
+ $this->cache_flush();
177
+
178
+ if($result === false) {
179
+ return false;
180
+ } else {
181
+ $this->id = $wpdb->insert_id;
182
+ return true;
183
+ }
184
+
185
+ }
186
+
187
+ /**
188
+ * Updates an existing login redirect based on ID.
189
+ *
190
+ * @global \wpdb $wpdb
191
+ * @return boolean Success|Fail
192
+ */
193
+ public function update() {
194
+ $this->priority = intval($this->priority);
195
+ $this->deny_wpadmin = !empty($this->deny_wpadmin);
196
+ $this->disable_toolbar = !empty($this->disable_toolbar);
197
+
198
+ global $wpdb;
199
+ $tablename = $this->table_name();
200
+
201
+ $sql = "SELECT priority FROM $tablename WHERE id = $this->id";
202
+ $db_priority = $wpdb->get_var($sql);
203
+ if(empty($db_priority)) {
204
+ return false;
205
+ }
206
+
207
+ if ($db_priority < $this->priority) {
208
+ $sql = "UPDATE $tablename "
209
+ . "SET priority = priority - 1 "
210
+ . "WHERE priority > $db_priority AND priority <= $this->priority";
211
+ $wpdb->query($sql);
212
+ }
213
+
214
+ if ($db_priority > $this->priority) {
215
+ $sql = "UPDATE $tablename "
216
+ . "SET priority = priority + 1 "
217
+ . "WHERE priority >= $this->priority AND priority < $db_priority";
218
+ $wpdb->query($sql);
219
+ }
220
+
221
+ if($this->priority < 1) {
222
+ $this->priority = 1;
223
+ } else {
224
+ $priority = $this->get_next_priority();
225
+ if($this->priority > $priority) {
226
+ $this->priority = $priority;
227
+ }
228
+ }
229
+
230
+ $result = $wpdb->update(
231
+ $tablename,
232
+ array(
233
+ 'role' => $this->role,
234
+ 'priority' => $this->priority,
235
+ 'url' => $this->url,
236
+ 'deny_wpadmin' => $this->deny_wpadmin,
237
+ 'disable_toolbar' => $this->disable_toolbar,
238
+ 'logout_url' => $this->logout_url
239
+ ),
240
+ array(
241
+ 'id' => $this->id
242
+ ),
243
+ array(
244
+ '%s',
245
+ '%d',
246
+ '%s',
247
+ '%d',
248
+ '%d',
249
+ '%s'
250
+ ),
251
+ array(
252
+ '%d'
253
+ )
254
+ );
255
+
256
+ $this->cache_flush();
257
+
258
+ return !empty($result);
259
+ }
260
+
261
+ /**
262
+ * Deletes a login redirect based role name.
263
+ *
264
+ * @param string $role
265
+ * @return bool
266
+ */
267
+ public function delete($role) {
268
+ global $wpdb;
269
+ $tablename = $this->table_name();
270
+
271
+ $sql = "SELECT priority "
272
+ . "FROM $tablename "
273
+ . "WHERE role = %s";
274
+ $current_priority = $wpdb->get_var($wpdb->prepare($sql, $role));
275
+ if(empty($current_priority)) {
276
+ return false;
277
+ }
278
+
279
+ $sql = "UPDATE $tablename "
280
+ . "SET priority = priority - 1 "
281
+ . "WHERE priority > %d";
282
+ $wpdb->query($wpdb->prepare($sql, $current_priority));
283
+
284
+ $sql = "DELETE FROM $tablename WHERE role = %s";
285
+ $sql = $wpdb->prepare($sql, $role);
286
+ $result = $wpdb->query($sql);
287
+
288
+ $this->cache_flush();
289
+
290
+ return !empty($result);
291
+ }
292
+
293
+ /**
294
+ * Returns the next priority value.
295
+ *
296
+ * @global \wpdb $wpdb
297
+ * @return int
298
+ */
299
+ public function get_next_priority() {
300
+ $data = $this->cache_get('next_priority');
301
+ if($data !== false) {
302
+ return $data;
303
+ }
304
+
305
+ $tablename = $this->table_name();
306
+ $sql = "SELECT MAX(priority) FROM $tablename";
307
+
308
+ global $wpdb;
309
+ $result = $wpdb->get_var($sql);
310
+
311
+ $data = intval($result) + 1;
312
+
313
+ $this->cache_set('next_priority', $data);
314
+
315
+ return $data;
316
+ }
317
+
318
+ /**
319
+ * Returns all login redirects as associative array.
320
+ *
321
+ * @global \wpdb $wpdb
322
+ * @return \WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_Entity[] priority => WPFront_User_Role_Editor_Login_Redirect_Entity.
323
+ */
324
+ public function get_all_login_redirects() {
325
+ $data = $this->cache_get('all_login_redirects');
326
+ if($data !== false) {
327
+ return $data;
328
+ }
329
+
330
+ $table_name = $this->table_name();
331
+
332
+ $sql = "SELECT id, role, priority, url, logout_url, (deny_wpadmin + 0) AS deny_wpadmin, (disable_toolbar + 0) AS disable_toolbar "
333
+ . "FROM $table_name "
334
+ . "ORDER BY priority";
335
+
336
+ global $wpdb;
337
+ $results = $wpdb->get_results($sql);
338
+
339
+ $data = array();
340
+ foreach ($results as $value) {
341
+ $entity = new WPFront_User_Role_Editor_Login_Redirect_Entity();
342
+
343
+ $entity->id = intval($value->id);
344
+ $entity->role = $value->role;
345
+ $entity->priority = intval($value->priority);
346
+ $entity->url = $value->url;
347
+ $entity->deny_wpadmin = (bool)$value->deny_wpadmin;
348
+ $entity->disable_toolbar = (bool)$value->disable_toolbar;
349
+ $entity->logout_url = $value->logout_url;
350
+
351
+ $data[$entity->priority] = $entity;
352
+ }
353
+
354
+ $this->cache_set('all_login_redirects', $data);
355
+
356
+ return $data;
357
+ }
358
+
359
+ protected function cache_flush() {
360
+ $this->cache_delete('all_login_redirects');
361
+ $this->cache_delete('next_priority');
362
+ }
363
+
364
+ }
365
+
366
+ (new WPFront_User_Role_Editor_Login_Redirect_Entity())->register();
367
+
368
+ }
{templates → includes/login-redirect}/index.php RENAMED
File without changes
includes/login-redirect/template-add-edit.php ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Login Redirect Add Edit
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect as LoginRedirect;
40
+
41
+ if(!class_exists('WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_Add_Edit_View')) {
42
+
43
+ class WPFront_User_Role_Editor_Login_Redirect_Add_Edit_View {
44
+
45
+ /**
46
+ *
47
+ * @var WPFront_User_Role_Editor_Login_Redirect_Entity
48
+ */
49
+ private $role_entity;
50
+
51
+ public function __construct($entity = null) {
52
+ $this->role_entity = $entity;
53
+ }
54
+
55
+ public function view() {
56
+ ?>
57
+ <div class="wrap login-redirect-add-edit">
58
+ <?php $this->title(); ?>
59
+ <?php $this->display_notices(); ?>
60
+ <form method="post" class="validate" action="<?php echo $this->get_form_action_url(); ?>">
61
+ <table class="form-table">
62
+ <tbody>
63
+ <?php $this->role_row(); ?>
64
+ <?php $this->priority_row(); ?>
65
+ <?php $this->login_redirect_url_row(); ?>
66
+ <?php $this->logout_redirect_url_row(); ?>
67
+ <?php $this->deny_wp_admin_row(); ?>
68
+ <?php $this->disable_toolbar_row(); ?>
69
+ </tbody>
70
+ </table>
71
+ <?php wp_nonce_field('add-edit-login-redirect'); ?>
72
+ <?php submit_button(); ?>
73
+ </form>
74
+ </div>
75
+ <?php
76
+ $this->scripts();
77
+ }
78
+
79
+ protected function title() {
80
+ if(empty($this->role_entity)) {
81
+ ?>
82
+ <h2>
83
+ <?php echo __('Add New Login Redirect', 'wpfront-user-role-editor'); ?>
84
+ <p><?php echo __('Enter the URL where the user will be redirected after login or on wp-admin access.', 'wpfront-user-role-editor'); ?></p>
85
+ </h2>
86
+ <div id="login-redirect-custom-role-disabled" class="error below-h2 hidden">
87
+ <p><?php echo __('Custom roles not supported in free version.', 'wpfront-user-role-editor') . ' ' . sprintf('<a target="_blank" href="https://wpfront.com/lgnred">%s</a>', __('Upgrade to Pro.', 'wpfront-user-role-editor')); ?></p>
88
+ </div>
89
+ <?php
90
+ } else {
91
+ ?>
92
+ <h2>
93
+ <?php echo __('Edit Login Redirect', 'wpfront-user-role-editor'); ?>
94
+ </h2>
95
+ <?php
96
+ }
97
+ }
98
+
99
+ protected function display_notices() {
100
+ if ((isset($_GET['changes-saved']) && $_GET['changes-saved'] == 'true')) {
101
+ Utils::notice_updated(__('Changes saved.', 'wpfront-user-role-editor'));
102
+ }
103
+ }
104
+
105
+ protected function get_form_action_url() {
106
+ if(empty($this->role_entity)) {
107
+ return LoginRedirect::instance()->get_add_new_url();
108
+ } else {
109
+ return LoginRedirect::instance()->get_edit_url($this->role_entity->role);
110
+ }
111
+ }
112
+
113
+ protected function role_row() {
114
+ ?>
115
+ <tr class="form-required <?php echo $this->is_role_valid() ? '' : 'form-invalid' ?>"">
116
+ <th scope="row">
117
+ <?php echo __('Role', 'wpfront-user-role-editor'); ?><span class="description"> (<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
118
+ </th>
119
+ <td>
120
+ <?php
121
+ if(empty($this->role_entity)) {
122
+ ?>
123
+ <select name="role" id="login-redirect-role">
124
+ <?php
125
+ $roles = $this->get_roles();
126
+ $current_role = $this->get_current_role();
127
+ foreach ($roles as $name => $role) {
128
+ $selected = '';
129
+ if($name == $current_role) {
130
+ $selected = 'selected';
131
+ }
132
+ echo "<option value='$name' data-allowed='$role->allowed' $selected>$role->display_name</option>";
133
+ }
134
+ ?>
135
+ </select>
136
+ <?php
137
+ } else {
138
+ ?>
139
+ <select name="role" id="login-redirect-role" disabled="true">
140
+ <?php
141
+ $display_name = LoginRedirect::instance()->get_role_display($this->role_entity->role);
142
+ echo "<option>$display_name</option>";
143
+ ?>
144
+ </select>
145
+ <?php
146
+ }
147
+ ?>
148
+ </td>
149
+ </tr>
150
+ <?php
151
+ }
152
+
153
+ protected function priority_row() {
154
+ ?>
155
+ <tr class="form-required <?php echo $this->is_priority_valid() ? '' : 'form-invalid' ?>">
156
+ <th scope="row">
157
+ <?php echo __('Priority', 'wpfront-user-role-editor'); ?><span class="description"> (<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
158
+ </th>
159
+ <td>
160
+ <input id="login-redirect-priority" class="small-text" name="priority" type="number" value="<?php echo $this->get_current_priority(); ?>" aria-required="true" />
161
+ </td>
162
+ </tr>
163
+ <?php
164
+ }
165
+
166
+ protected function login_redirect_url_row() {
167
+ ?>
168
+ <tr class="form-required <?php echo $this->is_url_valid() ? '' : 'form-invalid' ?>">
169
+ <th scope="row">
170
+ <?php echo __('Login Redirect URL', 'wpfront-user-role-editor'); ?><span class="description"> (<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
171
+ </th>
172
+ <td>
173
+ <input id="login-redirect-url" class="regular-text" name="url" type="text" value="<?php echo $this->get_current_url(); ?>" aria-required="true" />
174
+ <br />
175
+ <span class="description">[<?php echo __('Relative to home URL (recommended) or absolute URL.', 'wpfront-user-role-editor'); ?>]</span>
176
+ </td>
177
+ </tr>
178
+ <?php
179
+ }
180
+
181
+ protected function logout_redirect_url_row() {
182
+ ?>
183
+ <tr>
184
+ <th scope="row">
185
+ <?php echo __('Logout Redirect URL', 'wpfront-user-role-editor'); ?>
186
+ </th>
187
+ <td>
188
+ <input class="regular-text" name="logout_url" type="text" value="<?php echo $this->get_current_logout_url(); ?>" aria-required="true" />
189
+ <br />
190
+ <span class="description">[<?php echo __('Relative to home URL (recommended) or absolute URL.', 'wpfront-user-role-editor'); ?>]</span>
191
+ </td>
192
+ </tr>
193
+ <?php
194
+ }
195
+
196
+ protected function deny_wp_admin_row() {
197
+ ?>
198
+ <tr>
199
+ <th scope="row">
200
+ <?php echo __('Deny WP-ADMIN', 'wpfront-user-role-editor'); ?>
201
+ </th>
202
+ <td>
203
+ <input name="deny_wpadmin" type="checkbox" <?php echo $this->get_current_deny_wpadmin() ? 'checked' : '' ?> />
204
+ </td>
205
+ </tr>
206
+ <?php
207
+ }
208
+
209
+ protected function disable_toolbar_row() {
210
+ ?>
211
+ <tr>
212
+ <th scope="row">
213
+ <?php echo __('Disable Toolbar', 'wpfront-user-role-editor'); ?>
214
+ </th>
215
+ <td>
216
+ <input name="disable_toolbar" type="checkbox" <?php echo $this->get_current_disable_toolbar() ? 'checked' : '' ?> />
217
+ </td>
218
+ </tr>
219
+ <?php
220
+ }
221
+
222
+ protected function get_current_role() {
223
+ if(empty($_POST['role']))
224
+ return '';
225
+
226
+ return $_POST['role'];
227
+ }
228
+
229
+ protected function get_current_priority() {
230
+ if(!empty($_POST['submit'])) {
231
+ return isset($_POST['priority']) ? $_POST['priority'] : '';
232
+ }
233
+
234
+ if(!empty($this->role_entity)) {
235
+ return $this->role_entity->priority;
236
+ }
237
+
238
+ return LoginRedirect::instance()->get_next_priority();
239
+ }
240
+
241
+ protected function get_current_url() {
242
+ if(!empty($_POST['submit'])) {
243
+ return empty($_POST['url']) ? '' : $_POST['url'];
244
+ }
245
+
246
+ if(!empty($this->role_entity)) {
247
+ return $this->role_entity->url;
248
+ }
249
+
250
+ return '';
251
+ }
252
+
253
+ protected function get_current_logout_url() {
254
+ if(!empty($_POST['submit'])) {
255
+ return empty($_POST['logout_url']) ? '' : $_POST['logout_url'];
256
+ }
257
+
258
+ if(!empty($this->role_entity)) {
259
+ return $this->role_entity->logout_url;
260
+ }
261
+
262
+ return '';
263
+ }
264
+
265
+ protected function get_current_deny_wpadmin() {
266
+ if(!empty($_POST['submit'])) {
267
+ return !empty($_POST['deny_wpadmin']);
268
+ }
269
+
270
+ if(!empty($this->role_entity)) {
271
+ return $this->role_entity->deny_wpadmin;
272
+ }
273
+
274
+ return false;
275
+ }
276
+
277
+ protected function get_current_disable_toolbar() {
278
+ if(!empty($_POST['submit'])) {
279
+ return !empty($_POST['disable_toolbar']);
280
+ }
281
+
282
+ if(!empty($this->role_entity)) {
283
+ return $this->role_entity->disable_toolbar;
284
+ }
285
+
286
+ return false;
287
+ }
288
+
289
+ protected function is_role_valid() {
290
+ if(!empty($_POST['role'])) {
291
+ $role = $_POST['role'];
292
+ $roles_info = $this->get_roles();
293
+ if(!isset($roles_info[$role])) {
294
+ return false;
295
+ }
296
+
297
+ return $roles_info[$role]->allowed;
298
+ }
299
+
300
+ return true;
301
+ }
302
+
303
+ protected function is_priority_valid() {
304
+ if(!empty($_POST['submit'])) {
305
+ if(empty($_POST['priority'])) {
306
+ return false;
307
+ }
308
+ $priority = intval($_POST['priority']);
309
+ return $priority > 0;
310
+ }
311
+
312
+ return true;
313
+ }
314
+
315
+ protected function is_url_valid() {
316
+ if(!empty($_POST['submit'])) {
317
+ return !empty($_POST['url']);
318
+ }
319
+
320
+ return true;
321
+ }
322
+
323
+ protected function get_roles() {
324
+ return LoginRedirect::instance()->get_roles_info_for_new();
325
+ }
326
+
327
+ protected function scripts() {
328
+ ?>
329
+ <script type="text/javascript">
330
+ (function($) {
331
+ var role_check = function () {
332
+ var $option = $("#login-redirect-role option:selected");
333
+
334
+ if ($option.length === 0)
335
+ return;
336
+
337
+ if ($option.data("allowed")) {
338
+ $("#form-login-redirect input").prop("disabled", false)
339
+ $("#login-redirect-custom-role-disabled").addClass("hidden");
340
+ } else {
341
+ $("#form-login-redirect input").prop("disabled", true)
342
+ $("#login-redirect-custom-role-disabled").removeClass("hidden");
343
+ }
344
+ };
345
+
346
+ $("#login-redirect-role").change(function() {
347
+ $(this).closest("tr").removeClass("form-invalid");
348
+ role_check();
349
+ });
350
+
351
+ $("#login-redirect-priority").blur(function() {
352
+ if($(this).val() != "")
353
+ $(this).closest("tr").removeClass("form-invalid");
354
+ });
355
+
356
+ $("#login-redirect-url").blur(function() {
357
+ if($(this).val() != "")
358
+ $(this).closest("tr").removeClass("form-invalid");
359
+ });
360
+
361
+ role_check();
362
+ })(jQuery);
363
+ </script>
364
+ <?php
365
+ }
366
+
367
+ }
368
+
369
+ }
370
+
includes/login-redirect/template-delete.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Login Redirect Delete
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect as LoginRedirect;
39
+
40
+ if(!class_exists('WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_Delete_View')) {
41
+
42
+ class WPFront_User_Role_Editor_Login_Redirect_Delete_View {
43
+ /**
44
+ *
45
+ * @var string[]
46
+ */
47
+ private $roles;
48
+
49
+ public function __construct($roles) {
50
+ $this->roles = $roles;
51
+ }
52
+
53
+ public function view() {
54
+ ?>
55
+ <div class="wrap login-redirect">
56
+ <?php $this->title(); ?>
57
+ <form id="form-login-redirect" method='post'>
58
+ <ol>
59
+ <?php $this->roles_display(); ?>
60
+ </ol>
61
+ <?php wp_nonce_field('delete-login-redirect'); ?>
62
+ <?php submit_button(__('Confirm Delete', 'wpfront-user-role-editor'), 'button-secondary'); ?>
63
+ </form>
64
+ </div>
65
+ <?php
66
+ }
67
+
68
+ protected function title() {
69
+ ?>
70
+ <h2>
71
+ <?php echo __('Delete Login Redirects', 'wpfront-user-role-editor'); ?>
72
+ <p><?php echo __('The following role configurations will be deleted.', 'wpfront-user-role-editor'); ?></p>
73
+ </h2>
74
+ <?php
75
+ }
76
+
77
+ protected function roles_display() {
78
+ foreach ($this->roles as $role) {
79
+ $display = LoginRedirect::instance()->get_role_display($role);
80
+ echo "<li><strong>$display</strong> [$role]</li>";
81
+ echo "<input type='hidden' name='bulk-delete[$role]' />";
82
+ }
83
+ }
84
+ }
85
+
86
+ }
87
+
includes/login-redirect/template-login-redirect.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Login Redirect
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Login_Redirect;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect as LoginRedirect;
40
+
41
+ require_once dirname(__FILE__) . '/class-login-redirect-list-table.php';
42
+
43
+ if(!class_exists('WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Login_Redirect_View')) {
44
+
45
+ class WPFront_User_Role_Editor_Login_Redirect_View {
46
+
47
+ public function view() {
48
+ ?>
49
+ <div class="wrap login-redirect">
50
+ <?php $this->title(); ?>
51
+ <?php $this->display_notices(); ?>
52
+ <?php
53
+ $list_table = new WPFront_User_Role_Editor_Login_Redirect_List_Table();
54
+ $list_table->prepare_items();
55
+ ?>
56
+ <form action="" method="get" class="search-form">
57
+ <input type="hidden" name="page" value="<?php echo LoginRedirect::MENU_SLUG; ?>" />
58
+ <?php $list_table->search_box(__('Search', 'wpfront-user-role-editor'), 'login-redirect'); ?>
59
+ </form>
60
+ <form id="form-login-redirect" method='post'>
61
+ <?php
62
+ $list_table->display();
63
+ ?>
64
+ </form>
65
+ </div>
66
+ <?php
67
+ }
68
+
69
+ protected function title() {
70
+ ?>
71
+ <h2>
72
+ <?php echo __('Login Redirects', 'wpfront-user-role-editor'); ?>
73
+ <a href="<?php echo $this->get_add_new_url(); ?>" class="add-new-h2"><?php echo __('Add New', 'wpfront-user-role-editor'); ?></a>
74
+ </h2>
75
+ <?php
76
+ }
77
+
78
+ protected function display_notices() {
79
+ if ((isset($_GET['deleted']) && $_GET['deleted'] == 'true')) {
80
+ Utils::notice_updated(__('Role configurations deleted.', 'wpfront-user-role-editor'));
81
+ }
82
+ }
83
+
84
+ protected function get_add_new_url() {
85
+ return LoginRedirect::instance()->get_add_new_url();
86
+ }
87
+
88
+ }
89
+
90
+ }
91
+
includes/media/class-media-permissions.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Media Permissions
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Media;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
40
+ use WPFront\URE\Options\WPFront_User_Role_Editor_Options as Options;
41
+
42
+ if (!class_exists('\WPFront\URE\Media\WPFront_User_Role_Editor_Media_Permissions')) {
43
+
44
+ /**
45
+ * Media Permissions class
46
+ *
47
+ * @author Syam Mohan <syam@wpfront.com>
48
+ * @copyright 2014 WPFront.com
49
+ */
50
+ class WPFront_User_Role_Editor_Media_Permissions extends \WPFront\URE\WPFront_User_Role_Editor_Controller {
51
+
52
+ protected static $user_capabilities = array(
53
+ 'edit_attachments' => 'upload_files',
54
+ 'delete_attachments' => 'upload_files',
55
+ 'read_others_attachments' => 'upload_files',
56
+ 'edit_others_attachments' => 'upload_files',
57
+ 'delete_others_attachments' => 'upload_files'
58
+ );
59
+
60
+ protected function setUp() {
61
+ }
62
+
63
+ /**
64
+ * Init function.
65
+ */
66
+ protected function initialize() {
67
+ if(!is_admin()) {
68
+ return;
69
+ }
70
+
71
+ RolesHelper::add_capability_group('media', __('Media', 'wpfront-user-role-editor'));
72
+
73
+ foreach (self::$user_capabilities as $cap => $value) {
74
+ RolesHelper::add_new_capability_to_group('media', $cap);
75
+
76
+ add_filter("wpfront_ure_capability_{$cap}_functionality_enabled", '__return_false');
77
+ add_filter("wpfront_ure_capability_{$cap}_ui_help_link", array($this, 'cap_help_link'), 10, 2);
78
+ }
79
+
80
+ $this->add_capabilities_to_roles();
81
+
82
+ add_filter('wpfront_ure_restore_role_custom_caps', array($this, 'restore_role_custom_caps'));
83
+ }
84
+
85
+ /**
86
+ * Sets the new capabilities for the first time.
87
+ *
88
+ * @global \WP_Role[] $wp_roles
89
+ */
90
+ public function add_capabilities_to_roles() {
91
+ $option_key = 'media_permission_capabilities_processed';
92
+ $processed = Options::instance()->get_option_boolean($option_key);
93
+ if (!empty($processed)) {
94
+ return;
95
+ }
96
+
97
+ global $wp_roles;
98
+
99
+ foreach ($wp_roles->role_objects as $key => $role) {
100
+ foreach (self::$user_capabilities as $u_cap => $cap) {
101
+ if ($role->has_cap($cap)) {
102
+ $role->add_cap($u_cap);
103
+ }
104
+ }
105
+ }
106
+
107
+ Options::instance()->set_option($option_key, true);
108
+ }
109
+
110
+ public function restore_role_custom_caps($custom_caps) {
111
+ foreach (self::$user_capabilities as $key => $value) {
112
+ $custom_caps[$key] = $value;
113
+ }
114
+
115
+ return $custom_caps;
116
+ }
117
+
118
+ public function cap_help_link($help_link, $cap) {
119
+ return RolesHelper::get_wpfront_help_link($cap);
120
+ }
121
+
122
+ }
123
+
124
+ WPFront_User_Role_Editor_Media_Permissions::load();
125
+
126
+ }
includes/media/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
includes/nav-menu/class-nav-menu-permissions.php ADDED
@@ -0,0 +1,460 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Nav Menu Permissions
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Nav_Menu;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
40
+ use WPFront\URE\Options\WPFront_User_Role_Editor_Options as Options;
41
+
42
+ require_once dirname(__FILE__) . '/class-nav-menu-walker.php';
43
+
44
+ if (!class_exists('\WPFront\URE\Nav_Menu\WPFront_User_Role_Editor_Nav_Menu_Permissions')) {
45
+
46
+ /**
47
+ * Nav Menu Permissions
48
+ *
49
+ * @author Syam Mohan <syam@wpfront.com>
50
+ * @copyright 2014 WPFront.com
51
+ */
52
+ class WPFront_User_Role_Editor_Nav_Menu_Permissions extends \WPFront\URE\WPFront_User_Role_Editor_Controller {
53
+
54
+ protected static $ALL_USERS = 1;
55
+ protected static $LOGGEDIN_USERS = 2;
56
+ protected static $GUEST_USERS = 3;
57
+ protected static $ROLE_USERS = 4;
58
+ protected static $META_DATA_KEY = 'wpfront-user-role-editor-nav-menu-data';
59
+
60
+ const CAP = 'edit_nav_menu_permissions';
61
+
62
+ protected function setUp() {
63
+ $this->_setUp('edit_nav_menu_permissions');
64
+ }
65
+
66
+ /**
67
+ * Hooks into wpfront_ure_init.
68
+ */
69
+ protected function initialize() {
70
+ add_filter('wpfront_ure_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 30, 1);
71
+ add_filter('wpfront_ure_ms_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 30, 1);
72
+
73
+ if($this->disable_navigation_menu_permissions()) {
74
+ return;
75
+ }
76
+
77
+ //apply logic
78
+ add_filter('wp_get_nav_menu_items', array($this, 'override_nav_menu_items'), 10, 3);
79
+
80
+ if(!is_admin()) {
81
+ return;
82
+ }
83
+
84
+ //set menu walker
85
+ add_action('wp_loaded', array($this, 'wp_init'), PHP_INT_MAX);
86
+
87
+ //set custom fields
88
+ add_action('wp_nav_menu_item_custom_fields', array($this, 'menu_item_custom_fields'), 10, 4);
89
+ //set menu item title
90
+ add_action('wp_nav_menu_item_title_user_restriction_type', array($this, 'menu_item_title_user_restriction_type'), 10, 4);
91
+ //set menu item role list
92
+ add_action('wp_nav_menu_item_custom_fields_roles_list', array($this, 'menu_item_custom_fields_roles_list'), 10, 4);
93
+
94
+ //save menu item data
95
+ add_action('wp_update_nav_menu_item', array($this, 'update_nav_menu_item'), 10, 3);
96
+
97
+ if(Utils::doing_ajax()) {
98
+ return;
99
+ }
100
+
101
+ add_action('admin_print_scripts-nav-menus.php', array($this, 'enqueue_menu_scripts'));
102
+ add_action('admin_print_styles-nav-menus.php', array($this, 'enqueue_menu_styles'));
103
+ add_action('load-nav-menus.php', array($this, 'menu_walker_override_notice_action'));
104
+ }
105
+
106
+ /**
107
+ * Hooks into init and sets the filter for overriding menu walker.
108
+ */
109
+ public function wp_init() {
110
+ add_filter('wp_edit_nav_menu_walker', array($this, 'override_edit_nav_menu_walker'), PHP_INT_MAX);
111
+ }
112
+
113
+ /**
114
+ * Hooks into wp_edit_nav_menu_walker and sets the menu walker class.
115
+ *
116
+ * @param string $current
117
+ * @return string
118
+ */
119
+ public function override_edit_nav_menu_walker($current = 'Walker_Nav_Menu_Edit') {
120
+ if ($current !== 'Walker_Nav_Menu_Edit' && !$this->override_navigation_menu_permissions()) {
121
+ return $current;
122
+ }
123
+
124
+ return '\WPFront\URE\Nav_Menu\WPFront_User_Role_Editor_Nav_Menu_Walker';
125
+ }
126
+
127
+ /**
128
+ * Returns data saved for menu item.
129
+ *
130
+ * @param int $menu_item_db_id
131
+ * @return object
132
+ */
133
+ protected function get_meta_data($menu_item_db_id) {
134
+ $data = get_post_meta($menu_item_db_id, self::$META_DATA_KEY, true);
135
+
136
+ if (empty($data)) {
137
+ $data = (OBJECT) array('type' => self::$ALL_USERS);
138
+ }
139
+
140
+ switch (intval($data->type)) {
141
+ case self::$LOGGEDIN_USERS:
142
+ case self::$GUEST_USERS:
143
+ case self::$ROLE_USERS:
144
+ $data->type = intval($data->type);
145
+ break;
146
+ default:
147
+ $data->type = self::$ALL_USERS;
148
+ break;
149
+ }
150
+
151
+ return $data;
152
+ }
153
+
154
+ /**
155
+ * Hooks into wp_nav_menu_item_custom_fields, displays the custom fields.
156
+ *
157
+ * @param int $item_id
158
+ * @param object $item
159
+ * @param int $depth
160
+ * @param array $args
161
+ */
162
+ public function menu_item_custom_fields($item_id, $item, $depth, $args) {
163
+ if (!current_user_can(self::CAP)) {
164
+ return;
165
+ }
166
+
167
+ $data = $this->get_meta_data($item_id);
168
+ ?>
169
+ <p class="description description-wide"></p>
170
+ <p class="description description-wide">
171
+ <label><?php echo __('User Restrictions', 'wpfront-user-role-editor'); ?></label>
172
+ <span class="user-restriction-container">
173
+ <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$ALL_USERS; ?>" <?php echo $data->type === self::$ALL_USERS ? 'checked' : ''; ?> /><?php echo __('All Users', 'wpfront-user-role-editor'); ?></label>
174
+ <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$LOGGEDIN_USERS; ?>" <?php echo $data->type === self::$LOGGEDIN_USERS ? 'checked' : ''; ?> /><?php echo __('Logged in Users', 'wpfront-user-role-editor'); ?></label>
175
+ <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$GUEST_USERS; ?>" <?php echo $data->type === self::$GUEST_USERS ? 'checked' : ''; ?> /><?php echo __('Guest Users', 'wpfront-user-role-editor'); ?></label>
176
+ <label><input class="user-restriction-type" type="radio" name="<?php echo 'user-restriction-type-' . $item_id; ?>" value="<?php echo self::$ROLE_USERS; ?>" <?php echo $data->type === self::$ROLE_USERS ? 'checked' : ''; ?> /><?php echo __('Users by Role', 'wpfront-user-role-editor'); ?></label>
177
+ <span class="roles-container <?php echo $data->type === self::$ROLE_USERS ? '' : 'hidden'; ?>">
178
+ <?php do_action('wp_nav_menu_item_custom_fields_roles_list', $item_id, $item, $depth, $args); ?>
179
+ </span>
180
+ </span>
181
+ </p>
182
+ <?php
183
+ }
184
+
185
+ /**
186
+ * Hooks into wp_nav_menu_item_custom_fields_roles_list, display the roles list.
187
+ *
188
+ * @param int $item_id
189
+ * @param object $item
190
+ * @param int $depth
191
+ * @param array $args
192
+ */
193
+ public function menu_item_custom_fields_roles_list($item_id, $item, $depth, $args) {
194
+ printf(__('%s to limit based on roles.', 'wpfront-user-role-editor'), '<a target="_blank" href="https://wpfront.com/navmenu">' . __('Upgrade to Pro', 'wpfront-user-role-editor') . '</a>');
195
+ }
196
+
197
+ /**
198
+ * Hooks into wp_nav_menu_item_title_user_restriction_type, appends to menu item title.
199
+ *
200
+ * @param int $item_id
201
+ * @param object $item
202
+ * @param int $depth
203
+ * @param array $args
204
+ */
205
+ public function menu_item_title_user_restriction_type($item_id, $item, $depth, $args) {
206
+ if (!current_user_can(self::CAP)) {
207
+ return;
208
+ }
209
+
210
+ $data = $this->get_meta_data($item_id);
211
+ $text = __('All Users', 'wpfront-user-role-editor');
212
+
213
+ switch ($data->type) {
214
+ case self::$LOGGEDIN_USERS:
215
+ $text = __('Logged in Users', 'wpfront-user-role-editor');
216
+ break;
217
+ case self::$GUEST_USERS:
218
+ $text = __('Guest Users', 'wpfront-user-role-editor');
219
+ break;
220
+ case self::$ROLE_USERS:
221
+ $text = __('Users by Role', 'wpfront-user-role-editor');
222
+ break;
223
+ }
224
+ ?>
225
+ <span class="is-submenu">
226
+ <?php echo '(' . $text . ')'; ?>
227
+ </span>
228
+ <?php
229
+ }
230
+
231
+ /**
232
+ * Hooks into wp_update_nav_menu_item, saves data in DB.
233
+ *
234
+ * @param int $menu_id
235
+ * @param object $menu_item_db_id
236
+ * @param array $args
237
+ */
238
+ public function update_nav_menu_item($menu_id, $menu_item_db_id, $args) {
239
+ if (!current_user_can(self::CAP)) {
240
+ return;
241
+ }
242
+
243
+ $data = $this->get_nav_menu_item_post_data($menu_item_db_id);
244
+
245
+ update_post_meta($menu_item_db_id, self::$META_DATA_KEY, $data);
246
+ }
247
+
248
+ /**
249
+ * Reads data from $_POST and creates data object.
250
+ *
251
+ * @param int $menu_item_db_id
252
+ * @return object
253
+ */
254
+ protected function get_nav_menu_item_post_data($menu_item_db_id) {
255
+ $data = $this->get_meta_data($menu_item_db_id);
256
+
257
+ if (!empty($_POST['user-restriction-type-' . $menu_item_db_id])) {
258
+ $data->type = intval($_POST['user-restriction-type-' . $menu_item_db_id]);
259
+ }
260
+
261
+ return $data;
262
+ }
263
+
264
+ /**
265
+ * Hooks into wp_get_nav_menu_items, applies display logic.
266
+ *
267
+ * @param array $items
268
+ * @param object $menu
269
+ * @param array $args
270
+ */
271
+ public function override_nav_menu_items($items, $menu, $args) {
272
+ if (is_admin()) {
273
+ return $items;
274
+ }
275
+
276
+ $remove_parent = array();
277
+
278
+ foreach ($items as $key => $item) {
279
+ $data = $this->get_meta_data($item->db_id);
280
+
281
+ if (!$this->is_nav_menu_enabled($data)) {
282
+ $remove_parent[] = $item->ID;
283
+ unset($items[$key]);
284
+ }
285
+ }
286
+
287
+ while (!empty($remove_parent)) {
288
+ foreach ($items as $key => $item) {
289
+ if (empty($item)) {
290
+ continue;
291
+ }
292
+
293
+ if (intval($item->menu_item_parent) === intval($remove_parent[0])) {
294
+ $remove_parent[] = $item->ID;
295
+ unset($items[$key]);
296
+ }
297
+ }
298
+
299
+ array_shift($remove_parent);
300
+ }
301
+
302
+ return array_values($items);
303
+ }
304
+
305
+ /**
306
+ * Checks whether menu should be displayed.
307
+ *
308
+ * @param object $data
309
+ * @return boolean
310
+ */
311
+ protected function is_nav_menu_enabled($data) {
312
+ switch ($data->type) {
313
+ case self::$LOGGEDIN_USERS:
314
+ return is_user_logged_in();
315
+
316
+ case self::$GUEST_USERS:
317
+ return !is_user_logged_in();
318
+ }
319
+
320
+ return true;
321
+ }
322
+
323
+ /**
324
+ * Hooks into load-nav-menus.php, adds action display notice.
325
+ */
326
+ public function menu_walker_override_notice_action() {
327
+ add_action('admin_notices', array($this, 'menu_walker_override_warning'));
328
+ }
329
+
330
+ /**
331
+ * Hooks into admin_notices, to display walker class override warning.
332
+ */
333
+ public function menu_walker_override_warning() {
334
+ if ($this->disable_navigation_menu_permissions()) {
335
+ return;
336
+ }
337
+
338
+ if(!current_user_can(self::CAP)) {
339
+ return;
340
+ }
341
+
342
+ $menu_walker = apply_filters('wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', 0);
343
+ if ($menu_walker !== $this->override_edit_nav_menu_walker()) {
344
+ $message = sprintf(
345
+ '%s %s %s %s',
346
+ __('Menu walker class is overriden by a theme/plugin.', 'wpfront-user-role-editor'),
347
+ sprintf(__('Current value = %s.', 'wpfront-user-role-editor'), $menu_walker),
348
+ __('Navigation menu permissions may still work.', 'wpfront-user-role-editor'),
349
+ '<a target="_blank" href="' . $this->nav_menu_help_url() . '#navigation-menu-permission-warning">' . __('How to fix?', 'wpfront-user-role-editor') . '</a>'
350
+ );
351
+
352
+ Utils::notice_error($message);
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Hooks on options class to display ui.
358
+ *
359
+ * @param array $option_keys
360
+ */
361
+ public function wpfront_ure_options_register_ui_field($option_keys) {
362
+ $option_keys['disable_navigation_menu_permissions'] = '';
363
+ add_action('wpfront_ure_options_ui_field_disable_navigation_menu_permissions_label', array($this, 'options_ui_label'), 10, 1);
364
+ add_action('wpfront_ure_options_ui_field_disable_navigation_menu_permissions', array($this, 'options_ui_field'), 10, 1);
365
+ add_action('wpfront_ure_options_ui_field_disable_navigation_menu_permissions_update', array($this, 'options_ui_update'), 10, 1);
366
+ add_action('wpfront_ure_options_ui_field_disable_navigation_menu_permissions_help', array($this, 'options_ui_help'), 10, 2);
367
+
368
+ $option_keys['override_navigation_menu_permissions'] = '';
369
+ add_action('wpfront_ure_options_ui_field_override_navigation_menu_permissions_label', array($this, 'options_ui_label'), 10, 1);
370
+ add_action('wpfront_ure_options_ui_field_override_navigation_menu_permissions', array($this, 'options_ui_field'), 10, 1);
371
+ add_action('wpfront_ure_options_ui_field_override_navigation_menu_permissions_update', array($this, 'options_ui_update'), 10, 1);
372
+ add_action('wpfront_ure_options_ui_field_override_navigation_menu_permissions_help', array($this, 'options_ui_help'), 10, 2);
373
+
374
+ return $option_keys;
375
+ }
376
+
377
+ public function options_ui_label($key) {
378
+ if($key === 'disable_navigation_menu_permissions') {
379
+ echo __('Disable Navigation Menu Permissions', 'wpfront-user-role-editor');
380
+ } else {
381
+ echo __('Override Navigation Menu Permissions', 'wpfront-user-role-editor');
382
+ }
383
+ }
384
+
385
+ public function options_ui_field($key) {
386
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
387
+ $checked = !empty($_POST[$key]);
388
+ } else {
389
+ if(is_network_admin()) {
390
+ $checked = Options::instance()->get_network_option_boolean($key);
391
+ } else {
392
+ $checked = $this->Options->get_option_boolean($key, true);
393
+ }
394
+ }
395
+
396
+ $checked = $checked ? 'checked' : '';
397
+
398
+ echo "<input type='checkbox' name='$key' $checked />";
399
+ }
400
+
401
+ public function options_ui_update($key) {
402
+ $value = !empty($_POST[$key]);
403
+
404
+ if(is_network_admin()) {
405
+ Options::instance()->set_network_option($key, $value);
406
+ } else {
407
+ Options::instance()->set_option($key, $value);
408
+ }
409
+ }
410
+
411
+ public function options_ui_help($help, $key) {
412
+ if($key === 'disable_navigation_menu_permissions') {
413
+ return '<strong>' . __('Disable Navigation Menu Permissions', 'wpfront-user-role-editor') . '</strong>: ' . __('If enabled, disables navigation menu permissions functionality.', 'wpfront-user-role-editor');
414
+ } else {
415
+ return '<strong>' . __('Override Navigation Menu Permissions', 'wpfront-user-role-editor') . '</strong>: ' . __('If enabled, tries to reset navigation menu permissions UI, when a conflict is detected.', 'wpfront-user-role-editor');
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Return disable_navigation_menu_permissions setting value.
421
+ *
422
+ * @return boolean
423
+ */
424
+ public function disable_navigation_menu_permissions() {
425
+ return Options::instance()->get_option_boolean('disable_navigation_menu_permissions', true);
426
+ }
427
+
428
+ /**
429
+ * Return override_navigation_menu_permissions setting value.
430
+ *
431
+ * @return boolean
432
+ */
433
+ public function override_navigation_menu_permissions() {
434
+ return Options::instance()->get_option_boolean('override_navigation_menu_permissions', true);
435
+ }
436
+
437
+ public function enqueue_menu_scripts() {
438
+ wp_enqueue_script('jquery');
439
+ wp_enqueue_script('wpfront-user-role-editor-nav-menu-js', WPFURE::instance()->get_asset_url('js/nav-menu.js'), array('jquery'), WPFURE::VERSION);
440
+ }
441
+
442
+ public function enqueue_menu_styles() {
443
+ wp_enqueue_style('wpfront-user-role-editor-nav-menu-css', WPFURE::instance()->get_asset_url('css/nav-menu.css'), array(), WPFURE::VERSION);
444
+ }
445
+
446
+ public function nav_menu_help_url() {
447
+ return 'https://wpfront.com/user-role-editor-pro/navigation-menu-permissions/';
448
+ }
449
+
450
+ public static function uninstall() {
451
+ delete_post_meta_by_key(self::$META_DATA_KEY);
452
+ }
453
+
454
+ }
455
+
456
+ \WPFront\URE\WPFront_User_Role_Editor_Uninstall::register_callback('\WPFront\URE\Nav_Menu\WPFront_User_Role_Editor_Nav_Menu_Permissions::uninstall');
457
+
458
+ WPFront_User_Role_Editor_Nav_Menu_Permissions::load();
459
+
460
+ }
classes/class-wpfront-user-role-editor-nav-menu-walker.php → includes/nav-menu/class-nav-menu-walker.php RENAMED
@@ -1,94 +1,98 @@
1
- <?php
2
-
3
- /*
4
- WPFront User Role Editor Plugin
5
- Copyright (C) 2014, WPFront.com
6
- Website: wpfront.com
7
- Contact: syam@wpfront.com
8
-
9
- WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
- June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
- St, Fifth Floor, Boston, MA 02110, USA
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
- */
24
-
25
- if (!defined('ABSPATH')) {
26
- exit();
27
- }
28
-
29
- require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
30
-
31
- if (!class_exists('WPFront_User_Role_Editor_Nav_Menu_Walker')) {
32
-
33
- /**
34
- * Create HTML list of nav menu input items.
35
- *
36
- * Copied from nav-menu.php
37
- */
38
- class WPFront_User_Role_Editor_Nav_Menu_Walker extends Walker_Nav_Menu_Edit {
39
-
40
- /**
41
- * Start the element output.
42
- *
43
- * @see Walker_Nav_Menu::start_el()
44
- * @since 3.0.0
45
- *
46
- * @global int $_wp_nav_menu_max_depth
47
- *
48
- * @param string $output Passed by reference. Used to append additional content.
49
- * @param object $item Menu item data object.
50
- * @param int $depth Depth of menu item. Used for padding.
51
- * @param array $args Not used.
52
- * @param int $id Not used.
53
- */
54
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
55
- global $wp_version;
56
-
57
- $item_id = esc_attr( $item->ID );
58
- $parent_output = '';
59
-
60
- if(version_compare($wp_version, '5.4', '<')) {
61
- //controls
62
- ob_start();
63
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
64
- $custom = ob_get_clean();
65
-
66
- parent::start_el($parent_output, $item, $depth, $args, $id);
67
-
68
- $divider = '<fieldset class="field-move';
69
- $parts = explode($divider, $parent_output);
70
- $merge = implode($custom . $divider, $parts);
71
- $parent_output = $merge;
72
- } else {
73
- parent::start_el($parent_output, $item, $depth, $args, $id);
74
- }
75
-
76
- //title
77
- $divider = '<span class="item-controls">';
78
- $parts = explode($divider, $parent_output);
79
- //remove last </span>
80
- $index = strrpos($parts[0], '</span>');
81
- $parts[0] = substr($parts[0], 0, $index);
82
-
83
- ob_start();
84
- do_action( 'wp_nav_menu_item_title_user_restriction_type', $item_id, $item, $depth, $args );
85
- $title = ob_get_clean();
86
-
87
- $merge = implode($title . '</span>' . $divider, $parts);
88
-
89
- $output .= $merge;
90
- }
91
-
92
- } // Walker_Nav_Menu_Edit
93
-
 
 
 
 
94
  }
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ namespace WPFront\URE\Nav_Menu;
26
+
27
+ if (!defined('ABSPATH')) {
28
+ exit();
29
+ }
30
+
31
+ if(file_exists(ABSPATH . 'wp-admin/includes/nav-menu.php')) {
32
+ require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
33
+ }
34
+
35
+ if (!class_exists('\WPFront\URE\Nav_Menu\WPFront_User_Role_Editor_Nav_Menu_Walker')) {
36
+
37
+ /**
38
+ * Create HTML list of nav menu input items.
39
+ *
40
+ * Copied from nav-menu.php
41
+ */
42
+ class WPFront_User_Role_Editor_Nav_Menu_Walker extends \Walker_Nav_Menu_Edit {
43
+
44
+ /**
45
+ * Start the element output.
46
+ *
47
+ * @see Walker_Nav_Menu::start_el()
48
+ * @since 3.0.0
49
+ *
50
+ * @global int $_wp_nav_menu_max_depth
51
+ *
52
+ * @param string $output Used to append additional content (passed by reference).
53
+ * @param object $item Menu item data object.
54
+ * @param int $depth Depth of menu item. Used for padding.
55
+ * @param array $args Not used.
56
+ * @param int $id Not used.
57
+ */
58
+ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
59
+ global $wp_version;
60
+
61
+ $item_id = esc_attr( $item->ID );
62
+ $parent_output = '';
63
+
64
+ if(version_compare($wp_version, '5.4', '<')) {
65
+ //controls
66
+ ob_start();
67
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
68
+ $custom = ob_get_clean();
69
+
70
+ parent::start_el($parent_output, $item, $depth, $args, $id);
71
+
72
+ $divider = '<fieldset class="field-move';
73
+ $parts = explode($divider, $parent_output);
74
+ $merge = implode($custom . $divider, $parts);
75
+ $parent_output = $merge;
76
+ } else {
77
+ parent::start_el($parent_output, $item, $depth, $args, $id);
78
+ }
79
+
80
+ //title
81
+ $divider = '<span class="item-controls">';
82
+ $parts = explode($divider, $parent_output);
83
+ //remove last </span>
84
+ $index = strrpos($parts[0], '</span>');
85
+ $parts[0] = substr($parts[0], 0, $index);
86
+
87
+ ob_start();
88
+ do_action( 'wp_nav_menu_item_title_user_restriction_type', $item_id, $item, $depth, $args );
89
+ $title = ob_get_clean();
90
+
91
+ $merge = implode($title . '</span>' . $divider, $parts);
92
+
93
+ $output .= $merge;
94
+ }
95
+
96
+ } // Walker_Nav_Menu_Edit
97
+
98
  }
includes/nav-menu/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
includes/post-type/class-abstract-post-type-custom-cap.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Class for WPFront User Role Editor Post Type Custom Capabilities.
27
+ *
28
+ * @author Jinu Varghese
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Post_Type;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ use WPFront\URE\Options\WPFront_User_Role_Editor_Options as Options;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
40
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
41
+
42
+ if (!class_exists('\WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Custom_Capability')) {
43
+
44
+ /**
45
+ * Post Type Custom capability class
46
+ *
47
+ * @author Jinu Varghese
48
+ * @copyright 2014 WPFront.com
49
+ */
50
+ abstract class WPFront_User_Role_Editor_Post_Type_Custom_Capability {
51
+
52
+ /**
53
+ *
54
+ * @var WPFront_User_Role_Editor_Post_Type_Custom_Capability[]
55
+ */
56
+ private static $custom_cap_objs = array();
57
+ protected $cap_names = array();
58
+
59
+ /**
60
+ * Used in restore role to restore properly.
61
+ *
62
+ * @var string[]
63
+ */
64
+ protected static $custom_caps = array();
65
+
66
+ protected abstract function init($controller);
67
+
68
+ /**
69
+ * Returns custom cap prefix.
70
+ */
71
+ protected abstract function cap_prefix();
72
+
73
+ /**
74
+ * Returns cap prefix to add before in sort.
75
+ */
76
+ protected abstract function add_before_prefix();
77
+
78
+ /**
79
+ * Returns the cap to check while defining role defaults.
80
+ */
81
+ protected abstract function role_default_value_cap($post_type);
82
+
83
+ protected abstract function can_merge();
84
+
85
+ public static function initialize($controller) {
86
+ foreach (self::$custom_cap_objs as $key => $obj) {
87
+ $obj->init($controller);
88
+
89
+ if (!is_admin()) {
90
+ continue;
91
+ }
92
+
93
+ //sort cap in RolesHelper.
94
+ add_filter('wpfront_ure_role_group_capabilities', array($obj, 'order_group_caps'), 10, 2);
95
+ }
96
+ }
97
+
98
+ public static function register_post_type_args($controller, $args, $post_type) {
99
+ foreach (self::$custom_cap_objs as $key => $obj) {
100
+ $args = $obj->post_type_args($args, $post_type);
101
+ }
102
+ return $args;
103
+ }
104
+
105
+ public static function register($key, $objCustomCap) {
106
+ self::$custom_cap_objs[$key] = $objCustomCap;
107
+ }
108
+
109
+ protected function post_type_args($args, $post_type) {
110
+ //attachment caps are handled in media permissions class.
111
+ if ($post_type === 'attachment') {
112
+ return $args;
113
+ }
114
+
115
+ $args_local = $args;
116
+
117
+ if (empty($args_local['capability_type'])) {
118
+ $args_local['capability_type'] = 'post';
119
+ }
120
+
121
+ if (!$this->is_user_visible($args_local)) {
122
+ return $args;
123
+ }
124
+
125
+ if (!is_array($args_local['capability_type'])) {
126
+ $capability_type = array($args_local['capability_type'], $args_local['capability_type'] . 's');
127
+ } else {
128
+ $capability_type = $args_local['capability_type'];
129
+ }
130
+
131
+ list( $singular_base, $plural_base ) = $capability_type;
132
+
133
+ if (empty($args['capabilities'])) {
134
+ $args['capabilities'] = array();
135
+ }
136
+
137
+ $prefix = $this->cap_prefix();
138
+ $cap = $prefix . '_' . $plural_base;
139
+ $this->cap_names[$post_type] = [$cap, $plural_base];
140
+
141
+ if($this->can_merge()) {
142
+ $args['capabilities'] = array_merge($args['capabilities'], array($prefix . '_posts' => $cap));
143
+ }
144
+
145
+ if (!is_admin()) {
146
+ return $args;
147
+ }
148
+
149
+ $map_cap = $this->role_default_value_cap($post_type);
150
+ $settings_key = $this->update_role_caps_settings_key();
151
+ $this->update_role_caps($post_type, $cap, $map_cap, $singular_base, $settings_key);
152
+
153
+ if (Utils::doing_ajax()) {
154
+ return $args;
155
+ }
156
+
157
+ $this->toggle_cap_functionality($cap);
158
+
159
+ //for help links
160
+ if ($plural_base === 'posts' || $plural_base === 'pages') {
161
+ add_filter("wpfront_ure_capability_{$cap}_ui_help_link", array($this, 'cap_help_link'), 10, 2);
162
+ }
163
+
164
+ return $args;
165
+ }
166
+
167
+
168
+ /**
169
+ * Checks whether post type is user visible.
170
+ *
171
+ * @param array|string $args Array if post type arguments or post type name.
172
+ * @return boolean
173
+ */
174
+ protected function is_user_visible($args) {
175
+ $public = false;
176
+ $show_ui = false;
177
+ $cap_not_defaulted = false;
178
+
179
+ if(is_array($args)) {
180
+ if (!isset($args['public'])) { //public default is false.
181
+ return false;
182
+ }
183
+
184
+ if (!isset($args['show_ui'])) {
185
+ $args['show_ui'] = $args['public'];
186
+ }
187
+
188
+ if(empty($args['capability_type'])) {
189
+ $args['capability_type'] = 'post';
190
+ }
191
+
192
+ $public = $args['public'];
193
+ $show_ui = $args['show_ui'];
194
+ $cap_not_defaulted = $args['capability_type'] !== 'post';
195
+ } else {
196
+ $post_type_obj = get_post_type_object($args);
197
+ if(empty($post_type_obj)) {
198
+ return false;
199
+ }
200
+
201
+ $public = $post_type_obj->public;
202
+ $show_ui = $post_type_obj->show_ui;
203
+ $cap_not_defaulted = $post_type_obj->capability_type != 'post';
204
+ }
205
+
206
+ return $public && ($show_ui || $cap_not_defaulted);
207
+ }
208
+
209
+ protected function get_capability_name($post_type) {
210
+ return $this->cap_names[$post_type][0];
211
+ }
212
+
213
+ protected function get_capability_name_base($post_type) {
214
+ return $this->cap_names[$post_type][1];
215
+ }
216
+
217
+ /**
218
+ * Orders the custom cap in RolesHelper.
219
+ *
220
+ * @param string[] $group_caps
221
+ * @param object $group
222
+ * @return string[]
223
+ */
224
+ public function order_group_caps($group_caps, $group) {
225
+ if ($group->type === 'default') {
226
+ if ($group->key === 'posts') {
227
+ $group_caps = $this->reorder_cap('post', $group_caps);
228
+ }
229
+
230
+ if ($group->key === 'pages') {
231
+ $group_caps = $this->reorder_cap('page', $group_caps);
232
+ }
233
+ }
234
+
235
+ if ($group->type === 'custom_post') {
236
+ $group_caps = $this->reorder_cap($group->key, $group_caps);
237
+ }
238
+
239
+ return $group_caps;
240
+ }
241
+
242
+ /**
243
+ * Orders the custom cap in list.
244
+ *
245
+ * @param string $post_type
246
+ * @param string[] $caps
247
+ * @return string[]
248
+ */
249
+ protected function reorder_cap($post_type, $caps) {
250
+ if(!$this->is_user_visible($post_type)) {
251
+ return $caps;
252
+ }
253
+
254
+ $cap = $this->get_capability_name($post_type);
255
+
256
+ $index = array_search($cap, $caps);
257
+ if ($index !== false) {
258
+ array_splice($caps, $index, 1);
259
+ }
260
+
261
+ $index = array_search($this->add_before_prefix() . '_' . $this->get_capability_name_base($post_type), $caps);
262
+ array_splice($caps, $index, 0, $cap);
263
+
264
+ return $caps;
265
+ }
266
+
267
+ /**
268
+ * Returns cap help link.
269
+ *
270
+ * @param string $help_link
271
+ * @param string $cap
272
+ * @return string
273
+ */
274
+ public function cap_help_link($help_link, $cap) {
275
+ return RolesHelper::get_wpfront_help_link($cap);
276
+ }
277
+
278
+ protected function toggle_cap_functionality($cap) {
279
+ add_filter("wpfront_ure_capability_{$cap}_functionality_enabled", '__return_false');
280
+ }
281
+
282
+ protected function update_role_caps_settings_key() {
283
+ $settings_key = "post_type_custom_capabilities_default_state_processed";
284
+ return $settings_key;
285
+ }
286
+
287
+ protected function update_role_caps($post_type, $cap, $check_cap, $capability_type, $settings_key) {
288
+ if ($post_type !== 'post' && $capability_type === 'post') {
289
+ return;
290
+ }
291
+
292
+ self::$custom_caps[$cap] = $check_cap;
293
+
294
+ $value = Options::instance()->get_option($settings_key);
295
+ if (!empty($value[$cap . '_' . $post_type])) {
296
+ return;
297
+ }
298
+
299
+ $role_names = RolesHelper::get_roles();
300
+ foreach ($role_names as $role_name) {
301
+ $role = RolesHelper::get_role($role_name);
302
+ if (isset($role->capabilities[$check_cap])) {
303
+ if (!isset($role->capabilities[$cap])) {
304
+ $role->add_cap($cap, $role->capabilities[$check_cap]);
305
+ }
306
+ }
307
+ }
308
+
309
+ if (empty($value)) {
310
+ $value = array();
311
+ }
312
+
313
+ $value[$cap . '_' . $post_type] = true;
314
+
315
+ Options::instance()->set_option($settings_key, $value);
316
+ }
317
+
318
+ public static function restore_role_custom_caps($custom_caps) {
319
+ foreach (self::$custom_caps as $cap => $check) {
320
+ $custom_caps[$cap] = $check;
321
+ }
322
+
323
+ return $custom_caps;
324
+ }
325
+
326
+ }
327
+
328
+ add_filter('wpfront_ure_restore_role_custom_caps', array(WPFront_User_Role_Editor_Post_Type_Custom_Capability::class, 'restore_role_custom_caps'));
329
+ }
330
+
331
+ require_once dirname(__FILE__) . '/custom-caps/class-read-others-capability.php';
332
+ require_once dirname(__FILE__) . '/custom-caps/class-create-posts-capability.php';
includes/post-type/class-post-type-list-table.php ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * WPFront User Role Editor Post Type List Table
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Post_Type;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WP_List_Table')) {
38
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
39
+ }
40
+
41
+ if (!class_exists('\WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_List_Table')) {
42
+
43
+ /**
44
+ * Post Type List Table
45
+ *
46
+ * @author Vaisagh D <vaisaghd@wpfront.com>
47
+ * @copyright 2015 WPFront.com
48
+ */
49
+ class WPFront_User_Role_Editor_Post_Type_List_Table extends \WP_List_Table {
50
+
51
+ /**
52
+ *
53
+ * @var WPFront_User_Role_Editor_Post_Type
54
+ */
55
+ private $controller;
56
+
57
+ /**
58
+ *
59
+ * @param WPFront_User_Role_Editor_Post_Type $controller
60
+ */
61
+ public function __construct($controller) {
62
+ $this->controller = $controller;
63
+ parent::__construct(array('screen' => 'post-type'));
64
+ }
65
+
66
+ function prepare_items() {
67
+ $search = '';
68
+ if (!empty($_GET['s'])) {
69
+ $search = $_GET['s'];
70
+ }
71
+
72
+ $this->items = $this->controller->search($search);
73
+ $this->items = $this->controller->apply_active_list_filter($this->items);
74
+
75
+ $this->set_pagination_args(array(
76
+ 'total_items' => count($this->items),
77
+ 'per_page' => PHP_INT_MAX,
78
+ ));
79
+ }
80
+
81
+ function get_bulk_actions() {
82
+ $actions = array();
83
+
84
+ if (current_user_can('delete_posttypes')) {
85
+ $actions['delete'] = __('Delete', 'wpfront-user-role-editor');
86
+ }
87
+
88
+ if (current_user_can('edit_posttypes')) {
89
+ $actions['restore'] = __('Restore', 'wpfront-user-role-editor');
90
+ $actions['activate'] = __('Activate', 'wpfront-user-role-editor');
91
+ $actions['deactivate'] = __('Deactivate', 'wpfront-user-role-editor');
92
+ }
93
+
94
+ return $actions;
95
+ }
96
+
97
+ function get_columns() {
98
+ $columns = array(
99
+ 'cb' => '<input type="checkbox" />',
100
+ 'name' => __('Name', 'wpfront-user-role-editor'),
101
+ 'label' => __('Label', 'wpfront-user-role-editor'),
102
+ 'source' => __('Source', 'wpfront-user-role-editor'),
103
+ 'taxonomies' => __('Taxonomies', 'wpfront-user-role-editor'),
104
+ 'status' => __('Active', 'wpfront-user-role-editor'),
105
+ 'edited' => __('Edited', 'wpfront-user-role-editor')
106
+ );
107
+
108
+ return $columns;
109
+ }
110
+
111
+ function display_rows() {
112
+ foreach ($this->items as $item) {
113
+ $alt = empty($alt) ? 'alternate' : '';
114
+ ?>
115
+ <tr class="<?php echo $alt; ?>">
116
+ <?php
117
+ list( $columns, $hidden ) = $this->get_column_info();
118
+
119
+ foreach ($columns as $column_name => $column_display_name) {
120
+ $class = "class='$column_name column-$column_name'";
121
+
122
+ $style = '';
123
+ if (in_array($column_name, $hidden)) {
124
+ $style = ' style="display:none;"';
125
+ }
126
+
127
+ $attributes = "$class$style";
128
+
129
+ switch ($column_name) {
130
+ case 'cb':
131
+ $this->cb_cell($item);
132
+ break;
133
+
134
+ case 'name':
135
+ $this->name_cell($item, $attributes);
136
+ break;
137
+
138
+ case 'label':
139
+ $this->label_cell($item);
140
+ break;
141
+
142
+ case 'source':
143
+ $this->source_cell($item);
144
+ break;
145
+
146
+ case 'taxonomies':
147
+ $this->taxonomies_cell($item);
148
+ break;
149
+
150
+ case 'status':
151
+ $this->status_cell($item);
152
+ break;
153
+
154
+ case 'edited':
155
+ $this->edited_cell($item);
156
+ break;
157
+ }
158
+ }
159
+ ?>
160
+ </tr>
161
+ <?php
162
+ }
163
+ }
164
+
165
+ protected function cb_cell($item) {
166
+ ?>
167
+ <th scope="row" class="check-column">
168
+ <?php if ($item->can_edit) { ?>
169
+ <label class="screen-reader-text" for="post_type_select" ?></label>
170
+ <input type="checkbox" id="post_type_<?php echo $item->name; ?>" name="post_types[]" value="<?php echo esc_attr($item->name); ?>" />
171
+ <?php } ?>
172
+ </th>
173
+ <?php
174
+ }
175
+
176
+ protected function name_cell($item, $attributes) {
177
+ ?>
178
+
179
+ <td <?php echo $attributes; ?>>
180
+ <?php
181
+ if ($item->can_edit) {
182
+ $edit_link = $this->controller->get_edit_url($item->name);
183
+ ?>
184
+ <strong>
185
+ <a href="<?php echo $edit_link; ?>" class="edit">
186
+ <?php echo $item->name; ?>
187
+ </a>
188
+ </strong>
189
+ <?php
190
+ } else {
191
+ ?> <?php echo $item->name; ?> <?php
192
+ }
193
+ $actions = array();
194
+ if ($item->can_edit) {
195
+ $edit_link = $this->controller->get_edit_url($item->name);
196
+ $display = __('Edit', 'wpfront-user-role-editor');
197
+ $actions['edit'] = "<a href='$edit_link'>$display</a>";
198
+ }
199
+ if ($item->can_delete) {
200
+ $delete_link = $this->controller->get_delete_url($item->name);
201
+ $display = __('Delete', 'wpfront-user-role-editor');
202
+ $actions['delete'] = "<a href='$delete_link'>$display</a>";
203
+ }
204
+ if ($item->can_activate) {
205
+ $activate_link = $this->controller->get_activate_url($item->name);
206
+ $display = __('Activate', 'wpfront-user-role-editor');
207
+ $actions['activate'] = "<a href='$activate_link'>$display</a>";
208
+ }
209
+ if ($item->can_deactivate) {
210
+ $deactivate_link = $this->controller->get_deactivate_url($item->name);
211
+ $display = __('Deactivate', 'wpfront-user-role-editor');
212
+ $actions['deactivate'] = "<a href='$deactivate_link'>$display</a>";
213
+ }
214
+ if ($item->can_clone) {
215
+ $clone_link = $this->controller->get_clone_url($item->name);
216
+ $display = __('Clone', 'wpfront-user-role-editor');
217
+ $actions['clone'] = "<a href='$clone_link'>$display</a>";
218
+ }
219
+ if ($item->can_restore) {
220
+ $restore_link = $this->controller->get_restore_url($item->name);
221
+ $display = __('Restore', 'wpfront-user-role-editor');
222
+ $actions['restore'] = "<a href='$restore_link'>$display</a>";
223
+ }
224
+ echo $this->row_actions($actions);
225
+ ?>
226
+ </td>
227
+ <?php
228
+ }
229
+
230
+ protected function label_cell($item) {
231
+ ?>
232
+ <td class="label column-label">
233
+ <?php echo $item->label; ?>
234
+ </td>
235
+ <?php
236
+ }
237
+
238
+ protected function source_cell($item) {
239
+ ?>
240
+ <td class="source column-source">
241
+ <?php
242
+ switch ($item->source_type) {
243
+ case 0:
244
+ echo __('Built-In', 'wpfront-user-role-editor');
245
+ break;
246
+
247
+ case 1:
248
+ echo __('Other', 'wpfront-user-role-editor');
249
+ break;
250
+
251
+ default:
252
+ echo __('User Defined', 'wpfront-user-role-editor');
253
+ break;
254
+ }
255
+ ?>
256
+ </td>
257
+ <?php
258
+ }
259
+
260
+ protected function status_cell($item) {
261
+ $i = '';
262
+ ?>
263
+ <td class="status column-status">
264
+ <?php
265
+ switch ($item->status) {
266
+ case 0:
267
+ $i = '<i class ="fa fa-times"></i>';
268
+ break;
269
+
270
+ case 1:
271
+ $i = '<i class ="fa fa-check"></i>';
272
+ break;
273
+ }
274
+ echo $i;
275
+ ?>
276
+ </td>
277
+ <?php
278
+ }
279
+
280
+ protected function taxonomies_cell($item) {
281
+ ?>
282
+ <td class="taxonomies column-taxonomies">
283
+ <?php
284
+ $taxonomies = $item->taxonomies;
285
+ foreach ($taxonomies as $taxonomy) {
286
+ if (!empty($taxonomy)) {
287
+ $taxonomy_type = get_taxonomy($taxonomy);
288
+ if (!empty($taxonomy_type)) {
289
+ $taxonomy_types[] = $taxonomy_type->label;
290
+ }
291
+ }
292
+ }
293
+ if (!empty($taxonomy_types)) {
294
+ $taxonomy_types = implode(', ', $taxonomy_types);
295
+ echo $taxonomy_types;
296
+ }
297
+ ?>
298
+ </td>
299
+ <?php
300
+ }
301
+
302
+ protected function edited_cell($item) {
303
+ $i = '';
304
+ if (!empty($item->entity)) {
305
+ $i = '<i class ="fa fa-check-circle"></i>';
306
+ }
307
+ ?>
308
+ <td class ="edited column-edited">
309
+ <?php echo $i; ?>
310
+ </td>
311
+ <?php
312
+ }
313
+
314
+ }
315
+
316
+ }
317
+
includes/post-type/class-post-type.php ADDED
@@ -0,0 +1,1361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Controller for WPFront User Role Editor Post Type
27
+ *
28
+ * @author Vaisagh D <vaisaghd@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Post_Type;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ require_once dirname(__FILE__) . '/entity-post-type.php';
39
+ require_once dirname(__FILE__) . '/template-post-type.php';
40
+ require_once dirname(__FILE__) . '/template-add-edit.php';
41
+ require_once dirname(__FILE__) . '/template-delete.php';
42
+ require_once dirname(__FILE__) . '/class-abstract-post-type-custom-cap.php';
43
+
44
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
45
+ use \WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Custom_Capability;
46
+
47
+ if (!class_exists('\WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type')) {
48
+
49
+ /**
50
+ * Post Type List class
51
+ *
52
+ * @author Vaisagh D <vaisaghd@wpfront.com>
53
+ * @copyright 2014 WPFront.com
54
+ */
55
+ class WPFront_User_Role_Editor_Post_Type extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
56
+
57
+ const STATUS_ACTIVE = 1;
58
+ const STATUS_INACTIVE = 0;
59
+ const SOURCE_TYPE_BUILTIN = 0;
60
+ const SOURCE_TYPE_OTHER = 1;
61
+ const SOURCE_TYPE_USER_DEFINED = 2;
62
+ const MENU_SLUG = 'wpfront-user-role-editor-post-types';
63
+ const DATA_EDITED_KEY = 'wpfront-user-role-editor-post-types-data-edited';
64
+
65
+ private $entities = null;
66
+ private $post_types_cache = null;
67
+ private $post_types_cache_clear = false;
68
+ private $post_type_args = array();
69
+ private $post_types_unregistered = array();
70
+ private $objView = null;
71
+ public $errorMsg = null;
72
+ protected $AddEditViewClass = null;
73
+
74
+ protected function setUp() {
75
+ $this->_setUp('edit_posttypes', self::MENU_SLUG);
76
+ $this->AddEditViewClass = WPFront_User_Role_Editor_Post_Type_Add_Edit_View::class;
77
+ }
78
+
79
+ protected function initialize() {
80
+ add_action('init', array($this, 'register_post_types'), PHP_INT_MAX);
81
+ add_filter('register_post_type_args', array($this, 'register_post_type_args'), 1, 2);
82
+ add_action('registered_post_type', array($this, 'registered_post_type'), 1, 2);
83
+ add_action('registered_post_type', array($this, 'deactivate_other_post_types'), PHP_INT_MAX, 2);
84
+ add_action('wp_loaded', array($this, 'flush_rewrite_rules'), 1);
85
+
86
+ WPFront_User_Role_Editor_Post_Type_Custom_Capability::initialize($this);
87
+
88
+ if (!is_admin()) {
89
+ return;
90
+ }
91
+
92
+ $this->set_admin_menu(__('Post Types', 'wpfront-user-role-editor'), __('Post Types', 'wpfront-user-role-editor'), 60);
93
+ }
94
+
95
+ /**
96
+ * Register the user defined post type.
97
+ *
98
+ * @return string
99
+ */
100
+ public function register_post_types() {
101
+ $post_types = $this->get_all_post_types_data();
102
+ foreach ($post_types as $data) {
103
+ if ($data->status == self::STATUS_ACTIVE && $data->source_type === self::SOURCE_TYPE_USER_DEFINED) {
104
+ $args = $data->post_type_arg;
105
+ $args['taxonomies'] = $data->taxonomies;
106
+ register_post_type($data->name, $args);
107
+ }
108
+ }
109
+
110
+ $this->register_post_type_taxonomies_supports();
111
+
112
+ //set state of late registrations
113
+ add_action('registered_post_type', array($this, 'clear_cache'));
114
+ }
115
+
116
+ /**
117
+ * Taxonomies and supports needs to be registered within 'init' hook.
118
+ * For built-in types as part of 'arg' is not enough.
119
+ */
120
+ protected function register_post_type_taxonomies_supports() {
121
+ $post_types = $this->get_all_post_types_data();
122
+ foreach ($post_types as $data) {
123
+ if (empty($data->entity)) { //don't do anything if not edited.
124
+ continue;
125
+ }
126
+
127
+ //handle only built-in. other will be handled in 'register_post_type_args'.
128
+ if ($data->status == self::STATUS_ACTIVE && $data->source_type === self::SOURCE_TYPE_BUILTIN) {
129
+ if (isset($data->taxonomies) && is_array($data->taxonomies)) {
130
+ $registered = get_object_taxonomies($data->name);
131
+ $requested = $data->taxonomies;
132
+
133
+ $unregister = array_diff($registered, $requested);
134
+ $register = array_diff($requested, $registered);
135
+
136
+ foreach ($unregister as $tax) {
137
+ unregister_taxonomy_for_object_type($tax, $data->name);
138
+ }
139
+
140
+ foreach ($register as $tax) {
141
+ register_taxonomy_for_object_type($tax, $data->name);
142
+ }
143
+ }
144
+
145
+ if (isset($data->post_type_arg['supports'])) {
146
+ $registered = array_keys(get_all_post_type_supports($data->name));
147
+ $requested = is_array($data->post_type_arg['supports']) ? $data->post_type_arg['supports'] : [];
148
+
149
+ $unregister = array_diff($registered, $requested);
150
+ $register = array_diff($requested, $registered);
151
+
152
+ foreach ($unregister as $feature) {
153
+ remove_post_type_support($data->name, $feature);
154
+ }
155
+
156
+ foreach ($register as $feature) {
157
+ add_post_type_support($data->name, $feature);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Store post type registration arguments and merge them with edited arguments.
166
+ *
167
+ * @param type $args
168
+ * @param type $post_type
169
+ * @return type
170
+ */
171
+ public function register_post_type_args($args, $post_type) {
172
+ $entity_all = $this->get_all_entities();
173
+ $add_custom_caps = true;
174
+ if (isset($entity_all[$post_type])) {
175
+ if(empty($args['_builtin']) && $entity_all[$post_type]->status == self::STATUS_INACTIVE) {
176
+ $add_custom_caps = false;
177
+ }
178
+
179
+ $saved = $entity_all[$post_type]->post_type_arg;
180
+ $saved['taxonomies'] = $entity_all[$post_type]->taxonomies;
181
+
182
+ if (isset($saved['capability_type'])) {
183
+ $saved['capabilities'] = array(); //override, otherwise custom mapping will take over.
184
+ }
185
+
186
+ $args = array_merge($args, $saved);
187
+ }
188
+
189
+ if($add_custom_caps) {
190
+ $args = WPFront_User_Role_Editor_Post_Type_Custom_Capability::register_post_type_args($this, $args, $post_type);
191
+ }
192
+
193
+ $this->post_type_args[$post_type] = $args;
194
+
195
+ return $args;
196
+ }
197
+
198
+ /**
199
+ * Retrieve singular name after registration if it doesn't exist. WP doesn't provide it as part of arguments.
200
+ *
201
+ * @param type $post_type
202
+ * @param type $post_type_object
203
+ * @return type
204
+ */
205
+ public function registered_post_type($post_type, $post_type_object) {
206
+ if (empty($this->post_type_args[$post_type])) {
207
+ return;
208
+ }
209
+
210
+ if (!empty($this->post_type_args[$post_type]['labels']['singular_name'])) {
211
+ return;
212
+ }
213
+
214
+ $this->post_type_args[$post_type]['labels']['singular_name'] = $post_type_object->labels->singular_name;
215
+ }
216
+
217
+ /**
218
+ * Deactivate other post types based on DB state.
219
+ *
220
+ * @param type $post_type
221
+ * @param type $post_type_object
222
+ * @return type
223
+ */
224
+ public function deactivate_other_post_types($post_type, $post_type_object) {
225
+ if (!empty($post_type_object->_builtin)) {
226
+ return;
227
+ }
228
+
229
+ $entity_all = $this->get_all_entities();
230
+ if (isset($entity_all[$post_type]) && $entity_all[$post_type]->status === self::STATUS_INACTIVE) {
231
+ $this->post_types_unregistered[$post_type] = $post_type_object;
232
+ unregister_post_type($post_type);
233
+ }
234
+ }
235
+
236
+ public function flush_rewrite_rules() {
237
+ $value = $this->Options->get_option(self::DATA_EDITED_KEY);
238
+ if (!empty($value)) {
239
+ flush_rewrite_rules();
240
+ $this->Options->set_option(self::DATA_EDITED_KEY, false);
241
+ }
242
+ }
243
+
244
+ public function load_view() {
245
+ if (!parent::load_view()) {
246
+ return;
247
+ }
248
+
249
+ if ((!empty($_POST['action']) && $_POST['action'] !== '-1') || (!empty($_POST['action2']) && $_POST['action2'] !== '-1')) {
250
+ $action = $_POST['action'] === '-1' ? $_POST['action2'] : $_POST['action'];
251
+
252
+ $post_types = [];
253
+ if (!empty($_POST['post_types']) && is_array($_POST['post_types'])) {
254
+ foreach ($_POST['post_types'] as $value) {
255
+ $data = $this->get_post_type_data($value);
256
+ if (!empty($data)) {
257
+ $post_types[] = $data;
258
+ }
259
+ }
260
+ }
261
+
262
+ switch ($action) {
263
+ case 'delete':
264
+ case 'restore':
265
+ $this->handle_action($action, $post_types);
266
+ return;
267
+
268
+ case 'activate':
269
+ case 'deactivate':
270
+ $this->activate_deactivate_post_type($action, $post_types);
271
+ return;
272
+ }
273
+
274
+ wp_redirect($this->get_list_url());
275
+ exit;
276
+ }
277
+
278
+ if (!empty($_GET['screen'])) {
279
+ $screen = $_GET['screen'];
280
+
281
+ switch ($screen) {
282
+ case 'activate':
283
+ case 'deactivate':
284
+ $this->activate_deactivate_post_type($screen);
285
+ return;
286
+
287
+ case 'add-new':
288
+ case 'edit':
289
+ $this->add_edit_post_type($screen);
290
+ return;
291
+
292
+ case 'delete':
293
+ case 'restore':
294
+ $this->handle_action($screen);
295
+ return;
296
+
297
+ default:
298
+ break;
299
+ }
300
+ }
301
+
302
+ $this->objView = new WPFront_User_Role_Editor_Post_Type_List_View($this);
303
+ return;
304
+ }
305
+
306
+ private function activate_deactivate_post_type($screen, $datas = null) {
307
+ switch ($screen) {
308
+ case 'activate':
309
+ $cap = 'edit_posttypes';
310
+ $check = 'can_activate';
311
+ $q_arg = 'post-type-activated';
312
+ break;
313
+
314
+ case 'deactivate':
315
+ $cap = 'edit_posttypes';
316
+ $check = 'can_deactivate';
317
+ $q_arg = 'post-type-deactivated';
318
+ break;
319
+
320
+ default:
321
+ wp_redirect($this->get_list_url());
322
+ exit;
323
+ }
324
+
325
+ if (!current_user_can($cap)) {
326
+ $this->WPFURE->permission_denied();
327
+ exit;
328
+ }
329
+
330
+ if ($datas === null) { //url activate/deactivate
331
+ if (empty($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'])) {
332
+ $this->WPFURE->permission_denied();
333
+ exit;
334
+ }
335
+
336
+ $data = $this->get_post_type_data_from_url();
337
+ if (empty($data)) {
338
+ return;
339
+ }
340
+
341
+ $datas = [$data];
342
+ } else { //bulk post
343
+ check_admin_referer('bulk-post-type');
344
+ }
345
+
346
+ $count = 0;
347
+ foreach ($datas as $data) {
348
+ if ($data->$check) {
349
+ if (empty($data->entity)) { //no db data, either built-in or other post type.
350
+ if ($screen === 'deactivate') {
351
+ $entity = new WPFront_User_Role_Editor_Post_Type_Entity();
352
+ $entity->name = $data->name;
353
+ $entity->label = $data->label;
354
+ $entity->status = self::STATUS_INACTIVE;
355
+ $entity->post_type_arg = $this->post_type_args[$data->name];
356
+ $entity->taxonomies = isset($entity->post_type_arg['taxonomies']) ? $entity->post_type_arg['taxonomies'] : [];
357
+ $entity->update();
358
+ $count++;
359
+ }
360
+ continue;
361
+ }
362
+
363
+ if ($screen === 'activate') {
364
+ $data->entity->update_status(self::STATUS_ACTIVE);
365
+ } else {
366
+ $data->entity->update_status(self::STATUS_INACTIVE);
367
+ }
368
+ $count++;
369
+ }
370
+ }
371
+
372
+ wp_safe_redirect(add_query_arg($q_arg, $count, $this->get_list_url()));
373
+ exit;
374
+ }
375
+
376
+ private function add_edit_post_type($screen) {
377
+ $data = null;
378
+ $clone = null;
379
+ if ($screen == 'edit') {
380
+ if (!current_user_can('edit_posttypes')) {
381
+ $this->WPFURE->permission_denied();
382
+ exit;
383
+ }
384
+ $data = $this->get_post_type_data_from_url();
385
+ if (empty($data)) {
386
+ return;
387
+ }
388
+ if (!$data->can_edit) {
389
+ $this->WPFURE->permission_denied();
390
+ exit;
391
+ }
392
+ } elseif ($screen === 'add-new') {
393
+ if (!current_user_can('create_posttypes')) {
394
+ $this->WPFURE->permission_denied();
395
+ exit;
396
+ }
397
+ if (!empty($_GET['clone'])) {
398
+ $clone = $this->get_post_type_data($_GET['clone']);
399
+ }
400
+ }
401
+
402
+ $this->objView = new $this->AddEditViewClass(
403
+ $this,
404
+ $data,
405
+ empty($data) ? null : get_post_type_object($data->name),
406
+ $clone
407
+ );
408
+
409
+ if (!empty($_POST['submit']) || !empty($_POST['submit2'])) {
410
+ check_admin_referer('add-edit-post-type');
411
+
412
+ $entity = null;
413
+ if ($screen == 'add-new') {
414
+ if (!current_user_can('create_posttypes')) {
415
+ $this->WPFURE->permission_denied();
416
+ exit;
417
+ }
418
+ $name = $this->get_submitted_text('name');
419
+ if (empty($name)) {
420
+ $this->errorMsg = __('Name must be provided.', 'wpfront-user-role-editor');
421
+ return;
422
+ }
423
+
424
+ if (!$this->is_valid_slug($name)) {
425
+ $this->errorMsg = __('This post type name is not allowed (Use only lowercase letters, numbers, underscores and hyphens).', 'wpfront-user-role-editor');
426
+ return;
427
+ }
428
+
429
+ if (strlen($name) > 20) {
430
+ $this->errorMsg = __('This post type name is too long.', 'wpfront-user-role-editor');
431
+ return;
432
+ }
433
+
434
+ if (!empty($this->get_post_type_data($name))) {
435
+ $this->errorMsg = __('Post type already exists.', 'wpfront-user-role-editor');
436
+ return;
437
+ }
438
+
439
+ $reserved = ['action', 'author', 'order', 'theme'];
440
+ if (in_array($name, $reserved)) {
441
+ $this->errorMsg = __('This post type name is reserved and can not be added.', 'wpfront-user-role-editor');
442
+ return;
443
+ }
444
+
445
+ $entity = new WPFront_User_Role_Editor_Post_Type_Entity();
446
+ $entity->name = $name;
447
+ $entity->status = self::STATUS_ACTIVE;
448
+ } else {
449
+ if (!empty($data->entity)) {
450
+ $entity = $data->entity;
451
+ } else {
452
+ $entity = new WPFront_User_Role_Editor_Post_Type_Entity();
453
+ $entity->name = $data->name;
454
+ $entity->status = self::STATUS_ACTIVE;
455
+ }
456
+ }
457
+
458
+ $labels = $this->get_submitted_text('label');
459
+ if (empty($labels)) {
460
+ $this->errorMsg = __('Plural label must be provided.', 'wpfront-user-role-editor');
461
+ return;
462
+ }
463
+
464
+ $entity->label = $labels; //WordPress stores plural on label.
465
+
466
+ $label = $this->get_submitted_text('singular_name');
467
+ if (empty($label)) {
468
+ $this->errorMsg = __('Singular label must be provided.', 'wpfront-user-role-editor');
469
+ return;
470
+ }
471
+
472
+ $entity->taxonomies = $this->get_submitted_array('taxonomies');
473
+
474
+ if (!empty($data) && $data->source_type === self::SOURCE_TYPE_BUILTIN) {
475
+ $entity->status = self::STATUS_ACTIVE;
476
+ } else {
477
+ $value = $this->get_submitted_boolean('status');
478
+ $entity->status = $value ? self::STATUS_ACTIVE : self::STATUS_INACTIVE;
479
+ }
480
+
481
+ $post_type_args = array();
482
+ $post_type_args = $this->get_advanced_settings_arg();
483
+ $post_type_args['labels'] = $this->get_labels_arg();
484
+
485
+ if (!empty($this->errorMsg)) {
486
+ return;
487
+ }
488
+
489
+ $post_type_args = $this->sanitize_add_edit_post_type_args($screen, $post_type_args, $entity);
490
+
491
+ if (!empty($this->errorMsg)) {
492
+ return;
493
+ }
494
+
495
+ $entity->post_type_arg = $post_type_args;
496
+
497
+ if ($screen == 'add-new') {
498
+ $result = $entity->add();
499
+ $url_arg = 'post-type-added';
500
+ } else {
501
+ $result = $entity->update();
502
+ $url_arg = 'post-type-updated';
503
+ }
504
+
505
+ if ($result === false) {
506
+ $this->errorMsg = __('Unexpected error occured.', 'wpfront-user-role-editor');
507
+ return;
508
+ }
509
+
510
+ if (!current_user_can('edit_posttypes')) {
511
+ $args = apply_filters('wpfront_ure_post_type_add_edit_success_url_args', array('post-type-added' => 'true'), $entity);
512
+ wp_safe_redirect(add_query_arg($args, $this->get_list_url()));
513
+ exit;
514
+ } else {
515
+ $args = apply_filters('wpfront_ure_post_type_add_edit_success_url_args', array($url_arg => 'true'), $entity);
516
+ wp_safe_redirect(add_query_arg($args, $this->get_edit_url($entity->name)));
517
+ exit;
518
+ }
519
+ }
520
+ }
521
+
522
+ protected function sanitize_add_edit_post_type_args($screen, $post_type_args, $entity) {
523
+ return $post_type_args;
524
+ }
525
+
526
+ private function handle_action($action, $datas = null) {
527
+ switch ($action) {
528
+ case 'delete':
529
+ $cap = 'delete_posttypes';
530
+ $check = 'can_delete';
531
+ $q_arg = 'post-types-deleted';
532
+ break;
533
+
534
+ case 'restore':
535
+ $cap = 'edit_posttypes';
536
+ $check = 'can_restore';
537
+ $q_arg = 'post-types-restored';
538
+ break;
539
+
540
+ default:
541
+ wp_redirect($this->get_list_url());
542
+ exit;
543
+ }
544
+
545
+ if (!current_user_can($cap)) {
546
+ $this->WPFURE->permission_denied();
547
+ exit;
548
+ }
549
+
550
+ $entities = [];
551
+ if (empty($datas)) {
552
+ $data = $this->get_post_type_data_from_url();
553
+ if (!empty($data->$check)) {
554
+ $entities = [$data->entity];
555
+ }
556
+ } else {
557
+ foreach ($datas as $data) {
558
+ if ($data->$check) {
559
+ $entities[] = $data->entity;
560
+ }
561
+ }
562
+ }
563
+
564
+ if (empty($entities)) {
565
+ wp_redirect($this->get_list_url());
566
+ exit;
567
+ }
568
+
569
+ if (!empty($_POST['submit'])) {
570
+ check_admin_referer('bulk-action-view-post');
571
+ foreach ($entities as $entity) {
572
+ $entity->delete($action);
573
+ }
574
+ wp_safe_redirect(add_query_arg($q_arg, 'true', $this->get_list_url()));
575
+ exit;
576
+ }
577
+
578
+ $this->objView = new WPFront_User_Role_Editor_Post_Type_Delete_View($this, $entities, $action);
579
+ }
580
+
581
+ private function get_advanced_settings_arg() {
582
+ $args = array();
583
+
584
+ $props = [
585
+ 'rest_base',
586
+ 'rest_controller_class',
587
+ 'menu_position',
588
+ 'menu_icon'
589
+ ];
590
+
591
+ foreach ($props as $prop) {
592
+ $value = $this->get_submitted_text($prop);
593
+ if ($value !== null) {
594
+ $args[$prop] = $value;
595
+ }
596
+ }
597
+
598
+ if (isset($args['menu_position'])) {
599
+ $args['menu_position'] = (int) $args['menu_position'];
600
+ }
601
+
602
+ $props = [
603
+ 'supports'
604
+ ];
605
+
606
+ foreach ($props as $prop) {
607
+ $value = $this->get_submitted_array($prop);
608
+ if ($value !== null) {
609
+ $args[$prop] = $value;
610
+ }
611
+ }
612
+
613
+ if (empty($args['supports'])) {
614
+ $args['supports'] = false;
615
+ }
616
+
617
+ $custom_supports = $this->get_submitted_text_array('custom_supports');
618
+ if (!empty($custom_supports)) {
619
+ $supports = empty($args['supports']) ? [] : $args['supports'];
620
+ $args['supports'] = array_merge($supports, $custom_supports);
621
+ }
622
+
623
+ $props = [
624
+ 'public',
625
+ 'hierarchical',
626
+ 'exclude_from_search',
627
+ 'publicly_queryable',
628
+ 'show_ui',
629
+ 'show_in_menu',
630
+ 'show_in_nav_menus',
631
+ 'show_in_admin_bar',
632
+ 'show_in_rest',
633
+ 'has_archive',
634
+ 'query_var',
635
+ 'can_export',
636
+ 'delete_with_user',
637
+ 'rewrite'
638
+ ];
639
+
640
+ foreach ($props as $prop) {
641
+ $value = $this->get_submitted_boolean($prop);
642
+ if ($value !== null) {
643
+ $args[$prop] = $value;
644
+ }
645
+ }
646
+
647
+ if (!empty($args['show_in_menu'])) {
648
+ $slug = $this->get_submitted_text('show_in_menu_slug');
649
+ if ($slug !== null) {
650
+ $args['show_in_menu'] = $slug;
651
+ }
652
+ }
653
+
654
+ if (!empty($args['has_archive'])) {
655
+ $slug = $this->get_submitted_text('has_archive_slug');
656
+ if ($slug !== null) {
657
+ if (!$this->is_valid_rewrite_slug($slug)) {
658
+ $this->errorMsg = __('This archive name is not allowed (Use only lowercase letters, numbers, underscores, hyphens and slashes).', 'wpfront-user-role-editor');
659
+ return;
660
+ } else {
661
+ $args['has_archive'] = $slug;
662
+ }
663
+ }
664
+ }
665
+
666
+ if (!empty($args['query_var'])) {
667
+ $slug = $this->get_submitted_text('query_var_slug');
668
+ if ($slug !== null) {
669
+ $args['query_var'] = $slug;
670
+ }
671
+ }
672
+
673
+ if (!empty($args['rewrite'])) {
674
+ $rewrite_array = [];
675
+
676
+ $slug = $this->get_submitted_text('rewrite_slug');
677
+ if (!empty($slug)) {
678
+ if (!$this->is_valid_rewrite_slug($slug)) {
679
+ $this->errorMsg = __('This rewrite slug is not allowed (Use only lowercase letters, numbers, underscores, hyphens and slashes).', 'wpfront-user-role-editor');
680
+ return;
681
+ } else {
682
+ $rewrite_array['slug'] = $slug;
683
+ }
684
+ }
685
+
686
+ $with_front = $this->get_submitted_boolean('rewrite_with_front');
687
+ if (is_bool($with_front)) {
688
+ $rewrite_array['with_front'] = $with_front;
689
+ }
690
+
691
+ $ep_mask = $this->get_submitted_text('rewrite_ep_mask');
692
+ if ($ep_mask !== null) {
693
+ if (!$this->is_valid_ep_mask($ep_mask)) {
694
+ $this->errorMsg = __('This Rewrite EP Mask is not allowed (Use only numbers).', 'wpfront-user-role-editor');
695
+ return;
696
+ }
697
+ $rewrite_array['ep_mask'] = $ep_mask;
698
+ }
699
+
700
+ $feeds = $this->get_submitted_boolean('rewrite_feeds');
701
+ if (is_bool($feeds)) {
702
+ $rewrite_array['feeds'] = $feeds;
703
+ }
704
+
705
+ $pages = $this->get_submitted_boolean('rewrite_pages');
706
+ if (is_bool($pages)) {
707
+ $rewrite_array['pages'] = $pages;
708
+ }
709
+
710
+ if (empty($rewrite_array)) {
711
+ $args['rewrite'] = true;
712
+ } else {
713
+ $args['rewrite'] = $rewrite_array;
714
+ }
715
+ }
716
+
717
+ return $args;
718
+ }
719
+
720
+ private function get_labels_arg() {
721
+ $args = array();
722
+ $args['name'] = $this->get_submitted_text('label');
723
+
724
+ $props = [
725
+ 'singular_name',
726
+ 'add_new',
727
+ 'add_new_item',
728
+ 'edit_item',
729
+ 'new_item',
730
+ 'view_item',
731
+ 'view_items',
732
+ 'search_items',
733
+ 'not_found',
734
+ 'not_found_in_trash',
735
+ 'parent_item_colon',
736
+ 'all_items',
737
+ 'archives',
738
+ 'attributes',
739
+ 'insert_into_item',
740
+ 'uploaded_to_this_item',
741
+ 'featured_image',
742
+ 'set_featured_image',
743
+ 'remove_featured_image',
744
+ 'use_featured_image',
745
+ 'menu_name',
746
+ 'filter_items_list',
747
+ 'items_list_navigation',
748
+ 'items_list',
749
+ 'item_published',
750
+ 'item_published_privately',
751
+ 'item_reverted_to_draft',
752
+ 'item_scheduled',
753
+ 'item_updated',
754
+ 'description'
755
+ ];
756
+
757
+ foreach ($props as $prop) {
758
+ $value = $this->get_submitted_text($prop);
759
+ if ($value !== null) {
760
+ $args[$prop] = $value;
761
+ }
762
+ }
763
+
764
+
765
+ return $args;
766
+ }
767
+
768
+ private function get_post_type_data_from_url() {
769
+ if (empty($_GET['name'])) {
770
+ wp_safe_redirect($this->get_self_url());
771
+ exit;
772
+ }
773
+
774
+ $post_type = $this->get_post_type_data($_GET['name']);
775
+ if (empty($post_type) && empty($_GET['post-type-deleted'])) {
776
+ $this->errorMsg = __('Post type do not exists.', 'wpfront-user-role-editor');
777
+ $this->objView = new WPFront_User_Role_Editor_Post_Type_List_View($this);
778
+ return null;
779
+ }
780
+
781
+ return $post_type;
782
+ }
783
+
784
+ protected function get_submitted_text($name) {
785
+ if (empty($_POST[$name])) {
786
+ return null;
787
+ }
788
+
789
+ $txt = trim($_POST[$name]);
790
+
791
+ if (empty($txt)) {
792
+ return null;
793
+ }
794
+
795
+ return $txt;
796
+ }
797
+
798
+ private function get_submitted_array($name) {
799
+ if (!empty($_POST[$name]) && is_array($_POST[$name])) {
800
+ return $_POST[$name];
801
+ }
802
+
803
+ return null;
804
+ }
805
+
806
+ protected function get_submitted_text_array($name) {
807
+ if (!empty($_POST[$name])) {
808
+ $txt = $_POST[$name];
809
+ $values = explode(',', $txt);
810
+ $result = [];
811
+ foreach ($values as $value) {
812
+ $result[] = trim($value);
813
+ }
814
+
815
+ return $result;
816
+ }
817
+
818
+ return null;
819
+ }
820
+
821
+ protected function get_submitted_boolean($name) {
822
+ if (isset($_POST[$name]) && $_POST[$name] == '') {
823
+ return null;
824
+ }
825
+
826
+ return !empty($_POST[$name]);
827
+ }
828
+
829
+ /**
830
+ * Displays the post type view.
831
+ */
832
+ public function view() {
833
+ if (!parent::view()) {
834
+ return;
835
+ }
836
+
837
+ if (empty($this->objView)) {
838
+ $this->objView = new WPFront_User_Role_Editor_Post_Type_List_View($this);
839
+ }
840
+
841
+ $this->objView->view();
842
+ }
843
+
844
+ public function get_active_list_filter() {
845
+ if (empty($_GET['list']))
846
+ return 'all';
847
+
848
+ $list = $_GET['list'];
849
+
850
+ switch ($list) {
851
+ case 'all':
852
+ case 'builtin':
853
+ case 'other':
854
+ case 'userdefined':
855
+ case 'active':
856
+ case 'inactive':
857
+ break;
858
+ default:
859
+ $list = 'all';
860
+ break;
861
+ }
862
+
863
+ return $list;
864
+ }
865
+
866
+ public function get_list_filter_data() {
867
+ $filter_data = array();
868
+ $built_in = [];
869
+ $other = [];
870
+ $user_defined = [];
871
+ $active = [];
872
+ $inactive = [];
873
+ $post_types = $this->get_all_post_types_data();
874
+ $page = $this->get_self_url();
875
+
876
+ $filter_data['all'] = array(
877
+ 'display' => __('All', 'wpfront-user-role-editor'),
878
+ 'url' => $page . '&list=all',
879
+ 'count' => count($post_types)
880
+ );
881
+
882
+ foreach ($post_types as $entity) {
883
+ if ($entity->source_type === self::SOURCE_TYPE_BUILTIN) {
884
+ $built_in[] = $entity;
885
+ }
886
+ if ($entity->source_type === self::SOURCE_TYPE_OTHER) {
887
+ $other[] = $entity;
888
+ }
889
+
890
+ if ($entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
891
+ $user_defined[] = $entity;
892
+ }
893
+
894
+ if ($entity->status === self::STATUS_ACTIVE) {
895
+ $active[] = $entity;
896
+ }
897
+
898
+ if ($entity->status === self::STATUS_INACTIVE) {
899
+ $inactive[] = $entity;
900
+ }
901
+ }
902
+
903
+ $filter_data['builtin'] = array(
904
+ 'display' => __('Built-In', 'wpfront-user-role-editor'),
905
+ 'url' => $page . '&list=builtin',
906
+ 'count' => count($built_in)
907
+ );
908
+
909
+ $filter_data['other'] = array(
910
+ 'display' => __('Other', 'wpfront-user-role-editor'),
911
+ 'url' => $page . '&list=other',
912
+ 'count' => count($other)
913
+ );
914
+
915
+ $filter_data['userdefined'] = array(
916
+ 'display' => __('User Defined', 'wpfront-user-role-editor'),
917
+ 'url' => $page . '&list=userdefined',
918
+ 'count' => count($user_defined)
919
+ );
920
+
921
+ $filter_data['active'] = array(
922
+ 'display' => __('Active', 'wpfront-user-role-editor'),
923
+ 'url' => $page . '&list=active',
924
+ 'count' => count($active)
925
+ );
926
+
927
+ $filter_data['inactive'] = array(
928
+ 'display' => __('Inactive', 'wpfront-user-role-editor'),
929
+ 'url' => $page . '&list=inactive',
930
+ 'count' => count($inactive)
931
+ );
932
+
933
+ return $filter_data;
934
+ }
935
+
936
+ public function apply_active_list_filter($post_types = null) {
937
+ if ($post_types === null) {
938
+ $post_types = $this->get_all_post_types_data();
939
+ }
940
+
941
+ switch ($this->get_active_list_filter()) {
942
+ case 'all':
943
+ break;
944
+ case 'builtin':
945
+ foreach ($post_types as $key => $entity) {
946
+ if ($entity->source_type === self::SOURCE_TYPE_OTHER || $entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
947
+ unset($post_types[$key]);
948
+ }
949
+ }
950
+
951
+ break;
952
+
953
+ case 'other':
954
+ foreach ($post_types as $key => $entity) {
955
+ if ($entity->source_type === self::SOURCE_TYPE_BUILTIN || $entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
956
+ unset($post_types[$key]);
957
+ }
958
+ }
959
+ break;
960
+ case 'userdefined':
961
+ foreach ($post_types as $key => $entity) {
962
+ if ($entity->source_type === self::SOURCE_TYPE_OTHER || $entity->source_type === self::SOURCE_TYPE_BUILTIN) {
963
+ unset($post_types[$key]);
964
+ }
965
+ }
966
+ break;
967
+ case 'active':
968
+ foreach ($post_types as $key => $entity) {
969
+ if ($entity->status === self::STATUS_INACTIVE) {
970
+ unset($post_types[$key]);
971
+ }
972
+ }
973
+ break;
974
+ case 'inactive':
975
+ foreach ($post_types as $key => $entity) {
976
+ if ($entity->status === self::STATUS_ACTIVE) {
977
+ unset($post_types[$key]);
978
+ }
979
+ }
980
+ break;
981
+ }
982
+
983
+ return $post_types;
984
+ }
985
+
986
+ protected function get_all_entities() {
987
+ if ($this->entities !== null) {
988
+ return $this->entities;
989
+ }
990
+
991
+ $entity = new WPFront_User_Role_Editor_Post_Type_Entity();
992
+ $entities = $entity->get_all();
993
+
994
+ foreach ($entities as $post_type => $entity) {
995
+ if (!is_array($entity->post_type_arg)) { //customized from role add/edit screen.
996
+ $entity->post_type_arg = array();
997
+ $entity->post_type_arg['map_meta_cap'] = true;
998
+ }
999
+
1000
+ if (!empty($entity->capability_type)) {
1001
+ $entity->post_type_arg['capability_type'] = $entity->capability_type;
1002
+ }
1003
+ }
1004
+
1005
+ $this->entities = $this->sanitize_pro_fields($entities);
1006
+
1007
+ return $this->entities;
1008
+ }
1009
+
1010
+ protected function sanitize_pro_fields($entities) {
1011
+ foreach ($entities as $post_type => $entity) {
1012
+ if (isset($entity->post_type_arg['capability_type'])) {
1013
+ unset($entity->post_type_arg['capability_type']);
1014
+ }
1015
+
1016
+ if (isset($entity->post_type_arg['map_meta_cap'])) {
1017
+ unset($entity->post_type_arg['map_meta_cap']);
1018
+ }
1019
+
1020
+ $entity->capability_type = null;
1021
+ }
1022
+
1023
+ return $entities;
1024
+ }
1025
+
1026
+ public function clear_cache() {
1027
+ $this->post_types_cache_clear = true;
1028
+ }
1029
+
1030
+ /**
1031
+ * Returns list of post types.
1032
+ *
1033
+ * @return object[] Associative(post_type => object)
1034
+ */
1035
+ public function get_all_post_types_data() {
1036
+ if (!$this->post_types_cache_clear && !empty($this->post_types_cache)) {
1037
+ return $this->post_types_cache;
1038
+ }
1039
+
1040
+ $has_edit_cap = current_user_can('edit_posttypes');
1041
+ $has_delete_cap = current_user_can('delete_posttypes');
1042
+ $has_clone_cap = current_user_can('create_posttypes');
1043
+
1044
+ $post_types = get_post_types([], 'objects');
1045
+ $exiting = array();
1046
+ foreach ($post_types as $name => $post_type_obj) {
1047
+ if ($post_type_obj->_builtin && !is_post_type_viewable($name)) {
1048
+ continue;
1049
+ }
1050
+
1051
+ $data = new \stdClass();
1052
+ $data->name = $post_type_obj->name;
1053
+ $data->label = $post_type_obj->label;
1054
+ $data->status = self::STATUS_ACTIVE;
1055
+ $data->source_type = $post_type_obj->_builtin ? self::SOURCE_TYPE_BUILTIN : self::SOURCE_TYPE_OTHER;
1056
+ $taxes = get_object_taxonomies($post_type_obj->name);
1057
+ $data->taxonomies = is_array($taxes) ? $taxes : [];
1058
+ $data->post_type_arg = $this->post_type_args[$name];
1059
+ $data->entity = null;
1060
+
1061
+ $exiting[$name] = $data;
1062
+ }
1063
+
1064
+ $entity_all = $this->get_all_entities();
1065
+ $user_edited = [];
1066
+ foreach ($entity_all as $name => $entity) {
1067
+ $data = new \stdClass();
1068
+ $data->name = $entity->name;
1069
+ $data->label = $entity->label;
1070
+ $data->status = $entity->status;
1071
+ if (!isset($exiting[$name])) {
1072
+ if (isset($this->post_types_unregistered[$entity->name])) {
1073
+ $data->source_type = self::SOURCE_TYPE_OTHER;
1074
+ } else {
1075
+ $data->source_type = self::SOURCE_TYPE_USER_DEFINED;
1076
+ }
1077
+ } else {
1078
+ $data->source_type = $exiting[$name]->source_type;
1079
+ }
1080
+
1081
+ if (isset($this->post_type_args[$name])) { //only cap type and map_meta_cap may exist in post_type_arg on customization from role add/edit screen.
1082
+ $entity->post_type_arg = array_merge($this->post_type_args[$name], $entity->post_type_arg);
1083
+ }
1084
+
1085
+ $data->post_type_arg = $entity->post_type_arg;
1086
+
1087
+ $data->taxonomies = $entity->taxonomies;
1088
+ $data->entity = $entity;
1089
+
1090
+ $user_edited[$name] = $data;
1091
+ }
1092
+
1093
+ //reset source types to intial state to take care of registration changing source type.
1094
+ $post_types_merged = array_merge($exiting, $user_edited);
1095
+ foreach ($post_types_merged as $name => $data) {
1096
+ if (isset($this->post_types_cache[$name])) {
1097
+ $data->source_type = $this->post_types_cache[$name]->source_type;
1098
+ }
1099
+ }
1100
+
1101
+ $this->post_types_cache = $post_types_merged;
1102
+
1103
+ foreach ($this->post_types_cache as $name => $data) {
1104
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN) {
1105
+ $data->can_edit = $has_edit_cap && is_post_type_viewable($name);
1106
+ } else {
1107
+ $data->can_edit = $has_edit_cap;
1108
+ }
1109
+ $data->can_delete = $has_delete_cap && $data->source_type === self::SOURCE_TYPE_USER_DEFINED;
1110
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN || $data->source_type === self::SOURCE_TYPE_OTHER) {
1111
+ $data->can_restore = $has_edit_cap && !empty($data->entity);
1112
+ } else {
1113
+ $data->can_restore = false;
1114
+ }
1115
+ if ($data->can_edit && ($data->source_type === self::SOURCE_TYPE_USER_DEFINED || $data->source_type === self::SOURCE_TYPE_OTHER)) {
1116
+ if ($data->status == self::STATUS_ACTIVE) {
1117
+ $data->can_activate = false;
1118
+ $data->can_deactivate = true;
1119
+ } else if ($data->status == self::STATUS_INACTIVE) {
1120
+ $data->can_activate = true;
1121
+ $data->can_deactivate = false;
1122
+ }
1123
+ } else {
1124
+ $data->can_activate = false;
1125
+ $data->can_deactivate = false;
1126
+ }
1127
+ $data->can_clone = $has_clone_cap;
1128
+ }
1129
+
1130
+ return $this->post_types_cache;
1131
+ }
1132
+
1133
+ /**
1134
+ * Returns the post type.
1135
+ *
1136
+ * @return string
1137
+ */
1138
+ public function get_post_type_data($post_type) {
1139
+ $lists = $this->get_all_post_types_data();
1140
+ if (!empty($lists[$post_type])) {
1141
+ return $lists[$post_type];
1142
+ }
1143
+
1144
+ return null;
1145
+ }
1146
+
1147
+ public function search($search) {
1148
+ $post_types = $this->get_all_post_types_data();
1149
+ $post_types = $this->sort_post_types_data($post_types);
1150
+
1151
+ if (empty($search)) {
1152
+ return $post_types;
1153
+ }
1154
+
1155
+ foreach ($post_types as $name => $item) {
1156
+ if (strpos($item->name, $search) !== false) {
1157
+ continue;
1158
+ }
1159
+
1160
+ if (strpos($item->label, $search) !== false) {
1161
+ continue;
1162
+ }
1163
+
1164
+ unset($post_types[$name]);
1165
+ }
1166
+
1167
+ return $post_types;
1168
+ }
1169
+
1170
+ protected function sort_post_types_data($post_types) {
1171
+ $built_in_post_types = array();
1172
+ $other_post_types = array();
1173
+ $user_defined_post_types = array();
1174
+
1175
+ foreach ($post_types as $post_type => $data) {
1176
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN) {
1177
+ $built_in_post_types[$post_type] = $data;
1178
+ continue;
1179
+ }
1180
+
1181
+ if ($data->source_type === self::SOURCE_TYPE_OTHER) {
1182
+ $other_post_types[$post_type] = $data;
1183
+ continue;
1184
+ }
1185
+
1186
+ if ($data->source_type === self::SOURCE_TYPE_USER_DEFINED) {
1187
+ $user_defined_post_types[$post_type] = $data;
1188
+ continue;
1189
+ }
1190
+ }
1191
+
1192
+ ksort($built_in_post_types);
1193
+ ksort($other_post_types);
1194
+ ksort($user_defined_post_types);
1195
+ return array_merge($built_in_post_types, $other_post_types, $user_defined_post_types);
1196
+ }
1197
+
1198
+ protected function is_valid_slug($slug) {
1199
+ if (empty($slug)) {
1200
+ return false;
1201
+ }
1202
+
1203
+ return sanitize_key($slug) === $slug;
1204
+ }
1205
+
1206
+ protected function is_valid_rewrite_slug($slug) {
1207
+ $key = strtolower($slug);
1208
+ $key = preg_replace('/[^a-z0-9_\-\/]/', '', $key);
1209
+
1210
+ return $key === $slug;
1211
+ }
1212
+
1213
+ private function is_valid_ep_mask($ep_mask) {
1214
+ return !preg_match("/[^0-9]/", $ep_mask);
1215
+ }
1216
+
1217
+ /**
1218
+ * Return post type list url.
1219
+ *
1220
+ * @return string
1221
+ */
1222
+ public function get_list_url($key = '') {
1223
+ if (empty($key)) {
1224
+ return $this->get_self_url();
1225
+ }
1226
+
1227
+ return add_query_arg($key, 'true', $this->get_self_url());
1228
+ }
1229
+
1230
+ /**
1231
+ * Returns the add new post type URL.
1232
+ *
1233
+ * @return string
1234
+ */
1235
+ public function get_add_new_url($clone = null) {
1236
+ $p = ['screen' => 'add-new'];
1237
+ if (!empty($clone)) {
1238
+ $p['clone'] = $clone;
1239
+ }
1240
+ return $this->get_self_url($p);
1241
+ }
1242
+
1243
+ /**
1244
+ * Returns the edit post type URL.
1245
+ *
1246
+ * @return string
1247
+ */
1248
+ public function get_edit_url($name) {
1249
+ return $this->get_self_url(['screen' => 'edit', 'name' => $name]);
1250
+ }
1251
+
1252
+ /**
1253
+ * Returns the delete post type URL.
1254
+ *
1255
+ * @return string
1256
+ */
1257
+ public function get_delete_url($name) {
1258
+ if (empty($name)) {
1259
+ return $this->get_self_url(['screen' => 'delete']);
1260
+ }
1261
+
1262
+ return $this->get_self_url(['screen' => 'delete', 'name' => $name]);
1263
+ }
1264
+
1265
+ /**
1266
+ * Returns the activate post type URL.
1267
+ *
1268
+ * @return string
1269
+ */
1270
+ public function get_activate_url($name) {
1271
+ return wp_nonce_url($this->get_self_url(['screen' => 'activate', 'name' => $name]));
1272
+ }
1273
+
1274
+ /**
1275
+ * Returns the deactivate post type URL.
1276
+ *
1277
+ * @return string
1278
+ */
1279
+ public function get_deactivate_url($name) {
1280
+ return wp_nonce_url($this->get_self_url(['screen' => 'deactivate', 'name' => $name]));
1281
+ }
1282
+
1283
+ /**
1284
+ * Returns the clone post type URL.
1285
+ *
1286
+ * @return string
1287
+ */
1288
+ public function get_clone_url($name) {
1289
+ return $this->get_add_new_url($name);
1290
+ }
1291
+
1292
+ public function get_restore_url($name) {
1293
+ if (empty($name)) {
1294
+ return $this->get_self_url(['screen' => 'restore']);
1295
+ }
1296
+
1297
+ return $this->get_self_url(['screen' => 'restore', 'name' => $name]);
1298
+ }
1299
+
1300
+ public function get_user_visible_cpt() {
1301
+ $post_types = get_post_types(array(
1302
+ '_builtin' => false
1303
+ ));
1304
+
1305
+ $cpts = array();
1306
+
1307
+ foreach ($post_types as $name => $value) {
1308
+ $post_type_object = get_post_type_object($name);
1309
+
1310
+ if (!$this->is_cpt_user_visible($post_type_object)) {
1311
+ continue;
1312
+ }
1313
+
1314
+ $cpts[$name] = $post_type_object;
1315
+ }
1316
+
1317
+ return $cpts;
1318
+ }
1319
+
1320
+ protected function is_cpt_user_visible($post_type_object) {
1321
+ if ($post_type_object->_builtin) {
1322
+ return false;
1323
+ }
1324
+
1325
+ return is_post_type_viewable($post_type_object) || $post_type_object->show_ui || $post_type_object->capability_type !== 'post';
1326
+ }
1327
+
1328
+ public function get_cpt_customizable_hint_text($group_obj, $disabled) {
1329
+ $post_type_obj = get_post_type_object($group_obj->key);
1330
+ $post_type = $post_type_obj->capability_type;
1331
+ $post_type_obj = get_post_type_object($post_type);
1332
+
1333
+ $hint = __('Uses "%s" capability.', 'wpfront-user-role-editor');
1334
+ $hint = sprintf($hint, $post_type_obj->label);
1335
+
1336
+ $upgrade_message = sprintf(__('%s to customize capabilities.', 'wpfront-user-role-editor'), '<a href="https://wpfront.com/ureaddedit" target="_blank">' . __('Upgrade to Pro', 'wpfront-user-role-editor') . '</a>');
1337
+ $hint .= ' ' . $upgrade_message;
1338
+
1339
+ return $hint;
1340
+ }
1341
+
1342
+ public function get_customizied_custom_post_types_from_settings() {
1343
+ return array();
1344
+ }
1345
+
1346
+ public function admin_print_scripts() {
1347
+ parent::admin_print_scripts();
1348
+ wp_enqueue_script('jquery-ui-tooltip', null, array('jquery'));
1349
+ wp_enqueue_script('postbox');
1350
+ wp_enqueue_script('wpfront-user-role-editor-post-types', WPFURE::instance()->get_asset_url('js/chosen/chosen.jquery.min.js'), array('jquery'), WPFURE::VERSION);
1351
+ }
1352
+
1353
+ public function admin_print_styles() {
1354
+ parent::admin_print_styles();
1355
+ wp_enqueue_style('wpfront-user-role-editor-post-types', WPFURE::instance()->get_asset_url('css/chosen/chosen.min.css'), array(), WPFURE::VERSION);
1356
+ }
1357
+
1358
+ }
1359
+
1360
+ WPFront_User_Role_Editor_Post_Type::load();
1361
+ }
includes/post-type/custom-caps/class-create-posts-capability.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Controller for WPFront User Role Editor Create Posts Custom Capabilities.
27
+ *
28
+ * @author Jinu Varghese
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Post_Type\Custom_Caps;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ use WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Custom_Capability;
39
+
40
+ if (!class_exists('\WPFront\URE\Post_Type\Custom_Caps\WPFront_User_Role_Editor_Create_Posts_Capability')) {
41
+
42
+ /**
43
+ * Create Posts capability class
44
+ *
45
+ * @author Jinu Varghese
46
+ * @copyright 2014 WPFront.com
47
+ */
48
+ class WPFront_User_Role_Editor_Create_Posts_Capability extends WPFront_User_Role_Editor_Post_Type_Custom_Capability {
49
+
50
+ protected function init($controller) {
51
+
52
+ }
53
+
54
+ /**
55
+ * Returns custom cap prefix.
56
+ */
57
+ protected function cap_prefix() {
58
+ return 'create';
59
+ }
60
+
61
+ /**
62
+ * Returns cap prefix to add before in sort.
63
+ */
64
+ protected function add_before_prefix() {
65
+ return 'edit';
66
+ }
67
+
68
+ /**
69
+ * Returns the cap to check while defining role defaults.
70
+ */
71
+ protected function role_default_value_cap($post_type){
72
+ return 'edit_' . $this->cap_names[$post_type][1];
73
+ }
74
+
75
+ protected function can_merge() {
76
+ return false;
77
+ }
78
+
79
+ }
80
+
81
+ WPFront_User_Role_Editor_Post_Type_Custom_Capability::register('create', new WPFront_User_Role_Editor_Create_Posts_Capability);
82
+ }
83
+
includes/post-type/custom-caps/class-read-others-capability.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Controller for WPFront User Role Editor Read Others Custom Capabilities.
27
+ *
28
+ * @author Jinu Varghese
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Post_Type\Custom_Caps;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ use WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Custom_Capability;
39
+
40
+ if (!class_exists('\WPFront\URE\Post_Type\Custom_Caps\WPFront_User_Role_Editor_Read_Others_Capability')) {
41
+
42
+ /**
43
+ * Read others capability class
44
+ *
45
+ * @author Jinu Varghese
46
+ * @copyright 2014 WPFront.com
47
+ */
48
+ class WPFront_User_Role_Editor_Read_Others_Capability extends WPFront_User_Role_Editor_Post_Type_Custom_Capability {
49
+
50
+ protected function init($controller) {
51
+
52
+ }
53
+
54
+ /**
55
+ * Returns custom cap prefix.
56
+ */
57
+ protected function cap_prefix() {
58
+ return 'read_others';
59
+ }
60
+
61
+ /**
62
+ * Returns cap prefix to add before in sort.
63
+ */
64
+ protected function add_before_prefix() {
65
+ return 'edit_others';
66
+ }
67
+
68
+ /**
69
+ * Returns the cap to check while defining role defaults.
70
+ */
71
+ protected function role_default_value_cap($post_type){
72
+ return 'read';
73
+ }
74
+
75
+ protected function can_merge() {
76
+ return false;
77
+ }
78
+
79
+
80
+ }
81
+
82
+ WPFront_User_Role_Editor_Post_Type_Custom_Capability::register('read_others', new WPFront_User_Role_Editor_Read_Others_Capability());
83
+ }
84
+
includes/post-type/entity-post-type.php ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Entity for WPFront User Role Editor Post Type
27
+ *
28
+ * @author Vaisagh D <vaisaghd@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Post_Type;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ if (!class_exists('WPFront\URE\Login_Redirect\WPFront_User_Role_Editor_Post_Type_Entity')) {
39
+
40
+ /**
41
+ * Post Type Entity
42
+ *
43
+ * @author Vaisagh D <vaisaghd@wpfront.com>
44
+ * @copyright 2014 WPFront.com
45
+ */
46
+ class WPFront_User_Role_Editor_Post_Type_Entity extends \WPFront\URE\WPFront_User_Role_Editor_Entity_Base {
47
+
48
+ /**
49
+ * Primary key.
50
+ *
51
+ * @var int
52
+ */
53
+ public $id;
54
+
55
+ /**
56
+ * Post Type Name.
57
+ *
58
+ * @var text
59
+ */
60
+ public $name;
61
+
62
+ /**
63
+ * Post Type Label.
64
+ *
65
+ * @var string
66
+ */
67
+ public $label;
68
+
69
+ /**
70
+ * Post Type Status.
71
+ *
72
+ * @var int
73
+ */
74
+ public $status;
75
+
76
+ /**
77
+ * Post Type Object.
78
+ *
79
+ * @var \WP_Post_Type
80
+ */
81
+ public $post_type_arg;
82
+
83
+ /**
84
+ * Post Type Taxonomy.
85
+ *
86
+ * @var array
87
+ */
88
+ public $taxonomies;
89
+
90
+ /**
91
+ * Post Type Capability.
92
+ *
93
+ * @var string
94
+ */
95
+ public $capability_type;
96
+
97
+ protected function table_name_suffix() {
98
+ return 'post_type';
99
+ }
100
+
101
+ protected function table_create_sql() {
102
+ $table_name = $this->table_name();
103
+
104
+ global $wpdb;
105
+ $charset_collate = $wpdb->get_charset_collate();
106
+
107
+ $sql = "CREATE TABLE $table_name (\n"
108
+ . "id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n"
109
+ . "name varchar(150) DEFAULT NULL,\n"
110
+ . "label varchar(250) DEFAULT NULL,\n"
111
+ . "status int NOT NULL DEFAULT 1,\n"
112
+ . "post_type_arg text DEFAULT NULL,\n"
113
+ . "taxonomies varchar(1000) NOT NULL DEFAULT '',\n"
114
+ . "capability_type varchar(1000) DEFAULT NULL,\n"
115
+ . "PRIMARY KEY (id),\n"
116
+ . "UNIQUE KEY name (name)\n"
117
+ . ") $charset_collate;";
118
+
119
+ return $sql;
120
+ }
121
+
122
+ /**
123
+ * Adds a new post type.
124
+ *
125
+ * @global \wpdb $wpdb
126
+ * @return boolean Success|Fail
127
+ */
128
+ public function add() {
129
+ global $wpdb;
130
+ $tablename = $this->table_name();
131
+
132
+ if (!is_array($this->taxonomies)) {
133
+ $this->taxonomies = [];
134
+ }
135
+
136
+ $result = $wpdb->insert(
137
+ $tablename,
138
+ array(
139
+ 'name' => $this->name,
140
+ 'label' => $this->label,
141
+ 'status' => $this->status,
142
+ 'post_type_arg' => maybe_serialize($this->post_type_arg),
143
+ 'taxonomies' => implode(',', $this->taxonomies),
144
+ 'capability_type' => maybe_serialize($this->capability_type)
145
+ ),
146
+ array(
147
+ '%s',
148
+ '%s',
149
+ '%d',
150
+ '%s',
151
+ '%s',
152
+ '%s'
153
+ )
154
+ );
155
+
156
+ $this->sync($this->name, $this->status === 1 ? $this->taxonomies : []);
157
+
158
+ $this->cache_flush();
159
+
160
+ if ($result === false) {
161
+ return false;
162
+ } else {
163
+ $this->id = $wpdb->insert_id;
164
+ return true;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Updates an existing post type based on ID.
170
+ *
171
+ * @global \wpdb $wpdb
172
+ * @return boolean Success|Fail
173
+ */
174
+ public function update() {
175
+ global $wpdb;
176
+ $tablename = $this->table_name();
177
+
178
+ $sql = $wpdb->prepare("SELECT id FROM $tablename WHERE name = %s", $this->name);
179
+ $id = $wpdb->get_var($sql);
180
+ if (empty($id)) {
181
+ return $this->add();
182
+ }
183
+ $this->id = $id;
184
+
185
+ if (!is_array($this->taxonomies)) {
186
+ $this->taxonomies = [];
187
+ }
188
+
189
+ $result = $wpdb->update(
190
+ $tablename,
191
+ array(
192
+ 'name' => $this->name,
193
+ 'label' => $this->label,
194
+ 'status' => $this->status,
195
+ 'post_type_arg' => maybe_serialize($this->post_type_arg),
196
+ 'taxonomies' => implode(',', $this->taxonomies),
197
+ 'capability_type' => maybe_serialize($this->capability_type)
198
+ ),
199
+ array(
200
+ 'id' => $this->id
201
+ ),
202
+ array(
203
+ '%s',
204
+ '%s',
205
+ '%d',
206
+ '%s',
207
+ '%s',
208
+ '%s'
209
+ ),
210
+ array(
211
+ '%d'
212
+ )
213
+ );
214
+
215
+ $this->sync($this->name, $this->status === 1 ? $this->taxonomies : []);
216
+
217
+ $this->cache_flush();
218
+
219
+ return $result !== false;
220
+ }
221
+
222
+ /**
223
+ * Deletes a post type.
224
+ *
225
+ * @param string $role
226
+ * @return bool
227
+ */
228
+ public function delete($action = 'delete') {
229
+ global $wpdb;
230
+ $tablename = $this->table_name();
231
+
232
+ $sql = "DELETE FROM $tablename WHERE id = %d";
233
+ $sql = $wpdb->prepare($sql, $this->id);
234
+ $result = $wpdb->query($sql);
235
+
236
+ $this->sync($this->name, $action === 'delete' ? [] : $this->taxonomies);
237
+
238
+ $this->cache_flush();
239
+
240
+ return !empty($result);
241
+ }
242
+
243
+ /**
244
+ * Returns all post types.
245
+ *
246
+ * @param string $role
247
+ * @return bool
248
+ */
249
+ public function get_all() {
250
+ $data = $this->cache_get('all_post_types');
251
+ if ($data !== false) {
252
+ return $data;
253
+ }
254
+
255
+ $table_name = $this->table_name();
256
+
257
+ $sql = "SELECT id, name, label, status, post_type_arg, taxonomies, capability_type "
258
+ . "FROM $table_name ";
259
+
260
+ global $wpdb;
261
+ $results = $wpdb->get_results($sql);
262
+
263
+ $data = array();
264
+ foreach ($results as $value) {
265
+ $entity = new WPFront_User_Role_Editor_Post_Type_Entity();
266
+
267
+ $entity->id = intval($value->id);
268
+ $entity->name = $value->name;
269
+ $entity->label = $value->label;
270
+ $entity->status = intval($value->status);
271
+ $entity->post_type_arg = maybe_unserialize($value->post_type_arg);
272
+ $entity->taxonomies = empty($value->taxonomies) ? [] : explode(',', $value->taxonomies);
273
+ $entity->capability_type = maybe_unserialize($value->capability_type);
274
+
275
+ $data[$entity->name] = $entity;
276
+ }
277
+
278
+ $this->cache_set('all_post_types', $data);
279
+
280
+ return $data;
281
+ }
282
+
283
+ /**
284
+ * Activates/Deactivates a post type.
285
+ *
286
+ * @return bool
287
+ */
288
+ public function update_status($status) {
289
+ global $wpdb;
290
+ $tablename = $this->table_name();
291
+
292
+ $sql = "UPDATE $tablename SET status=%d WHERE id=%d";
293
+ $sql = $wpdb->prepare($sql, $status, $this->id);
294
+ $result = $wpdb->query($sql);
295
+
296
+ $this->sync($this->name, $status === 1 ? $this->taxonomies : []);
297
+
298
+ $this->cache_flush();
299
+
300
+ return !empty($result);
301
+ }
302
+
303
+ public function sync_taxonomies($taxonomy, $post_types) {
304
+ $tablename = $this->table_name();
305
+
306
+ $sql = "SELECT id, name, taxonomies FROM $tablename";
307
+ global $wpdb;
308
+ $results = $wpdb->get_results($sql);
309
+
310
+ foreach ($results as $obj) {
311
+ $taxonomies = empty($obj->taxonomies) ? [] : explode(',', $obj->taxonomies);
312
+ $update = false;
313
+
314
+ if (in_array($obj->name, $post_types)) { //post_type is present in the list passed, add taxonomy if not exists.
315
+ if (!in_array($taxonomy, $taxonomies)) { //taxonomy do not exists in data, add it.
316
+ $taxonomies[] = $taxonomy;
317
+ $update = true;
318
+ }
319
+ } else { //post type not present in the list passed, so remove if taxonomy exists.
320
+ if (in_array($taxonomy, $taxonomies)) { //taxonomy exists in data, remove it.
321
+ $taxonomies = array_diff($taxonomies, [$taxonomy]);
322
+ $update = true;
323
+ }
324
+ }
325
+
326
+ if ($update) {
327
+ $wpdb->update(
328
+ $tablename,
329
+ array(
330
+ 'taxonomies' => implode(',', $taxonomies)
331
+ ),
332
+ array(
333
+ 'id' => $obj->id
334
+ ),
335
+ array(
336
+ '%s'
337
+ ),
338
+ array(
339
+ '%d'
340
+ )
341
+ );
342
+ }
343
+ }
344
+
345
+ $this->cache_flush();
346
+ }
347
+
348
+ protected function sync($post_type, $taxonomies) {
349
+ $entity = new \WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies_Entity();
350
+ $entity->sync_post_types($post_type, $taxonomies);
351
+ }
352
+
353
+ protected function cache_flush() {
354
+ $this->cache_delete('all_post_types');
355
+
356
+ $options = \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance();
357
+ $options->set_option(WPFront_User_Role_Editor_Post_Type::DATA_EDITED_KEY, true);
358
+ }
359
+
360
+ }
361
+
362
+ (new WPFront_User_Role_Editor_Post_Type_Entity())->register();
363
+ }
includes/post-type/template-add-edit.php ADDED
@@ -0,0 +1,1249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Post Type Add Edit
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Post_Type;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
38
+
39
+ if (!class_exists('WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Add_Edit_View')) {
40
+
41
+ class WPFront_User_Role_Editor_Post_Type_Add_Edit_View {
42
+
43
+ /**
44
+ *
45
+ * @var WPFront_User_Role_Editor_Post_Type
46
+ */
47
+ private $controller;
48
+ private $post_type_data;
49
+ private $post_type_obj;
50
+ private $clone_from;
51
+
52
+ public function __construct($controller, $data = null, $post_type_obj = null, $clone = null) {
53
+ $this->controller = $controller;
54
+ $this->post_type_data = $data;
55
+ $this->post_type_obj = $post_type_obj;
56
+ $this->clone_from = $clone;
57
+ }
58
+
59
+ public function view() {
60
+ ?>
61
+ <div class="wrap post-type-add-edit">
62
+ <?php $this->title(); ?>
63
+ <?php $this->display_notices(); ?>
64
+ <?php
65
+ if (empty($this->post_type_data)) {
66
+ $action = $this->controller->get_add_new_url();
67
+ } else {
68
+ $action = $this->controller->get_edit_url($this->post_type_data->name);
69
+ }
70
+ ?>
71
+ <form method="post" class="validate" action="<?php echo $action; ?>">
72
+ <?php $this->create_meta_boxes(); ?>
73
+ <div id="poststuff">
74
+ <div id="post-body" class="metabox-holder columns-2" style="display:flow-root">
75
+ <div id="post-body-content" style="position:relative">
76
+ <?php do_meta_boxes($this->controller->get_menu_slug(), 'normal', null); ?>
77
+ </div>
78
+ <div id="postbox-container-1" class="postbox-container" style="position: sticky; top: 40px;">
79
+ <?php do_meta_boxes($this->controller->get_menu_slug(), 'side', null); ?>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ <?php wp_nonce_field('add-edit-post-type'); ?>
84
+ <?php submit_button(null, 'primary', 'submit2', false); ?>
85
+ </form>
86
+ </div>
87
+ <?php $this->scripts(); ?>
88
+ <?php
89
+ }
90
+
91
+ public function title() {
92
+ if (empty($this->post_type_data)) {
93
+ ?>
94
+ <h2>
95
+ <?php echo __('Add New Post Type', 'wpfront-user-role-editor'); ?>
96
+ </h2>
97
+ <?php
98
+ } else {
99
+ ?>
100
+ <h2>
101
+ <?php echo __('Edit Post Type', 'wpfront-user-role-editor'); ?>
102
+ </h2>
103
+ <?php
104
+ }
105
+ }
106
+
107
+ protected function display_notices() {
108
+ if (!empty($this->controller->errorMsg)) {
109
+ Utils::notice_error($this->controller->errorMsg);
110
+ }
111
+
112
+ if (!empty($_GET['post-type-added'])) {
113
+ Utils::notice_updated(__('Post type added successfully.', 'wpfront-user-role-editor'));
114
+ } elseif (!empty($_GET['post-type-updated'])) {
115
+ Utils::notice_updated(__('Post type updated successfully.', 'wpfront-user-role-editor'));
116
+ }
117
+ }
118
+
119
+ protected function get_meta_box_groups() {
120
+ return [
121
+ (object) [
122
+ 'group_name' => 'basic_settings',
123
+ 'title' => __('Basic Settings', 'wpfront-user-role-editor'),
124
+ 'render' => 'postbox_render_basic_settings'
125
+ ],
126
+ (object) [
127
+ 'group_name' => 'labels',
128
+ 'title' => __('Additional Labels', 'wpfront-user-role-editor'),
129
+ 'render' => 'postbox_render_labels'
130
+ ],
131
+ (object) [
132
+ 'group_name' => 'advanced_settings',
133
+ 'title' => __('Advanced Settings', 'wpfront-user-role-editor'),
134
+ 'render' => 'postbox_render_advanced_settings'
135
+ ]
136
+ ];
137
+ }
138
+
139
+ protected function create_meta_boxes() {
140
+ $groups = $this->get_meta_box_groups();
141
+
142
+ foreach ($groups as $group) {
143
+ add_meta_box("postbox-{$group->group_name}", $group->title, array($this, $group->render), $this->controller->get_menu_slug(), 'normal', 'default', $group);
144
+ }
145
+
146
+ add_meta_box("postbox-side", __('Actions', 'wpfront-user-role-editor'), array($this, 'action_buttons'), $this->controller->get_menu_slug(), 'side', 'default', $group);
147
+
148
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
149
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
150
+ }
151
+
152
+ public function action_buttons() {
153
+ submit_button();
154
+ ?>
155
+ <p>
156
+ <a class="auto-populate-labels button button-secondary"><?php echo __('Auto Populate Labels', 'wpfront-user-role-editor'); ?></a>
157
+ </p>
158
+ <p>
159
+ <a class="clear-labels button button-secondary"><?php echo __('Clear Labels', 'wpfront-user-role-editor'); ?></a>
160
+ </p>
161
+ <?php
162
+ }
163
+
164
+ public function postbox_render_basic_settings() {
165
+ ?>
166
+ <table class="form-table">
167
+ <tbody>
168
+ <?php
169
+ $this->textbox_basic_settings(__('Name', 'wpfront-user-role-editor'), 'name');
170
+ $this->textbox_basic_settings(__('Plural Label', 'wpfront-user-role-editor'), 'label');
171
+ $this->textbox_basic_settings(__('Singular Label', 'wpfront-user-role-editor'), 'singular_name');
172
+ $this->dropdown_basic_settings(
173
+ 'Status',
174
+ 'status',
175
+ true
176
+ );
177
+ ?>
178
+ </tbody>
179
+ </table>
180
+ <?php
181
+ }
182
+
183
+ public function postbox_render_labels() {
184
+ ?>
185
+ <table class="form-table">
186
+ <tbody>
187
+ <?php
188
+ $this->textbox_additional_labels(
189
+ __('Menu Name Label', 'wpfront-user-role-editor'),
190
+ 'menu_name',
191
+ __('Label for the menu name. Default is the same as plural label. Leave empty to use default value.', 'wpfront-user-role-editor'),
192
+ '%S0'
193
+ );
194
+ $this->textbox_additional_labels(
195
+ __('Add New Label', 'wpfront-user-role-editor'),
196
+ 'add_new',
197
+ __('Default is Add New for both non-hierarchical (like posts) and hierarchical (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
198
+ __('Add New', 'wpfront-user-role-editor')
199
+ );
200
+ ?>
201
+ <?php
202
+ $this->textbox_additional_labels(
203
+ __('Add New Item Label', 'wpfront-user-role-editor'),
204
+ 'add_new_item',
205
+ __('Label for adding a new singular item. Default is Add New Post for non-hierarchical types (like posts) and Add New Page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
206
+ __('Add New %S1', 'wpfront-user-role-editor')
207
+ );
208
+ ?>
209
+ <?php
210
+ $this->textbox_additional_labels(
211
+ __('Edit Item Label', 'wpfront-user-role-editor'),
212
+ 'edit_item',
213
+ __('Label for editing a new singular item. Default is Edit Post for non-hierarchical types (like posts) and Edit Page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
214
+ __('Edit %S1', 'wpfront-user-role-editor')
215
+ );
216
+ ?>
217
+ <?php
218
+ $this->textbox_additional_labels(
219
+ __('New Item Label', 'wpfront-user-role-editor'),
220
+ 'new_item',
221
+ __('Label for the new item page title. Default is New Post for non-hierarchical types (like posts) and New Page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
222
+ __('New %S1', 'wpfront-user-role-editor')
223
+ );
224
+ ?>
225
+ <?php
226
+ $this->textbox_additional_labels(
227
+ __('View Item Label', 'wpfront-user-role-editor'),
228
+ 'view_item',
229
+ __('Label for viewing a singular item. Default is View Post for non-hierarchical types (like posts) and View Page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
230
+ __('View %S1', 'wpfront-user-role-editor')
231
+ );
232
+ ?>
233
+ <?php
234
+ $this->textbox_additional_labels(
235
+ __('View Items Label', 'wpfront-user-role-editor'),
236
+ 'view_items',
237
+ __('Label for viewing post type archives. Default is View Posts for non-hierarchical types (like posts) and View Pages for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
238
+ __('View %S0', 'wpfront-user-role-editor')
239
+ );
240
+ ?>
241
+ <?php
242
+ $this->textbox_additional_labels(
243
+ __('Search Items Label', 'wpfront-user-role-editor'),
244
+ 'search_items',
245
+ __('Label for searching plural items. Default is Search Posts for non-hierarchical types (like posts) and Search Pages for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
246
+ __('Search %S0', 'wpfront-user-role-editor')
247
+ );
248
+ ?>
249
+ <?php
250
+ $this->textbox_additional_labels(
251
+ __('Not Found Label', 'wpfront-user-role-editor'),
252
+ 'not_found',
253
+ __('Label used when no items are found. Default is No posts found for non-hierarchical types (like posts) and No pages found for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
254
+ __('No %s0 found.', 'wpfront-user-role-editor')
255
+ );
256
+ ?>
257
+ <?php
258
+ $this->textbox_additional_labels(
259
+ __('Not Found in Trash Label', 'wpfront-user-role-editor'),
260
+ 'not_found_in_trash',
261
+ __('Label used when no items are found in the trash. Default is No posts found in trash for non-hierarchical types (like posts) and No pages found in trash for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
262
+ __('No %s0 found in Trash.', 'wpfront-user-role-editor')
263
+ );
264
+ ?>
265
+ <?php
266
+ $this->textbox_additional_labels(
267
+ __('Parent Item Colon Label', 'wpfront-user-role-editor'),
268
+ 'parent_item_colon',
269
+ __('Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is Parent Page:. Leave empty to use default value.', 'wpfront-user-role-editor'),
270
+ __('Parent %S1:', 'wpfront-user-role-editor')
271
+ );
272
+ ?>
273
+ <?php
274
+ $this->textbox_additional_labels(
275
+ __('All Items Label', 'wpfront-user-role-editor'),
276
+ 'all_items',
277
+ __('Label to signify all items in a submenu link. Default is All posts for non-hierarchical types (like posts) and All pages for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
278
+ __('%S0', 'wpfront-user-role-editor')
279
+ );
280
+ ?>
281
+ <?php
282
+ $this->textbox_additional_labels(
283
+ __('Archives Label', 'wpfront-user-role-editor'),
284
+ 'archives',
285
+ __('Label for archives in nav menus. Default is Post Archives for non-hierarchical types (like posts) and Page Archives for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
286
+ __('%S0', 'wpfront-user-role-editor')
287
+ );
288
+ ?>
289
+ <?php
290
+ $this->textbox_additional_labels(
291
+ __('Insert into item Label', 'wpfront-user-role-editor'),
292
+ 'insert_into_item',
293
+ __(' Label for the media frame button. Default is Insert into post for non-hierarchical types (like posts) and Insert into page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
294
+ __('Insert into %s1', 'wpfront-user-role-editor')
295
+ );
296
+ ?>
297
+ <?php
298
+ $this->textbox_additional_labels(
299
+ __('Uploaded to this item Label', 'wpfront-user-role-editor'),
300
+ 'uploaded_to_this_item',
301
+ __(' Label for the media frame filter. Default is Uploaded to this post for non-hierarchical types (like posts) and Uploaded to this page for hierarchical types (like pages). Leave empty to use default value.', 'wpfront-user-role-editor'),
302
+ __('Uploaded to this %s1', 'wpfront-user-role-editor')
303
+ );
304
+ ?>
305
+ <?php
306
+ $this->textbox_additional_labels(
307
+ __('Featured Image Label', 'wpfront-user-role-editor'),
308
+ 'featured_image',
309
+ __('Label for the featured image meta box title. Default is Featured image. Leave empty to use default value.', 'wpfront-user-role-editor'),
310
+ __('Featured image', 'wpfront-user-role-editor')
311
+ );
312
+ ?>
313
+ <?php
314
+ $this->textbox_additional_labels(
315
+ __('Set Featured Image Label', 'wpfront-user-role-editor'),
316
+ 'set_featured_image',
317
+ __('Label for setting the featured image. Default is Set featured image. Leave empty to use default value.', 'wpfront-user-role-editor'),
318
+ __('Set featured image', 'wpfront-user-role-editor')
319
+ );
320
+ ?>
321
+ <?php
322
+ $this->textbox_additional_labels(
323
+ __('Remove Featured Image Label', 'wpfront-user-role-editor'),
324
+ 'remove_featured_image',
325
+ __('Label for removing the featured image. Default is Remove featured image. Leave empty to use default value.', 'wpfront-user-role-editor'),
326
+ __('Remove featured image', 'wpfront-user-role-editor')
327
+ );
328
+ ?>
329
+ <?php
330
+ $this->textbox_additional_labels(
331
+ __('Use Featured Image Label', 'wpfront-user-role-editor'),
332
+ 'use_featured_image',
333
+ __('Label in the media frame for using a featured image. Default is Use as featured image. Leave empty to use default value.', 'wpfront-user-role-editor'),
334
+ __('Use as featured image', 'wpfront-user-role-editor')
335
+ );
336
+ ?>
337
+ <?php
338
+ $this->textbox_additional_labels(
339
+ __('Filter Items List Label', 'wpfront-user-role-editor'),
340
+ 'filter_items_list',
341
+ __('Label for the table views hidden heading. Default is Filter posts list for non-hierarchical types (like posts) and Filter pages list for hierarchical types (like pages).', 'wpfront-user-role-editor'),
342
+ __('Filter %s0 list', 'wpfront-user-role-editor')
343
+ );
344
+ ?>
345
+ <?php
346
+ $this->textbox_additional_labels(
347
+ __('Item List Navigation Label', 'wpfront-user-role-editor'),
348
+ 'items_list_navigation',
349
+ __('Label for the table pagination hidden heading. Default is Posts lists navigation for non-hierarchical types (like posts) and Pages lists navigation for hierarchical types (like pages).', 'wpfront-user-role-editor'),
350
+ __('%S0 list navigation', 'wpfront-user-role-editor')
351
+ );
352
+ ?>
353
+ <?php
354
+ $this->textbox_additional_labels(
355
+ __('Item List Label', 'wpfront-user-role-editor'),
356
+ 'items_list',
357
+ __('Label for the table hidden heading. Default is Posts list for non-hierarchical types (like posts) and Pages list for hierarchical types (like pages).', 'wpfront-user-role-editor'),
358
+ __('%S0 list', 'wpfront-user-role-editor')
359
+ );
360
+ ?>
361
+ <?php
362
+ $this->textbox_additional_labels(
363
+ __('Item Published Label', 'wpfront-user-role-editor'),
364
+ 'item_published',
365
+ __('Label used when an item is published. Default is Post publsihed for non-hierarchical types (like posts) and Page published for hierarchical types (like pages).', 'wpfront-user-role-editor'),
366
+ __('%S1 published.', 'wpfront-user-role-editor')
367
+ );
368
+ ?>
369
+ <?php
370
+ $this->textbox_additional_labels(
371
+ __('Item Published Privately Label', 'wpfront-user-role-editor'),
372
+ 'item_published_privately',
373
+ __('Label used when an item is published private visibility. Default is Post publsihed privately for non-hierarchical types (like posts) and Page published privately for hierarchical types (like pages).', 'wpfront-user-role-editor'),
374
+ __('%S1 published privately.', 'wpfront-user-role-editor')
375
+ );
376
+ ?>
377
+ <?php
378
+ $this->textbox_additional_labels(
379
+ __('Item Reverted to Draft Label', 'wpfront-user-role-editor'),
380
+ 'item_reverted_to_draft',
381
+ __('Label used when an item is switched to a draft. Default is Post reverted to draft for non-hierarchical types (like posts) and Page reverted to draft for hierarchical types (like pages).', 'wpfront-user-role-editor'),
382
+ __('%S1 reverted to draft.', 'wpfront-user-role-editor')
383
+ );
384
+ ?>
385
+ <?php
386
+ $this->textbox_additional_labels(
387
+ __('Item Scheduled Label', 'wpfront-user-role-editor'),
388
+ 'item_scheduled',
389
+ __('Label used when an item is scheduled for publishing. Default is Post scheduled for non-hierarchical types (like posts) and Page scheduled for hierarchical types (like pages).', 'wpfront-user-role-editor'),
390
+ __('%S1 scheduled.', 'wpfront-user-role-editor')
391
+ );
392
+ ?>
393
+ <?php
394
+ $this->textbox_additional_labels(
395
+ __('Item Updated', 'wpfront-user-role-editor'),
396
+ 'item_updated',
397
+ __('Label used when an item is updated. Default is Post updated for non-hierarchical types (like posts) and Page updated for hierarchical types (like pages).', 'wpfront-user-role-editor'),
398
+ __('%S1 updated.', 'wpfront-user-role-editor')
399
+ );
400
+ ?>
401
+ <?php
402
+ $this->textbox_additional_labels(
403
+ __('Description', 'wpfront-user-role-editor'),
404
+ 'description',
405
+ __('A short descriptive summary of what the post type is.', 'wpfront-user-role-editor')
406
+ );
407
+ ?>
408
+ </tbody>
409
+ </table>
410
+ <?php
411
+ }
412
+
413
+ public function postbox_render_advanced_settings() {
414
+ ?>
415
+ <table class="form-table">
416
+ <tbody>
417
+ <?php
418
+ $this->dropdown_advanced_settings_boolean(
419
+ __('Public', 'wpfront-user-role-editor'),
420
+ 'public',
421
+ __('Whether a post type is intended for use publicly either via the admin interface or by front-end users. Default value is false.', 'wpfront-user-role-editor'),
422
+ true
423
+ );
424
+ $this->dropdown_advanced_settings_boolean(
425
+ __('Hierarchical', 'wpfront-user-role-editor'),
426
+ 'hierarchical',
427
+ __('Whether the post type is hierarchical (e.g. page). Default is false.', 'wpfront-user-role-editor')
428
+ );
429
+ $this->dropdown_advanced_settings_boolean(
430
+ __('Exclude From Search', 'wpfront-user-role-editor'),
431
+ 'exclude_from_search',
432
+ __('Whether to exclude posts with this post type from front end search results. Default is the opposite value of <b>"Public"</b>.', 'wpfront-user-role-editor')
433
+ );
434
+ $this->dropdown_advanced_settings_boolean(
435
+ __('Publicaly Queryable', 'wpfront-user-role-editor'),
436
+ 'publicly_queryable',
437
+ __('Whether queries can be performed on the front end for the post type as part of parse_request(). Default is inherited from <b>"Public"</b>.', 'wpfront-user-role-editor'),
438
+ true
439
+ );
440
+ $this->dropdown_advanced_settings_boolean(
441
+ __('Show UI', 'wpfront-user-role-editor'),
442
+ 'show_ui',
443
+ __('Whether to generate and allow a UI for managing this post type in the admin. Default is value of <b>"Public"</b>.', 'wpfront-user-role-editor'),
444
+ true
445
+ );
446
+ $this->dropdown_advanced_settings_boolean(
447
+ __('Show in Menu', 'wpfront-user-role-editor'),
448
+ 'show_in_menu',
449
+ __('Where to show the post type in the admin menu. If true, the post type is shown in its own top level menu. If false, no menu is shown. Default is value of <b>"Show UI"</b>.', 'wpfront-user-role-editor'),
450
+ true
451
+ );
452
+ $this->dropdown_advanced_settings_boolean(
453
+ __('Show in Nav Menu', 'wpfront-user-role-editor'),
454
+ 'show_in_nav_menus',
455
+ __('Makes this post type available for selection in navigation menus. Default is value of <b>"Public"</b>.', 'wpfront-user-role-editor')
456
+ );
457
+ $this->dropdown_advanced_settings_boolean(
458
+ __('Show in Admin Bar', 'wpfront-user-role-editor'),
459
+ 'show_in_admin_bar',
460
+ __('Makes this post type available via the admin bar. Default is value of <b>"Show in Menu"</b>.', 'wpfront-user-role-editor')
461
+ );
462
+ $this->dropdown_advanced_settings_boolean(
463
+ __('Show in REST', 'wpfront-user-role-editor'),
464
+ 'show_in_rest',
465
+ __('Whether to include the post type in the REST API. Set this to true for the post type to be available in the block editor.', 'wpfront-user-role-editor'),
466
+ true
467
+ );
468
+
469
+ $this->textbox_advanced_settings(
470
+ __('REST Base', 'wpfront-user-role-editor'),
471
+ 'rest_base',
472
+ __('To change the base url of REST API route. Default is <b>"Name"</b>.', 'wpfront-user-role-editor')
473
+ );
474
+ $this->textbox_advanced_settings(
475
+ __('REST Controller Class', 'wpfront-user-role-editor'),
476
+ 'rest_controller_class',
477
+ __('REST API Controller class name. Default is WP_REST_Posts_Controller', 'wpfront-user-role-editor')
478
+ );
479
+ $this->dropdown_advanced_settings_boolean(
480
+ __('Has Archive', 'wpfront-user-role-editor'),
481
+ 'has_archive',
482
+ __('Whether there should be post type archives, or if a string, the archive slug to use. Will generate the proper rewrite rules if <b>"Rewrite"</b> is enabled. Default false.', 'wpfront-user-role-editor'),
483
+ true
484
+ );
485
+ $this->textbox_advanced_settings(
486
+ __('Menu Position', 'wpfront-user-role-editor'),
487
+ 'menu_position',
488
+ __('The position in the menu order the post type should appear. To work, <b>"show_in_menu"</b> must be true. Default is null.', 'wpfront-user-role-editor')
489
+ );
490
+ $this->textbox_advanced_settings(
491
+ __('Menu Icon', 'wpfront-user-role-editor'),
492
+ 'menu_icon',
493
+ __('The url to the icon to be used for this menu. Defaults to use the posts icon.', 'wpfront-user-role-editor')
494
+ );
495
+ $this->multilist_advanced_settings(
496
+ __('Supports', 'wpfront-user-role-editor'),
497
+ 'supports',
498
+ __('Core feature(s) the post type supports. Serves as an alias for calling add_post_type_support() directly.', 'wpfront-user-role-editor')
499
+ );
500
+ $this->textbox_advanced_settings(
501
+ __('Custom Supports', 'wpfront-user-role-editor'),
502
+ 'custom_supports',
503
+ __('Core feature(s) the post type supports. Serves as an alias for calling add_post_type_support() directly.', 'wpfront-user-role-editor')
504
+ );
505
+ $this->dropdown_advanced_settings_boolean(
506
+ __('Can Export', 'wpfront-user-role-editor'),
507
+ 'can_export',
508
+ __('Whether to allow this post type to be exported. Default true.', 'wpfront-user-role-editor')
509
+ );
510
+ $this->dropdown_advanced_settings_boolean(
511
+ __('Query Var', 'wpfront-user-role-editor'),
512
+ 'query_var',
513
+ __('Sets the query_var key for this post type. Defaults to <b>"Name"</b> key. If false, a post type cannot be loaded at ?{query_var}={post_slug}. If specified as a string, the query ?{query_var_string}={post_slug} will be valid.', 'wpfront-user-role-editor')
514
+ );
515
+ $this->dropdown_advanced_settings_boolean(
516
+ __('Delete with User', 'wpfront-user-role-editor'),
517
+ 'delete_with_user',
518
+ __('Whether to delete posts of this type when deleting a user. If true, posts of this type belonging to the user will be moved to Trash when the user is deleted. If false, posts of this type belonging to the user will not be trashed or deleted. If not set (the default), posts are trashed if post type supports the author feature. Otherwise posts are not trashed or deleted. Default is null.', 'wpfront-user-role-editor')
519
+ );
520
+ $this->multilist_advanced_settings(
521
+ __('Taxonomies', 'wpfront-user-role-editor'),
522
+ 'taxonomies',
523
+ __('An array of taxonomy identifiers that will be registered for the post type.', 'wpfront-user-role-editor')
524
+ );
525
+ $this->rewrite_settings();
526
+ ?>
527
+ </tbody>
528
+ </table>
529
+ <?php
530
+ }
531
+
532
+ protected function textbox_basic_settings($label, $name) {
533
+ $value = $this->get_property_value($name);
534
+ $attr = 'maxlength="20" ';
535
+ if ($name === 'name') {
536
+ if (!empty($this->post_type_data)) {
537
+ $value = $this->post_type_data->name;
538
+ $attr = 'disabled="true"';
539
+ }
540
+ } elseif ($name === 'singular_name') {
541
+ $value = $this->get_labels_value('singular_name');
542
+ }
543
+
544
+ $this->textbox_row($label, $name, $value, (object) ['required' => true, 'attr' => $attr]);
545
+ }
546
+
547
+ protected function dropdown_basic_settings($label, $name, $default_value = '', $arg_value = null, $current_property_value = null) {
548
+ $options = [(object) ['label' => __('Active', 'wpfront-user-role-editor'), 'value' => true], (object) ['label' => __('Inactive', 'wpfront-user-role-editor'), 'value' => false]];
549
+ $attr = '';
550
+ if ($arg_value === null) {
551
+ $arg_value = $this->get_property_value($name, $default_value);
552
+ }
553
+
554
+ if ($arg_value === 1) {
555
+ $arg_value = true;
556
+ } elseif ($arg_value === 0) {
557
+ $arg_value = false;
558
+ }
559
+
560
+ if ($current_property_value === true) {
561
+ $current_property_value = __('Activate', 'wpfront-user-role-editor');
562
+ } elseif ($current_property_value === false) {
563
+ $current_property_value = __('Deactivate', 'wpfront-user-role-editor');
564
+ }
565
+
566
+ if (isset($this->post_type_data->source_type) && $this->post_type_data->source_type === $this->controller::SOURCE_TYPE_BUILTIN) {
567
+ $attr = 'disabled="true"';
568
+ }
569
+
570
+ $this->dropdown_row($label, $name, $options, $arg_value, (object) ['attr' => $attr]);
571
+ }
572
+
573
+ protected function textbox_additional_labels($label, $name, $help, $auto_format = '') {
574
+ $this->textbox_row($label, $name, $this->get_labels_value($name), (object) ['help' => $help, 'help_current_value' => $this->get_current_labels_value($name), 'auto_format' => $auto_format]);
575
+ }
576
+
577
+ protected function dropdown_advanced_settings_boolean($label, $name, $help, $default_value = '', $exclude_default = false, $arg_value = null, $current_property_value = null) {
578
+ $options = [(object) ['label' => __('True', 'wpfront-user-role-editor'), 'value' => true], (object) ['label' => __('False', 'wpfront-user-role-editor'), 'value' => false]];
579
+ if (!$exclude_default) {
580
+ array_unshift($options, (object) ['label' => __('Default', 'wpfront-user-role-editor'), 'value' => '']);
581
+ }
582
+
583
+ if ($name === 'map_meta_cap') {
584
+ $customized = $this->controller->get_customizied_custom_post_types_from_settings();
585
+ if (!empty($customized)) {
586
+ $value = $this->get_property_value('name');
587
+ if (in_array($value, $customized)) {
588
+ $arg_value = true;
589
+ } else {
590
+ $arg_value = null;
591
+ }
592
+ }
593
+ }
594
+
595
+ if ($arg_value === null) {
596
+ $arg_value = $this->get_property_value($name, $default_value);
597
+ }
598
+
599
+ if ($current_property_value === null) {
600
+ $current_property_value = $this->get_current_property_value($name);
601
+ }
602
+
603
+ if ($current_property_value === true) {
604
+ $current_property_value = __('True', 'wpfront-user-role-editor');
605
+ } elseif ($current_property_value === false) {
606
+ $current_property_value = __('False', 'wpfront-user-role-editor');
607
+ }
608
+
609
+ $obj = ['help' => $help, 'help_current_value' => $current_property_value];
610
+
611
+
612
+ //On POST with a validation error $arg_value will be one of empty string, 1 or 0
613
+ if ($arg_value === '1') {
614
+ $arg_value = true;
615
+ } elseif ($arg_value === '0') {
616
+ $arg_value = false;
617
+ }
618
+
619
+ $has_depends = null;
620
+ switch ($name) {
621
+ case 'has_archive':
622
+ case 'show_in_menu':
623
+ case 'query_var':
624
+ $has_depends = $name . '_slug';
625
+ break;
626
+
627
+ default:
628
+ break;
629
+ }
630
+
631
+ if (!empty($has_depends)) {
632
+ if (empty($arg_value) || is_bool($arg_value)) { //selected default or true/false
633
+ $current_property_value = '';
634
+ } else { //specified a value in textbox.
635
+ $current_property_value = $arg_value;
636
+ $arg_value = true;
637
+ }
638
+
639
+ $obj['txt'] = ['name' => $has_depends, 'value' => $current_property_value, 'depends_on' => 'true'];
640
+ }
641
+
642
+
643
+ // $arg_value will be null when Default is selected.
644
+ if ($arg_value === null) {
645
+ $arg_value = '';
646
+ }
647
+
648
+ $this->dropdown_row($label, $name, $options, $arg_value, (object) $obj);
649
+ }
650
+
651
+ protected function rewrite_settings() {
652
+ $arg_value = $this->get_property_value('rewrite', '');
653
+ if ($arg_value === null) {
654
+ $arg_value = '';
655
+ }
656
+
657
+ $current_property_value = $this->get_current_property_value('rewrite');
658
+
659
+ $this->dropdown_advanced_settings_boolean(
660
+ __('Rewrite', 'wpfront-user-role-editor'),
661
+ 'rewrite',
662
+ __('Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. Defaults to true, using <b>"Name"</b> as slug. ', 'wpfront-user-role-editor'),
663
+ '',
664
+ false,
665
+ is_array($arg_value) ? true : $arg_value,
666
+ !empty($current_property_value) ? 'True' : 'False'
667
+ );
668
+
669
+ $this->textbox_advanced_settings(
670
+ __('Rewrite Slug', 'wpfront-user-role-editor'),
671
+ 'rewrite_slug',
672
+ __('Customize the permastruct slug. Defaults to <b>"Name"</b> key.', 'wpfront-user-role-editor'),
673
+ isset($arg_value['slug']) ? $arg_value['slug'] : null,
674
+ isset($current_property_value['slug']) ? $current_property_value['slug'] : ''
675
+ );
676
+
677
+
678
+ $this->dropdown_advanced_settings_boolean(
679
+ __('Rewrite With Front', 'wpfront-user-role-editor'),
680
+ 'rewrite_with_front',
681
+ __('Whether the permastruct should be prepended with WP_Rewrite::$front. Default true. ', 'wpfront-user-role-editor'),
682
+ '',
683
+ false,
684
+ isset($arg_value['with_front']) ? $arg_value['with_front'] : null,
685
+ isset($current_property_value['with_front']) ? $current_property_value['with_front'] : ''
686
+ );
687
+
688
+ $this->dropdown_advanced_settings_boolean(
689
+ __('Rewrite Feeds', 'wpfront-user-role-editor'),
690
+ 'rewrite_feeds',
691
+ __('Whether the feed permastruct should be built for this post type. Default is value of <b>"has_archive"<b>.', 'wpfront-user-role-editor'),
692
+ '',
693
+ false,
694
+ isset($arg_value['feeds']) ? $arg_value['feeds'] : null,
695
+ isset($current_property_value['feeds']) ? $current_property_value['feeds'] : ''
696
+ );
697
+
698
+ $this->dropdown_advanced_settings_boolean(
699
+ __('Rewrite Pages', 'wpfront-user-role-editor'),
700
+ 'rewrite_pages',
701
+ __('Whether the permastruct should provide for pagination. Default true.', 'wpfront-user-role-editor'),
702
+ '',
703
+ false,
704
+ isset($arg_value['pages']) ? $arg_value['pages'] : null,
705
+ isset($current_property_value['pages']) ? $current_property_value['pages'] : ''
706
+ );
707
+
708
+ $this->textbox_advanced_settings(
709
+ __('Rewrite EP Mask', 'wpfront-user-role-editor'),
710
+ 'rewrite_ep_mask',
711
+ __('Endpoint mask to assign. If not specified and permalink_epmask is set, inherits from $permalink_epmask. If not specified and permalink_epmask is not set, defaults to EP_PERMALINK.', 'wpfront-user-role-editor'),
712
+ isset($arg_value['ep_mask']) ? $arg_value['ep_mask'] : null,
713
+ isset($current_property_value['ep_mask']) ? $current_property_value['ep_mask'] : ''
714
+ );
715
+ return;
716
+ }
717
+
718
+ protected function textbox_advanced_settings($label, $name, $help, $prop_value = null, $prop_current_value = null) {
719
+ if ($name === 'custom_supports') {
720
+ $prop_value = $this->get_property_value('supports');
721
+ $core_supports = array_keys($this->get_core_supports());
722
+ if (is_array($prop_value)) {
723
+ $prop_value = array_diff($prop_value, $core_supports);
724
+ $prop_value = implode(', ', $prop_value);
725
+ }
726
+
727
+ if (empty($prop_value)) {
728
+ $prop_value = $this->get_property_value($name);
729
+ }
730
+
731
+ $prop_current_value = '';
732
+ if (isset($this->post_type_obj->name)) {
733
+ $prop_current_value = array_keys(get_all_post_type_supports($this->post_type_obj->name));
734
+ if (is_array($prop_current_value)) {
735
+ $prop_current_value = array_diff($prop_current_value, $core_supports);
736
+ } else {
737
+ $prop_current_value = [];
738
+ }
739
+ $prop_current_value = implode(', ', $prop_current_value);
740
+ }
741
+ } elseif ($name === 'capability_type') {
742
+ $customized = $this->controller->get_customizied_custom_post_types_from_settings();
743
+ if (!empty($customized)) {
744
+ $value = $this->get_property_value('name');
745
+ if (in_array($value, $customized)) {
746
+ $prop_value = $value;
747
+ }
748
+ }
749
+
750
+ if(empty($prop_value)) {
751
+ $prop_value = $this->get_property_value($name);
752
+ }
753
+ $prop_current_value = $this->get_current_property_value($name);
754
+ } else {
755
+ if ($prop_value === null) {
756
+ $prop_value = $this->get_property_value($name);
757
+ }
758
+
759
+ if ($prop_current_value === null) {
760
+ $prop_current_value = $this->get_current_property_value($name);
761
+ }
762
+ }
763
+
764
+ $this->textbox_row($label, $name, $prop_value, (object) ['help' => $help, 'help_current_value' => $prop_current_value]);
765
+ }
766
+
767
+ protected function checkbox_advanced_settings($label, $name, $help) {
768
+ $this->checkbox_row($label, $name, (object) ['help' => $help]);
769
+ }
770
+
771
+ protected function multilist_advanced_settings($label, $name, $help) {
772
+ $options = [];
773
+ $values = $this->get_property_value($name);
774
+ $current_property_value = '';
775
+
776
+ if ($name == 'supports') {
777
+ $options = $this->get_core_supports();
778
+ if (isset($this->post_type_obj->name)) {
779
+ $current_property_value = get_all_post_type_supports($this->post_type_obj->name);
780
+ }
781
+ } else if ($name == 'taxonomies') {
782
+ $taxonomies = get_taxonomies(['public' => true], 'objects');
783
+ foreach ($taxonomies as $taxonomy) {
784
+ $options[$taxonomy->name] = $taxonomy->label;
785
+ }
786
+
787
+ if (isset($this->post_type_obj->name)) {
788
+ $current_property_value = get_object_taxonomies($this->post_type_obj->name, 'objects');
789
+ }
790
+ }
791
+
792
+ if (is_array($current_property_value)) {
793
+ $p = [];
794
+ foreach ($current_property_value as $key => $value) {
795
+ if (!empty($options[$key])) {
796
+ $p[] = $options[$key];
797
+ }
798
+ }
799
+ $current_property_value = implode(', ', $p);
800
+ } else {
801
+ $current_property_value = strval($current_property_value);
802
+ }
803
+
804
+ $obj = ['help' => $help, 'help_current_value' => $current_property_value];
805
+
806
+ $this->multilist_row($label, $name, $values, $options, (object) $obj);
807
+ }
808
+
809
+ private function get_core_supports() {
810
+ return [
811
+ 'title' => __('Title', 'wpfront-user-role-editor'),
812
+ 'editor' => __('Editor', 'wpfront-user-role-editor'),
813
+ 'comments' => __('Comments', 'wpfront-user-role-editor'),
814
+ 'revisions' => __('Revisions', 'wpfront-user-role-editor'),
815
+ 'trackbacks' => __('Trackbacks', 'wpfront-user-role-editor'),
816
+ 'author' => __('Author', 'wpfront-user-role-editor'),
817
+ 'excerpt' => __('Excerpt', 'wpfront-user-role-editor'),
818
+ 'page-attributes' => __('Page Attributes', 'wpfront-user-role-editor'),
819
+ 'thumbnail' => __('Thumbnail', 'wpfront-user-role-editor'),
820
+ 'custom-fields' => __('Custom Fields', 'wpfront-user-role-editor'),
821
+ 'post-formats' => __('Post Formats', 'wpfront-user-role-editor')
822
+ ];
823
+ }
824
+
825
+ protected function textbox_row($label, $name, $value, $obj) {
826
+ $attr = '';
827
+ $class = '';
828
+ if (!empty($obj->attr)) {
829
+ $attr .= $obj->attr . ' ';
830
+ }
831
+ if (!empty($obj->required)) {
832
+ $attr .= 'aria-required="true" ';
833
+ }
834
+ if (!empty($obj->help_current_value)) {
835
+ $attr .= 'placeholder="' . esc_attr($obj->help_current_value) . '" ';
836
+ }
837
+ if (!empty($obj->auto_format)) {
838
+ $attr .= 'data-auto-format="' . esc_attr($obj->auto_format) . '" ';
839
+ $class .= 'auto-populate';
840
+ }
841
+ if (is_array($value)) {
842
+ $value = implode(', ', $value);
843
+ }
844
+ ?>
845
+ <tr class="<?php echo!empty($obj->required) ? 'form-required ' : ''; ?>">
846
+ <th scope="row">
847
+ <?php echo $label; ?>
848
+ <?php if (!empty($obj->required)) { ?>
849
+ <span class="description"> (<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
850
+ <?php } ?>
851
+ </th>
852
+ <td>
853
+ <input id="<?php echo $name; ?>" class="regular-text <?php echo $class; ?>" name="<?php echo $name; ?>" type="text" value="<?php echo $value; ?>" <?php echo $attr; ?> />
854
+ <?php
855
+ if (!empty($obj->help)) {
856
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
857
+ }
858
+ ?>
859
+ </td>
860
+ </tr>
861
+ <?php
862
+ }
863
+
864
+ protected function dropdown_row($label, $name, $options, $value, $obj) {
865
+ $attr = '';
866
+ $placeholder = '';
867
+ if (!empty($obj->attr)) {
868
+ $attr .= $obj->attr . ' ';
869
+ }
870
+ if ($name === 'show_in_menu') {
871
+ $placeholder = __('top level menu', 'wpfront-user-role-editor');
872
+ }
873
+ if ($name === 'has_archive' || $name === 'query_var') {
874
+ if (isset($this->post_type_obj->name)) {
875
+ $placeholder = $this->post_type_obj->name;
876
+ }
877
+ }
878
+ ?>
879
+ <tr>
880
+ <th scope="row">
881
+ <?php echo $label; ?>
882
+ </th>
883
+ <td>
884
+ <select name="<?php echo $name; ?>" class="<?php echo!empty($obj->txt) ? 'has-depends' : ''; ?>" <?php echo $attr; ?> >
885
+ <?php
886
+ foreach ($options as $option) {
887
+ $selected = $option->value === $value ? 'selected' : '';
888
+ if ($option->value === true) {
889
+ $option->value = '1';
890
+ } elseif ($option->value === false) {
891
+ $option->value = '0';
892
+ }
893
+ echo "<option value='{$option->value}' $selected>{$option->label}</option>";
894
+ }
895
+ ?>
896
+ </select>
897
+ <?php
898
+ if (!empty($obj->txt)) {
899
+ $txt_value = $obj->txt['value'];
900
+ if (!empty($_POST['submit'])) { //on a POST with validation error, display POSTed value.
901
+ $txt_value = $_POST[$obj->txt['name']];
902
+ }
903
+ ?>
904
+ <input type="text" name="<?php echo $obj->txt['name']; ?>" placeholder="<?php echo $placeholder; ?>" value="<?php echo $txt_value; ?>" data-depends="<?php echo $name; ?>" data-depends-on="<?php echo $obj->txt['depends_on']; ?>" />
905
+ <?php
906
+ }
907
+ ?>
908
+ <?php
909
+ if (!empty($obj->help)) {
910
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
911
+ }
912
+ ?>
913
+ </tr>
914
+ <?php
915
+ }
916
+
917
+ protected function multilist_row($label, $name, $values, $options, $obj) {
918
+ if (empty($values)) {
919
+ $values = [];
920
+ }
921
+ ?>
922
+ <tr>
923
+ <th scope="row">
924
+ <?php
925
+ echo $label;
926
+ $placeholder = __('Choose From Options', 'wpfront-user-role-editor');
927
+ ?>
928
+ </th>
929
+ <td>
930
+ <select data-placeholder="<?php echo $placeholder; ?>" name="<?php echo $name; ?>[]" class="chosen-select" multiple>
931
+ <?php
932
+ foreach ($options as $value => $label) {
933
+ $selected = in_array($value, $values) ? 'selected' : '';
934
+ echo "<option value='$value' $selected>$label</option>";
935
+ }
936
+ ?>
937
+ </select>
938
+ <?php
939
+ if (!empty($obj->help)) {
940
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
941
+ }
942
+ ?>
943
+ </tr>
944
+ <?php
945
+ }
946
+
947
+ protected function echo_help_tooltip($pretext, $current_value) {
948
+ $title = esc_attr($pretext);
949
+ if (!empty($this->post_type_obj)) {
950
+ $title .= '<br />' . esc_attr(sprintf(__('Current value is "<b>%s</b>"', 'wpfront-user-role-editor'), $current_value));
951
+ }
952
+ ?>
953
+ <i class="fa fa-question-circle-o" title="<?php echo $title; ?>"></i>
954
+ <?php
955
+ }
956
+
957
+ protected function get_property_value($prop, $default = '') {
958
+ if (!empty($_POST['submit'])) {
959
+ return !isset($_POST[$prop]) ? $default : $_POST[$prop];
960
+ }
961
+
962
+ if (!empty($this->post_type_data)) { //edit
963
+ if ($prop === 'taxonomies') {
964
+ return $this->post_type_data->$prop;
965
+ }
966
+
967
+ if (isset($this->post_type_data->post_type_arg[$prop])) {
968
+ return $this->post_type_data->post_type_arg[$prop];
969
+ }
970
+
971
+ if (isset($this->post_type_data->$prop)) {
972
+ return $this->post_type_data->$prop;
973
+ }
974
+
975
+ return null;
976
+ }
977
+
978
+ if (!empty($this->clone_from)) { //add with clone
979
+ if (isset($this->clone_from->post_type_arg)) { //our post type
980
+ if (isset($this->clone_from->post_type_arg[$prop])) {
981
+ $f = $this->clone_from->post_type_arg[$prop];
982
+ return $this->clone_from->post_type_arg[$prop];
983
+ }
984
+
985
+ if (isset($this->clone_from->$prop)) { //our post type
986
+ return $this->clone_from->$prop;
987
+ }
988
+
989
+ return null;
990
+ }
991
+
992
+
993
+
994
+ if (is_object($this->clone_from->post_type_obj)) { //for built-in and other
995
+ if ($prop === 'supports') {
996
+ $supports = get_all_post_type_supports($this->clone_from->post_type_obj->name);
997
+ if (is_array($supports)) {
998
+ return array_keys($supports);
999
+ }
1000
+
1001
+ return [];
1002
+ }
1003
+
1004
+ if ($prop === 'taxonomies') {
1005
+ return get_object_taxonomies($this->clone_from->post_type_obj->name);
1006
+ }
1007
+
1008
+ if (isset($this->clone_from->post_type_obj->$prop)) {
1009
+ return $this->clone_from->post_type_obj->$prop;
1010
+ }
1011
+
1012
+ return null;
1013
+ }
1014
+
1015
+ return null;
1016
+ }
1017
+
1018
+ return $default;
1019
+ }
1020
+
1021
+ protected function get_labels_value($prop, $default = '') {
1022
+ if (!empty($_POST['submit'])) {
1023
+ return empty($_POST[$prop]) ? $default : $_POST[$prop];
1024
+ }
1025
+
1026
+ if (!empty($this->post_type_data)) { //edit
1027
+ if (isset($this->post_type_data->post_type_arg['labels'][$prop])) {
1028
+ return $this->post_type_data->post_type_arg['labels'][$prop];
1029
+ }
1030
+ }
1031
+
1032
+ if (!empty($this->clone_from)) { //add with clone
1033
+ if (isset($this->clone_from->post_type_arg['labels'][$prop])) { //our post type
1034
+ return $this->clone_from->post_type_arg['labels'][$prop];
1035
+ }
1036
+
1037
+ if (isset($this->clone_from->post_type_obj->labels->$prop)) { //for built-in and others
1038
+ return $this->clone_from->post_type_obj->labels->$prop;
1039
+ }
1040
+ }
1041
+
1042
+ return $default;
1043
+ }
1044
+
1045
+ protected function get_current_labels_value($prop) {
1046
+ if (!empty($this->post_type_obj) && isset($this->post_type_obj->labels) && isset($this->post_type_obj->labels->$prop)) {
1047
+ return $this->post_type_obj->labels->$prop;
1048
+ }
1049
+
1050
+ return '';
1051
+ }
1052
+
1053
+ protected function get_current_property_value($prop) {
1054
+ if (!empty($this->post_type_obj)) {
1055
+ if (isset($this->post_type_obj->$prop)) {
1056
+ if ($prop == 'rest_base' && $this->post_type_obj->$prop == '') {
1057
+ return $this->post_type_obj->name;
1058
+ } elseif ($prop == 'rest_controller_class' && $this->post_type_obj->$prop == '') {
1059
+ return 'WP_REST_Posts_Controller';
1060
+ } else {
1061
+ return $this->post_type_obj->$prop;
1062
+ }
1063
+ }
1064
+
1065
+ if ($prop === 'menu_position') {
1066
+ return __('at the bottom', 'wpfront-user-role-editor');
1067
+ }
1068
+
1069
+ if ($prop === 'menu_icon') {
1070
+ return __('use "Posts" menu icon', 'wpfront-user-role-editor');
1071
+ }
1072
+ }
1073
+
1074
+ return null; //Either on ADD screen or on a Deactivated post type.
1075
+ }
1076
+
1077
+ protected function scripts() {
1078
+ ?>
1079
+ <script type="text/javascript">
1080
+ (function ($) {
1081
+ var $div = $('div.wrap.post-type-add-edit');
1082
+
1083
+ //select change to hide/show textboxes.
1084
+ $div.on('change', 'select.has-depends', function () {
1085
+ var $select = $(this);
1086
+ var $d = $select.next();
1087
+ var on = $d.data('depends-on');
1088
+ if ($select.val() == on) {
1089
+ $d.show();
1090
+ } else {
1091
+ $d.hide();
1092
+ }
1093
+ });
1094
+
1095
+ //rewrite disable
1096
+ $div.on('change', "select[name='rewrite']", function () {
1097
+ var $rewrite_slug = $("input[name='rewrite_slug']");
1098
+ var $ep_mask = $("input[name='rewrite_ep_mask']");
1099
+ var $with_front = $("select[name='rewrite_with_front']");
1100
+ var $feeds = $("select[name='rewrite_feeds']");
1101
+ var $pages = $("select[name='rewrite_pages']");
1102
+ if ($(this).val() === '1') {
1103
+ $rewrite_slug.prop('disabled', false);
1104
+ $ep_mask.prop('disabled', false);
1105
+ $with_front.prop('disabled', false);
1106
+ $feeds.prop('disabled', false);
1107
+ $pages.prop('disabled', false);
1108
+ } else {
1109
+ $rewrite_slug.prop('disabled', true);
1110
+ $ep_mask.prop('disabled', true);
1111
+ $with_front.prop('disabled', true);
1112
+ $feeds.prop('disabled', true);
1113
+ $pages.prop('disabled', true);
1114
+ }
1115
+ });
1116
+
1117
+ //parent item colon
1118
+ $div.on('change', "select[name='hierarchical']", function () {
1119
+ var $parent_item_colon = $("input[name='parent_item_colon']");
1120
+ if ($(this).val() === '1') {
1121
+ $parent_item_colon.prop('disabled', false);
1122
+ } else {
1123
+ $parent_item_colon.prop('disabled', true);
1124
+ }
1125
+ });
1126
+
1127
+ $div.find("select.has-depends, select[name='rewrite'], select[name='hierarchical']").trigger('change');
1128
+
1129
+ //auto populate labels and validation
1130
+ $div.find(".auto-populate-labels").on('click', function () {
1131
+ var S0 = $("input[name='label']");
1132
+ var S1 = $("input[name='singular_name']");
1133
+
1134
+ var ret = false;
1135
+ if ($.trim(S1.val()) === "") {
1136
+ S1.parent().parent().addClass("form-invalid");
1137
+ S1.focus();
1138
+ ret = true;
1139
+ } else {
1140
+ S1.parent().parent().removeClass("form-invalid");
1141
+ }
1142
+
1143
+ if ($.trim(S0.val()) === "") {
1144
+ S0.parent().parent().addClass("form-invalid");
1145
+ S0.focus();
1146
+ ret = true;
1147
+ } else {
1148
+ S0.parent().parent().removeClass("form-invalid");
1149
+ }
1150
+
1151
+ if (ret) {
1152
+ return false;
1153
+ }
1154
+
1155
+ S0 = $.trim(S0.val());
1156
+ S1 = $.trim(S1.val());
1157
+ var s0 = S0.toLowerCase();
1158
+ var s1 = S1.toLowerCase();
1159
+
1160
+ $div.find("#postbox-labels input.auto-populate").each(function (i, e) {
1161
+ var $e = $(e);
1162
+ if ($e.val() !== "" || $e.is(":disabled")) {
1163
+ return;
1164
+ }
1165
+
1166
+ var format = $e.data("auto-format");
1167
+ if (typeof String.prototype.replaceAll === "function") {
1168
+ format = format.replaceAll("%S0", S0);
1169
+ format = format.replaceAll("%S1", S1);
1170
+ format = format.replaceAll("%s0", s0);
1171
+ format = format.replaceAll("%s1", s1);
1172
+ } else {
1173
+ format = format.replace("%S0", S0);
1174
+ format = format.replace("%S1", S1);
1175
+ format = format.replace("%s0", s0);
1176
+ format = format.replace("%s1", s1);
1177
+ }
1178
+
1179
+ $e.val(format);
1180
+ });
1181
+
1182
+ return false;
1183
+ });
1184
+
1185
+ //clear labels
1186
+ $div.find(".clear-labels").on('click', function () {
1187
+ $div.find("#postbox-labels input.auto-populate").val('');
1188
+ return false;
1189
+ });
1190
+
1191
+ //validation
1192
+ $div.children('form').on('submit', function () {
1193
+ var name = $("input[name='name']");
1194
+ var labels = $("input[name='label']");
1195
+ var label = $("input[name='singular_name']");
1196
+
1197
+ var ele = null;
1198
+
1199
+ if ($.trim(label.val()) == "") {
1200
+ label.parent().parent().addClass("form-invalid");
1201
+ ele = label;
1202
+ }
1203
+
1204
+ if ($.trim(labels.val()) == "") {
1205
+ labels.parent().parent().addClass("form-invalid");
1206
+ ele = labels;
1207
+ }
1208
+
1209
+ if ($.trim(name.val()) == "") {
1210
+ name.parent().parent().addClass("form-invalid");
1211
+ ele = name;
1212
+ }
1213
+
1214
+ if (ele !== null) {
1215
+ ele.focus();
1216
+ return false;
1217
+ }
1218
+ });
1219
+
1220
+ $div.find(".chosen-select").chosen({width: "27em"});
1221
+
1222
+ //postbox
1223
+ $(function () {
1224
+ $div.find('.if-js-closed').removeClass('if-js-closed').addClass('closed');
1225
+ postboxes.add_postbox_toggles('<?php echo $this->controller->get_menu_slug(); ?>');
1226
+ });
1227
+
1228
+ //for tooltip
1229
+ $(function () {
1230
+ $div.find('i').tooltip({
1231
+ position: {my: "left+10 center", at: "right center"},
1232
+ content: function () {
1233
+ return $(this).prop('title');
1234
+ },
1235
+ hide: 50
1236
+ });
1237
+ });
1238
+ })(jQuery);
1239
+ </script>
1240
+ <?php
1241
+ }
1242
+
1243
+ }
1244
+
1245
+ }
1246
+
1247
+
1248
+
1249
+
includes/post-type/template-delete.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Post Type Delete
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Post_Type;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor as URE;
38
+ use WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type as PostType;
39
+
40
+ if (!class_exists('WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Delete_View')) {
41
+
42
+ class WPFront_User_Role_Editor_Post_Type_Delete_View {
43
+
44
+ /**
45
+ *
46
+ * @var WPFront_User_Role_Editor_Post_Type
47
+ */
48
+ private $controller;
49
+ private $post_type_entitties;
50
+ private $display = array();
51
+
52
+ public function __construct($controller, $entities, $view = 'delete') {
53
+ $this->controller = $controller;
54
+ $this->post_type_entitties = $entities;
55
+
56
+ $this->display['action'] = $view;
57
+ switch ($view) {
58
+ case 'restore':
59
+ $this->display['url'] = $this->controller->get_restore_url(null);
60
+ $this->display['button_text'] = __('Confirm Restore', 'wpfront-user-role-editor');
61
+ $this->display['title'] = __('Restore Post Types', 'wpfront-user-role-editor');
62
+ $this->display['description'] = __('The following Post Types will be restored.', 'wpfront-user-role-editor');
63
+ break;
64
+
65
+ default:
66
+ $this->display['url'] = $this->controller->get_delete_url(null);
67
+ $this->display['button_text'] = __('Confirm Delete', 'wpfront-user-role-editor');
68
+ $this->display['title'] = __('Delete Post Types', 'wpfront-user-role-editor');
69
+ $this->display['description'] = __('The following Post Types will be deleted.', 'wpfront-user-role-editor');
70
+ break;
71
+ }
72
+ }
73
+
74
+ public function view() {
75
+ ?>
76
+ <div class="wrap post-type">
77
+ <?php
78
+ $this->title();
79
+ ?>
80
+ <form id="form-post-type" method="post" action="<?php echo $this->display['url']; ?>">
81
+ <ol>
82
+ <?php $this->post_types_display(); ?>
83
+ </ol>
84
+ <input type="hidden" name="action" value="<?php echo $this->display['action']; ?>" />
85
+ <?php
86
+ wp_nonce_field('bulk-action-view-post');
87
+ submit_button($this->display['button_text'], 'button-secondary');
88
+ ?>
89
+ </form>
90
+ </div>
91
+ <?php
92
+ }
93
+
94
+ protected function title() {
95
+ ?>
96
+ <h2>
97
+ <?php echo $this->display['title']; ?>
98
+ <p><?php echo $this->display['description']; ?></p>
99
+ </h2>
100
+ <?php
101
+ }
102
+
103
+ protected function post_types_display() {
104
+ foreach ($this->post_type_entitties as $entity) {
105
+ echo "<li>{$entity->label} [{$entity->name}]</li>";
106
+ echo "<input type='hidden' name='post_types[]' value='{$entity->name}' />";
107
+ }
108
+ }
109
+
110
+ }
111
+
112
+ }
113
+
includes/post-type/template-post-type.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Post Type
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Post_Type;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
38
+
39
+ require_once dirname(__FILE__) . '/class-post-type-list-table.php';
40
+
41
+ if (!class_exists('WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_List_View')) {
42
+
43
+ class WPFront_User_Role_Editor_Post_Type_List_View {
44
+
45
+ /**
46
+ *
47
+ * @var WPFront_User_Role_Editor_Post_Type
48
+ */
49
+ private $controller;
50
+
51
+ /**
52
+ *
53
+ * @param WPFront_User_Role_Editor_Post_Type $controller
54
+ */
55
+ public function __construct($controller) {
56
+ $this->controller = $controller;
57
+ $this->PostType = WPFront_User_Role_Editor_Post_Type::instance();
58
+ }
59
+
60
+ public function view() {
61
+ ?>
62
+ <div class="wrap post-type">
63
+ <?php $this->title(); ?>
64
+ <?php $this->display_notices(); ?>
65
+ <?php $this->filter_links(); ?>
66
+ <?php
67
+ $list_table = new WPFront_User_Role_Editor_Post_Type_List_Table($this->controller);
68
+ $list_table->prepare_items();
69
+ ?>
70
+ <form action="" method="get" class="search-form">
71
+ <input type="hidden" name="page" value="<?php echo $this->controller::MENU_SLUG; ?>" />
72
+ <?php $list_table->search_box(__('Search', 'wpfront-user-role-editor'), 'post-type'); ?>
73
+ </form>
74
+ <form id="form-post-type" method="post">
75
+ <?php
76
+ $list_table->display();
77
+ ?>
78
+ </form>
79
+ </div>
80
+ <?php
81
+ }
82
+
83
+ protected function title() {
84
+ ?>
85
+ <h2>
86
+ <?php
87
+ echo __('Post Types', 'wpfront-user-role-editor');
88
+ if (current_user_can('create_posttypes')) {
89
+ ?>
90
+ <a href="<?php echo $this->controller->get_add_new_url() ?>" class="add-new-h2"><?php echo __('Add New', 'wpfront-user-role-editor'); ?></a>
91
+ <?php
92
+ }
93
+ ?>
94
+ </h2>
95
+ <?php
96
+ }
97
+
98
+ protected function filter_links() {
99
+ ?>
100
+ <ul class="subsubsub">
101
+ <li>
102
+ <?php
103
+ $link_data = array();
104
+ $active_filter = $this->PostType->get_active_list_filter();
105
+ $filter_data = $this->PostType->get_list_filter_data();
106
+ foreach ($filter_data as $key => $value) {
107
+ $link_data[] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', $value['url'], ($active_filter == $key ? 'current' : ''), $value['display'], $value['count']);
108
+ }
109
+ echo implode('&#160;|&#160;</li><li> ', $link_data);
110
+ ?>
111
+ </li>
112
+ </ul>
113
+ <?php
114
+ }
115
+
116
+ protected function display_notices() {
117
+ if (!empty($this->controller->errorMsg)) {
118
+ Utils::notice_error($this->controller->errorMsg);
119
+ }
120
+
121
+ if (isset($_GET['post-type-activated'])) {
122
+ $count = $_GET['post-type-activated'];
123
+ Utils::notice_updated(sprintf(__('%d post type(s) activated successfully.', 'wpfront-user-role-editor'), $count));
124
+ } elseif (isset($_GET['post-type-deactivated'])) {
125
+ $count = $_GET['post-type-deactivated'];
126
+ Utils::notice_updated(sprintf(__('%d post type(s) deactivated successfully.', 'wpfront-user-role-editor'), $count));
127
+ } elseif (!empty($_GET['post-types-deleted'])) {
128
+ Utils::notice_updated(__('Post type(s) deleted successfully.', 'wpfront-user-role-editor'));
129
+ } elseif (!empty($_GET['post-type-added'])) {
130
+ Utils::notice_updated(__('Post type added successfully.', 'wpfront-user-role-editor'));
131
+ } elseif (!empty($_GET['post-types-restored'])) {
132
+ Utils::notice_updated(__('Post type(s) restored successfully.', 'wpfront-user-role-editor'));
133
+ }
134
+ }
135
+
136
+ }
137
+
138
+ }
includes/restore/class-restore.php ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Restore Role
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Restore;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/template-restore.php';
38
+
39
+ if (!class_exists('\WPFront\URE\Restore\WPFront_User_Role_Editor_Restore')) {
40
+
41
+ /**
42
+ * Restore Role
43
+ *
44
+ * @author Syam Mohan <syam@wpfront.com>
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Restore extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
48
+
49
+ protected function setUp() {
50
+ $this->_setUp('edit_roles', 'wpfront-user-role-editor-restore');
51
+
52
+ $this->ViewClass = WPFront_User_Role_Editor_Restore_View::class;
53
+ }
54
+
55
+ protected function initialize() {
56
+ add_action('admin_init', array($this, 'admin_init'));
57
+
58
+ if (!$this->in_admin_ui()) {
59
+ return;
60
+ }
61
+
62
+ $this->set_admin_menu(__('Restore Role', 'wpfront-user-role-editor'), __('Restore', 'wpfront-user-role-editor'));
63
+
64
+ add_filter('wpfront_ure_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 20, 1);
65
+ add_filter('wpfront_ure_ms_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 20, 1);
66
+ }
67
+
68
+ /**
69
+ * Adds ajax functions on admin_init
70
+ */
71
+ public function admin_init() {
72
+ add_action('wp_ajax_wpfront_user_role_editor_restore_role', array($this, 'restore_role_callback'), 10, 0);
73
+ }
74
+
75
+ /**
76
+ * Hooks on options class to display ui.
77
+ *
78
+ * @param array $option_keys
79
+ */
80
+ public function wpfront_ure_options_register_ui_field($option_keys) {
81
+ $option_keys['remove_nonstandard_capabilities_restore'] = '';
82
+
83
+ add_action('wpfront_ure_options_ui_field_remove_nonstandard_capabilities_restore_label', array($this, 'options_ui_label'));
84
+ add_action('wpfront_ure_options_ui_field_remove_nonstandard_capabilities_restore', array($this, 'options_ui_field'));
85
+ add_action('wpfront_ure_options_ui_field_remove_nonstandard_capabilities_restore_update', array($this, 'options_ui_update'));
86
+ add_action('wpfront_ure_options_ui_field_remove_nonstandard_capabilities_restore_help', array($this, 'options_ui_help'));
87
+
88
+ return $option_keys;
89
+ }
90
+
91
+ public function options_ui_label() {
92
+ echo __('Remove Non-Standard Capabilities on Restore', 'wpfront-user-role-editor');
93
+ }
94
+
95
+ public function options_ui_field() {
96
+ $key = 'remove_nonstandard_capabilities_restore';
97
+
98
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
99
+ $checked = !empty($_POST[$key]);
100
+ } else {
101
+ if (is_network_admin()) {
102
+ $checked = $this->Options->get_network_option_boolean($key);
103
+ } else {
104
+ $checked = $this->Options->get_option_boolean($key, true);
105
+ }
106
+ }
107
+
108
+ $checked = $checked ? 'checked' : '';
109
+
110
+ echo "<input type='checkbox' name='$key' $checked />";
111
+ }
112
+
113
+ public function options_ui_update() {
114
+ $key = 'remove_nonstandard_capabilities_restore';
115
+ $value = !empty($_POST[$key]);
116
+
117
+ if (is_network_admin()) {
118
+ $this->Options->set_network_option($key, $value, 'ms_', false);
119
+ } else {
120
+ $this->Options->set_option($key, $value, false);
121
+ }
122
+ }
123
+
124
+ public function options_ui_help() {
125
+ return '<strong>' . __('Remove Non-Standard Capabilities on Restore', 'wpfront-user-role-editor') . '</strong>: ' . __(' If enabled, while restoring WordPress built-in roles, non-standard capabilities will be removed.', 'wpfront-user-role-editor');
126
+ }
127
+
128
+ public function load_view() {
129
+ if (!parent::load_view()) {
130
+ return;
131
+ }
132
+
133
+ $this->set_help_tab();
134
+ }
135
+
136
+ /**
137
+ * Displays the add/edit role view.
138
+ */
139
+ public function view() {
140
+ if (!parent::view()) {
141
+ return;
142
+ }
143
+
144
+ $objView = new $this->ViewClass();
145
+ $objView->view();
146
+ }
147
+
148
+ /**
149
+ * Returns restorable roles with display name.
150
+ *
151
+ * @return array
152
+ */
153
+ public function get_restorable_roles() {
154
+ $rolenames = $this->RolesHelperClass::get_default_rolenames();
155
+ $roles = array();
156
+
157
+ foreach ($rolenames as $role) {
158
+ $display_name = $this->RolesHelperClass::get_display_name($role, true);
159
+ $roles[$role] = $display_name;
160
+ }
161
+
162
+ return $roles;
163
+ }
164
+
165
+ /**
166
+ * Restore action ajax call back.
167
+ */
168
+ public function restore_role_callback() {
169
+ check_ajax_referer('restore-role', 'nonce');
170
+
171
+ if (!current_user_can($this->get_cap())) {
172
+ wp_die(-1, 403);
173
+ }
174
+
175
+ if (empty($_POST['role'])) {
176
+ wp_die(-1, 403);
177
+ }
178
+
179
+ $role = $_POST['role'];
180
+ $allowed_roles = $this->get_restorable_roles();
181
+
182
+ if (!array_key_exists($role, $allowed_roles)) {
183
+ wp_die(-1, 403);
184
+ }
185
+
186
+ $this->restore_role($role);
187
+
188
+ wp_die(json_encode(true));
189
+ }
190
+
191
+ protected function restore_role($role) {
192
+ $remove_non_std = $this->remove_nonstandard_capabilities_restore();
193
+ if ($remove_non_std) {
194
+ remove_role($role);
195
+ }
196
+
197
+ $role_object = get_role($role);
198
+ if (empty($role_object)) {
199
+ $this->RolesHelperClass::add_role($role, $this->RolesHelperClass::get_display_name($role, true), array());
200
+ }
201
+
202
+ if ($role === $this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY) {
203
+ $groups = $this->RolesHelperClass::get_capabilty_groups();
204
+
205
+ if (isset($groups['network'])) {
206
+ $this->RolesHelperClass::remove_capabilities_from_role($role, $this->RolesHelperClass::get_standard_network_capabilities());
207
+ unset($groups['network']);
208
+ }
209
+
210
+ $grant = array();
211
+ foreach ($groups as $name => $group) {
212
+ $caps = $this->RolesHelperClass::get_group_capabilities($group);
213
+ if (is_array($caps)) {
214
+ $grant = array_merge($grant, $caps);
215
+ }
216
+ }
217
+ $grant = array_fill_keys($grant, true);
218
+ $this->RolesHelperClass::add_capabilities_to_role($role, $grant);
219
+ } else {
220
+ $caps = $this->RolesHelperClass::get_standard_capabilities($role);
221
+ $custom_caps = apply_filters('wpfront_ure_restore_role_custom_caps', array(), $role);
222
+
223
+ $custom_caps_check = array();
224
+ foreach ($custom_caps as $cap => $depend_on) {
225
+ if ($cap === $depend_on) {
226
+ continue;
227
+ }
228
+
229
+ if (!isset($custom_caps_check[$depend_on])) {
230
+ $custom_caps_check[$depend_on] = array();
231
+ }
232
+
233
+ $custom_caps_check[$depend_on][] = $cap;
234
+ }
235
+
236
+ $grant = array();
237
+ $remove = array();
238
+ if (is_array($caps)) {
239
+ foreach ($caps as $cap => $enabled) {
240
+ if ($enabled) {
241
+ $grant[$cap] = true;
242
+ } else {
243
+ $remove[] = $cap;
244
+ }
245
+
246
+ $this->custom_caps_restore($custom_caps_check, $cap, $enabled, $grant, $remove);
247
+ }
248
+ }
249
+
250
+ $this->RolesHelperClass::add_capabilities_to_role($role, $grant);
251
+ $this->RolesHelperClass::remove_capabilities_from_role($role, $remove);
252
+ }
253
+ }
254
+
255
+ protected function custom_caps_restore($custom_caps, $cap, $enabled, &$grant, &$remove) {
256
+ if (isset($custom_caps[$cap])) {
257
+ $check = $custom_caps[$cap];
258
+ foreach ($check as $c_cap) {
259
+ if ($enabled) {
260
+ $grant[$c_cap] = true;
261
+ $this->custom_caps_restore($custom_caps, $c_cap, true, $grant, $remove);
262
+ } else {
263
+ $remove[] = $c_cap;
264
+ }
265
+ }
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Sets the help tab
271
+ */
272
+ protected function set_help_tab() {
273
+ $tabs = array(
274
+ array(
275
+ 'id' => 'overview',
276
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
277
+ 'content' => '<p>'
278
+ . __('This screen allows you to restore WordPress built-in roles to its standard capability settings.', 'wpfront-user-role-editor')
279
+ . '</p>'
280
+ . '<p>'
281
+ . __('To restore a role, click the Restore button then Confirm.', 'wpfront-user-role-editor')
282
+ . '</p>'
283
+ )
284
+ );
285
+
286
+ $sidebar = array(
287
+ array(
288
+ __('Documentation on Restore', 'wpfront-user-role-editor'),
289
+ 'restore-role/'
290
+ )
291
+ );
292
+
293
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
294
+ }
295
+
296
+ /**
297
+ * Returns remove_nonstandard_capabilities_restore setting value.
298
+ *
299
+ * @return boolean
300
+ */
301
+ public function remove_nonstandard_capabilities_restore() {
302
+ return $this->Options->get_option_boolean('remove_nonstandard_capabilities_restore', true);
303
+ }
304
+
305
+ }
306
+
307
+ WPFront_User_Role_Editor_Restore::load();
308
+ }
includes/restore/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
includes/restore/template-restore.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Role Restore
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Restore;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if(!class_exists('WPFront\URE\Restore\WPFront_User_Role_Editor_Restore_View')) {
38
+
39
+ class WPFront_User_Role_Editor_Restore_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
40
+
41
+ protected $Restore;
42
+
43
+ public function __construct() {
44
+ parent::__construct();
45
+
46
+ $this->Restore = WPFront_User_Role_Editor_Restore::instance();
47
+ }
48
+
49
+ public function view() {
50
+ ?>
51
+ <div class="wrap role-restore">
52
+ <?php $this->title(__('Restore Role', 'wpfront-user-role-editor')); ?>
53
+
54
+ <table class="form-table">
55
+ <tbody>
56
+ <?php $this->display_restore_rows(); ?>
57
+ </tbody>
58
+ </table>
59
+ </div>
60
+ <?php
61
+ $this->scripts();
62
+ }
63
+
64
+ protected function display_restore_rows() {
65
+ $roles = $this->Restore->get_restorable_roles();
66
+
67
+ foreach ($roles as $name => $display) {
68
+ $this->display_role_row($name, $display);
69
+ }
70
+
71
+ }
72
+
73
+ protected function display_role_row($role_name, $display_name) {
74
+ ?>
75
+ <tr class="form-field">
76
+ <th scope="row">
77
+ <?php echo $display_name; ?>
78
+ </th>
79
+ <td>
80
+ <button class="button button-primary restore-role" value="<?php echo $role_name; ?>"><?php echo __('Restore', 'wpfront-user-role-editor'); ?></button>
81
+ <div class="restore-role-button-container">
82
+ <button class="button restore-role-cancel" value="<?php echo $role_name; ?>"><?php echo __('Cancel', 'wpfront-user-role-editor'); ?></button>
83
+ <button class="button restore-role-confirm" value="<?php echo $role_name; ?>"><?php echo __('Confirm', 'wpfront-user-role-editor'); ?></button>
84
+ </div>
85
+ <div class="restore-role-loader">
86
+ <img src="<?php echo $this->WPFURE->get_asset_url('images/loading.gif'); ?>" />
87
+ </div>
88
+ <div class="restore-role-success">
89
+ <button class="button button" disabled="true">
90
+ <i class="fa fa-check fa-1"></i>
91
+ <?php echo __('Restored', 'wpfront-user-role-editor'); ?>
92
+ </button>
93
+ </div>
94
+ </td>
95
+ </tr>
96
+ <?php
97
+ }
98
+
99
+ protected function ajax_url() {
100
+ return json_encode(admin_url('admin-ajax.php'));
101
+ }
102
+
103
+ protected function scripts() {
104
+ ?>
105
+ <script type="text/javascript">
106
+ (function($) {
107
+ $("button.restore-role").click(function() {
108
+
109
+ $(this).hide().next().show();
110
+ });
111
+
112
+ $("button.restore-role-cancel").click(function() {
113
+ $(this).parent().hide().prev().show();
114
+ });
115
+
116
+ $("button.restore-role-confirm").click(function() {
117
+ $("button.restore-role-confirm").prop("disabled", true);
118
+
119
+ var _this = $(this).parent().hide().next().show();
120
+
121
+ var data = {
122
+ "action": "wpfront_user_role_editor_restore_role",
123
+ "role": $(this).val(),
124
+ "nonce": <?php echo json_encode(wp_create_nonce("restore-role")); ?>
125
+ };
126
+
127
+ var response_process = function(response) {
128
+ if (typeof response === "undefined" || response == null) {
129
+ response = {"result": false, "message": <?php echo json_encode(__('Unexpected error / Timed out', 'wpfront-user-role-editor')); ?>};
130
+ }
131
+ _this.hide();
132
+ if (response.result)
133
+ _this.next().show();
134
+ else
135
+ _this.next().text(response.message).css("color", "Red").show();
136
+
137
+ $("button.restore-role-confirm").prop("disabled", false);
138
+ };
139
+
140
+ var ajaxurl = <?php echo $this->ajax_url(); ?>;
141
+ $.post(ajaxurl, data, response_process, "json").fail(function() {
142
+ response_process();
143
+ });
144
+ });
145
+ })(jQuery);
146
+ </script>
147
+ <?php
148
+ }
149
+
150
+ }
151
+
152
+ }
153
+
includes/roles/class-role-add-edit.php ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Add/Edit Role
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/template-role-add-edit.php';
38
+
39
+ if (!class_exists('\WPFront\URE\Roles\WPFront_User_Role_Editor_Role_Add_Edit')) {
40
+
41
+ /**
42
+ * Add Edit Role
43
+ *
44
+ * @author Syam Mohan <syam@wpfront.com>
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Role_Add_Edit extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
48
+
49
+ protected $mode = 'EDIT';
50
+ protected $role_data = null;
51
+
52
+ protected $RolesList;
53
+
54
+ protected function setUp() {
55
+ $this->_setUp('edit_roles', 'wpfront-user-role-editor-add-new');
56
+
57
+ $this->ViewClass = WPFront_User_Role_Editor_Role_Add_Edit_View::class;
58
+ $this->RolesList = WPFront_User_Role_Editor_Roles_List::instance();
59
+ }
60
+
61
+ public function get_cap() {
62
+ if($this->mode === 'ADD') {
63
+ return 'create_roles';
64
+ } else {
65
+ return 'edit_roles';
66
+ }
67
+ }
68
+
69
+ protected function initialize() {
70
+ add_action('wp_before_admin_bar_render', array($this, 'admin_bar_menu'), 1);
71
+ add_action('admin_init', array($this, 'admin_init'));
72
+
73
+ if(!$this->in_admin_ui()) {
74
+ return;
75
+ }
76
+
77
+ $this->set_admin_menu(__('Add New Role', 'wpfront-user-role-editor'), __('Add New', 'wpfront-user-role-editor'));
78
+
79
+ add_filter('wpfront_ure_capability_edit_role_menus_functionality_enabled', '__return_false');
80
+ add_filter('wpfront_ure_capability_edit_content_shortcodes_functionality_enabled', '__return_false');
81
+ add_filter('wpfront_ure_capability_delete_content_shortcodes_functionality_enabled', '__return_false');
82
+ }
83
+
84
+ /**
85
+ * Adds ajax functions on admin_init
86
+ */
87
+ public function admin_init() {
88
+ add_action('wp_ajax_wpfront_user_role_editor_copy_capabilities', array($this, 'copy_capabilities_callback'), 10, 0);
89
+ }
90
+
91
+ public function admin_print_scripts() {
92
+ parent::admin_print_scripts();
93
+
94
+ wp_enqueue_script('postbox');
95
+ wp_enqueue_script('jquery-ui-draggable');
96
+ }
97
+
98
+ /**
99
+ * Hooks into admin_bar_menu to add Roles under New in tool bar.
100
+ *
101
+ * @param WP_Admin_Bar $wp_admin_bar
102
+ */
103
+ public function admin_bar_menu() {
104
+ if(current_user_can('create_roles')) {
105
+ global $wp_admin_bar;
106
+ $wp_admin_bar->add_menu(array(
107
+ 'parent' => 'new-content',
108
+ 'id' => $this->get_menu_slug(),
109
+ 'title' => __('Role', 'wpfront-user-role-editor'),
110
+ 'href' => admin_url('admin.php?page=' . $this->get_menu_slug()))
111
+ );
112
+ }
113
+ }
114
+
115
+ public function load_view() {
116
+ $this->mode = 'ADD';
117
+
118
+ $this->edit_role();
119
+ $this->set_add_help_tab();
120
+ }
121
+
122
+ /**
123
+ * Returns whether the current user action is edit role.
124
+ *
125
+ * @return boolean
126
+ */
127
+ public function edit_role() {
128
+ if(!empty($_POST['createrole'])) {
129
+ check_admin_referer('add-new-role');
130
+
131
+ if($this->mode === 'ADD') {
132
+ if(!current_user_can($this->get_cap())) {
133
+ $this->WPFURE->permission_denied();
134
+ return false;
135
+ }
136
+
137
+ $role_data = $this->get_role_data();
138
+ if(!empty($role_data['error'])) {
139
+ return false;
140
+ }
141
+
142
+ $this->RolesHelperClass::add_role($role_data['role_name'], $role_data['display_name'], $role_data['capabilities']);
143
+
144
+ if(wp_safe_redirect($this->get_edit_role_url($role_data['role_name']) . '&role-added=true')) {
145
+ exit();
146
+ }
147
+
148
+ return false;
149
+ } else {
150
+ if(!current_user_can($this->get_cap())) {
151
+ $this->WPFURE->permission_denied();
152
+ return true;
153
+ }
154
+
155
+ $role_data = $this->get_role_data();
156
+ if(empty($role_data)) {
157
+ if(wp_safe_redirect($this->RolesList->get_list_roles_url())) {
158
+ exit();
159
+ }
160
+ return true;
161
+ }
162
+
163
+ if($role_data['is_readonly']) {
164
+ $this->WPFURE->permission_denied();
165
+ return true;
166
+ }
167
+
168
+ if(!empty($role_data['error'])) {
169
+ return true;
170
+ }
171
+
172
+ $this->RolesHelperClass::update_role($role_data['role_name'], $role_data['display_name'], $role_data['capabilities']);
173
+
174
+ if(wp_safe_redirect($this->get_edit_role_url($role_data['role_name']) . '&role-updated=true')) {
175
+ exit();
176
+ }
177
+
178
+ return true;
179
+ }
180
+ }
181
+
182
+ if(!empty($_GET['edit_role'])) {
183
+ if(empty($this->get_role_data())) {
184
+ if(wp_safe_redirect($this->RolesList->get_list_roles_url())) {
185
+ exit();
186
+ }
187
+ }
188
+ return true;
189
+ }
190
+
191
+ return false;
192
+ }
193
+
194
+ /**
195
+ * Returns role information as array.
196
+ *
197
+ * @return array
198
+ */
199
+ public function get_role_data() {
200
+ if($this->role_data !== null) {
201
+ return $this->role_data;
202
+ }
203
+
204
+ if($this->mode === 'ADD') {
205
+ $error = null;
206
+ $role_name = '';
207
+ $display_name = '';
208
+ $is_readonly = false;
209
+ $is_role_name_valid = true;
210
+ $is_display_name_valid = true;
211
+ $capabilities = array();
212
+
213
+ if(!empty($_POST['createrole'])) {
214
+ $posted = $this->get_role_name_posted();
215
+ $role_name = $posted[0];
216
+ $is_role_name_valid = $posted[1];
217
+ $error = $posted[2];
218
+
219
+ $posted = $this->get_display_name_posted();
220
+ $display_name = $posted[0];
221
+ $is_display_name_valid = $posted[1];
222
+ $error = $error ?? $posted[2];
223
+
224
+ $capabilities = $this->get_capabilities_posted();
225
+ }
226
+ } else {
227
+ if(empty($_GET['edit_role'])) {
228
+ return null;
229
+ }
230
+
231
+ $role_name = $_GET['edit_role'];
232
+ $is_role_name_valid = true;
233
+ if(!$this->RolesHelperClass::is_role($role_name)) {
234
+ return null;
235
+ }
236
+
237
+ $display_name = $this->RolesHelperClass::get_display_name($role_name);
238
+ $is_display_name_valid = true;
239
+
240
+ $capabilities = $this->RolesHelperClass::get_capabilities($role_name);
241
+
242
+ $error = null;
243
+
244
+ if(!empty($_POST['createrole'])) {
245
+ $posted = $this->get_display_name_posted();
246
+ $display_name = $posted[0];
247
+ $is_display_name_valid = $posted[1];
248
+ $error = $posted[2];
249
+
250
+ $capabilities = $this->get_capabilities_posted();
251
+ }
252
+
253
+ $is_readonly = !$this->is_role_editable($role_name);
254
+ }
255
+
256
+ $this->role_data = array();
257
+
258
+ $this->role_data['role_name'] = $role_name;
259
+ $this->role_data['is_role_name_valid'] = $is_role_name_valid;
260
+ $this->role_data['display_name'] = $display_name;
261
+ $this->role_data['is_display_name_valid'] = $is_display_name_valid;
262
+ $this->role_data['capabilities'] = $capabilities;
263
+ $this->role_data['is_readonly'] = $is_readonly;
264
+ $this->role_data['error'] = $error;
265
+
266
+ return $this->role_data;
267
+ }
268
+
269
+ protected function get_role_name_posted() {
270
+ $role_name = '';
271
+ $is_role_name_valid = true;
272
+ $error = null;
273
+
274
+ if(!empty($_POST['role_name'])) {
275
+ $role_name = strtolower(preg_replace('/\W/', '', preg_replace('/ /', '_', trim($_POST['role_name']))));
276
+ if($role_name === '') {
277
+ $is_role_name_valid = false;
278
+ $error = __('Role name cannot be empty.', 'wpfront-user-role-editor');
279
+ } else {
280
+ if($this->is_role_exists($role_name)) {
281
+ $is_role_name_valid = false;
282
+ $error = __('This role already exists in this site.', 'wpfront-user-role-editor');
283
+ }
284
+ }
285
+ } else {
286
+ $is_role_name_valid = false;
287
+ $error = __('Role name cannot be empty.', 'wpfront-user-role-editor');
288
+ }
289
+
290
+ return [$role_name, $is_role_name_valid, $error];
291
+ }
292
+
293
+ protected function get_display_name_posted() {
294
+ $display_name = '';
295
+ $is_display_name_valid = true;
296
+ $error = null;
297
+
298
+ if(!empty($_POST['display_name'])) {
299
+ $display_name = trim($_POST['display_name']);
300
+ if($display_name === '') {
301
+ $is_display_name_valid = false;
302
+ $error = __('Display name cannot be empty.', 'wpfront-user-role-editor');
303
+ }
304
+ } else {
305
+ $is_display_name_valid = false;
306
+ $error = __('Display name cannot be empty.', 'wpfront-user-role-editor');
307
+ }
308
+
309
+ return [$display_name, $is_display_name_valid, $error];
310
+ }
311
+
312
+ protected function get_capabilities_posted() {
313
+ $capabilities = array();
314
+
315
+ if(!empty($_POST['capabilities'])) {
316
+ foreach ($_POST['capabilities'] as $key => $value) {
317
+ if(isset($value['allow'])) {
318
+ $capabilities[$key] = true;
319
+ } elseif(isset($value['deny'])) {
320
+ $capabilities[$key] = false;
321
+ }
322
+ }
323
+ }
324
+
325
+ return $capabilities;
326
+ }
327
+
328
+ protected function is_role_exists($role_name) {
329
+ return $this->RolesHelperClass::is_role($role_name);
330
+ }
331
+
332
+ protected function is_role_editable($role_name) {
333
+ $editable_roles = get_editable_roles();
334
+ return array_key_exists($role_name, $editable_roles);
335
+ }
336
+
337
+ /**
338
+ * Returns capability group info.
339
+ *
340
+ * @return array
341
+ */
342
+ public function get_meta_box_groups() {
343
+ $caps_groups = $this->RolesHelperClass::get_capabilty_groups();
344
+ $role_data = $this->get_role_data();
345
+
346
+ $caps_data = array();
347
+
348
+ foreach ($caps_groups as $group => $obj) {
349
+ $caps = $this->RolesHelperClass::get_group_capabilities($obj);
350
+
351
+ if(empty($caps)) {
352
+ continue;
353
+ }
354
+
355
+ $is_disabled = false;
356
+ if(!empty($role_data)) {
357
+ $is_disabled = $role_data['is_readonly'];
358
+ }
359
+
360
+ if($caps === 'defaulted') {
361
+ $is_disabled = true;
362
+ } else {
363
+ if($group == 'network' && !$this->RolesHelperClass::can_set_network_capability()) {
364
+ $is_disabled = true;
365
+ }
366
+ }
367
+
368
+ $caps_data[$group] = (OBJECT) array(
369
+ 'caps' => $caps,
370
+ 'display_name' => $obj->label,
371
+ 'deprecated' => false,
372
+ 'disabled' => $is_disabled,
373
+ 'hidden' => false,
374
+ 'key' => $group,
375
+ 'group_obj' => $obj,
376
+ 'mode' => $this->mode
377
+ );
378
+ }
379
+
380
+ return $caps_data;
381
+ }
382
+
383
+ /**
384
+ * Displays the add/edit role view.
385
+ */
386
+ public function view() {
387
+ $cap = $this->get_cap();
388
+
389
+ if(!current_user_can($cap)) {
390
+ $this->WPFURE->permission_denied();
391
+ return;
392
+ }
393
+
394
+ $objView = new $this->ViewClass();
395
+ $objView->view();
396
+ }
397
+
398
+ /**
399
+ * Returns the 'Add New' role menu url.
400
+ *
401
+ * @return string
402
+ */
403
+ public function get_add_new_role_url() {
404
+ return menu_page_url($this->get_menu_slug(), false);
405
+ }
406
+
407
+ /**
408
+ * Retunrs the edit url for the passed role.
409
+ *
410
+ * @param string $role_name
411
+ * @return string
412
+ */
413
+ public function get_edit_role_url($role_name) {
414
+ return menu_page_url($this->RolesList->get_menu_slug(), false) . '&edit_role=' . $role_name;
415
+ }
416
+
417
+ /**
418
+ * Returns json string for copy capabilities ajax call back.
419
+ *
420
+ * @return string
421
+ */
422
+ public function copy_capabilities_callback() {
423
+ check_ajax_referer('copy-capabilities', 'nonce');
424
+
425
+ if (empty($_POST['role'])) {
426
+ wp_die('{}');
427
+ }
428
+
429
+ $caps = $this->RolesHelperClass::get_capabilities($_POST['role']);
430
+ if ($caps == null) {
431
+ wp_die('{}');
432
+ }
433
+
434
+ wp_die(json_encode($caps));
435
+ }
436
+
437
+ /**
438
+ * Sets the help tab of edit roles.
439
+ */
440
+ protected function set_add_help_tab() {
441
+ $tabs = array(
442
+ array(
443
+ 'id' => 'overview',
444
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
445
+ 'content' => '<p>'
446
+ . __('This screen allows you to add a new role within your site.', 'wpfront-user-role-editor')
447
+ . '</p>'
448
+ . '<p>'
449
+ . __('You can copy capabilities from existing roles using the Copy from drop down list. Select the role you want to copy from, then click Apply to copy the capabilities. You can select or deselect capabilities even after you copy.', 'wpfront-user-role-editor')
450
+ . '</p>'
451
+ ),
452
+ array(
453
+ 'id' => 'displayname',
454
+ 'title' => __('Display Name', 'wpfront-user-role-editor'),
455
+ 'content' => '<p>'
456
+ . __('Use the Display Name field to set the display name for the new role. WordPress uses display name to display this role within your site. This field is required.', 'wpfront-user-role-editor')
457
+ . '</p>'
458
+ ),
459
+ array(
460
+ 'id' => 'rolename',
461
+ 'title' => __('Role Name', 'wpfront-user-role-editor'),
462
+ 'content' => '<p>'
463
+ . __('Use the Role Name field to set the role name for the new role. WordPress uses role name to identify this role within your site. Once set role name cannot be changed. This field is required. This plugin will auto populate role name from the display name you have given, but you can change it.', 'wpfront-user-role-editor')
464
+ . '</p>'
465
+ ),
466
+ array(
467
+ 'id' => 'capabilities',
468
+ 'title' => __('Capabilities', 'wpfront-user-role-editor'),
469
+ 'content' => '<p>'
470
+ . __('Capabilities are displayed as different groups for easy access. The Roles section displays capabilities created by this plugin. The Other Capabilities section displays non-standard capabilities within your site. These are usually created by plugins and themes. Use the check boxes to select the capabilities required for this new role.', 'wpfront-user-role-editor')
471
+ . '</p>'
472
+ )
473
+ );
474
+
475
+ $sidebar = array(
476
+ array(
477
+ __('Documentation on Add New Role', 'wpfront-user-role-editor'),
478
+ 'add-role/'
479
+ )
480
+ );
481
+
482
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
483
+ }
484
+
485
+ /**
486
+ * Sets the help tab of edit roles.
487
+ */
488
+ public function set_edit_help_tab() {
489
+ $tabs = array(
490
+ array(
491
+ 'id' => 'overview',
492
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
493
+ 'content' => '<p>'
494
+ . __('This screen allows you to edit a role within your site.', 'wpfront-user-role-editor')
495
+ . '</p>'
496
+ . '<p>'
497
+ . __('You can copy capabilities from existing roles using the Copy from drop down list. Select the role you want to copy from, then click Apply to copy the capabilities. You can select or deselect capabilities even after you copy.', 'wpfront-user-role-editor')
498
+ . '</p>'
499
+ ),
500
+ array(
501
+ 'id' => 'displayname',
502
+ 'title' => __('Display Name', 'wpfront-user-role-editor'),
503
+ 'content' => '<p>'
504
+ . __('Use the Display Name field to edit display name of the role. WordPress uses display name to display this role within your site. This field is required.', 'wpfront-user-role-editor')
505
+ . '</p>'
506
+ ),
507
+ array(
508
+ 'id' => 'rolename',
509
+ 'title' => __('Role Name', 'wpfront-user-role-editor'),
510
+ 'content' => '<p>'
511
+ . __('Role Name is read only. WordPress uses role name to identify this role within your site.', 'wpfront-user-role-editor')
512
+ . '</p>'
513
+ ),
514
+ array(
515
+ 'id' => 'capabilities',
516
+ 'title' => __('Capabilities', 'wpfront-user-role-editor'),
517
+ 'content' => '<p>'
518
+ . __('Capabilities are displayed as different groups for easy access. The Roles section displays capabilities created by this plugin. The Other Capabilities section displays non-standard capabilities within your site. These are usually created by plugins and themes. Use the check boxes to select the capabilities required.', 'wpfront-user-role-editor')
519
+ . '</p>'
520
+ )
521
+ );
522
+
523
+ $sidebar = array(
524
+ array(
525
+ __('Documentation on Edit Role', 'wpfront-user-role-editor'),
526
+ 'edit-role/'
527
+ )
528
+ );
529
+
530
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
531
+ }
532
+ }
533
+
534
+ add_action('wpfront_ure_init', '\WPFront\URE\Roles\WPFront_User_Role_Editor_Role_Add_Edit::init');
535
+
536
+ }
includes/roles/class-role-delete.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Delete Role
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/template-role-delete.php';
38
+
39
+ if (!class_exists('\WPFront\URE\Roles\WPFront_User_Role_Editor_Role_Delete')) {
40
+
41
+ /**
42
+ * Delete Role
43
+ *
44
+ * @author Syam Mohan <syam@wpfront.com>
45
+ * @copyright 2014 WPFront.com
46
+ */
47
+ class WPFront_User_Role_Editor_Role_Delete extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
48
+
49
+ protected $role_data;
50
+
51
+ protected $RolesList;
52
+
53
+ protected function setUp() {
54
+ $this->_setUp('delete_roles');
55
+
56
+ $this->ViewClass = WPFront_User_Role_Editor_Role_Delete_View::class;
57
+ $this->RolesList = WPFront_User_Role_Editor_Roles_List::instance();
58
+ }
59
+
60
+ protected function initialize() {
61
+ }
62
+
63
+ /**
64
+ * Performs delete roles functionality.
65
+ * Returns whether current user action is delete role.
66
+ *
67
+ * @return boolean
68
+ */
69
+ public function delete_role() {
70
+ if(!empty($_POST['confirm-delete'])) {
71
+ check_admin_referer('delete-roles');
72
+
73
+ if(!current_user_can($this->get_cap())) {
74
+ $this->WPFURE->permission_denied();
75
+ return true;
76
+ }
77
+
78
+ $roles = $this->get_delete_data();
79
+
80
+ foreach ($roles as $key => $value) {
81
+ if($value->is_deletable) {
82
+ remove_role($key);
83
+ }
84
+ }
85
+
86
+ if(wp_safe_redirect($this->RolesList->get_list_roles_url(). '&roles-deleted=true')) {
87
+ exit();
88
+ }
89
+
90
+ return true;
91
+ }
92
+
93
+ if(!empty($_GET['delete_role'])) {
94
+ return true;
95
+ }
96
+
97
+ if(!empty($_POST['action_top']) && $_POST['action_top'] === 'delete' && !empty($_POST['selected-roles'])) {
98
+ return true;
99
+ }
100
+
101
+ if(!empty($_POST['action_bottom']) && $_POST['action_bottom'] === 'delete' && !empty($_POST['selected-roles'])) {
102
+ return true;
103
+ }
104
+
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Displays delete roles view.
110
+ */
111
+ public function view() {
112
+ if(!current_user_can($this->get_cap())) {
113
+ $this->WPFURE->permission_denied();
114
+ return;
115
+ }
116
+
117
+ $objView = new $this->ViewClass();
118
+ $objView->view();
119
+ }
120
+
121
+ /**
122
+ * Returns an array of role names submitted for delete.
123
+ *
124
+ * @return array
125
+ */
126
+ protected function get_submitted_roles() {
127
+ if(!empty($_POST['confirm-delete'])) {
128
+ return array_keys($_POST['delete-roles']);
129
+ }
130
+
131
+ if(!empty($_GET['delete_role'])) {
132
+ return array(trim($_GET['delete_role']));
133
+ }
134
+
135
+ if(!empty($_POST['action_top']) && $_POST['action_top'] === 'delete' && !empty($_POST['selected-roles'])) {
136
+ return array_keys($_POST['selected-roles']);
137
+ }
138
+
139
+ if(!empty($_POST['action_bottom']) && $_POST['action_bottom'] === 'delete' && !empty($_POST['selected-roles'])) {
140
+ return array_keys($_POST['selected-roles']);
141
+ }
142
+
143
+ return array();
144
+ }
145
+
146
+ /**
147
+ * Returns an array containing role data, with delete permission information.
148
+ *
149
+ * @return array
150
+ */
151
+ public function get_delete_data() {
152
+ if($this->role_data !== null) {
153
+ return $this->role_data;
154
+ }
155
+
156
+ $this->role_data = array();
157
+ $editable_roles = get_editable_roles();
158
+ $delete_roles = $this->get_submitted_roles();
159
+
160
+ $user = wp_get_current_user();
161
+ $user_roles = $user->roles;
162
+
163
+ foreach ($delete_roles as $role) {
164
+ if ($this->RolesHelperClass::is_role($role)) {
165
+ $status_message = '';
166
+ $is_deletable = true;
167
+
168
+ if(!$this->RolesHelperClass::is_super_admin()) {
169
+ if (!array_key_exists($role, $editable_roles)) {
170
+ $status_message = __('This role cannot be deleted: Permission denied.', 'wpfront-user-role-editor');
171
+ $is_deletable = false;
172
+ } elseif (in_array($role, $user_roles)) {
173
+ $status_message = __('Current user\'s role cannot be deleted.', 'wpfront-user-role-editor');
174
+ $is_deletable = false;
175
+ }
176
+ }
177
+
178
+ $this->role_data[$role] = (OBJECT) array(
179
+ 'name' => $role,
180
+ 'display_name' => $this->RolesHelperClass::get_display_name($role),
181
+ 'is_deletable' => $is_deletable,
182
+ 'status_message' => $status_message
183
+ );
184
+ }
185
+ }
186
+
187
+ return $this->role_data;
188
+ }
189
+
190
+ /**
191
+ * Returns the delete role url for the passed role name.
192
+ *
193
+ * @param string $role_name
194
+ * @return string
195
+ */
196
+ public function get_delete_role_url($role_name) {
197
+ return menu_page_url($this->RolesList->get_menu_slug(), false) . '&delete_role=' . $role_name;
198
+ }
199
+
200
+ /**
201
+ * Sets the help tab of delete roles.
202
+ */
203
+ public function set_help_tab() {
204
+ $tabs = array(
205
+ array(
206
+ 'id' => 'overview',
207
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
208
+ 'content' => '<p>'
209
+ . __('This screen allows you to delete roles from your WordPress site.', 'wpfront-user-role-editor')
210
+ . '</p>'
211
+ . '<p>'
212
+ . __('Use the Roles List screen to select the roles you want to delete. You can delete individual roles using the Delete row action link or delete multiple roles at the same time using the bulk action.', 'wpfront-user-role-editor')
213
+ . '</p>'
214
+ . '<p>'
215
+ . __('You cannot delete administrator role, current user’s role and roles you do not have permission to.', 'wpfront-user-role-editor')
216
+ . '</p>'
217
+ )
218
+ );
219
+
220
+ $sidebar = array(
221
+ array(
222
+ __('Documentation on Delete Roles', 'wpfront-user-role-editor'),
223
+ 'delete-role/'
224
+ )
225
+ );
226
+
227
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
228
+ }
229
+
230
+ }
231
+
232
+ }
includes/roles/class-roles-list.php ADDED
@@ -0,0 +1,669 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor List Roles
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/template-roles-list.php';
38
+ require_once dirname(__FILE__) . '/class-role-delete.php';
39
+
40
+ if (!class_exists('\WPFront\URE\Roles\WPFront_User_Role_Editor_Roles_List')) {
41
+
42
+ /**
43
+ * List Roles controller.
44
+ *
45
+ * @author Syam Mohan <syam@wpfront.com>
46
+ * @copyright 2014 WPFront.com
47
+ */
48
+ class WPFront_User_Role_Editor_Roles_List extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
49
+
50
+ protected $objView = null;
51
+ protected $role_data = null;
52
+ protected $role_user_counts = null;
53
+
54
+ protected $AddEditViewClass;
55
+ protected $DeleteViewClass;
56
+
57
+ protected $UserProfile;
58
+
59
+ protected function setUp() {
60
+ $this->_setUp('list_roles', 'wpfront-user-role-editor-all-roles');
61
+
62
+ $this->ViewClass = WPFront_User_Role_Editor_Roles_List_View::class;
63
+ $this->AddEditViewClass = WPFront_User_Role_Editor_Role_Add_Edit::class;
64
+ $this->DeleteViewClass = WPFront_User_Role_Editor_Role_Delete::class;
65
+
66
+ $this->UserProfile = \WPFront\URE\Assign_Migrate\WPFront_User_Role_Editor_User_Profile::instance();
67
+ }
68
+
69
+ protected function initialize() {
70
+ if(!$this->in_admin_ui()) {
71
+ return;
72
+ }
73
+
74
+ $this->set_admin_menu(__('All Roles', 'wpfront-user-role-editor'), __('All Roles', 'wpfront-user-role-editor'));
75
+
76
+ add_filter('wpfront_ure_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 10, 1);
77
+ add_filter('wpfront_ure_ms_options_register_ui_field', array($this, 'wpfront_ure_options_register_ui_field'), 10, 1);
78
+
79
+ //Set Site Role column with links
80
+ add_filter('manage_users_columns', array($this, 'manage_users_columns'), PHP_INT_MAX);
81
+ add_filter('manage_users_custom_column', array($this, 'manage_users_custom_column'), PHP_INT_MAX, 3);
82
+ }
83
+
84
+ public function admin_print_scripts() {
85
+ parent::admin_print_scripts();
86
+
87
+ wp_enqueue_script('postbox');
88
+ wp_enqueue_script('jquery-ui-draggable');
89
+ }
90
+
91
+ /**
92
+ * Hooks on options class to display ui.
93
+ *
94
+ * @param array $option_keys
95
+ */
96
+ public function wpfront_ure_options_register_ui_field($option_keys) {
97
+ $option_keys['override_edit_permissions'] = '';
98
+
99
+ add_action('wpfront_ure_options_ui_field_override_edit_permissions_label', array($this, 'options_ui_label'));
100
+ add_action('wpfront_ure_options_ui_field_override_edit_permissions', array($this, 'options_ui_field'));
101
+ add_action('wpfront_ure_options_ui_field_override_edit_permissions_update', array($this, 'options_ui_update'));
102
+ add_action('wpfront_ure_options_ui_field_override_edit_permissions_help', array($this, 'options_ui_help'));
103
+
104
+ return $option_keys;
105
+ }
106
+
107
+ public function options_ui_label() {
108
+ echo __('Override Role Edit Permissions', 'wpfront-user-role-editor');
109
+ }
110
+
111
+ public function options_ui_field() {
112
+ $key = 'override_edit_permissions';
113
+
114
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
115
+ $checked = !empty($_POST[$key]);
116
+ } else {
117
+ if(is_network_admin()) {
118
+ $checked = $this->Options->get_network_option_boolean($key);
119
+ } else {
120
+ $checked = $this->Options->get_option_boolean($key, true);
121
+ }
122
+ }
123
+
124
+ $checked = $checked ? 'checked' : '';
125
+
126
+ echo "<input type='checkbox' name='$key' $checked />";
127
+ }
128
+
129
+ public function options_ui_update() {
130
+ $key = 'override_edit_permissions';
131
+ $value = !empty($_POST[$key]);
132
+
133
+ if(is_network_admin()) {
134
+ $this->Options->set_network_option($key, $value, 'ms_', false);
135
+ } else {
136
+ $this->Options->set_option($key, $value, false);
137
+ }
138
+ }
139
+
140
+ public function options_ui_help() {
141
+ return '<strong>' . __('Override Role Edit Permissions', 'wpfront-user-role-editor') . '</strong>: ' . __('Allows you to edit non-editable roles.', 'wpfront-user-role-editor');
142
+ }
143
+
144
+ /**
145
+ * Hooks on load-page. Sets the view controller based on current user action.
146
+ *
147
+ */
148
+ public function load_view() {
149
+ if(!parent::load_view()) {
150
+ return;
151
+ }
152
+
153
+ add_filter('editable_roles', array($this, 'editable_roles_filter_callback'), PHP_INT_MAX, 1);
154
+
155
+ if($this->set_default_role()) {
156
+ return;
157
+ }
158
+
159
+ $this->objView = $this->AddEditViewClass::instance();
160
+ if($this->objView->edit_role()) {
161
+ $this->objView->set_edit_help_tab();
162
+ return;
163
+ }
164
+
165
+ $this->objView = $this->DeleteViewClass::instance();
166
+ if($this->objView->delete_role()) {
167
+ $this->objView->set_help_tab();
168
+ return;
169
+ }
170
+
171
+ $this->objView = new $this->ViewClass();
172
+ $this->set_help_tab();
173
+ }
174
+
175
+ /**
176
+ * Displays the view for this controller.
177
+ */
178
+ public function view() {
179
+ if(!parent::view()) {
180
+ return;
181
+ }
182
+
183
+ $this->objView->view();
184
+ }
185
+
186
+ /**
187
+ * Returns an array containing filter links information.
188
+ *
189
+ * @return array
190
+ */
191
+ public function get_list_filter_data() {
192
+ $filter_data = array();
193
+
194
+ $roles = $this->RolesHelperClass::get_roles();
195
+ $page = $this->get_self_url();
196
+
197
+ $filter_data['all'] = array(
198
+ 'display' => __('All', 'wpfront-user-role-editor'),
199
+ 'url' => $page,
200
+ 'count' => count($roles)
201
+ );
202
+
203
+ $count_users = $this->get_role_user_counts();
204
+
205
+ $count = 0;
206
+ foreach ($roles as $role_name) {
207
+ if(isset($count_users[$role_name]) && $count_users[$role_name] > 0)
208
+ $count++;
209
+ }
210
+
211
+ $filter_data['haveusers'] = array(
212
+ 'display' => __('Having Users', 'wpfront-user-role-editor'),
213
+ 'url' => $page . '&list=haveusers',
214
+ 'count' => $count
215
+ );
216
+
217
+ $filter_data['nousers'] = array(
218
+ 'display' => __('No Users', 'wpfront-user-role-editor'),
219
+ 'url' => $page . '&list=nousers',
220
+ 'count' => count($roles) - $count
221
+ );
222
+
223
+ $count = 0;
224
+ foreach ($roles as $role_name) {
225
+ if ($this->RolesHelperClass::is_default_role($role_name))
226
+ $count++;
227
+ }
228
+ $filter_data['builtin'] = array(
229
+ 'display' => __('Built-In', 'wpfront-user-role-editor'),
230
+ 'url' => $page . '&list=builtin',
231
+ 'count' => $count
232
+ );
233
+
234
+ $filter_data['custom'] = array(
235
+ 'display' => __('Custom', 'wpfront-user-role-editor'),
236
+ 'url' => $page . '&list=custom',
237
+ 'count' => count($roles) - $count
238
+ );
239
+
240
+ return $filter_data;
241
+ }
242
+
243
+ /**
244
+ * Returns an array containing role information formatted for display.
245
+ *
246
+ * @return array
247
+ */
248
+ public function get_role_data() {
249
+ if($this->role_data !== null) {
250
+ return $this->role_data;
251
+ }
252
+
253
+ $roles = $this->RolesHelperClass::get_names();
254
+
255
+ $editable_roles = get_editable_roles();
256
+ $user_default = get_option('default_role');
257
+ $default_sec_roles = $this->UserProfile->get_new_user_default_secondary_roles();
258
+
259
+ $count_users = $this->get_role_user_counts();
260
+
261
+ $role_data = array();
262
+
263
+ foreach ($roles as $key => $value) {
264
+ $caps = $this->RolesHelperClass::get_capabilities($key);
265
+ $allowed_caps_count = count(array_filter($caps));
266
+ $denied_caps_count = count($caps) - $allowed_caps_count;
267
+
268
+ $user_default_order = $key == $user_default ? 1 : (in_array($key, $default_sec_roles) ? 2 : 0);
269
+
270
+ $role_data[$key] = array(
271
+ 'role_name' => $key,
272
+ 'display_name' => $value,
273
+ 'is_default' => $this->RolesHelperClass::is_default_role($key),
274
+ 'user_count' => isset($count_users[$key]) ? $count_users[$key] : 0,
275
+ 'caps_count' => $allowed_caps_count . ' / ' . $denied_caps_count,
276
+ 'user_default' => $user_default_order
277
+ );
278
+
279
+ $role_data = $this->role_data_set_edit_url($key, $editable_roles, $role_data);
280
+ $role_data = $this->role_data_set_delete_url($key, $editable_roles, $role_data);
281
+ $role_data = $this->role_data_set_default_url($key, $user_default_order, $role_data);
282
+ }
283
+
284
+ $this->role_data = $role_data;
285
+
286
+ return $role_data;
287
+ }
288
+
289
+ /**
290
+ * Returns number of users per role.
291
+ *
292
+ * @return int[] role_name=>count
293
+ */
294
+ protected function get_role_user_counts() {
295
+ if($this->role_user_counts !== null) {
296
+ return $this->role_user_counts;
297
+ }
298
+
299
+ $count_users = count_users();
300
+ $count_users = $count_users['avail_roles'];
301
+
302
+ $this->role_user_counts = $count_users;
303
+
304
+ return $count_users;
305
+ }
306
+
307
+
308
+ /**
309
+ * Helper function to set role data edit url details.
310
+ *
311
+ * @param string $role_name
312
+ * @param array $editable_roles
313
+ * @param array $role_data
314
+ */
315
+ protected function role_data_set_edit_url($role_name, $editable_roles, $role_data) {
316
+ if (current_user_can('edit_roles')) {
317
+ $role_data[$role_name]['edit_url'] = $this->get_edit_role_url($role_name);
318
+ $role_data[$role_name]['is_editable'] = array_key_exists($role_name, $editable_roles);
319
+ } else {
320
+ $role_data[$role_name]['edit_url'] = null;
321
+ $role_data[$role_name]['is_editable'] = false;
322
+ }
323
+
324
+ return $role_data;
325
+ }
326
+
327
+ /**
328
+ * Helper function to set role data delete url details.
329
+ *
330
+ * @param string $role_name
331
+ * @param array $editable_roles
332
+ * @param array $role_data
333
+ */
334
+ protected function role_data_set_delete_url($role_name, $editable_roles, $role_data) {
335
+ if (current_user_can('delete_roles')) {
336
+ if (!array_key_exists($role_name, $editable_roles))
337
+ $role_data[$role_name]['delete_url'] = null;
338
+ else {
339
+ $role_data[$role_name]['delete_url'] = $this->get_delete_role_url($role_name);
340
+ }
341
+ } else {
342
+ $role_data[$role_name]['delete_url'] = null;
343
+ }
344
+
345
+ return $role_data;
346
+ }
347
+
348
+ /**
349
+ * Helper function to set role data set default role url details.
350
+ *
351
+ * @param string $role_name
352
+ * @param string $user_default_role
353
+ * @param array $role_data
354
+ */
355
+ protected function role_data_set_default_url($role_name, $user_default_order, $role_data) {
356
+ if(current_user_can('manage_options')) {
357
+ $role_data[$role_name]['set_default_url'] = $this->get_set_default_role_url($role_name, $user_default_order);
358
+ } else {
359
+ $role_data[$role_name]['set_default_url'] = null;
360
+ }
361
+
362
+ return $role_data;
363
+ }
364
+
365
+ /**
366
+ * Returns set new user default role url for the passed role with nonce.
367
+ *
368
+ * @param string $role_name
369
+ * @return string
370
+ */
371
+ protected function get_set_default_role_url($role_name, $user_default_order) {
372
+ $url = add_query_arg(array(
373
+ 'new_user_default_role' => $role_name,
374
+ 'action' => $user_default_order > 0 ? 'minus' : 'plus'
375
+ ), $this->get_self_url());
376
+
377
+ return wp_nonce_url($url, 'default_role_action');
378
+ }
379
+
380
+ /**
381
+ * Updates the new user default role based on request params.
382
+ * Returns whether user action is set default role.
383
+ *
384
+ * @return boolean
385
+ */
386
+ protected function set_default_role() {
387
+ if(!empty($_GET['new_user_default_role'])) {
388
+ check_admin_referer('default_role_action');
389
+
390
+ if(!current_user_can('manage_options')) {
391
+ $this->WPFURE->permission_denied();
392
+ return true;
393
+ }
394
+
395
+ $role = trim($_GET['new_user_default_role']);
396
+
397
+ if(!$this->RolesHelperClass::is_role($role) || empty($_GET['action'])) {
398
+ if(wp_safe_redirect($this->get_self_url())) {
399
+ exit();
400
+ }
401
+ return true;
402
+ }
403
+
404
+ $action = $_GET['action'];
405
+ $default = get_option('default_role');
406
+ $default_sec_roles = $this->UserProfile->get_new_user_default_secondary_roles();
407
+ if($action == 'minus') {
408
+ if($role == $default) {
409
+ $r = reset($default_sec_roles);
410
+ update_option('default_role', $r);
411
+ array_splice($default_sec_roles, 0, 1);
412
+ }
413
+
414
+ $index = array_search($role, $default_sec_roles);
415
+ if($index !== false) {
416
+ array_splice($default_sec_roles, $index, 1);
417
+ }
418
+ } elseif($action == 'plus') {
419
+ if(!$this->RolesHelperClass::is_role($default)) {
420
+ if($role == $this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY) {
421
+ update_option('default_role', $role);
422
+ } else {
423
+ $r = reset($default_sec_roles);
424
+ if($r === false) {
425
+ update_option('default_role', $role);
426
+ } else {
427
+ update_option('default_role', $r);
428
+ array_splice($default_sec_roles, 0, 1);
429
+ $default_sec_roles[] = $role;
430
+ }
431
+ }
432
+ } else {
433
+ if($role == $this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY) {
434
+ update_option('default_role', $role);
435
+ array_unshift($default_sec_roles, $default);
436
+ } else {
437
+ $default_sec_roles[] = $role;
438
+ }
439
+ }
440
+ }
441
+ $this->UserProfile->set_new_user_default_secondary_roles($default_sec_roles);
442
+
443
+ if(wp_safe_redirect($this->get_self_url() . '&default-role-updated=true')) {
444
+ exit();
445
+ }
446
+
447
+ return true;
448
+ }
449
+
450
+ return false;
451
+ }
452
+
453
+ /**
454
+ * Rename role column to user_role column.
455
+ *
456
+ * @param array $columns
457
+ * @return array
458
+ */
459
+ public function manage_users_columns($columns) {
460
+ if(current_user_can('list_roles') && current_user_can('edit_roles') && array_key_exists('role', $columns)) {
461
+ $keys = array_keys($columns);
462
+ $keys[array_search('role', $keys)] = 'user_role';
463
+ return array_combine($keys, $columns);
464
+ }
465
+
466
+ return $columns;
467
+ }
468
+
469
+ /**
470
+ * Returns edit link on user_role custom column.
471
+ *
472
+ * @param string $value
473
+ * @param string $column
474
+ * @param int $user_id
475
+ * @return string
476
+ */
477
+ public function manage_users_custom_column($value, $column, $user_id) {
478
+ if($column === 'user_role') {
479
+ $user = get_userdata($user_id);
480
+ $roles = $user->roles;
481
+ $links = array();
482
+ if(empty($roles)) {
483
+ $value = __('None', 'wpfront-user-role-editor');
484
+ } else {
485
+ foreach ($roles as $role) {
486
+ $display = $this->RolesHelperClass::get_display_name($role);
487
+ $url = $this->get_edit_role_url($role);
488
+ $links[] = "<a href='$url'>$display</a>";
489
+ }
490
+
491
+ return implode(', ', $links);
492
+ }
493
+ }
494
+
495
+ return $value;
496
+ }
497
+
498
+ /**
499
+ * Returns 'All Roles' menu url.
500
+ *
501
+ * @return string
502
+ */
503
+ public function get_list_roles_url() {
504
+ return $this->get_self_url();
505
+ }
506
+
507
+ /**
508
+ * Returns 'Add New' role menu url.
509
+ *
510
+ * @return string
511
+ */
512
+ public function get_add_new_role_url() {
513
+ return $this->AddEditViewClass::instance()->get_add_new_role_url();
514
+ }
515
+
516
+ /**
517
+ * Returns edit url for the passed role name.
518
+ *
519
+ * @param string $role_name
520
+ * @return string
521
+ */
522
+ protected function get_edit_role_url($role_name) {
523
+ return $this->AddEditViewClass::instance()->get_edit_role_url($role_name);
524
+ }
525
+
526
+ /**
527
+ * Returns delete url for the passed role name.
528
+ *
529
+ * @param string $role_name
530
+ * @return string
531
+ */
532
+ protected function get_delete_role_url($role_name) {
533
+ return $this->DeleteViewClass::instance()->get_delete_role_url($role_name);
534
+ }
535
+
536
+ /**
537
+ * Returns override_edit_permissions setting value.
538
+ *
539
+ * @return boolean
540
+ */
541
+ public function override_edit_permissions() {
542
+ return $this->Options->get_option_boolean('override_edit_permissions', true);
543
+ }
544
+
545
+ /**
546
+ * Hooks into editable_roles WordPress filter.
547
+ * @param array $roles
548
+ * @return array
549
+ */
550
+ public function editable_roles_filter_callback($roles) {
551
+ if($this->RolesHelperClass::is_super_admin()) {
552
+ return wp_roles()->roles;
553
+ }
554
+
555
+ if($this->override_edit_permissions()) {
556
+ $roles = wp_roles()->roles;
557
+ } else {
558
+ unset($roles[$this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY]);
559
+ }
560
+
561
+ if(!defined('WPFURE_ADMINISTRATOR_ROLE_EDIT') || !WPFURE_ADMINISTRATOR_ROLE_EDIT) {
562
+ unset($roles[$this->RolesHelperClass::ADMINISTRATOR_ROLE_KEY]);
563
+ }
564
+
565
+ return $roles;
566
+ }
567
+
568
+ /**
569
+ * Sets the help tab of list roles.
570
+ */
571
+ protected function set_help_tab() {
572
+ $tabs = array(
573
+ array(
574
+ 'id' => 'overview',
575
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
576
+ 'content' => '<p>'
577
+ . __('This screen lists all the existing roles within your site.', 'wpfront-user-role-editor')
578
+ . '</p>'
579
+ . '<p>'
580
+ . __('To add a new role, click the Add New button at the top of the screen or Add New in the Roles menu section.', 'wpfront-user-role-editor')
581
+ . '</p>'
582
+ ),
583
+ array(
584
+ 'id' => 'columns',
585
+ 'title' => __('Columns', 'wpfront-user-role-editor'),
586
+ 'content' => '<p><strong>'
587
+ . __('Display Name', 'wpfront-user-role-editor')
588
+ . '</strong>: '
589
+ . __('Used to display this role within this site.', 'wpfront-user-role-editor')
590
+ . '</p>'
591
+ . '<p><strong>'
592
+ . __('Role Name', 'wpfront-user-role-editor')
593
+ . '</strong>: '
594
+ . __('Is used by WordPress to identify this role.', 'wpfront-user-role-editor')
595
+ . '</p>'
596
+ . '<p><strong>'
597
+ . __('Type', 'wpfront-user-role-editor')
598
+ . '</strong>: '
599
+ . __('Says whether the role is a WordPress built-in role or not. There are five built-in roles.', 'wpfront-user-role-editor')
600
+ . '</p>'
601
+ . '<p><strong>'
602
+ . __('User Default', 'wpfront-user-role-editor')
603
+ . '</strong>: '
604
+ . __('Displays whether a role is the default role of a new user.', 'wpfront-user-role-editor')
605
+ . '</p>'
606
+ . '<p><strong>'
607
+ . __('Users', 'wpfront-user-role-editor')
608
+ . '</strong>: '
609
+ . __('Number of users in that role.', 'wpfront-user-role-editor')
610
+ . '</p>'
611
+ . '<p><strong>'
612
+ . __('Capabilities', 'wpfront-user-role-editor')
613
+ . '</strong>: '
614
+ . __('Number of capabilities that role have.', 'wpfront-user-role-editor')
615
+ . '</p>'
616
+ . '<p><strong>'
617
+ . __('Menu Edited', 'wpfront-user-role-editor')
618
+ . '</strong>: '
619
+ . __('Displays whether the menu has been edited for this role. This is a pro feature.', 'wpfront-user-role-editor')
620
+ . '</p>'
621
+ ),
622
+ array(
623
+ 'id' => 'actions',
624
+ 'title' => __('Actions', 'wpfront-user-role-editor'),
625
+ 'content' => '<p>'
626
+ . __('Hovering over a row in the roles list will display action links that allow you to manage roles. You can perform the following actions:', 'wpfront-user-role-editor')
627
+ . '</p>'
628
+ . '<p><strong>'
629
+ . __('View', 'wpfront-user-role-editor')
630
+ . '</strong>: '
631
+ . __('Display details about the role. You can see the capabilities assigned for that role. View link will only appear when you do not have permission to edit that role.', 'wpfront-user-role-editor')
632
+ . '</p>'
633
+ . '<p><strong>'
634
+ . __('Edit', 'wpfront-user-role-editor')
635
+ . '</strong>: '
636
+ . __('Allows you to edit that role. You can see the capabilities assigned for that role and also edit them. Edit link will only appear when you have permission to edit that role.', 'wpfront-user-role-editor')
637
+ . '</p>'
638
+ . '<p><strong>'
639
+ . __('Delete', 'wpfront-user-role-editor')
640
+ . '</strong>: '
641
+ . __('Allows you to delete that role. Delete action will not appear if you do not have permission to delete that role.', 'wpfront-user-role-editor')
642
+ . '</p>'
643
+ . '<p><strong>'
644
+ . __('Default', 'wpfront-user-role-editor')
645
+ . '</strong>: '
646
+ . __('Allows you to set that role as the default role for new user registration.', 'wpfront-user-role-editor')
647
+ . '</p>'
648
+ . '<p><strong>'
649
+ . __('Edit Menu', 'wpfront-user-role-editor')
650
+ . '</strong>: '
651
+ . __('Takes you to the menu editor screen for that role. You need "edit_role_menus" capability for this link to appear. This is a pro feature.', 'wpfront-user-role-editor')
652
+ . '</p>'
653
+ )
654
+ );
655
+
656
+ $sidebar = array(
657
+ array(
658
+ __('Documentation on Roles', 'wpfront-user-role-editor'),
659
+ 'list-roles/'
660
+ )
661
+ );
662
+
663
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
664
+ }
665
+
666
+ }
667
+
668
+ WPFront_User_Role_Editor_Roles_List::load();
669
+ }
includes/roles/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
includes/roles/template-role-add-edit.php ADDED
@@ -0,0 +1,721 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Role Add/Edit
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies;
38
+ use WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type;
39
+
40
+ if (!class_exists('WPFront\URE\Roles\WPFront_User_Role_Editor_Role_Add_Edit_View')) {
41
+
42
+ class WPFront_User_Role_Editor_Role_Add_Edit_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
43
+
44
+ protected $RoleAddEdit;
45
+
46
+ public function __construct() {
47
+ parent::__construct();
48
+
49
+ $this->RoleAddEdit = WPFront_User_Role_Editor_Role_Add_Edit::instance();
50
+ }
51
+
52
+ public function view() {
53
+ add_thickbox();
54
+ ?>
55
+ <div class="wrap role-add-new">
56
+ <?php $this->title(__('Add New Role', 'wpfront-user-role-editor')); ?>
57
+ <?php $this->display_notices(); ?>
58
+ <?php $this->display_errors(); ?>
59
+ <?php $this->display_description(); ?>
60
+ <form method="post" id="createuser" name="createuser" class="validate">
61
+ <?php wp_nonce_field('add-new-role'); ?>
62
+ <?php $this->display_name_fields(); ?>
63
+ <?php $this->display_subhead_controls(); ?>
64
+ <div class="metabox-holder">
65
+ <?php $this->create_meta_boxes(); ?>
66
+ </div>
67
+ <?php
68
+ $this->submit_button();
69
+
70
+ $role_data = $this->RoleAddEdit->get_role_data();
71
+ $role_name = $role_data['role_name'];
72
+ $read_only = $role_data['is_readonly'];
73
+ ?>
74
+ <input type="hidden" id="role-add-edit-role-name" name="role-add-edit-role-name" value="<?php echo $role_name; ?>" />
75
+ <input type="hidden" id="role-add-edit-is-readonly" name="role-add-edit-is-readonly" value="<?php echo $read_only; ?>" />
76
+ </form>
77
+ </div>
78
+ <?php $this->scripts(); ?>
79
+ <?php
80
+ }
81
+
82
+ protected function title($title, $add_new = array(), $search = null) {
83
+ $is_edit_role = $this->RoleAddEdit->edit_role();
84
+
85
+ if ($is_edit_role) {
86
+ $title = __('Edit Role', 'wpfront-user-role-editor');
87
+
88
+ if (current_user_can('create_roles')) {
89
+ $add_new[0] = __('Add New', 'wpfront-user-role-editor');
90
+ $add_new[1] = $this->RoleAddEdit->get_add_new_role_url();
91
+ }
92
+ }
93
+
94
+ parent::title($title, $add_new);
95
+ }
96
+
97
+ protected function display_description() {
98
+ $is_edit_role = $this->RoleAddEdit->edit_role();
99
+ if (!$is_edit_role) {
100
+ printf('<p>%s</p>', __('Create a brand new role and add it to this site.', 'wpfront-user-role-editor'));
101
+ }
102
+ }
103
+
104
+ protected function display_errors() {
105
+ $role_data = $this->RoleAddEdit->get_role_data();
106
+ if (!empty($role_data['error'])) {
107
+ $this->UtilsClass::notice_error($role_data['error']);
108
+ }
109
+ }
110
+
111
+ protected function display_notices() {
112
+ if (!empty($_GET['role-added']) && $_GET['role-added'] === 'true') {
113
+ $this->UtilsClass::notice_updated(__('New role added.', 'wpfront-user-role-editor'));
114
+ } elseif (!empty($_GET['role-updated']) && $_GET['role-updated'] === 'true') {
115
+ $this->UtilsClass::notice_updated(__('Role updated.', 'wpfront-user-role-editor'));
116
+ }
117
+ }
118
+
119
+ protected function display_name_fields() {
120
+ ?>
121
+ <table class="form-table">
122
+ <tbody>
123
+ <tr class="form-field form-required <?php echo $this->is_display_name_valid() ? '' : 'form-invalid' ?>">
124
+ <th scope="row">
125
+ <label for="display_name">
126
+ <?php echo __('Display Name', 'wpfront-user-role-editor'); ?> <span class="description">(<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
127
+ </label>
128
+ </th>
129
+ <td>
130
+ <input name="display_name" type="text" id="display_name" value="<?php echo $this->get_role_display_name(); ?>" aria-required="true" <?php echo $this->is_role_display_name_disabled() ? 'disabled' : ''; ?> />
131
+ </td>
132
+ </tr>
133
+ <tr class="form-field form-required <?php echo $this->is_role_name_valid() ? '' : 'form-invalid' ?>">
134
+ <th scope="row">
135
+ <label for="role_name">
136
+ <?php echo __('Role Name', 'wpfront-user-role-editor'); ?> <span class="description">(<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
137
+ </label>
138
+ </th>
139
+ <td>
140
+ <input name="role_name" type="text" id="role_name" value="<?php echo $this->get_role_name(); ?>" aria-required="true" <?php echo $this->is_role_name_disabled() ? 'disabled' : ''; ?> />
141
+ </td>
142
+ </tr>
143
+ </tbody>
144
+ </table>
145
+ <?php
146
+ }
147
+
148
+ protected function display_subhead_controls() {
149
+ $disabled = $this->is_sub_controls_disabled();
150
+ ?>
151
+ <table class="form-table sub-head">
152
+ <tbody>
153
+ <tr>
154
+ <th class="sub-head">
155
+ <h3> <?php echo __('Capabilities', 'wpfront-user-role-editor'); ?></h3>
156
+ </th>
157
+ <td class="sub-head-controls">
158
+ <div>
159
+ <label class="view-type button button-secondary <?php echo $disabled ? 'disabled' : ''; ?>"><input class="view-type" name="view-type" type="radio" checked="true" value="allow" <?php echo $disabled ? 'disabled' : ''; ?> /><?php echo __('Allow Caps View', 'wpfront-user-role-editor') ?></label>
160
+ <label class="view-type button button-secondary <?php echo $disabled ? 'disabled' : ''; ?>"><input class="view-type" name="view-type" type="radio" value="deny" <?php echo $disabled ? 'disabled' : ''; ?> /><?php echo __('Deny Caps View', 'wpfront-user-role-editor') ?></label>
161
+ <div class="spacer"></div>
162
+ <select <?php echo $disabled ? 'disabled' : ''; ?>>
163
+ <option value=""><?php echo __('Copy from', 'wpfront-user-role-editor'); ?></option>
164
+ <?php
165
+ $roles = $this->get_copy_from_roles();
166
+ foreach ($roles as $name => $display) {
167
+ printf('<option value="%s">%s</option>', $name, $display);
168
+ }
169
+ ?>
170
+ </select>
171
+ <input type="button" id="cap_apply" name="cap_apply" class="button action" value="<?php echo __('Apply', 'wpfront-user-role-editor'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
172
+ </div>
173
+ <div class="spacer"></div>
174
+ <div class="select-all-none">
175
+ <input type="button" class="button action chk-helpers select-all" value="<?php echo __('Select All', 'wpfront-user-role-editor'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
176
+ <input type="button" class="button action chk-helpers select-none" value="<?php echo __('Select None', 'wpfront-user-role-editor'); ?>" <?php echo $disabled ? 'disabled' : ''; ?> />
177
+ </div>
178
+ </td>
179
+ </tr>
180
+ </tbody>
181
+ </table>
182
+ <?php
183
+ }
184
+
185
+ protected function create_meta_boxes() {
186
+ $groups = $this->RoleAddEdit->get_meta_box_groups();
187
+
188
+ foreach ($groups as $group_name => $value) {
189
+ if (empty($value->caps)) {
190
+ continue;
191
+ }
192
+
193
+ //TODO:do not display disabled on add screen???
194
+ // if($value->disabled && $value->mode === 'ADD') {
195
+ // continue;
196
+ // }
197
+
198
+ add_meta_box("postbox-$group_name", $this->postbox_title($value), array($this, 'postbox_render'), $this->RoleAddEdit->get_menu_slug(), 'normal', 'default', $value);
199
+ }
200
+
201
+ do_meta_boxes($this->RoleAddEdit->get_menu_slug(), 'normal', null);
202
+
203
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
204
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
205
+ }
206
+
207
+ public function postbox_render($context, $args) {
208
+ $value = $args['args'];
209
+
210
+ $disabled = false;
211
+ $role_data = $this->RoleAddEdit->get_role_data();
212
+ if (!empty($role_data)) {
213
+ $disabled = $role_data['is_readonly'];
214
+ }
215
+ ?>
216
+ <div class="main <?php echo $value->deprecated ? 'deprecated' : 'active'; ?> <?php echo $value->hidden ? 'hidden' : 'visible';?>">
217
+ <?php
218
+ if ($value->group_obj->type === 'custom_post' && $value->caps === 'defaulted') {
219
+ echo WPFront_User_Role_Editor_Post_Type::instance()->get_cpt_customizable_hint_text($value->group_obj, $disabled);
220
+ } elseif ($value->group_obj->type === 'taxonomy' && $value->caps === 'defaulted') {
221
+ echo WPFront_User_Role_Editor_Taxonomies::instance()->get_taxonomy_customizable_hint_text($value->group_obj, $disabled);
222
+ } else {
223
+ $this->render_caps($value);
224
+ }
225
+ ?>
226
+ </div>
227
+ <?php
228
+ }
229
+
230
+ public function render_caps($value) {
231
+ foreach ($value->caps as $cap) {
232
+ $enabled = apply_filters("wpfront_ure_capability_{$cap}_functionality_enabled", true, $cap);
233
+ $help_url = apply_filters('wpfront_ure_capability_ui_help_link', '', $cap, $value->group_obj);
234
+ $help_url = apply_filters("wpfront_ure_capability_{$cap}_ui_help_link", $help_url, $cap);
235
+ ?>
236
+ <div>
237
+ <input type="checkbox" class="allow" id="<?php echo 'cap-' . $cap . '-allow'; ?>" name="capabilities[<?php echo $cap; ?>][allow]" <?php echo $value->disabled ? 'disabled' : '' ?> <?php echo $this->is_cap_granted($cap) ? 'checked' : '' ?> />
238
+ <input type="checkbox" class="deny hidden" id="<?php echo 'cap-' . $cap . '-deny'; ?>" name="capabilities[<?php echo $cap; ?>][deny]" <?php echo $value->disabled ? 'disabled' : '' ?> <?php echo $this->is_cap_denied($cap) ? 'checked' : '' ?> />
239
+ <label class="cap-label cap-label-<?php echo $cap; ?> <?php echo $enabled ? '' : 'disabled'; ?> <?php echo $this->is_cap_denied($cap) ? 'denied' : '' ?>" data-cap="<?php echo $cap; ?>" title="<?php echo $cap; ?>"><?php echo esc_html($cap); ?></label>
240
+ <?php
241
+ if (!empty($help_url)) {
242
+ ?>
243
+ <a target="_blank" href="<?php echo $help_url; ?>">
244
+ <i class="fa fa-question-circle-o"></i>
245
+ </a>
246
+ <?php
247
+ }
248
+ ?>
249
+ </div>
250
+ <?php
251
+ }
252
+ }
253
+
254
+ protected function postbox_title($value) {
255
+ return '<label class="select-all ' . ($value->deprecated ? 'deprecated' : 'active') . '"><input id="' . $value->key . '" type="checkbox" class="select-all" ' . ($value->disabled ? 'disabled' : '') . ' />' . $value->display_name . '</label>';
256
+ }
257
+
258
+ protected function get_cap_state($cap) {
259
+ $role_data = $this->RoleAddEdit->get_role_data();
260
+ if (empty($role_data)) {
261
+ return null;
262
+ }
263
+
264
+ if (isset($role_data['capabilities'][$cap])) {
265
+ return $role_data['capabilities'][$cap];
266
+ }
267
+
268
+ return null;
269
+ }
270
+
271
+ protected function is_cap_granted($cap) {
272
+ return $this->get_cap_state($cap) === true;
273
+ }
274
+
275
+ protected function is_cap_denied($cap) {
276
+ return $this->get_cap_state($cap) === false;
277
+ }
278
+
279
+ protected function submit_button() {
280
+ $is_edit_role = $this->RoleAddEdit->edit_role();
281
+
282
+ $attr = ['id' => 'createusersub'];
283
+ if ($this->is_sub_controls_disabled()) {
284
+ $attr['disabled'] = true;
285
+ }
286
+
287
+ submit_button(
288
+ $is_edit_role ? __('Update Role', 'wpfront-user-role-editor') : __('Add New Role', 'wpfront-user-role-editor'),
289
+ 'primary',
290
+ 'createrole',
291
+ true,
292
+ $attr
293
+ );
294
+ }
295
+
296
+ protected function get_role_name() {
297
+ $role_data = $this->RoleAddEdit->get_role_data();
298
+
299
+ if ($role_data === null) {
300
+ return '';
301
+ }
302
+
303
+ return $role_data['role_name'];
304
+ }
305
+
306
+ protected function is_role_name_disabled() {
307
+ $is_edit_role = $this->RoleAddEdit->edit_role();
308
+
309
+ return $is_edit_role;
310
+ }
311
+
312
+ protected function is_role_name_valid() {
313
+ $role_data = $this->RoleAddEdit->get_role_data();
314
+
315
+ if ($role_data === null) {
316
+ return false;
317
+ }
318
+
319
+ return $role_data['is_role_name_valid'];
320
+ }
321
+
322
+ protected function get_role_display_name() {
323
+ $role_data = $this->RoleAddEdit->get_role_data();
324
+
325
+ if ($role_data === null) {
326
+ return '';
327
+ }
328
+
329
+ return $role_data['display_name'];
330
+ }
331
+
332
+ protected function is_role_display_name_disabled() {
333
+ $role_data = $this->RoleAddEdit->get_role_data();
334
+
335
+ if ($role_data === null) {
336
+ return true;
337
+ }
338
+
339
+ return $role_data['is_readonly'];
340
+ }
341
+
342
+ protected function is_display_name_valid() {
343
+ $role_data = $this->RoleAddEdit->get_role_data();
344
+
345
+ if ($role_data === null) {
346
+ return false;
347
+ }
348
+
349
+ return $role_data['is_display_name_valid'];
350
+ }
351
+
352
+ protected function is_sub_controls_disabled() {
353
+ return $this->is_role_display_name_disabled();
354
+ }
355
+
356
+ protected function get_copy_from_roles() {
357
+ $role_data = $this->RoleAddEdit->get_role_data();
358
+
359
+ if ($role_data !== null && $role_data['is_readonly']) {
360
+ return array();
361
+ }
362
+
363
+ return $this->RolesHelperClass::get_names();
364
+ }
365
+
366
+ protected function ajax_url() {
367
+ return json_encode(admin_url('admin-ajax.php'));
368
+ }
369
+
370
+ protected function scripts() {
371
+ ?>
372
+ <script type="text/javascript">
373
+ (function ($) {
374
+ var editRole = <?php echo $this->RoleAddEdit->edit_role() ? 'true' : 'false'; ?>;
375
+ var $viewType = $('input.view-type');
376
+
377
+ function change_select_all($divs) {
378
+ var viewType = $viewType.filter(':checked').val();
379
+
380
+ $divs.each(function () {
381
+ var $this = $(this);
382
+ var $chks = $this.find("input." + viewType);
383
+
384
+ if ($chks.length == 0) {
385
+ return;
386
+ }
387
+
388
+ if ($chks.length === $chks.filter(":checked").length) {
389
+ $this.closest("div.postbox").find("input.select-all").prop("checked", true);
390
+ } else {
391
+ $this.closest("div.postbox").find("input.select-all").prop("checked", false);
392
+ }
393
+
394
+ //disable select-all if all chechboxes are disabled.
395
+ if ($chks.length === $chks.filter(":disabled").length) {
396
+ $this.closest("div.postbox").find("input.select-all").prop("disabled", true);
397
+ }
398
+ });
399
+ }
400
+
401
+ function set_cap_fields_state($labels, value, viewType) {
402
+ var viewType = viewType || $viewType.filter(':checked').val();
403
+
404
+ //find all labels with same cap and apply the action to all labels.
405
+ var l = $();
406
+ $labels.each(function (i, e) {
407
+ var $e = $(e);
408
+ var cap = $e.data("cap");
409
+
410
+ l = l.add($("label.cap-label[data-cap='" + cap + "']"));
411
+ });
412
+
413
+ $labels = l;
414
+
415
+ if (viewType == 'allow') {
416
+ $labels.prev().prop('checked', false);
417
+ $labels.prev().prev().prop('checked', value);
418
+ $labels.removeClass('denied');
419
+ } else {
420
+ $labels.prev().prop('checked', value);
421
+ $labels.prev().prev().prop('checked', false);
422
+ $labels.removeClass('denied');
423
+ if (value) {
424
+ $labels.addClass('denied');
425
+ }
426
+ }
427
+
428
+ change_select_all($labels.closest('div.main'));
429
+ }
430
+
431
+ //postbox
432
+ $(function () {
433
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
434
+ postboxes.add_postbox_toggles('<?php echo $this->RoleAddEdit->get_menu_slug(); ?>');
435
+ $('div.postbox div.main.hidden').closest('div.postbox').addClass('hide-if-js');
436
+ $('div.postbox div.main.visible').closest('div.postbox').removeClass('hide-if-js');
437
+ });
438
+
439
+ //select all - none buttons
440
+ $("div.role-add-new table.sub-head td.sub-head-controls div.select-all-none").on("click", "input.chk-helpers", function () {
441
+ var $labels = $("div.role-add-new div.postbox div.inside label");
442
+
443
+ if ($(this).hasClass('select-all')) {
444
+ set_cap_fields_state($labels, true);
445
+ } else {
446
+ var viewType = $viewType.filter(':checked').val();
447
+ if (viewType === 'allow') {
448
+ set_cap_fields_state($labels.filter(':not(.denied)'), false);
449
+ } else {
450
+ set_cap_fields_state($labels.filter('.denied'), false);
451
+ }
452
+ }
453
+ });
454
+
455
+ //select all caps checkbox
456
+ $("div.role-add-new div.postbox label.select-all").on("click", "input.select-all:not(:disabled)", function (event) {
457
+ var $this = $(this);
458
+ var $labels = $this.closest('div').next().find("label");
459
+ set_cap_fields_state($labels, $this.prop('checked'));
460
+
461
+ event.stopPropagation();
462
+ });
463
+
464
+ $("div.role-add-new div.postbox label.select-all").on("click", function (event) {
465
+ event.stopPropagation();
466
+ });
467
+
468
+ //set select all caps on caps click
469
+ $("div.role-add-new").on("click", "div.postbox div.main input", function () {
470
+ var $this = $(this);
471
+ var $label = $this.next();
472
+ if ($this.hasClass('allow')) {
473
+ $label = $label.next();
474
+ }
475
+
476
+ set_cap_fields_state($label, $this.prop('checked'));
477
+ });
478
+
479
+ //auto role name from display name
480
+ if (!editRole) {
481
+ $("#display_name").keyup(function () {
482
+ var $this = $(this);
483
+ if ($.trim($this.val()) == "")
484
+ return;
485
+ $("#role_name").val($.trim($this.val()).toLowerCase().replace(/ /g, "_").replace(/\W/g, ""));
486
+ });
487
+
488
+ $("#role_name").blur(function () {
489
+ var ele = $(this);
490
+ var str = $.trim(ele.val()).toLowerCase();
491
+ str = str.replace(/ /g, "_").replace(/\W/g, "");
492
+ ele.val(str);
493
+ if (str != "") {
494
+ ele.parent().parent().removeClass("form-invalid");
495
+ }
496
+ });
497
+ }
498
+
499
+ //validation
500
+ $("#createusersub").click(function () {
501
+ var role_name = $("#role_name");
502
+ var display_name = $("#display_name");
503
+ if ($.trim(role_name.val()) == "") {
504
+ role_name.parent().parent().addClass("form-invalid");
505
+ }
506
+
507
+ if ($.trim(display_name.val()) == "") {
508
+ display_name.parent().parent().addClass("form-invalid");
509
+ }
510
+
511
+ if ($.trim(display_name.val()) == "") {
512
+ display_name.focus();
513
+ return false;
514
+ }
515
+
516
+ if ($.trim(role_name.val()) == "") {
517
+ role_name.focus();
518
+ return false;
519
+ }
520
+
521
+ return true;
522
+ });
523
+
524
+ //validation status set
525
+ $("#display_name").blur(function () {
526
+ var $this = $(this);
527
+ if ($.trim($this.val()) != "") {
528
+ $this.parent().parent().removeClass("form-invalid");
529
+ }
530
+ $("#role_name").blur();
531
+ });
532
+
533
+ //copy capabilities
534
+ $("#cap_apply").click(function () {
535
+ var $this = $(this);
536
+
537
+ if ($this.prev().val() == "")
538
+ return;
539
+
540
+ var button = $this.prop("disabled", true);
541
+ var data = {
542
+ "action": "wpfront_user_role_editor_copy_capabilities",
543
+ "role": $this.prev().val(),
544
+ "nonce": <?php echo json_encode(wp_create_nonce('copy-capabilities')); ?>
545
+ };
546
+
547
+ var ajaxurl = <?php echo $this->ajax_url(); ?>;
548
+ $.post(ajaxurl, data, function (response) {
549
+ $("div.role-add-new div.postbox input").prop("checked", false);
550
+ $("div.role-add-new div.postbox label").removeClass('denied');
551
+
552
+ var allowed = [];
553
+ var denied = [];
554
+
555
+ for (m in response) {
556
+ if (response[m]) {
557
+ allowed.push('.cap-label-' + m);
558
+ } else {
559
+ denied.push('.cap-label-' + m);
560
+ }
561
+ }
562
+
563
+ if (allowed.length > 0) {
564
+ set_cap_fields_state($(allowed.join()), true, 'allow');
565
+ }
566
+
567
+ if (denied.length > 0) {
568
+ set_cap_fields_state($(denied.join()), true, 'deny');
569
+ }
570
+
571
+ button.prop("disabled", false);
572
+ }, 'json');
573
+ });
574
+
575
+ //view change
576
+ $viewType.change(function () {
577
+ //active class change
578
+ $('label.view-type').removeClass('active');
579
+ var $this = $(this);
580
+ $this.parent().addClass('active');
581
+ var val = $this.val();
582
+
583
+ //cap label for set
584
+ $('label.cap-label').each(function () {
585
+ var $label = $(this);
586
+ var cap = $label.data('cap');
587
+ var chkId = 'cap' + '-' + cap + '-' + val;
588
+ $label.prop('for', chkId);
589
+
590
+ if (val === 'allow') {
591
+ $label.prev().addClass('hidden').prev().removeClass('hidden');
592
+ } else {
593
+ $label.prev().removeClass('hidden').prev().addClass('hidden');
594
+ }
595
+
596
+ //disable other checkboxes with same cap
597
+ var $chks = $("input[id='" + chkId + "']");
598
+ if ($chks.length > 1) {
599
+ $chks.slice(1).prop('disabled', true);
600
+ }
601
+
602
+ //remove id if its checkbox is disabled, because we could have multiple checkboxes with same id.
603
+ if ($label.siblings("#" + $.escapeSelector(chkId)).is(":disabled")) {
604
+ $label.prop('for', '');
605
+ }
606
+ });
607
+
608
+ //set select all caps checkbox state on load
609
+ change_select_all($("div.role-add-new div.postbox div.main"));
610
+ }).filter(':checked').change();
611
+
612
+ //customize capability
613
+ $(function () {
614
+ var $div = null;
615
+ var $divInner;
616
+ var fnSubmit = null;
617
+
618
+ $("div.role-add-new").on("click", "a.thickbox.customize_capability", function () {
619
+ var $this = $(this);
620
+
621
+ if ($div === null) {
622
+ $div = $('<div id="div_customize_capability" class="hidden" />');
623
+ $divInner = $("<div class='thickbox' style='text-align:center'></div>");
624
+ $divInner.append($('<p><label><?php echo __('Capability Type', 'wpfront-user-role-editor'); ?> <input type="text" class="capability" /></label></p>'));
625
+ $divInner.append('<p><input type="submit" class="button button-secondary customize_capability" value="<?php echo __('Submit', 'wpfront-user-role-editor'); ?>" /></p>');
626
+ $divInner.append('<p class="error hidden"></p>');
627
+ $div.append($divInner);
628
+ $("body").append($div);
629
+
630
+ $divInner.on('click', 'input[type="submit"].customize_capability', function () {
631
+ $(this).prop('disabled', true);
632
+ fnSubmit(tb_remove);
633
+ });
634
+ }
635
+
636
+ var cap = $this.data("cap");
637
+ $div.find("input.capability").val(cap);
638
+
639
+ var url = '#TB_inline?&width=400&height=200&inlineId=div_customize_capability';
640
+ $this.prop("href", url);
641
+
642
+ var $error = $divInner.find("p.error").html("").addClass("hidden");
643
+
644
+ var delete_duplicates_under_other_caps = function (caps) {
645
+ caps.forEach((cap) => {
646
+ var $label = $("#postbox-other .inside .main label[data-cap='" + cap + "' ]");
647
+ $label.closest('div').remove();
648
+ });
649
+ };
650
+
651
+ var fnDone = function (error) {
652
+ if (error) {
653
+ $error.html(error).removeClass("hidden");
654
+ }
655
+
656
+ $divInner.find("input[type='submit'].customize_capability").prop('disabled', false);
657
+ };
658
+
659
+ fnSubmit = function (fn) {
660
+ $error.addClass("hidden");
661
+
662
+ $.ajax({
663
+ type: 'POST',
664
+ url: ajaxurl,
665
+ data: {
666
+ action: $this.data("action"),
667
+ key: $this.data("key"),
668
+ cap: $divInner.find("input.capability").val(),
669
+ nonce: $this.data("nonce")
670
+ },
671
+ success: function (response) {
672
+ if (!response.success) {
673
+ fnDone(response.data.error);
674
+ return;
675
+ }
676
+ var $readOnly = $('#role-add-edit-is-readonly').val();
677
+
678
+ $.post(ajaxurl, {
679
+ action: response.data.action,
680
+ key: $this.data("key"),
681
+ nonce: $this.data("nonce"),
682
+ role_name: $('#role-add-edit-role-name').val(),
683
+ read_only: $readOnly
684
+ }, function (response) {
685
+ if (!response.success) {
686
+ fn();
687
+ return;
688
+ }
689
+ if (!$readOnly) {
690
+ $this.closest('.postbox').find('input').prop('disabled', false);
691
+ }
692
+
693
+ var $postbox = $this.closest('.postbox');
694
+ $this.closest('.main').html(response.data.html);
695
+
696
+ delete_duplicates_under_other_caps(response.data.caps);
697
+
698
+ //reset all checkbox state.
699
+ $viewType.filter(':checked').triggerHandler('change');
700
+
701
+ fnDone();
702
+ fn();
703
+ });
704
+ },
705
+ error: function (xhr, textStatus, error) {
706
+ var ex = "<?php echo esc_html(__('An unexpected error occured. Please reload this page.', 'wpfront-user-role-editor')); ?>";
707
+ $divInner.html(ex + "<br>" + error);
708
+ }
709
+ });
710
+ };
711
+ });
712
+ });
713
+ })(jQuery);
714
+ </script>
715
+ <?php
716
+ }
717
+
718
+ }
719
+
720
+ }
721
+
includes/roles/template-role-delete.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Role Delete
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if(!class_exists('WPFront\URE\Roles\WPFront_User_Role_Editor_Role_Delete_View')) {
38
+
39
+ class WPFront_User_Role_Editor_Role_Delete_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
40
+
41
+ protected $RoleDelete;
42
+
43
+ public function __construct() {
44
+ parent::__construct();
45
+
46
+ $this->RoleDelete = WPFront_User_Role_Editor_Role_Delete::instance();
47
+ }
48
+
49
+ public function view() {
50
+ ?>
51
+ <div class="wrap delete-roles">
52
+ <?php $this->title(__('Delete Roles', 'wpfront-user-role-editor')); ?>
53
+ <?php $this->description(); ?>
54
+ <form method="post">
55
+ <?php wp_nonce_field('delete-roles'); ?>
56
+ <ul>
57
+ <?php $this->display_data(); ?>
58
+ </ul>
59
+ <?php
60
+ $attr = [];
61
+ if(!$this->is_submit_allowed()) {
62
+ $attr['disabled'] = true;
63
+ }
64
+ submit_button(__('Confirm Deletion', 'wpfront-user-role-editor'), 'primary', 'confirm-delete', true, $attr);
65
+ ?>
66
+ </form>
67
+ </div>
68
+ <?php
69
+ }
70
+
71
+ protected function description() {
72
+ ?>
73
+ <p><?php echo __('You have specified these roles for deletion', 'wpfront-user-role-editor'); ?>:</p>
74
+ <?php
75
+ }
76
+
77
+ protected function display_data() {
78
+ $role_data = $this->RoleDelete->get_delete_data();
79
+
80
+ foreach ($role_data as $key => $value) {
81
+ ?>
82
+ <li>
83
+ <?php $this->display_role_data($value); ?>
84
+ </li>
85
+ <?php
86
+ }
87
+ }
88
+
89
+ protected function display_role_data($data) {
90
+ printf('%s: <strong>%s</strong> [<strong>%s</strong>]', __('Role', 'wpfront-user-role-editor'), $data->name, $data->display_name);
91
+ if(!empty($data->status_message)) {
92
+ printf(' - <strong>%s</strong>', $data->status_message);
93
+ }
94
+ ?>
95
+ <input type="hidden" name="delete-roles[<?php echo $data->name; ?>]" value="1" />
96
+ <?php
97
+ }
98
+
99
+ protected function is_submit_allowed() {
100
+ $role_data = $this->RoleDelete->get_delete_data();
101
+
102
+ foreach ($role_data as $key => $value) {
103
+ if ($value->is_deletable)
104
+ return true;
105
+ }
106
+
107
+ return false;
108
+ }
109
+
110
+ }
111
+
112
+ }
113
+
includes/roles/template-roles-list.php ADDED
@@ -0,0 +1,435 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor List Roles
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Roles;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if(!class_exists('WPFront\URE\Roles\WPFront_User_Role_Editor_Roles_List_View')) {
38
+
39
+ class WPFront_User_Role_Editor_Roles_List_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
40
+
41
+ protected $RolesList;
42
+
43
+ protected $custom_columns = null;
44
+ protected $role_data = null;
45
+
46
+ public function __construct() {
47
+ parent::__construct();
48
+
49
+ $this->RolesList = WPFront_User_Role_Editor_Roles_List::instance();
50
+ }
51
+
52
+ public function view() {
53
+ ?>
54
+ <div class="wrap list-roles">
55
+ <?php
56
+ $add_new = array();
57
+ if (current_user_can('create_roles')) {
58
+ $add_new[0] = __('Add New', 'wpfront-user-role-editor');
59
+ $add_new[1] = $this->RolesList->get_add_new_role_url();
60
+ }
61
+ ?>
62
+ <?php $this->title(__('Roles', 'wpfront-user-role-editor'), $add_new, $this->get_search_term()); ?>
63
+ <?php $this->display_notices(); ?>
64
+ <?php $this->filter_links(); ?>
65
+ <form method = "post">
66
+ <?php wp_nonce_field('roles-list'); ?>
67
+ <?php $this->search_box(); ?>
68
+ <?php $this->bulk_actions('top'); ?>
69
+ <table class="wp-list-table widefat fixed users">
70
+ <thead>
71
+ <?php $this->table_header(); ?>
72
+ </thead>
73
+ <tfoot>
74
+ <?php $this->table_header(); ?>
75
+ </tfoot>
76
+ <tbody id="the-list">
77
+ <?php $this->create_rows(); ?>
78
+ </tbody>
79
+ </table>
80
+ <?php $this->bulk_actions('bottom'); ?>
81
+ </form>
82
+ </div>
83
+ <?php
84
+ $this->scripts();
85
+ }
86
+
87
+ protected function display_notices() {
88
+ if ((isset($_GET['default-role-updated']) && $_GET['default-role-updated'] == 'true')) {
89
+ $this->UtilsClass::notice_updated(__('New users\'s default roles has been updated.', 'wpfront-user-role-editor'));
90
+ }
91
+
92
+ if ((isset($_GET['roles-deleted']) && $_GET['roles-deleted'] == 'true')) {
93
+ $this->UtilsClass::notice_updated(__('Selected roles have been deleted.', 'wpfront-user-role-editor'));
94
+ }
95
+ }
96
+
97
+ protected function filter_links() {
98
+ ?>
99
+ <ul class="subsubsub">
100
+ <li>
101
+ <?php
102
+ $link_data = array();
103
+ $active_filter = $this->get_active_list_filter();
104
+ $filter_data = $this->RolesList->get_list_filter_data();
105
+ foreach ($filter_data as $key => $value) {
106
+ $link_data[] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', $value['url'], ($active_filter == $key ? 'current' : ''), $value['display'], $value['count']);
107
+ }
108
+ echo implode('&#160;|&#160;</li><li> ', $link_data);
109
+ ?>
110
+ </li>
111
+ </ul>
112
+ <?php
113
+ }
114
+
115
+ protected function search_box() {
116
+ ?>
117
+ <p class = "search-box">
118
+ <label class = "screen-reader-text" for = "role-search-input"><?php echo __('Search Roles', 'wpfront-user-role-editor') . ':'; ?></label>
119
+ <input type="search" id="role-search-input" name="s" value="<?php echo $this->get_search_term(); ?>">
120
+ <input type="submit" name="search-submit" id="search-submit" class="button" value="<?php echo __('Search Roles', 'wpfront-user-role-editor'); ?>">
121
+ </p>
122
+ <?php
123
+ }
124
+
125
+ protected function bulk_actions($position) {
126
+ ?>
127
+ <div class="tablenav <?php echo $position; ?>">
128
+ <div class="alignleft actions bulkactions">
129
+ <select name="action_<?php echo $position; ?>">
130
+ <option value="" selected="selected"><?php echo __('Bulk Actions', 'wpfront-user-role-editor'); ?></option>
131
+ <?php if (current_user_can('delete_roles')) { ?>
132
+ <option value="delete"><?php echo __('Delete', 'wpfront-user-role-editor'); ?></option>
133
+ <?php } ?>
134
+ </select>
135
+ <input type="submit" name="doaction_<?php echo $position; ?>" class="button bulk action" value="<?php echo __('Apply', 'wpfront-user-role-editor'); ?>">
136
+ </div>
137
+ <div class="tablenav-pages one-page"><span class="displaying-num"><?php echo sprintf(__('%s item(s)', 'wpfront-user-role-editor'), count($this->get_roles())); ?></span>
138
+ <br class="clear">
139
+ </div>
140
+ </div>
141
+ <?php
142
+ }
143
+
144
+ protected function table_header() {
145
+ $custom_columns = $this->get_custom_columns();
146
+ ?>
147
+ <tr>
148
+ <td scope="col" id="cb" class="manage-column column-cb check-column">
149
+ <label class="screen-reader-text" for="cb-select-all-1"><?php echo __('Select All', 'wpfront-user-role-editor'); ?></label>
150
+ <input id="cb-select-all-1" type="checkbox" />
151
+ </td>
152
+ <th scope="col" id="displayname" class="manage-column column-displayname">
153
+ <a><span><?php echo __('Display Name', 'wpfront-user-role-editor'); ?></span></a>
154
+ </th>
155
+ <th scope="col" id="rolename" class="manage-column column-rolename">
156
+ <a><span><?php echo __('Role Name', 'wpfront-user-role-editor'); ?></span></a>
157
+ </th>
158
+ <th scope="col" id="roletype" class="manage-column column-roletype">
159
+ <a><span><?php echo __('Type', 'wpfront-user-role-editor'); ?></span></a>
160
+ </th>
161
+ <th scope="col" id="userdefault" class="manage-column column-userdefault num">
162
+ <a><span><?php echo __('New User Default', 'wpfront-user-role-editor'); ?></span></a>
163
+ </th>
164
+ <th scope="col" id="usercount" class="manage-column column-usercount num">
165
+ <a><span><?php echo __('Users', 'wpfront-user-role-editor'); ?></span></a>
166
+ </th>
167
+ <th scope="col" id="capscount" class="manage-column column-capscount num">
168
+ <a><span><?php echo __('Capabilities', 'wpfront-user-role-editor'); ?></span></a>
169
+ </th>
170
+ <?php
171
+ foreach ($custom_columns as $key => $value) {
172
+ printf('
173
+ <th scope="col" id="%1$s" class="manage-column column-%1$s num">
174
+ <a><span>%2$s</span></a>
175
+ </th>
176
+ ', $key, $value);
177
+ }
178
+ ?>
179
+ </tr>
180
+ <?php
181
+ }
182
+
183
+ protected function create_rows() {
184
+ $roles = $this->get_roles();
185
+
186
+ $index = 0;
187
+ foreach ($roles as $key => $value) {
188
+ $this->create_row($key, $value, $index);
189
+ $index++;
190
+ }
191
+ }
192
+
193
+ protected function create_row($role_name, $value, $index) {
194
+ ?>
195
+ <tr id="<?php echo $role_name; ?>" class="<?php echo $index % 2 == 0 ? 'alternate' : ''; ?>">
196
+ <?php $this->cell_select_checkbox($role_name, $value['display_name'], $value['is_editable']); ?>
197
+ <?php $this->cell_display_name($role_name, $value); ?>
198
+ <?php $this->cell_role_name($role_name, $value); ?>
199
+ <?php $this->cell_role_type($value['is_default']); ?>
200
+ <?php $this->cell_user_default($value['user_default']); ?>
201
+ <?php $this->cell_user_count($value['user_count']); ?>
202
+ <?php $this->cell_caps_count($value['caps_count']); ?>
203
+ <?php $this->cell_custom_columns($role_name); ?>
204
+ </tr>
205
+ <?php
206
+ }
207
+
208
+ protected function cell_select_checkbox($role_name, $display_name, $is_editable) {
209
+ ?>
210
+ <th scope="row" class="check-column">
211
+ <?php if($is_editable) { ?>
212
+ <label class="screen-reader-text" for="cb-select-<?php echo $role_name; ?>"><?php echo sprintf(__('Select %s', 'wpfront-user-role-editor'), $display_name) ?></label>
213
+ <input type="checkbox" name="selected-roles[<?php echo $role_name; ?>]" id="cb-select-<?php echo $role_name; ?>" />
214
+ <?php } ?>
215
+ </th>
216
+ <?php
217
+ }
218
+
219
+ protected function cell_display_name($role_name, $value) {
220
+ $display_name = $value['display_name'];
221
+ $edit_url = $value['edit_url'];
222
+ $is_editable = $value['is_editable'];
223
+ $delete_url = $value['delete_url'];
224
+ $set_default_url = $value['set_default_url'];
225
+ ?>
226
+ <td class="displayname column-displayname">
227
+ <strong>
228
+ <?php
229
+ if (empty($edit_url))
230
+ echo $display_name;
231
+ else
232
+ printf('<a href="%s">%s</a>', $edit_url, $display_name);
233
+ ?>
234
+ </strong>
235
+ <br />
236
+ <?php $this->row_actions($role_name, $value, $edit_url, $is_editable, $delete_url, $set_default_url); ?>
237
+ </td>
238
+ <?php
239
+ }
240
+
241
+ protected function row_actions($role_name, $role_data, $edit_url, $is_editable, $delete_url, $set_default_url) {
242
+ ?>
243
+ <div class="row-actions">
244
+ <?php
245
+ $links = array();
246
+ if (!empty($edit_url)) {
247
+ $links[] = sprintf('<span class="edit"><a href="%s">%s</a></span>', $edit_url, ($is_editable ? __('Edit', 'wpfront-user-role-editor') : __('View', 'wpfront-user-role-editor')));
248
+ }
249
+ if (!empty($delete_url)) {
250
+ $links[] = sprintf('<span class="delete"><a href="%s">%s</a></span>', $delete_url, __('Delete', 'wpfront-user-role-editor'));
251
+ }
252
+ if (!empty($set_default_url)) {
253
+ $text = __('Default', 'wpfront-user-role-editor');
254
+ if($role_data['user_default'] > 0) {
255
+ $text = '-' . $text;
256
+ } else {
257
+ $text = '+' . $text;
258
+ }
259
+ $links[] = sprintf('<span class="set-default"><a href="%s">%s</a></span>', $set_default_url, $text);
260
+ }
261
+ $custom_links = apply_filters('role_row_actions', array(), get_role($role_name));
262
+ foreach ($custom_links as $link_key => $link_value) {
263
+ $links[] = sprintf('<span class="%s">%s</span>', $link_key, $link_value);
264
+ }
265
+ echo implode(' | ', $links);
266
+ ?>
267
+ </div>
268
+ <?php
269
+ }
270
+
271
+ protected function cell_role_name($role_name, $value) {
272
+ ?>
273
+ <td class="rolename column-rolename">
274
+ <?php echo $role_name; ?>
275
+ </td>
276
+ <?php
277
+ }
278
+
279
+ protected function cell_role_type($is_default) {
280
+ ?>
281
+ <td class="roletype column-roletype">
282
+ <?php echo $is_default ? __('Built-In', 'wpfront-user-role-editor') : __('Custom', 'wpfront-user-role-editor'); ?>
283
+ </td>
284
+ <?php
285
+ }
286
+
287
+ protected function cell_user_default($user_default) {
288
+ ?>
289
+ <td class="userdefault column-userdefault num">
290
+ <?php
291
+ if ($user_default == 1) {
292
+ ?>
293
+ <i class="fa fa-check-circle"></i>
294
+ <?php
295
+ } elseif ($user_default == 2) {
296
+ ?>
297
+ <i class="fa fa-check-circle-o"></i>
298
+ <?php
299
+ }
300
+ ?>
301
+ </td>
302
+ <?php
303
+ }
304
+
305
+ protected function cell_user_count($user_count) {
306
+ ?>
307
+ <td class="usercount column-usercount num">
308
+ <?php echo $user_count; ?>
309
+ </td>
310
+ <?php
311
+ }
312
+
313
+ protected function cell_caps_count($caps_count) {
314
+ ?>
315
+ <td class="capscount column-capscount num">
316
+ <?php echo $caps_count; ?>
317
+ </td>
318
+ <?php
319
+ }
320
+
321
+ protected function cell_custom_columns($role_name) {
322
+ $custom_columns = $this->get_custom_columns();
323
+
324
+ foreach ($custom_columns as $column_key => $column_value) {
325
+ echo "<td class='$column_key column-$column_key num'>"
326
+ . apply_filters('manage_roles_custom_column', $column_value, $column_key, $role_name)
327
+ . "</td>";
328
+ }
329
+ }
330
+
331
+ protected function get_active_list_filter() {
332
+ if (empty($_GET['list']))
333
+ return 'all';
334
+
335
+ $list = $_GET['list'];
336
+
337
+ switch ($list) {
338
+ case 'all':
339
+ case 'haveusers':
340
+ case 'nousers':
341
+ case 'builtin':
342
+ case 'custom':
343
+ break;
344
+ default:
345
+ $list = 'all';
346
+ break;
347
+ }
348
+
349
+ return $list;
350
+ }
351
+
352
+ protected function get_search_term() {
353
+ if (empty($_POST['s']))
354
+ return '';
355
+
356
+ return esc_html($_POST['s']);
357
+ }
358
+
359
+ protected function get_roles() {
360
+ if($this->role_data != null) {
361
+ return $this->role_data;
362
+ }
363
+
364
+ $role_data = $this->RolesList->get_role_data();
365
+
366
+ $role_data = $this->apply_active_list_filter($role_data);
367
+ $role_data = $this->apply_search_term($role_data);
368
+
369
+ $this->role_data = $role_data;
370
+
371
+ return $role_data;
372
+ }
373
+
374
+ protected function apply_active_list_filter($role_data) {
375
+ switch ($this->get_active_list_filter()) {
376
+ case 'all':
377
+ break;
378
+ case 'haveusers':
379
+ foreach ($role_data as $key => $value) {
380
+ if ($value['user_count'] == 0)
381
+ unset($role_data[$key]);
382
+ }
383
+ break;
384
+ case 'nousers':
385
+ foreach ($role_data as $key => $value) {
386
+ if ($value['user_count'] !== 0)
387
+ unset($role_data[$key]);
388
+ }
389
+ break;
390
+ case 'builtin':
391
+ foreach ($role_data as $key => $value) {
392
+ if (!$value['is_default'])
393
+ unset($role_data[$key]);
394
+ }
395
+ break;
396
+ case 'custom':
397
+ foreach ($role_data as $key => $value) {
398
+ if ($value['is_default'])
399
+ unset($role_data[$key]);
400
+ }
401
+ break;
402
+ }
403
+
404
+ return $role_data;
405
+ }
406
+
407
+ protected function apply_search_term($role_data) {
408
+ $search = $this->get_search_term();
409
+ $search = strtolower(trim($search));
410
+ if ($search !== '') {
411
+ foreach ($role_data as $key => $value) {
412
+ if (strpos(strtolower($value['display_name']), $search) === false) {
413
+ unset($role_data[$key]);
414
+ }
415
+ }
416
+ }
417
+
418
+ return $role_data;
419
+ }
420
+
421
+ protected function get_custom_columns() {
422
+ if($this->custom_columns === null) {
423
+ $this->custom_columns = apply_filters('manage_roles_columns', array());
424
+ }
425
+
426
+ return $this->custom_columns;
427
+ }
428
+
429
+ protected function scripts() {
430
+ }
431
+
432
+ }
433
+
434
+ }
435
+
includes/settings/class-options.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Controller for WPFront User Role Editor Options
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Options;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ require_once dirname(__FILE__) . '/entity-options.php';
38
+ require_once dirname(__FILE__) . '/template-options.php';
39
+
40
+ if (!class_exists('WPFront\URE\Options\WPFront_User_Role_Editor_Options')) {
41
+
42
+ interface iWPFront_User_Role_Editor_Settings_Controller {
43
+ public function getKey();
44
+ public function getTitle();
45
+ public function view_callback();
46
+ public function load_view_callback($options);
47
+ public function display_notices();
48
+ }
49
+
50
+ /**
51
+ * Options Controller
52
+ *
53
+ * @author Syam Mohan <syam@wpfront.com>
54
+ * @copyright 2014 WPFront.com
55
+ */
56
+ class WPFront_User_Role_Editor_Options extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller implements iWPFront_User_Role_Editor_Settings_Controller {
57
+
58
+ /**
59
+ *
60
+ * @var iWPFront_User_Role_Editor_Settings_Controller
61
+ */
62
+ protected $controllers = null;
63
+
64
+ /**
65
+ *
66
+ * @var iWPFront_User_Role_Editor_Settings_Controller[]
67
+ */
68
+ protected $current_controller = null;
69
+
70
+ protected $view = null;
71
+
72
+ /**
73
+ * UI field keys, populated from filter.
74
+ *
75
+ * @var string[] key => group.
76
+ */
77
+ protected $option_keys = array();
78
+
79
+ protected function setUp() {
80
+ $this->_setUp('manage_options', \WPFront\URE\WPFront_User_Role_Editor::PLUGIN_SLUG);
81
+
82
+ $this->ViewClass = WPFront_User_Role_Editor_Options_View::class;
83
+ $this->EntityClass = WPFront_User_Role_Editor_Options_Entity::class;
84
+ }
85
+
86
+ protected function initialize() {
87
+ if(!$this->in_admin_ui()) {
88
+ return;
89
+ }
90
+
91
+ $this->set_admin_menu(__('Settings', 'wpfront-user-role-editor'), __('Settings', 'wpfront-user-role-editor'), 100);
92
+
93
+ add_action('plugin_action_links_' . $this->WPFURE->get_plugin_basename(), array($this, 'plugin_action_links'));
94
+ }
95
+
96
+ public function plugin_action_links($links) {
97
+ if(current_user_can($this->get_cap())) {
98
+ $url = $this->get_self_url();
99
+ $text = __('Settings', 'wpfront-user-role-editor');
100
+ $a = sprintf('<a href="%s">%s</a>', $url, $text);
101
+ array_unshift($links, $a);
102
+ }
103
+
104
+ return $links;
105
+ }
106
+
107
+ public function getKey() {
108
+ return null;
109
+ }
110
+
111
+ public function getTitle() {
112
+ return __('Settings', 'wpfront-user-role-editor');
113
+ }
114
+
115
+ public function load_view() {
116
+ if(!parent::load_view()) {
117
+ return;
118
+ }
119
+
120
+ if(!empty($_POST['submit'])) {
121
+ check_admin_referer('save-settings');
122
+ }
123
+
124
+ $this->controllers = apply_filters('wpfront_ure_settings_controllers', array());
125
+ array_unshift($this->controllers, $this);
126
+
127
+ if(!empty($_GET['key'])) {
128
+ $key = $_GET['key'];
129
+ foreach ($this->controllers as $ctrl) {
130
+ if($ctrl->getKey() === $key) {
131
+ $this->current_controller = $ctrl;
132
+ break;
133
+ }
134
+ }
135
+ }
136
+
137
+ if(empty($this->current_controller)) {
138
+ $this->current_controller = $this;
139
+ }
140
+
141
+ $this->current_controller->load_view_callback($this);
142
+ }
143
+
144
+ public function load_view_callback($options) {
145
+ $this->load_option_keys();
146
+
147
+ if(!empty($_POST['submit'])) {
148
+ foreach ($this->option_keys as $key => $group) {
149
+ $error = apply_filters('wpfront_ure_options_ui_field_' . $key . '_validate', '', $key);
150
+ if(!empty($error)) {
151
+ return;
152
+ }
153
+
154
+ do_action('wpfront_ure_options_ui_field_' . $key . '_update', $key);
155
+ }
156
+
157
+ if(wp_safe_redirect($this->get_self_url() . '&settings-updated=true')) {
158
+ exit();
159
+ }
160
+ }
161
+
162
+ $this->set_help_tab();
163
+ }
164
+
165
+ protected function load_option_keys() {
166
+ $this->option_keys = apply_filters('wpfront_ure_options_register_ui_field', $this->option_keys);
167
+ }
168
+
169
+ public function view() {
170
+ if(!parent::view()) {
171
+ return;
172
+ }
173
+
174
+ $view = new $this->ViewClass();
175
+ $view->view($this, $this->controllers, $this->current_controller);
176
+ }
177
+
178
+ public function view_callback() {
179
+ $view = new $this->ViewClass();
180
+ $view->view_settings($this->option_keys);
181
+ }
182
+
183
+ public function display_notices() {
184
+ $view = new $this->ViewClass();
185
+ $view->display_notices();
186
+ }
187
+
188
+ /**
189
+ * Sets the help tab of edit roles.
190
+ */
191
+ protected function set_help_tab() {
192
+ $help = '';
193
+ foreach ($this->option_keys as $key => $group) {
194
+ $h = apply_filters('wpfront_ure_options_ui_field_' . $key . '_help', '', $key);
195
+ if(!empty($h)) {
196
+ $help .= "<p>$h</p>";
197
+ }
198
+ }
199
+
200
+ $tabs = array(
201
+ array(
202
+ 'id' => 'overview',
203
+ 'title' => __('Overview', 'wpfront-user-role-editor'),
204
+ 'content' => $help
205
+ )
206
+ );
207
+
208
+ $sidebar = array(
209
+ array(
210
+ __('Documentation on Settings', 'wpfront-user-role-editor'),
211
+ 'settings/'
212
+ )
213
+ );
214
+
215
+ $this->UtilsClass::set_help_tab($tabs, $sidebar);
216
+ }
217
+
218
+ public function set_option($key, $value, $auto_load = true) {
219
+ $entity = new $this->EntityClass();
220
+ $entity->update_option($key, $value, $auto_load);
221
+ }
222
+
223
+ public function get_option($key, $fallback = false) {
224
+ if($fallback && is_multisite()) {
225
+ $exists = false;
226
+ $entity = new $this->EntityClass();
227
+ $result = $entity->get_option($key, $exists);
228
+ if($exists) {
229
+ return $result;
230
+ }
231
+
232
+ return $this->get_network_option($key);
233
+
234
+ } else {
235
+ $entity = new $this->EntityClass();
236
+ return $entity->get_option($key);
237
+ }
238
+ }
239
+
240
+ public function get_option_boolean($key, $fallback = false) {
241
+ return filter_var($this->get_option($key, $fallback), FILTER_VALIDATE_BOOLEAN);
242
+ }
243
+
244
+ public function delete_option($key) {
245
+ $entity = new $this->EntityClass();
246
+ $entity->delete_option($key);
247
+ }
248
+
249
+ public function get_network_option($key, $prefix = 'ms_') {
250
+ $this->switch_to_main_blog();
251
+ $result = $this->get_option($prefix . $key);
252
+ $this->restore_current_blog();
253
+
254
+ return $result;
255
+ }
256
+
257
+ public function get_network_option_boolean($key, $prefix = 'ms_') {
258
+ return filter_var($this->get_network_option($key, $prefix), FILTER_VALIDATE_BOOLEAN);
259
+ }
260
+
261
+ public function set_network_option($key, $value, $prefix = 'ms_', $auto_load = true) {
262
+ $this->switch_to_main_blog();
263
+ $this->set_option($prefix . $key, $value, $auto_load);
264
+ $this->restore_current_blog();
265
+ }
266
+
267
+ public function delete_network_option($key, $prefix = 'ms_') {
268
+ $this->switch_to_main_blog();
269
+ $this->delete_option($prefix . $key);
270
+ $this->restore_current_blog();
271
+ }
272
+
273
+ protected function switch_to_main_blog() {
274
+ if(is_multisite()) {
275
+ switch_to_blog(get_main_site_id());
276
+ }
277
+ }
278
+
279
+ protected function restore_current_blog() {
280
+ if(is_multisite()) {
281
+ restore_current_blog();
282
+ }
283
+ }
284
+
285
+ /**
286
+ *
287
+ * @param iWPFront_User_Role_Editor_Settings_Controller $ctrl
288
+ */
289
+ public function getControllerUrl($ctrl) {
290
+ $key = $ctrl->getKey();
291
+ if($key === null) {
292
+ return $this->get_self_url();
293
+ }
294
+
295
+ return $this->get_self_url(['key' => $ctrl->getKey()]);
296
+ }
297
+
298
+ }
299
+
300
+ add_action('wpfront_ure_init', '\WPFront\URE\Options\WPFront_User_Role_Editor_Options::init');
301
+
302
+ }
includes/settings/entity-options.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Entity for WPFront User Role Editor Options
27
+ *
28
+ * @author Syam Mohan <syam@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Options;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ if (!class_exists('WPFront\URE\Options\WPFront_User_Role_Editor_Options_Entity')) {
39
+
40
+ /**
41
+ * Options Entity
42
+ *
43
+ * @author Syam Mohan <syam@wpfront.com>
44
+ * @copyright 2014 WPFront.com
45
+ */
46
+ class WPFront_User_Role_Editor_Options_Entity extends \WPFront\URE\WPFront_User_Role_Editor_Entity_Base {
47
+
48
+ private static $cache = null;
49
+
50
+ protected function table_name_suffix() {
51
+ return 'options';
52
+ }
53
+
54
+ protected function table_create_sql() {
55
+ $table_name = $this->table_name();
56
+
57
+ global $wpdb;
58
+ $charset_collate = $wpdb->get_charset_collate();
59
+
60
+ $sql = "CREATE TABLE $table_name (\n"
61
+ . "id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n"
62
+ . "option_name varchar(250) DEFAULT NULL,\n"
63
+ . "option_value longtext DEFAULT NULL,\n"
64
+ . "auto_load tinyint DEFAULT 1,\n"
65
+ . "PRIMARY KEY (id),\n"
66
+ . "KEY option_name (option_name),\n"
67
+ . "KEY auto_load (auto_load)\n"
68
+ . ") $charset_collate;";
69
+
70
+ return $sql;
71
+ }
72
+
73
+ private function load_options() {
74
+ if (self::$cache !== null) {
75
+ return;
76
+ }
77
+
78
+ self::$cache = array();
79
+
80
+ $found = false;
81
+ $this->cache_get('role_capabilities_processed', $found);
82
+ if (!$found) {
83
+ global $wpdb;
84
+ $table_name = $this->table_name();
85
+
86
+ $sql = "SELECT option_name, option_value FROM $table_name WHERE auto_load=1";
87
+ $results = $wpdb->get_results($sql);
88
+
89
+ foreach ($results as $value) {
90
+ self::$cache[$value->option_name] = maybe_unserialize($value->option_value);
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Returns option value against option name.
97
+ *
98
+ * @global \wpdb $wpdb
99
+ * @param string $option_name
100
+ * @param boolean $exists
101
+ * @return string
102
+ */
103
+ public function get_option($option_name, &$exists = null) {
104
+ $this->load_options();
105
+
106
+ $found = false;
107
+ $value = $this->cache_get($option_name, $found);
108
+ if ($value !== false) {
109
+ $exists = true;
110
+ return $value;
111
+ }
112
+ if ($found) {
113
+ $exists = false;
114
+ return false;
115
+ }
116
+
117
+ if (isset(self::$cache[$option_name])) {
118
+ $value = self::$cache[$option_name];
119
+ $exists = true;
120
+ } else {
121
+ global $wpdb;
122
+ $table_name = $this->table_name();
123
+
124
+ $sql = $wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s", $option_name);
125
+ $value = $wpdb->get_row($sql);
126
+
127
+ if (empty($value)) {
128
+ $exists = false;
129
+ $value = false;
130
+ } else {
131
+ $value = maybe_unserialize($value->option_value);
132
+ $exists = true;
133
+ }
134
+ }
135
+
136
+ $this->cache_set($option_name, $value);
137
+
138
+ return $value;
139
+ }
140
+
141
+ /**
142
+ * Inserts or Updates an option value.
143
+ *
144
+ * @global \wpdb $wpdb
145
+ * @param string $option_name
146
+ * @param string $value
147
+ * @param boolean $auto_load
148
+ */
149
+ public function update_option($option_name, $value, $auto_load = true) {
150
+ if ($value === false) {
151
+ $value = '0';
152
+ }
153
+
154
+ global $wpdb;
155
+ $table_name = $this->table_name();
156
+
157
+ $sql = $wpdb->prepare("SELECT EXISTS(SELECT 1 FROM $table_name WHERE option_name = %s)", $option_name);
158
+ $result = $wpdb->get_var($sql);
159
+
160
+ if (empty($result)) {
161
+ $wpdb->insert(
162
+ $table_name,
163
+ array(
164
+ 'option_name' => $option_name,
165
+ 'option_value' => maybe_serialize($value),
166
+ 'auto_load' => $auto_load
167
+ ),
168
+ array(
169
+ '%s',
170
+ '%s',
171
+ '%d'
172
+ )
173
+ );
174
+ } else {
175
+ $wpdb->update(
176
+ $table_name,
177
+ array(
178
+ 'option_value' => maybe_serialize($value),
179
+ 'auto_load' => $auto_load
180
+ ),
181
+ array(
182
+ 'option_name' => $option_name
183
+ ),
184
+ array(
185
+ '%s',
186
+ '%d'
187
+ ),
188
+ array(
189
+ '%s'
190
+ )
191
+ );
192
+ }
193
+
194
+ $this->cache_set($option_name, $value);
195
+ }
196
+
197
+ /**
198
+ * Deletes an option value against its name.
199
+ *
200
+ * @global \wpdb $wpdb
201
+ * @param string $option_name
202
+ */
203
+ public function delete_option($option_name) {
204
+ global $wpdb;
205
+ $table_name = $this->table_name();
206
+
207
+ $this->cache_delete($option_name);
208
+ unset(self::$cache[$option_name]);
209
+
210
+ $wpdb->delete(
211
+ $table_name,
212
+ array(
213
+ 'option_name' => $option_name
214
+ ),
215
+ array(
216
+ '%s'
217
+ )
218
+ );
219
+ }
220
+
221
+ }
222
+
223
+ (new WPFront_User_Role_Editor_Options_Entity())->register();
224
+ }
includes/settings/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden.
includes/settings/template-options.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Options
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Options;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('WPFront\URE\Roles\WPFront_User_Role_Editor_Options_View')) {
38
+
39
+ class WPFront_User_Role_Editor_Options_View extends \WPFront\URE\WPFront_User_Role_Editor_View {
40
+
41
+ /**
42
+ *
43
+ * @var string[] key => group.
44
+ */
45
+ protected $option_keys;
46
+
47
+ /**
48
+ *
49
+ * @param iWPFront_User_Role_Editor_Settings_Controller[] $controllers
50
+ * @param iWPFront_User_Role_Editor_Settings_Controller $current
51
+ */
52
+ public function view($parent, $controllers, $current) {
53
+ ?>
54
+ <div class="wrap">
55
+ <?php $this->title(__('WPFront User Role Editor Settings', 'wpfront-user-role-editor')); ?>
56
+ <?php $current->display_notices(); ?>
57
+ <nav class="nav-tab-wrapper" aria-label="Tabbed Menu">
58
+ <?php
59
+ foreach ($controllers as $ctrl) {
60
+ $class = 'nav-tab';
61
+ $url = $parent->getControllerUrl($ctrl);
62
+ if($ctrl->getKey() === $current->getKey()) {
63
+ $class .= ' nav-tab-active';
64
+ $url = '#!';
65
+ }
66
+ ?>
67
+ <a class="<?php echo $class; ?>" href="<?php echo $url; ?>"><?php echo $ctrl->getTitle(); ?></a>
68
+ <?php
69
+ }
70
+ ?>
71
+ </nav>
72
+ <div>
73
+ <form method="post" action="<?php echo $parent->getControllerUrl($current); ?>">
74
+ <?php wp_nonce_field('save-settings'); ?>
75
+ <div class="inside">
76
+ <?php echo $current->view_callback(); ?>
77
+ <?php submit_button(); ?>
78
+ </div>
79
+ </form>
80
+ </div>
81
+ </div>
82
+ <?php
83
+ }
84
+
85
+ public function view_settings($option_keys) {
86
+ $this->option_keys = $option_keys;
87
+ ?>
88
+ <div id="wpfront-user-role-editor-options">
89
+ <table class="form-table">
90
+ <?php $this->display_rows(); ?>
91
+ </table>
92
+ </div>
93
+ <?php
94
+ }
95
+
96
+ public function display_notices() {
97
+ if ((isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true')) {
98
+ $this->UtilsClass::notice_updated(__('Settings updated.', 'wpfront-user-role-editor'));
99
+ }
100
+ }
101
+
102
+ protected function display_rows() {
103
+ foreach ($this->option_keys as $key => $group) {
104
+ ?>
105
+ <tr>
106
+ <th scope="row">
107
+ <?php do_action('wpfront_ure_options_ui_field_' . $key . '_label', $key); ?>
108
+ </th>
109
+ <td>
110
+ <?php do_action('wpfront_ure_options_ui_field_' . $key, $key); ?>
111
+ </td>
112
+ </tr>
113
+ <?php
114
+ }
115
+ }
116
+
117
+ }
118
+
119
+ }
classes/class-wpfront-user-role-editor-shortcodes.php → includes/shortcodes/class-shortcodes.php RENAMED
@@ -21,29 +21,43 @@
21
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
  */
23
 
 
 
 
 
 
 
 
 
 
24
  if (!defined('ABSPATH')) {
25
  exit();
26
  }
27
 
28
- if (!class_exists('WPFront_User_Role_Editor_Shortcodes')) {
 
 
 
 
 
29
 
30
  /**
31
- * Main class of WPFront User Role Editor Shortcodes
32
  *
33
  * @author Syam Mohan <syam@wpfront.com>
34
  * @copyright 2014 WPFront.com
35
  */
36
- class WPFront_User_Role_Editor_Shortcodes extends WPFront_User_Role_Editor_Controller_Base {
37
 
38
  const CURRENT_USER_ROLES = 'wpfront_ure_current_user_roles';
39
 
40
- public function __construct($main) {
41
- parent::__construct($main);
42
-
43
- add_action('plugins_loaded', array($this, 'plugins_loaded'));
44
  }
45
 
46
- public function plugins_loaded() {
 
 
 
47
  add_shortcode(self::CURRENT_USER_ROLES, array($this, 'process_current_user_roles'));
48
  }
49
 
@@ -52,12 +66,12 @@ if (!class_exists('WPFront_User_Role_Editor_Shortcodes')) {
52
  return '';
53
  }
54
 
55
- $atts = shortcode_atts(array('label' => $this->__('Current Roles: ')), $atts, $shortcode);
56
  $label = $atts['label'];
57
 
58
  $user = wp_get_current_user();
59
  if(empty($user->roles)) {
60
- $roles_text = $this->__('None');
61
  } else {
62
  $roles = $user->roles;
63
  global $wp_roles;
@@ -75,7 +89,9 @@ if (!class_exists('WPFront_User_Role_Editor_Shortcodes')) {
75
 
76
  return $label . $roles_text;
77
  }
78
-
79
  }
80
-
81
- }
 
 
21
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
  */
23
 
24
+ /**
25
+ * Controller for WPFront User Role Editor Shortcodes
26
+ *
27
+ * @author Syam Mohan <syam@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Shortcodes;
32
+
33
  if (!defined('ABSPATH')) {
34
  exit();
35
  }
36
 
37
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+ use WPFront\URE\WPFront_User_Role_Editor_Roles_Helper as RolesHelper;
40
+ use WPFront\URE\Options\WPFront_User_Role_Editor_Options as Options;
41
+
42
+ if (!class_exists('\WPFront\URE\Shortcodes\WPFront_User_Role_Editor_Shortcodes')) {
43
 
44
  /**
45
+ * Shortcodes class
46
  *
47
  * @author Syam Mohan <syam@wpfront.com>
48
  * @copyright 2014 WPFront.com
49
  */
50
+ class WPFront_User_Role_Editor_Shortcodes extends \WPFront\URE\WPFront_User_Role_Editor_Controller {
51
 
52
  const CURRENT_USER_ROLES = 'wpfront_ure_current_user_roles';
53
 
54
+ protected function setUp() {
 
 
 
55
  }
56
 
57
+ /**
58
+ * Hooks into wpfront_ure_init.
59
+ */
60
+ protected function initialize() {
61
  add_shortcode(self::CURRENT_USER_ROLES, array($this, 'process_current_user_roles'));
62
  }
63
 
66
  return '';
67
  }
68
 
69
+ $atts = shortcode_atts(array('label' => __('Current Roles: ', 'wpfront-user-role-editor')), $atts, $shortcode);
70
  $label = $atts['label'];
71
 
72
  $user = wp_get_current_user();
73
  if(empty($user->roles)) {
74
+ $roles_text = __('None', 'wpfront-user-role-editor');
75
  } else {
76
  $roles = $user->roles;
77
  global $wp_roles;
89
 
90
  return $label . $roles_text;
91
  }
92
+
93
  }
94
+
95
+ add_action('wpfront_ure_init', '\WPFront\URE\Shortcodes\WPFront_User_Role_Editor_Shortcodes::init');
96
+
97
+ }
includes/taxonomies/class-taxonomies-list-table.php ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * WPFront User Role Editor Taxonomies List Table
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Taxonomies;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ if (!class_exists('\WP_List_Table')) {
38
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
39
+ }
40
+
41
+ if (!class_exists('\WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies_List_Table')) {
42
+
43
+ /**
44
+ * Taxonomies List Table
45
+ *
46
+ * @author Vaisagh D <vaisaghd@wpfront.com>
47
+ * @copyright 2015 WPFront.com
48
+ */
49
+ class WPFront_User_Role_Editor_Taxonomies_List_Table extends \WP_List_Table {
50
+
51
+ /**
52
+ *
53
+ * @var WPFront_User_Role_Editor_Taxonomies
54
+ */
55
+ private $controller;
56
+
57
+ /**
58
+ *
59
+ * @param WPFront_User_Role_Editor_Taxonomies $controller
60
+ */
61
+ public function __construct($controller) {
62
+ $this->controller = $controller;
63
+ parent::__construct(array('screen' => 'taxonomies'));
64
+ }
65
+
66
+ function prepare_items() {
67
+ $search = '';
68
+ if (!empty($_GET['s'])) {
69
+ $search = $_GET['s'];
70
+ $this->items = $this->controller->search($search);
71
+ } else {
72
+ $taxonomies = $this->controller->apply_active_list_filter();
73
+ $this->items = $taxonomies;
74
+ }
75
+ $this->set_pagination_args(array(
76
+ 'total_items' => count($this->items),
77
+ 'per_page' => PHP_INT_MAX,
78
+ ));
79
+ }
80
+
81
+ function get_bulk_actions() {
82
+ $actions = array();
83
+
84
+ if (current_user_can('delete_taxonomies')) {
85
+ $actions['delete'] = __('Delete', 'wpfront-user-role-editor');
86
+ }
87
+
88
+ if (current_user_can('edit_taxonomies')) {
89
+ $actions['restore'] = __('Restore', 'wpfront-user-role-editor');
90
+ $actions['activate'] = __('Activate', 'wpfront-user-role-editor');
91
+ $actions['deactivate'] = __('Deactivate', 'wpfront-user-role-editor');
92
+ }
93
+
94
+ return $actions;
95
+ }
96
+
97
+ function get_columns() {
98
+ $columns = array(
99
+ 'cb' => '<input type="checkbox" />',
100
+ 'name' => __('Name', 'wpfront-user-role-editor'),
101
+ 'label' => __('Label', 'wpfront-user-role-editor'),
102
+ 'source' => __('Source', 'wpfront-user-role-editor'),
103
+ 'post_types' => __('Post Types', 'wpfront-user-role-editor'),
104
+ 'status' => __('Active', 'wpfront-user-role-editor'),
105
+ 'edited' => __('Edited', 'wpfront-user-role-editor')
106
+ );
107
+
108
+ return $columns;
109
+ }
110
+
111
+ function display_rows() {
112
+ foreach ($this->items as $item) {
113
+ $alt = empty($alt) ? 'alternate' : '';
114
+ ?>
115
+ <tr class="<?php echo $alt; ?>">
116
+ <?php
117
+ list( $columns, $hidden ) = $this->get_column_info();
118
+
119
+ foreach ($columns as $column_name => $column_display_name) {
120
+ $class = "class='$column_name column-$column_name'";
121
+
122
+ $style = '';
123
+ if (in_array($column_name, $hidden)) {
124
+ $style = ' style="display:none;"';
125
+ }
126
+
127
+ $attributes = "$class$style";
128
+
129
+ switch ($column_name) {
130
+ case 'cb':
131
+ $this->cb_cell($item);
132
+ break;
133
+
134
+ case 'name':
135
+ $this->name_cell($item, $attributes);
136
+ break;
137
+
138
+ case 'label':
139
+ $this->label_cell($item);
140
+ break;
141
+
142
+ case 'source':
143
+ $this->source_cell($item);
144
+ break;
145
+
146
+ case 'post_types':
147
+ $this->post_types_cell($item);
148
+ break;
149
+
150
+ case 'status':
151
+ $this->status_cell($item);
152
+ break;
153
+
154
+ case 'edited':
155
+ $this->edited_cell($item);
156
+ break;
157
+ }
158
+ }
159
+ ?>
160
+ </tr>
161
+ <?php
162
+ }
163
+ }
164
+
165
+ protected function cb_cell($item) {
166
+ ?>
167
+ <th scope="row" class="check-column">
168
+ <?php if ($item->can_edit) { ?>
169
+ <label class="screen-reader-text" for="taxonomy_select" ?></label>
170
+ <input type="checkbox" id="taxonomy_<?php echo $item->name; ?>" name="taxonomies[]" value="<?php echo esc_attr($item->name); ?>" />
171
+ <?php } ?>
172
+ </th>
173
+ <?php
174
+ }
175
+
176
+ protected function name_cell($item, $attributes) {
177
+ ?>
178
+
179
+ <td <?php echo $attributes; ?>>
180
+ <?php
181
+ if ($item->can_edit) {
182
+ $edit_link = $this->controller->get_edit_url($item->name);
183
+ ?>
184
+ <strong>
185
+ <a href="<?php echo $edit_link; ?>" class="edit">
186
+ <?php echo $item->name; ?>
187
+ </a>
188
+ </strong>
189
+ <?php
190
+ } else {
191
+ ?> <?php echo $item->name; ?> <?php
192
+ } $actions = array();
193
+ if ($item->can_edit) {
194
+ $edit_link = $this->controller->get_edit_url($item->name);
195
+ $display = __('Edit', 'wpfront-user-role-editor');
196
+ $actions['edit'] = "<a href='$edit_link'>$display</a>";
197
+ }
198
+ if ($item->can_delete) {
199
+ $delete_link = $this->controller->get_delete_url($item->name);
200
+ $display = __('Delete', 'wpfront-user-role-editor');
201
+ $actions['delete'] = "<a href='$delete_link'>$display</a>";
202
+ }
203
+ if ($item->can_activate) {
204
+ $activate_link = $this->controller->get_activate_url($item->name);
205
+ $display = __('Activate', 'wpfront-user-role-editor');
206
+ $actions['activate'] = "<a href='$activate_link'>$display</a>";
207
+ }
208
+ if ($item->can_deactivate) {
209
+ $deactivate_link = $this->controller->get_deactivate_url($item->name);
210
+ $display = __('Deactivate', 'wpfront-user-role-editor');
211
+ $actions['deactivate'] = "<a href='$deactivate_link'>$display</a>";
212
+ }
213
+ if ($item->can_clone) {
214
+ $clone_link = $this->controller->get_clone_url($item->name);
215
+ $display = __('Clone', 'wpfront-user-role-editor');
216
+ $actions['clone'] = "<a href='$clone_link'>$display</a>";
217
+ }
218
+ if ($item->can_restore) {
219
+ $restore_link = $this->controller->get_restore_url($item->name);
220
+ $display = __('Restore', 'wpfront-user-role-editor');
221
+ $actions['restore'] = "<a href='$restore_link'>$display</a>";
222
+ }
223
+ echo $this->row_actions($actions);
224
+ ?>
225
+ </td>
226
+ <?php
227
+ }
228
+
229
+ protected function label_cell($item) {
230
+ ?>
231
+ <td class="label column-label">
232
+ <?php echo $item->label; ?>
233
+ </td>
234
+ <?php
235
+ }
236
+
237
+ protected function source_cell($item) {
238
+ ?>
239
+ <td class="source column-source">
240
+ <?php
241
+ switch ($item->source_type) {
242
+ case 0:
243
+ echo __('Built-In', 'wpfront-user-role-editor');
244
+ break;
245
+
246
+ case 1:
247
+ echo __('Other', 'wpfront-user-role-editor');
248
+ break;
249
+
250
+ default:
251
+ echo __('User Defined', 'wpfront-user-role-editor');
252
+ break;
253
+ }
254
+ ?>
255
+ </td>
256
+ <?php
257
+ }
258
+
259
+ protected function post_types_cell($item) {
260
+ ?>
261
+ <td class="post-types column-post-types">
262
+ <?php
263
+ $post_types = $item->post_types;
264
+ foreach ($post_types as $post_type) {
265
+ if ($post_type === 'link') {
266
+ $object_types[] = $post_type;
267
+ } elseif (!empty($post_type)) {
268
+ $object_type = get_post_type_object($post_type);
269
+ if (!empty($object_type)) {
270
+ $object_types[] = $object_type->label;
271
+ }
272
+ }
273
+ }
274
+ if(!empty($object_types)) {
275
+ $object_types = implode(', ', $object_types);
276
+ echo $object_types;
277
+ }
278
+ ?>
279
+ </td>
280
+ <?php
281
+ }
282
+
283
+ protected function status_cell($item) {
284
+ $i = '';
285
+ ?>
286
+ <td class="status column-status">
287
+ <?php
288
+ switch ($item->status) {
289
+ case 0:
290
+ $i = '<i class ="fa fa-times"></i>';
291
+ break;
292
+
293
+ case 1:
294
+ $i = '<i class ="fa fa-check"></i>';
295
+ break;
296
+ }
297
+ echo $i;
298
+ ?>
299
+ </td>
300
+ <?php
301
+ }
302
+
303
+ protected function edited_cell($item) {
304
+ $i = '';
305
+ if (!empty($item->entity)) {
306
+ $i = '<i class ="fa fa-check-circle"></i>';
307
+ }
308
+ ?>
309
+ <td class ="edited column-edited">
310
+ <?php echo $i; ?>
311
+ </td>
312
+ <?php
313
+ }
314
+
315
+ }
316
+
317
+ }
includes/taxonomies/class-taxonomies.php ADDED
@@ -0,0 +1,1210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Controller for WPFront User Role Editor Taxonomies
27
+ *
28
+ * @author Vaisagh D <vaisaghd@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Taxonomies;
33
+
34
+ use WPFront\URE\WPFront_User_Role_Editor as WPFURE;
35
+
36
+ if (!defined('ABSPATH')) {
37
+ exit();
38
+ }
39
+
40
+ require_once dirname(__FILE__) . '/entity-taxonomies.php';
41
+ require_once dirname(__FILE__) . '/template-taxonomies.php';
42
+ require_once dirname(__FILE__) . '/template-add-edit.php';
43
+ require_once dirname(__FILE__) . '/template-delete.php';
44
+
45
+ if (!class_exists('\WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies')) {
46
+
47
+ /**
48
+ * Taxonomies List class
49
+ *
50
+ * @author Vaisagh D <vaisaghd@wpfront.com>
51
+ * @copyright 2014 WPFront.com
52
+ */
53
+ class WPFront_User_Role_Editor_Taxonomies extends \WPFront\URE\WPFront_User_Role_Editor_View_Controller {
54
+
55
+ const STATUS_ACTIVE = 1;
56
+ const STATUS_INACTIVE = 0;
57
+ const SOURCE_TYPE_BUILTIN = 0;
58
+ const SOURCE_TYPE_OTHER = 1;
59
+ const SOURCE_TYPE_USER_DEFINED = 2;
60
+ const MENU_SLUG = 'wpfront-user-role-editor-taxonomies';
61
+ const DATA_EDITED_KEY = \WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type::DATA_EDITED_KEY; //let Post Type handle rewrite rules flush.
62
+
63
+ private $entities = null;
64
+ private $taxonomies_cache = null;
65
+ private $taxonomies_cache_clear = false;
66
+ private $taxonomy_args = array();
67
+ private $objView = null;
68
+ private $taxonomies_unregistered = array();
69
+ public $errorMsg = null;
70
+ protected $AddEditViewClass = null;
71
+
72
+ protected function setUp() {
73
+ $this->_setUp('edit_taxonomies', self::MENU_SLUG);
74
+ $this->AddEditViewClass = WPFront_User_Role_Editor_Taxonomies_Add_Edit_View::class;
75
+ }
76
+
77
+ protected function initialize() {
78
+ add_action('init', array($this, 'register_taxonomy'), PHP_INT_MAX - 1);
79
+ add_filter('register_taxonomy_args', array($this, 'register_taxonomy_args'), 1, 3);
80
+ add_action('registered_taxonomy', array($this, 'deactivate_other_taxonomies'), PHP_INT_MAX, 3);
81
+ add_action('registered_taxonomy', array($this, 'registered_taxonomy'), 1, 3);
82
+ add_action('registered_taxonomy', array($this, 'attach_post_types_on_taxonomy_registration'), 2, 1);
83
+ add_action('registered_post_type', array($this, 'attach_post_types_on_post_type_registration'), 2, 1);
84
+
85
+ if (!is_admin()) {
86
+ return;
87
+ }
88
+
89
+ $this->set_admin_menu(__('Taxonomies', 'wpfront-user-role-editor'), __('Taxonomies', 'wpfront-user-role-editor'), 70);
90
+ }
91
+
92
+ /**
93
+ * Register the user defined taxonomy.
94
+ *
95
+ * @return string
96
+ */
97
+ public function register_taxonomy() {
98
+ $taxonomies = $this->get_all_taxonomies_data(); //calling data before registration allows to caputre correct source type.
99
+ foreach ($taxonomies as $data) {
100
+ if ($data->status == self::STATUS_ACTIVE && $data->source_type === self::SOURCE_TYPE_USER_DEFINED) {
101
+ $args = $data->taxonomy_arg;
102
+ register_taxonomy($data->name, $data->post_types, $args);
103
+ }
104
+ }
105
+
106
+ //set state of late registrations
107
+ add_action('registered_taxonomy', array($this, 'clear_cache'));
108
+
109
+ //handle post registrations of post types
110
+ add_action('registered_taxonomy_for_object_type', array($this, 'registered_taxonomy_for_object_type'), PHP_INT_MAX, 2);
111
+ add_action('unregistered_taxonomy_for_object_type', array($this, 'unregistered_taxonomy_for_object_type'), PHP_INT_MAX, 2);
112
+ }
113
+
114
+ /**
115
+ * Store taxonomy registration arguments and merge them with edited arguments.
116
+ *
117
+ * @param type $args
118
+ * @param type $taxonomy
119
+ * @param type $object_type
120
+ * @return type
121
+ */
122
+ public function register_taxonomy_args($args, $taxonomy, $object_type) {
123
+ $entity_all = $this->get_all_entities();
124
+ if (isset($entity_all[$taxonomy])) {
125
+ $entity = $entity_all[$taxonomy];
126
+ $saved = $entity->taxonomy_arg;
127
+ if(empty($saved)){
128
+ $saved = array();
129
+ }
130
+
131
+ if (!empty($entity->capability_type)) { //TODO: move location
132
+ $type = $entity->capability_type;
133
+ $caps = $this->get_custom_caps($type);
134
+ $saved['capabilities'] = $caps;
135
+ }
136
+
137
+ $args = array_merge($args, $saved);
138
+ }
139
+
140
+ $this->taxonomy_args[$taxonomy] = $args;
141
+
142
+ return $args;
143
+ }
144
+
145
+ public function attach_post_types_on_taxonomy_registration($taxonomy) {
146
+ $entity_all = $this->get_all_entities();
147
+ if (isset($entity_all[$taxonomy])) {
148
+ $post_types = $entity_all[$taxonomy]->post_types;
149
+ foreach ($post_types as $post_type) {
150
+ register_taxonomy_for_object_type($taxonomy, $post_type);
151
+ }
152
+ }
153
+ }
154
+
155
+ /**
156
+ * To handle late post type registrations.
157
+ *
158
+ * @param string $post_type
159
+ */
160
+ public function attach_post_types_on_post_type_registration($post_type) {
161
+ $entity_all = $this->get_all_entities();
162
+ foreach ($entity_all as $taxonomy => $entity) {
163
+ $post_types = $entity->post_types;
164
+ if(in_array($post_type, $post_types)) {
165
+ register_taxonomy_for_object_type($taxonomy, $post_type);
166
+ }
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Retrieve singular name after registration if it doesn't exist. WP doesn't provide it as part of arguments.
172
+ *
173
+ * @param type $taxonomy
174
+ * @param type $object_type
175
+ * @param type $args
176
+ * @return type
177
+ */
178
+ public function registered_taxonomy($taxonomy, $object_type, $args) {
179
+ if (empty($this->taxonomy_args[$taxonomy])) {
180
+ return;
181
+ }
182
+
183
+ if (!empty($this->taxonomy_args[$taxonomy]['labels']['singular_name'])) {
184
+ return;
185
+ }
186
+
187
+ $this->taxonomy_args[$taxonomy]['labels']['singular_name'] = $args['labels']->singular_name;
188
+ }
189
+
190
+ /**
191
+ * Deactivate other taxonomy based on DB state.
192
+ *
193
+ * @param type $taxonomy
194
+ * @param type $object_type
195
+ * @param type $args
196
+ * @return type
197
+ */
198
+ public function deactivate_other_taxonomies($taxonomy, $object_type, $args) {
199
+ if (!empty($args['_builtin'])) {
200
+ return;
201
+ }
202
+
203
+ $entity_all = $this->get_all_entities();
204
+ if (isset($entity_all[$taxonomy]) && $entity_all[$taxonomy]->status === self::STATUS_INACTIVE) {
205
+ $taxonomy_object = get_taxonomy($taxonomy);
206
+ $this->taxonomies_unregistered[$taxonomy] = $taxonomy_object;
207
+ unregister_taxonomy($taxonomy);
208
+ }
209
+ }
210
+
211
+ public function load_view() {
212
+ if (!parent::load_view()) {
213
+ return;
214
+ }
215
+
216
+ if ((!empty($_POST['action']) && $_POST['action'] !== '-1') || (!empty($_POST['action2']) && $_POST['action2'] !== '-1')) {
217
+ $action = $_POST['action'] === '-1' ? $_POST['action2'] : $_POST['action'];
218
+
219
+ $taxonomies = [];
220
+ if (!empty($_POST['taxonomies']) && is_array($_POST['taxonomies'])) {
221
+ foreach ($_POST['taxonomies'] as $value) {
222
+ $data = $this->get_taxonomy_data($value);
223
+ if (!empty($data)) {
224
+ $taxonomies[] = $data;
225
+ }
226
+ }
227
+ }
228
+
229
+ switch ($action) {
230
+ case 'delete':
231
+ case 'restore':
232
+ $this->handle_action($action, $taxonomies);
233
+ return;
234
+
235
+ case 'activate':
236
+ case 'deactivate':
237
+ $this->activate_deactivate_taxonomies($action, $taxonomies);
238
+ return;
239
+ }
240
+
241
+ wp_redirect($this->get_list_url());
242
+ exit;
243
+ }
244
+
245
+ if (!empty($_GET['screen'])) {
246
+ $screen = $_GET['screen'];
247
+ switch ($screen) {
248
+ case 'activate':
249
+ case 'deactivate':
250
+ $this->activate_deactivate_taxonomies($screen);
251
+ return;
252
+
253
+ case 'add-new':
254
+ case 'edit':
255
+ $this->add_edit_taxonomies($screen);
256
+ return;
257
+ case 'delete':
258
+ case 'restore':
259
+ $this->handle_action($screen);
260
+ return;
261
+
262
+ default:
263
+ break;
264
+ }
265
+ }
266
+
267
+ $this->objView = new WPFront_User_Role_Editor_Taxonomies_List_View($this);
268
+ return;
269
+ }
270
+
271
+ private function activate_deactivate_taxonomies($screen, $datas = null) {
272
+ switch ($screen) {
273
+ case 'activate':
274
+ $cap = 'edit_taxonomies';
275
+ $check = 'can_activate';
276
+ $q_arg = 'taxonomy-activated';
277
+ break;
278
+
279
+ case 'deactivate':
280
+ $cap = 'edit_taxonomies';
281
+ $check = 'can_deactivate';
282
+ $q_arg = 'taxonomy-deactivated';
283
+ break;
284
+
285
+ default:
286
+ wp_redirect($this->get_list_url());
287
+ exit;
288
+ }
289
+
290
+ if (!current_user_can($cap)) {
291
+ $this->WPFURE->permission_denied();
292
+ exit;
293
+ }
294
+
295
+ if ($datas === null) { //url activate/deactivate
296
+ if (empty($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'])) {
297
+ $this->WPFURE->permission_denied();
298
+ exit;
299
+ }
300
+
301
+ $data = $this->get_taxonomy_data_from_url();
302
+ if (empty($data)) {
303
+ return;
304
+ }
305
+
306
+ $datas = [$data];
307
+ } else { //bulk post
308
+ check_admin_referer('bulk-taxonomies');
309
+ }
310
+
311
+ $count = 0;
312
+ foreach ($datas as $data) {
313
+ if ($data->$check) {
314
+ if (empty($data->entity)) { //no db data, either built-in or other taxonomies.
315
+ if ($screen === 'deactivate') {
316
+ $entity = new WPFront_User_Role_Editor_Taxonomies_Entity();
317
+ $entity->name = $data->name;
318
+ $entity->label = $data->label;
319
+ $entity->status = self::STATUS_INACTIVE;
320
+ $entity->taxonomy_arg = $this->taxonomy_args[$data->name];
321
+ $entity->update();
322
+ $count++;
323
+ }
324
+ continue;
325
+ }
326
+
327
+ if ($screen === 'activate') {
328
+ $data->entity->update_status(self::STATUS_ACTIVE);
329
+ } else {
330
+ $data->entity->update_status(self::STATUS_INACTIVE);
331
+ }
332
+ $count++;
333
+ }
334
+ }
335
+
336
+ wp_safe_redirect(add_query_arg($q_arg, $count, $this->get_list_url()));
337
+ exit;
338
+ }
339
+
340
+ protected function add_edit_taxonomies($screen) {
341
+ $data = null;
342
+ $clone = null;
343
+ if ($screen == 'edit') {
344
+ if (!current_user_can('edit_taxonomies')) {
345
+ $this->WPFURE->permission_denied();
346
+ exit;
347
+ }
348
+ $data = $this->get_taxonomy_data_from_url();
349
+ if (empty($data)) {
350
+ return;
351
+ }
352
+ if (!$data->can_edit) {
353
+ $this->WPFURE->permission_denied();
354
+ exit;
355
+ }
356
+ } elseif ($screen === 'add-new') {
357
+ if (!current_user_can('create_taxonomies')) {
358
+ $this->WPFURE->permission_denied();
359
+ exit;
360
+ }
361
+ if (!empty($_GET['clone'])) {
362
+ $clone = $this->get_taxonomy_data($_GET['clone']);
363
+ }
364
+ }
365
+ $this->objView = new $this->AddEditViewClass(
366
+ $this,
367
+ $data,
368
+ empty($data) ? null : get_taxonomy($data->name),
369
+ $clone
370
+ );
371
+ if (!empty($_POST['submit']) || !empty($_POST['submit2'])) {
372
+ check_admin_referer('add-edit-taxonomies');
373
+
374
+ $entity = null;
375
+ if ($screen == 'add-new') {
376
+ if (!current_user_can('create_taxonomies')) {
377
+ $this->WPFURE->permission_denied();
378
+ exit;
379
+ }
380
+ $name = $this->get_submitted_text('name');
381
+ if (empty($name)) {
382
+ $this->errorMsg = __('Name must be provided.', 'wpfront-user-role-editor');
383
+ return;
384
+ }
385
+
386
+ if (!$this->is_valid_slug($name)) {
387
+ $this->errorMsg = __('This taxonomy name is not allowed (Use only lowercase letters, numbers, underscores and hyphens).', 'wpfront-user-role-editor');
388
+ return;
389
+ }
390
+
391
+ if (!empty($this->get_taxonomy_data($name))) {
392
+ $this->errorMsg = __('Taxonomy already exists.', 'wpfront-user-role-editor');
393
+ return;
394
+ }
395
+
396
+ $reserved = ['attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name',
397
+ 'comments_per_page', 'comments_popup', 'custom', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'embed', 'error', 'exact',
398
+ 'feed', 'fields', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name', 'nav_menu', 'nonce', 'nopaging',
399
+ 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format',
400
+ 'post_mime_type', 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots',
401
+ 's', 'search', 'second', 'sentence', 'showposts', 'static', 'status', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in',
402
+ 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'terms', 'theme', 'title', 'type', 'types', 'w', 'withcomments', 'withoutcomments',
403
+ 'year'
404
+ ];
405
+ if (in_array($name, $reserved)) {
406
+ $this->errorMsg = __('This taxonomy name is reserved and can not be added.', 'wpfront-user-role-editor');
407
+ return;
408
+ }
409
+
410
+ $entity = new WPFront_User_Role_Editor_Taxonomies_Entity();
411
+ $entity->name = $name;
412
+ $entity->status = self::STATUS_ACTIVE;
413
+ } else {
414
+ if (!empty($data->entity)) {
415
+ $entity = $data->entity;
416
+ } else {
417
+ $entity = new WPFront_User_Role_Editor_Taxonomies_Entity();
418
+ $entity->name = $data->name;
419
+ $entity->status = self::STATUS_ACTIVE;
420
+ }
421
+ }
422
+
423
+ $labels = $this->get_submitted_text('label');
424
+ if (empty($labels)) {
425
+ $this->errorMsg = __('Plural label must be provided.', 'wpfront-user-role-editor');
426
+ return;
427
+ }
428
+
429
+ $entity->label = $labels; //WordPress stores plural on label.
430
+
431
+ $label = $this->get_submitted_text('singular_name');
432
+ if (empty($label)) {
433
+ $this->errorMsg = __('Singular label must be provided.', 'wpfront-user-role-editor');
434
+ return;
435
+ }
436
+
437
+ $entity->post_types = $this->get_submitted_array('post_types');
438
+
439
+ $taxonomy_args = array();
440
+ $taxonomy_args = $this->get_advanced_settings_arg();
441
+ $taxonomy_args['labels'] = $this->get_labels_arg();
442
+
443
+ if (!empty($this->errorMsg)) {
444
+ return;
445
+ }
446
+
447
+ $taxonomy_args = $this->sanitize_add_edit_taxonomy_args($screen, $taxonomy_args, $entity);
448
+
449
+ if (!empty($this->errorMsg)) {
450
+ return;
451
+ }
452
+
453
+ $entity->taxonomy_arg = $taxonomy_args;
454
+
455
+ if ($screen == 'add-new') {
456
+ $result = $entity->add();
457
+ $url_arg = 'taxonomy-added';
458
+ } else {
459
+ $result = $entity->update();
460
+ $url_arg = 'taxonomy-updated';
461
+ }
462
+
463
+ if ($result === false) {
464
+ $this->errorMsg = __('Unexpected error occured.', 'wpfront-user-role-editor');
465
+ return;
466
+ }
467
+
468
+ if (!current_user_can('edit_taxonomies')) {
469
+ wp_safe_redirect(add_query_arg('taxonomy-added', 'true', $this->get_list_url()));
470
+ exit;
471
+ } else {
472
+ wp_safe_redirect(add_query_arg($url_arg, 'true', $this->get_edit_url($entity->name)));
473
+ exit;
474
+ }
475
+ }
476
+ }
477
+
478
+ private function handle_action($action, $datas = null) {
479
+ switch ($action) {
480
+ case 'delete':
481
+ $cap = 'delete_taxonomies';
482
+ $check = 'can_delete';
483
+ $q_arg = 'taxonomy-deleted';
484
+ break;
485
+
486
+ case 'restore':
487
+ $cap = 'edit_taxonomies';
488
+ $check = 'can_restore';
489
+ $q_arg = 'taxonomy-restored';
490
+ break;
491
+
492
+ default:
493
+ wp_redirect($this->get_list_url());
494
+ exit;
495
+ }
496
+
497
+ if (!current_user_can($cap)) {
498
+ $this->WPFURE->permission_denied();
499
+ exit;
500
+ }
501
+
502
+ $entities = [];
503
+ if (empty($datas)) {
504
+ $data = $this->get_taxonomy_data_from_url();
505
+ if (!empty($data->$check)) {
506
+ $entities = [$data->entity];
507
+ }
508
+ } else {
509
+ foreach ($datas as $data) {
510
+ if ($data->$check) {
511
+ $entities[] = $data->entity;
512
+ }
513
+ }
514
+ }
515
+
516
+ if (empty($entities)) {
517
+ wp_redirect($this->get_list_url());
518
+ exit;
519
+ }
520
+
521
+ if (!empty($_POST['submit'])) {
522
+ check_admin_referer('bulk-action-view-taxonomy');
523
+ foreach ($entities as $entity) {
524
+ $entity->delete($action);
525
+ }
526
+ wp_safe_redirect(add_query_arg($q_arg, 'true', $this->get_list_url()));
527
+ exit;
528
+ }
529
+
530
+ $this->objView = new WPFront_User_Role_Editor_Taxonomy_Delete_View($this, $entities, $action);
531
+ }
532
+
533
+ protected function sanitize_add_edit_taxonomy_args($screen, $taxonomy_args, $entity) {
534
+ return $taxonomy_args;
535
+ }
536
+
537
+ private function get_labels_arg() {
538
+ $args = array();
539
+ $args['name'] = $this->get_submitted_text('label');
540
+
541
+ $props = [
542
+ 'singular_name',
543
+ 'search_items',
544
+ 'popular_items',
545
+ 'all_items',
546
+ 'edit_item',
547
+ 'parent_item',
548
+ 'parent_item_colon',
549
+ 'view_item',
550
+ 'update_item',
551
+ 'add_new_item',
552
+ 'new_item_name',
553
+ 'separate_items_with_commas',
554
+ 'add_or_remove_items',
555
+ 'choose_from_most_used',
556
+ 'not_found',
557
+ 'no_terms',
558
+ 'filter_by_item',
559
+ 'items_list_navigation',
560
+ 'items_list',
561
+ 'most_used',
562
+ 'back_to_items'
563
+ ];
564
+ foreach ($props as $prop) {
565
+ $value = $this->get_submitted_text($prop);
566
+ if ($value !== null) {
567
+ $args[$prop] = $value;
568
+ }
569
+ }
570
+
571
+
572
+ return $args;
573
+ }
574
+
575
+ private function get_advanced_settings_arg() {
576
+ $args = array();
577
+
578
+ $props = [
579
+ 'rest_base',
580
+ 'rest_controller_class'
581
+ ];
582
+
583
+ foreach ($props as $prop) {
584
+ $value = $this->get_submitted_text($prop);
585
+ if ($value !== null) {
586
+ $args[$prop] = $value;
587
+ }
588
+ }
589
+
590
+ $props = [
591
+ 'public',
592
+ 'hierarchical',
593
+ 'publicly_queryable',
594
+ 'show_ui',
595
+ 'show_in_menu',
596
+ 'show_in_nav_menus',
597
+ 'show_in_rest',
598
+ 'show_tagcloud',
599
+ 'show_in_quick_edit',
600
+ 'show_admin_column',
601
+ 'query_var',
602
+ 'rewrite'
603
+ ];
604
+
605
+ foreach ($props as $prop) {
606
+ $value = $this->get_submitted_boolean($prop);
607
+ if ($value !== null) {
608
+ $args[$prop] = $value;
609
+ }
610
+ }
611
+
612
+ if (!empty($args['query_var'])) {
613
+ $slug = $this->get_submitted_text('query_var_slug');
614
+ if ($slug !== null) {
615
+ $args['query_var'] = $slug;
616
+ }
617
+ }
618
+
619
+ if (!empty($args['rewrite'])) {
620
+ $rewrite_array = [];
621
+
622
+ $slug = $this->get_submitted_text('rewrite_slug');
623
+ if (!empty($slug)) {
624
+ if (!$this->is_valid_rewrite_slug($slug)) {
625
+ $this->errorMsg = __('This rewrite slug is not allowed (Use only lowercase letters, numbers, underscores, hyphens and slashes).', 'wpfront-user-role-editor');
626
+ return;
627
+ } else {
628
+ $rewrite_array['slug'] = $slug;
629
+ }
630
+ }
631
+
632
+ $with_front = $this->get_submitted_boolean('rewrite_with_front');
633
+ if (is_bool($with_front)) {
634
+ $rewrite_array['with_front'] = $with_front;
635
+ }
636
+
637
+ $ep_mask = $this->get_submitted_text('rewrite_ep_mask');
638
+ if ($ep_mask !== null) {
639
+ if (!$this->is_valid_ep_mask($ep_mask)) {
640
+ $this->errorMsg = __('This Rewrite EP Mask is not allowed (Use only numbers).', 'wpfront-user-role-editor');
641
+ return;
642
+ }
643
+ $rewrite_array['ep_mask'] = $ep_mask;
644
+ }
645
+
646
+
647
+ $hierarchical = $this->get_submitted_boolean('rewrite_hierarchical');
648
+ if (is_bool($hierarchical)) {
649
+ $rewrite_array['hierarchical'] = $hierarchical;
650
+ }
651
+
652
+ if (empty($rewrite_array)) {
653
+ $args['rewrite'] = true;
654
+ } else {
655
+ $args['rewrite'] = $rewrite_array;
656
+ }
657
+ }
658
+
659
+ return $args;
660
+ }
661
+
662
+ /**
663
+ * Displays the taxonomies view.
664
+ */
665
+ public function view() {
666
+ if (!parent::view()) {
667
+ return;
668
+ }
669
+
670
+ if (empty($this->objView)) {
671
+ $this->objView = new WPFront_User_Role_Editor_Taxonomies_List_View($this);
672
+ }
673
+
674
+ $this->objView->view();
675
+ }
676
+
677
+ public function apply_active_list_filter() {
678
+ $taxonomies = $this->get_all_taxonomies_data();
679
+ $taxonomies = $this->sort_taxonomies_data($taxonomies);
680
+
681
+ switch ($this->get_active_list_filter()) {
682
+ case 'all':
683
+ break;
684
+
685
+ case 'builtin':
686
+ foreach ($taxonomies as $key => $entity) {
687
+ if ($entity->source_type === self::SOURCE_TYPE_OTHER || $entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
688
+ unset($taxonomies[$key]);
689
+ }
690
+ }
691
+ break;
692
+
693
+ case 'other':
694
+ foreach ($taxonomies as $key => $entity) {
695
+ if ($entity->source_type === self::SOURCE_TYPE_BUILTIN || $entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
696
+ unset($taxonomies[$key]);
697
+ }
698
+ }
699
+ break;
700
+
701
+ case 'userdefined':
702
+ foreach ($taxonomies as $key => $entity) {
703
+ if ($entity->source_type === self::SOURCE_TYPE_OTHER || $entity->source_type === self::SOURCE_TYPE_BUILTIN) {
704
+ unset($taxonomies[$key]);
705
+ }
706
+ }
707
+ break;
708
+
709
+ case 'active':
710
+ foreach ($taxonomies as $key => $entity) {
711
+ if ($entity->status === self::STATUS_INACTIVE) {
712
+ unset($taxonomies[$key]);
713
+ }
714
+ }
715
+ break;
716
+
717
+ case 'inactive':
718
+ foreach ($taxonomies as $key => $entity) {
719
+ if ($entity->status === self::STATUS_ACTIVE) {
720
+ unset($taxonomies[$key]);
721
+ }
722
+ }
723
+ break;
724
+ }
725
+
726
+ return $taxonomies;
727
+ }
728
+
729
+ public function get_active_list_filter() {
730
+ if (empty($_GET['list'])) {
731
+ return 'all';
732
+ }
733
+
734
+ $list = $_GET['list'];
735
+
736
+ switch ($list) {
737
+ case 'all':
738
+ case 'builtin':
739
+ case 'other':
740
+ case 'userdefined':
741
+ case 'active':
742
+ case 'inactive':
743
+ break;
744
+
745
+ default:
746
+ $list = 'all';
747
+ break;
748
+ }
749
+
750
+ return $list;
751
+ }
752
+
753
+ protected function get_all_entities() {
754
+ if ($this->entities !== null) {
755
+ return $this->entities;
756
+ }
757
+
758
+ $entity = new WPFront_User_Role_Editor_Taxonomies_Entity();
759
+ $this->entities = $entity->get_all();
760
+
761
+ $this->entities = $this->sanitize_pro_fields($this->entities);
762
+
763
+ return $this->entities;
764
+ }
765
+
766
+ protected function sanitize_pro_fields($entities) {
767
+ foreach ($entities as $post_type => $entity) {
768
+ $entity->capability_type = null;
769
+ }
770
+
771
+ return $entities;
772
+ }
773
+
774
+ public function search($search) {
775
+ $taxonomies = $this->get_all_taxonomies_data();
776
+ $taxonomies = $this->sort_taxonomies_data($taxonomies);
777
+
778
+ if (empty($search)) {
779
+ return $taxonomies;
780
+ }
781
+
782
+ foreach ($taxonomies as $name => $item) {
783
+ if (strpos($item->name, $search) !== false) {
784
+ continue;
785
+ }
786
+
787
+ if (strpos($item->label, $search) !== false) {
788
+ continue;
789
+ }
790
+
791
+ unset($taxonomies[$name]);
792
+ }
793
+
794
+ return $taxonomies;
795
+ }
796
+
797
+ protected function sort_taxonomies_data($taxonomies) {
798
+ $built_in_taxonomies = array();
799
+ $other_taxonomies = array();
800
+ $user_defined_taxonomies = array();
801
+
802
+ foreach ($taxonomies as $taxonomy => $data) {
803
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN) {
804
+ $built_in_taxonomies[$taxonomy] = $data;
805
+ continue;
806
+ }
807
+
808
+ if ($data->source_type === self::SOURCE_TYPE_OTHER) {
809
+ $other_taxonomies[$taxonomy] = $data;
810
+ continue;
811
+ }
812
+
813
+ if ($data->source_type === self::SOURCE_TYPE_USER_DEFINED) {
814
+ $user_defined_taxonomies[$taxonomy] = $data;
815
+ continue;
816
+ }
817
+ }
818
+
819
+ ksort($built_in_taxonomies);
820
+ ksort($other_taxonomies);
821
+ ksort($user_defined_taxonomies);
822
+ return array_merge($built_in_taxonomies, $other_taxonomies, $user_defined_taxonomies);
823
+ }
824
+
825
+ public function get_list_filter_data() {
826
+ $filter_data = array();
827
+ $built_in = [];
828
+ $other = [];
829
+ $user_defined = [];
830
+ $active = [];
831
+ $inactive = [];
832
+ $taxonomies = $this->get_all_taxonomies_data();
833
+ $page = $this->get_self_url();
834
+
835
+ $filter_data['all'] = array(
836
+ 'display' => __('All', 'wpfront-user-role-editor'),
837
+ 'url' => $page . '&list=all',
838
+ 'count' => count($taxonomies)
839
+ );
840
+
841
+ foreach ($taxonomies as $entity) {
842
+ if ($entity->source_type === self::SOURCE_TYPE_BUILTIN) {
843
+ $built_in[] = $entity;
844
+ } elseif ($entity->source_type === self::SOURCE_TYPE_OTHER) {
845
+ $other[] = $entity;
846
+ } elseif ($entity->source_type === self::SOURCE_TYPE_USER_DEFINED) {
847
+ $user_defined[] = $entity;
848
+ }
849
+
850
+ if ($entity->status === self::STATUS_ACTIVE) {
851
+ $active[] = $entity;
852
+ } elseif ($entity->status === self::STATUS_INACTIVE) {
853
+ $inactive[] = $entity;
854
+ }
855
+ }
856
+
857
+ $filter_data['builtin'] = array(
858
+ 'display' => __('Built-In', 'wpfront-user-role-editor'),
859
+ 'url' => $page . '&list=builtin',
860
+ 'count' => count($built_in)
861
+ );
862
+
863
+ $filter_data['other'] = array(
864
+ 'display' => __('Other', 'wpfront-user-role-editor'),
865
+ 'url' => $page . '&list=other',
866
+ 'count' => count($other)
867
+ );
868
+
869
+ $filter_data['userdefined'] = array(
870
+ 'display' => __('User Defined', 'wpfront-user-role-editor'),
871
+ 'url' => $page . '&list=userdefined',
872
+ 'count' => count($user_defined)
873
+ );
874
+
875
+ $filter_data['active'] = array(
876
+ 'display' => __('Active', 'wpfront-user-role-editor'),
877
+ 'url' => $page . '&list=active',
878
+ 'count' => count($active)
879
+ );
880
+
881
+ $filter_data['inactive'] = array(
882
+ 'display' => __('Inactive', 'wpfront-user-role-editor'),
883
+ 'url' => $page . '&list=inactive',
884
+ 'count' => count($inactive)
885
+ );
886
+
887
+ return $filter_data;
888
+ }
889
+
890
+ public function clear_cache() {
891
+ $this->taxonomies_cache_clear = true;
892
+ }
893
+
894
+ public function get_all_taxonomies_data() {
895
+ if (!$this->taxonomies_cache_clear && !empty($this->taxonomies_cache)) {
896
+ return $this->taxonomies_cache;
897
+ }
898
+
899
+ $has_edit_cap = current_user_can('edit_taxonomies');
900
+ $has_delete_cap = current_user_can('delete_taxonomies');
901
+ $has_clone_cap = current_user_can('create_taxonomies');
902
+
903
+ $taxonomies = get_taxonomies([], 'objects');
904
+ $exiting = array();
905
+ foreach ($taxonomies as $name => $taxonomy_obj) {
906
+ if ($taxonomy_obj->_builtin && !is_taxonomy_viewable($name)) {
907
+ continue;
908
+ }
909
+
910
+ $data = new \stdClass();
911
+ $data->name = $taxonomy_obj->name;
912
+ $data->label = $taxonomy_obj->label;
913
+ $data->status = self::STATUS_ACTIVE;
914
+ $data->source_type = $taxonomy_obj->_builtin ? self::SOURCE_TYPE_BUILTIN : self::SOURCE_TYPE_OTHER;
915
+ $data->post_types = is_array($taxonomy_obj->object_type) ? $taxonomy_obj->object_type : [];
916
+ $data->taxonomy_arg = $this->taxonomy_args[$name];
917
+
918
+ if ($taxonomy_obj->_builtin) {
919
+ $data->capability_type = null;
920
+ } else {
921
+ $cap = $taxonomy_obj->cap->manage_terms;
922
+ if ($cap === 'manage_categories') {
923
+ $data->capability_type = null;
924
+ } else {
925
+ $data->capability_type = substr($cap, strlen('manage_'));
926
+ }
927
+ }
928
+
929
+ $data->entity = null;
930
+
931
+ $exiting[$name] = $data;
932
+ }
933
+
934
+ $entity_all = $this->get_all_entities();
935
+ $user_edited = [];
936
+ foreach ($entity_all as $name => $entity) {
937
+ $data = new \stdClass();
938
+ $data->name = $entity->name;
939
+ $data->label = $entity->label;
940
+ $data->status = $entity->status;
941
+ if (!isset($exiting[$name])) {
942
+ if (isset($this->taxonomies_unregistered[$entity->name])) {
943
+ $data->source_type = self::SOURCE_TYPE_OTHER;
944
+ } else {
945
+ $data->source_type = self::SOURCE_TYPE_USER_DEFINED;
946
+ }
947
+ } else {
948
+ $data->source_type = $exiting[$name]->source_type;
949
+ }
950
+ $data->post_types = $entity->post_types;
951
+ $data->capability_type = $entity->capability_type;
952
+ $data->entity = $entity;
953
+
954
+ $data->taxonomy_arg = (empty($entity->taxonomy_arg) && isset($exiting[$name]->taxonomy_arg)) ? $exiting[$name]->taxonomy_arg : $entity->taxonomy_arg;
955
+ if(empty($data->taxonomy_arg)) {
956
+ $data->taxonomy_arg = array();
957
+ }
958
+
959
+ $user_edited[$name] = $data;
960
+ }
961
+
962
+ //reset source types to intial state to take care of registration changing source type.
963
+ $taxes = array_merge($exiting, $user_edited);
964
+ foreach ($taxes as $name => $data) {
965
+ if(isset($this->taxonomies_cache[$name])) {
966
+ $data->source_type = $this->taxonomies_cache[$name]->source_type;
967
+ }
968
+ }
969
+
970
+ $this->taxonomies_cache = $taxes;
971
+
972
+ foreach ($this->taxonomies_cache as $name => $data) {
973
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN) {
974
+ $data->can_edit = $has_edit_cap && is_taxonomy_viewable($name);
975
+ } else {
976
+ $data->can_edit = $has_edit_cap;
977
+ }
978
+
979
+ $data->can_delete = $has_delete_cap && $data->source_type === self::SOURCE_TYPE_USER_DEFINED;
980
+
981
+ if ($data->source_type === self::SOURCE_TYPE_BUILTIN || $data->source_type === self::SOURCE_TYPE_OTHER) {
982
+ $data->can_restore = $has_edit_cap && !empty($data->entity);
983
+ } else {
984
+ $data->can_restore = false;
985
+ }
986
+
987
+ if ($data->can_edit && ($data->source_type === self::SOURCE_TYPE_USER_DEFINED || $data->source_type === self::SOURCE_TYPE_OTHER)) {
988
+ if ($data->status == self::STATUS_ACTIVE) {
989
+ $data->can_activate = false;
990
+ $data->can_deactivate = true;
991
+ } elseif ($data->status == self::STATUS_INACTIVE) {
992
+ $data->can_activate = true;
993
+ $data->can_deactivate = false;
994
+ }
995
+ } else {
996
+ $data->can_activate = false;
997
+ $data->can_deactivate = false;
998
+ }
999
+
1000
+ $data->can_clone = $has_clone_cap;
1001
+ }
1002
+
1003
+ return $this->taxonomies_cache;
1004
+ }
1005
+
1006
+ /**
1007
+ * Return taxonomy list url.
1008
+ *
1009
+ * @return string
1010
+ */
1011
+ public function get_list_url($key = '') {
1012
+ if (empty($key)) {
1013
+ return $this->get_self_url();
1014
+ }
1015
+
1016
+ return add_query_arg($key, 'true', $this->get_self_url());
1017
+ }
1018
+
1019
+ /**
1020
+ * Returns the add new taxonomies URL.
1021
+ *
1022
+ * @return string
1023
+ */
1024
+ public function get_add_new_url($clone = null) {
1025
+ $p = ['screen' => 'add-new'];
1026
+ if (!empty($clone)) {
1027
+ $p['clone'] = $clone;
1028
+ }
1029
+ return $this->get_self_url($p);
1030
+ }
1031
+
1032
+ /**
1033
+ * Returns the activate taxonomy URL.
1034
+ *
1035
+ * @return string
1036
+ */
1037
+ public function get_activate_url($name) {
1038
+ return wp_nonce_url($this->get_self_url(['screen' => 'activate', 'name' => $name]));
1039
+ }
1040
+
1041
+ /**
1042
+ * Returns the deactivate taxonomy URL.
1043
+ *
1044
+ * @return string
1045
+ */
1046
+ public function get_deactivate_url($name) {
1047
+ return wp_nonce_url($this->get_self_url(['screen' => 'deactivate', 'name' => $name]));
1048
+ }
1049
+
1050
+ /**
1051
+ * Returns the delete taxonomy URL.
1052
+ *
1053
+ * @return string
1054
+ */
1055
+ public function get_delete_url($name) {
1056
+ if (empty($name)) {
1057
+ return $this->get_self_url(['screen' => 'delete']);
1058
+ }
1059
+
1060
+ return $this->get_self_url(['screen' => 'delete', 'name' => $name]);
1061
+ }
1062
+
1063
+ public function get_edit_url($name) {
1064
+ return $this->get_self_url(['screen' => 'edit', 'name' => $name]);
1065
+ }
1066
+
1067
+ /**
1068
+ * Returns the clone taxonomies URL.
1069
+ *
1070
+ * @return string
1071
+ */
1072
+ public function get_clone_url($name) {
1073
+ return $this->get_add_new_url($name);
1074
+ }
1075
+
1076
+ public function get_restore_url($name) {
1077
+ if (empty($name)) {
1078
+ return $this->get_self_url(['screen' => 'restore']);
1079
+ }
1080
+
1081
+ return $this->get_self_url(['screen' => 'restore', 'name' => $name]);
1082
+ }
1083
+
1084
+ protected function get_submitted_text($name) {
1085
+ if (empty($_POST[$name])) {
1086
+ return null;
1087
+ }
1088
+
1089
+ $txt = trim($_POST[$name]);
1090
+
1091
+ if (empty($txt)) {
1092
+ return null;
1093
+ }
1094
+
1095
+ return $txt;
1096
+ }
1097
+
1098
+ protected function get_submitted_boolean($name) {
1099
+ if (isset($_POST[$name]) && $_POST[$name] == '') {
1100
+ return null;
1101
+ }
1102
+
1103
+ return !empty($_POST[$name]);
1104
+ }
1105
+
1106
+ private function get_submitted_array($name) {
1107
+ if (!empty($_POST[$name]) && is_array($_POST[$name])) {
1108
+ return $_POST[$name];
1109
+ }
1110
+
1111
+ return [];
1112
+ }
1113
+
1114
+ public function get_taxonomy_data($taxonomy) {
1115
+ $lists = $this->get_all_taxonomies_data();
1116
+ if (!empty($lists[$taxonomy])) {
1117
+ return $lists[$taxonomy];
1118
+ }
1119
+
1120
+ return null;
1121
+ }
1122
+
1123
+ protected function get_taxonomy_data_from_url() {
1124
+ if (empty($_GET['name'])) {
1125
+ wp_safe_redirect($this->get_self_url());
1126
+ exit;
1127
+ }
1128
+
1129
+ $taxonomy = $this->get_taxonomy_data($_GET['name']);
1130
+ if (empty($taxonomy)) {
1131
+ $this->errorMsg = __('Taxonomy do not exists.', 'wpfront-user-role-editor');
1132
+ $this->objView = new WPFront_User_Role_Editor_Taxonomies_List_View($this);
1133
+ return null;
1134
+ }
1135
+
1136
+ return $taxonomy;
1137
+ }
1138
+
1139
+ protected function is_valid_slug($slug) {
1140
+ if(empty($slug)) {
1141
+ return false;
1142
+ }
1143
+
1144
+ return sanitize_key($slug) === $slug;
1145
+ }
1146
+
1147
+ protected function is_valid_rewrite_slug($slug) {
1148
+ $key = strtolower($slug);
1149
+ $key = preg_replace('/[^a-z0-9_\-\/]/', '', $key);
1150
+
1151
+ return $key === $slug;
1152
+ }
1153
+
1154
+ private function is_valid_ep_mask($ep_mask) {
1155
+ return !preg_match("/[^0-9]/", $ep_mask);
1156
+ }
1157
+
1158
+ public function admin_print_scripts() {
1159
+ parent::admin_print_scripts();
1160
+ wp_enqueue_script('jquery-ui-tooltip', null, array('jquery'));
1161
+ wp_enqueue_script('postbox');
1162
+ wp_enqueue_script('wpfront-user-role-editor-post-types', WPFURE::instance()->get_asset_url('js/chosen/chosen.jquery.min.js'), array('jquery'), WPFURE::VERSION);
1163
+ }
1164
+
1165
+ public function admin_print_styles() {
1166
+ parent::admin_print_styles();
1167
+ wp_enqueue_style('wpfront-user-role-editor-post-types', WPFURE::instance()->get_asset_url('css/chosen/chosen.min.css'), array(), WPFURE::VERSION);
1168
+ }
1169
+
1170
+ public function get_taxonomy_customizable_hint_text($group_obj, $disabled) {
1171
+ $hint = __('Uses "manage_categories" capability.', 'wpfront-user-role-editor');
1172
+ $upgrade_message = sprintf(__('%s to customize capabilities.', 'wpfront-user-role-editor'), '<a href="https://wpfront.com/ureaddedit" target="_blank">' . __('Upgrade to Pro', 'wpfront-user-role-editor') . '</a>');
1173
+ $hint .= ' ' . $upgrade_message;
1174
+
1175
+ return $hint;
1176
+ }
1177
+
1178
+ protected function get_custom_caps($cap_type) {
1179
+ return array(
1180
+ 'manage_terms' => "manage_$cap_type",
1181
+ 'edit_terms' => "edit_$cap_type",
1182
+ 'delete_terms' => "delete_$cap_type",
1183
+ 'assign_terms' => "assign_$cap_type"
1184
+ );
1185
+ }
1186
+
1187
+ public function registered_taxonomy_for_object_type($taxonomy, $object_type) {
1188
+ $data = $this->get_all_taxonomies_data();
1189
+ if (isset($data[$taxonomy])) {
1190
+ $data = $data[$taxonomy];
1191
+ if (!in_array($object_type, $data->post_types)) {
1192
+ $this->clear_cache();
1193
+ }
1194
+ }
1195
+ }
1196
+
1197
+ public function unregistered_taxonomy_for_object_type($taxonomy, $object_type) {
1198
+ $data = $this->get_all_taxonomies_data();
1199
+ if (isset($data[$taxonomy])) {
1200
+ $data = $data[$taxonomy];
1201
+ if (in_array($object_type, $data->post_types)) {
1202
+ $this->clear_cache();
1203
+ }
1204
+ }
1205
+ }
1206
+
1207
+ }
1208
+
1209
+ WPFront_User_Role_Editor_Taxonomies::load();
1210
+ }
includes/taxonomies/entity-taxonomies.php ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ WPFront User Role Editor Plugin
5
+ Copyright (C) 2014, WPFront.com
6
+ Website: wpfront.com
7
+ Contact: syam@wpfront.com
8
+
9
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
10
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
11
+ St, Fifth Floor, Boston, MA 02110, USA
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
+
25
+ /**
26
+ * Entity for WPFront User Role Editor Taxonomies
27
+ *
28
+ * @author Vaisagh D <vaisaghd@wpfront.com>
29
+ * @copyright 2014 WPFront.com
30
+ */
31
+
32
+ namespace WPFront\URE\Taxonomies;
33
+
34
+ if (!defined('ABSPATH')) {
35
+ exit();
36
+ }
37
+
38
+ if (!class_exists('WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies_Entity')) {
39
+
40
+ /**
41
+ * Taxonomy Entity
42
+ *
43
+ * @author Vaisagh D <vaisaghd@wpfront.com>
44
+ * @copyright 2014 WPFront.com
45
+ */
46
+ class WPFront_User_Role_Editor_Taxonomies_Entity extends \WPFront\URE\WPFront_User_Role_Editor_Entity_Base {
47
+
48
+ /**
49
+ * Primary key.
50
+ *
51
+ * @var int
52
+ */
53
+ public $id;
54
+
55
+ /**
56
+ * Taxonomy Name.
57
+ *
58
+ * @var text
59
+ */
60
+ public $name;
61
+
62
+ /**
63
+ * Taxonomy Label.
64
+ *
65
+ * @var string
66
+ */
67
+ public $label;
68
+
69
+ /**
70
+ * Taxonomy Status.
71
+ *
72
+ * @var int
73
+ */
74
+ public $status;
75
+
76
+ /**
77
+ * Taxonomy Post Type.
78
+ *
79
+ * @var array
80
+ */
81
+ public $post_types;
82
+
83
+ /**
84
+ * Taxonomy Object.
85
+ *
86
+ * @var \WP_Taxonomy
87
+ */
88
+ public $taxonomy_arg;
89
+
90
+ /**
91
+ * Taxonomy Capability.
92
+ *
93
+ * @var text
94
+ */
95
+ public $capability_type;
96
+
97
+ protected function table_name_suffix() {
98
+ return 'taxonomy';
99
+ }
100
+
101
+ protected function table_create_sql() {
102
+ $table_name = $this->table_name();
103
+
104
+ global $wpdb;
105
+ $charset_collate = $wpdb->get_charset_collate();
106
+
107
+ $sql = "CREATE TABLE $table_name (\n"
108
+ . "id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n"
109
+ . "name varchar(150) DEFAULT NULL,\n"
110
+ . "label varchar(250) DEFAULT NULL,\n"
111
+ . "status int NOT NULL DEFAULT 1,\n"
112
+ . "taxonomy_arg text DEFAULT NULL,\n"
113
+ . "post_types varchar(1000) NOT NULL DEFAULT '',\n"
114
+ . "capability_type varchar(250) DEFAULT NULL,\n"
115
+ . "PRIMARY KEY (id),\n"
116
+ . "UNIQUE KEY name (name)\n"
117
+ . ") $charset_collate;";
118
+
119
+ return $sql;
120
+ }
121
+
122
+ /**
123
+ * Adds a new taxonomy.
124
+ *
125
+ * @global \wpdb $wpdb
126
+ * @return boolean Success|Fail
127
+ */
128
+ public function add() {
129
+ global $wpdb;
130
+ $tablename = $this->table_name();
131
+
132
+ if(!is_array($this->post_types)) {
133
+ $this->post_types = [];
134
+ }
135
+
136
+ $result = $wpdb->insert(
137
+ $tablename,
138
+ array(
139
+ 'name' => $this->name,
140
+ 'label' => $this->label,
141
+ 'status' => $this->status,
142
+ 'taxonomy_arg' => maybe_serialize($this->taxonomy_arg),
143
+ 'post_types' => implode(',', $this->post_types),
144
+ 'capability_type' => $this->capability_type
145
+ ),
146
+ array(
147
+ '%s',
148
+ '%s',
149
+ '%d',
150
+ '%s',
151
+ '%s',
152
+ '%s'
153
+ )
154
+ );
155
+
156
+ $this->sync($this->name, $this->status === 1 ? $this->post_types : []);
157
+
158
+ $this->cache_flush();
159
+
160
+ if ($result === false) {
161
+ return false;
162
+ } else {
163
+ $this->id = $wpdb->insert_id;
164
+ return true;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Updates an existing taxonomy based on ID.
170
+ *
171
+ * @global \wpdb $wpdb
172
+ * @return boolean Success|Fail
173
+ */
174
+ public function update() {
175
+ global $wpdb;
176
+ $tablename = $this->table_name();
177
+
178
+ $sql = $wpdb->prepare("SELECT id FROM $tablename WHERE name = %s", $this->name);
179
+ $id = $wpdb->get_var($sql);
180
+ if (empty($id)) {
181
+ return $this->add();
182
+ }
183
+ $this->id = $id;
184
+
185
+ if(!is_array($this->post_types)) {
186
+ $this->post_types = [];
187
+ }
188
+
189
+ $result = $wpdb->update(
190
+ $tablename,
191
+ array(
192
+ 'name' => $this->name,
193
+ 'label' => $this->label,
194
+ 'status' => $this->status,
195
+ 'taxonomy_arg' => serialize($this->taxonomy_arg),
196
+ 'post_types' => implode(',', $this->post_types),
197
+ 'capability_type' => $this->capability_type
198
+ ),
199
+ array(
200
+ 'id' => $this->id
201
+ ),
202
+ array(
203
+ '%s',
204
+ '%s',
205
+ '%d',
206
+ '%s',
207
+ '%s',
208
+ '%s'
209
+ ),
210
+ array(
211
+ '%d'
212
+ )
213
+ );
214
+
215
+ $this->sync($this->name, $this->status === 1 ? $this->post_types : []);
216
+
217
+ $this->cache_flush();
218
+
219
+ return $result !== false;
220
+ }
221
+
222
+ /**
223
+ * Deletes a taxonomy
224
+ *
225
+ * @param string $role
226
+ * @return bool
227
+ */
228
+ public function delete($action = 'delete') {
229
+ global $wpdb;
230
+ $tablename = $this->table_name();
231
+
232
+ $sql = "DELETE FROM $tablename WHERE id = %d";
233
+ $sql = $wpdb->prepare($sql, $this->id);
234
+ $result = $wpdb->query($sql);
235
+
236
+ $this->sync($this->name, $action === 'delete' ? [] : $this->post_types);
237
+
238
+ $this->cache_flush();
239
+
240
+ return !empty($result);
241
+ }
242
+
243
+ /**
244
+ * Returns all taxonomy.
245
+ *
246
+ * @param string $role
247
+ * @return bool
248
+ */
249
+ public function get_all() {
250
+ $data = $this->cache_get('all_taxonomies');
251
+ if ($data !== false) {
252
+ return $data;
253
+ }
254
+
255
+ $table_name = $this->table_name();
256
+
257
+ $sql = "SELECT id, name, label, status, taxonomy_arg, post_types, capability_type "
258
+ . "FROM $table_name ";
259
+
260
+ global $wpdb;
261
+ $results = $wpdb->get_results($sql);
262
+
263
+ $data = array();
264
+ foreach ($results as $value) {
265
+ $entity = new WPFront_User_Role_Editor_Taxonomies_Entity();
266
+
267
+ $entity->id = intval($value->id);
268
+ $entity->name = $value->name;
269
+ $entity->label = $value->label;
270
+ $entity->status = intval($value->status);
271
+ $entity->taxonomy_arg = maybe_unserialize($value->taxonomy_arg);
272
+ $entity->post_types = empty($value->post_types) ? [] : explode(',', $value->post_types);
273
+ $entity->capability_type = $value->capability_type;
274
+
275
+ $data[$entity->name] = $entity;
276
+ }
277
+
278
+ $this->cache_set('all_taxonomies', $data);
279
+
280
+ return $data;
281
+ }
282
+
283
+ /**
284
+ * Activates/Deactivates a taxonomy.
285
+ *
286
+ * @return bool
287
+ */
288
+ public function update_status($status) {
289
+ global $wpdb;
290
+ $tablename = $this->table_name();
291
+
292
+ $sql = "UPDATE $tablename SET status=%d WHERE id=%d";
293
+ $sql = $wpdb->prepare($sql, $status, $this->id);
294
+ $result = $wpdb->query($sql);
295
+
296
+ $this->sync($this->name, $status === 1 ? $this->post_types : []);
297
+
298
+ $this->cache_flush();
299
+
300
+ return !empty($result);
301
+ }
302
+
303
+ public function sync_post_types($post_type, $taxonomies) {
304
+ $tablename = $this->table_name();
305
+
306
+ $sql = "SELECT id, name, post_types FROM $tablename";
307
+ global $wpdb;
308
+ $results = $wpdb->get_results($sql);
309
+
310
+ foreach ($results as $obj) {
311
+ $post_types = empty($obj->post_types) ? [] : explode(',', $obj->post_types);
312
+ $update = false;
313
+
314
+ if (in_array($obj->name, $taxonomies)) { //taxonomy is present in the list passed, add post type if not exists.
315
+ if (!in_array($post_type, $post_types)) { //post type do not exists in data, add it.
316
+ $post_types[] = $post_type;
317
+ $update = true;
318
+ }
319
+ } else { //taxonomy not present in the list passed, so remove if post type exists.
320
+ if (in_array($post_type, $post_types)) { //post type exists in data, remove it.
321
+ $post_types = array_diff($post_types, [$post_type]);
322
+ $update = true;
323
+ }
324
+ }
325
+
326
+ if ($update) {
327
+ $wpdb->update(
328
+ $tablename,
329
+ array(
330
+ 'post_types' => implode(',', $post_types)
331
+ ),
332
+ array(
333
+ 'id' => $obj->id
334
+ ),
335
+ array(
336
+ '%s'
337
+ ),
338
+ array(
339
+ '%d'
340
+ )
341
+ );
342
+ }
343
+ }
344
+
345
+ $this->cache_flush();
346
+ }
347
+
348
+ protected function sync($taxonomy, $post_types) {
349
+ $entity = new \WPFront\URE\Post_Type\WPFront_User_Role_Editor_Post_Type_Entity();
350
+ $entity->sync_taxonomies($taxonomy, $post_types);
351
+ }
352
+
353
+ protected function cache_flush() {
354
+ $this->cache_delete('all_taxonomies');
355
+
356
+ $options = \WPFront\URE\Options\WPFront_User_Role_Editor_Options::instance();
357
+ $options->set_option(WPFront_User_Role_Editor_Taxonomies::DATA_EDITED_KEY, true);
358
+ }
359
+
360
+ }
361
+
362
+ (new WPFront_User_Role_Editor_Taxonomies_Entity())->register();
363
+ }
includes/taxonomies/template-add-edit.php ADDED
@@ -0,0 +1,999 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPFront User Role Editor Plugin
4
+ Copyright (C) 2014, WPFront.com
5
+ Website: wpfront.com
6
+ Contact: syam@wpfront.com
7
+
8
+ WPFront User Role Editor Plugin is distributed under the GNU General Public License, Version 3,
9
+ June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin
10
+ St, Fifth Floor, Boston, MA 02110, USA
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+ */
23
+
24
+ /**
25
+ * Template for WPFront User Role Editor Taxonomies Add Edit
26
+ *
27
+ * @author Vaisagh D <vaisaghd@wpfront.com>
28
+ * @copyright 2014 WPFront.com
29
+ */
30
+
31
+ namespace WPFront\URE\Taxonomies;
32
+
33
+ if (!defined('ABSPATH')) {
34
+ exit();
35
+ }
36
+
37
+ use WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies as Taxonomies;
38
+ use WPFront\URE\WPFront_User_Role_Editor_Utils as Utils;
39
+
40
+ if (!class_exists('WPFront\URE\Taxonomies\WPFront_User_Role_Editor_Taxonomies_Add_Edit_View')) {
41
+
42
+ class WPFront_User_Role_Editor_Taxonomies_Add_Edit_View {
43
+
44
+ /**
45
+ *
46
+ * @var WPFront_User_Role_Editor_Taxonomies
47
+ */
48
+ private $controller;
49
+ private $taxonomy_data;
50
+ private $taxonomy_obj;
51
+
52
+ public function __construct($controller, $data = null, $taxonomy_obj = null, $clone = null) {
53
+ $this->controller = $controller;
54
+ $this->taxonomy_data = $data;
55
+ $this->taxonomy_obj = $taxonomy_obj;
56
+ $this->clone_from = $clone;
57
+ }
58
+
59
+ public function view() {
60
+ ?>
61
+ <div class="wrap taxonomy-add-edit">
62
+ <?php $this->title(); ?>
63
+ <?php $this->display_notices(); ?>
64
+ <?php
65
+ if (empty($this->taxonomy_data)) {
66
+ $action = $this->controller->get_add_new_url();
67
+ } else {
68
+ $action = $this->controller->get_edit_url($this->taxonomy_data->name);
69
+ }
70
+ ?>
71
+ <form method="post" class="validate" action="<?php echo $action; ?>">
72
+ <?php $this->create_meta_boxes(); ?>
73
+ <div id="poststuff">
74
+ <div id="post-body" class="metabox-holder columns-2" style="display:flow-root">
75
+ <div id="post-body-content" style="position:relative">
76
+ <?php do_meta_boxes($this->controller->get_menu_slug(), 'normal', null); ?>
77
+ </div>
78
+ <div id="postbox-container-1" class="postbox-container" style="position: sticky; top: 40px;">
79
+ <?php do_meta_boxes($this->controller->get_menu_slug(), 'side', null); ?>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ <?php wp_nonce_field('add-edit-taxonomies'); ?>
84
+ <?php submit_button(null, 'primary', 'submit2', false); ?>
85
+ </form>
86
+ </div>
87
+ <?php $this->scripts(); ?>
88
+ <?php
89
+ }
90
+
91
+ public function title() {
92
+ if (empty($this->taxonomy_data)) {
93
+ ?>
94
+ <h2>
95
+ <?php echo __('Add New Taxonomy', 'wpfront-user-role-editor'); ?>
96
+ </h2>
97
+ <?php
98
+ } else {
99
+ ?>
100
+ <h2>
101
+ <?php echo __('Edit Taxonomy', 'wpfront-user-role-editor'); ?>
102
+ </h2>
103
+ <?php
104
+ }
105
+ }
106
+
107
+ protected function display_notices() {
108
+ if (!empty($this->controller->errorMsg)) {
109
+ Utils::notice_error($this->controller->errorMsg);
110
+ }
111
+
112
+ if (!empty($_GET['taxonomy-added'])) {
113
+ Utils::notice_updated(__('Taxonomy added successfully.', 'wpfront-user-role-editor'));
114
+ } elseif (!empty($_GET['taxonomy-updated'])) {
115
+ Utils::notice_updated(__('Taxonomy updated successfully.', 'wpfront-user-role-editor'));
116
+ }
117
+ }
118
+
119
+ protected function get_meta_box_groups() {
120
+ return [
121
+ (object) [
122
+ 'group_name' => 'basic_settings',
123
+ 'title' => __('Basic Settings', 'wpfront-user-role-editor'),
124
+ 'render' => 'postbox_render_basic_settings'
125
+ ],
126
+ (object) [
127
+ 'group_name' => 'labels',
128
+ 'title' => __('Additional Labels', 'wpfront-user-role-editor'),
129
+ 'render' => 'postbox_render_labels'
130
+ ],
131
+ (object) [
132
+ 'group_name' => 'advanced_settings',
133
+ 'title' => __('Advanced Settings', 'wpfront-user-role-editor'),
134
+ 'render' => 'postbox_render_advanced_settings'
135
+ ]
136
+ ];
137
+ }
138
+
139
+ protected function create_meta_boxes() {
140
+ $groups = $this->get_meta_box_groups();
141
+
142
+ foreach ($groups as $group) {
143
+ add_meta_box("postbox-{$group->group_name}", $group->title, array($this, $group->render), $this->controller->get_menu_slug(), 'normal', 'default', $group);
144
+ }
145
+
146
+ add_meta_box("postbox-side", __('Actions', 'wpfront-user-role-editor'), array($this, 'action_buttons'), $this->controller->get_menu_slug(), 'side', 'default', $group);
147
+
148
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
149
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
150
+ }
151
+
152
+ public function action_buttons() {
153
+ submit_button();
154
+ ?>
155
+ <p>
156
+ <a class="auto-populate-labels button button-secondary"><?php echo __('Auto Populate Labels', 'wpfront-user-role-editor'); ?></a>
157
+ </p>
158
+ <p>
159
+ <a class="clear-labels button button-secondary"><?php echo __('Clear Labels', 'wpfront-user-role-editor'); ?></a>
160
+ </p>
161
+ <?php
162
+ }
163
+
164
+ public function postbox_render_basic_settings() {
165
+ ?>
166
+ <table class="form-table">
167
+ <tbody>
168
+ <?php
169
+ $this->textbox_basic_settings(__('Name', 'wpfront-user-role-editor'), 'name');
170
+ $this->textbox_basic_settings(__('Plural Label', 'wpfront-user-role-editor'), 'label');
171
+ $this->textbox_basic_settings(__('Singular Label', 'wpfront-user-role-editor'), 'singular_name');
172
+ $this->multilist_basic_settings(
173
+ __('Post Types', 'wpfront-user-role-editor'),
174
+ 'post_types',
175
+ __('Post types for the taxonomy.', 'wpfront-user-role-editor')
176
+ );
177
+ ?>
178
+ </tbody>
179
+ </table>
180
+ <?php
181
+ }
182
+
183
+ public function postbox_render_labels() {
184
+ ?>
185
+ <table class="form-table">
186
+ <tbody>
187
+ <?php
188
+ $this->textbox_additional_labels(
189
+ __('Search Items Label', 'wpfront-user-role-editor'),
190
+ 'search_items',
191
+ __(' Default Search Tags/Search Categories. Leave empty to use default value.', 'wpfront-user-role-editor'),
192
+ __('Search %S0', 'wpfront-user-role-editor')
193
+ );
194
+ $this->textbox_additional_labels(
195
+ __('Popular Items Label', 'wpfront-user-role-editor'),
196
+ 'popular_items',
197
+ __('This label is only used for non-hierarchical taxonomies. Default Popular Tags. Leave empty to use default value.', 'wpfront-user-role-editor'),
198
+ __('Popular %S0', 'wpfront-user-role-editor')
199
+ );
200
+ $this->textbox_additional_labels(
201
+ __('All Items Label', 'wpfront-user-role-editor'),
202
+ 'all_items',
203
+ __('Default is All Tags/All Categories. Leave empty to use default value.', 'wpfront-user-role-editor'),
204
+ __('%S0', 'wpfront-user-role-editor')
205
+ );
206
+ $this->textbox_additional_labels(
207
+ __('Edit Item Label', 'wpfront-user-role-editor'),
208
+ 'edit_item',
209
+ __('Default Edit Tag/Edit Category. Leave empty to use default value.', 'wpfront-user-role-editor'),
210
+ __('Edit %S1', 'wpfront-user-role-editor')
211
+ );
212
+ $this->textbox_additional_labels(
213
+ __('Parent Item Label', 'wpfront-user-role-editor'),
214
+ 'parent_item',
215
+ __('This label is only used for hierarchical taxonomies. Default Parent Category. Leave empty to use default value.', 'wpfront-user-role-editor'),
216
+ __('Parent %S1', 'wpfront-user-role-editor')
217
+ );
218
+ $this->textbox_additional_labels(
219
+ __('Parent Item Colon', 'wpfront-user-role-editor'),
220
+ 'parent_item_colon',
221
+ __('The same as parent_item, but with colon : in the end.', 'wpfront-user-role-editor'),
222
+ __('Parent %S1:', 'wpfront-user-role-editor')
223
+ );
224
+ $this->textbox_additional_labels(
225
+ __('View Items Label', 'wpfront-user-role-editor'),
226
+ 'view_item',
227
+ __('Default is View Tag/View Category.', 'wpfront-user-role-editor'),
228
+ __('View %S1', 'wpfront-user-role-editor')
229
+ );
230
+ $this->textbox_additional_labels(
231
+ __('Update Item Label', 'wpfront-user-role-editor'),
232
+ 'update_item',
233
+ __('Default is Update Tag/Update Category.', 'wpfront-user-role-editor'),
234
+ __('Update %S1', 'wpfront-user-role-editor')
235
+ );
236
+ $this->textbox_additional_labels(
237
+ __('Add New Item Label', 'wpfront-user-role-editor'),
238
+ 'add_new_item',
239
+ __(' Default is Add New Tag/Add New Category.', 'wpfront-user-role-editor'),
240
+ __('Add New %S1', 'wpfront-user-role-editor')
241
+ );
242
+ $this->textbox_additional_labels(
243
+ __('New Item Name Label', 'wpfront-user-role-editor'),
244
+ 'new_item_name',
245
+ __('Default New Tag Name/New Category Name.', 'wpfront-user-role-editor'),
246
+ __('New %S1 Name', 'wpfront-user-role-editor')
247
+ );
248
+ $this->textbox_additional_labels(
249
+ __('Separate Items with Commas Label', 'wpfront-user-role-editor'),
250
+ 'separate_items_with_commas',
251
+ __('This label is only used for non-hierarchical taxonomies. Default Separate tags with commas, used in the meta box.', 'wpfront-user-role-editor'),
252
+ __('Separate %s0 with commas', 'wpfront-user-role-editor')
253
+ );
254
+ $this->textbox_additional_labels(
255
+ __('Add or Remove Items Label', 'wpfront-user-role-editor'),
256
+ 'add_or_remove_items',
257
+ __('This label is only used for non-hierarchical taxonomies. Default Add or remove tags, used in the meta box when JavaScript is disabled.', 'wpfront-user-role-editor'),
258
+ __('Add or remove %s0', 'wpfront-user-role-editor')
259
+ );
260
+ $this->textbox_additional_labels(
261
+ __('Choose from Most Used Label', 'wpfront-user-role-editor'),
262
+ 'choose_from_most_used',
263
+ __('This label is only used on non-hierarchical taxonomies. Default Choose from the most used tags, used in the meta box.', 'wpfront-user-role-editor'),
264
+ __('Choose from the most used %s0', 'wpfront-user-role-editor')
265
+ );
266
+ $this->textbox_additional_labels(
267
+ __('Not Found Label', 'wpfront-user-role-editor'),
268
+ 'not_found',
269
+ __('Default is No tags found/No categories found, used in the meta box and taxonomy list table.', 'wpfront-user-role-editor'),
270
+ __('No %s0 found.', 'wpfront-user-role-editor')
271
+ );
272
+ $this->textbox_additional_labels(
273
+ __('No Terms Label', 'wpfront-user-role-editor'),
274
+ 'no_terms',
275
+ __('Default is No tags/No categories, used in the posts and media list tables.', 'wpfront-user-role-editor'),
276
+ __('No %s0', 'wpfront-user-role-editor')
277
+ );
278
+ $this->textbox_additional_labels(
279
+ __('Filter by Item Label', 'wpfront-user-role-editor'),
280
+ 'filter_by_item',
281
+ __('This label is only used for hierarchical taxonomies. Default Filter by category, used in the posts list table.', 'wpfront-user-role-editor'),
282
+ __('Filter by %S1', 'wpfront-user-role-editor')
283
+ );
284
+ $this->textbox_additional_labels(
285
+ __('Item List Navigation Label', 'wpfront-user-role-editor'),
286
+ 'items_list_navigation',
287
+ __('Label for the table pagination hidden heading.', 'wpfront-user-role-editor'),
288
+ __('%S0 list navigation', 'wpfront-user-role-editor')
289
+ );
290
+ $this->textbox_additional_labels(
291
+ __('Item List Label', 'wpfront-user-role-editor'),
292
+ 'items_list',
293
+ __('Label for the table hidden heading.', 'wpfront-user-role-editor'),
294
+ __('%S0 list', 'wpfront-user-role-editor')
295
+ );
296
+ $this->textbox_additional_labels(
297
+ __('Most Used Label', 'wpfront-user-role-editor'),
298
+ 'most_used',
299
+ __('Title for the Most Used tab. Default Most Used.', 'wpfront-user-role-editor'),
300
+ __('Most Used', 'wpfront-user-role-editor')
301
+ );
302
+ $this->textbox_additional_labels(
303
+ __('Back to Items Label', 'wpfront-user-role-editor'),
304
+ 'back_to_items',
305
+ __('Label displayed after a term has been updated.', 'wpfront-user-role-editor'),
306
+ __('&larr; Go to %S0', 'wpfront-user-role-editor')
307
+ );
308
+ ?>
309
+ </tbody>
310
+ </table>
311
+ <?php
312
+ }
313
+
314
+ public function postbox_render_advanced_settings() {
315
+ ?>
316
+ <table class="form-table">
317
+ <tbody>
318
+ <?php
319
+ $this->dropdown_advanced_settings_boolean(
320
+ __('Public', 'wpfront-user-role-editor'),
321
+ 'public',
322
+ __('Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users. The default settings of <b>"Publicly Queryable"</b>, <b>"Show UI"</b>, and <b>"Show in Nav Menus"</b> are inherited from <b>"Public"</b>.', 'wpfront-user-role-editor'),
323
+ true
324
+ );
325
+ $this->dropdown_advanced_settings_boolean(
326
+ __('Hierarchical', 'wpfront-user-role-editor'),
327
+ 'hierarchical',
328
+ __('Whether the taxonomy is hierarchical. Default false.', 'wpfront-user-role-editor')
329
+ );
330
+ $this->dropdown_advanced_settings_boolean(
331
+ __('Publicaly Queryable', 'wpfront-user-role-editor'),
332
+ 'publicly_queryable',
333
+ __('Whether the taxonomy is publicly queryable. If not set, the default is inherited from <b>"Public"</b>.', 'wpfront-user-role-editor'),
334
+ true
335
+ );
336
+ $this->dropdown_advanced_settings_boolean(
337
+ __('Show in Menu', 'wpfront-user-role-editor'),
338
+ 'show_in_menu',
339
+ __('Whether to show the taxonomy in the admin menu. If true, the taxonomy is shown as a submenu of the object type menu. If false, no menu is shown <b>"Show UI"</b> must be true. If not set, default is inherited from <b>"Show UI"</b> (Default is true).', 'wpfront-user-role-editor'),
340
+ true
341
+ );
342
+ $this->dropdown_advanced_settings_boolean(
343
+ __('Show UI', 'wpfront-user-role-editor'),
344
+ 'show_ui',
345
+ __('Whether to generate and allow a UI for managing terms in this taxonomy in the admin. If not set, the default is inherited from <b>"Public"</b> (Default is true).', 'wpfront-user-role-editor'),
346
+ true
347
+ );
348
+ $this->dropdown_advanced_settings_boolean(
349
+ __('Show in Nav Menus', 'wpfront-user-role-editor'),
350
+ 'show_in_nav_menus',
351
+ __('Makes this taxonomy available for selection in navigation menus. If not set, the default is inherited from <b>"Public"</b>.', 'wpfront-user-role-editor')
352
+ );
353
+ $this->dropdown_advanced_settings_boolean(
354
+ __('Show in REST', 'wpfront-user-role-editor'),
355
+ 'show_in_rest',
356
+ __('Whether to include the taxonomy in the REST API. Set this to true for the taxonomy to be available in the block editor.', 'wpfront-user-role-editor'),
357
+ true
358
+ );
359
+ $this->textbox_advanced_settings(
360
+ __('REST Base', 'wpfront-user-role-editor'),
361
+ 'rest_base',
362
+ __('To change the base url of REST API route. Default is <b>"Name"</b>.', 'wpfront-user-role-editor')
363
+ );
364
+ $this->textbox_advanced_settings(
365
+ __('REST Controller Class', 'wpfront-user-role-editor'),
366
+ 'rest_controller_class',
367
+ __('REST API Controller class name. Default is WP_REST_Terms_Controller', 'wpfront-user-role-editor')
368
+ );
369
+ $this->dropdown_advanced_settings_boolean(
370
+ __('Show Tagcloud', 'wpfront-user-role-editor'),
371
+ 'show_tagcloud',
372
+ __('Whether to list the taxonomy in the Tag Cloud Widget controls. If not set, the default is inherited from <b>"Show UI"</b> (Default is true).', 'wpfront-user-role-editor')
373
+ );
374
+ $this->dropdown_advanced_settings_boolean(
375
+ __('Show in Quick Edit', 'wpfront-user-role-editor'),
376
+ 'show_in_quick_edit',
377
+ __('Whether to show the taxonomy in the quick/bulk edit panel. If not set, the default is inherited from <b>"Show UI"</b> (Default is true).', 'wpfront-user-role-editor')
378
+ );
379
+ $this->dropdown_advanced_settings_boolean(
380
+ __('Show Admin Column', 'wpfront-user-role-editor'),
381
+ 'show_admin_column',
382
+ __('Whether to display a column for the taxonomy on its post type listing screens. Default is false.', 'wpfront-user-role-editor')
383
+ );
384
+ $this->dropdown_advanced_settings_boolean(
385
+ __('Query Var', 'wpfront-user-role-editor'),
386
+ 'query_var',
387
+ __('Sets the query var key for this taxonomy. Default is <b>"Name"</b> key. If false, a taxonomy cannot be loaded at ?{query_var}={term_slug}. If a string, the query ?{query_var}={term_slug} will be valid.', 'wpfront-user-role-editor')
388
+ );
389
+ $this->rewrite_settings();
390
+ ?>
391
+ </tbody>
392
+ </table>
393
+ <?php
394
+ }
395
+
396
+ protected function rewrite_settings() {
397
+ $arg_value = $this->get_property_value('rewrite', '');
398
+ if ($arg_value === null) {
399
+ $arg_value = '';
400
+ }
401
+
402
+ $current_property_value = $this->get_current_property_value('rewrite');
403
+
404
+ $this->dropdown_advanced_settings_boolean(
405
+ __('Rewrite', 'wpfront-user-role-editor'),
406
+ 'rewrite',
407
+ __('Triggers the handling of rewrites for this taxonomy. Default is true, using <b>"Name"</b> as slug. To prevent rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:', 'wpfront-user-role-editor'),
408
+ '',
409
+ false,
410
+ is_array($arg_value) ? true : $arg_value,
411
+ !empty($current_property_value) ? 'True' : 'False'
412
+ );
413
+
414
+ $this->textbox_advanced_settings(
415
+ __('Rewrite Slug', 'wpfront-user-role-editor'),
416
+ 'rewrite_slug',
417
+ __(' Customize the permastruct slug. Default is <b>"Name"</b> key.', 'wpfront-user-role-editor'),
418
+ isset($arg_value['slug']) ? $arg_value['slug'] : null,
419
+ isset($current_property_value['slug']) ? $current_property_value['slug'] : ''
420
+ );
421
+
422
+
423
+ $this->dropdown_advanced_settings_boolean(
424
+ __('Rewrite With Front', 'wpfront-user-role-editor'),
425
+ 'rewrite_with_front',
426
+ __('Should the permastruct be prepended with WP_Rewrite::$front. Default is true. ', 'wpfront-user-role-editor'),
427
+ '',
428
+ false,
429
+ isset($arg_value['with_front']) ? $arg_value['with_front'] : null,
430
+ isset($current_property_value['with_front']) ? $current_property_value['with_front'] : ''
431
+ );
432
+
433
+ $this->dropdown_advanced_settings_boolean(
434
+ __('Rewrite Hierarchical', 'wpfront-user-role-editor'),
435
+ 'rewrite_hierarchical',
436
+ __('Either hierarchical rewrite tag or not. Default is false.', 'wpfront-user-role-editor'),
437
+ '',
438
+ false,
439
+ isset($arg_value['hierarchical']) ? $arg_value['hierarchical'] : null,
440
+ isset($current_property_value['hierarchical']) ? $current_property_value['hierarchical'] : ''
441
+ );
442
+
443
+ $this->textbox_advanced_settings(
444
+ __('Rewrite EP Mask', 'wpfront-user-role-editor'),
445
+ 'rewrite_ep_mask',
446
+ __('Assign an endpoint mask. Default is EP_NONE. ', 'wpfront-user-role-editor'),
447
+ isset($arg_value['ep_mask']) ? $arg_value['ep_mask'] : null,
448
+ isset($current_property_value['ep_mask']) ? $current_property_value['ep_mask'] : ''
449
+ );
450
+ return;
451
+ }
452
+
453
+ protected function textbox_basic_settings($label, $name) {
454
+ $value = $this->get_property_value($name);
455
+ $attr = '';
456
+ if ($name === 'name') {
457
+ if (!empty($this->taxonomy_data)) {
458
+ $value = $this->taxonomy_data->name;
459
+ $attr = 'disabled="true"';
460
+ }
461
+ } elseif ($name === 'singular_name') {
462
+ $value = $this->get_labels_value('singular_name');
463
+ }
464
+
465
+ $this->textbox_row($label, $name, $value, (object) ['required' => true, 'attr' => $attr]);
466
+ }
467
+
468
+ protected function multilist_basic_settings($label, $name, $help) {
469
+ $options = [];
470
+ $values = $this->get_property_value('post_types');
471
+ $current_property_value = '';
472
+
473
+ if (isset($this->taxonomy_data->post_types)) {
474
+ $post_types = $this->taxonomy_data->post_types;
475
+ foreach ($post_types as $post_type) {
476
+ if ($post_type === 'link') {
477
+ $object_types[] = $post_type;
478
+ } elseif (!empty($post_type)) {
479
+ $object_type = get_post_type_object($post_type);
480
+ if (!empty($object_type)) {
481
+ $object_types[] = $object_type->label;
482
+ }
483
+ }
484
+ }
485
+ if (!empty($object_types)) {
486
+ $current_property_value = implode(', ', $object_types);
487
+ }
488
+ }
489
+
490
+ $post_types = get_post_types();
491
+ foreach ($post_types as $post_type) {
492
+ $post_type_obj = get_post_type_object($post_type);
493
+ if (is_post_type_viewable($post_type) || empty($post_type_obj->_builtin)) {
494
+
495
+ $options[$post_type_obj->name] = $post_type_obj->label;
496
+ }
497
+ }
498
+
499
+ $obj = ['help' => $help, 'help_current_value' => $current_property_value];
500
+
501
+ $this->multilist_row($label, $name, $values, $options, (object) $obj);
502
+ }
503
+
504
+ protected function textbox_additional_labels($label, $name, $help, $auto_format = '') {
505
+ $this->textbox_row($label, $name, $this->get_labels_value($name), (object) ['help' => $help, 'help_current_value' => $this->get_current_labels_value($name), 'auto_format' => $auto_format]);
506
+ }
507
+
508
+ protected function dropdown_advanced_settings_boolean($label, $name, $help, $default_value = '', $exclude_default = false, $arg_value = null, $current_property_value = null) {
509
+ $options = [(object) ['label' => __('True', 'wpfront-user-role-editor'), 'value' => true], (object) ['label' => __('False', 'wpfront-user-role-editor'), 'value' => false]];
510
+ if (!$exclude_default) {
511
+ array_unshift($options, (object) ['label' => __('Default', 'wpfront-user-role-editor'), 'value' => '']);
512
+ }
513
+
514
+ if ($arg_value === null) {
515
+ $arg_value = $this->get_property_value($name, $default_value);
516
+ if ($name === 'customize_capability') { //for customize_capability default = null, false = ''
517
+ if ($arg_value === null) {
518
+ $arg_value = '';
519
+ } elseif ($arg_value === '') {
520
+ $arg_value = false;
521
+ }
522
+ }
523
+ }
524
+
525
+ if ($current_property_value === null) {
526
+ if($name === 'customize_capability') {
527
+ if(empty($this->taxonomy_data->capability_type)) {
528
+ $current_property_value = 'manage_categories';
529
+ } else {
530
+ $current_property_value = $this->taxonomy_data->capability_type;
531
+ }
532
+ } else {
533
+ $current_property_value = $this->get_current_property_value($name);
534
+ }
535
+ }
536
+
537
+ if ($current_property_value === true) {
538
+ $current_property_value = __('True', 'wpfront-user-role-editor');
539
+ } elseif ($current_property_value === false) {
540
+ $current_property_value = __('False', 'wpfront-user-role-editor');
541
+ }
542
+
543
+ $obj = ['help' => $help, 'help_current_value' => $current_property_value];
544
+
545
+ //On POST with a validation error $arg_value will be one of empty string, 1 or 0
546
+ if ($arg_value === '1') {
547
+ $arg_value = true;
548
+ } elseif ($arg_value === '0') {
549
+ $arg_value = false;
550
+ }
551
+
552
+ switch ($name) {
553
+ case 'query_var':
554
+ case 'customize_capability':
555
+ $has_depends = $name . '_slug';
556
+ break;
557
+
558
+ default:
559
+ break;
560
+ }
561
+
562
+ if (!empty($has_depends)) {
563
+ if (empty($arg_value) || is_bool($arg_value)) { //selected default or true/false
564
+ if ($name === 'customize_capability') {
565
+ $current_property_value = $this->get_property_value('label', '');
566
+ $current_property_value = $this->controller->sanitize_capability_type($current_property_value);
567
+ } else {
568
+ $current_property_value = '';
569
+ }
570
+ } else { //specified a value in textbox.
571
+ $current_property_value = $arg_value;
572
+ $arg_value = true;
573
+ }
574
+
575
+ $obj['txt'] = ['name' => $has_depends, 'value' => $current_property_value, 'depends_on' => 'true'];
576
+ }
577
+
578
+ // $arg_value will be null when Default is selected.
579
+ if ($arg_value === null) {
580
+ $arg_value = '';
581
+ }
582
+
583
+ $this->dropdown_row($label, $name, $options, $arg_value, (object) $obj);
584
+ }
585
+
586
+ protected function textbox_advanced_settings($label, $name, $help, $prop_value = null, $prop_current_value = null) {
587
+ if ($prop_value === null) {
588
+ $prop_value = $this->get_property_value($name);
589
+ }
590
+
591
+ if ($prop_current_value === null) {
592
+ $prop_current_value = $this->get_current_property_value($name);
593
+ }
594
+
595
+ $this->textbox_row($label, $name, $prop_value, (object) ['help' => $help, 'help_current_value' => $prop_current_value]);
596
+ }
597
+
598
+ protected function textbox_row($label, $name, $value, $obj) {
599
+ $attr = '';
600
+ $class = '';
601
+ if (!empty($obj->attr)) {
602
+ $attr .= $obj->attr . ' ';
603
+ }
604
+ if (!empty($obj->required)) {
605
+ $attr .= 'aria-required="true" ';
606
+ }
607
+ if (!empty($obj->help_current_value)) {
608
+ $attr .= 'placeholder="' . esc_attr($obj->help_current_value) . '" ';
609
+ }
610
+ if (!empty($obj->auto_format)) {
611
+ $attr .= 'data-auto-format="' . esc_attr($obj->auto_format) . '" ';
612
+ $class .= 'auto-populate';
613
+ }
614
+ if (is_array($value)) {
615
+ $value = implode(', ', $value);
616
+ }
617
+ ?>
618
+ <tr class="<?php echo!empty($obj->required) ? 'form-required ' : ''; ?>">
619
+ <th scope="row">
620
+ <?php echo $label; ?>
621
+ <?php if (!empty($obj->required)) { ?>
622
+ <span class="description"> (<?php echo __('required', 'wpfront-user-role-editor'); ?>)</span>
623
+ <?php } ?>
624
+ </th>
625
+ <td>
626
+ <input class="regular-text <?php echo $class; ?>" name="<?php echo $name; ?>" type="text" value="<?php echo $value; ?>" <?php echo $attr; ?> />
627
+ <?php
628
+ if (!empty($obj->help)) {
629
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
630
+ }
631
+ ?>
632
+ </td>
633
+ </tr>
634
+ <?php
635
+ }
636
+
637
+ protected function multilist_row($label, $name, $values, $options, $obj) {
638
+ if (empty($values)) {
639
+ $values = [];
640
+ }
641
+ ?>
642
+ <tr>
643
+ <th scope="row">
644
+ <?php
645
+ echo $label;
646
+ $placeholder = __('Choose From Options', 'wpfront-user-role-editor');
647
+ ?>
648
+ </th>
649
+ <td>
650
+ <select data-placeholder="<?php echo $placeholder; ?>" name="<?php echo $name; ?>[]" class="chosen-select" multiple>
651
+ <?php
652
+ foreach ($options as $value => $label) {
653
+ $selected = in_array($value, $values) ? 'selected' : '';
654
+ echo "<option value='$value' $selected>$label</option>";
655
+ }
656
+ ?>
657
+ </select>
658
+ <?php
659
+ if (!empty($obj->help)) {
660
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
661
+ }
662
+ ?>
663
+ </tr>
664
+ <?php
665
+ }
666
+
667
+ protected function dropdown_row($label, $name, $options, $value, $obj) {
668
+ $attr = '';
669
+ $placeholder = '';
670
+ if (!empty($obj->attr)) {
671
+ $attr .= $obj->attr . ' ';
672
+ }
673
+ ?>
674
+ <tr>
675
+ <th scope="row">
676
+ <?php echo $label; ?>
677
+ </th>
678
+ <td>
679
+ <select id="<?php echo $name; ?>" name="<?php echo $name; ?>" class="<?php echo!empty($obj->txt) ? 'has-depends' : ''; ?>" <?php echo $attr; ?> >
680
+ <?php
681
+ foreach ($options as $option) {
682
+ $selected = $option->value === $value ? 'selected' : '';
683
+ if ($option->value === true) {
684
+ $option->value = '1';
685
+ } elseif ($option->value === false) {
686
+ $option->value = '0';
687
+ }
688
+ echo "<option value='{$option->value}' $selected>{$option->label}</option>";
689
+ }
690
+ ?>
691
+ </select>
692
+ <?php
693
+ if (!empty($obj->txt)) {
694
+ $txt_value = $obj->txt['value'];
695
+ if (!empty($_POST['submit'])) { //on a POST with validation error, display POSTed value.
696
+ $txt_value = $_POST[$obj->txt['name']];
697
+ }
698
+ ?>
699
+ <input type="text" name="<?php echo $obj->txt['name']; ?>" placeholder="<?php echo $placeholder; ?>" value="<?php echo $txt_value; ?>" data-depends="<?php echo $name; ?>" data-depends-on="<?php echo $obj->txt['depends_on']; ?>" />
700
+ <?php
701
+ }
702
+ ?>
703
+ <?php
704
+ if (!empty($obj->help)) {
705
+ $this->echo_help_tooltip($obj->help, $obj->help_current_value);
706
+ }
707
+ ?>
708
+ </tr>
709
+ <?php
710
+ }
711
+
712
+ protected function echo_help_tooltip($pretext, $current_value) {
713
+ $title = esc_attr($pretext);
714
+ if (!empty($this->taxonomy_obj)) {
715
+ $title .= '<br />' . esc_attr(sprintf(__('Current value is "<b>%s</b>"', 'wpfront-user-role-editor'), $current_value));
716
+ }
717
+ ?>
718
+ <i class="fa fa-question-circle-o" title="<?php echo $title; ?>"></i>
719
+ <?php
720
+ }
721
+
722
+ protected function get_property_value($prop, $default = '') {
723
+ if (!empty($_POST['submit'])) {
724
+ if (!isset($_POST[$prop])) {
725
+ return $default;
726
+ }
727
+
728
+ if ($prop === 'customize_capability') {
729
+ if ($_POST[$prop] === '') { //for customize_capability, default = null, false = ''
730
+ return $default;
731
+ }
732
+ }
733
+
734
+ return $_POST[$prop];
735
+ }
736
+
737
+ if (!empty($this->taxonomy_data)) { //edit
738
+ if (isset($this->taxonomy_data->taxonomy_arg[$prop])) {
739
+ return $this->taxonomy_data->taxonomy_arg[$prop];
740
+ }
741
+ if (isset($this->taxonomy_data->$prop)) {
742
+ return $this->taxonomy_data->$prop;
743
+ }
744
+
745
+ if ($prop === 'post_types') {
746
+ return $this->taxonomy_data->$prop;
747
+ }
748
+
749
+ if ($prop === 'customize_capability') {
750
+ return $this->taxonomy_data->capability_type;
751
+ }
752
+
753
+ return null;
754
+ }
755
+
756
+ if (!empty($this->clone_from)) { //add with clone
757
+ if (isset($this->clone_from->taxonomy_arg)) { //our taxonomy
758
+ if (isset($this->clone_from->taxonomy_arg[$prop])) {
759
+ return $this->clone_from->taxonomy_arg[$prop];
760
+ }
761
+
762
+ if (isset($this->clone_from->$prop)) { //our taxonomy
763
+ return $this->clone_from->$prop;
764
+ }
765
+
766
+ return null;
767
+ }
768
+ return null;
769
+ }
770
+
771
+ return $default;
772
+ }
773
+
774
+ protected function get_labels_value($prop, $default = '') {
775
+ if (!empty($_POST['submit'])) {
776
+ return empty($_POST[$prop]) ? $default : $_POST[$prop];
777
+ }
778
+
779
+ if (!empty($this->taxonomy_data)) { //edit
780
+ if (isset($this->taxonomy_data->taxonomy_arg['labels'][$prop])) {
781
+ return $this->taxonomy_data->taxonomy_arg['labels'][$prop];
782
+ }
783
+ }
784
+ if (!empty($this->clone_from)) { //add with clone
785
+ if (isset($this->clone_from->taxonomy_arg['labels'][$prop])) { //our taxonomy
786
+ return $this->clone_from->taxonomy_arg['labels'][$prop];
787
+ }
788
+ }
789
+ return $default;
790
+ }
791
+
792
+ protected function get_current_labels_value($prop) {
793
+ if (!empty($this->taxonomy_obj) && isset($this->taxonomy_obj->labels) && isset($this->taxonomy_obj->labels->$prop)) {
794
+ return $this->taxonomy_obj->labels->$prop;
795
+ }
796
+
797
+ return '';
798
+ }
799
+
800
+ protected function get_current_property_value($prop) {
801
+ if (!empty($this->taxonomy_obj)) {
802
+ if (isset($this->taxonomy_obj->$prop)) {
803
+ if ($prop == 'rest_base' && $this->taxonomy_obj->$prop == '') {
804
+ return $this->taxonomy_obj->name;
805
+ } elseif ($prop == 'rest_controller_class' && $this->taxonomy_obj->$prop == '') {
806
+ return 'WP_REST_Terms_Controller';
807
+ } else {
808
+ return $this->taxonomy_obj->$prop;
809
+ }
810
+ }
811
+ }
812
+
813
+ return null; //Either on ADD screen or on a Deactivated taxonomy.
814
+ }
815
+
816
+ protected function scripts() {
817
+ ?>
818
+ <script type="text/javascript">
819
+ (function ($) {
820
+ var $div = $('div.wrap.taxonomy-add-edit');
821
+
822
+ $div.on('change', 'select.has-depends', function () {
823
+ var $select = $(this);
824
+ var $d = $select.next();
825
+ var on = $d.data('depends-on');
826
+ if ($select.val() == on) {
827
+ $d.show();
828
+ } else {
829
+ $d.hide();
830
+ }
831
+ });
832
+
833
+ //rewrite disable
834
+ $div.on('change', "select[name='rewrite']", function () {
835
+ var $rewrite_slug = $("input[name='rewrite_slug']");
836
+ var $ep_mask = $("input[name='rewrite_ep_mask']");
837
+ var $with_front = $("select[name='rewrite_with_front']");
838
+ var $hierarchical = $("select[name='rewrite_hierarchical']");
839
+ if ($(this).val() === '1') {
840
+ $rewrite_slug.prop('disabled', false);
841
+ $ep_mask.prop('disabled', false);
842
+ $with_front.prop('disabled', false);
843
+ $hierarchical.prop('disabled', false);
844
+ } else {
845
+ $rewrite_slug.prop('disabled', true);
846
+ $ep_mask.prop('disabled', true);
847
+ $with_front.prop('disabled', true);
848
+ $hierarchical.prop('disabled', true);
849
+ }
850
+ });
851
+
852
+ //auto populate labels and validation
853
+ $div.find(".auto-populate-labels").on('click', function () {
854
+ var S0 = $("input[name='label']");
855
+ var S1 = $("input[name='singular_name']");
856
+
857
+ var ret = false;
858
+ if ($.trim(S1.val()) === "") {
859
+ S1.parent().parent().addClass("form-invalid");
860
+ S1.focus();
861
+ ret = true;
862
+ } else {
863
+ S1.parent().parent().removeClass("form-invalid");
864
+ }
865
+
866
+ if ($.trim(S0.val()) === "") {
867
+ S0.parent().parent().addClass("form-invalid");
868
+ S0.focus();
869
+ ret = true;
870
+ } else {
871
+ S0.parent().parent().removeClass("form-invalid");
872
+ }
873
+
874
+ if (ret) {
875
+ return false;
876
+ }
877
+
878
+ S0 = $.trim(S0.val());
879
+ S1 = $.trim(S1.val());
880
+ var s0 = S0.toLowerCase();
881
+ var s1 = S1.toLowerCase();
882
+
883
+ $div.find("#postbox-labels input.auto-populate").each(function (i, e) {
884
+ var $e = $(e);
885
+ if ($e.val() !== "" || $e.is(":disabled")) {
886
+ return;
887
+ }
888
+
889
+ var format = $e.data("auto-format");
890
+ if (typeof String.prototype.replaceAll === "function") {
891
+ format = format.replaceAll("%S0", S0);
892
+ format = format.replaceAll("%S1", S1);
893
+ format = format.replaceAll("%s0", s0);
894
+ format = format.replaceAll("%s1", s1);
895
+ } else {
896
+ format = format.replace("%S0", S0);
897
+ format = format.replace("%S1", S1);
898
+ format = format.replace("%s0", s0);
899
+ format = format.replace("%s1", s1);
900
+ }
901
+
902
+ $e.val(format);
903
+ });
904
+
905
+ return false;
906
+ });
907
+
908
+ //hierarchical disable
909
+ $div.on('change', "select[name='hierarchical']", function () {
910
+ var $parent_item = $("input[name='parent_item']");
911
+ var $popular_items = $("input[name='popular_items']");
912
+ var $parent_item_colon = $("input[name='parent_item_colon']");
913
+ var $separate_items_with_commas = $("input[name='separate_items_with_commas']");
914
+ var $add_or_remove_items = $("input[name='add_or_remove_items']");
915
+ var $choose_from_most_used = $("input[name='choose_from_most_used']");
916
+ var $filter_by_item = $("input[name='filter_by_ite