[resolved] Adding error messages to post.php (looking as WP default ones) (2 posts)

  1. aurimas
    Posted 5 years ago #


    I am currently working on developing custom post types in WP 3.0 (custom meta boxes, custom fields, etc). In some cases on a save_post hook I am doing some back-end verification (like, to see if an uploaded image fits the required dimensions or a custom caption length does not exceed XX characters).
    In case the verification fails, I would like to display users notifications (around the place where the "Post updated" message appears). However I can't find anything about how that could be done. I definitely know that some plugins throw such notifications on their own pages, but browsing through their code did not help.

    Any guidance would be appreciated ;)

  2. aurimas
    Posted 5 years ago #

    And, of course, a bit of more google search, and I arrived at the asnwer:

    one needs to use the admin_notices hook:

    add_action('admin_notices', create_function('', 'echo "<div class=\"error\">This is my error";')); //for errors (red background)
    add_action('admin_notices', create_function('', 'echo "<div class=\"updated\">This is my error";')); //for other notifications (yellow background)

Topic Closed

This topic has been closed to new replies.

About this Topic