Opened 5 years ago
Closed 4 years ago
#48325 closed enhancement (fixed)
Additional filter in media-template.php. Let developers to hide attachment page link.
Reported by: | limera1n | Owned by: | garrett-eclipse |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch commit |
Focuses: | ui, administration | Cc: |
Description
Hi,
currently there is no easy way to hide "View attachment page" link from "media-modal" window. I think it would be great to add simple filter to disable this link and also add some HTML markups for "|" separators which can help users to use CSS selectors and style them. For example:
media-template.php, lines from 428
<div class="actions"> <?php if ( ! apply_filters( 'disable_attachment_page_link', '' ) ) : ?> <a class="view-attachment" href="{{ data.link }}"><?php _e( 'View attachment page' ); ?></a> <span class="links-separator">|</span> <?php endif; ?>
I think this feature is especially important when we don't want allow our users to access this type of pages.
Attachments (8)
Change History (28)
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
5 years ago
#2
@
5 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
4 years ago
- Keywords has-patch added; needs-patch removed
All right, I have combined both requests.
I have created a hook and checked if data.link is set.
I used a boolean to check the filter value, so if you want to disable it from a theme/plugin, you would do it like this:
<?php add_filter( 'disable_attachment_page_link', '__return_true' );
This ticket was mentioned in Slack in #core-media by florian-tiar. View the logs.
4 years ago
#6
@
4 years ago
- Keywords dev-feedback added
@Mista-Flo great work. Wondering if we need a new filter here though. If we just conditionally check for data.link
before use then users can disable using the pre-existing attachment_link
filter which lives in the get_attachment_link
used to populate data.link
. Could update the filter docblock to indicate it's now used in this case.
Most users will want to just disable all or they could conditionally run on a screen or post bases.
P.S. If a new filter is decided to be added then take a look at documenting them here;
https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#4-hooks-actions-and-filters
#7
@
4 years ago
Arg forgot to check if an existing filter was in the PHP side. Good catch thank you Garret. So IMO, it doesn’t make sense to add a new filter in the template. But what we can do is to keep a check if data.link so that empty strings won't be displayed if the user want to use the filter you mentioned. This is my proposed patch (6th).
#8
@
4 years ago
Thanks @Mista-Flo that's great, I think it's looking really well.
Only issue I see now is with the separator functionality. Prior to our changes there was always a first item so all following conditional items could just place the separator first and it would always work nicely.
Now if there's not a following item due to the conditionals we can end up with a orphaned separator on the end. There's two approaches (maybe more) not sure what's best; we could wrap conditionals around the separators to check there's going to be a following item, or we could drop them in the html and move to CSS to place as an after element only when element + element
selector works. Or there might be css we can use to hide that orphaned separator.
Thoughts?
#9
@
4 years ago
I have uploaded a new patch. I'm not a huge fan of the resulted logic (less readable), but it handles each case so we won't end up with orphaned.
The CSS way seems a bit overkill here, but if anyone feels it's better, feel free to write an updated patch.
#10
@
4 years ago
- Focuses administration added
- Keywords needs-testing added; dev-feedback removed
- Milestone changed from Future Release to 5.6
Thanks @Mista-Flo appreciate the refresh, it's looking good to me. Can't wrap my head around a simpler CSS solution so let's stick with that.
This ticket was mentioned in Slack in #core-media by florian-tiar. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 years ago
#15
follow-up:
↓ 16
@
4 years ago
Recapping discussion from today's Media scrub, ie so we don't forget:
Per @antpb
I can do the test and even run the commit. I think from the comment Garrett is feeling good about it so we really just need one more person to test and commit
#16
in reply to:
↑ 15
@
4 years ago
- Keywords commit added; needs-testing removed
- Owner set to garrett-eclipse
- Status changed from assigned to accepted
Replying to hellofromTonya / @antpb:
I can do the test and even run the commit. I think from the comment Garrett is feeling good about it so we really just need one more person to test and commit
Marking for commit, I'm happy with the logic and setup. After re-reading the thread I found my comment on adding a @since
to the attachment_link
filter to expose fact you can now disable the link via that filter. To handle that I added 48325.8.diff which is the same logic just adds a @since comment. For reference my mention of that:
comment#6:
Could update the filter docblock to indicate it's now used in this case.
Hi @limera1n,
Thanks for this report. I agree that this is not an easy thing to override at the moment. You would either need to override the whole template, or hide that link with CSS—neither a good option.
Allowing that template code to be filtered is one option for how to solve this, but I wonder if a better approach would be to update that template to check for the existence of a
data.link
value before printing the link so that this won't show up if the link value isn't available for any reason?