doutuoshou8915 2014-05-27 18:52
浏览 104

Wordpress设置Flashdata错误

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 : blue success : green warning : yellow error : 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?

  • 写回答

1条回答 默认 最新

  • dskvfdxgdo2422392 2014-05-27 20:28
    关注

    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:

    The class "updated" will display the message with a white background and a green left border (used to be a yellow background before WordPress 3.8.).

    The class "error" will display the message with a white background and a red left border (used to be a red background before WordPress 3.8.).

    The class "update-nag" will display the message with a white background and a yellow left border. In addition, the message will be moved above the page title (<h2>).

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法