Displaying admin notice dynamically

I would like show the admin notice while post text is being edited (before Save post). I suppose admin_notice hook wont work in this (it doesn’t for me). Any idea how to show some error message to alert the user that Post content is not going to be accepted ?

I prefer inline display like admin notice instead of popups that could be blocked.

Following doesn’t work

function secure_oembed_filter($html, $url, $attr, $post_ID) {

    if (strlen($html) > 0 && strpos($html, "http://")) {
        //wp_die("Unsecure link in embeds", "Unsecured post");
    } else {
        add_action('admin_notices', array($this, 'show_error'));
    }
    return $html;
}

private function show_error () {

    echo '<div class="error"><p>This is an error</p></div>';
}

1 Answer
1

In that case wp_remote_get() will work fine.

Create a notice.php file and uploaded it on my server.

Then I have added these code into my plugin and it works for me.

<?php
$remote_data = wp_remote_get( 'http://example.com/notice.php' );
$remote_body = wp_remote_retrieve_datat( $remote_data );
?>

<div class="notice">
    <?php echo $remote_body ?>
</div>

Hope that helps.

Leave a Comment