| 开发者 |
presswell
benplum |
|---|---|
| 更新时间 | 2026年11月4日 23:42 |
| PHP版本: | 8.2 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
/pwad-image/?id=...&size=...). The plugin includes an automatic compatibility check in wp-admin.
Regenerator
The Regenerator screen (Media -> Regenerate Thumbnails) builds a queue and processes images in batches, with progress metrics and retry handling for failed jobs. You can choose exactly which sizes should be regenerated. The screen is available while Smart Cache is off; with it on, sizes are generated when first requested, and wp pwad regenerate is still available from WP-CLI.
Documentation
Public APIs
pwad_add_image_size( $args )
name, key, height, width, crop (optional), and optionally thumbnails values.[size]-[thumbnail]. Thumbnails use the parent's crop, and cropped thumbnails are kept at the parent's aspect ratio (the width is kept and the height recalculated).thumbnail, large, my-size, my-size-mobile, etc.)thumbnail, large, my-size, my-size-mobile, etc.)file, url, path (relative to uploads), height, width, and mime-type values, plus a deprecated src key (the same as url), or false. A missing size is generated (Smart Cache) or given an /pwad-image/ endpoint URL (Endpoint Mode, where path is empty). full, an unknown size key, or a size the original is too small for returns the original image.
Example:
$square_large = pwad_get_image_src( $img_ID, 'square' );
$square_small = pwad_get_image_src( $img_ID, 'square-small' );
pwad_get_focal_point( $attachment_ID )
array( 'left' => float, 'top' => float ), each from 0 to 1 measured from the left and top edges: the saved point, or the center when none is saved, after the pwad_focal_point filter.
Example:
$point = pwad_get_focal_point( $img_ID );
$position = ( $point['left'] * 100 ) . '% ' . ( $point['top'] * 100 ) . '%';
Actions
pwad/image_generated
Fires immediately after a custom crop file is generated so themes/plugins can queue optimizers or post-processing.
Arguments:
left and top, each from 0 to 1.null when the image had none.null when every image was cleared.focal_point, media (Clear Image Cache), debug (the Debug tab's rebuild), image (code calling delete_cache()), tools (Delete Cache on the Tools tab), clean (wp pwad cache-clean), or prune (wp pwad cache-prune).label (string), value (string), and status (ok, warning, or empty). Rows without a string label and value are skipped.left and top from 0 to 1 are ignored.
0.5, 0.5) when none is saved.pwad_get_image() returns. Not applied to the Art Directed Image block or wp_get_attachment_image(). Non-string return values are ignored.
<img> tag, or an empty string when the image can't be found.pwad_get_image().--queue-per-page=<int> (default 200)--batch-size=<int> (default 25)--target-seconds=<float> (default 5)--resume-last=<0|1> (default 0, continue the last interrupted queue)--sitemap=<url> (optional, auto-detects from robots.txt/common sitemap endpoints)--page-limit=<int> (default unlimited)--image-limit=<int> (default unlimited)--delay-ms=<int> (default 250)--timeout=<float> (default 10)--retries=<int> (default 2, retries image requests that fail with a server error, 500 to 504)--include-external=<0|1> (default 0)--force-endpoint=<0|1> (default 0)--report-csv=<path> (optional, writes per-URL status/error report; relative paths are saved privately in wp-content/uploads/pwad-logs/)--dry-run=<0|1> (default 0)--resume-last=<0|1> (default 0, continue the last interrupted prime run; can't be combined with --dry-run=1)--sitemap=<url> (optional, auto-detects from robots.txt/common sitemap endpoints)--batch-size=<int> (default 200)--max-images=<int> (default unlimited)--page-limit=<int> (default unlimited)--image-limit=<int> (default unlimited)--timeout=<float> (default 10)--grace-days=<int> (default 0, uses file modified time)--include-external=<0|1> (default 0)--force-endpoint=<0|1> (default 0)--report-csv=<path> (optional, writes per-file keep/delete report; relative paths are saved privately in wp-content/uploads/pwad-logs/)--dry-run=<0|1> (default 1)--resume-last=<0|1> (default 0, continue the last interrupted prune run; pass --dry-run=0 with it)--batch-size=<int> (default 200)--max-images=<int> (default unlimited)--include-default=<0|1> (default 0)--dry-run=<0|1> (default 1)--resume-last=<0|1> (default 0, continue the last interrupted clean run; pass --dry-run=0 with it)wp-content/plugins/.
Configuration
wp pwad regenerate from WP-CLI).When viewing an image in the media library click the 'Set Focal Point' button. Use the size dropdown to change the crop preview. Click and drag the blue focal point marker to identify the subject of the image. When finished, click the 'Save Focal Point' button to update the focal point settings and clear the image thumbnail cache for regeneration.
Focal points let you control crop framing across many sizes without manually defining crop coordinates for every variant.
Themes often register many custom sizes, but only a subset are used on the live site. Dynamic generation (Smart Cache) creates only the thumbnails that are actually requested. It needs pretty permalinks; with plain permalinks Smart Cache is treated as off.
Endpoint Mode serves generated images through a WordPress endpoint when your server does not pass filename-based 404 image requests to WordPress. The plugin can auto-enable this mode when compatibility checks fail.
With Smart Cache off, open Media -> Regenerate Thumbnails and run the regenerator. With Smart Cache on that screen is hidden, because sizes are generated when first requested; wp pwad regenerate works in either mode from WP-CLI.
When migrating a large site it is beneficial to delete any generated image sizes to speed up the data transfer. Images will be re-generated dynamically when requested from the new location.
Turn on Image Block Support under Settings -> Art Direction. The Image block's Resolution then lists your image sets (with core's Thumbnail, Medium, Large, and Full Size) instead of every generated size, and srcset serves each set's smaller sizes. Pick a set to choose the image's shape: it uses the set's real crop, cut around the image's focal point. The block's Art Direction panel shows which set is in use and lets you drag the image's focal point without leaving the editor, with any set's crop outlined on the image (it starts with the block's Resolution). Saving rebuilds the image's crops around the new point; the focal point belongs to the image, so it applies everywhere the image is used. The Image block's aspect ratio presets are removed, so shapes come from your sets rather than CSS crops; other blocks keep the theme's presets. Image blocks that already use an aspect ratio matching a set are served that set's crop, and other aspect ratios are centred on the image's focal point. Nothing is changed in saved posts, so turning the setting off returns everything to how it was.
Add the Art Directed Image block. Choose an image, then pick an image set for Desktop, Tablet, and Mobile in the block's sidebar; tablet uses the desktop crop and mobile uses the tablet crop unless you choose another. Choosing a device also switches the editor's preview, so the canvas shows the crop you're working on. The block outputs a <picture> element, so browsers download only the crop that fits the screen.
The breakpoints come from WordPress itself (480px for mobile and 782px for tablet by default, or your theme's settings.viewport in theme.json), so crops switch exactly where the editor's device preview and the theme's responsive styles do. The block has the same focal point editor as the Image block, plus alt text, a caption, alignment, and a transform to and from the Image block.
Settings -> Art Direction -> Debug has a status table covering how images are generated and served (Smart Cache, Compatibility Mode, missing file requests, the image editor, the uploads folder, and custom sizes), focal points, the last regenerator and cache command runs, and any conflicting plugins. It also has an image debugger that shows every size and URL for one image, and the private debug log.
pwad/image_generated action for post-processing.