本文介绍了Wordpress 设置 Flashdata 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用 codeigniter、cakephp、zend、magento 做了很多工作,它们都有设置我听说的 flashdata 错误的方法.
见:
这基本上是在会话中设置的值,每个页面都会查找该值,如果找到则显示,然后从会话中清除,以便只显示一次.
通常,这些以弹出窗口或短寿命的小框的形式显示,根据级别进行颜色编码.
例如:留言:蓝色成功:绿色警告:黄色错误:红色
wordpress 中是否有这样的东西,例如,您可以通过帖子执行一些业务逻辑以说wp_ajax"或wp_ajax_nonpriv",并且如果在添加 flash 数据错误后出现问题重定向到上一页?
解决方案
如果您想在 wp-admin 区域内显示 Flash 消息,您可以在 admin_notices 中添加一个操作代码>钩子.它会像这样工作(取自 此处 和 此处):
//将动作添加到钩子中add_action('admin_notices', 'your_custom_function');函数 your_custom_function() {?><div class="updated"><p><?php _e('更新了!', 'my-text-domain');?></p>
<?php}
至于 CSS 类,看起来选项很少:
类更新"将显示带有白色背景和绿色左边框的消息(在 WordPress 3.8 之前曾经是黄色背景.).
类错误"将显示带有白色背景和红色左边框的消息(在 WordPress 3.8 之前曾经是红色背景.).
update-nag"类将显示带有白色背景和黄色左边框的消息.此外,消息将移动到页面标题上方(
).
但这不应该阻止您创建自己的 CSS 类并使用它们.
如果您想在 wp-admin 之外显示消息,您可能需要开发自己的解决方案或 获取用户生成的解决方案.不幸的是,WP 没有内置功能,因为它可能因主题而异.
I've done a bunch of work with codeigniter, cakephp, zend, magento and they all have methods for setting what I've heard called flashdata errors.
see:
This is basically a value set in session that every page looks for and if found displays then clears from the session so that it is only displayed once.
Typically these are displayed in the form of a popup or small short lived box that is color coded depending on the level.
Ex: message : bluesuccess : greenwarning : yellowerror : red
Is there something like this within wordpress where you can for instance do some business logic through a post to say "wp_ajax" or "wp_ajax_nonpriv" and if something breaks redirect to the previous page after adding a flash data error?
解决方案
If you want to display flash messages within the wp-admin area, you can add an action to admin_notices
hook. It would work like this (taken from here and here):
// Adds the action to the hook
add_action( 'admin_notices', 'your_custom_function' );
function your_custom_function() {
?>
<div class="updated">
<p><?php _e( 'Updated!', 'my-text-domain' ); ?></p>
</div>
<?php
}
As for the CSS classes, looks like there are few options:
But that shouldn't keep you from creating your own CSS classes and using them.
If you want to display the messages outside wp-admin, you might need to develop your own solution or get user generated solutions. Unfortunately WP doesn't have a built-in functionality for that as it may vary from theme to theme.
这篇关于Wordpress 设置 Flashdata 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!