-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add text template #49
Add text template #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kt-12 this is looking good. I am approving as I did not see the missing docblocks for test data providers as a total blocker, but if you can add them that would be great!
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a couple of things here that I think we need to address before merging.
src/wp-includes/class-wp-scripts.php
Outdated
$after_non_standalone_handle = $this->print_inline_script( $handle, 'after-non-standalone', false ); | ||
|
||
if ( $after_non_standalone_handle ) { | ||
$after_handle .= sprintf( "<script%s id='%s-js-after' type='text/template'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $after_non_standalone_handle ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach seems wrong to me. Shouldn't we instead change the value of $this->type_attr
rather than hard coding a second type attribute onto the script? You can even see in the unit tests below that the scripts are getting two type attributes applied to them. Alternately, if we don't want to update the main type_attr
property on this class, we should at least remove it when we are hard coding a text/template
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch @joemcgill. Totally my fault here, shouldn't have slipped under my radar. I was focusing on the condition and getting text/template
, I forgot to see it was injecting text/javascript
too.
Fixed now.
src/wp-includes/class-wp-scripts.php
Outdated
@@ -482,7 +498,11 @@ public function print_inline_script( $handle, $position = 'after', $display = tr | |||
$output = trim( implode( "\n", $output ), "\n" ); | |||
|
|||
if ( $display ) { | |||
printf( "<script%s id='%s-js-%s'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output ); | |||
if ( 'after-non-standalone' === $position ) { | |||
printf( "<script%s id='%s-js-after' type='text/template'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're hard coding the position in the ID here, I think we also need to remove the $position
variable that's being passed to the printf
function. We should probably add a unit test to cover this case as well.
printf( "<script%s id='%s-js-after' type='text/template'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output ); | |
printf( "<script%s id='%s-js-after' type='text/template'>\n%s\n</script>\n", $this->type_attr, esc_attr( $handle ), $output ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @joemcgill. This is fixed now.
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kt-12, this is looking better now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kt-12 I did another round of review on this and it 's looking good to me. Good catch on some of those issues @joemcgill thank you!
Implement load handlers
Trac ticket:
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.