Add listing image focal-point controls - #2962
Open
RabbiIslamRony wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
What kind of change does this PR introduce?
Description
This PR adds listing-image focal-point controls to Directorist Core and keeps the editor preview compatible with the existing Fill, Fit, and Original Preview Image modes.
How to test the changes:
Any linked issues
No linked GitHub issue. Related support investigation: Directorist ticket #3199.
Checklist
Summary
150 × 150single-listing popup pre-crop and lets the existing frame crop through CSS.Product decision
xandycontract.Compatibility
50% 50%positioning.directorist-image-focal-pointutility class.Verification
Known local limitation
The configured Google Maps API project returns
ApiProjectMapErrorlocally, so the interactive Google popup could not be opened. The authenticated server-rendered popup markup, selected image fallback, focal utility class, and focal CSS variables were verified.CI note
The repository's PHPCS workflow run stops in
actions/checkoutbefore dependencies are installed or PHPCS executes. The checkout action refuses to load a fork PR head inside the currentpull_request_targetworkflow with its safe defaults. This is a base-workflow policy failure rather than a code-scan result. Scoped PHPCS, PHP syntax, JavaScript ESLint, diff whitespace, and the legacy production build passed locally.Full product and compatibility document
View the complete Image Focal Point document
Directorist Image Focal Point
Status: Implemented in Directorist Core on
codex/feature/image-focal-pointDocument type: Product guide, use-case analysis, and packaging decision
Last reviewed: August 9, 2026
Executive decision
Keep the manual Image Focal Point capability in Directorist Core. Do not release it as a separate paid extension.
The feature controls how Directorist's existing preview image is cropped inside an existing listing card. Preview-image selection, card rendering, container dimensions, and fill/fit behavior already belong to Core. Focal-point control completes that workflow by allowing the listing owner to identify the important part of the image.
The Directorist Image Gallery extension should remain responsible for advanced multi-image gallery presentation. It may consume Core focal-point data in the future, but the basic focal-point control should not require Gallery or any other extension.
Product assessment: high potential as a Core quality feature, low potential as a standalone extension.
The problem in plain language
Directorist listing cards usually display images inside fixed or responsive containers. When the source image and card have different shapes,
object-fit: coverfills the card by cropping part of the image.The browser normally crops from the center. That can hide the important subject:
Image Focal Point lets the listing owner say, “Keep this part visible.” It does not cut, resize, or modify the original image. It only changes the visual position used when Directorist displays the cropped card image.
What the feature does
The frontend Add/Edit Listing form shows a permanent Image focus panel beneath the current Preview image. It always explains the current state:
From that panel, the owner can:
For an existing published listing, the Dashboard More menu includes Edit image focus. That shortcut opens the normal Edit Listing form and moves keyboard/visual focus directly to the image-focus panel. It does not create a separate inline editor on the public listing page.
Directorist saves the chosen point and uses it when the preview image is rendered in Core archive cards.
The current feature deliberately controls position only. It does not enlarge the image or save a zoom level. This keeps the editor predictable across Directorist's Cover, Fit, and Original image modes and preserves the existing
x/yintegration contract.flowchart LR A["Administrator enables Image Focal Point"] --> B["Listing owner uploads or reorders images"] B --> C["Current Preview image shows its focus status and actions"] C --> D["Owner selects the important point"] D --> E["Directorist saves X and Y percentages"] E --> F["Core listing card uses object-position"] F --> G["Important subject remains visible across crops"]Who uses it
Directory administrator
The administrator decides whether the control is available for a directory's Images field.
Path:
The option is enabled by default. Existing directory configurations that do not contain the new option also behave as enabled, which makes the feature backward-compatible.
Listing owner
The listing owner controls the crop without needing WordPress admin access or image-editing software.
Steps:
If another image is moved into the Preview position, the control follows the new Preview image. Previously saved focal points remain associated with their listing images.
Directory visitor
The visitor does not interact with any extra control. They simply see a better-positioned listing image.
Primary use cases
Benefits
Benefits for listing owners
Benefits for directory administrators
Benefits for visitors
Benefits for Directorist as a product
How it works technically
1. Builder control
The Core Images preset field contains an
enable_image_focustoggle. This keeps the capability aligned with Directorist's directory-specific Add Listing Form builder.Implementation:
includes/modules/multi-directory-setup/builder-preset-fields.phptemplates/listing-form/fields/image_upload.php2. Frontend editor
After the EZ Media Uploader initializes, Directorist adds a persistent status/action panel for the current Preview item. Reordering or replacing the Preview image immediately updates the panel to that image's saved state. The editor supports mouse, touch, keyboard arrows, range inputs, presets, focus trapping, Escape-to-close, and a mobile scroll layout.
The Dashboard shortcut adds
directorist_edit_focus=1to the normal Edit Listing URL. The Add Listing script then finds the image field regardless of its builder section label, scrolls it into view, highlights the panel briefly, and focuses its primary action.Implementation:
assets/src/js/global/components/image-focal-point.jsassets/src/js/global/add-listing.jsassets/src/scss/component/_add-listing.scss3. Data model
Coordinates are saved as percentages from
0to100:Example:
{ "55": { "x": 50, "y": 10 } }The map is saved in listing meta:
The attachment ID is the map key. The data is listing-specific rather than globally attached to the Media Library item. Therefore, the same attachment can use different positions in different listings.
The centered default does not need its own stored record. When the owner uses Reset to center and saves the listing, Directorist removes that Preview image's custom focal entry. Existing consumers still receive and render the safe
50 / 50fallback.All submitted coordinates are numeric, sanitized, and clamped to the
0–100range. A submitted Preview image must resolve to one of the images selected for that listing.Implementation:
includes/helper-functions.phpincludes/classes/class-add-listing.phpincludes/classes/class-submission-controller.php4. Rendering
Core archive images receive two CSS custom properties:
Directorist applies them through:
The
50% 50%fallback preserves the old centered behavior for listings without focal-point data. Core applies the position to archive cards, map popup images, and Dashboard listing thumbnails. The editor reads the same normalized Preview Image configuration as the archive renderer:object-fit: cover.object-fit: containand the selected blur or color background.Focal data remains editable in every mode because map, Dashboard, custom-template, or future card surfaces may still crop the image.
Implementation:
includes/model/Listings.phpincludes/model/SingleListing.phpincludes/model/ListingDashboard.phpassets/src/scss/component/listings/_listing-card.scss5. Theme and extension integration
Templates that own their image markup can opt into the same behavior without copying Core storage logic:
directorist-image-focal-pointsets onlyobject-position; it does not impose dimensions orobject-fit. Custom templates remain responsible for their own frame and crop behavior.The normalized display configuration is filterable through
directorist_listing_preview_image_display_config. Saved coordinates remain filterable throughdirectorist_listing_image_focal_point.6. REST API
Directorist REST listing image objects include a
focal_pointvalue so non-PHP consumers can reproduce the same crop:{ "focal_point": { "x": 50, "y": 10 } }Implementation:
includes/rest-api/Version1/class-listings-controller.phpincludes/rest-api/Version2/class-listings-controller.php7. Cleanup and fallback behavior
Current scope
Included now:
Not included now:
Zoom decision
Current decision
Do not add saved zoom to the first Core focal-point release.
The present control answers one clear question: which part of the image should survive a crop? Saved zoom answers a different question: how tightly should Directorist crop the subject? Combining both immediately would turn the lightweight focal picker into a full crop editor and expand the storage, rendering, REST, compatibility, and image-quality requirements.
An editor-only magnifier is also not recommended right now. If the user can zoom while editing but that zoom is not reflected in the published image, the preview becomes misleading. Any future zoom control must represent a saved visual result rather than temporary inspection magnification.
Why zoom is deferred
xandyvaluesobject-positionSafe future implementation contract
Reconsider basic zoom only after repeated customer requests or usage evidence shows that repositioning alone does not solve common crops. If implemented, use these constraints:
1as the backward-compatible default. A practical first range is1to2, subject to image-quality validation.{"x":45,"y":30,"zoom":1.25}, but the current response remainsxandyonly.directorist-image-focal-pointapply transforms. The existing utility must remain neutral and safe for third-party templates.1×fallback for old listings and custom templates.Device-specific zoom, separate zoom values per card ratio, AI smart cropping, and advanced per-gallery-image crop tools belong in a broader Gallery or Smart Media capability rather than the basic Core focal control.
Product potential assessment
This assessment is based on the implemented workflow, the reported client problem, Directorist's current image architecture, and established focal-point behavior in WordPress and Shopify. It is not based on Directorist usage telemetry or a large customer survey.
Potential conclusion
The feature has strong adoption potential because it solves a common visual defect with little setup or performance cost. Its strongest value is retention, perceived quality, and fewer crop-related support requests—not direct standalone add-on revenue.
Core versus extension decision
Final packaging decision
Ship the manual focal-point picker as a Directorist Core image capability.
Do not make users install or purchase an extension to fix the crop of a Core listing preview image. Treat this as a quality and usability improvement to the existing Core Images field and archive renderer.
Relationship with the Image Gallery extension
Directorist Image Gallery remains a separate extension because it adds a broader gallery workflow: unlimited gallery images, gallery layouts, columns, lightbox behavior, custom dimensions, and gallery cropping.
Recommended boundary:
Future Gallery integration should read the Core focal-point API rather than duplicate storage or create a second incompatible picker.
When a premium media feature would make sense
A future premium Gallery or “Smart Media” capability could be justified if it adds substantial functionality beyond the manual Core control, such as:
The simple manual picker should remain the shared Core foundation for those advanced features.
Recommended rollout
Core release
Follow-up Core improvements
Optional Gallery enhancement
focal_pointREST value.Acceptance criteria
The feature is ready when all of the following are true:
0–100range.xandypair.Verification completed for the current implementation
823 × 1024source at its natural aspect ratio without the configured crop frame.44 × 44cover thumbnails rendered custom focal values and retained50% 50%for default images.ApiProjectMapError.300 × 173attachment source instead of a destructive150 × 150pre-crop, then applied focal positioning in CSS.390 × 844modal stayed within its viewport without internal horizontal overflow.External product and UX references
object-position.