@wp-operations/wp-ops 0.3.0 → 0.4.0

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 (119) hide show
  1. package/README.md +6 -3
  2. package/package.json +6 -2
  3. package/src/commands/platform.js +58 -2
  4. package/src/commands/start.js +2 -2
  5. package/src/main.js +19 -8
  6. package/wp-operations/CHANGELOG.md +14 -0
  7. package/wp-operations/README.md +39 -0
  8. package/wp-operations/agents/builder/AGENT.md +15 -0
  9. package/wp-operations/assets/admin.css +631 -0
  10. package/wp-operations/assets/admin.js +614 -0
  11. package/wp-operations/assets/app/app.css +1 -0
  12. package/wp-operations/assets/app/app.js +70 -0
  13. package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
  14. package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
  15. package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
  16. package/wp-operations/assets/app/login.css +42 -0
  17. package/wp-operations/assets/brand/icon.svg +20 -0
  18. package/wp-operations/assets/brand/mark.svg +19 -0
  19. package/wp-operations/assets/editors/audiobook.css +311 -0
  20. package/wp-operations/assets/editors/audiofile.css +286 -0
  21. package/wp-operations/assets/editors/course.css +701 -0
  22. package/wp-operations/assets/editors/course.js +698 -0
  23. package/wp-operations/assets/editors/faq.css +258 -0
  24. package/wp-operations/assets/editors/faq.js +196 -0
  25. package/wp-operations/assets/editors/interactive.css +220 -0
  26. package/wp-operations/assets/editors/interactive.js +378 -0
  27. package/wp-operations/assets/editors/media-sources.css +3 -0
  28. package/wp-operations/assets/editors/media-sources.js +40 -0
  29. package/wp-operations/assets/editors/open-media.css +114 -0
  30. package/wp-operations/assets/editors/open-media.js +182 -0
  31. package/wp-operations/assets/editors/thumbnails.css +335 -0
  32. package/wp-operations/assets/editors/thumbnails.js +447 -0
  33. package/wp-operations/assets/editors/translator.css +818 -0
  34. package/wp-operations/functions.php +24 -0
  35. package/wp-operations/index.php +14 -0
  36. package/wp-operations/platform.json +1836 -0
  37. package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
  38. package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
  39. package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
  40. package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
  41. package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
  42. package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
  43. package/wp-operations/skills/wp-security/SKILL.md +90 -0
  44. package/wp-operations/src/Admin.php +78 -0
  45. package/wp-operations/src/App/Access.php +57 -0
  46. package/wp-operations/src/App/Admin.php +442 -0
  47. package/wp-operations/src/App/App.php +157 -0
  48. package/wp-operations/src/App/Apps.php +379 -0
  49. package/wp-operations/src/App/Bundle.php +111 -0
  50. package/wp-operations/src/App/Contents.php +676 -0
  51. package/wp-operations/src/App/Engine.php +554 -0
  52. package/wp-operations/src/App/Github.php +308 -0
  53. package/wp-operations/src/App/Module.php +23 -0
  54. package/wp-operations/src/App/Ops.php +470 -0
  55. package/wp-operations/src/App/Packages.php +289 -0
  56. package/wp-operations/src/App/Rest.php +539 -0
  57. package/wp-operations/src/App/Sandboxes.php +206 -0
  58. package/wp-operations/src/App/Store.php +104 -0
  59. package/wp-operations/src/App/Usage.php +268 -0
  60. package/wp-operations/src/Config.php +249 -0
  61. package/wp-operations/src/Content/Editor.php +223 -0
  62. package/wp-operations/src/Content/Fields.php +681 -0
  63. package/wp-operations/src/Content/Scoring.php +253 -0
  64. package/wp-operations/src/Content/Structure.php +293 -0
  65. package/wp-operations/src/Content/Types.php +150 -0
  66. package/wp-operations/src/Content/Uploads.php +50 -0
  67. package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
  68. package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
  69. package/wp-operations/src/Editors/AudiobookCover.php +235 -0
  70. package/wp-operations/src/Editors/Audiofile.php +462 -0
  71. package/wp-operations/src/Editors/Course.php +784 -0
  72. package/wp-operations/src/Editors/Ebook.php +242 -0
  73. package/wp-operations/src/Editors/Editors.php +44 -0
  74. package/wp-operations/src/Editors/Faq.php +237 -0
  75. package/wp-operations/src/Editors/Files.php +139 -0
  76. package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
  77. package/wp-operations/src/Editors/Interactive/Card.php +76 -0
  78. package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
  79. package/wp-operations/src/Editors/Interactive/Field.php +272 -0
  80. package/wp-operations/src/Editors/Interactive/Map.php +84 -0
  81. package/wp-operations/src/Editors/Interactive/Models.php +227 -0
  82. package/wp-operations/src/Editors/Interactive/Report.php +59 -0
  83. package/wp-operations/src/Editors/Interactive/Save.php +323 -0
  84. package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
  85. package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
  86. package/wp-operations/src/Editors/Legal.php +235 -0
  87. package/wp-operations/src/Editors/OpenMedia.php +140 -0
  88. package/wp-operations/src/Editors/OriginalTitle.php +112 -0
  89. package/wp-operations/src/Editors/Sources.php +28 -0
  90. package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
  91. package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
  92. package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
  93. package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
  94. package/wp-operations/src/Editors/Translator/Admin.php +913 -0
  95. package/wp-operations/src/Editors/Translator/Api.php +63 -0
  96. package/wp-operations/src/Editors/Translator/Bar.php +83 -0
  97. package/wp-operations/src/Editors/Translator/Fields.php +273 -0
  98. package/wp-operations/src/Editors/Translator/Storage.php +131 -0
  99. package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
  100. package/wp-operations/src/Identity.php +104 -0
  101. package/wp-operations/src/Languages.php +45 -0
  102. package/wp-operations/src/Lockdown.php +85 -0
  103. package/wp-operations/src/Modules/Apps/Admin.php +472 -0
  104. package/wp-operations/src/Modules/Apps/Api.php +193 -0
  105. package/wp-operations/src/Modules/Apps/Apps.php +279 -0
  106. package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
  107. package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
  108. package/wp-operations/src/Modules/Apps/Table.php +101 -0
  109. package/wp-operations/src/Modules/Thumbnails.php +68 -0
  110. package/wp-operations/src/Modules/Translations.php +133 -0
  111. package/wp-operations/src/Platform.php +59 -0
  112. package/wp-operations/src/Setup.php +273 -0
  113. package/wp-operations/src/Status.php +99 -0
  114. package/wp-operations/src/Storage/Client.php +168 -0
  115. package/wp-operations/src/Storage/Offload.php +120 -0
  116. package/wp-operations/src/Storage/Settings.php +166 -0
  117. package/wp-operations/src/Storage/Storage.php +35 -0
  118. package/wp-operations/src/Updates.php +151 -0
  119. package/wp-operations/style.css +11 -0
