@wp-operations/wp-ops 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/package.json +6 -2
  2. package/src/commands/platform.js +16 -2
  3. package/src/main.js +9 -3
  4. package/wp-operations/CHANGELOG.md +14 -0
  5. package/wp-operations/README.md +39 -0
  6. package/wp-operations/agents/builder/AGENT.md +15 -0
  7. package/wp-operations/assets/admin.css +631 -0
  8. package/wp-operations/assets/admin.js +614 -0
  9. package/wp-operations/assets/app/app.css +1 -0
  10. package/wp-operations/assets/app/app.js +70 -0
  11. package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
  12. package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
  13. package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
  14. package/wp-operations/assets/app/login.css +42 -0
  15. package/wp-operations/assets/brand/icon.svg +20 -0
  16. package/wp-operations/assets/brand/mark.svg +19 -0
  17. package/wp-operations/assets/editors/audiobook.css +311 -0
  18. package/wp-operations/assets/editors/audiofile.css +286 -0
  19. package/wp-operations/assets/editors/course.css +701 -0
  20. package/wp-operations/assets/editors/course.js +698 -0
  21. package/wp-operations/assets/editors/faq.css +258 -0
  22. package/wp-operations/assets/editors/faq.js +196 -0
  23. package/wp-operations/assets/editors/interactive.css +220 -0
  24. package/wp-operations/assets/editors/interactive.js +378 -0
  25. package/wp-operations/assets/editors/media-sources.css +3 -0
  26. package/wp-operations/assets/editors/media-sources.js +40 -0
  27. package/wp-operations/assets/editors/open-media.css +114 -0
  28. package/wp-operations/assets/editors/open-media.js +182 -0
  29. package/wp-operations/assets/editors/thumbnails.css +335 -0
  30. package/wp-operations/assets/editors/thumbnails.js +447 -0
  31. package/wp-operations/assets/editors/translator.css +818 -0
  32. package/wp-operations/functions.php +24 -0
  33. package/wp-operations/index.php +14 -0
  34. package/wp-operations/platform.json +1836 -0
  35. package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
  36. package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
  37. package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
  38. package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
  39. package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
  40. package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
  41. package/wp-operations/skills/wp-security/SKILL.md +90 -0
  42. package/wp-operations/src/Admin.php +78 -0
  43. package/wp-operations/src/App/Access.php +57 -0
  44. package/wp-operations/src/App/Admin.php +442 -0
  45. package/wp-operations/src/App/App.php +157 -0
  46. package/wp-operations/src/App/Apps.php +379 -0
  47. package/wp-operations/src/App/Bundle.php +111 -0
  48. package/wp-operations/src/App/Contents.php +676 -0
  49. package/wp-operations/src/App/Engine.php +554 -0
  50. package/wp-operations/src/App/Github.php +308 -0
  51. package/wp-operations/src/App/Module.php +23 -0
  52. package/wp-operations/src/App/Ops.php +470 -0
  53. package/wp-operations/src/App/Packages.php +289 -0
  54. package/wp-operations/src/App/Rest.php +539 -0
  55. package/wp-operations/src/App/Sandboxes.php +206 -0
  56. package/wp-operations/src/App/Store.php +104 -0
  57. package/wp-operations/src/App/Usage.php +268 -0
  58. package/wp-operations/src/Config.php +249 -0
  59. package/wp-operations/src/Content/Editor.php +223 -0
  60. package/wp-operations/src/Content/Fields.php +681 -0
  61. package/wp-operations/src/Content/Scoring.php +253 -0
  62. package/wp-operations/src/Content/Structure.php +293 -0
  63. package/wp-operations/src/Content/Types.php +150 -0
  64. package/wp-operations/src/Content/Uploads.php +50 -0
  65. package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
  66. package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
  67. package/wp-operations/src/Editors/AudiobookCover.php +235 -0
  68. package/wp-operations/src/Editors/Audiofile.php +462 -0
  69. package/wp-operations/src/Editors/Course.php +784 -0
  70. package/wp-operations/src/Editors/Ebook.php +242 -0
  71. package/wp-operations/src/Editors/Editors.php +44 -0
  72. package/wp-operations/src/Editors/Faq.php +237 -0
  73. package/wp-operations/src/Editors/Files.php +139 -0
  74. package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
  75. package/wp-operations/src/Editors/Interactive/Card.php +76 -0
  76. package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
  77. package/wp-operations/src/Editors/Interactive/Field.php +272 -0
  78. package/wp-operations/src/Editors/Interactive/Map.php +84 -0
  79. package/wp-operations/src/Editors/Interactive/Models.php +227 -0
  80. package/wp-operations/src/Editors/Interactive/Report.php +59 -0
  81. package/wp-operations/src/Editors/Interactive/Save.php +323 -0
  82. package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
  83. package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
  84. package/wp-operations/src/Editors/Legal.php +235 -0
  85. package/wp-operations/src/Editors/OpenMedia.php +140 -0
  86. package/wp-operations/src/Editors/OriginalTitle.php +112 -0
  87. package/wp-operations/src/Editors/Sources.php +28 -0
  88. package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
  89. package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
  90. package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
  91. package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
  92. package/wp-operations/src/Editors/Translator/Admin.php +913 -0
  93. package/wp-operations/src/Editors/Translator/Api.php +63 -0
  94. package/wp-operations/src/Editors/Translator/Bar.php +83 -0
  95. package/wp-operations/src/Editors/Translator/Fields.php +273 -0
  96. package/wp-operations/src/Editors/Translator/Storage.php +131 -0
  97. package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
  98. package/wp-operations/src/Identity.php +104 -0
  99. package/wp-operations/src/Languages.php +45 -0
  100. package/wp-operations/src/Lockdown.php +85 -0
  101. package/wp-operations/src/Modules/Apps/Admin.php +472 -0
  102. package/wp-operations/src/Modules/Apps/Api.php +193 -0
  103. package/wp-operations/src/Modules/Apps/Apps.php +279 -0
  104. package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
  105. package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
  106. package/wp-operations/src/Modules/Apps/Table.php +101 -0
  107. package/wp-operations/src/Modules/Thumbnails.php +68 -0
  108. package/wp-operations/src/Modules/Translations.php +133 -0
  109. package/wp-operations/src/Platform.php +59 -0
  110. package/wp-operations/src/Setup.php +273 -0
  111. package/wp-operations/src/Status.php +99 -0
  112. package/wp-operations/src/Storage/Client.php +168 -0
  113. package/wp-operations/src/Storage/Offload.php +120 -0
  114. package/wp-operations/src/Storage/Settings.php +166 -0
  115. package/wp-operations/src/Storage/Storage.php +35 -0
  116. package/wp-operations/src/Updates.php +151 -0
  117. package/wp-operations/style.css +11 -0
