【问题标题】:Displaying admin notice dynamically动态显示管理员通知
【发布时间】:2016-07-11 06:17:44
【问题描述】:

我想在编辑帖子文本时显示管理员通知(在保存帖子之前)。我想 admin_notice 钩子在这方面不起作用(它不适合我)。知道如何显示一些错误消息以提醒用户 Post 内容不会被接受吗?

我更喜欢像管理员通知这样的内联显示,而不是可能被阻止的弹出窗口。

以下不起作用

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>';
}

【问题讨论】:

    标签: php wordpress plugins


    【解决方案1】:

    在这种情况下,wp_remote_get() 可以正常工作。

    创建一个notice.php文件并上传到我的服务器上。

    然后我将这些代码添加到我的插件中,它对我有用。

    <?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>
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多