Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

wp-style-engine

/wp-style-engine

Generuje i audytuje CSS bloków przez publiczne funkcje Style Engine w WordPress, w tym style z presetów, selektory, konteksty i granice bezpieczeństwa reguł.

Licencja
MIT
Ostatnia zmiana repozytorium
20.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
3
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 20.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Generuje i audytuje CSS bloków przez publiczne funkcje Style Engine w WordPress, w tym style z presetów, selektory, konteksty i granice bezpieczeństwa reguł.

Oryginalny opis (EN)

Generate and audit block-style CSS with WordPress's public Style Engine functions. Covers wp_style_engine_get_styles, wp_style_engine_get_stylesheet_from_css_rules, wp_style_engine_get_stylesheet_from_context, style objects, preset tokens, selectors, rule groups, request-local contexts, optimized output, WP_Style_Engine_CSS_Declarations, WordPress 7.1 declaration options and !important support, and the security boundary around selector and at-rule input. Use when a block, theme, or plugin turns structured style data into CSS or must share generated rules without hand-building declarations.

Jak działa

  1. Choose the public entry point
  2. Generate styles for one block
  3. Compile a stylesheet
  4. WordPress 7.1 declaration objects
  5. Contexts are runtime aggregation, not persistence
  6. Security and correctness rules
  7. Related skills
  8. References
Sekcje z nagłówków SKILL.md, w oryginale · 160 linii, 740 słów
Podgląd SKILL.md
---
name: wp-style-engine
description: >-
  Generate and audit block-style CSS with WordPress's public Style Engine
  functions. Covers wp_style_engine_get_styles,
  wp_style_engine_get_stylesheet_from_css_rules,
  wp_style_engine_get_stylesheet_from_context, style objects, preset tokens,
  selectors, rule groups, request-local contexts, optimized output,
  WP_Style_Engine_CSS_Declarations, WordPress 7.1 declaration options and
  !important support, and the security boundary around selector and at-rule
  input. Use when a block, theme, or plugin turns structured style data into
  CSS or must share generated rules without hand-building declarations.
license: GPLv2-or-later
metadata:
  wp-skills-author: "Soczó Kristóf"
  wp-skills-contact: "mailto:lonsdale201@hotmail.com"
  wp-skills-plugin: "wordpress"
  wp-skills-plugin-version-tested: "6.1 - 7.1"
  wp-skills-wp-version-tested: "7.1"
  wp-skills-php-min: "7.4"
  wp-skills-last-updated: "2026-08-20"
---

# WordPress Style Engine

Use the Style Engine when input already follows WordPress's structured block
style shape or when several selector/declaration pairs must become one
stylesheet. It reduces hand-built CSS and preserves preset-token conventions,
but it is not a general CSS parser and it does not make arbitrary selectors or
at-rules trustworthy.

## Choose the public entry point

| Need | Function |
|---|---|
| Convert one block/theme style object to declarations, CSS, and class names | `wp_style_engine_get_styles()` |
| Compile multiple selector/declaration rules | `wp_style_engine_get_stylesheet_from_css_rules()` |
| Compile rules accumulated under a request-local context | `wp_style_engine_get_stylesheet_from_context()` |

Core explicitly marks `WP_Style_Engine` itself as internal and directs
extenders to `wp_style_engine_get_styles()`. Do not call its parsing,
compilation, or store methods directly merely because they are public PHP
methods.

## Generate styles for one block

```php
$generated = wp_style_engine_get_styles(
	array(
		'color'      => array( 'text' => 'var:preset|color|contrast' ),
		'dimensions' => array( 'minWidth' => '18rem' ),
	),
	array(
		'selector' => '.acme-card',
		'context'  => 'acme-card',
	)
);

$class_names = $generated['classnames'] ?? '';
$css         = $generated['css'] ?? '';
```

The return keys are conditional; do not assume `css`, `declarations`, or
`classnames` always exists. Preset strings can become CSS variables and class
names. When outputting a dynamic block, combine plugin-owned classes with
`get_block_wrapper_attributes()` and escape any additional attribute values.

WordPress 7.1 adds Style Engine support relevant to
`background.gradient` and `dimensions.minWidth`. The registered block and
theme settings still determine whether editor controls are offered; generating
CSS does not grant support to a block by itself.

## Compile a stylesheet

```php
$css = wp_style_engine_get_stylesheet_from_css_rules(
	array(
		array(
			'selector'     => '.acme-card',
			'declarations' => array(
				'color'   => '#222',
				'padding' => '1rem',
			),
		),
		array(
			'rules_group'  => '@media (max-width: 48rem)',
			'selector'     => '.acme-card',
			'declarations' => array( 'padding' => '0.75rem' ),
		),
	),
	array(
		'optimize' => true,
		'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
	)
);

if ( '' !== $css ) {
	wp_add_inline_style( 'acme-card', $css );
}
```

