Plugin Directory

Changeset 968313


Ignore:
Timestamp:
08/19/2014 01:48:08 PM (11 years ago)
Author:
arenddeboer
Message:

Extra options to hide: plugins, appearance, dashboard, general code updates

Location:
clean-admin-ui/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • clean-admin-ui/trunk/clean-admin-ui.php

    r756063 r968313  
    11<?php
    22/*
    3     Plugin Name: Clean Admin UI
    4     Plugin URI: http://www.arenddeboer.com/clean-admin-ui-a-new-wordpress-plugin-to-remove-admin-menu-items/
    5     Version: 1.2
    6     Description: Configure and remove admin menu items like posts, pages, comments
    7     Author: Arend de Boer
    8     Author URI: http://www.arenddeboer.com/clean-admin-ui-a-new-wordpress-plugin-to-remove-admin-menu-items/
    9 
    10     Copyright 2011  Arend de Boer  (email : [email protected])
    11 
    12     This program is free software; you can redistribute it and/or modify
    13     it under the terms of the GNU General Public License as published by
    14     the Free Software Foundation; either version 2 of the License, or
    15     (at your option) any later version.
    16 
    17     This program is distributed in the hope that it will be useful,
    18     but WITHOUT ANY WARRANTY; without even the implied warranty of
    19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20     GNU General Public License for more details.
    21 
    22     You should have received a copy of the GNU General Public License
    23     along with this program; if not, write to the Free Software
    24     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     3Plugin Name: Clean Admin UI
     4Plugin URI: http://www.arenddeboer.com/clean-admin-ui-a-new-wordpress-plugin-to-remove-admin-menu-items/
     5Version: 1.3
     6Description: Configure and remove admin menu items like posts, pages, comments
     7Author: Arend de Boer
     8Author URI: http://www.arenddeboer.com/clean-admin-ui-a-new-wordpress-plugin-to-remove-admin-menu-items/
     9
     10Copyright 2011  Arend de Boer  (email : [email protected])
     11
     12This program is free software; you can redistribute it and/or modify
     13it under the terms of the GNU General Public License as published by
     14the Free Software Foundation; either version 2 of the License, or
     15(at your option) any later version.
     16
     17This program is distributed in the hope that it will be useful,
     18but WITHOUT ANY WARRANTY; without even the implied warranty of
     19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20GNU General Public License for more details.
     21
     22You should have received a copy of the GNU General Public License
     23along with this program; if not, write to the Free Software
     24Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2525*/
    2626
     
    2929===============================================================================
    3030
    31    set default options when plugin is activated, remove options when deactivated
     31set default options when plugin is activated, remove options when deactivated
    3232
    3333===============================================================================
     
    3636global $CAUdefaults;
    3737$CAUdefaults = array(
    38                         'show_menu_posts'=>'1',
    39                         'show_menu_media'=>'1',
    40                         'show_menu_page_links'=>'1',
    41                         'show_menu_pages'=>'1',
    42                         'show_menu_comments'=>'1',
    43                         'show_menu_users'=>'1',
    44                         'show_menu_tools'=>'1');
     38    'show_menu_posts'=>'1',
     39    'show_menu_media'=>'1',
     40    'show_menu_page_links'=>'1',
     41    'show_menu_pages'=>'1',
     42    'show_menu_comments'=>'1',
     43    'show_menu_users'=>'1',
     44    'show_menu_plugins'=>'1',
     45    'show_menu_themes'=>'1',
     46    'show_menu_tools'=>'1',
     47    'show_menu_dashboard'=>'1',
     48    'db_version'=>'1.1');
    4549
    4650register_activation_hook( __FILE__, 'onCAUActivation' );
    4751register_deactivation_hook( __FILE__, 'onCAUDeactivation' );
    4852
     53/***
     54* Generate the menu options to hide from the database
     55*
     56*/
    4957function onCAUActivation() {
    5058    global $CAUdefaults;
     
    5260
    5361}
     62/***
     63* Remove options from the database
     64*
     65*/
    5466function onCAUDeactivation() { delete_option('CAUoptions'); }
    5567
     
    5769===============================================================================
    5870
    59    insert styles into <head>
    60 
    61 ===============================================================================
    62 */
    63 
     71insert styles into <head>
     72
     73===============================================================================
     74*/
     75/***
     76* Request stored options from db
     77*
     78* @var mixed
     79*/
    6480$CAUoptions = get_option('CAUoptions');
    6581
     
    6783===============================================================================
    6884
    69    Clean Admin UI settings
    70 
    71 ===============================================================================
    72 */
    73 
     85Clean Admin UI settings
     86
     87===============================================================================
     88*/
     89/***
     90* Register for add_action hook
     91*/
    7492add_action('admin_menu', 'clean_admin_ui_init', 1);
    7593
    76 
     94/***
     95* Add this plugin to the menu
     96*
     97*/
    7798function clean_admin_ui_init() {
    7899    add_options_page('Clean Admin UI', 'Clean Admin UI', 'activate_plugins', 'clean-admin-ui', 'CAUoptions');
    79    
     100
    80101    clean_admin_ui_do_clean();
    81102}
    82103
     104/***
     105* Actual cleanup function which removes the selected menu items
     106*
     107*/
    83108function clean_admin_ui_do_clean() {
    84    
     109
    85110    global $menu;
    86    
     111
    87112    $wp_version = explode('.', get_bloginfo('version'));
    88113    if($wp_version[0] >= 3 && $wp_version[1] >= 1 ) {
     
    91116        $legacy = true;
    92117    }
    93     //DebugBreak();
     118
    94119    $CAUoptions = get_option('CAUoptions');
     120
    95121    foreach ($CAUoptions as $key => $value) {
    96122        switch ($key) {
    97123            case "show_menu_posts":
    98124                if(!$value && !$legacy) {
     125
    99126                    remove_menu_page('edit.php');
    100127                } elseif(!$value && $legacy) {
     
    144171                }
    145172                break;
    146         }
    147     }
    148 }
    149 
     173            case "show_menu_themes":
     174                if(!$value && !$legacy) {
     175                    remove_menu_page('themes.php');   
     176                }
     177                break;
     178            case "show_menu_plugins":
     179                if(!$value && !$legacy) {
     180                    remove_menu_page('plugins.php');   
     181                }
     182                break;
     183            case "show_menu_dashboard":
     184                if(!$value && !$legacy) {
     185                    remove_the_dashboard();
     186                }
     187                break;
     188        }
     189    }
     190}
     191
     192/***
     193* Generate a refresh link
     194*
     195*/
    150196function curPageURL() {
    151  $pageURL = 'http';
    152  if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    153  $pageURL .= "://";
    154  if ($_SERVER["SERVER_PORT"] != "80") {
    155   $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    156  } else {
    157   $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    158  }
    159  return $pageURL;
    160 }
    161 
     197    $pageURL = 'http';
     198    if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     199    $pageURL .= "://";
     200    if ($_SERVER["SERVER_PORT"] != "80") {
     201        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     202    } else {
     203        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     204    }
     205    return $pageURL;
     206}
     207
     208// borrowed from http://bavotasan.com/2008/hiding-the-wordpress-dashboard-for-non-admin-users/ original code by  Austin Matzko
     209// Modified by c.bavota of http://bavotasan.com for WordPress 2.7 and to allow the dashboard for Admins.
     210function remove_the_dashboard () {
     211    if (current_user_can('level_10') && false) {
     212        //return; apply to all
     213    } else {
     214
     215        global $menu, $submenu, $user_ID;
     216        $the_user = new WP_User($user_ID);
     217        reset($menu); $page = key($menu);
     218        while ((__('Dashboard') != $menu[$page][0]) && next($menu))
     219            $page = key($menu);
     220        if (__('Dashboard') == $menu[$page][0]) unset($menu[$page]);
     221        reset($menu); $page = key($menu);
     222        while (!$the_user->has_cap($menu[$page][1]) && next($menu))
     223            $page = key($menu);
     224        if (preg_match('#wp-admin/?(index.php)?$#',$_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]))
     225            wp_redirect(get_option('siteurl') . '/wp-admin/post-new.php');
     226    }
     227}
     228/***
     229* Create and update the CAUoptions object based on POST condition
     230*
     231*/
    162232function CAUoptions() { ?>
    163233
    164234    <?php
     235    $message = "";
    165236    global $CAUdefaults;
    166     if ($_POST['submit']) {
    167         $_POST['content'] = stripslashes($_POST['content']);
     237    if (isset($_POST['submit'])) {
     238        if(isset($_POST['content'])) {
     239            $_POST['content'] = stripslashes($_POST['content']);
     240        }
     241
    168242        $CAUoptions = array();
    169243        foreach ($CAUdefaults as $name => $value) {
    170             $CAUoptions[$name] = $_POST[$name];
    171         }
    172 
    173        
     244            if(isset($_POST[$name])) {
     245                $CAUoptions[$name] = $_POST[$name];
     246            } else {
     247                $CAUoptions[$name] = "";
     248            }
     249        }
     250
     251
    174252        update_option('CAUoptions', $CAUoptions);
    175253        $message = '<div id="message" class="updated"><p>Clean Admin UI settings updated.</p>
     
    179257    } else {
    180258        $CAUoptions = get_option('CAUoptions');
     259        if(!isset($CAUoptions['show_menu_plugins']) && !isset($CAUoptions['show_menu_themes']) && !isset($CAUoptions['db_version']) ) {
     260            // new options since 1.3
     261            update_option('CAUoptions', array_merge($CAUoptions, array('show_menu_plugins' => '1', 'show_menu_themes' => '1', 'db_version', '1.1', 'show_menu_dashboard' => '1')));
     262            $CAUoptions = get_option('CAUoptions');
     263        }
    181264    }
    182265    ?>
    183266
    184267    <style type="text/css">
    185     .formField {
    186         width: 60%;
    187         padding: 5px 0px 10px 0px;
    188     }
    189     .form-table input[type="text"], .form-table textarea {
    190         width: 50%;
    191     }
    192     .form-table th {
    193         width: 150px;
    194     }
    195     #CAUcss {
    196         display: block;
    197         margin-top: 8px;
    198         width: 93%;
    199     }
     268        .formField {
     269            width: 60%;
     270            padding: 5px 0px 10px 0px;
     271        }
     272        .form-table input[type="text"], .form-table textarea {
     273            width: 50%;
     274        }
     275        .form-table th {
     276            width: 150px;
     277        }
     278        #CAUcss {
     279            display: block;
     280            margin-top: 8px;
     281            width: 93%;
     282        }
    200283    </style>
    201284
    202285    <div class="wrap">
    203    
     286
    204287        <a href="http://www.arenddeboer.com/clean-admin-ui-a-new-wordpress-plugin-to-remove-admin-menu-items/" target="_blank"></a><h2>Clean Admin UI</h2>
    205288        <?php print $message; ?>
     
    209292        <form action="" method="post">
    210293
    211         <table class="form-table">
    212            
    213             <tr>
    214             <th scope="row" colspan="2" class="th-full">
    215             <label for="show_menu_posts"><input type="checkbox" name="show_menu_posts" <?php if ($CAUoptions['show_menu_posts']) {print 'checked="checked" ';} ?>/> Show <strong>Posts</strong> menu entry.</label>
    216             </th>
    217             </tr>
    218            
    219             <tr>
    220             <th scope="row" colspan="2" class="th-full">
    221             <label for="show_menu_media"><input type="checkbox" name="show_menu_media" <?php if ($CAUoptions['show_menu_media']) {print 'checked="checked" ';} ?>/> Show <strong>Media</strong> menu entry.</label>
    222             </th>
    223             </tr>
    224            
    225             <tr>
    226             <th scope="row" colspan="2" class="th-full">
    227             <label for="show_menu_page_links"><input type="checkbox" name="show_menu_page_links" <?php if ($CAUoptions['show_menu_page_links']) {print 'checked="checked" ';} ?>/> Show <strong>Page Links</strong> menu entry.</label>
    228             </th>
    229             </tr>
    230            
    231             <tr>
    232             <th scope="row" colspan="2" class="th-full">
    233             <label for="show_menu_pages"><input type="checkbox" name="show_menu_pages" <?php if ($CAUoptions['show_menu_pages']) {print 'checked="checked" ';} ?>/> Show <strong>Pages</strong> menu entry.</label>
    234             </th>
    235             </tr>
    236            
    237             <tr>
    238             <th scope="row" colspan="2" class="th-full">
    239             <label for="show_menu_comments"><input type="checkbox" name="show_menu_comments" <?php if ($CAUoptions['show_menu_comments']) {print 'checked="checked" ';} ?>/> Show <strong>Comments</strong> menu entry.</label>
    240             </th>
    241             </tr>
    242 
    243             <tr>
    244             <th scope="row" colspan="2" class="th-full">
    245             <label for="show_menu_users"><input type="checkbox" name="show_menu_users" <?php if ($CAUoptions['show_menu_users']) {print 'checked="checked" ';} ?>/> Show <strong>Users</strong> menu entry.</label>
    246             </th>
    247             </tr>
    248            
    249             <tr>
    250             <th scope="row" colspan="2" class="th-full">
    251             <label for="show_menu_tools"><input type="checkbox" name="show_menu_tools" <?php if ($CAUoptions['show_menu_tools']) {print 'checked="checked" ';} ?>/> Show <strong>Tools</strong> menu entry.</label>
    252             </th>
    253             </tr>
    254            
    255         </table><!-- form-table -->
    256        
    257         <p class="submit"><input type="submit" class="button-primary" name="submit" value="Save Changes" /></p>
    258        
     294            <table class="form-table">
     295
     296                <tr>
     297                    <th scope="row" colspan="2" class="th-full">
     298                        <label>
     299                            <input type="checkbox" name="show_menu_posts" <?php if ($CAUoptions['show_menu_posts']) {print 'checked="checked" ';} ?>/> Show <strong>Posts</strong> menu entry.
     300                        </label>
     301                    </th>
     302                </tr>
     303
     304                <tr>
     305                    <th scope="row" colspan="2" class="th-full">
     306                        <label>
     307                            <input type="checkbox" name="show_menu_media" <?php if ($CAUoptions['show_menu_media']) {print 'checked="checked" ';} ?>/> Show <strong>Media</strong> menu entry.
     308                        </label>
     309                    </th>
     310                </tr>
     311
     312                <tr>
     313                    <th scope="row" colspan="2" class="th-full">
     314                        <label>
     315                            <input type="checkbox" name="show_menu_page_links" <?php if ($CAUoptions['show_menu_page_links']) {print 'checked="checked" ';} ?>/> Show <strong>Page Links</strong> menu entry.
     316                        </label>
     317                    </th>
     318                </tr>
     319
     320                <tr>
     321                    <th scope="row" colspan="2" class="th-full">
     322                        <label>
     323                            <input type="checkbox" name="show_menu_pages" <?php if ($CAUoptions['show_menu_pages']) {print 'checked="checked" ';} ?>/> Show <strong>Pages</strong> menu entry.
     324                        </label>
     325                    </th>
     326                </tr>
     327
     328                <tr>
     329                    <th scope="row" colspan="2" class="th-full">
     330                        <label>
     331                            <input type="checkbox" name="show_menu_comments" <?php if ($CAUoptions['show_menu_comments']) {print 'checked="checked" ';} ?>/> Show <strong>Comments</strong> menu entry.
     332                        </label>
     333                    </th>
     334                </tr>
     335
     336                <tr>
     337                    <th scope="row" colspan="2" class="th-full">
     338                        <label>
     339                            <input type="checkbox" name="show_menu_users" <?php if ($CAUoptions['show_menu_users']) {print 'checked="checked" ';} ?>/> Show <strong>Users</strong> menu entry.
     340                        </label>
     341                    </th>
     342                </tr>
     343
     344                <tr>
     345                    <th scope="row" colspan="2" class="th-full">
     346                        <label>
     347                            <input type="checkbox" name="show_menu_tools" <?php if ($CAUoptions['show_menu_tools']) {print 'checked="checked" ';} ?>/> Show <strong>Tools</strong> menu entry.
     348                        </label>
     349                    </th>
     350                </tr>
     351
     352                <tr>
     353                    <th scope="row" colspan="2" class="th-full">
     354                        <label>
     355                            <input type="checkbox" name="show_menu_plugins" <?php if ($CAUoptions['show_menu_plugins']) {print 'checked="checked" ';} ?>/> Show <strong>Plugins</strong> menu entry.
     356                        </label>
     357                    </th>
     358                </tr>
     359
     360                <tr>
     361                    <th scope="row" colspan="2" class="th-full">
     362                        <label>
     363                            <input type="checkbox" name="show_menu_themes" <?php if ($CAUoptions['show_menu_themes']) {print 'checked="checked" ';} ?>/> Show <strong>Appearance</strong> menu entry.
     364                        </label>
     365                    </th>
     366                </tr>
     367                <tr>
     368                    <th scope="row" colspan="2" class="th-full">
     369                        <label>
     370                            <input type="checkbox" name="show_menu_dashboard" <?php if ($CAUoptions['show_menu_dashboard']) {print 'checked="checked" ';} ?>/> Show <strong>Dashboard</strong> menu entry.
     371                        </label>
     372                    </th>
     373                </tr>
     374
     375            </table><!-- form-table -->
     376
     377            <p class="submit"><input type="submit" class="button-primary" name="submit" value="Save Changes" /></p>
     378
    259379        </form>
    260380
    261381    </div><!-- wrap -->
    262382
    263 <?php }
     383    <?php }
    264384
    265385?>
  • clean-admin-ui/trunk/readme.txt

    r412052 r968313  
    22Tags: admin, menu, cms, ui
    33Requires at least: 2.8
    4 Tested up to: 3.2.1
     4Tested up to: 3.9.2
    55Stable tag: trunk
    66
    7 Remove menu elements from the admin menu
     7Easy Wordpress Menu, Remove menu items from the admin menu
    88
    99== Description ==
    1010Use this plugin to hide admin menu items like Posts, Comments, Users, etc
     11This makes it easier for your clients to navigate Wordpress, no distractions, leave only those options that are required.
    1112
    1213== Installation ==
    13141. Upload the `clean-admin-ui` directory to the `/wp-content/plugins/` directory.
    14 2. Activate `Clean Admin UI` through the 'Plugins' menu in WordPress.
     152. Activate `Clean Admin UI` through the 'Plugins' menu in WordPress end select which items to hide.
    1516
    1617== Changelog ==
     18= 1.3 =
     19* Added option to hide plugins, appearance end dashboard (for Wordpress 2.7 and higher)
     20* Database versioning
     21* Better update handling
     22* Updated to comply with Wordpress WP_DEBUG code guidance
    1723= 1.2 =
    1824* Removed bug where menu item Pages remained visible
Note: See TracChangeset for help on using the changeset viewer.