-
Notifications
You must be signed in to change notification settings - Fork 6
Prepend the textdomain to the slug #180
Prepend the textdomain to the slug #180
Conversation
If you agree with this, your call when we release it. No need to release it in |
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.
@mike-day, You put it very well:
|
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.
Hi @dreamwhisper, |
If it's alright, let's release this in the upcoming |
@kienstra It looks like a forward slash is getting left in the slug after this change. At least, that's what the failed test is showing. I'm not sure if we need to strip that out? |
Ah…let me see |
// Make sure the post_name (aka "slug") of the post and the slug in the file match. | ||
$this->assertSame( $post->post_name, $pattern['slug'] ); | ||
// Make sure the ->post_name is the same as the slug, other than the prefixed textdomain. | ||
$this->assertStringEndsWith( $post->post_name, $pattern['slug'] ); |
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.
$pattern['slug']
was '/new-pattern-originally-created-with-pattern-manager'
because prepend_textdomain()
added the /
.
The unit tests don't have a theme textdomain, so prepend_textdomain()
only prefixed /
to it, instead of a textdomain.
Now, it doesn't prefix a textdomain if there is no textdomain.
function prepend_textdomain( $name ) { | ||
return implode( | ||
'/', | ||
array_filter( [ wp_get_theme()->get( 'TextDomain' ), $name ] ) |
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.
Filters out an empty textdomain or $name
.
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.
There's both a textdomain and pattern name: yourtheme/foo-pattern-name
There's no textdomain: foo-pattern-name
There's no pattern name (shouldn't happen): yourtheme
Hi @johnstonphilip, |
@@ -128,7 +128,7 @@ public function test_slug_and_filename_stay_the_same_after_content_update() { | |||
$post->post_title = 'This title remains the same after content changes.'; | |||
$post->post_content = 'test pattern content'; | |||
$post->post_status = 'publish'; | |||
$post->post_name = 'this-slug-remains-the-same-after-content-changes'; | |||
$post->post_name = 'remains-the-same-after-content-changes'; |
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.
Hope it's OK I changed this, as it's not only the slug.
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.
Can you elaborate on that? What is it other than the slug?
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.
It's also the filename (the filename is saved as the ->post_name
, where the pattern slug is never in the WP_Post).
Happy to revert this, it's a nitpick of mine.
public function test_prepend_textdomain() { | ||
$this->assertStringEndsWith( | ||
'my-new-pattern', | ||
prepend_textdomain( 'my-new-pattern' ) |
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.
Not a complete test, but it's hard to mock wp_get_theme()
in prepend_textdomain()
, to mock the textdomain being empty.
Thanks a lot, @johnstonphilip! Happy to revert #180 (comment) if you'd like. |
…#185) * Add a naive function to update a slug * Use preg_replace() to update the slug * Fix the conversion, using addslashes * Add a helper to get whether a pattern has a pattern block * Add a function to update all patterns * Prepend the textdomain to the slug (#180) * Add a naive function to update a slug * Handle multiple attributes in pattern block * Only output the name and textdomain if they exist --------- Co-authored-by: Phil Johnston <phil.johnston@wpengine.com>
Summary of changes
An addition to #175
Prepends the texdomain to the slug. This will only apply on changing the title, or creating a new pattern.
All PM patterns created before this PR still won't have a textdomain prepended to the slug, unless they edit the title.
Before
* Slug: my-new-pattern
After
* Slug: twentytwentythree/my-new-pattern
How to test
<textdomain>/my-new-pattern*