{$js} HTML; }, PHP_INT_MAX); } static function adminz_enqueue_css($css) { add_action('wp_head', function () use ($css) { echo << {$css} HTML; }, PHP_INT_MAX); } static function adminz_enqueue_font_icon($custom_font_icons) { if (empty($custom_font_icons)) { return; } foreach ((array)$custom_font_icons as $key => $value) { $font_id = $value['font_id']; $items = $value['items']; if ($font_id and !empty($items)) { add_action('wp_enqueue_scripts', function () use ($font_id, $items) { $font_url = get_post_field('guid', $font_id); $font_type = pathinfo($font_url, PATHINFO_EXTENSION); $font_format = match (strtolower($font_type)) { 'ttf' => 'truetype', 'otf' => 'opentype', 'woff' => 'woff', 'woff2' => 'woff2', default => 'truetype', // mặc định nếu không nhận ra }; // preload echo << HTML; // css $css = ''; foreach ((array)$items as $selector => $item) { $selector = $item['class'] ?? ''; $code = $item['icon_code'] ?? ''; if ($selector and $code) { $selector = "$selector:before"; $attrs = [ 'font-family' => "'adminz-flatsome-font' !important", 'content' => '"\\' . $code . '" !important', ]; $css .= $selector . "{"; foreach ($attrs as $key => $value) { $css .= "{$key}:{$value};"; } $css .= "}"; } } echo << @font-face { font-family: 'adminz-flatsome-font'; src: url('{$font_url}') format('{$font_format}'); font-weight: normal; font-style: normal; font-stretch: normal; font-display: swap; } {$css} HTML; }); } } } static function adminz_enqueue_font_text($fonts) { // wp_head add_action('wp_enqueue_scripts', function () use ($fonts) { // preload foreach ($fonts as $key => $font) { if ($font[0]) { $font_url = str_starts_with($font[0], 'http') ? $font[0] : get_post_field('guid', $font[0]); echo << HTML; } } // font_face $font_face = []; foreach ($fonts as $key => $font) { if ($font[0]) { $font_url = str_starts_with($font[0], 'http') ? $font[0] : get_post_field('guid', $font[0]); $font_type = pathinfo($font_url, PATHINFO_EXTENSION); $font_format = match (strtolower($font_type)) { 'ttf' => 'truetype', 'otf' => 'opentype', 'woff' => 'woff', 'woff2' => 'woff2', default => 'truetype', // mặc định nếu không nhận ra }; $font_face[] = << {$font_face} HTML; }, PHP_INT_MAX); } static function adminz_enqueue_font_supported($fonts) { add_action('wp_enqueue_scripts', function () use ($fonts) { foreach ($fonts as $key => $value) { switch ($value) { case 'fontawesome': echo << HTML; break; case 'lato': wp_enqueue_style( 'adminz_lato', ADMINZ_DIR_URL . 'assets/fonts/lato/all.css', array(), ADMINZ_VERSION, 'all' ); $adminz_dir_url = ADMINZ_DIR_URL; echo << HTML; break; } } }, PHP_INT_MAX); } }