-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Legacy widget's preview functionality is broken when the page is moved #34011
Closed
anton-vlasenko
wants to merge
18
commits into
WordPress:trunk
from
anton-vlasenko:fix/getWPAdminURL-returns-relative-url
Closed
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9829ad8
1. Add new getWPAdminURL and setWPAdminURL functions to be able to se…
anton-vlasenko dac4f40
Use getWPAdminURL instead of addQueryArgs to generate correct absolut…
anton-vlasenko fdeac24
Use getWPAdminURL from @wordpress/url becase we removed it from util…
anton-vlasenko bf2401e
Add wpAbsoluteAdminUrl to the block editor settings.
anton-vlasenko 54238b3
Revert the changes as we are not going to implement it like that.
anton-vlasenko 7af12cd
Use an absolute URL for widget preview.
anton-vlasenko ed4d56f
Fix code style (automatic).
anton-vlasenko f11a7e7
Rename the variable.
anton-vlasenko 42a3aa0
Fix code style.
anton-vlasenko 62a956a
Remove redundant line at the end of the file.
anton-vlasenko b30ec6b
1. Check if the admin_url function exists before calling it.
anton-vlasenko 36370d9
1. Use destruct assignment to get the value of admin URL.
anton-vlasenko b6f24f3
1. Use destruct assignment to get the value of admin URL.
anton-vlasenko 288266d
Fix code style.
anton-vlasenko 198191e
Use function_exists instead of is_callable because using function_exi…
anton-vlasenko bb21211
Use context to get adminUrl value.
anton-vlasenko 2e4e645
Use context to get adminUrl value (customizer page).
anton-vlasenko 5ac6a14
Get rid of the WidgetsSettings and load preview using the new REST AP…
anton-vlasenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,19 @@ import { addQueryArgs } from '@wordpress/url'; | |
import { useState } from '@wordpress/element'; | ||
import { Placeholder, Spinner, Disabled } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
export default function Preview( { idBase, instance, isVisible } ) { | ||
const [ isLoaded, setIsLoaded ] = useState( false ); | ||
const { adminUrl } = useSelect( ( select ) => { | ||
kevin940726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return select( blockEditorStore ).getSettings(); | ||
}, [] ); | ||
|
||
const widgetPreviewUrl = ( adminUrl ?? '' ) + 'widgets.php'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we ever not have |
||
const widgetPreviewUrlQueryParameters = { | ||
'legacy-widget-preview': { idBase, instance }, | ||
}; | ||
|
||
// Resize the iframe on either the load event, or when the iframe becomes visible. | ||
const ref = useRefEffect( | ||
|
@@ -96,12 +106,10 @@ export default function Preview( { idBase, instance, isVisible } ) { | |
// TODO: This chokes when the query param is too big. | ||
// Ideally, we'd render a <ServerSideRender>. Maybe by | ||
// rendering one in an iframe via a portal. | ||
src={ addQueryArgs( 'widgets.php', { | ||
'legacy-widget-preview': { | ||
idBase, | ||
instance, | ||
}, | ||
} ) } | ||
src={ addQueryArgs( | ||
widgetPreviewUrl, | ||
widgetPreviewUrlQueryParameters | ||
) } | ||
onLoad={ ( event ) => { | ||
// To hide the scrollbars of the preview frame for some edge cases, | ||
// such as negative margins in the Gallery Legacy Widget. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we better create our own filter? This function is a shim that exists for WordPress 5.7 and may get removed so we should not tie into it. I think it's better to define something like
gutenberg_add_admin_url_to_editor_settings
and run that throughadd_filter
just likegutenberg_extend_post_editor_settings
.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.
Don't think there's a chance
admin_url()
will be missing. It is in wp-includes/link-template.php which is included before the REST API and plugins.