post_content, '[frontglut_' ) ) { self::need(); } if ( is_singular() && $post && has_block( 'frontglut/dashboard', $post ) ) { self::need(); } if ( apply_filters( 'frontglut_force_assets', false ) ) { self::need(); } } /** Call from any renderer that outputs FrontGlut markup. */ public static function need() { if ( ! wp_style_is( 'frontglut', 'registered' ) ) { self::register(); } wp_enqueue_style( 'frontglut' ); wp_enqueue_script( 'frontglut' ); if ( ! self::$needed ) { self::$needed = true; wp_add_inline_style( 'frontglut', self::theme_css() ); wp_localize_script( 'frontglut', 'FrontGlut', array( 'ajax' => Ajax::url(), 'nonce' => Ajax::nonce(), 'rest' => esc_url_raw( rest_url( 'frontglut/v1/' ) ), 'i18n' => array( 'confirm' => __( 'Are you sure?', 'frontglut' ), 'saved' => __( 'Saved.', 'frontglut' ), 'error' => __( 'Something went wrong.', 'frontglut' ), 'uploading' => __( 'Uploading…', 'frontglut' ), 'remove' => __( 'Remove', 'frontglut' ), 'addrow' => __( 'Add row', 'frontglut' ), ), ) ); } } public static function theme_css() { $t = Settings::get( 'theme', array() ); $primary = sanitize_hex_color( isset( $t['primary'] ) ? $t['primary'] : '#2563eb' ); $primary = $primary ? $primary : '#2563eb'; $radius = max( 0, min( 28, (int) ( isset( $t['radius'] ) ? $t['radius'] : 10 ) ) ); $fonts = array( 'system' => 'system-ui,-apple-system,"Segoe UI",Roboto,sans-serif', 'serif' => 'Georgia,"Times New Roman",serif', 'mono' => 'ui-monospace,SFMono-Regular,Menlo,monospace', 'inherit' => 'inherit', ); $font = isset( $fonts[ $t['font'] ?? 'system' ] ) ? $fonts[ $t['font'] ?? 'system' ] : $fonts['system']; $css = ":root{--frontglut-primary:{$primary};--frontglut-radius:{$radius}px;--frontglut-font:{$font}}"; $mode = $t['mode'] ?? 'auto'; if ( 'dark' === $mode ) { $css .= ':root{color-scheme:dark}.frontglut-app,.frontglut-box{--frontglut-bg:#0f1218;--frontglut-card:#171b23;--frontglut-fg:#e8ebf0;--frontglut-mut:#9aa3b2;--frontglut-line:#2a303b}'; } return $css; } public static function admin( $hook ) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $own_pt = $screen && 0 === strpos( (string) $screen->post_type, 'frontglut_' ); if ( ! $own_pt && false === strpos( (string) $hook, 'frontglut' ) && false === strpos( (string) $hook, 'frontglut-' ) ) { return; } wp_enqueue_style( 'frontglut', FRONTGLUT_URL . 'assets/css/frontglut.css', array( 'dashicons' ), FRONTGLUT_VERSION ); wp_enqueue_style( 'frontglut-admin', FRONTGLUT_URL . 'assets/css/admin.css', array( 'frontglut' ), FRONTGLUT_VERSION ); wp_enqueue_media(); wp_enqueue_script( 'frontglut', FRONTGLUT_URL . 'assets/js/frontglut.js', array(), FRONTGLUT_VERSION, true ); wp_enqueue_script( 'frontglut-admin', FRONTGLUT_URL . 'assets/js/admin.js', array( 'frontglut', 'jquery-ui-sortable' ), FRONTGLUT_VERSION, true ); wp_localize_script( 'frontglut', 'FrontGlut', array( 'ajax' => Ajax::url(), 'nonce' => Ajax::nonce(), 'rest' => esc_url_raw( rest_url( 'frontglut/v1/' ) ), 'i18n' => array( 'confirm' => __( 'Are you sure?', 'frontglut' ), 'saved' => __( 'Saved.', 'frontglut' ), 'error' => __( 'Something went wrong.', 'frontglut' ), 'uploading' => __( 'Uploading…', 'frontglut' ), 'remove' => __( 'Remove', 'frontglut' ), 'addrow' => __( 'Add row', 'frontglut' ) ), ) ); } }