I was able to figure it out by looking at the form parameters, which I don’t really like doing since it’s not part of the wordpress api. if anybody has a better idea, please leave a comment.
$_REQUEST['post_id'] > 0 // it's being uploaded from a page/post
$_REQUEST['post_id'] == 0 // it's being uploaded from the media library
empty($_REQUEST['post_id']) // it came from somewhere else (plugin, theme, etc)
It seems to be reliable for posts and library, but the “other” is probably not 100% reliable since plugins and themes could add parameters to trick the code into thinking it was one of the other types.
Related Posts:
- Redirect to another page using contact form 7? [closed]
- 500 Internal server error wp_handle_upload_prefilter
- Where is the best place to use add_filter
- Edit plugin without hooks in functions.php
- Using add_filter inside another class
- how does wp.media javascript library work?
- How to list the Hooks and order of execution in current loading page? [duplicate]
- Pass A Value From Outside To A Plugin Variable
- Failed to invoke other hook from the init hook
- How can I add a custom meta value on file upload?
- How can I filter blog name?
- Deleting images through upload folder, but not deleting from media library
- Custom preview_post_link not working for draft post
- Add Fields with Sub-Fields to WP Job Manager
- Determine plugin name from within plugin_action_links filter
- merging an array to an existing array using add_filter
- Admin page: form with enctype=”multipart/form-data” does not transfer its data
- Changing image URLs in media library
- Upload file inside plugins options page
- Adding Attachment Display Settings in custom media frame
- Creating a plugin to sanitize comment and the url field before display only
- White page by using filter template_include
- How to check current user before all actions and filters?
- Create a navbar filter that filters by a custom field
- Passing an array from shortcode-function to filter-function
- Get Time Taken By Each Action Hook in WordPress
- wp.media javascript issue with on select
- qTranslate remove default directory from link
- How to change the name of the “edit my profile” link in the WordPress admin backend
- Plugin Not Working After Being Uploaded To WordPress Plugin Repository
- Proper way to replace the_content only for pages created by custom plugin
- add_filter doesn’t work
- Check if variable is set in filter
- Is it possible for a plugin to force reading and writing of uploaded images to a database instead of to a filesystem?
- Check filter defined or not?
- adding a button to the media uploader
- custom uploader in the admin area
- How programatically cause uploads folder to be created?
- Add a function call after content automatically?
- Issue with wp_handle_upload
- what is the point of telling add_filter how many parameters you want passed to the function?
- How to add filter for wordpress plugin?
- How to use add_action for multiple instances of the same class
- How To Create A File Archive in WordPress?
- How to append new form elements in “Add New” form of Users in WordPress admin panel?
- Want to create custom design of progress indicator in wpforms
- Add hook after content without formatting
- How to upload large media file in chunks, without any plugin?
- Using OR Condition with facetwp facets
- How to copy the all WordPress media items to another custom plugin folder?
- Access remote SFTP server via WordPress login?
- what functions to use to resize images and create DB metadata for them after/during upload?
- Nested Actions and Filters
- Uploading images to custom table
- Remove action added in plugin class from theme
- Using multi-dimensional array with filter
- Media Upload to custom database and Custom Directory
- Can I add content before post content without using the_content filter
- WordPress Add advertising ads befor and after content with periority [closed]
- trying to create simple plugin to filter categories from all authors
- shortcode which is introduced into entry the blog, and appears in side bar
- How do i get all author posts on custom post type list
- Upload Image to desired directory through plugin
- Unable to pass arguments from plugin form to filter hook using ajax, the data is transferring via ajax but unable to pass as arguments in filter hooks
- wp_handle_upload – specified file failed upload test
- Why do I get this “plugin does not have a valid header” error?
- How to upload image with simple form?
- Making plugin unique to not conflict with plugins with the same name
- How to get posts by content?
- Plugin not saving values when placed in a folder within /wp-content/plugins
- How to integrate plugin in WordPress theme
- How to add Internationalization in WordPress using Javascript/React?
- creating html reusable blocks via shortcodes
- I want to auto populate data in three fields if one drop down is selected
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- Can I load the textdomain before a plugin is activated?
- Unable to give correct path in wordpress
- Disable variations on woo commerce if out of stock
- How to add img into a plugin?
- How to log custom plugin error to debug.log file
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- How to create admin setting for this small plugin
- Unpublished Pages Failing To Appear On Custom Path
- How to fix caching issue in PHP data from database
- How to securely controlling data without keeping it in postmeta?
- Does having apply_filters in the middle of an array make a difference?
- Soflyy WP All Import Custom File Download Issue
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- Custom pages with plugin
- How to insert category name above post title in a featured pages plugin?
- Displaying friend’s posts only
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- How to set-up multiple cron task with wp_schedule_event so that they do not overlap?
- Site is setup statically – how to make it content managable?
- Modifying lightbox plugin to allow for quoting, Does this exist? [closed]
- Plugin version number after code rewrite [closed]
- How to escape html code?
- How to make a Template page to show the information of different things Shop and Product page?