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
- How can we extent core/group or cover block?
- wp_head filter not executed inside custom class
- Custom uploader – Upload files and save link into database
- media_sideload_image only works on localhost and without return id or src
- How does translation (gettext) work for translating config file of plugin?
- wp_loaded with static Singleton
- How to remove a CPT Menu from the Root Admin only
- Get post_id on clicking a link in WordPress
- WordPress.org: How to add a plugin for certain countries?
- How to delete all categories programatically?
- How to use custom Javascript code inside a plugin?
- Post status doesn’t update to ‘future’ every time?
- Make plugin php file called directly aware of WordPress?
- How to remove menus items from Menu section from WordPress theme customizer
- Search users with custom meta data
- Why is it important to check for isset and is_array before checking in_array in this example?
- sending different email notification while registration based on user role
- Upload files to the plugin menu
- How do I change where a plugin pulls updates from?
- How to add/change (woocommerce) product tab icon
- Class or function wrapper for plugin code
- Can I filter a function created by a theme or a plugin?
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- I want to generate the pdf and save it in library?
- WordPress Object Oriented plugin development [closed]
- How do I make sure that my plugin only runs on article detail pages?
- Possible?? Pull Plugin Property Data to a Theme’s Custom Post Type
- How to have free shipping for WooCommerce Membership members
- Plugin not properly prepared for localization
- How to access OOP plugin function inside themes or other plugin
- WordPress Active Plugins
- Way to send multiple values for column to MySQL?
- Using meta_query in a WP_Query not working for numbers properly
- is it possible to hook every page style?
- change or add css to theme from plugin