最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Update user meta when an external link in admin notice is clicked

programmeradmin2浏览0评论

I want my plugin to show a dismissable notice. There are 2 links that do not redirect the user anywhere, just dismiss the notice and make sure that it will never show up again. This is only a minimal example from my settings class and this part works flawlessly:

I have the following in construct:

add_action('admin_notices', array($this, 'acau_notice' ) );
add_action('admin_init', array( $this, 'acau_ignore_notice') );

The following is a part of acau_notice function:

global $current_user ;
$user_id = $current_user->ID;

if ( ! get_user_meta( $user_id, 'acau_ignore_notice' )) {       
        echo '<p><a href="?acau_ignore_notice=0">Dismiss permanently 1</a></p>';
        echo '<p><a href="?acau_ignore_notice=0">Dismiss permanently 2</a></p>';
    }
}

And here is a function to store the information whether the notice should be displayed:

public function acau_ignore_notice() {
    global $current_user;
    $user_id = $current_user->ID;

    if ( isset($_GET['acau_ignore_notice']) && '0' == $_GET['acau_ignore_notice'] ) {
        add_user_meta($user_id, 'acau_ignore_notice', 'true', true);
    }
}

I would like to echo a third link that redirects the user to an external page, but also make it dismiss the notice and make it never show up again. Can it be done with PHP?

发布评论

评论列表(0)

  1. 暂无评论