Skip to content

Commit

Permalink
Merge branch 'main' into update-wellknown-features
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb authored Feb 4, 2025
2 parents 934c9bf + 8750d94 commit 116938f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions dist/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -195,6 +227,7 @@ function usesInteractivityAPI() {
}

const wordpress = {
theme: getWordPressTheme(),
block_theme: usesBlockTheme(),
has_embed_block: hasWordPressEmbedBlock(),
embed_block_count: getWordPressEmbedBlockCounts(),
Expand Down

0 comments on commit 116938f

Please sign in to comment.