Skip to content

Instantly share code, notes, and snippets.

@mauriciogofas
Created September 25, 2015 13:36
Show Gist options
  • Save mauriciogofas/8c04b73197f2cec49536 to your computer and use it in GitHub Desktop.
Save mauriciogofas/8c04b73197f2cec49536 to your computer and use it in GitHub Desktop.
Prevents subscribers access to wp-admin and redirects to specific page of the front end
<?php
/*
* Impede o acesso de assinantes ao wp-admin e os redireciona para página específica do front end
* Prevents subscribers access to wp-admin and redirects to specific page of the front end
*/
function gfs_restrict_admin_with_redirect() {
if ( ! current_user_can( 'edit_posts' /* edit_posts = minimum capacity required to access the dashboard */ ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect( site_url() . '/?p=322' ); // 322 = Page ID to redirect
exit;
}
}
add_action( 'admin_init', 'gfs_restrict_admin_with_redirect', 1 );
// End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment