Find us on Facebook

LightBlog
Responsive Ads Here

Thứ Sáu, 29 tháng 12, 2017

Wordpress- admin notice on Insert Media popup screen

Question:

I want an admin notice box on all media upload pages. I did that for media library page by code
  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>';
        }
But i want this message on add media popup screen also . But i am not founding any solution.

Answer:

I'm unaware of any hooks that tap in in the pop up, but there might be.
If not, you could use some jQuery to put your message on the pop-up when Add Media is clicked. I was able to with the following:
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);

Không có nhận xét nào:

Đăng nhận xét