Avoid PHP notices in media modal caused by orphaned attachments.

fixes #29566 for trunk.
Built from https://develop.svn.wordpress.org/trunk@29724


git-svn-id: http://core.svn.wordpress.org/trunk@29498 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Make sure we're on the media grid page before calling wp.media().

props azaozz.
fixes #29520 for trunk.
Built from https://develop.svn.wordpress.org/trunk@29725


git-svn-id: http://core.svn.wordpress.org/trunk@29499 1a063a9b-81f0-0310-95a4-ce76da25c4cd