wir
4/2/2015 - 4:28 PM

disable-menu.php

define( 'DISALLOW_FILE_MODS', true );
include( 'class-tgm-plugin-activation.php' );

add_action( 'tgmpa_register', 'my_register_plugins' );
function my_register_plugins() {
    $plugins = array(
         array(
            'name'               => 'Advanced Custom Fields',
            'slug'               => 'advanced-custom-fields-pro',
            'source'             => get_stylesheet_directory() . '/plugins/advanced-custom-fields-pro.zip',
            'required'           => true,
            'version'            => '5.2.0',
            'force_activation'   => true,
            'force_deactivation' => false,
            'external_url'       => '',
        ),
        array(
            'name' => 'ACF Date And Time Picker',
            'slug' => 'acf-field-date-time-picker',
            'required' => true,
            'version' => '2.0.18.1',
            'force_activation'   => true,
            'force_deactivation' => false,
        )
    );
    $config = array(
        'default_path' => '',
        'menu'         => 'tgmpa-install-plugins',
        'has_notices'  => true,
        'dismissable'  => false,
        'dismiss_msg'  => 'Some plugins have been deactivated which are needed for your website to function. Please re-activate or install the required plugins using the link below. If you are unable to do so please contact <a href="mailto:developer@yourwebsite.com">developer@yourwebsite.com</a> as soon as possible.',
        'is_automatic' => true,
        'message'      => '',
        'strings'      => array(
            'page_title'                      => 'Install Required Plugins',
            'menu_title'                      => 'Install Plugins',
            'installing'                      => 'Installing Plugin: %s',
            'oops'                            => 'Something went wrong with the plugin API.',
            'notice_can_install_required'     => _n_noop( '', '' ),
            'notice_can_install_recommended'  => _n_noop( '', '' ),
            'notice_cannot_install'           => _n_noop( 'Sorry, but you do not have the correct permissions to install plugins. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install plugins. Contact the administrator of this site for help on getting the plugins installed.' ),
            'notice_can_activate_required'    => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ),
            'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ),
            'notice_cannot_activate'          => _n_noop( 'Sorry, but you do not have the correct permissions to activate the plugins. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate plugins. Contact the administrator of this site for help on getting the plugins activated.' ),
            'notice_ask_to_update'            => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ),
            'notice_cannot_update'            => _n_noop( 'Sorry, but you do not have the correct permissions to update plugins. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update plugins. Contact the administrator of this site for help on getting the plugins updated.' ), // %1$s = plugin name(s).
            'install_link'                    => _n_noop( 'Install Plugins Now', 'Install Plugins Now' ),
            'activate_link'                   => _n_noop( 'Activate Plugins Now', 'Activate Plugins Now' ),
            'return'                          => 'Return to Required Plugins Installer',
            'plugin_activated'                => 'Plugin activated successfully.',
            'complete'                        => 'All plugins installed and activated successfully. %s',
            'nag_type'                        => 'error'
        )
    );
    tgmpa( $plugins, $config );
}

register_activation_hook( __FILE__, 'my_initial_setup' );
function my_initial_setup() {
    $admin = get_role( 'administrator' );
    $overlord_caps = $admin->capabilities;
    $overlord_caps[] = 'be_superadmin';
    $role = add_role( 'overlord', 'Overlord', $overlord_caps );
}
add_filter( 'plugin_action_links', 'my_disable_plugin_actions', 10, 4 );
function my_disable_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) {
	$plugins = aray( 'advanced-custom-fields-pro/acf.php', 'acf-field-date-time-picker/acf-date_time_picker.php' );
	if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, $plugins )) {
 		unset( $actions['deactivate'] );
	}
 	return $actions;
}
add_filter( 'plugin_action_links', 'my_disable_plugin_actions', 10, 4 );
function my_disable_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) {
	$plugins = aray( 'advanced-custom-fields-pro/acf.php', 'acf-field-date-time-picker/acf-date_time_picker.php' );
	if ( array_key_exists( 'deactivate', $actions ) && current_user_can( 'can_overlord' ) && in_array( $plugin_file, $plugins )) {
 		unset( $actions['deactivate'] );
	}
 	return $actions;
}
function remove_plugin_menu(){
	remove_menu_page( 'plugins.php' );
}
add_action( 'admin_menu', 'remove_plugin_menu' );