Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

rechazame on "Whento use 'init' and when to use a function in functions.php?"

$
0
0

Let's say I want to disable users from viewing the dashboard.

I can add the following to functions.php:

function hide_dashboard_init() {
	if ( is_admin() && !current_user_can( 'manage_options' ) ) {
		wp_redirect( home_url() );
		exit;
	}
}
add_action( 'init', 'hide_dashboard_init' );

But why not just add a regular function to functions.php? Something like that:

function hide_dashboard() {
if ( is_admin() && !current_user_can( 'manage_options' ) ) {
wp_redirect( home_url() );
}
}


Viewing all articles
Browse latest Browse all 8245

Trending Articles