-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Live Preview: Show the current theme name on the theme activation mod…
…al (#57588) * Live Preview: Show the current theme name on the theme activation modal * Handle error * Update comments * Add missing period
- Loading branch information
1 parent
d6aaa3f
commit 44ba13d
Showing
3 changed files
with
62 additions
and
27 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
const ACTIVE_THEMES_URL = '/wp/v2/themes?status=active'; | ||
|
||
export function useActualCurrentTheme() { | ||
const [ currentTheme, setCurrentTheme ] = useState(); | ||
|
||
useEffect( () => { | ||
// Set the `wp_theme_preview` to empty string to bypass the createThemePreviewMiddleware. | ||
const path = addQueryArgs( ACTIVE_THEMES_URL, { | ||
context: 'edit', | ||
wp_theme_preview: '', | ||
} ); | ||
|
||
apiFetch( { path } ) | ||
.then( ( activeThemes ) => setCurrentTheme( activeThemes[ 0 ] ) ) | ||
// Do nothing | ||
.catch( () => {} ); | ||
}, [] ); | ||
|
||
return currentTheme; | ||
} |