2

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>';
}
2
  • 1
    This would be tricky server side, since you want to keep existing content unchanged, but at the same time keep user's edits (losing them would be horrible UX). Had you considered doing it with JS client-side?
    – Rarst
    Commented Jul 11, 2016 at 18:06
  • yes merely flag to the user that the content wont be acceptable, will explore JS
    – rysv
    Commented Jul 11, 2016 at 18:43

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.