Skip to content
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

Edit site: fix site base URL #25409

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/edit-site-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function gutenberg_edit_site_init( $hook ) {
'imageSizes' => $available_image_sizes,
'isRTL' => is_rtl(),
'maxUploadFileSize' => $max_upload_size,
'siteUrl' => site_url(),
);

list( $color_palette, ) = (array) get_theme_support( 'editor-color-palette' );
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './plugins';
import './hooks';
import registerEditSiteStore from './store';
import Editor from './components/editor';
import { findTemplate } from './utils';

const fetchLinkSuggestions = ( search, { perPage = 20 } = {} ) =>
apiFetch( {
Expand Down Expand Up @@ -52,6 +53,7 @@ const fetchLinkSuggestions = ( search, { perPage = 20 } = {} ) =>
* @param {Object} settings Editor settings.
*/
export function initialize( id, settings ) {
findTemplate.siteUrl = settings.siteUrl;
settings.__experimentalFetchLinkSuggestions = fetchLinkSuggestions;

registerEditSiteStore( { settings } );
Expand Down
6 changes: 5 additions & 1 deletion packages/edit-site/src/utils/find-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const { fetch } = window;
*/
export default async function findTemplate( path, getEntityRecords ) {
const { data } = await fetch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use apiFetch instead? I believe it might solve the issue as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to move the endpoints to use the REST API instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a requirement for apiFetch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no option in apiFetch to change the root URL. In this case, the root URL would be the site URL instead of the REST API URL.

addQueryArgs( path, { '_wp-find-template': true } )
addQueryArgs( findTemplate.siteUrl + path, {
'_wp-find-template': true,
} )
).then( ( res ) => res.json() );

let newTemplateId = data.ID;
Expand All @@ -33,3 +35,5 @@ export default async function findTemplate( path, getEntityRecords ) {

return newTemplateId;
}

findTemplate.siteUrl = '';