@@ -0,0 +1,227 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Models {
7
+ public static function all(): array {
8
+ return [
9
+ 'profile' => [
10
+ 'label' => __( 'Ranked Profile' ),
11
+ 'summary' => __( 'Every subscale gets an average score. They are ranked against each other and the highest one is the answer. There is no pass mark and no comparison to other people.' ),
12
+ 'examples' => __( 'CliftonStrengths top 5 · Holland career codes · Enneagram · Love Languages · Belbin team roles' ),
13
+ 'uses' => [ 'subscales', 'option_value' ],
14
+ 'params' => [
15
+ 'show_top' => [
16
+ 'label' => __( 'How many results to show' ),
17
+ 'type' => 'number',
18
+ 'default' => 3,
19
+ ],
20
+ 'tie_break' => [
21
+ 'label' => __( 'If two subscales tie' ),
22
+ 'type' => 'select',
23
+ 'default' => 'order',
24
+ 'options' => [
25
+ 'order' => __( 'Keep the order they are listed in' ),
26
+ 'items' => __( 'More answered questions wins' ),
27
+ ],
28
+ ],
29
+ ],
30
+ ],
31
+
32
+ 'band' => [
33
+ 'label' => __( 'Score Band' ),
34
+ 'summary' => __( 'All answers add up to one total. The total falls into a band you define, and that band is the result. Nothing is compared to other people.' ),
35
+ 'examples' => __( 'GAD-7 anxiety · PHQ-9 depression · AUDIT · Perceived Stress Scale · Epworth Sleepiness Scale' ),
36
+ 'uses' => [ 'bands', 'option_value' ],
37
+ 'params' => [
38
+ 'reduce' => [
39
+ 'label' => __( 'Combine answers by' ),
40
+ 'type' => 'select',
41
+ 'default' => 'sum',
42
+ 'options' => [
43
+ 'sum' => __( 'Adding them up' ),
44
+ 'mean' => __( 'Averaging them' ),
45
+ ],
46
+ ],
47
+ ],
48
+ ],
49
+
50
+ 'subscale_bands' => [
51
+ 'label' => __( 'Band Per Subscale' ),
52
+ 'summary' => __( 'Like Score Band, but each subscale is banded on its own. The result is a list of levels rather than a single one, so a report can say which part is high and which is low.' ),
53
+ 'examples' => __( 'DASS-21 depression / anxiety / stress · Maslach Burnout Inventory · Strengths and Difficulties Questionnaire' ),
54
+ 'uses' => [ 'subscales', 'bands', 'option_value' ],
55
+ 'params' => [
56
+ 'reduce' => [
57
+ 'label' => __( 'Combine answers by' ),
58
+ 'type' => 'select',
59
+ 'default' => 'sum',
60
+ 'options' => [
61
+ 'sum' => __( 'Adding them up' ),
62
+ 'mean' => __( 'Averaging them' ),
63
+ ],
64
+ ],
65
+ ],
66
+ ],
67
+
68
+ 'typology' => [
69
+ 'label' => __( 'Type From Axes' ),
70
+ 'summary' => __( 'Each axis is one subscale split at a midpoint into a low side and a high side. The sides combine into a named type, so the result is a type rather than a score.' ),
71
+ 'examples' => __( 'MBTI 16 types · DISC quadrants · Attachment style from anxiety and avoidance · Political Compass' ),
72
+ 'uses' => [ 'subscales', 'axes', 'types', 'option_value' ],
73
+ 'params' => [],
74
+ ],
75
+
76
+ 'weighted_outcome' => [
77
+ 'label' => __( 'Points To Outcomes' ),
78
+ 'summary' => __( 'Points sit on the answer options, not on the questions. One option can send points to several outcomes. The outcome with the most points wins. This is the model for recommendation and sign-up funnels.' ),
79
+ 'examples' => __( 'Which plan suits you · product and skin-type finders · diet matchers · lead scoring' ),
80
+ 'uses' => [ 'outcomes', 'option_points' ],
81
+ 'params' => [
82
+ 'tie_break' => [
83
+ 'label' => __( 'If two outcomes tie' ),
84
+ 'type' => 'select',
85
+ 'default' => 'order',
86
+ 'options' => [
87
+ 'order' => __( 'Keep the order they are listed in' ),
88
+ 'latest' => __( 'The most recently scored wins' ),
89
+ ],
90
+ ],
91
+ 'min_points' => [
92
+ 'label' => __( 'Minimum points to accept a winner' ),
93
+ 'type' => 'number',
94
+ 'default' => 0,
95
+ ],
96
+ ],
97
+ ],
98
+
99
+ 'graded' => [
100
+ 'label' => __( 'Graded Answers' ),
101
+ 'summary' => __( 'Options are marked right or wrong. Right answers earn their question weight, and the total can be banded or checked against a pass mark.' ),
102
+ 'examples' => __( 'Certification and licensing exams · driving theory tests · placement tests · pattern puzzles' ),
103
+ 'uses' => [ 'bands', 'option_correct' ],
104
+ 'params' => [
105
+ 'weighting' => [
106
+ 'label' => __( 'Question weights' ),
107
+ 'type' => 'select',
108
+ 'default' => 'flat',
109
+ 'options' => [
110
+ 'flat' => __( 'Every question counts the same' ),
111
+ 'item' => __( 'Use the weight set on each question' ),
112
+ ],
113
+ ],
114
+ 'pass_mark' => [
115
+ 'label' => __( 'Pass mark as a percentage' ),
116
+ 'type' => 'number',
117
+ 'default' => 60,
118
+ ],
119
+ 'negative_marking' => [
120
+ 'label' => __( 'Points removed for a wrong answer' ),
121
+ 'type' => 'number',
122
+ 'default' => 0,
123
+ ],
124
+ ],
125
+ ],
126
+
127
+ 'normed' => [
128
+ 'label' => __( 'Standardised Index' ),
129
+ 'summary' => __( 'The raw score is converted onto a standard scale so it can be read as a percentile and an index number. Subscales can be mixed at different weights, and completion time can nudge the result.' ),
130
+ 'examples' => __( 'WAIS and Stanford-Binet IQ · Raven\'s Progressive Matrices · clinical T-scores · stanines · percentile ranks' ),
131
+ 'uses' => [ 'subscales', 'mix', 'bands', 'option_correct' ],
132
+ 'params' => [
133
+ 'mean' => [
134
+ 'label' => __( 'Index mean' ),
135
+ 'type' => 'number',
136
+ 'default' => 100,
137
+ ],
138
+ 'sd' => [
139
+ 'label' => __( 'Index standard deviation' ),
140
+ 'type' => 'number',
141
+ 'default' => 15,
142
+ ],
143
+ 'floor' => [
144
+ 'label' => __( 'Lowest index allowed' ),
145
+ 'type' => 'number',
146
+ 'default' => 55,
147
+ ],
148
+ 'ceiling' => [
149
+ 'label' => __( 'Highest index allowed' ),
150
+ 'type' => 'number',
151
+ 'default' => 160,
152
+ ],
153
+ 'expected_seconds' => [
154
+ 'label' => __( 'Expected completion time in seconds' ),
155
+ 'type' => 'number',
156
+ 'default' => 2100,
157
+ ],
158
+ 'time_min' => [
159
+ 'label' => __( 'Smallest time multiplier' ),
160
+ 'type' => 'text',
161
+ 'default' => '0.95',
162
+ ],
163
+ 'time_max' => [
164
+ 'label' => __( 'Largest time multiplier' ),
165
+ 'type' => 'text',
166
+ 'default' => '1.05',
167
+ ],
168
+ ],
169
+ ],
170
+ ];
171
+ }
172
+
173
+ public static function keys(): array {
174
+ return array_keys( self::all() );
175
+ }
176
+
177
+ public static function exists( string $key ): bool {
178
+ return isset( self::all()[ $key ] );
179
+ }
180
+
181
+ public static function get( string $key ): array {
182
+ return self::all()[ $key ] ?? [];
183
+ }
184
+
185
+ public static function choices(): array {
186
+ $choices = [];
187
+
188
+ foreach ( self::all() as $key => $model ) {
189
+ $choices[ $key ] = $model['label'];
190
+ }
191
+
192
+ return $choices;
193
+ }
194
+
195
+ public static function params( string $key ): array {
196
+ return self::get( $key )['params'] ?? [];
197
+ }
198
+
199
+ public static function uses( string $key ): array {
200
+ return self::get( $key )['uses'] ?? [];
201
+ }
202
+
203
+ public static function panels(): array {
204
+ return [
205
+ 'subscales' => __( 'Subscales' ),
206
+ 'outcomes' => __( 'Outcomes' ),
207
+ 'axes' => __( 'Axes' ),
208
+ 'types' => __( 'Types' ),
209
+ 'mix' => __( 'Subscale Mix' ),
210
+ 'bands' => __( 'Bands' ),
211
+ ];
212
+ }
213
+
214
+ public static function for_script(): array {
215
+ $out = [];
216
+
217
+ foreach ( self::all() as $key => $model ) {
218
+ $out[ $key ] = [
219
+ 'summary' => $model['summary'],
220
+ 'examples' => $model['examples'],
221
+ 'uses' => $model['uses'],
222
+ ];
223
+ }
224
+
225
+ return $out;
226
+ }
227
+ }
@@ -0,0 +1,59 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Report {
7
+ public static function register(): void {
8
+ foreach ( Map::with_box( 'report' ) as $type ) {
9
+ add_meta_box(
10
+ 'report',
11
+ __( 'Report' ),
12
+ [ __CLASS__, 'render' ],
13
+ $type,
14
+ 'normal',
15
+ 'default'
16
+ );
17
+ }
18
+ }
19
+
20
+ public static function render( \WP_Post $post ): void {
21
+ Field::reset();
22
+
23
+ echo '<div class="interactive-panel report">';
24
+ echo '<input type="hidden" name="interactive_report" value="1" />';
25
+
26
+ Field::repeater(
27
+ '_report',
28
+ Field::rows( $post->ID, '_report' ),
29
+ [ __CLASS__, 'entry' ],
30
+ [ 'add' => __( 'Add report entry' ) ]
31
+ );
32
+
33
+ echo '</div>';
34
+ }
35
+
36
+ public static function entry( array $row ): void {
37
+ echo '<div class="field-row">';
38
+ Field::text( 'key', __( 'Result key' ), (string) ( $row['key'] ?? '' ), [ 'list' => 'report-keys', 'width' => 'key' ] );
39
+ Field::text( 'title', __( 'Title' ), (string) ( $row['title'] ?? '' ), [ 'width' => 'wide' ] );
40
+ echo '</div>';
41
+
42
+ Field::textarea( 'description', __( 'Description' ), (string) ( $row['description'] ?? '' ), [ 'rows' => 3 ] );
43
+
44
+ Field::repeater(
45
+ 'blocks',
46
+ is_array( $row['blocks'] ?? null ) ? $row['blocks'] : [],
47
+ static function ( array $block ): void {
48
+ echo '<div class="field-row">';
49
+ Field::text( 'type', __( 'Block type' ), (string) ( $block['type'] ?? '' ), [ 'width' => 'key' ] );
50
+ Field::text( 'heading', __( 'Heading' ), (string) ( $block['heading'] ?? '' ), [ 'width' => 'wide' ] );
51
+ echo '</div>';
52
+
53
+ Field::textarea( 'text', __( 'Text' ), (string) ( $block['text'] ?? '' ), [ 'rows' => 3 ] );
54
+ Field::textarea( 'items', __( 'List, one per line' ), Field::array_to_lines( $block['items'] ?? [] ), [ 'rows' => 4 ] );
55
+ },
56
+ [ 'label' => __( 'Blocks' ), 'add' => __( 'Add block' ) ]
57
+ );
58
+ }
59
+ }
@@ -0,0 +1,323 @@
1
+ <?php
2
+ namespace Platform\Editors\Interactive;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ final class Save {
7
+ public static function handle( int $post_id, \WP_Post $post ): void {
8
+ if ( ! Map::supports( $post->post_type ) ) {
9
+ return;
10
+ }
11
+
12
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
13
+ return;
14
+ }
15
+
16
+ if ( ! isset( $_POST['interactive_nonce'] ) || ! wp_verify_nonce( $_POST['interactive_nonce'], 'interactive_save' ) ) {
17
+ return;
18
+ }
19
+
20
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
21
+ return;
22
+ }
23
+
24
+ $type = $post->post_type;
25
+
26
+ if ( Map::has_box( $type, 'card' ) && isset( $_POST['_icon'] ) ) {
27
+ self::card( $post_id );
28
+ }
29
+
30
+ if ( Map::has_box( $type, 'scoring' ) && isset( $_POST['_algorithm'] ) ) {
31
+ self::scoring( $post_id );
32
+ }
33
+
34
+ if ( Map::has_box( $type, 'report' ) && isset( $_POST['interactive_report'] ) ) {
35
+ self::report( $post_id );
36
+ }
37
+
38
+ if ( Map::has_box( $type, 'structure' ) && isset( $_POST['children'] ) ) {
39
+ self::children( $post_id, $type );
40
+ }
41
+ }
42
+
43
+ private static function card( int $post_id ): void {
44
+ update_post_meta( $post_id, '_icon', sanitize_text_field( $_POST['_icon'] ?? '' ) );
45
+ update_post_meta( $post_id, '_minutes', self::num( $_POST['_minutes'] ?? '' ) );
46
+ update_post_meta( $post_id, '_rating', self::num( $_POST['_rating'] ?? '' ) );
47
+ update_post_meta( $post_id, '_reviews', self::num( $_POST['_reviews'] ?? '' ) );
48
+ update_post_meta( $post_id, '_unlock', sanitize_key( $_POST['_unlock'] ?? 'open' ) );
49
+ update_post_meta( $post_id, '_intro_points', Field::lines_to_array( $_POST['_intro_points'] ?? '' ) );
50
+ }
51
+
52
+ private static function scoring( int $post_id ): void {
53
+ $model = sanitize_key( $_POST['_algorithm'] ?? '' );
54
+
55
+ if ( ! Models::exists( $model ) ) {
56
+ $model = 'profile';
57
+ }
58
+
59
+ update_post_meta( $post_id, '_algorithm', $model );
60
+
61
+ $submitted = $_POST['_algorithm_params'][ $model ] ?? [];
62
+ $params = [];
63
+
64
+ foreach ( Models::params( $model ) as $key => $param ) {
65
+ $value = $submitted[ $key ] ?? $param['default'];
66
+
67
+ $params[ $key ] = $param['type'] === 'select'
68
+ ? sanitize_key( $value )
69
+ : self::num( $value );
70
+ }
71
+
72
+ update_post_meta( $post_id, '_algorithm_params', $params );
73
+
74
+ update_post_meta( $post_id, '_scales', self::scales( $_POST['_scales'] ?? [] ) );
75
+
76
+ update_post_meta( $post_id, '_subscales', self::rows( $_POST['_subscales'] ?? [], [
77
+ 'key' => 'key',
78
+ 'title' => 'text',
79
+ 'description' => 'textarea',
80
+ ], 'key' ) );
81
+
82
+ update_post_meta( $post_id, '_outcomes', self::rows( $_POST['_outcomes'] ?? [], [
83
+ 'key' => 'key',
84
+ 'title' => 'text',
85
+ ], 'key' ) );
86
+
87
+ update_post_meta( $post_id, '_axes', self::rows( $_POST['_axes'] ?? [], [
88
+ 'subscale' => 'key',
89
+ 'midpoint' => 'num',
90
+ 'pole_low' => 'text',
91
+ 'pole_high' => 'text',
92
+ ], 'subscale' ) );
93
+
94
+ update_post_meta( $post_id, '_types', self::rows( $_POST['_types'] ?? [], [
95
+ 'combination' => 'text',
96
+ 'key' => 'key',
97
+ 'title' => 'text',
98
+ ], 'key' ) );
99
+
100
+ update_post_meta( $post_id, '_mix', self::rows( $_POST['_mix'] ?? [], [
101
+ 'subscale' => 'key',
102
+ 'weight' => 'num',
103
+ ], 'subscale' ) );
104
+
105
+ update_post_meta( $post_id, '_bands', self::rows( $_POST['_bands'] ?? [], [
106
+ 'key' => 'key',
107
+ 'title' => 'text',
108
+ 'min' => 'num',
109
+ 'max' => 'num',
110
+ 'subscale' => 'key',
111
+ ], 'key' ) );
112
+ }
113
+
114
+ private static function report( int $post_id ): void {
115
+ $entries = [];
116
+
117
+ foreach ( (array) ( $_POST['_report'] ?? [] ) as $entry ) {
118
+ if ( ! is_array( $entry ) || empty( $entry['key'] ) ) {
119
+ continue;
120
+ }
121
+
122
+ $blocks = [];
123
+
124
+ foreach ( (array) ( $entry['blocks'] ?? [] ) as $block ) {
125
+ if ( ! is_array( $block ) || empty( $block['type'] ) ) {
126
+ continue;
127
+ }
128
+
129
+ $blocks[] = [
130
+ 'type' => sanitize_key( $block['type'] ),
131
+ 'heading' => sanitize_text_field( $block['heading'] ?? '' ),
132
+ 'text' => wp_kses_post( $block['text'] ?? '' ),
133
+ 'items' => Field::lines_to_array( $block['items'] ?? '' ),
134
+ ];
135
+ }
136
+
137
+ $entries[] = [
138
+ 'key' => sanitize_key( $entry['key'] ),
139
+ 'title' => sanitize_text_field( $entry['title'] ?? '' ),
140
+ 'description' => wp_kses_post( $entry['description'] ?? '' ),
141
+ 'blocks' => $blocks,
142
+ ];
143
+ }
144
+
145
+ update_post_meta( $post_id, '_report', $entries );
146
+ }
147
+
148
+ private static function children( int $post_id, string $parent_type ): void {
149
+ $config = Map::get( $parent_type );
150
+ $submitted = (array) ( $_POST['children'] ?? [] );
151
+
152
+ foreach ( $submitted as $child_id => $data ) {
153
+ $child_id = absint( $child_id );
154
+
155
+ if ( ! $child_id || ! is_array( $data ) ) {
156
+ continue;
157
+ }
158
+
159
+ $child = get_post( $child_id );
160
+
161
+ if ( ! $child || $child->post_type !== $config['child'] || (int) $child->post_parent !== $post_id ) {
162
+ continue;
163
+ }
164
+
165
+ if ( ! current_user_can( 'edit_post', $child_id ) ) {
166
+ continue;
167
+ }
168
+
169
+ $title = sanitize_text_field( $data['title'] ?? '' );
170
+
171
+ if ( $title !== '' && $title !== $child->post_title ) {
172
+ wp_update_post( [
173
+ 'ID' => $child_id,
174
+ 'post_title' => $title,
175
+ ] );
176
+ }
177
+
178
+ if ( Map::is_staged( $parent_type ) ) {
179
+ update_post_meta( $child_id, '_section_type', sanitize_key( $data['type'] ?? 'items' ) );
180
+ }
181
+
182
+ update_post_meta( $child_id, '_prompt', wp_kses_post( $data['prompt'] ?? '' ) );
183
+ update_post_meta( $child_id, $config['items_key'], self::items( $data['items'] ?? [] ) );
184
+ }
185
+ }
186
+
187
+ private static function items( $raw ): array {
188
+ $items = [];
189
+
190
+ foreach ( (array) $raw as $item ) {
191
+ if ( ! is_array( $item ) ) {
192
+ continue;
193
+ }
194
+
195
+ $text = sanitize_textarea_field( $item['text'] ?? '' );
196
+
197
+ if ( $text === '' ) {
198
+ continue;
199
+ }
200
+
201
+ $items[] = [
202
+ 'text' => $text,
203
+ 'subscale' => sanitize_key( $item['subscale'] ?? '' ),
204
+ 'scale' => sanitize_key( $item['scale'] ?? '' ),
205
+ 'weight' => self::num( $item['weight'] ?? 1 ),
206
+ 'reversed' => empty( $item['reversed'] ) ? 0 : 1,
207
+ 'render' => sanitize_key( $item['render'] ?? '' ),
208
+ 'params' => Field::pairs_to_array( $item['params'] ?? '' ),
209
+ 'options' => self::options( $item['options'] ?? [] ),
210
+ ];
211
+ }
212
+
213
+ return $items;
214
+ }
215
+
216
+ private static function options( $raw ): array {
217
+ $options = [];
218
+
219
+ foreach ( (array) $raw as $option ) {
220
+ if ( ! is_array( $option ) ) {
221
+ continue;
222
+ }
223
+
224
+ $label = sanitize_text_field( $option['label'] ?? '' );
225
+ $render = sanitize_key( $option['render'] ?? '' );
226
+
227
+ if ( $label === '' && $render === '' ) {
228
+ continue;
229
+ }
230
+
231
+ $options[] = [
232
+ 'label' => $label,
233
+ 'value' => self::num( $option['value'] ?? '' ),
234
+ 'correct' => empty( $option['correct'] ) ? 0 : 1,
235
+ 'points' => self::points( $option['points'] ?? '' ),
236
+ 'render' => $render,
237
+ 'params' => Field::pairs_to_array( $option['params'] ?? '' ),
238
+ ];
239
+ }
240
+
241
+ return $options;
242
+ }
243
+
244
+ private static function points( $raw ): array {
245
+ $points = [];
246
+
247
+ foreach ( Field::pairs_to_array( $raw ) as $outcome => $value ) {
248
+ $points[ $outcome ] = self::num( $value );
249
+ }
250
+
251
+ return $points;
252
+ }
253
+
254
+ private static function scales( $raw ): array {
255
+ $scales = [];
256
+
257
+ foreach ( (array) $raw as $scale ) {
258
+ if ( ! is_array( $scale ) || empty( $scale['key'] ) ) {
259
+ continue;
260
+ }
261
+
262
+ $options = [];
263
+
264
+ foreach ( (array) ( $scale['options'] ?? [] ) as $option ) {
265
+ if ( ! is_array( $option ) || ( $option['label'] ?? '' ) === '' ) {
266
+ continue;
267
+ }
268
+
269
+ $options[] = [
270
+ 'label' => sanitize_text_field( $option['label'] ),
271
+ 'value' => self::num( $option['value'] ?? '' ),
272
+ 'color' => sanitize_key( $option['color'] ?? '' ),
273
+ ];
274
+ }
275
+
276
+ $scales[] = [
277
+ 'key' => sanitize_key( $scale['key'] ),
278
+ 'label' => sanitize_text_field( $scale['label'] ?? '' ),
279
+ 'options' => $options,
280
+ ];
281
+ }
282
+
283
+ return $scales;
284
+ }
285
+
286
+ private static function rows( $raw, array $schema, string $required ): array {
287
+ $rows = [];
288
+
289
+ foreach ( (array) $raw as $row ) {
290
+ if ( ! is_array( $row ) || ( $row[ $required ] ?? '' ) === '' ) {
291
+ continue;
292
+ }
293
+
294
+ $clean = [];
295
+
296
+ foreach ( $schema as $field => $kind ) {
297
+ $value = $row[ $field ] ?? '';
298
+
299
+ if ( $kind === 'key' ) {
300
+ $clean[ $field ] = sanitize_key( $value );
301
+ } elseif ( $kind === 'num' ) {
302
+ $clean[ $field ] = self::num( $value );
303
+ } elseif ( $kind === 'textarea' ) {
304
+ $clean[ $field ] = sanitize_textarea_field( $value );
305
+ } else {
306
+ $clean[ $field ] = sanitize_text_field( $value );
307
+ }
308
+ }
309
+
310
+ $rows[] = $clean;
311
+ }
312
+
313
+ return $rows;
314
+ }
315
+
316
+ private static function num( $value ) {
317
+ if ( is_array( $value ) || ! is_numeric( $value ) ) {
318
+ return '';
319
+ }
320
+
321
+ return $value + 0;
322
+ }
323
+ }