Last active
October 29, 2019 10:29
-
-
Save yratof/29ff351d0d6ea45aacf41540e343a715 to your computer and use it in GitHub Desktop.
Remove Wordpress dashboard, replace it with WooCommerce Product archive view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Removing the useless Dashboard from Wordpress | |
* | |
* Required: Wordpress, Woocommerce | |
*/ | |
/** | |
* Class Dashboard Resolver | |
*/ | |
class DashboardResolver { | |
// Admin URL to redirect to | |
const REDIRECTED = 'edit.php?post_type=product'; | |
/* | |
Setup function | |
*/ | |
static public function setup() { | |
add_action( 'load-index.php', __CLASS__ . '::dashboard_redirect' ); | |
add_filter( 'login_redirect', __CLASS__ . '::login_redirect', 10, 3 ); | |
add_action( 'admin_menu', __CLASS__ . '::remove_menus' ); | |
} | |
/* | |
Return admin redirect to WooCommerce Products list | |
*/ | |
static public function dashboard_redirect(){ | |
wp_redirect( admin_url( self::REDIRECTED ) ); | |
} | |
/* | |
Return admin redirect to WooCommerce Products list | |
*/ | |
static public function login_redirect( $redirect_to, $request, $user ){ | |
return admin_url( self::REDIRECTED ); | |
} | |
/* | |
Remove the Dashboard menu item | |
Options are: | |
'Dashboard','Posts','Media','Links','Pages', | |
'Appearance','Tools','Users','Settings', | |
'Comments','Plugins' | |
*/ | |
static public function remove_menus () { | |
global $menu; | |
$restricted = [ __('Dashboard') ]; | |
end( $menu ); | |
while( prev( $menu ) ) { | |
$value = explode( ' ', $menu[key( $menu )][0] ); | |
if ( in_array( $value[0] != NULL ? $value[0] : '', $restricted ) ) { | |
unset( $menu[key( $menu )] ); | |
} | |
} | |
} | |
} | |
DashboardResolver::setup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment