Handling admin notice on Edit Post
当动作与
post
或
editpost
, 我们将面临
redirect_post
作用有两个过滤器可用于处理post消息,
redirect_post_location
和
post_updated_messages
(请参阅
https://core.trac.wordpress.org/browser/tags/4.8/src/wp-admin/edit-form-advanced.php#L135 ).
下面是如何处理消息的示例代码。
Create new message (optional)
add_filter( \'post_updated_messages\', function( $messages ) {
//create another message code, i.e 11
$messages[\'post\'] = $messages[\'post\'] + array( 11 => __( \'Something Wrong\', \'textdomain\' ) );
return $messages;
} );
Handling redirection
add_filter( \'redirect_post_location\', function( $location, $post_id ) {
//let say the conditon is false, or you can create your code here
$condition = false;
if ( ! $condition ) //add 11 as code message or use in the list post messages
$location = add_query_arg( \'message\', 11, get_edit_post_link( $post_id, \'url\' ) );
return $location;
}, 10, 2 );
作为法典参考,代码
0
将不会通知我们。通知将始终提供更新通知(绿色),如果我们需要错误或警告通知,我建议创建自己的管理员通知。我希望这有帮助。