PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/adminimize/adminimize.php

https://gitlab.com/hunglion1368/wordpress-boilerplate
PHP | 1914 lines | 1483 code | 218 blank | 213 comment | 258 complexity | 52fd64184a69f1cf55a883f3ac290750 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Plugin Name: Adminimize
  4. * Plugin URI: https://wordpress.org/plugins/adminimize/
  5. * Text Domain: adminimize
  6. * Domain Path: /languages
  7. * Description: Visually compresses the administrative meta-boxes so that more admin page content can be initially
  8. * seen. The plugin that lets you hide 'unnecessary' items from the WordPress administration menu, for all roles of
  9. * your install. You can also hide post meta controls on the edit-area to simplify the interface. It is possible to
  10. * simplify the admin in different for all roles.
  11. * Author: Frank Bültge
  12. * Author URI: http://bueltge.de/
  13. * Version: 1.8.5
  14. * License: GPLv2+
  15. *
  16. * Php Version 5.3
  17. *
  18. * @package WordPress
  19. * @author Frank Bültge <f.bueltge@inpsyde.com>
  20. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  21. * @version 2015-03-19
  22. */
  23. /**
  24. * The stylesheet and the initial idea is from Eric A. Meyer, http://meyerweb.com/
  25. * and i have written a plugin with many options on the basis
  26. * of differently user-right and a user-friendly range in admin-area.
  27. *
  28. * :( grmpf i have so much wishes and hints form users, do use the plugin and
  29. * it is not possible to development this on my free time
  30. */
  31. if ( ! function_exists( 'add_action' ) ) {
  32. echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
  33. exit;
  34. }
  35. // plugin definitions
  36. define( 'FB_ADMINIMIZE_BASENAME', plugin_basename( __FILE__ ) );
  37. define( 'FB_ADMINIMIZE_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
  38. define( 'FB_ADMINIMIZE_TEXTDOMAIN', _mw_adminimize_get_plugin_data( 'TextDomain' ) );
  39. function _mw_adminimize_get_plugin_data( $value = 'Version' ) {
  40. if ( ! function_exists( 'get_plugin_data' ) ) {
  41. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  42. }
  43. $plugin_data = get_plugin_data( __FILE__ );
  44. $plugin_value = $plugin_data[ $value ];
  45. return $plugin_value;
  46. }
  47. function _mw_adminimize_textdomain() {
  48. load_plugin_textdomain(
  49. _mw_adminimize_get_plugin_data( 'TextDomain' ),
  50. FALSE,
  51. dirname( FB_ADMINIMIZE_BASENAME ) . _mw_adminimize_get_plugin_data( 'DomainPath' )
  52. );
  53. }
  54. function _mw_adminimize_recursive_in_array( $needle, $haystack ) {
  55. if ( '' != $haystack ) {
  56. foreach ( $haystack as $stalk ) {
  57. if ( $needle == $stalk
  58. || ( is_array( $stalk ) && _mw_adminimize_recursive_in_array( $needle, $stalk )
  59. )
  60. ) {
  61. return TRUE;
  62. }
  63. }
  64. return FALSE;
  65. }
  66. return FALSE;
  67. }
  68. /**
  69. * some basics for message
  70. */
  71. class _mw_adminimize_message_class {
  72. /**
  73. * constructor
  74. */
  75. function _mw_adminimize_message_class() {
  76. $this->localizion_name = FB_ADMINIMIZE_TEXTDOMAIN;
  77. $this->errors = new WP_Error();
  78. $this->initialize_errors();
  79. }
  80. /**
  81. * get_error - Returns an error message based on the passed code
  82. * Parameters - $code (the error code as a string)
  83. *
  84. * @param string $code
  85. *
  86. * @return string $errorMessage
  87. */
  88. function get_error( $code = '' ) {
  89. $errorMessage = $this->errors->get_error_message( $code );
  90. if ( NULL == $errorMessage ) {
  91. return __( 'Unknown error.', $this->localizion_name );
  92. }
  93. return $errorMessage;
  94. }
  95. /**
  96. * Initializes all the error messages
  97. */
  98. function initialize_errors() {
  99. $this->errors->add( '_mw_adminimize_update', __( 'The updates were saved.', $this->localizion_name ) );
  100. $this->errors->add(
  101. '_mw_adminimize_access_denied',
  102. __( 'You have not enough rights to edit entries in the database.', $this->localizion_name )
  103. );
  104. $this->errors->add(
  105. '_mw_adminimize_import', __( 'All entries in the database were imported.', $this->localizion_name )
  106. );
  107. $this->errors->add(
  108. '_mw_adminimize_deinstall', __( 'All entries in the database were deleted.', $this->localizion_name )
  109. );
  110. $this->errors->add(
  111. '_mw_adminimize_deinstall_yes', __( 'Set the checkbox on deinstall-button.', $this->localizion_name )
  112. );
  113. $this->errors->add(
  114. '_mw_adminimize_get_option', __( 'Can\'t load menu and submenu.', $this->localizion_name )
  115. );
  116. $this->errors->add( '_mw_adminimize_set_theme', __( 'Backend-Theme was activated!', $this->localizion_name ) );
  117. $this->errors->add(
  118. '_mw_adminimize_load_theme', __( 'Load user data to themes was successful.', $this->localizion_name )
  119. );
  120. }
  121. } // end class
  122. function _mw_adminimize_exclude_super_admin() {
  123. // exclude super admin
  124. if ( function_exists( 'is_super_admin' )
  125. && is_super_admin()
  126. && 1 == _mw_adminimize_get_option_value( '_mw_adminimize_exclude_super_admin' )
  127. ) {
  128. return TRUE;
  129. }
  130. return FALSE;
  131. }
  132. /**
  133. * _mw_adminimize_get_all_user_roles() - Returns an array with all user roles(names) in it.
  134. * Inclusive self defined roles (for example with the 'Role Manager' plugin).
  135. * code by Vincent Weber, www.webRtistik.nl
  136. *
  137. * @uses $wp_roles
  138. * @return array $user_roles
  139. */
  140. function _mw_adminimize_get_all_user_roles() {
  141. global $wp_roles;
  142. $user_roles = array();
  143. if ( isset( $wp_roles->roles ) && is_array( $wp_roles->roles ) ) {
  144. foreach ( $wp_roles->roles as $role => $data ) {
  145. array_push( $user_roles, $role );
  146. //$data contains caps, maybe for later use..
  147. }
  148. }
  149. // exclude the new bbPress roles
  150. $user_roles = array_diff(
  151. $user_roles,
  152. array( 'bbp_keymaster', 'bbp_moderator', 'bbp_participant', 'bbp_spectator', 'bbp_blocked' )
  153. );
  154. return $user_roles;
  155. }
  156. /**
  157. * _mw_adminimize_get_all_user_roles_names() - Returns an array with all user roles_names in it.
  158. * Inclusive self defined roles (for example with the 'Role Manager' plugin).
  159. *
  160. * @uses $wp_roles
  161. * @return array $user_roles_names
  162. */
  163. function _mw_adminimize_get_all_user_roles_names() {
  164. global $wp_roles;
  165. $user_roles_names = array();
  166. foreach ( $wp_roles->role_names as $role_name => $data ) {
  167. if ( function_exists( 'translate_user_role' ) ) {
  168. $data = translate_user_role( $data );
  169. } else {
  170. $data = _x( $data, 'Translate each user role.' );
  171. }
  172. array_push( $user_roles_names, $data );
  173. }
  174. // exclude the new bbPress roles
  175. $user_roles_names = array_diff(
  176. $user_roles_names,
  177. array(
  178. __( 'Keymaster', 'bbpress' ),
  179. __( 'Moderator', 'bbpress' ),
  180. __( 'Participant', 'bbpress' ),
  181. __( 'Spectator', 'bbpress' ),
  182. __( 'Blocked', 'bbpress' )
  183. )
  184. );
  185. return $user_roles_names;
  186. }
  187. /**
  188. * Control Flash Uploader
  189. *
  190. * @return boolean
  191. */
  192. function _mw_adminimize_control_flashloader() {
  193. $_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
  194. if ( $_mw_adminimize_control_flashloader == '1' ) {
  195. return FALSE;
  196. } else {
  197. return TRUE;
  198. }
  199. }
  200. /**
  201. * return post type
  202. */
  203. function _mw_get_current_post_type() {
  204. global $post, $typenow, $current_screen;
  205. //we have a post so we can just get the post type from that
  206. if ( $post && $post->post_type ) {
  207. return $post->post_type;
  208. } //check the global $typenow - set in admin.php
  209. else if ( $typenow ) {
  210. return $typenow;
  211. } // check the global $current_screen object - set in sceen.php
  212. else if ( $current_screen && $current_screen->post_type ) {
  213. return $current_screen->post_type;
  214. } // lastly check the post_type querystring
  215. else if ( isset( $_REQUEST[ 'post_type' ] ) ) {
  216. return sanitize_key( $_REQUEST[ 'post_type' ] );
  217. }
  218. // we do not know the post type!
  219. return NULL;
  220. }
  221. /**
  222. * check user-option and add new style
  223. *
  224. * @uses $pagenow
  225. */
  226. function _mw_adminimize_admin_init() {
  227. global $pagenow, $post_type, $menu, $submenu;
  228. if ( isset( $_GET[ 'post' ] ) ) {
  229. $post_id = (int) esc_attr( $_GET[ 'post' ] );
  230. } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
  231. $post_id = (int) esc_attr( $_POST[ 'post_ID' ] );
  232. } else {
  233. $post_id = 0;
  234. }
  235. $current_post_type = $post_type;
  236. if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
  237. $current_post_type = get_post_type( $post_id );
  238. }
  239. if ( ! isset( $current_post_type ) || empty( $current_post_type ) ) {
  240. $current_post_type = _mw_get_current_post_type();
  241. }
  242. if ( ! $current_post_type ) // set hard to post
  243. {
  244. $current_post_type = 'post';
  245. }
  246. $user_roles = _mw_adminimize_get_all_user_roles();
  247. // check for use on multisite
  248. if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
  249. $adminimizeoptions = get_site_option( 'mw_adminimize' );
  250. } else {
  251. $adminimizeoptions = get_option( 'mw_adminimize' );
  252. }
  253. // pages for post type Post
  254. $def_post_pages = array( 'edit.php', 'post.php', 'post-new.php' );
  255. $def_post_types = array( 'post' );
  256. $disabled_metaboxes_post_all = array();
  257. // pages for post type Page
  258. $def_page_pages = array_merge( $def_post_pages, array( 'page-new.php', 'page.php' ) );
  259. $def_page_types = array( 'page' );
  260. $disabled_metaboxes_page_all = array();
  261. // pages for custom post types
  262. $def_custom_pages = $def_post_pages;
  263. $args = array( 'public' => TRUE, '_builtin' => FALSE );
  264. $def_custom_types = get_post_types( $args );
  265. // pages for link pages
  266. $link_pages = array( 'link.php', 'link-manager.php', 'link-add.php', 'edit-link-categories.php' );
  267. // pages for nav menu
  268. $nav_menu_pages = array( 'nav-menus.php' );
  269. // widget pages
  270. $widget_pages = array( 'widgets.php' );
  271. foreach ( $user_roles as $role ) {
  272. $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
  273. 'mw_adminimize_disabled_admin_bar_' . $role . '_items'
  274. );
  275. $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
  276. 'mw_adminimize_disabled_global_option_' . $role . '_items'
  277. );
  278. $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
  279. 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
  280. );
  281. $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
  282. 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
  283. );
  284. foreach ( $def_custom_types as $post_type ) {
  285. $disabled_metaboxes_[ $post_type . '_' . $role ] = _mw_adminimize_get_option_value(
  286. 'mw_adminimize_disabled_metaboxes_' . $post_type . '_' . $role . '_items'
  287. );
  288. }
  289. $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
  290. 'mw_adminimize_disabled_link_option_' . $role . '_items'
  291. );
  292. $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
  293. 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
  294. );
  295. $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
  296. 'mw_adminimize_disabled_widget_option_' . $role . '_items'
  297. );
  298. array_push( $disabled_metaboxes_post_all, $disabled_metaboxes_post_[ $role ] );
  299. array_push( $disabled_metaboxes_page_all, $disabled_metaboxes_page_[ $role ] );
  300. }
  301. // global options
  302. // exclude super admin
  303. if ( ! _mw_adminimize_exclude_super_admin() ) {
  304. $_mw_adminimize_footer = _mw_adminimize_get_option_value( '_mw_adminimize_footer' );
  305. switch ( $_mw_adminimize_footer ) {
  306. case 1:
  307. wp_enqueue_script(
  308. '_mw_adminimize_remove_footer',
  309. WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_footer.js',
  310. array( 'jquery' )
  311. );
  312. break;
  313. }
  314. $_mw_adminimize_header = _mw_adminimize_get_option_value( '_mw_adminimize_header' );
  315. switch ( $_mw_adminimize_header ) {
  316. case 1:
  317. wp_enqueue_script(
  318. '_mw_adminimize_remove_header',
  319. WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/remove_header.js',
  320. array( 'jquery' )
  321. );
  322. break;
  323. }
  324. //post-page options
  325. if ( in_array( $pagenow, $def_post_pages ) ) {
  326. $_mw_adminimize_tb_window = _mw_adminimize_get_option_value( '_mw_adminimize_tb_window' );
  327. switch ( $_mw_adminimize_tb_window ) {
  328. case 1:
  329. wp_deregister_script( 'media-upload' );
  330. wp_enqueue_script(
  331. 'media-upload',
  332. WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/tb_window.js',
  333. array( 'thickbox' )
  334. );
  335. break;
  336. }
  337. $_mw_adminimize_timestamp = _mw_adminimize_get_option_value( '_mw_adminimize_timestamp' );
  338. switch ( $_mw_adminimize_timestamp ) {
  339. case 1:
  340. wp_enqueue_script(
  341. '_mw_adminimize_timestamp',
  342. WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/js/timestamp.js',
  343. array( 'jquery' )
  344. );
  345. break;
  346. }
  347. //category options
  348. $_mw_adminimize_cat_full = _mw_adminimize_get_option_value( '_mw_adminimize_cat_full' );
  349. switch ( $_mw_adminimize_cat_full ) {
  350. case 1:
  351. wp_enqueue_style(
  352. 'adminimize-ful-category',
  353. WP_PLUGIN_URL . '/' . FB_ADMINIMIZE_BASEFOLDER . '/css/mw_cat_full.css'
  354. );
  355. break;
  356. }
  357. // set default editor tinymce
  358. if ( _mw_adminimize_recursive_in_array(
  359. '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
  360. $disabled_metaboxes_page_all
  361. )
  362. || _mw_adminimize_recursive_in_array(
  363. '#editor-toolbar #edButtonHTML, #quicktags, #content-html',
  364. $disabled_metaboxes_post_all
  365. )
  366. ) {
  367. add_filter( 'wp_default_editor', create_function( '', 'return "tinymce";' ) );
  368. }
  369. // remove media bottons
  370. if ( _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_page_all )
  371. || _mw_adminimize_recursive_in_array( 'media_buttons', $disabled_metaboxes_post_all )
  372. ) {
  373. remove_action( 'media_buttons', 'media_buttons' );
  374. }
  375. }
  376. $_mw_adminimize_control_flashloader = _mw_adminimize_get_option_value( '_mw_adminimize_control_flashloader' );
  377. switch ( $_mw_adminimize_control_flashloader ) {
  378. case 1:
  379. add_filter( 'flash_uploader', '_mw_adminimize_control_flashloader', 1 );
  380. break;
  381. }
  382. }
  383. // set menu option
  384. add_action( 'admin_head', '_mw_adminimize_set_menu_option', 1 );
  385. // global_options
  386. add_action( 'admin_head', '_mw_adminimize_set_global_option', 1 );
  387. // set metabox post option
  388. if ( in_array( $pagenow, $def_post_pages ) && in_array( $current_post_type, $def_post_types ) ) {
  389. add_action( 'admin_head', '_mw_adminimize_set_metabox_post_option', 1 );
  390. }
  391. // set metabox page option
  392. if ( in_array( $pagenow, $def_page_pages ) && in_array( $current_post_type, $def_page_types ) ) {
  393. add_action( 'admin_head', '_mw_adminimize_set_metabox_page_option', 1 );
  394. }
  395. // set custom post type options
  396. if ( function_exists( 'get_post_types' ) && in_array( $pagenow, $def_custom_pages )
  397. && in_array(
  398. $current_post_type, $def_custom_types
  399. )
  400. ) {
  401. add_action( 'admin_head', '_mw_adminimize_set_metabox_cp_option', 1 );
  402. }
  403. // set link option
  404. if ( in_array( $pagenow, $link_pages ) ) {
  405. add_action( 'admin_head', '_mw_adminimize_set_link_option', 1 );
  406. }
  407. // set wp nav menu options
  408. if ( in_array( $pagenow, $nav_menu_pages ) ) {
  409. add_action( 'admin_head', '_mw_adminimize_set_nav_menu_option', 1 );
  410. }
  411. // set widget options
  412. if ( in_array( $pagenow, $widget_pages ) ) {
  413. add_action( 'admin_head', '_mw_adminimize_set_widget_option', 1 );
  414. }
  415. $adminimizeoptions[ 'mw_adminimize_default_menu' ] = $menu;
  416. $adminimizeoptions[ 'mw_adminimize_default_submenu' ] = $submenu;
  417. }
  418. /**
  419. * Init always with WP
  420. */
  421. function _mw_adminimize_init() {
  422. // change Admin Bar and user Info
  423. if ( version_compare( $GLOBALS[ 'wp_version' ], '3.3alpha', '>=' ) ) {
  424. _mw_adminimize_set_menu_option_33();
  425. } else {
  426. add_action( 'admin_head', '_mw_adminimize_set_user_info' );
  427. add_action( 'wp_head', '_mw_adminimize_set_user_info' );
  428. }
  429. }
  430. // on admin init
  431. define( 'MW_ADMIN_FILE', plugin_basename( __FILE__ ) );
  432. if ( is_admin() ) {
  433. add_action( 'admin_init', '_mw_adminimize_textdomain' );
  434. add_action( 'admin_init', '_mw_adminimize_admin_init', 2 );
  435. /* maybe later
  436. if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) )
  437. add_action( 'network_admin_menu', '_mw_adminimize_add_settings_page' );
  438. */
  439. add_action( 'admin_menu', '_mw_adminimize_add_settings_page' );
  440. add_action( 'admin_menu', '_mw_adminimize_remove_dashboard' );
  441. }
  442. add_action( 'init', '_mw_adminimize_init', 2 );
  443. register_activation_hook( __FILE__, '_mw_adminimize_install' );
  444. register_uninstall_hook( __FILE__, '_mw_adminimize_deinstall' );
  445. //register_deactivation_hook(__FILE__, '_mw_adminimize_deinstall' );
  446. /**
  447. * list category-box in sidebar
  448. *
  449. * @uses $post_ID
  450. */
  451. function _mw_adminimize_sidecat_list_category_box() {
  452. global $post_ID;
  453. ?>
  454. <div class="inside" id="categorydivsb">
  455. <p><strong><?php _e( "Categories" ); ?></strong></p>
  456. <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
  457. <?php wp_category_checklist( $post_ID ); ?>
  458. </ul>
  459. <?php if ( ! defined( 'WP_PLUGIN_DIR' ) ) { // for wp <2.6 ?>
  460. <div id="category-adder" class="wp-hidden-children">
  461. <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
  462. '+ Add New Category'
  463. ); ?></a></h4>
  464. <p id="category-add" class="wp-hidden-child">
  465. <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
  466. 'New category name'
  467. ); ?>" tabindex="3" />
  468. <?php wp_dropdown_categories(
  469. array(
  470. 'hide_empty' => 0,
  471. 'name' => 'newcat_parent',
  472. 'orderby' => 'name',
  473. 'hierarchical' => 1,
  474. 'show_option_none' => __( 'Parent category' ),
  475. 'tab_index' => 3
  476. )
  477. ); ?>
  478. <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
  479. 'Add'
  480. ); ?>" tabindex="3" />
  481. <?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
  482. <span id="category-ajax-response"></span>
  483. </p>
  484. </div>
  485. <?php } else { ?>
  486. <div id="category-adder" class="wp-hidden-children">
  487. <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e(
  488. '+ Add New Category'
  489. ); ?></a></h4>
  490. <p id="category-add" class="wp-hidden-child">
  491. <label class="hidden" for="newcat"><?php _e(
  492. 'Add New Category'
  493. ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e(
  494. 'New category name'
  495. ); ?>" tabindex="3" aria-required="TRUE" />
  496. <br />
  497. <label class="hidden" for="newcat_parent"><?php _e(
  498. 'Parent category'
  499. ); ?>:</label><?php wp_dropdown_categories(
  500. array(
  501. 'hide_empty' => 0,
  502. 'name' => 'newcat_parent',
  503. 'orderby' => 'name',
  504. 'hierarchical' => 1,
  505. 'show_option_none' => __( 'Parent category' ),
  506. 'tab_index' => 3
  507. )
  508. ); ?>
  509. <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e(
  510. 'Add'
  511. ); ?>" tabindex="3" />
  512. <?php wp_nonce_field( 'add-category', '_ajax_nonce', FALSE ); ?>
  513. <span id="category-ajax-response"></span>
  514. </p>
  515. </div>
  516. <?php } ?>
  517. </div>
  518. <?php
  519. }
  520. /**
  521. * Remove the dashboard
  522. *
  523. * @author Basic Austin Matzko
  524. * @see http://www.ilfilosofo.com/blog/2006/05/24/plugin-remove-the-wordpress-dashboard/
  525. */
  526. function _mw_adminimize_remove_dashboard() {
  527. global $menu, $user_ID, $wp_version;
  528. $disabled_menu_ = '';
  529. $disabled_submenu_ = '';
  530. $user_roles = _mw_adminimize_get_all_user_roles();
  531. foreach ( $user_roles as $role ) {
  532. $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
  533. 'mw_adminimize_disabled_menu_' . $role . '_items'
  534. );
  535. $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
  536. 'mw_adminimize_disabled_submenu_' . $role . '_items'
  537. );
  538. }
  539. $disabled_menu_all = array();
  540. $disabled_submenu_all = array();
  541. foreach ( $user_roles as $role ) {
  542. array_push( $disabled_menu_all, $disabled_menu_[ $role ] );
  543. array_push( $disabled_submenu_all, $disabled_submenu_[ $role ] );
  544. }
  545. // remove dashboard
  546. if ( $disabled_menu_all != '' || $disabled_submenu_all != '' ) {
  547. foreach ( $user_roles as $role ) {
  548. if ( current_user_can( $role ) ) {
  549. if ( _mw_adminimize_recursive_in_array(
  550. 'index.php', $disabled_menu_[ $role ]
  551. )
  552. || _mw_adminimize_recursive_in_array( 'index.php', $disabled_submenu_[ $role ] )
  553. ) {
  554. $redirect = TRUE;
  555. } else {
  556. $redirect = FALSE;
  557. }
  558. }
  559. }
  560. // redirect option, if Dashboard is inactive
  561. if ( isset( $redirect ) && $redirect ) {
  562. $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect' );
  563. $_mw_adminimize_db_redirect_admin_url = get_option( 'siteurl' ) . '/wp-admin/';
  564. switch ( $_mw_adminimize_db_redirect ) {
  565. case 0:
  566. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'profile.php';
  567. break;
  568. case 1:
  569. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php';
  570. break;
  571. case 2:
  572. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit.php?post_type=page';
  573. break;
  574. case 3:
  575. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'post-new.php';
  576. break;
  577. case 4:
  578. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'page-new.php';
  579. break;
  580. case 5:
  581. $_mw_adminimize_db_redirect = $_mw_adminimize_db_redirect_admin_url . 'edit-comments.php';
  582. break;
  583. case 6:
  584. $_mw_adminimize_db_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_db_redirect_txt' );
  585. break;
  586. }
  587. // fallback for WP smaller 3.0
  588. if ( version_compare(
  589. $wp_version, "3.0alpha", "<"
  590. )
  591. && 'edit.php?post_type=page' == $_mw_adminimize_db_redirect
  592. ) {
  593. $_mw_adminimize_db_redirect = 'edit-pages.php';
  594. }
  595. $the_user = new WP_User( $user_ID );
  596. reset( $menu );
  597. $page = key( $menu );
  598. while ( ( __( 'Dashboard' ) != $menu[ $page ][ 0 ] ) && next( $menu )
  599. || ( __(
  600. 'Dashboard'
  601. ) != $menu[ $page ][ 1 ] )
  602. && next( $menu ) ) {
  603. $page = key( $menu );
  604. }
  605. if ( __( 'Dashboard' ) == $menu[ $page ][ 0 ] || __( 'Dashboard' ) == $menu[ $page ][ 1 ] ) {
  606. unset( $menu[ $page ] );
  607. }
  608. reset( $menu );
  609. $page = key( $menu );
  610. while ( ! $the_user->has_cap( $menu[ $page ][ 1 ] ) && next( $menu ) ) {
  611. $page = key( $menu );
  612. }
  613. if ( preg_match( '#wp-admin/?(index.php)?$#', $_SERVER[ 'REQUEST_URI' ] ) ) {
  614. wp_redirect( $_mw_adminimize_db_redirect );
  615. }
  616. }
  617. }
  618. }
  619. /**
  620. * set menu options from database
  621. */
  622. function _mw_adminimize_set_user_info() {
  623. global $user_identity, $wp_version;
  624. // exclude super admin
  625. if ( _mw_adminimize_exclude_super_admin() ) {
  626. return NULL;
  627. }
  628. $user_roles = _mw_adminimize_get_all_user_roles();
  629. foreach ( $user_roles as $role ) {
  630. $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
  631. 'mw_adminimize_disabled_menu_' . $role . '_items'
  632. );
  633. $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
  634. 'mw_adminimize_disabled_submenu_' . $role . '_items'
  635. );
  636. }
  637. $_mw_adminimize_admin_head = "\n";
  638. $_mw_adminimize_user_info = _mw_adminimize_get_option_value( '_mw_adminimize_user_info' );
  639. $_mw_adminimize_ui_redirect = _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' );
  640. // change user-info
  641. switch ( $_mw_adminimize_user_info ) {
  642. case 1:
  643. $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
  644. $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove(); });' . "\n";
  645. $_mw_adminimize_admin_head .= '</script>' . "\n";
  646. break;
  647. case 2:
  648. if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
  649. if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
  650. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  651. dirname( __FILE__ )
  652. ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
  653. }
  654. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  655. dirname( __FILE__ )
  656. ) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
  657. } elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
  658. if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
  659. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  660. dirname( __FILE__ )
  661. ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
  662. }
  663. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  664. dirname( __FILE__ )
  665. ) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
  666. } elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
  667. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  668. dirname( __FILE__ )
  669. ) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
  670. } else {
  671. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  672. dirname( __FILE__ )
  673. ) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
  674. }
  675. $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
  676. $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
  677. if ( $_mw_adminimize_ui_redirect == '1' ) {
  678. $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
  679. 'siteurl'
  680. ) . wp_nonce_url(
  681. ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
  682. ) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
  683. } else {
  684. $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
  685. 'siteurl'
  686. ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
  687. 'Log Out'
  688. ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
  689. }
  690. $_mw_adminimize_admin_head .= '</script>' . "\n";
  691. break;
  692. case 3:
  693. if ( version_compare( $wp_version, "3.2alpha", ">=" ) ) {
  694. if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
  695. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  696. dirname( __FILE__ )
  697. ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
  698. }
  699. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  700. dirname( __FILE__ )
  701. ) . '/css/mw_small_user_info32.css" type="text/css" />' . "\n";
  702. } elseif ( version_compare( $wp_version, "3.0alpha", ">=" ) ) {
  703. if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) {
  704. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  705. dirname( __FILE__ )
  706. ) . '/css/mw_small_user_info31.css" type="text/css" />' . "\n";
  707. }
  708. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  709. dirname( __FILE__ )
  710. ) . '/css/mw_small_user_info30.css" type="text/css" />' . "\n";
  711. } elseif ( version_compare( substr( $wp_version, 0, 3 ), '2.7', '>=' ) ) {
  712. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  713. dirname( __FILE__ )
  714. ) . '/css/mw_small_user_info27.css" type="text/css" />' . "\n";
  715. } else {
  716. $_mw_adminimize_admin_head .= '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(
  717. dirname( __FILE__ )
  718. ) . '/css/mw_small_user_info.css" type="text/css" />' . "\n";
  719. }
  720. $_mw_adminimize_admin_head .= '<script type="text/javascript">' . "\n";
  721. $_mw_adminimize_admin_head .= "\t" . 'jQuery(document).ready(function() { jQuery(\'#user_info\' ).remove();';
  722. if ( $_mw_adminimize_ui_redirect == '1' ) {
  723. $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
  724. 'siteurl'
  725. ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
  726. 'siteurl'
  727. ) . wp_nonce_url(
  728. ( '/wp-login.php?action=logout&amp;redirect_to=' ) . get_option( 'siteurl' ), 'log-out'
  729. ) . '" title="' . __( 'Log Out' ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
  730. } else {
  731. $_mw_adminimize_admin_head .= 'jQuery(\'div#wpcontent\' ).after(\'<div id="small_user_info"><p><a href="' . get_option(
  732. 'siteurl'
  733. ) . ( '/wp-admin/profile.php' ) . '">' . $user_identity . '</a> | <a href="' . get_option(
  734. 'siteurl'
  735. ) . wp_nonce_url( ( '/wp-login.php?action=logout' ), 'log-out' ) . '" title="' . __(
  736. 'Log Out'
  737. ) . '">' . __( 'Log Out' ) . '</a></p></div>\' ) });' . "\n";
  738. }
  739. $_mw_adminimize_admin_head .= '</script>' . "\n";
  740. break;
  741. }
  742. echo $_mw_adminimize_admin_head;
  743. }
  744. /**
  745. * Set menu for settings
  746. */
  747. function _mw_adminimize_set_menu_option() {
  748. global $menu, $submenu, $current_screen;
  749. // exclude super admin
  750. if ( _mw_adminimize_exclude_super_admin() ) {
  751. return NULL;
  752. }
  753. if ( 'settings_page_adminimize/adminimize' === $current_screen->id ) {
  754. return NULL;
  755. }
  756. $user_roles = _mw_adminimize_get_all_user_roles();
  757. $disabled_menu_ = '';
  758. $disabled_submenu_ = '';
  759. foreach ( $user_roles as $role ) {
  760. $disabled_menu_[ $role ] = _mw_adminimize_get_option_value(
  761. 'mw_adminimize_disabled_menu_' . $role . '_items'
  762. );
  763. $disabled_submenu_[ $role ] = _mw_adminimize_get_option_value(
  764. 'mw_adminimize_disabled_submenu_' . $role . '_items'
  765. );
  766. }
  767. $mw_adminimize_menu = '';
  768. // set menu
  769. if ( isset( $disabled_menu_[ 'editor' ] ) && '' != $disabled_menu_[ 'editor' ] ) {
  770. // set admin-menu
  771. foreach ( $user_roles as $role ) {
  772. $user = wp_get_current_user();
  773. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  774. if ( current_user_can( $role ) ) {
  775. $mw_adminimize_menu = $disabled_menu_[ $role ];
  776. $mw_adminimize_submenu = $disabled_submenu_[ $role ];
  777. }
  778. }
  779. }
  780. // fallback on users.php on all userroles smaller admin
  781. if ( is_array( $mw_adminimize_menu ) && in_array( 'users.php', $mw_adminimize_menu ) ) {
  782. $mw_adminimize_menu[ ] = 'profile.php';
  783. }
  784. if ( isset( $menu ) && ! empty( $menu ) ) {
  785. foreach ( $menu as $index => $item ) {
  786. if ( 'index.php' === $item ) {
  787. continue;
  788. }
  789. if ( isset( $mw_adminimize_menu ) && in_array( $item[ 2 ], $mw_adminimize_menu ) ) {
  790. unset( $menu[ $index ] );
  791. }
  792. if ( isset( $submenu ) && ! empty( $submenu[ $item[ 2 ] ] ) ) {
  793. foreach ( $submenu[ $item[ 2 ] ] as $subindex => $subitem ) {
  794. if ( isset( $mw_adminimize_submenu ) && in_array( $subitem[ 2 ], $mw_adminimize_submenu ) )
  795. //if ( 'profile.php' === $subitem[2] )
  796. // unset( $menu[70] );
  797. {
  798. unset( $submenu[ $item[ 2 ] ][ $subindex ] );
  799. }
  800. }
  801. }
  802. }
  803. }
  804. }
  805. }
  806. /**
  807. * set global options in backend in all areas
  808. */
  809. function _mw_adminimize_set_global_option() {
  810. global $_wp_admin_css_colors;
  811. // exclude super admin
  812. if ( _mw_adminimize_exclude_super_admin() ) {
  813. return NULL;
  814. }
  815. $user_roles = _mw_adminimize_get_all_user_roles();
  816. $_mw_adminimize_admin_head = '';
  817. // remove_action( 'admin_head', 'index_js' );
  818. foreach ( $user_roles as $role ) {
  819. $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value(
  820. 'mw_adminimize_disabled_global_option_' . $role . '_items'
  821. );
  822. }
  823. foreach ( $user_roles as $role ) {
  824. if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) {
  825. $disabled_global_option_[ $role ][ '0' ] = '';
  826. }
  827. }
  828. $global_options = '';
  829. // new 1.7.8
  830. foreach ( $user_roles as $role ) {
  831. $user = wp_get_current_user();
  832. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  833. if ( current_user_can( $role )
  834. && isset( $disabled_global_option_[ $role ] )
  835. && is_array( $disabled_global_option_[ $role ] )
  836. ) {
  837. $global_options = implode( ', ', $disabled_global_option_[ $role ] );
  838. }
  839. }
  840. }
  841. if ( isset( $global_options ) && 0 != strpos( $global_options, '#your-profile .form-table fieldset' ) ) {
  842. $_wp_admin_css_colors = 0;
  843. }
  844. $_mw_adminimize_admin_head .= '<!-- global options -->' . "\n";
  845. $_mw_adminimize_admin_head .= '<style type="text/css">' . $global_options . ' {display: none !important;}</style>' . "\n";
  846. if ( ! empty( $global_options ) ) {
  847. echo $_mw_adminimize_admin_head;
  848. }
  849. }
  850. /**
  851. * set metabox options from database an area post
  852. */
  853. function _mw_adminimize_set_metabox_post_option() {
  854. // exclude super admin
  855. if ( _mw_adminimize_exclude_super_admin() ) {
  856. return NULL;
  857. }
  858. $user_roles = _mw_adminimize_get_all_user_roles();
  859. $_mw_adminimize_admin_head = '';
  860. $metaboxes = '';
  861. foreach ( $user_roles as $role ) {
  862. $disabled_metaboxes_post_[ $role ] = _mw_adminimize_get_option_value(
  863. 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items'
  864. );
  865. if ( ! isset( $disabled_metaboxes_post_[ $role ][ '0' ] ) ) {
  866. $disabled_metaboxes_post_[ $role ][ '0' ] = '';
  867. }
  868. // new 1.7.8
  869. $user = wp_get_current_user();
  870. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  871. if ( current_user_can( $role ) && isset( $disabled_metaboxes_post_[ $role ] )
  872. && is_array(
  873. $disabled_metaboxes_post_[ $role ]
  874. )
  875. ) {
  876. $metaboxes = implode( ',', $disabled_metaboxes_post_[ $role ] );
  877. }
  878. }
  879. }
  880. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  881. $metaboxes . ' {display: none !important;}</style>' . "\n";
  882. if ( ! empty( $metaboxes ) ) {
  883. echo $_mw_adminimize_admin_head;
  884. }
  885. }
  886. /**
  887. * set metabox options from database an area page
  888. */
  889. function _mw_adminimize_set_metabox_page_option() {
  890. // exclude super admin
  891. if ( _mw_adminimize_exclude_super_admin() ) {
  892. return NULL;
  893. }
  894. $user_roles = _mw_adminimize_get_all_user_roles();
  895. $_mw_adminimize_admin_head = '';
  896. $metaboxes = '';
  897. foreach ( $user_roles as $role ) {
  898. $disabled_metaboxes_page_[ $role ] = _mw_adminimize_get_option_value(
  899. 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items'
  900. );
  901. if ( ! isset( $disabled_metaboxes_page_[ $role ][ '0' ] ) ) {
  902. $disabled_metaboxes_page_[ $role ][ '0' ] = '';
  903. }
  904. // new 1.7.8
  905. $user = wp_get_current_user();
  906. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  907. if ( current_user_can( $role )
  908. && isset( $disabled_metaboxes_page_[ $role ] )
  909. && is_array( $disabled_metaboxes_page_[ $role ] )
  910. ) {
  911. $metaboxes = implode( ',', $disabled_metaboxes_page_[ $role ] );
  912. }
  913. }
  914. }
  915. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  916. $metaboxes . ' {display: none !important;}</style>' . "\n";
  917. if ( ! empty( $metaboxes ) ) {
  918. echo $_mw_adminimize_admin_head;
  919. }
  920. }
  921. /**
  922. * set metabox options from database an area post
  923. */
  924. function _mw_adminimize_set_metabox_cp_option() {
  925. // exclude super admin
  926. if ( _mw_adminimize_exclude_super_admin() ) {
  927. return NULL;
  928. }
  929. if ( isset( $_GET[ 'post' ] ) ) {
  930. $post_id = (int) $_GET[ 'post' ];
  931. } elseif ( isset( $_POST[ 'post_ID' ] ) ) {
  932. $post_id = (int) $_POST[ 'post_ID' ];
  933. } else {
  934. $post_id = 0;
  935. }
  936. $current_post_type = $GLOBALS[ 'post_type' ];
  937. if ( ! isset( $current_post_type ) ) {
  938. $current_post_type = get_post_type( $post_id );
  939. }
  940. if ( ! isset( $current_post_type ) || ! $current_post_type ) {
  941. $current_post_type = str_replace( 'post_type=', '', esc_attr( $_SERVER[ 'QUERY_STRING' ] ) );
  942. }
  943. // set hard to post
  944. if ( ! $current_post_type ) {
  945. $current_post_type = 'post';
  946. }
  947. $user_roles = _mw_adminimize_get_all_user_roles();
  948. $_mw_adminimize_admin_head = '';
  949. $metaboxes = '';
  950. foreach ( $user_roles as $role ) {
  951. $disabled_metaboxes_[ $current_post_type . '_' . $role ] = _mw_adminimize_get_option_value(
  952. 'mw_adminimize_disabled_metaboxes_' . $current_post_type . '_' . $role . '_items'
  953. );
  954. if ( ! isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] ) ) {
  955. $disabled_metaboxes_[ $current_post_type . '_' . $role ][ '0' ] = '';
  956. }
  957. $user = wp_get_current_user();
  958. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  959. if ( current_user_can( $role )
  960. && isset( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
  961. && is_array( $disabled_metaboxes_[ $current_post_type . '_' . $role ] )
  962. ) {
  963. $metaboxes = implode( ',', $disabled_metaboxes_[ $current_post_type . '_' . $role ] );
  964. }
  965. }
  966. }
  967. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  968. $metaboxes . ' {display: none !important;}</style>' . "\n";
  969. if ( ! empty( $metaboxes ) ) {
  970. echo $_mw_adminimize_admin_head;
  971. }
  972. }
  973. /**
  974. * set link options in area Links of Backend
  975. */
  976. function _mw_adminimize_set_link_option() {
  977. // exclude super admin
  978. if ( _mw_adminimize_exclude_super_admin() ) {
  979. return NULL;
  980. }
  981. $user_roles = _mw_adminimize_get_all_user_roles();
  982. $_mw_adminimize_admin_head = '';
  983. // remove_action( 'admin_head', 'index_js' );
  984. foreach ( $user_roles as $role ) {
  985. $disabled_link_option_[ $role ] = _mw_adminimize_get_option_value(
  986. 'mw_adminimize_disabled_link_option_' . $role . '_items'
  987. );
  988. }
  989. foreach ( $user_roles as $role ) {
  990. if ( ! isset( $disabled_link_option_[ $role ][ '0' ] ) ) {
  991. $disabled_link_option_[ $role ][ '0' ] = '';
  992. }
  993. }
  994. $link_options = '';
  995. // new 1.7.8
  996. foreach ( $user_roles as $role ) {
  997. $user = wp_get_current_user();
  998. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  999. if ( current_user_can( $role )
  1000. && isset( $disabled_link_option_[ $role ] )
  1001. && is_array( $disabled_link_option_[ $role ] )
  1002. ) {
  1003. $link_options = implode( ',', $disabled_link_option_[ $role ] );
  1004. }
  1005. }
  1006. }
  1007. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  1008. $link_options . ' {display: none !important;}</style>' . "\n";
  1009. if ( ! empty( $link_options ) ) {
  1010. echo $_mw_adminimize_admin_head;
  1011. }
  1012. }
  1013. /**
  1014. * remove objects on wp nav menu
  1015. */
  1016. function _mw_adminimize_set_nav_menu_option() {
  1017. // exclude super admin
  1018. if ( _mw_adminimize_exclude_super_admin() ) {
  1019. return NULL;
  1020. }
  1021. $user_roles = _mw_adminimize_get_all_user_roles();
  1022. $_mw_adminimize_admin_head = '';
  1023. // remove_action( 'admin_head', 'index_js' );
  1024. foreach ( $user_roles as $role ) {
  1025. $disabled_nav_menu_option_[ $role ] = _mw_adminimize_get_option_value(
  1026. 'mw_adminimize_disabled_nav_menu_option_' . $role . '_items'
  1027. );
  1028. }
  1029. foreach ( $user_roles as $role ) {
  1030. if ( ! isset( $disabled_nav_menu_option_[ $role ][ '0' ] ) ) {
  1031. $disabled_nav_menu_option_[ $role ][ '0' ] = '';
  1032. }
  1033. }
  1034. $nav_menu_options = '';
  1035. // new 1.7.8
  1036. foreach ( $user_roles as $role ) {
  1037. $user = wp_get_current_user();
  1038. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  1039. if ( current_user_can( $role )
  1040. && isset( $disabled_nav_menu_option_[ $role ] )
  1041. && is_array( $disabled_nav_menu_option_[ $role ] )
  1042. ) {
  1043. $nav_menu_options = implode( ',', $disabled_nav_menu_option_[ $role ] );
  1044. }
  1045. }
  1046. }
  1047. //remove_meta_box( $id, 'nav-menus', 'side' );
  1048. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  1049. $nav_menu_options . ' {display: none !important;}</style>' . "\n";
  1050. if ( $nav_menu_options ) {
  1051. echo $_mw_adminimize_admin_head;
  1052. }
  1053. }
  1054. /**
  1055. * Remove areas in Widget Settings
  1056. */
  1057. function _mw_adminimize_set_widget_option() {
  1058. // exclude super admin
  1059. if ( _mw_adminimize_exclude_super_admin() ) {
  1060. return NULL;
  1061. }
  1062. $user_roles = _mw_adminimize_get_all_user_roles();
  1063. $_mw_adminimize_admin_head = '';
  1064. foreach ( $user_roles as $role ) {
  1065. $disabled_widget_option_[ $role ] = _mw_adminimize_get_option_value(
  1066. 'mw_adminimize_disabled_widget_option_' . $role . '_items'
  1067. );
  1068. }
  1069. foreach ( $user_roles as $role ) {
  1070. if ( ! isset( $disabled_widget_option_[ $role ][ '0' ] ) ) {
  1071. $disabled_widget_option_[ $role ][ '0' ] = '';
  1072. }
  1073. }
  1074. $widget_options = '';
  1075. // new 1.7.8
  1076. foreach ( $user_roles as $role ) {
  1077. $user = wp_get_current_user();
  1078. if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
  1079. if ( current_user_can( $role )
  1080. && isset( $disabled_widget_option_[ $role ] )
  1081. && is_array( $disabled_widget_option_[ $role ] )
  1082. ) {
  1083. $widget_options = implode( ',', $disabled_widget_option_[ $role ] );
  1084. }
  1085. }
  1086. }
  1087. //remove_meta_box( $id, 'nav-menus', 'side' );
  1088. $_mw_adminimize_admin_head .= '<style type="text/css">' .
  1089. $widget_options . ' {display: none !important;}</style>' . "\n";
  1090. if ( $widget_options ) {
  1091. echo $_mw_adminimize_admin_head;
  1092. }
  1093. }
  1094. /**
  1095. * small user-info
  1096. */
  1097. function _mw_adminimize_small_user_info() {
  1098. ?>
  1099. <div id="small_user_info">
  1100. <p>
  1101. <a href="<?php echo wp_nonce_url(
  1102. site_url( 'wp-login.php?action=logout' ),
  1103. 'log-out'
  1104. ) ?>"
  1105. title="<?php _e( 'Log Out' ) ?>"><?php _e( 'Log Out' ); ?></a>
  1106. </p>
  1107. </div>
  1108. <?php
  1109. }
  1110. /**
  1111. * include options-page in wp-admin
  1112. */
  1113. // include helping functions
  1114. require_once( 'inc-setup/helping_hands.php' );
  1115. // inc. settings page
  1116. require_once( 'adminimize_page.php' );
  1117. // @ToDO release XML Ex-Import
  1118. //require_once( 'inc-options/class-eximport.php' );
  1119. // dashboard options
  1120. require_once( 'inc-setup/dashboard.php' );
  1121. // widget options
  1122. require_once( 'inc-setup/widget.php' );
  1123. require_once( 'inc-setup/admin-footer.php' );
  1124. // global settings
  1125. //require_once( 'inc-options/settings_notice.php' );
  1126. // remove admin bar
  1127. require_once( 'inc-setup/remove-admin-bar.php' );
  1128. // admin bar helper, setup
  1129. // work always in frontend
  1130. require_once( 'inc-setup/admin-bar-items.php' );
  1131. // meta boxes helper, setup
  1132. //require_once( 'inc-setup/meta-boxes.php' );
  1133. /**
  1134. * @version WP 2.8
  1135. * Add action link(s) to plugins page
  1136. *
  1137. * @param $links , $file
  1138. *
  1139. * @param $file
  1140. *
  1141. * @return $links
  1142. */
  1143. function _mw_adminimize_filter_plugin_meta( $links, $file ) {
  1144. /* create link */
  1145. if ( FB_ADMINIMIZE_BASENAME == $file ) {
  1146. array_unshift(
  1147. $links,
  1148. sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_ADMINIMIZE_BASENAME, __( 'Settings' ) )
  1149. );
  1150. }
  1151. return $links;
  1152. }
  1153. /**
  1154. * settings in plugin-admin-page
  1155. */
  1156. function _mw_adminimize_add_settings_page() {
  1157. /*
  1158. * Maybe later
  1159. if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
  1160. $pagehook = add_submenu_page(
  1161. 'settings.php',
  1162. __( 'Adminimize Network Options', FB_ADMINIMIZE_TEXTDOMAIN ),
  1163. __( 'Adminimize', FB_ADMINIMIZE_TEXTDOMAIN ),
  1164. 'manage_options',
  1165. plugin_basename( __FILE__ ),
  1166. '_mw_adminimize_options'
  1167. );
  1168. }
  1169. */
  1170. $pagehook = add_options_page(
  1171. __( 'Adminimize Options', FB_ADMINIMIZE_TEXTDOMAIN ),
  1172. __( 'Adminimize', FB_ADMINIMIZE_TEXTDOMAIN ),
  1173. 'manage_options',
  1174. __FILE__,
  1175. '_mw_adminimize_options'
  1176. );
  1177. if ( ! is_network_admin() ) {
  1178. add_filter( 'plugin_action_links', '_mw_adminimize_filter_plugin_meta', 10, 2 );
  1179. }
  1180. add_action( 'load-' . $pagehook, '_mw_adminimize_on_load_page' );
  1181. }
  1182. function _mw_adminimize_on_load_page() {
  1183. wp_register_style( 'adminimize-style', plugins_url( 'css/style.css', __FILE__ ) );
  1184. wp_enqueue_style( 'adminimize-style' );
  1185. wp_register_script(
  1186. 'adminimize-settings-script',
  1187. plugins_url( 'js/adminimize.js', __FILE__ ),
  1188. array( 'jquery' ),
  1189. '05/02/2013',
  1190. TRUE
  1191. );
  1192. wp_enqueue_script( 'adminimize-settings-script' );
  1193. }
  1194. /**
  1195. * Set theme for users
  1196. * Kill with version 1.7.18
  1197. */
  1198. function _mw_adminimize_set_theme() {
  1199. if ( ! current_user_can( 'edit_users' ) ) {
  1200. wp_die( __( 'Cheatin&#8217; uh?' ) );
  1201. }
  1202. $user_ids = $_POST[ 'mw_adminimize_theme_items' ];
  1203. $admin_color = htmlspecialchars( stripslashes( $_POST[ '_mw_adminimize_set_theme' ] ) );
  1204. if ( ! $user_ids ) {
  1205. return FALSE;
  1206. }
  1207. foreach ( $user_ids as $user_id ) {
  1208. update_user_meta( $user_id, 'admin_color', $admin_color );
  1209. }
  1210. return TRUE;
  1211. }
  1212. /**
  1213. * read options
  1214. *
  1215. * @param $key
  1216. *
  1217. * @return null
  1218. */
  1219. function _mw_adminimize_get_option_value( $key ) {
  1220. // check for use on multisite
  1221. if ( is_multisite() && is_plugin_active_for_network( MW_ADMIN_FILE ) ) {
  1222. $adminimizeoptions = get_site_option( 'mw_adminimize' );
  1223. } else {
  1224. $adminimizeoptions = get_option( 'mw_adminimize' );
  1225. }
  1226. return ( isset( $adminimizeoptions[ $key ] ) ) ?
  1227. ( $adminimizeoptions[ $key ] ) : NULL;
  1228. }
  1229. /**
  1230. * Update options in database
  1231. */
  1232. function _mw_adminimize_update() {
  1233. $user_roles = _mw_adminimize_get_all_user_roles();
  1234. $args = array( 'public' => TRUE, '_builtin' => FALSE );
  1235. $post_types = get_post_types( $args );
  1236. $adminimizeoptions[ 'mw_adminimize_admin_bar_nodes' ] = _mw_adminimize_get_option_value(
  1237. 'mw_adminimize_admin_bar_nodes'
  1238. );
  1239. // admin bar options
  1240. foreach ( $user_roles as $role ) {
  1241. // admin abr options
  1242. if ( isset( $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] ) ) {
  1243. $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ];
  1244. } else {
  1245. $adminimizeoptions[ 'mw_adminimize_disabled_admin_bar_' . $role . '_items' ] = array();
  1246. }
  1247. }
  1248. if ( isset( $_POST[ '_mw_adminimize_user_info' ] ) ) {
  1249. $adminimizeoptions[ '_mw_adminimize_user_info' ] = strip_tags(
  1250. stripslashes( $_POST[ '_mw_adminimize_user_info' ] )
  1251. );
  1252. } else {
  1253. $adminimizeoptions[ '_mw_adminimize_user_info' ] = 0;
  1254. }
  1255. if ( isset( $_POST[ '_mw_adminimize_dashmenu' ] ) ) {
  1256. $adminimizeoptions[ '_mw_adminimize_dashmenu' ] = strip_tags(
  1257. stripslashes( $_POST[ '_mw_adminimize_dashmenu' ] )
  1258. );
  1259. } else {
  1260. $adminimizeoptions[ '_mw_adminimize_dashmenu' ] = 0;
  1261. }
  1262. if ( isset( $_POST[ '_mw_adminimize_footer' ] ) ) {
  1263. $adminimizeoptions[ '_mw_adminimize_footer' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_footer' ] ) );
  1264. } else {
  1265. $adminimizeoptions[ '_mw_adminimize_footer' ] = 0;
  1266. }
  1267. if ( isset( $_POST[ '_mw_adminimize_header' ] ) ) {
  1268. $adminimizeoptions[ '_mw_adminimize_header' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_header' ] ) );
  1269. } else {
  1270. $adminimizeoptions[ '_mw_adminimize_header' ] = 0;
  1271. }
  1272. if ( isset( $_POST[ '_mw_adminimize_exclude_super_admin' ] ) ) {
  1273. $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = strip_tags(
  1274. stripslashes( $_POST[ '_mw_adminimize_exclude_super_admin' ] )
  1275. );
  1276. } else {
  1277. $adminimizeoptions[ '_mw_adminimize_exclude_super_admin' ] = 0;
  1278. }
  1279. if ( isset( $_POST[ '_mw_adminimize_tb_window' ] ) ) {
  1280. $adminimizeoptions[ '_mw_adminimize_tb_window' ] = strip_tags(
  1281. stripslashes( $_POST[ '_mw_adminimize_tb_window' ] )
  1282. );
  1283. } else {
  1284. $adminimizeoptions[ '_mw_adminimize_tb_window' ] = 0;
  1285. }
  1286. if ( isset( $_POST[ '_mw_adminimize_cat_full' ] ) ) {
  1287. $adminimizeoptions[ '_mw_adminimize_cat_full' ] = strip_tags(
  1288. stripslashes( $_POST[ '_mw_adminimize_cat_full' ] )
  1289. );
  1290. } else {
  1291. $adminimizeoptions[ '_mw_adminimize_cat_full' ] = 0;
  1292. }
  1293. if ( isset( $_POST[ '_mw_adminimize_db_redirect' ] ) ) {
  1294. $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = strip_tags(
  1295. stripslashes( $_POST[ '_mw_adminimize_db_redirect' ] )
  1296. );
  1297. } else {
  1298. $adminimizeoptions[ '_mw_adminimize_db_redirect' ] = 0;
  1299. }
  1300. if ( isset( $_POST[ '_mw_adminimize_ui_redirect' ] ) ) {
  1301. $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = strip_tags(
  1302. stripslashes( $_POST[ '_mw_adminimize_ui_redirect' ] )
  1303. );
  1304. } else {
  1305. $adminimizeoptions[ '_mw_adminimize_ui_redirect' ] = 0;
  1306. }
  1307. if ( isset( $_POST[ '_mw_adminimize_advice' ] ) ) {
  1308. $adminimizeoptions[ '_mw_adminimize_advice' ] = strip_tags( stripslashes( $_POST[ '_mw_adminimize_advice' ] ) );
  1309. } else {
  1310. $adminimizeoptions[ '_mw_adminimize_advice' ] = 0;
  1311. }
  1312. if ( isset( $_POST[ '_mw_adminimize_advice_txt' ] ) ) {
  1313. $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = stripslashes( $_POST[ '_mw_adminimize_advice_txt' ] );
  1314. } else {
  1315. $adminimizeoptions[ '_mw_adminimize_advice_txt' ] = 0;
  1316. }
  1317. if ( isset( $_POST[ '_mw_adminimize_timestamp' ] ) ) {
  1318. $adminimizeoptions[ '_mw_adminimize_timestamp' ] = strip_tags(
  1319. stripslashes( $_POST[ '_mw_adminimize_timestamp' ] )
  1320. );
  1321. } else {
  1322. $adminimizeoptions[ '_mw_adminimize_timestamp' ] = 0;
  1323. }
  1324. if ( isset( $_POST[ '_mw_adminimize_control_flashloader' ] ) ) {
  1325. $adminimizeoptions[ '_mw_adminimize_control_flashloader' ] = strip_tags(
  1326. stripslashes( $_POST[ '_mw_adminimize_control_flashloader' ] )
  1327. );
  1328. } else {
  1329. $adminimizeoptions[ '_mw_adminimize_control_flashloader' ] = 0;
  1330. }
  1331. if ( isset( $_POST[ '_mw_adminimize_db_redirect_txt' ] ) ) {
  1332. $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = stripslashes(
  1333. $_POST[ '_mw_adminimize_db_redirect_txt' ]
  1334. );
  1335. } else {
  1336. $adminimizeoptions[ '_mw_adminimize_db_redirect_txt' ] = 0;
  1337. }
  1338. // menu update
  1339. foreach ( $user_roles as $role ) {
  1340. if ( isset( $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] ) ) {
  1341. $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_menu_' . $role . '_items' ];
  1342. } else {
  1343. $adminimizeoptions[ 'mw_adminimize_disabled_menu_' . $role . '_items' ] = array();
  1344. }
  1345. if ( isset( $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] ) ) {
  1346. $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ];
  1347. } else {
  1348. $adminimizeoptions[ 'mw_adminimize_disabled_submenu_' . $role . '_items' ] = array();
  1349. }
  1350. }
  1351. // global_options, metaboxes update
  1352. foreach ( $user_roles as $role ) {
  1353. // global options
  1354. if ( isset( $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] ) ) {
  1355. $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ];
  1356. } else {
  1357. $adminimizeoptions[ 'mw_adminimize_disabled_global_option_' . $role . '_items' ] = array();
  1358. }
  1359. if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] ) ) {
  1360. $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ];
  1361. } else {
  1362. $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_post_' . $role . '_items' ] = array();
  1363. }
  1364. if ( isset( $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] ) ) {
  1365. $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = $_POST[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ];
  1366. } else {
  1367. $adminimizeoptions[ 'mw_adminimize_disabled_metaboxes_page_' . $role . '_items' ] = array();
  1368. }

Large files files are truncated, but you can click here to view the full file