Rules without a non-empty selector or declarations are skipped. `rules_group`
supports parent selectors and nested at-rules, but both it and `selector` are
structural input owned by the caller. Never interpolate request data, database
labels, post content, or remote values into either field.

Declaration properties are normalized and values pass through WordPress safe
CSS filtering during compilation. That is not enough to make attacker-chosen
rule structure safe.

## WordPress 7.1 declaration objects

In WordPress 7.1, a stylesheet rule may receive a
`WP_Style_Engine_CSS_Declarations` object and retain per-declaration options.
This is the supported way to request `!important` from this API:

```php
$declarations = new WP_Style_Engine_CSS_Declarations();
$declarations->add_declaration(
	'display',
	'none',
	array( 'important' => true )
);

$css = wp_style_engine_get_stylesheet_from_css_rules(
	array(
		array(
			'selector'     => '.acme-is-hidden',
			'declarations' => $declarations,
		),
	)
);
```

Use `!important` only for a measured cascade requirement, not as a default.
The option is appended only when the filtered result is one valid declaration.
Feature-detect the WordPress version before passing the object when supporting
7.0 or older; prior versions documented declarations as arrays.

## Contexts are runtime aggregation, not persistence

Passing the same non-empty `context` and selectors stores rules in the Style
Engine registry for the current PHP request. Later,
`wp_style_engine_get_stylesheet_from_context( 'acme-card' )` compiles that
store. It does not save rules to the database or carry them into another
request.

Use a namespaced context, emit the result once, and avoid mixing unrelated
frontend/admin/editor policies into the same store. A context is an aggregation
key, not a CSS scoping boundary or an authorization mechanism.

## Security and correctness rules

- Allowlist selector patterns and rule groups; never accept raw user CSS here.
- Keep untrusted style values within a deliberately supported property map.
- Do not mistake declaration sanitization for complete CSS-policy validation.
- Do not emit the same context repeatedly or combine inline output with a
  second hand-built copy of the same rule.
- Treat empty output as valid; malformed or filtered declarations can vanish.
- Use stable plugin-owned selectors rather than generated editor class names.
- Test editor canvas and frontend separately, including WordPress 7.1's always
  iframed post editor.
- Test RTL, preset changes, user Global Styles, responsive groups, and CSS
  source order before adding specificity or `!important`.

Read `references/output-and-testing.md` for context and security probes.

## Related skills

- `wp-block-registration-and-assets` for block metadata and wrapper output.
- `block-theme-global-styles` for WordPress 7.1 theme.json responsive states.
- `wp-block-editor-iframe-compatibility` for editor asset placement.
- `wp-plugin-assets-loading` for registering and printing the target stylesheet.

## References

- WordPress core: `wp-includes/style-engine.php`.
- WordPress core: `wp-includes/style-engine/class-wp-style-engine.php`.
- WordPress core: `wp-includes/style-engine/class-wp-style-engine-css-declarations.php`.
- <https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/>
- <https://make.wordpress.org/core/2026/08/04/miscellaneous-block-editor-changes-in-wordpress-7-1/>
Pliki w paczce (3)
  • SKILL.md 7 KB
  • agents/openai.yaml 1 KB
  • references/output-and-testing.md 2 KB

Wersje

W bazie nie ma innych skilli o nazwie wp-style-engine.

Migawka bazy z 13.11.2026 · wersja paczki 1660c83fcf8a (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100html-to-block-theme
    Zamienia statyczne projekty HTML, CSS i JS lub istniejącą stronę w blokowy motyw WordPress, gotowy do użycia jako prawdziwa witryna.
  • 100change-built-theme
    Zmienia i rozbudowuje motyw blokowy WordPress zbudowany wcześniej z HTML: theme.json, szablony i style bloków.
  • 100wp-block-theme-converter
    Zamienia statyczną stronę HTML, CSS i JS w motyw blokowy WordPressa z theme.json, szablonami FSE i wzorcami bloków.
  • 90wordpress-wp-block-themes
    Pomaga w motywach blokowych WordPress: theme.json, szablony, części szablonów, wzorce i rozwiązywanie problemów w edytorze witryny.
  • 100block-theme-global-styles
    Buduje i audytuje Global Styles oraz theme.json w motywach blokowych WordPress 7.1: schemat 3, stany responsywne, pseudostany bloków, warianty stylów, walidacja i zgodność edytora z frontendem.
  • 90code-style-css
    Podpowiada zasady stylu przy edycji CSS, SCSS i bloków stylów w plikach Svelte.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.