=== Snaggly ===
Contributors: thebronzepatriot
Tags: media, download, remote, optimization, performance
Requires at least: 5.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.8.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Scan selected post types for remote files and download them individually to your media library.

== Description ==

Snaggly scans the content of selected public post types for remote files and downloads them individually to your WordPress Media Library. Links must point to the file itself; Snaggly does not crawl linked webpages to find their download buttons. Published posts are scanned by default; private posts can be included in settings.

= Included in Free =

* Scan posts, pages, and custom post types for file types permitted by WordPress
* Download individual files with no lifetime download quota
* Automatically replace remote file URLs with local URLs
* Reuse previously downloaded files when duplicate grouping is enabled
* Roll back recorded URL replacements
* Progressive scanning for larger sites
* Security protections, rate limiting, and diagnostic tools

= Available in Snaggly Pro =

* Bulk and progressive downloads
* Excerpt and custom field scanning

Learn more at https://getsnaggly.com.

== Installation ==

1. Upload the snaggly folder to /wp-content/plugins/ or install the ZIP through Plugins > Add New.
2. Activate Snaggly. No license is required.
3. Open Tools > Snaggly, start a scan, and click Download beside a file.

== Frequently Asked Questions ==

= Is there a download quota? =

No. Free supports individual file downloads. Bulk downloads are available in Pro.

= Which file formats are included? =

File types permitted by WordPress and selected in Snaggly settings, including images and documents. WordPress upload security checks still apply. Existing installations retain their selected extensions.

= Can I upgrade without losing my work? =

Yes. Keep Snaggly installed and active, then install and activate the separate Snaggly Pro add-on. Both plugins run together. Deactivating Pro returns you to the core features without deleting settings, media, or URL mappings. Existing customers using the older standalone Pro plugin should follow the migration instructions supplied with the new release.

= Can it scan custom fields or custom post types? =

Custom post types are included in Snaggly. Custom field and excerpt scanning, along with bulk downloading, are provided by the separate Snaggly Pro add-on.

== External requests ==

Secure remote requests require the PHP cURL extension. Each redirect destination is validated independently. Diagnostic logs are stored in a bounded, non-autoloaded database option; older public log files are removed.

When you run a scan or view results, Snaggly can request remote file headers to check file sizes. Downloading a file requests that URL from its original host. These requests disclose your server's IP address, the requested URL, and the configured HTTP user agent to that host. The diagnostic tool, when run, checks connectivity to https://www.google.com. Snaggly does not send license information to these hosts and does not require a license or account for core features.

