| 1 |
import { updatePageTitlePattern } from '@page-creator/api/WPApi'; |
| 2 |
import apiFetch from '@wordpress/api-fetch'; |
| 3 |
import { decodeEntities } from '@wordpress/html-entities'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Overwrite the theme’s default “page-with-title” template with the |
| 7 |
* stored page-title pattern, but only if the template has never been |
| 8 |
*/ |
| 9 |
export const syncPageTitleTemplate = async (pageTitlePattern) => { |
| 10 |
if (!pageTitlePattern) return; |
| 11 |
|
| 12 |
const tpl = await apiFetch({ |
| 13 |
path: '/wp/v2/templates/extendable//page-with-title', |
| 14 |
}); |
| 15 |
|
| 16 |
if (tpl.source === 'theme') { |
| 17 |
await updatePageTitlePattern(decodeEntities(pageTitlePattern)); |
| 18 |
} |
| 19 |
}; |
| 20 |
|