-
Notifications
You must be signed in to change notification settings - Fork 2k
Full Site Editing: account for -wpcom suffixes on dotorg installs
#35684
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
Conversation
Themes installed from wpcom on dotorg installs will receive a `-wpcom` suffix and fail this check. Now they won't.
|
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
noahtallen
left a comment
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.
Interestingly we also rely on normalize theme slug here:
Lines 60 to 66 in 4e996aa
| public function normalize_theme_slug( $theme_slug ) { | |
| if ( 'pub/' === substr( $theme_slug, 0, 4 ) ) { | |
| $theme_slug = str_replace( 'pub/', '', $theme_slug ); | |
| } | |
| return $theme_slug; | |
| } |
We just copied the function over manually because... Iirc the context for FullSiteEditing was different from the context of WpTemplate which made it pull the wrong theme slug. I.e. it pulled the theme slug of the API wordpress instance instead of the actual site instance.
Could just add these lines there, but it may be worth putting the function somewhere which can be used by both classes.
| $theme_slug = str_replace( 'pub/', '', $theme_slug ); | ||
| } | ||
| if ( '-wpcom' === substr( $theme_slug, -6, 6 ) ) { | ||
| $theme_slug = preg_replace( '#-wpcom$#', '', $theme_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.
I wonder, from a purely performance standpoint, if it would be better to use a substr( $theme_slug, 0, -6 ) instead of the regexp, considering we know both the string length and position.
(Same could be said for the previous str_replace, btw)
It seems like a fine idea but, as these plugins may be split out in some future, we'll just leave 'em separate. If these ideas. I'll update both functions for now, using @Copons' optimization suggestion, too. |
Copons
left a comment
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.
LGTM!
Themes installed from wpcom on dotorg installs will receive a
-wpcomsuffix and fail this check. Now they won't.Testing instructions
wp shellsession on your dotorg site, verify that the following returnstrue:This is needed for Automattic/jetpack#13196