admin - How to display a WordPress notice on create_term action

I am hijacking create_term to do stuff when a new term is created... Fire the function when new term is createdadd_ac

I am hijacking create_term to do stuff when a new term is created...

// Fire the function when new term is created
add_action( 'create_term', 'process_term', 11, 3 );

function process_term($term_id, $tt_id, $taxonomy) {

    if ($taxonomy == 'post_tag') {
        // Do stuff
    }

}

By means of experimentation and learning, I'd like // Do stuff to include displaying a feedback confirming that we saw a new 'post_tag' term was created.

I have read that create_term does not support echoing anything back to the browser. Indeed, Doing a simple in the function breaks something in display...

echo $taxonomy;

In my case, IF the term was created in the admin backend (ie. either in the edit-tags.php Tags section or in the post-new.php or similar Post edit screen), I'd like the feedback to take the form of a WordPress alert notice bar on the subsequent screen.

"Subsequent" is an interesting question, I suppose, because the edit-tags.php page doesn't refresh to a new page when a term is created on it. And I guess that is the same for post-new.php, sometimes (?). They often update in-situ.

I'd settle for a simple echo in order to understand whether doing anything out of create_term is possible. But I guess that's what a "notice" really is... you echo out HTML with the notice class, right?

With that in mind, the following code, which places admin_notices inside my create_term function, does not produce broken displayed code - but it also does not display any notice message at all, suggesting admin_notices isn't even firing...

// Fire the function when new term is created
add_action( 'create_term', 'process_term', 11, 3 );

function process_term($term_id, $tt_id, $taxonomy) {

        add_action('admin_notices', 'my_admin_notice');

}



function my_admin_notice() {
    ?>

    <div class="notice notice-success is-dismissible">
        <p>This is a success message.</p>
    </div>

    <?php
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745225305a4617432.html

相关推荐

  • admin - How to display a WordPress notice on create_term action

    I am hijacking create_term to do stuff when a new term is created... Fire the function when new term is createdadd_ac

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信