您需要通过URL将通知消息(或者可能是一个引用特定标准通知消息的键)发送到下一页。
我建议将其封装在自己的函数中。类似于。。。
public function render_to_pdf() {
// ... whatever you need to do
my_trigger_notice( 1 ); // 1 here would be a key that refers to a particular message, defined elsewhere (and not shown here)
}
然后在函数中添加新函数。php(或admin.php文件):
function my_trigger_notice( $key = \'\' ) {
add_filter(
\'redirect_post_location\',
function ( $location ) use ( $key ) {
$key = sanitize_text_field( $key );
return add_query_arg( array( \'notice_key\' => rawurlencode( sanitize_key( $key ) ) ), $location );
}
);
}
现在,当页面重定向时,它应该将您的通知键附加到URL上,使下一个页面能够在
admin_notice
挂钩(也在functions.php或admin.php中设置):
function my_admin_notices() {
if ( ! isset( $_GET[\'notice_key\'] ) ) {
return;
}
$notice_key = wp_unslash( sanitize_text_field( $_GET[\'notice_key\'] ) );
$all_notices = [
1 => \'some notice\',
2 => \'some other notice\',
]
if ( empty( $all_notices[ $notice_key ] ) ) {
return;
}
?>
<div class="error">
<p>
<?php echo esc_html( $all_notices[ $notice_key ] ); ?>
</p>
</div>
<?php
}
add_action( \'admin_notices\', \'my_admin_notices\' );