diff --git a/dist/cms.js b/dist/cms.js index fa92bf8..f708bc0 100644 --- a/dist/cms.js +++ b/dist/cms.js @@ -4,6 +4,38 @@ function usesBlockTheme() { return !!document.querySelector('div.wp-site-blocks'); } +/** + * Detects the WordPress parent and child theme slugs. + * + * See https://core.trac.wordpress.org/changeset/59698. + * + * @returns {object} Object with fields `theme` and `parent_theme`. + */ +function getWordPressTheme() { + const theme = { + theme: null, + child_theme: null, + }; + try { + const bodyClass = document.body.classList; + + const parentTheme = Array.from( bodyClass ).find( c => c.startsWith( 'wp-theme-' ) ); + + if ( parentTheme ) { + theme.theme = parentTheme.replace( 'wp-theme-', '' ); + theme.child_theme = ''; + } + + const childTheme = Array.from( bodyClass ).find( c => c.startsWith( 'wp-child-theme-' ) ); + + if ( childTheme ) { + theme.child_theme = childTheme.replace( 'wp-child-theme-', '' ); + } + + } catch ( e ) {} + return theme; +} + // Detects if a WordPress embed block is on the page function hasWordPressEmbedBlock() { return !!document.querySelector('figure.wp-block-embed'); @@ -195,6 +227,7 @@ function usesInteractivityAPI() { } const wordpress = { + theme: getWordPressTheme(), block_theme: usesBlockTheme(), has_embed_block: hasWordPressEmbedBlock(), embed_block_count: getWordPressEmbedBlockCounts(),