使用 PHP 代码接管 Typecho 提示消息

编程开发Typecho 2021-07-01 196℃ 0 0

开发前台登陆的时候发现前台登陆错误不提示,看了一下Typecho代码后发现后台是用JS实现的,我不太想用JS实现,那就PHP呗。

直接给出代码,把下面的代码放到functions.php,然后调用xNotice方法即可

/**
 * 接管 Typecho 提示
 *
 * @return void
 */
function xNotice()
{
    $notice = json_decode(Typecho_Cookie::get('__typecho_notice', ''));
    if (is_array($notice)) $notice = array_shift($notice);
    $type = Typecho_Cookie::get('__typecho_notice_type', '');
    $typeMapper = array(
        'success' => 'success',
        'notice' => 'info',
        'error' => 'danger'
    );
    if (!empty($type) && in_array($type, array('success', 'notice', 'error'))) {
        if (!empty($notice)) {
            echo '<div class="alert alert-' . $typeMapper[$type] . '">' . $notice . '</div>';
            Typecho_Cookie::delete('__typecho_notice');
            Typecho_Cookie::delete('__typecho_notice_type');
        }
    }
}

评论 (0)

友情链接
最近评论
  1. the original source : Thanks for a marvelous posting! I genuinely enjoyed reading it, you may be a great author.I
    will ensure that I bookmark your blog and will often come back sometime soon. I want to encourage yourself to continue your great writing, have a nice weekend!
  2. see this page : Hi, i read your blog from time to time and i own a similar one and i was just curious if you get a lot
    of spam feedback? If so how do you stop it, any plugin or
    anything you can advise? I get so much lately it's driving me insane so any support is very much appreciated.
  3. click to read more : Hi there, just became alert to your blog through Google, and found that it's really
    informative. I'm gonna watch out for brussels. I will be grateful if
    you continue this in future. Numerous people will be benefited
    from your writing. Cheers!
  4. Thiết kế phòng hát karaoke : I got this website from my pal who told me on the topic of this site and now this time I am visiting this site and
    reading very informative articles or reviews here.
  5. Lil Durk : Hello I am so grateful I found your website, I really found you by accident, while
    I was researching on Google for something else, Regardless I am here now and would just like to say
    thanks for a marvelous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also
    added your RSS feeds, so when I have time I will be back to read more, Please do keep up the superb b.
Top