WordPress.org

Plugin Directory

Changeset 591619


Ignore:
Timestamp:
08/28/12 23:20:52 (20 months ago)
Author:
barrykooij
Message:

Fixed hiding plugin activation link bug.
Added a method that prevents users from trying to activate/deactivate plugins through direct URL entry.

Location:
admin-restriction/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • admin-restriction/trunk/ARHooks.php

    r590473 r591619  
    33{ 
    44   
    5   private static $objInstance = null; 
     5  private static $instance = null; 
    66   
    7   public static function getInstance() 
     7  public static function get_instance() 
    88  { 
    9     if(self::$objInstance==null) 
     9    if(self::$instance==null) 
    1010    { 
    11       self::$objInstance = new self(); 
     11      self::$instance = new self(); 
    1212    } 
    13     return self::$objInstance; 
     13    return self::$instance; 
    1414  } 
    1515 
     
    2424  } 
    2525   
    26   public function disallow_plugin_deactivation($actions) 
     26  public function hide_plugin_controls($actions) 
    2727  { 
    2828    global $current_user; 
    2929    get_currentuserinfo(); 
     30 
    3031    if($current_user->ID != 1) 
    3132    { 
    32       unset($actions['edit']); 
    33       unset($actions['deactivate']); 
     33      if(isset($actions['activate'])){unset($actions['activate']);} 
     34      if(isset($actions['edit'])){unset($actions['edit']);} 
     35      if(isset($actions['deactivate'])){unset($actions['deactivate']);} 
    3436    } 
    3537    return $actions; 
     38  } 
     39 
     40  public function catch_plugin_cap( $allcaps, $caps, $args ) 
     41  { 
     42    global $current_user, $action; 
     43    get_currentuserinfo(); 
     44    if($current_user->ID == 1){return $allcaps;} 
     45    if( isset($action) && ($action=='activate' || $action=='deactivate') ) 
     46    { 
     47      $allcaps['activate_plugins'] = 0; 
     48    } 
     49    return $allcaps; 
    3650  } 
    3751   
  • admin-restriction/trunk/admin-restriction.php

    r590473 r591619  
    44Plugin URI: http://www.cageworks.nl/admin-restriction 
    55Description: Disables updating the WordPress Core plus plugin and theme installation, updating and removal. 
    6 Version: 1.0 
     6Version: 1.1.0 
    77Author: Barry Kooij 
    88Author URI: http://www.barrykooij.nl/ 
     
    1111class AdminRestriction  
    1212{ 
    13   private function __construct(){} 
     13  public function __construct() 
     14  { 
     15    $this->setup(); 
     16  } 
    1417   
    1518  public static function setup() 
    1619  { 
    17     add_action('admin_menu', array(ARHooks::getInstance(), 'disallow_editor')); 
    18     add_filter('plugin_action_links', array(ARHooks::getInstance(), 'disallow_plugin_deactivation'), 10, 4); 
    19     add_filter('pre_site_transient_update_core', array(ARHooks::getInstance(), 'disallow_core_update')); 
     20    add_action('admin_menu', array(ARHooks::get_instance(), 'disallow_editor')); 
     21    add_filter('pre_site_transient_update_core', array(ARHooks::get_instance(), 'disallow_core_update')); 
     22    add_filter('plugin_action_links', array(ARHooks::get_instance(), 'hide_plugin_controls'), 10, 4); 
     23    add_filter('user_has_cap', array(ARHooks::get_instance(), 'catch_plugin_cap'), 10, 3); 
    2024  } 
    2125   
    2226} 
    2327 
    24 AdminRestriction::setup(); 
     28new AdminRestriction(); 
    2529?> 
  • admin-restriction/trunk/readme.txt

    r590473 r591619  
    55Requires at least: 3.0 
    66Tested up to: 3.4.1 
    7 Stable tag: 1.0 
     7Stable tag: 1.1.0 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    2222== Frequently asked questions == 
    2323 
     24= What users will be able to upgrade core, theme and plugin modifications? = 
    2425 
     26The administrator created at WordPress installation (administrator with id 1) will be the only user that is able to do Core, plugin and theme installation, updating and removal. 
     27 
     28You have to be an Administrator to see the "What The File" option. 
    2529 
    2630== Screenshots == 
     
    3034== Changelog == 
    3135 
    32  
     36= 1.1.0 = 
     37* Fixed hiding plugin activation link bug. 
     38* Added a method that prevents users from trying to activate/deactivate plugins through direct URL entry. 
    3339 
    3440== Upgrade notice == 
Note: See TracChangeset for help on using the changeset viewer.