Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Created August 26, 2021 15:03
Show Gist options
  • Save anythinggraphic/833bc638dcb5a55ec153139130637898 to your computer and use it in GitHub Desktop.
Save anythinggraphic/833bc638dcb5a55ec153139130637898 to your computer and use it in GitHub Desktop.
WordPress: Redirect the Plugins and Plugins > Add New pages to the WP Admin Dashboard.
<?php
/**
* WP Admin Page Redirects.
*
* Redirect the Plugins and Plugins > Add New pages to the WP Admin Dashboard in
* order to prevent the installation of plugins for overzealous editors.
*
* @since 1.0.0
*
* @param object|null $my_current_screen Get the current screen object
*/
add_action(
'current_screen',
function() {
$my_current_screen = get_current_screen();
if ( isset( $my_current_screen->base ) && 'plugin-install' || 'plugins' === $my_current_screen->base ) {
wp_safe_redirect( admin_url() );
exit();
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment