Skip to content
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
12 changes: 1 addition & 11 deletions classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
*/
class Page {

/**
* Whether the branding inline styles have been added.
*
* @var boolean
*/
protected static $branding_inline_styles_added = false;

/**
* Constructor.
*/
Expand Down Expand Up @@ -285,10 +278,7 @@ public function enqueue_styles() {

\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/variables-color' );
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/admin' );
if ( ! static::$branding_inline_styles_added ) {
\wp_add_inline_style( 'progress-planner/admin', \progress_planner()->get_ui__branding()->get_custom_css() );
static::$branding_inline_styles_added = true;
}
\progress_planner()->get_ui__branding()->enqueue_inline_css( 'progress-planner/admin' );
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/web-components/prpl-tooltip' );
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/web-components/prpl-install-plugin' );

Expand Down
31 changes: 31 additions & 0 deletions classes/ui/class-branding.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ final class Branding {
'default' => 0,
];

/**
* Style handles that have already received the branding inline CSS this request.
*
* @var array<string, bool>
*/
private static $inline_css_attached = [];

/**
* Constructor.
*/
Expand Down Expand Up @@ -124,6 +131,30 @@ public function get_custom_css(): string {
: $this->get_api_data()['custom_css'];
}

/**
* Attach the branding custom CSS to a registered/enqueued stylesheet.
*
* Idempotent per handle within a single request, so callers do not need to
* track whether the CSS has already been added.
*
* @param string $handle The style handle to attach the inline CSS to.
*
* @return void
*/
public function enqueue_inline_css( string $handle ): void {
if ( isset( self::$inline_css_attached[ $handle ] ) ) {
return;
}
self::$inline_css_attached[ $handle ] = true;

$css = $this->get_custom_css();
if ( '' === $css ) {
return;
}

\wp_add_inline_style( $handle, $css );
}

/**
* Get the admin-menu icon.
*
Expand Down
Loading