@@ -0,0 +1,103 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Builder {
7
+ public static function register(): void {
8
+ add_action( 'wp_ajax_interactive_add_child', [ __CLASS__, 'add_child' ] );
9
+ add_action( 'wp_ajax_interactive_delete_child', [ __CLASS__, 'delete_child' ] );
10
+ add_action( 'wp_ajax_interactive_sort_children', [ __CLASS__, 'sort_children' ] );
11
+ add_action( 'before_delete_post', [ __CLASS__, 'delete_children' ] );
12
+ }
13
+
14
+ public static function add_child(): void {
15
+ self::verify();
16
+
17
+ $parent_id = absint( $_POST['parent'] ?? 0 );
18
+ $parent_type = sanitize_key( $_POST['type'] ?? '' );
19
+
20
+ if ( ! $parent_id || ! Map::supports( $parent_type ) ) {
21
+ wp_send_json_error( [ 'message' => __( 'Unknown parent.' ) ] );
22
+ }
23
+
24
+ if ( ! current_user_can( 'edit_post', $parent_id ) ) {
25
+ wp_send_json_error( [ 'message' => __( 'Not allowed.' ) ] );
26
+ }
27
+
28
+ $config = Map::get( $parent_type );
29
+ $count = count( Structure::children( $parent_id, $config['child'] ) );
30
+
31
+ $child_id = wp_insert_post( [
32
+ 'post_type' => $config['child'],
33
+ 'post_title' => sprintf( '%s %d', $config['child_label'], $count + 1 ),
34
+ 'post_status' => 'publish',
35
+ 'post_parent' => $parent_id,
36
+ 'menu_order' => $count + 1,
37
+ ], true );
38
+
39
+ if ( is_wp_error( $child_id ) ) {
40
+ wp_send_json_error( [ 'message' => $child_id->get_error_message() ] );
41
+ }
42
+
43
+ ob_start();
44
+ Structure::child( get_post( $child_id ), $parent_type );
45
+
46
+ wp_send_json_success( [ 'html' => ob_get_clean() ] );
47
+ }
48
+
49
+ public static function delete_child(): void {
50
+ self::verify();
51
+
52
+ $child_id = absint( $_POST['child'] ?? 0 );
53
+
54
+ if ( ! $child_id || ! current_user_can( 'delete_post', $child_id ) ) {
55
+ wp_send_json_error( [ 'message' => __( 'Not allowed.' ) ] );
56
+ }
57
+
58
+ if ( ! in_array( get_post_type( $child_id ), Map::children(), true ) ) {
59
+ wp_send_json_error( [ 'message' => __( 'Unknown item.' ) ] );
60
+ }
61
+
62
+ wp_delete_post( $child_id, true );
63
+
64
+ wp_send_json_success();
65
+ }
66
+
67
+ public static function sort_children(): void {
68
+ self::verify();
69
+
70
+ $order = array_map( 'absint', (array) ( $_POST['order'] ?? [] ) );
71
+
72
+ foreach ( $order as $position => $child_id ) {
73
+ if ( ! $child_id || ! current_user_can( 'edit_post', $child_id ) ) {
74
+ continue;
75
+ }
76
+
77
+ wp_update_post( [
78
+ 'ID' => $child_id,
79
+ 'menu_order' => $position + 1,
80
+ ] );
81
+ }
82
+
83
+ wp_send_json_success();
84
+ }
85
+
86
+ public static function delete_children( int $post_id ): void {
87
+ $type = (string) get_post_type( $post_id );
88
+
89
+ if ( ! Map::supports( $type ) || Map::child( $type ) === '' ) {
90
+ return;
91
+ }
92
+
93
+ foreach ( Structure::children( $post_id, Map::child( $type ) ) as $child ) {
94
+ wp_delete_post( $child->ID, true );
95
+ }
96
+ }
97
+
98
+ private static function verify(): void {
99
+ if ( ! check_ajax_referer( 'interactive_builder', 'nonce', false ) ) {
100
+ wp_send_json_error( [ 'message' => __( 'Security check failed.' ) ] );
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,76 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Card {
7
+ public static function register(): void {
8
+ foreach ( Map::with_box( 'card' ) as $type ) {
9
+ add_meta_box(
10
+ 'card',
11
+ __( 'Card' ),
12
+ [ __CLASS__, 'render' ],
13
+ $type,
14
+ 'side',
15
+ 'default'
16
+ );
17
+ }
18
+ }
19
+
20
+ public static function nonce( \WP_Post $post ): void {
21
+ if ( Map::supports( $post->post_type ) ) {
22
+ wp_nonce_field( 'interactive_save', 'interactive_nonce' );
23
+ }
24
+ }
25
+
26
+ public static function render( \WP_Post $post ): void {
27
+ Field::reset();
28
+
29
+ echo '<div class="interactive-panel">';
30
+
31
+ Field::text(
32
+ '_icon',
33
+ __( 'Icon name' ),
34
+ (string) get_post_meta( $post->ID, '_icon', true )
35
+ );
36
+
37
+ Field::number(
38
+ '_minutes',
39
+ __( 'Minutes to complete' ),
40
+ get_post_meta( $post->ID, '_minutes', true ),
41
+ [ 'step' => '1' ]
42
+ );
43
+
44
+ Field::text(
45
+ '_rating',
46
+ __( 'Rating' ),
47
+ (string) get_post_meta( $post->ID, '_rating', true )
48
+ );
49
+
50
+ Field::number(
51
+ '_reviews',
52
+ __( 'Review count' ),
53
+ get_post_meta( $post->ID, '_reviews', true ),
54
+ [ 'step' => '1' ]
55
+ );
56
+
57
+ Field::select(
58
+ '_unlock',
59
+ __( 'Order' ),
60
+ (string) get_post_meta( $post->ID, '_unlock', true ),
61
+ [
62
+ 'open' => __( 'Open, any part can be started' ),
63
+ 'sequential' => __( 'Sequential, each part unlocks the next' ),
64
+ ]
65
+ );
66
+
67
+ Field::textarea(
68
+ '_intro_points',
69
+ __( 'Intro points, one per line' ),
70
+ Field::array_to_lines( get_post_meta( $post->ID, '_intro_points', true ) ),
71
+ [ 'rows' => 4 ]
72
+ );
73
+
74
+ echo '</div>';
75
+ }
76
+ }
@@ -0,0 +1,42 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ use Platform\Platform;
5
+
6
+ defined( 'ABSPATH' ) || exit;
7
+
8
+ final class Editor {
9
+
10
+ public static function register(): void {
11
+ add_action( 'edit_form_after_title', [ Card::class, 'nonce' ] );
12
+ add_action( 'add_meta_boxes', [ Card::class, 'register' ] );
13
+ add_action( 'add_meta_boxes', [ Scoring::class, 'register' ] );
14
+ add_action( 'add_meta_boxes', [ Structure::class, 'register' ] );
15
+ add_action( 'add_meta_boxes', [ Report::class, 'register' ] );
16
+ add_action( 'save_post', [ Save::class, 'handle' ], 10, 2 );
17
+ add_action( 'admin_enqueue_scripts', [ __CLASS__, 'assets' ] );
18
+ Builder::register();
19
+ }
20
+
21
+ public static function assets( string $hook ): void {
22
+ if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) {
23
+ return;
24
+ }
25
+
26
+ $screen = get_current_screen();
27
+
28
+ if ( ! $screen || ! Map::supports( $screen->post_type ) ) {
29
+ return;
30
+ }
31
+
32
+ wp_enqueue_style( 'interactive-admin', Platform::url( 'assets/editors/interactive.css' ), [], Platform::asset_version( 'assets/editors/interactive.css' ) );
33
+ wp_enqueue_script( 'interactive-admin', Platform::url( 'assets/editors/interactive.js' ), [], Platform::asset_version( 'assets/editors/interactive.js' ), true );
34
+ wp_localize_script( 'interactive-admin', 'InteractiveCMS', [
35
+ 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
36
+ 'nonce' => wp_create_nonce( 'interactive_builder' ),
37
+ 'models' => Models::for_script(),
38
+ 'confirmRow' => __( 'Remove this row?' ),
39
+ 'confirmAll' => sprintf( __( 'Delete this %s and everything in it?' ), strtolower( Map::child_label( $screen->post_type ) ) ),
40
+ ] );
41
+ }
42
+ }
@@ -0,0 +1,272 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Field {
7
+ private static array $stack = [];
8
+
9
+ public static function push( string $segment ): void {
10
+ self::$stack[] = $segment;
11
+ }
12
+
13
+ public static function pop(): void {
14
+ array_pop( self::$stack );
15
+ }
16
+
17
+ public static function reset(): void {
18
+ self::$stack = [];
19
+ }
20
+
21
+ public static function name( string $key ): string {
22
+ $segments = self::$stack;
23
+ $segments[] = $key;
24
+
25
+ $head = array_shift( $segments );
26
+
27
+ return $head . implode( '', array_map( static fn( $s ) => '[' . $s . ']', $segments ) );
28
+ }
29
+
30
+ public static function text( string $key, string $label, string $value, array $args = [] ): void {
31
+ self::open_field( $label, $args );
32
+ printf(
33
+ '<input type="text" name="%s" data-key="%s" value="%s"%s />',
34
+ esc_attr( self::name( $key ) ),
35
+ esc_attr( $key ),
36
+ esc_attr( $value ),
37
+ self::extra_attrs( $args )
38
+ );
39
+ self::close_field();
40
+ }
41
+
42
+ public static function number( string $key, string $label, $value, array $args = [] ): void {
43
+ self::open_field( $label, $args );
44
+ printf(
45
+ '<input type="number" step="%s" name="%s" data-key="%s" value="%s"%s />',
46
+ esc_attr( $args['step'] ?? 'any' ),
47
+ esc_attr( self::name( $key ) ),
48
+ esc_attr( $key ),
49
+ esc_attr( (string) $value ),
50
+ self::extra_attrs( $args )
51
+ );
52
+ self::close_field();
53
+ }
54
+
55
+ public static function select( string $key, string $label, string $value, array $options, array $args = [] ): void {
56
+ self::open_field( $label, $args );
57
+ printf(
58
+ '<select name="%s" data-key="%s"%s>',
59
+ esc_attr( self::name( $key ) ),
60
+ esc_attr( $key ),
61
+ self::extra_attrs( $args )
62
+ );
63
+
64
+ if ( ! empty( $args['empty'] ) ) {
65
+ printf( '<option value="">%s</option>', esc_html( $args['empty'] ) );
66
+ }
67
+
68
+ foreach ( $options as $option_value => $option_label ) {
69
+ printf(
70
+ '<option value="%s"%s>%s</option>',
71
+ esc_attr( (string) $option_value ),
72
+ selected( $value, (string) $option_value, false ),
73
+ esc_html( $option_label )
74
+ );
75
+ }
76
+
77
+ echo '</select>';
78
+ self::close_field();
79
+ }
80
+
81
+ public static function checkbox( string $key, string $label, $value, array $args = [] ): void {
82
+ printf( '<p class="field field-check"%s>', self::need_attr( $args ) );
83
+ printf(
84
+ '<label><input type="hidden" name="%1$s" data-key="%2$s" value="0" /><input type="checkbox" name="%1$s" data-key="%2$s" value="1"%3$s /> %4$s</label>',
85
+ esc_attr( self::name( $key ) ),
86
+ esc_attr( $key ),
87
+ checked( (string) $value, '1', false ),
88
+ esc_html( $label )
89
+ );
90
+ echo '</p>';
91
+ }
92
+
93
+ public static function textarea( string $key, string $label, string $value, array $args = [] ): void {
94
+ self::open_field( $label, $args );
95
+ printf(
96
+ '<textarea name="%s" data-key="%s" rows="%d"%s>%s</textarea>',
97
+ esc_attr( self::name( $key ) ),
98
+ esc_attr( $key ),
99
+ (int) ( $args['rows'] ?? 3 ),
100
+ self::extra_attrs( $args ),
101
+ esc_textarea( $value )
102
+ );
103
+ self::close_field();
104
+ }
105
+
106
+ public static function repeater( string $key, array $rows, callable $render, array $args = [] ): void {
107
+ $add = $args['add'] ?? __( 'Add row' );
108
+
109
+ printf(
110
+ '<div class="rep" data-rep="%s">',
111
+ esc_attr( $key )
112
+ );
113
+
114
+ if ( ! empty( $args['label'] ) ) {
115
+ printf( '<span class="rep-label">%s</span>', esc_html( $args['label'] ) );
116
+ }
117
+
118
+ self::push( $key );
119
+
120
+ echo '<div class="rep-list">';
121
+
122
+ foreach ( array_values( $rows ) as $index => $row ) {
123
+ self::push( (string) $index );
124
+ echo '<div class="rep-row">';
125
+ echo '<span class="rep-handle dashicons dashicons-menu"></span>';
126
+ $render( is_array( $row ) ? $row : [] );
127
+ echo '<button type="button" class="button-link rep-remove dashicons dashicons-no-alt"></button>';
128
+ echo '</div>';
129
+ self::pop();
130
+ }
131
+
132
+ echo '</div>';
133
+
134
+ self::push( '0' );
135
+ echo '<template class="rep-template">';
136
+ echo '<div class="rep-row">';
137
+ echo '<span class="rep-handle dashicons dashicons-menu"></span>';
138
+ $render( [] );
139
+ echo '<button type="button" class="button-link rep-remove dashicons dashicons-no-alt"></button>';
140
+ echo '</div>';
141
+ echo '</template>';
142
+ self::pop();
143
+
144
+ self::pop();
145
+
146
+ printf( '<button type="button" class="button rep-add">%s</button>', esc_html( $add ) );
147
+
148
+ echo '</div>';
149
+ }
150
+
151
+ public static function lines_to_array( $raw ): array {
152
+ if ( ! is_string( $raw ) || trim( $raw ) === '' ) {
153
+ return [];
154
+ }
155
+
156
+ $lines = preg_split( '/\r\n|\r|\n/', $raw );
157
+ $out = [];
158
+
159
+ foreach ( $lines as $line ) {
160
+ $line = sanitize_text_field( $line );
161
+ if ( $line !== '' ) {
162
+ $out[] = $line;
163
+ }
164
+ }
165
+
166
+ return $out;
167
+ }
168
+
169
+ public static function array_to_lines( $value ): string {
170
+ return is_array( $value ) ? implode( "\n", $value ) : '';
171
+ }
172
+
173
+ public static function pairs_to_array( $raw ): array {
174
+ $out = [];
175
+
176
+ foreach ( self::lines_to_array( $raw ) as $line ) {
177
+ if ( strpos( $line, ':' ) === false ) {
178
+ continue;
179
+ }
180
+
181
+ [ $pair_key, $pair_value ] = array_map( 'trim', explode( ':', $line, 2 ) );
182
+
183
+ if ( $pair_key === '' ) {
184
+ continue;
185
+ }
186
+
187
+ $out[ preg_replace( '/[^A-Za-z0-9_\-]/', '', $pair_key ) ] = $pair_value;
188
+ }
189
+
190
+ return $out;
191
+ }
192
+
193
+ public static function array_to_pairs( $value ): string {
194
+ if ( ! is_array( $value ) ) {
195
+ return '';
196
+ }
197
+
198
+ $lines = [];
199
+
200
+ foreach ( $value as $pair_key => $pair_value ) {
201
+ $lines[] = $pair_key . ': ' . ( is_scalar( $pair_value ) ? $pair_value : '' );
202
+ }
203
+
204
+ return implode( "\n", $lines );
205
+ }
206
+
207
+ public static function rows( int $post_id, string $key ): array {
208
+ $value = get_post_meta( $post_id, $key, true );
209
+
210
+ return is_array( $value ) ? $value : [];
211
+ }
212
+
213
+ public static function keys_of( array $rows, string $column ): array {
214
+ $out = [];
215
+
216
+ foreach ( $rows as $row ) {
217
+ if ( ! empty( $row[ $column ] ) ) {
218
+ $out[] = (string) $row[ $column ];
219
+ }
220
+ }
221
+
222
+ return array_values( array_unique( $out ) );
223
+ }
224
+
225
+ public static function datalist( string $id, array $values ): void {
226
+ printf( '<datalist id="%s">', esc_attr( $id ) );
227
+
228
+ foreach ( $values as $value ) {
229
+ printf( '<option value="%s"></option>', esc_attr( $value ) );
230
+ }
231
+
232
+ echo '</datalist>';
233
+ }
234
+
235
+ private static function open_field( string $label, array $args ): void {
236
+ printf(
237
+ '<p class="field%s"%s>',
238
+ isset( $args['width'] ) ? ' field-' . esc_attr( $args['width'] ) : '',
239
+ self::need_attr( $args )
240
+ );
241
+
242
+ if ( $label !== '' ) {
243
+ printf( '<label>%s</label>', esc_html( $label ) );
244
+ }
245
+ }
246
+
247
+ private static function close_field(): void {
248
+ echo '</p>';
249
+ }
250
+
251
+ private static function need_attr( array $args ): string {
252
+ return empty( $args['need'] ) ? '' : sprintf( ' data-need="%s"', esc_attr( $args['need'] ) );
253
+ }
254
+
255
+ private static function extra_attrs( array $args ): string {
256
+ $out = '';
257
+
258
+ if ( ! empty( $args['list'] ) ) {
259
+ $out .= sprintf( ' list="%s"', esc_attr( $args['list'] ) );
260
+ }
261
+
262
+ if ( ! empty( $args['placeholder'] ) ) {
263
+ $out .= sprintf( ' placeholder="%s"', esc_attr( $args['placeholder'] ) );
264
+ }
265
+
266
+ if ( ! empty( $args['class'] ) ) {
267
+ $out .= sprintf( ' class="%s"', esc_attr( $args['class'] ) );
268
+ }
269
+
270
+ return $out;
271
+ }
272
+ }
@@ -0,0 +1,84 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Map {
7
+ public static function all(): array {
8
+ return [
9
+ 'surveys' => [
10
+ 'child' => 'sections',
11
+ 'child_label' => __( 'Section' ),
12
+ 'group_label' => __( 'Sections' ),
13
+ 'items_key' => '_items',
14
+ 'items_label' => __( 'Questions' ),
15
+ 'taxonomy' => 'survey-category',
16
+ 'staged' => true,
17
+ 'boxes' => [ 'card', 'scoring', 'structure', 'report' ],
18
+ ],
19
+ 'quizzes' => [
20
+ 'child' => 'levels',
21
+ 'child_label' => __( 'Level' ),
22
+ 'group_label' => __( 'Levels' ),
23
+ 'items_key' => '_questions',
24
+ 'items_label' => __( 'Questions' ),
25
+ 'taxonomy' => 'quiz-category',
26
+ 'staged' => false,
27
+ 'boxes' => [ 'card', 'scoring', 'structure', 'report' ],
28
+ ],
29
+ ];
30
+ }
31
+
32
+ public static function supports( string $type ): bool {
33
+ return isset( self::all()[ $type ] );
34
+ }
35
+
36
+ public static function get( string $type ): array {
37
+ return self::all()[ $type ] ?? [];
38
+ }
39
+
40
+ public static function parents(): array {
41
+ return array_keys( self::all() );
42
+ }
43
+
44
+ public static function children(): array {
45
+ return array_column( self::all(), 'child' );
46
+ }
47
+
48
+ public static function child( string $type ): string {
49
+ return self::get( $type )['child'] ?? '';
50
+ }
51
+
52
+ public static function child_label( string $type ): string {
53
+ return self::get( $type )['child_label'] ?? '';
54
+ }
55
+
56
+ public static function items_key( string $type ): string {
57
+ return self::get( $type )['items_key'] ?? '_items';
58
+ }
59
+
60
+ public static function parent_of( string $child ): string {
61
+ foreach ( self::all() as $parent => $config ) {
62
+ if ( $config['child'] === $child ) {
63
+ return $parent;
64
+ }
65
+ }
66
+
67
+ return '';
68
+ }
69
+
70
+ public static function is_staged( string $type ): bool {
71
+ return ! empty( self::get( $type )['staged'] );
72
+ }
73
+
74
+ public static function has_box( string $type, string $box ): bool {
75
+ return in_array( $box, self::get( $type )['boxes'] ?? [], true );
76
+ }
77
+
78
+ public static function with_box( string $box ): array {
79
+ return array_values( array_filter(
80
+ self::parents(),
81
+ static fn( string $type ): bool => self::has_box( $type, $box )
82
+ ) );
83
+ }
84
+ }