我在检查用户是否为管理员后使用此选项
if ( isset($_GET[\'action\']) && $_GET[\'action\'] === \'edit\' )
有更好的方法吗?我在检查用户是否为管理员后使用此选项
if ( isset($_GET[\'action\']) && $_GET[\'action\'] === \'edit\' )
有更好的方法吗?您可以使用get_current_screen
来确定这一点。
$screen = get_current_screen();
if ( $screen->parent_base == \'edit\' ) {
echo \'edit screen\';
}
我不知道我是否会确切地说这总是更好的,这取决于需要什么,但这可能是我会做的方式。这种方法的最大好处是,您可以访问更多的信息,因此可以进行更多不同的区分。只要看一下文档就可以理解我的意思。应该在以后的挂钩中使用,Codex 表示:
函数返回null
如果从调用admin_init
钩可以在以后的挂钩中使用,例如current_screen
.
global $pagenow;
if (( $pagenow == \'post.php\' ) || (get_post_type() == \'post\')) {
// editing a page
}
if ($pagenow == \'profile.php\') {
// editing user profile page
}
资料来源:https://wordpress.stackexchange.com/a/7281/33667使用“get\\u current\\u screen”,只需事先确保它存在codex says 此函数在大多数管理页上定义,但不是在所有管理页上定义
// Remove pointless post meta boxes
function FRANK_TWEAKS_current_screen() {
// "This function is defined on most admin pages, but not all."
if ( function_exists(\'get_current_screen\')) {
$pt = get_current_screen()->post_type;
if ( $pt != \'post\' && $pt != \'page\') return;
remove_meta_box( \'authordiv\',$pt ,\'normal\' ); // Author Metabox
remove_meta_box( \'commentstatusdiv\',$pt ,\'normal\' ); // Comments Status Metabox
remove_meta_box( \'commentsdiv\',$pt ,\'normal\' ); // Comments Metabox
remove_meta_box( \'postcustom\',$pt ,\'normal\' ); // Custom Fields Metabox
remove_meta_box( \'postexcerpt\',$pt ,\'normal\' ); // Excerpt Metabox
remove_meta_box( \'revisionsdiv\',$pt ,\'normal\' ); // Revisions Metabox
remove_meta_box( \'slugdiv\',$pt ,\'normal\' ); // Slug Metabox
remove_meta_box( \'trackbacksdiv\',$pt ,\'normal\' ); // Trackback Metabox
}
}
add_action( \'current_screen\', \'FRANK_TWEAKS_current_screen\' );
这个wp_editor 功能在显示编辑器和发送信息方面工作正常,但信息从未按原样发送。在负责从前端更新帖子的模板文件中,var\\u dumping始终显示来自数据库的内容与编辑器通过POST变量发送的内容之间的差异,即使用户在编辑器下什么都不更改。例如,问题之一是POST变量发送的字符串包含\"\\ 而不是\". 在我创建的网站中,我需要使用PEAR text\\U diff库显示帖子编辑之间的差异。应用程序告诉我,编辑之间总是存在差异,即使事实并非如此,因为即使在esc_attr, 和strip_ta