The optional diagnostic connectivity check runs only when you click Run Diagnostic. It sends HTTP requests to Google (https://www.google.com) to test outbound connectivity. Google receives your server IP address and the user agent "Snaggly Plugin Diagnostic"; no post content, license information, or account credentials are sent. Redirects may contact another host operated by the destination. No account is required.

Google Terms: https://policies.google.com/terms
Google Privacy: https://policies.google.com/privacy

Remote file hosts are determined by URLs in your site's content, not by a fixed Snaggly service integration. Snaggly does not load its own scripts, styles, or images from Amazon or Google CDNs. Administrators should download only files they have permission to copy.

== Screenshots ==

1. Main scanner interface
2. Settings page
3. Scan results

== Changelog ==

= 1.8.6 =
* Style the optional Pro callout and save dismissal per user across Snaggly screens.
* Protect dismissal with nonce and capability checks, accessible controls, and error recovery.

= 1.8.5 =
* Removed automatic postmeta index creation during activation. Snaggly uses WordPress's existing indexes without altering core table schemas.
* Enforce edit permissions on content replacement and rollback.
* Normalize HTTPS authorities so mixed-case URLs retain validated DNS pinning.
* Handle HTML-encoded and JSON-escaped remote URLs during replacement and rollback.
* Detect complete file URLs without truncating longer extensions, and infer safe extensions from file bytes for direct extensionless downloads.
* Scope admin styling and interactions to Snaggly, fix delayed notification cleanup, and export spreadsheet-safe CSV cells.
* Make resetting unchanged defaults succeed and respect empty export filters.

= 1.8.4 =
* Fix scans across multiple batches and scans with no selected post types.
* Bind progressive scan sessions to their owner and respect private-post permissions.
* Require upload permission for downloads and reject malformed AJAX input.
* Preserve content backslashes and keep source URL comments outside HTML attributes.
* Render notifications as text and keep certificate verification enabled outside configured development environments.
* Run legacy-log cleanup during upgrades and clean up expiring transients on uninstall.
* Reject additional special-use IP ranges, including cloud metadata and IPv6 transition addresses.


= 1.8.3 =
* Validate and pin every remote redirect; require cURL for secure connections.
* Store bounded diagnostics in the database and remove legacy public logs.
* Ignore forwarded IP headers and bind authenticated rate limits to user accounts.
* Sanitize form and imported settings consistently, rejecting malformed payloads.

= 1.8.2 =
* Remove edition restrictions on file types and custom post types.
* Implement the documented extension, MIME type, and post type filters.
* Enqueue Media Library styles and clarify external diagnostic requests.
* Validate redirect destinations and enforce transfer and imported file size limits.

= 1.8.1 =
* Fix cache invalidation compatibility on older WordPress and cache backends.
* Use WordPress post counts instead of a dynamic SQL count query.
* Keep diagnostic logs in the uploads-based Snaggly log.
* Document narrowly scoped checker exceptions for read-only filtering, URL detection, and DNS pinning.


= 1.8.0 =
* Snaggly Pro is now a separate add-on installed alongside Snaggly.
* Paid bulk and advanced-scanning implementations are excluded from core.
* Preserve Pro preferences while the add-on is inactive.


= 1.7.1 =
* New: Standalone free edition with individual image downloads from posts and pages.
* Keeps URL replacement, rollback, security protections, and progressive scanning.
* Removes license activation and paid update initialization from the free edition.
* Restricts bulk endpoints, file imports, and advanced scanning on the server.


= 1.7.0 =
* Security: Downloads are now checked against `current_user_can('edit_post', $post_id)` for the post they're attributed to, not just the plugin's own required capability — closes a gap where lowering `snaggly_required_capability` below `manage_options` could let a lower-privileged user attribute downloads to posts they can't edit.
* Fixed: The "total posts" count shown before a scan could disagree with what the scan itself would walk, because it hardcoded `publish/private/draft` instead of matching the "Scan Private Posts" setting.
* Fixed: Custom-field scanning only ever looked at plain string meta values, silently skipping structured fields (ACF repeaters/groups and similar array-shaped custom fields) that store nested arrays.
* New: A "Rollback URL Replacements" tool — the URL-mapping data "Auto-update content" was already recording per post is now actually usable to restore the original remote URLs.
* New: Media Library integration — a "Snaggly" column shows which attachments were downloaded by the plugin (and when), with a filter dropdown to view just those.
* New: A "Settings" link on the plugin's Plugins-list row.
* New: "Clear My Rate Limit" and "Clear Debug Logs" tools, and rate-limit/log statistics now included in the diagnostic report.
* Improved: Removed three settings (`custom_upload_dir`, `enable_background_processing`, `scan_timeout_handling`) that had no UI, no consumer, and no documented behavior — dead configuration that looked like it did something but didn't.
* Improved: URL replacement and rollback now apply all of a post's URL mappings in a single pass instead of one `str_replace()` per mapping, so one mapping's search/replacement string can no longer corrupt another's when one happens to be a substring of the other (e.g. a resized/query-string variant of the same base URL).

= 1.6.0 =
* Security: Fixed a stored-XSS path where scan results (post titles, filenames, URLs derived from post content) were inserted into the admin results table without HTML-escaping.
* Security: Added DNS-rebinding mitigation — remote requests now pin to the IP address that was validated moments earlier, instead of trusting a second, independent DNS resolution.
* Fixed: The "Settings saved" / "Error saving settings" admin notice could never display due to a condition that compared a nonce value against the literal string "true".
* Fixed: A non-existent `wp_max_execution_time` filter (WordPress has no such filter) has been replaced with a direct `set_time_limit()` call for large scans.
* Fixed: The "Scan Private Posts" setting previously had no effect; scans now honor it.
* Fixed: `is_url_already_downloaded()` is now public, matching how the test suite (and any integrating code) already called it.
* New: Settings UI for previously hidden-only options — Scan Excerpts, Scan Custom Fields (+ Excluded Custom Fields), Scan Private Posts, Logging Level, Batch Size, Large Site Threshold, and Rate Limiting.
* New: `snaggly_after_scan` and `snaggly_after_download` actions (documented since 1.0 but never actually fired) now fire.
* New: Diagnostic tool includes database statistics; its external connectivity checks are filterable via `snaggly_diagnostic_connectivity_urls`.
* Improved: Consolidated duplicated SSRF/URL-safety, memory-limit, and "looks like a file" logic (previously copy-pasted across three classes and already drifting) into shared utility classes.
* Improved: Removed several hundred lines of unused query-builder methods from the database optimizer.
* Improved: Activation no longer maintains a second, separate copy of the settings defaults.
* Changed: Plugin authorship transferred to Elevate The Web (https://elevatetheweb.co).

= 1.5 =
* New: Selectable user-agent option for download requests to improve compatibility with various servers

= 1.4 =
* New: Batch processing indicator for better visibility during operations
* New: Download All button for convenient bulk downloading
* Improved: Updated interface colors for a modern, cohesive look
* Fixed: Various UX/UI improvements and polish

= 1.3.1 =
* Fixed: Improved error handling for edge cases in URL validation
* Fixed: Resolved memory leak issues during large batch processing
* Fixed: Enhanced compatibility with WordPress 6.6+ admin interface
* Fixed: Corrected timeout handling for long-running scan operations
* Improved: Better logging for debugging scan and download issues
* Improved: Optimized database queries for better performance on large sites
* Security: Enhanced input sanitization for custom field scanning

= 1.3.0 =
* Enhanced error handling and logging
* Added rate limiting for AJAX endpoints
* Improved database optimization for large datasets
* Refactored long methods for better maintainability
* Added comprehensive PHPDoc blocks
* Enhanced security features

= 1.2.1 =
* Enhanced error handling and logging
* Added rate limiting for AJAX endpoints
* Improved database optimization for large datasets
* Refactored long methods for better maintainability
* Added comprehensive PHPDoc blocks
* Enhanced security features

= 1.1.0 =
* Added progressive scanning for large sites
* Improved memory management
* Enhanced error handling
* Added retry mechanisms
* Improved user interface

= 1.0.0 =
* Initial release
* Basic scanning and downloading functionality
* Settings management
* Admin interface

== Upgrade Notice ==

= 1.6.0 =
Fixes a stored-XSS issue in the scan-results table and hardens SSRF protection. Update recommended for all sites.

== Additional Information ==

The hooks below are available to developers. WordPress upload security checks still apply when extending supported file types.

= Hooks and Filters =

**Actions:**
* `snaggly_after_scan` - Fired after a scan is completed, with the array of found links
* `snaggly_after_download` - Fired after a file is downloaded, with the attachment ID, original URL, and post ID
* `snaggly_cleanup_expired_sessions` - Scheduled cleanup action

**Filters:**
* `snaggly_required_capability` - Filter required capability
* `snaggly_allowed_extensions` - Filter allowed file extensions
* `snaggly_allowed_mime_types` - Filter allowed MIME types
* `snaggly_scan_post_types` - Filter post types to scan
* `snaggly_ajax_sslverify` - Filter SSL verification
* `snaggly_allowed_remote_host` - Deny specific hosts; public-IP validation always applies
* `snaggly_diagnostic_connectivity_urls` - Filter the URLs pinged by the diagnostic tool's connectivity check
