Redirection de la page d'administration
3 réponses
- votes
-
- 2013-02-19
/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function disallowed_admin_pages() { global $pagenow; # Check current admin page. if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) { wp_redirect( admin_url( '/post-new.php?post_type=page' ) ); exit; } }
Déclenchez lafonction ci-dessus sur le crochet
admin_init
.^add_action( 'admin_init', 'disallowed_admin_pages' );
Syntaxe alternative:
/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ add_action( 'admin_init', function () { global $pagenow; # Check current admin page. if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) { wp_redirect( admin_url( '/post-new.php?post_type=page' ) ); exit; } } );
/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function disallowed_admin_pages() { global $pagenow; # Check current admin page. if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) { wp_redirect( admin_url( '/post-new.php?post_type=page' ) ); exit; } }
Fire the above function on the hook
admin_init
.add_action( 'admin_init', 'disallowed_admin_pages' );
Alternate syntax:
/** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ add_action( 'admin_init', function () { global $pagenow; # Check current admin page. if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) { wp_redirect( admin_url( '/post-new.php?post_type=page' ) ); exit; } } );
-
- 2016-01-13
La solution de Michael semble être destinée à être utilisée dans une classe,doncpourtoutepersonne souhaitant unefonction autonome quifonctionnera directement dansfunctions.php,l'exemple ci-dessous comprend une redirection de custom.php vers unepage d'options dethèmeet celle deFonction originale de Michael.
function admin_redirects() { global $pagenow; /* Redirect Customizer to Theme options */ if($pagenow == 'customize.php'){ wp_redirect(admin_url('/admin.php?page=theme_options', 'http'), 301); exit; } /* OP's redirect from /wp-admin/edit.php?post_type=page */ if($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'page'){ wp_redirect(admin_url('/post-new.php?post_type=page', 'http'), 301); exit; } } add_action('admin_init', 'admin_redirects');
Michael's solution appears to be intended for use inside a class, so for anyone wanting a standalone function which will work directly in functions.php, the example below includes a redirect from customize.php to a theme options page and the one from Michael's original function.
function admin_redirects() { global $pagenow; /* Redirect Customizer to Theme options */ if($pagenow == 'customize.php'){ wp_redirect(admin_url('/admin.php?page=theme_options', 'http'), 301); exit; } /* OP's redirect from /wp-admin/edit.php?post_type=page */ if($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'page'){ wp_redirect(admin_url('/post-new.php?post_type=page', 'http'), 301); exit; } } add_action('admin_init', 'admin_redirects');
-
- 2012-05-15
Oui,celaestpossibleen ajoutant une action à
admin_init
,à ce stade,vouspouvez vérifier l'URI de la demandepour voir s'il correspond à/wp-admin/edit.php?post_type=page
et s'il émet une redirection vers lapage d'ajout demessages:/wp-admin/post-new.php?post_type=page
.Également l ' Plugin API et l' lespages de référence aux actions sur le codex WordPress donnentplus de détails sur les actionset leurfonctionnement.
Yes this is possible by adding an action to
admin_init
, at that point you could check the request uri to see if it matches/wp-admin/edit.php?post_type=page
and if it does issue a redirect to the add posts page:/wp-admin/post-new.php?post_type=page
.Also the Plugin API and the action reference pages on the WordPress codex go into more detail about actions and how they work.
Est-ilpossible de rediriger les utilisateurs vers unepage d'administration s'ils accèdent à une autrepage d'administration?
Parexemple,si un utilisateur accède à "toutes lespages"
/wp-admin/edit.php?post_type=page
ils seraient redirigés vers "Ajouter unenouvellepage"
/wp-admin/post-new.php?post_type=page