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?
- Change Page’s Tag Using functions.php File
- Function to activate WordPress theme inside a plugin
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- shortcode doesn’t work
- What are the benefit in adding hook in the init() hook?
- building plugin and it is displaying above plugins page
- load_theme_textdomain path
- Why does my functions.php cause white-screen and media-library issues?
- How to set taxonomy in custom plugin?
- Plugin development: Buggy plugin preview
- How can i create page through plugin
- Custom license for WordPress plugin
- Does using `add_action( ‘init’…` cause performance issues?
- How to create plugin/ page that reads from database
- Plugin not properly prepared for localization
- WordPress Active Plugins
- Adding a jQuery modal dialog to the admin area
- Excluding specific post from custom next/previous theme function
- How to store a secret for a plugin inside public_html
- Cannot run script properly with my custom plugin
- Cookie value changes back to previous value after changing
- How to use functions found inside pluggable.php with my plugin files
- Is it okay to make a plugin to the WordPress repo, but limit it’s actions to maximum N events?
- AJAX update fails for public/non-admin users
- WordPress Product Detail and catalog
- Create Database Tables on Plugin Activation hook
- Change page according to fetched GET Parameters
- How to change response of admin-ajax request?
- Plugin keeps saying needs to be updated and it’s in a constant loop [closed]
- Activate plugin button do nothing [closed]
- wp_enqueue_script doesn’t load JS in plugin
- AI Code For OpenAI
- Pulsing circle before the post title (Breaking news flash)
- Why WP CLI command is not visible in VIP CLI