0

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.

Thanks

1

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);
            border-left: 3px solid #168fc0;
            box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
        }
        </style>
    </style>
    <?php
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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