add ability to remove dns-prefetch or preconnect link tags#1023
add ability to remove dns-prefetch or preconnect link tags#1023aatanasov-cloudinary merged 2 commits intocloudinary:developfrom
Conversation
|
@tharsheblows, please check. |
tharsheblows
left a comment
There was a problem hiding this comment.
@atdcloud I've left a comment -- it's not necessarily a blocker but will make the filter a bit easier to use and understand.
Is there somewhere where we should add documentation about the filter?
php/class-delivery.php
Outdated
| */ | ||
| public function dns_prefetch( $urls, $relation_type ) { | ||
|
|
||
| $relation_type = apply_filters('cld_dns_prefetch', $relation_type); |
There was a problem hiding this comment.
📝 note
This will work but I think the way to do it is something like below. It keeps it a bit more understandable when looking at the code.
...
$dns_prefetch_types = apply_filters( 'cld_dns_prefetch_types', array ( 'dns-prefetch', 'preconnect' ) );
if ( in_array( $relation_type, $dns_prefetch_types, true ) {
...
There was a problem hiding this comment.
hmmm...I think the IF clause that evaluates the $relation_type is already a dead giveaway.
There was a problem hiding this comment.
I think we should do a couple of things here:
- Avoid using the words
prefetch_typesin filter and variable names, as it's a misnomer. Let's useresource_hints. - I support using
in_arrayto explicitly search through an array instead of mutating$relation_type. In fact, mutating it has no purpose, as the$relation_typesets the context for the entire method and should, in my opinion, be treated as immutable.
...
$resource_hints = apply_filters( 'cld_resource_hints', array ( 'dns-prefetch', 'preconnect' ) );
if ( in_array( $relation_type, $resource_hints, true ) {
...There was a problem hiding this comment.
... and we need to add a hook comment above the new hook in order to make sure the generated documentation is correctly created.
Issue: #1022
Approach
Implemented apply_filters in setup_hooks
QA notes
Simple hooks and implemented in test environment.