PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/api-rest/wp-content/plugins/material-admin/lib/mtrl-settings.php

https://gitlab.com/neyberbz/suelos-ualm
PHP | 464 lines | 285 code | 98 blank | 81 comment | 62 complexity | 00c85123f4a0b86e12719cb2b76db135 MD5 | raw file
  1. <?php
  2. /* --------------- Admin Settings ---------------- */
  3. require_once( trailingslashit(dirname( __FILE__ )) . 'mtrl-menu-settings.php' );
  4. function mtrl_panel_settings(){
  5. global $mtrladmin;
  6. //print_r($mtrladmin);
  7. mtrl_add_option( "mtrladmin_plugin_access", "manage_options");
  8. mtrl_add_option( "mtrladmin_plugin_page", "show");
  9. mtrl_add_option( "mtrladmin_plugin_userid", "");
  10. mtrl_add_option( "mtrladmin_menumng_page", "enable");
  11. mtrl_add_option( "mtrladmin_admin_menumng_page", "enable");
  12. mtrl_add_option( "mtrladmin_admintheme_page", "enable");
  13. mtrl_add_option( "mtrladmin_logintheme_page", "enable");
  14. mtrl_add_option( "mtrladmin_master_theme", "0");
  15. $get_menumng_page = mtrl_get_option( "mtrladmin_menumng_page","enable");
  16. $get_admin_menumng_page = mtrl_get_option( "mtrladmin_admin_menumng_page","enable");
  17. $get_admintheme_page = mtrl_get_option( "mtrladmin_admintheme_page","enable");
  18. $get_logintheme_page = mtrl_get_option( "mtrladmin_logintheme_page","enable");
  19. $get_mastertheme_page = mtrl_get_option( "mtrladmin_master_theme","0");
  20. // manageoptions and super admin
  21. $mtrladmin_permissions = mtrl_get_option( "mtrladmin_plugin_access","manage_options");
  22. if($mtrladmin_permissions == "super_admin" && is_super_admin()){
  23. $mtrladmin_permissions = 'manage_options';
  24. }
  25. // specific user
  26. $mtrladmin_userid = mtrl_get_option( "mtrladmin_plugin_userid","");
  27. if($mtrladmin_permissions == "specific_user" && $mtrladmin_userid == get_current_user_id()){
  28. $mtrladmin_permissions = 'read';
  29. }
  30. $showtabs = true;
  31. if(is_multisite() && mtrl_network_active()){
  32. if(!is_main_site()){
  33. $showtabs = false;
  34. }
  35. }
  36. if($showtabs){
  37. add_menu_page('Material Admin Addon', __('Material Admin Addon', 'mtrl_framework'), $mtrladmin_permissions, 'mtrl_permission_settings', 'mtrl_permission_settings_page');
  38. add_submenu_page('mtrl_permission_settings', 'Plugin Settings', __('Plugin Settings', 'mtrl_framework'), $mtrladmin_permissions, 'mtrl_permission_settings', 'mtrl_permission_settings_page');
  39. if($get_menumng_page != "disable"){
  40. add_submenu_page('mtrl_permission_settings', 'Menu Management', __('Menu Management', 'mtrl_framework'), $mtrladmin_permissions, 'mtrl_menumng_settings', 'mtrl_menumng_settings_page');
  41. }
  42. }
  43. }
  44. function mtrl_permission_settings_page(){
  45. if (isset($_POST['action']) && $_POST['action'] == 'mtrl_save_settings') {
  46. mtrl_save_permission_settings();
  47. }
  48. $currentUser = wp_get_current_user();
  49. $isMultisite = is_multisite();
  50. $isSuperAdmin = is_super_admin();
  51. $get_plugin_access = mtrl_get_option( "mtrladmin_plugin_access","manage_options");
  52. $get_plugin_page = mtrl_get_option( "mtrladmin_plugin_page","show");
  53. $get_menumng_page = mtrl_get_option( "mtrladmin_menumng_page","enable");
  54. $get_admin_menumng_page = mtrl_get_option( "mtrladmin_admin_menumng_page","enable");
  55. $get_admintheme_page = mtrl_get_option( "mtrladmin_admintheme_page","enable");
  56. $get_logintheme_page = mtrl_get_option( "mtrladmin_logintheme_page","enable");
  57. $get_mastertheme_page = mtrl_get_option( "mtrladmin_master_theme","0");
  58. global $mtrladmin;
  59. //echo $mtrladmin['dynamic-css-type'];
  60. //echo "jhi";
  61. global $wpdb;
  62. global $blog_id;
  63. //echo "<pre>"; print_r($mtrladmin); echo "</pre>";
  64. ?>
  65. <div class="wrap">
  66. <h1>Material Admin Settings</h1>
  67. <?php
  68. $mtrl_plugin_settings = true;
  69. if(mtrl_network_active() && $blog_id != 1){
  70. $mtrl_plugin_settings = false;
  71. }
  72. ?>
  73. <?php if($mtrl_plugin_settings) { ?>
  74. <form method="post" action="<?php echo esc_url(add_query_arg(array())); ?>" id="mtrladmin_settings_form">
  75. <table class="form-table">
  76. <tbody>
  77. <tr>
  78. <th scope="row">
  79. Plugin Access Rights
  80. </th>
  81. <td>
  82. <fieldset>
  83. <p>
  84. <label>
  85. <input type="radio" name="plugin_access" value="super_admin"
  86. <?php checked('super_admin', $get_plugin_access); ?>
  87. >
  88. Super Admin
  89. <?php if ( !$isMultisite ) : ?>
  90. <br><span class="description">
  91. On a single site installation this is usually
  92. the same as the Administrator role.
  93. </span>
  94. <?php endif; ?>
  95. </label>
  96. </p>
  97. <p>
  98. <label>
  99. <input type="radio" name="plugin_access" value="manage_options"
  100. <?php checked('manage_options', $get_plugin_access); ?>
  101. >
  102. User the "manage_options" capability
  103. <br><span class="description">
  104. Only Administrators have this capability by default.
  105. </span>
  106. </label>
  107. </p>
  108. <p>
  109. <label>
  110. <input type="radio" name="plugin_access" value="specific_user"
  111. <?php checked('specific_user', $get_plugin_access); ?>
  112. <?php disabled( $isMultisite && !$isSuperAdmin ); ?>>
  113. Only the current user
  114. <br>
  115. <span class="description">
  116. Login: <?php echo $currentUser->user_login; ?>,
  117. user ID: <?php echo get_current_user_id(); ?>
  118. </span>
  119. </label>
  120. </p>
  121. </fieldset>
  122. <p>
  123. <label>
  124. <input type="checkbox" name="hide_plugin_from_others" value="1"
  125. <?php checked( $get_plugin_page == "hide" ); ?>
  126. <?php disabled( $isMultisite && !is_super_admin() ); ?>
  127. >
  128. Hide the "Material Admin" entry on the "Plugins" page from other users.<br><span class="description">(Other users are all users expect selected user type or user above.)</span>
  129. </label>
  130. </p>
  131. </td>
  132. </tr>
  133. <tr>
  134. <th scope="row">
  135. Menu Management
  136. </th>
  137. <td>
  138. <p>
  139. <label>
  140. <input type="checkbox" name="mtrl_disable_menumng" value="1"
  141. <?php checked( $get_menumng_page == "disable" ); ?>
  142. <?php disabled( $isMultisite && !is_super_admin() ); ?>
  143. >
  144. Check to <u>DISABLE</u> Material Admin MENU MANAGEMENT Addon.<br><span class="description">Generally disabled when the admin menu management is managed by some other premium plugins (providing similar functionality).</span>
  145. </label>
  146. </p>
  147. </td>
  148. </tr>
  149. <tr>
  150. <th scope="row">
  151. User Based Menu Management
  152. </th>
  153. <td>
  154. <p>
  155. <label>
  156. <input type="checkbox" name="mtrl_disable_admin_menumng" value="1"
  157. <?php checked( $get_admin_menumng_page == "disable" ); ?>
  158. <?php disabled( $isMultisite && !is_super_admin() ); ?>
  159. >
  160. Check to show Original Admin menu to administrator or super admin user. <br><span class="description">Means the edited menu (from Menu Management Addon) will be shown to all users except administrator or super admin users.</span>
  161. </label>
  162. </p>
  163. </td>
  164. </tr>
  165. <tr>
  166. <th scope="row">
  167. Material Admin Theme on Admin Pages
  168. </th>
  169. <td>
  170. <p>
  171. <label>
  172. <input type="checkbox" name="mtrl_disable_admintheme" value="1"
  173. <?php checked( $get_admintheme_page == "disable" ); ?>
  174. <?php disabled( $isMultisite && !is_super_admin() ); ?>
  175. >
  176. Check to <u>DISABLE</u> Material Admin Theme on ADMIN PAGES after successful user login.
  177. </label>
  178. </p>
  179. </td>
  180. </tr>
  181. <tr>
  182. <th scope="row">
  183. Material Admin Theme on Login Page
  184. </th>
  185. <td>
  186. <p>
  187. <label>
  188. <input type="checkbox" name="mtrl_disable_logintheme" value="1"
  189. <?php checked( $get_logintheme_page == "disable" ); ?>
  190. <?php disabled( $isMultisite && !is_super_admin() ); ?>
  191. >
  192. Check to <u>DISABLE</u> Material Admin Theme on LOGIN PAGE.
  193. </label>
  194. </p>
  195. </td>
  196. </tr>
  197. <?php /* if($isMultisite && $isSuperAdmin){ ?>
  198. <tr>
  199. <th scope="row">
  200. Material Admin Theme (on all network)
  201. </th>
  202. <td>
  203. <p>
  204. <select name='mtrl_multisite_options' id='mtrl_multisite_options'>
  205. <option value='0'>Individual Site Settings</option>
  206. <?php
  207. $blogarr = mtrl_multisite_allsites();
  208. foreach ($blogarr as $blogid => $blogname) {
  209. if($get_mastertheme_page == $blogid){ $mastersel = "selected"; } else { $mastersel = "";}
  210. echo '<option value="'.$blogid.'" '.$mastersel.'>'.$blogname.'</option>';
  211. }
  212. ?>
  213. </select>
  214. <br>Selected site &quot;Material Admin theme options&quot; will be applied to all the sites on network. All the sites on network will have same look and feel. &quot;Individual site settings&quot; means all the sites will have their own individual settings.
  215. </p>
  216. </td>
  217. </tr>
  218. <?php } */ ?>
  219. <?php /* <tr>
  220. <th scope="row">
  221. Multisite settings
  222. </th>
  223. <td>
  224. <fieldset id="ame-menu-scope-settings">
  225. <p>
  226. <label>
  227. <input type="radio" name="menu_config_scope" value="global"
  228. id="ame-menu-config-scope-global"
  229. <?php checked('global', $settings['menu_config_scope']); ?>
  230. <?php disabled(!$isMultisite || !$isSuperAdmin); ?>>
  231. Global &mdash;
  232. Use the same admin menu settings for all network sites.
  233. </label><br>
  234. </p>
  235. <label>
  236. <input type="radio" name="menu_config_scope" value="site"
  237. <?php checked('site', $settings['menu_config_scope']); ?>
  238. <?php disabled(!$isMultisite || !$isSuperAdmin); ?>>
  239. Per-site &mdash;
  240. Use different admin menu settings for each site.
  241. </label>
  242. </fieldset>
  243. </td>
  244. </tr> */
  245. ?>
  246. </tbody>
  247. </table>
  248. <input type="hidden" name="plugin_userid" value="<?php echo get_current_user_id(); ?>">
  249. <input type="hidden" name="action" value="mtrl_save_settings">
  250. <?php
  251. wp_nonce_field('save_settings');
  252. submit_button();
  253. ?>
  254. </form>
  255. <?php } ?>
  256. </div>
  257. <?php
  258. }
  259. function mtrl_save_permission_settings(){
  260. if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'save_settings')) {
  261. die('Save Permissions check failed.');
  262. }
  263. global $wpdb;
  264. $plugin_access = "manage_options";
  265. //print_r($_POST);
  266. if ($_POST['action'] == 'mtrl_save_settings')
  267. {
  268. // plugin access
  269. $plugin_access = $_POST['plugin_access'];
  270. mtrl_update_option( "mtrladmin_plugin_access", $plugin_access);
  271. // show on plugin page
  272. $plugin_page = "show";
  273. if (isset($_POST['hide_plugin_from_others'])) {
  274. $plugin_page = "hide";
  275. }
  276. mtrl_update_option( "mtrladmin_plugin_page", $plugin_page);
  277. // user specific
  278. $onlyuser = "";
  279. if ($plugin_access == "specific_user") {
  280. $onlyuser = $_POST['plugin_userid'];
  281. }
  282. mtrl_update_option( "mtrladmin_plugin_userid", $onlyuser);
  283. // show on menu mngmnt page
  284. $menumng_page = "enable";
  285. if (isset($_POST['mtrl_disable_menumng'])) {
  286. $menumng_page = "disable";
  287. }
  288. mtrl_update_option( "mtrladmin_menumng_page", $menumng_page);
  289. // show on menu mngmnt page for admin users
  290. $admin_menumng_page = "enable";
  291. if (isset($_POST['mtrl_disable_admin_menumng'])) {
  292. $admin_menumng_page = "disable";
  293. }
  294. mtrl_update_option( "mtrladmin_admin_menumng_page", $admin_menumng_page);
  295. // show on admin theme
  296. $admintheme_page = "enable";
  297. if (isset($_POST['mtrl_disable_admintheme'])) {
  298. $admintheme_page = "disable";
  299. }
  300. mtrl_update_option( "mtrladmin_admintheme_page", $admintheme_page);
  301. // show on login theme
  302. $logintheme_page = "enable";
  303. if (isset($_POST['mtrl_disable_logintheme'])) {
  304. $logintheme_page = "disable";
  305. }
  306. mtrl_update_option( "mtrladmin_logintheme_page", $logintheme_page);
  307. /*Update multisite in one click settings*/
  308. $master_theme = 0;
  309. $master_options = "";
  310. if (isset($_POST['mtrl_multisite_options']) && $_POST['mtrl_multisite_options'] != "0" && is_numeric($_POST['mtrl_multisite_options'])) {
  311. $master_theme = $_POST['mtrl_multisite_options'];
  312. update_option( "mtrladmin_master_theme", $master_theme);
  313. if($master_theme != "0"){
  314. $master_options = get_blog_option( $master_theme, 'mtrl_demo' );
  315. $blogarr = mtrl_multisite_allsites();
  316. foreach ($blogarr as $blogid => $blogname) {
  317. update_blog_option($blogid, 'mtrl_demo', $master_options);
  318. }
  319. }
  320. }
  321. }
  322. }
  323. add_filter('all_plugins', 'mtrl_filter_plugin_list');
  324. function mtrl_filter_plugin_list(){
  325. if ( ! function_exists( 'get_plugins' ) ) {
  326. require_once ABSPATH . 'wp-admin/includes/plugin.php';
  327. }
  328. $plugins = get_plugins();
  329. //print_r($plugins);
  330. $currentUser = wp_get_current_user();
  331. $uaccess = mtrl_get_option( "mtrladmin_plugin_access","manage_options");
  332. $upage = mtrl_get_option( "mtrladmin_plugin_page","show");
  333. $uid = mtrl_get_option( "mtrladmin_plugin_userid","");
  334. if($upage == "hide"){
  335. if($uaccess == "super_admin" && !is_super_admin()){
  336. unset($plugins['material-admin/mtrl-core.php']);
  337. }
  338. if($uaccess == "specific_user" && $uid != get_current_user_id()){
  339. unset($plugins['material-admin/mtrl-core.php']);
  340. }
  341. if($uaccess == "manage_options" && !current_user_can('manage_options')){
  342. unset($plugins['material-admin/mtrl-core.php']);
  343. }
  344. }
  345. return $plugins;
  346. /*
  347. if($get_plugin_access == "specific_user" && $get_plugin_page == "hide"){
  348. }
  349. $get_plugin_userid == get_current_user_id()
  350. $allowed_user_id = $this->wp_menu_editor->get_plugin_option('plugins_page_allowed_user_id');
  351. if ( get_current_user_id() != $allowed_user_id ) {
  352. unset($plugins[$this->wp_menu_editor->plugin_basename]);
  353. }
  354. return $plugins;*/
  355. }
  356. ?>