我想在所有媒体上传页面上都有一个管理员通知框。我是按代码为媒体库页面做的
add_action( \'load-upload.php\', array( $this, \'media_library_message_load\' ) );
public function media_library_message_load(){
add_action( \'admin_notices\', array( $this, \'media_library_message_display\' ) );
}
public function wpb_media_library_message_display() {
echo \'<div class="notice update-nag">
<strong>Note: my message </strong>
</div>\';
}
但我想在添加媒体弹出屏幕上也显示这条消息。但我没有找到任何解决方案。
谢谢
最合适的回答,由SO网友:David Sword 整理而成
我不知道弹出窗口中是否有任何挂钩,但可能有。
如果没有,您可以使用一些jQuery在单击添加媒体时将消息放在弹出窗口中。我能够做到以下几点:
add_action(\'admin_head\',\'myplugin_add_media_popup_notice\');
function myplugin_add_media_popup_notice() {
?>
<script>
jQuery(window).load(function() {
// the MEDIA buttons you want the notice on
jQuery(\'#insert-media-button\').click(function(){
// give the lightbox half a second to add itself
setTimeout(myplugin_add_media_popup_notice, 500);
});
function myplugin_add_media_popup_notice() {
// if we haven\'t added a notice already
if (!jQuery(\'body\').hasClass(\'addedMediaPopUp\')) {
// the the notice
jQuery(\'.media-frame-router\').before(\'<div class="update-nag notice"><strong>Note: my message </strong></div>\');
// and mark it to not show again if media btn reclicked
jQuery(\'body\').addClass(\'addedMediaPopUp\')
}
}
});
</script>
<style>
/* and some css since .notice isn\'t completely defined at this scope */
.media-frame .update-nag.notice {
position: absolute;
top: -10px;
right: 40px;
z-index: 999;
width: calc(100% - 600px);
border-left: 3px solid #168fc0;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}
</style>
</style>
<?php
}