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
26 changes: 22 additions & 4 deletions inc/class-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function init(): void {

add_action('init', [$this, 'register_default_styles']);

add_action('admin_init', [$this, 'enqueue_default_admin_styles']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_default_admin_styles']);

add_action('admin_init', [$this, 'enqueue_default_admin_scripts']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_default_admin_scripts']);

add_action('wp_ajax_wu_toggle_container', [$this, 'update_use_container']);

Expand Down Expand Up @@ -427,10 +427,19 @@ public function register_default_styles(): void {
/**
* Loads the default admin styles.
*
* Only enqueued on WP Ultimo admin pages to avoid loading 150KB+ of CSS
* on unrelated admin pages (e.g., Posts, Plugins, Settings).
*
* @since 2.0.0
*
* @param string $hook_suffix The current admin page hook suffix.
* @return void
*/
public function enqueue_default_admin_styles(): void {
public function enqueue_default_admin_styles(string $hook_suffix): void {

if ( ! wu_is_wu_page($hook_suffix)) {
return;
}

wp_enqueue_style('wu-admin');

Expand All @@ -441,10 +450,19 @@ public function enqueue_default_admin_styles(): void {
/**
* Loads the default admin scripts.
*
* Only enqueued on WP Ultimo admin pages to avoid loading scripts
* on unrelated admin pages (e.g., Posts, Plugins, Settings).
*
* @since 2.0.0
*
* @param string $hook_suffix The current admin page hook suffix.
* @return void
*/
public function enqueue_default_admin_scripts(): void {
public function enqueue_default_admin_scripts(string $hook_suffix): void {

if ( ! wu_is_wu_page($hook_suffix)) {
return;
}

wp_enqueue_script('wu-admin');

Expand Down
27 changes: 27 additions & 0 deletions inc/functions/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,30 @@ function wu_get_asset($asset, $assets_dir = 'img', $base_dir = 'assets') {

return wu_url("$base_dir/$assets_dir/$asset");
}

/**
* Checks if the current admin page belongs to WP Ultimo.
*
* Used to guard asset enqueues so that WP Ultimo scripts and styles are only
* loaded on WP Ultimo admin pages, not on every page in the network admin.
*
* Detection relies on the hook suffix passed to `admin_enqueue_scripts`. All
* WP Ultimo admin pages register with an ID prefixed by `wp-ultimo`, which
* WordPress uses when generating the page hook (e.g., `toplevel_page_wp-ultimo`,
* `wp-ultimo_page_wp-ultimo-settings`). The hook suffix always contains the
* page slug, so checking for `wp-ultimo` is reliable.
*
* @since 2.4.2
*
* @param string $hook_suffix The hook suffix passed to `admin_enqueue_scripts`.
* @return bool True if the current page is a WP Ultimo admin page.
*/
function wu_is_wu_page(string $hook_suffix = ''): bool {

if ('' === $hook_suffix) {
$screen = get_current_screen();
$hook_suffix = $screen ? (string) $screen->id : '';
}

return str_contains($hook_suffix, 'wp-ultimo');
}
Loading