@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.
- package/README.md +6 -3
- package/package.json +6 -2
- package/src/commands/platform.js +58 -2
- package/src/commands/start.js +2 -2
- package/src/main.js +19 -8
- package/wp-operations/CHANGELOG.md +14 -0
- package/wp-operations/README.md +39 -0
- package/wp-operations/agents/builder/AGENT.md +15 -0
- package/wp-operations/assets/admin.css +631 -0
- package/wp-operations/assets/admin.js +614 -0
- package/wp-operations/assets/app/app.css +1 -0
- package/wp-operations/assets/app/app.js +70 -0
- package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
- package/wp-operations/assets/app/login.css +42 -0
- package/wp-operations/assets/brand/icon.svg +20 -0
- package/wp-operations/assets/brand/mark.svg +19 -0
- package/wp-operations/assets/editors/audiobook.css +311 -0
- package/wp-operations/assets/editors/audiofile.css +286 -0
- package/wp-operations/assets/editors/course.css +701 -0
- package/wp-operations/assets/editors/course.js +698 -0
- package/wp-operations/assets/editors/faq.css +258 -0
- package/wp-operations/assets/editors/faq.js +196 -0
- package/wp-operations/assets/editors/interactive.css +220 -0
- package/wp-operations/assets/editors/interactive.js +378 -0
- package/wp-operations/assets/editors/media-sources.css +3 -0
- package/wp-operations/assets/editors/media-sources.js +40 -0
- package/wp-operations/assets/editors/open-media.css +114 -0
- package/wp-operations/assets/editors/open-media.js +182 -0
- package/wp-operations/assets/editors/thumbnails.css +335 -0
- package/wp-operations/assets/editors/thumbnails.js +447 -0
- package/wp-operations/assets/editors/translator.css +818 -0
- package/wp-operations/functions.php +24 -0
- package/wp-operations/index.php +14 -0
- package/wp-operations/platform.json +1836 -0
- package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
- package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
- package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
- package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
- package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
- package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
- package/wp-operations/skills/wp-security/SKILL.md +90 -0
- package/wp-operations/src/Admin.php +78 -0
- package/wp-operations/src/App/Access.php +57 -0
- package/wp-operations/src/App/Admin.php +442 -0
- package/wp-operations/src/App/App.php +157 -0
- package/wp-operations/src/App/Apps.php +379 -0
- package/wp-operations/src/App/Bundle.php +111 -0
- package/wp-operations/src/App/Contents.php +676 -0
- package/wp-operations/src/App/Engine.php +554 -0
- package/wp-operations/src/App/Github.php +308 -0
- package/wp-operations/src/App/Module.php +23 -0
- package/wp-operations/src/App/Ops.php +470 -0
- package/wp-operations/src/App/Packages.php +289 -0
- package/wp-operations/src/App/Rest.php +539 -0
- package/wp-operations/src/App/Sandboxes.php +206 -0
- package/wp-operations/src/App/Store.php +104 -0
- package/wp-operations/src/App/Usage.php +268 -0
- package/wp-operations/src/Config.php +249 -0
- package/wp-operations/src/Content/Editor.php +223 -0
- package/wp-operations/src/Content/Fields.php +681 -0
- package/wp-operations/src/Content/Scoring.php +253 -0
- package/wp-operations/src/Content/Structure.php +293 -0
- package/wp-operations/src/Content/Types.php +150 -0
- package/wp-operations/src/Content/Uploads.php +50 -0
- package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
- package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
- package/wp-operations/src/Editors/AudiobookCover.php +235 -0
- package/wp-operations/src/Editors/Audiofile.php +462 -0
- package/wp-operations/src/Editors/Course.php +784 -0
- package/wp-operations/src/Editors/Ebook.php +242 -0
- package/wp-operations/src/Editors/Editors.php +44 -0
- package/wp-operations/src/Editors/Faq.php +237 -0
- package/wp-operations/src/Editors/Files.php +139 -0
- package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
- package/wp-operations/src/Editors/Interactive/Card.php +76 -0
- package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
- package/wp-operations/src/Editors/Interactive/Field.php +272 -0
- package/wp-operations/src/Editors/Interactive/Map.php +84 -0
- package/wp-operations/src/Editors/Interactive/Models.php +227 -0
- package/wp-operations/src/Editors/Interactive/Report.php +59 -0
- package/wp-operations/src/Editors/Interactive/Save.php +323 -0
- package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
- package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
- package/wp-operations/src/Editors/Legal.php +235 -0
- package/wp-operations/src/Editors/OpenMedia.php +140 -0
- package/wp-operations/src/Editors/OriginalTitle.php +112 -0
- package/wp-operations/src/Editors/Sources.php +28 -0
- package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
- package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
- package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
- package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
- package/wp-operations/src/Editors/Translator/Admin.php +913 -0
- package/wp-operations/src/Editors/Translator/Api.php +63 -0
- package/wp-operations/src/Editors/Translator/Bar.php +83 -0
- package/wp-operations/src/Editors/Translator/Fields.php +273 -0
- package/wp-operations/src/Editors/Translator/Storage.php +131 -0
- package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
- package/wp-operations/src/Identity.php +104 -0
- package/wp-operations/src/Languages.php +45 -0
- package/wp-operations/src/Lockdown.php +85 -0
- package/wp-operations/src/Modules/Apps/Admin.php +472 -0
- package/wp-operations/src/Modules/Apps/Api.php +193 -0
- package/wp-operations/src/Modules/Apps/Apps.php +279 -0
- package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
- package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
- package/wp-operations/src/Modules/Apps/Table.php +101 -0
- package/wp-operations/src/Modules/Thumbnails.php +68 -0
- package/wp-operations/src/Modules/Translations.php +133 -0
- package/wp-operations/src/Platform.php +59 -0
- package/wp-operations/src/Setup.php +273 -0
- package/wp-operations/src/Status.php +99 -0
- package/wp-operations/src/Storage/Client.php +168 -0
- package/wp-operations/src/Storage/Offload.php +120 -0
- package/wp-operations/src/Storage/Settings.php +166 -0
- package/wp-operations/src/Storage/Storage.php +35 -0
- package/wp-operations/src/Updates.php +151 -0
- package/wp-operations/style.css +11 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors\Interactive;
|
|
3
|
+
|
|
4
|
+
defined( 'ABSPATH' ) || exit;
|
|
5
|
+
|
|
6
|
+
final class Scoring {
|
|
7
|
+
public static function register(): void {
|
|
8
|
+
foreach ( Map::with_box( 'scoring' ) as $type ) {
|
|
9
|
+
add_meta_box(
|
|
10
|
+
'scoring',
|
|
11
|
+
__( 'Scoring' ),
|
|
12
|
+
[ __CLASS__, 'render' ],
|
|
13
|
+
$type,
|
|
14
|
+
'normal',
|
|
15
|
+
'high'
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static function render( \WP_Post $post ): void {
|
|
21
|
+
Field::reset();
|
|
22
|
+
|
|
23
|
+
$model = (string) get_post_meta( $post->ID, '_algorithm', true );
|
|
24
|
+
$params = get_post_meta( $post->ID, '_algorithm_params', true );
|
|
25
|
+
$params = is_array( $params ) ? $params : [];
|
|
26
|
+
|
|
27
|
+
if ( ! Models::exists( $model ) ) {
|
|
28
|
+
$model = 'profile';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
echo '<div class="interactive-panel scoring">';
|
|
32
|
+
|
|
33
|
+
Field::select(
|
|
34
|
+
'_algorithm',
|
|
35
|
+
__( 'Scoring model' ),
|
|
36
|
+
$model,
|
|
37
|
+
Models::choices(),
|
|
38
|
+
[ 'class' => 'model-select', 'width' => 'wide' ]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
echo '<div class="model-info"><p class="model-summary"></p><p class="model-examples"></p></div>';
|
|
42
|
+
|
|
43
|
+
self::params( $model, $params );
|
|
44
|
+
self::scales( $post );
|
|
45
|
+
self::subscales( $post );
|
|
46
|
+
self::outcomes( $post );
|
|
47
|
+
self::axes( $post );
|
|
48
|
+
self::types( $post );
|
|
49
|
+
self::mix( $post );
|
|
50
|
+
self::bands( $post );
|
|
51
|
+
|
|
52
|
+
echo '</div>';
|
|
53
|
+
|
|
54
|
+
self::datalists( $post );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private static function params( string $active, array $saved ): void {
|
|
58
|
+
foreach ( Models::all() as $key => $model ) {
|
|
59
|
+
if ( empty( $model['params'] ) ) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
printf(
|
|
64
|
+
'<div class="model-params" data-model="%1$s" data-prefix="_algorithm_params[%1$s]">',
|
|
65
|
+
esc_attr( $key )
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
Field::push( '_algorithm_params' );
|
|
69
|
+
Field::push( $key );
|
|
70
|
+
|
|
71
|
+
foreach ( $model['params'] as $param_key => $param ) {
|
|
72
|
+
$value = $key === $active && isset( $saved[ $param_key ] )
|
|
73
|
+
? (string) $saved[ $param_key ]
|
|
74
|
+
: (string) $param['default'];
|
|
75
|
+
|
|
76
|
+
if ( $param['type'] === 'select' ) {
|
|
77
|
+
Field::select( $param_key, $param['label'], $value, $param['options'], [ 'width' => 'wide' ] );
|
|
78
|
+
} elseif ( $param['type'] === 'number' ) {
|
|
79
|
+
Field::number( $param_key, $param['label'], $value );
|
|
80
|
+
} else {
|
|
81
|
+
Field::text( $param_key, $param['label'], $value );
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Field::pop();
|
|
86
|
+
Field::pop();
|
|
87
|
+
|
|
88
|
+
echo '</div>';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private static function scales( \WP_Post $post ): void {
|
|
93
|
+
self::group( __( 'Response Scales' ), '', function () use ( $post ) {
|
|
94
|
+
Field::repeater(
|
|
95
|
+
'_scales',
|
|
96
|
+
Field::rows( $post->ID, '_scales' ),
|
|
97
|
+
static function ( array $row ): void {
|
|
98
|
+
Field::text( 'key', __( 'Key' ), (string) ( $row['key'] ?? '' ), [ 'width' => 'key' ] );
|
|
99
|
+
Field::text( 'label', __( 'Label' ), (string) ( $row['label'] ?? '' ) );
|
|
100
|
+
|
|
101
|
+
Field::repeater(
|
|
102
|
+
'options',
|
|
103
|
+
is_array( $row['options'] ?? null ) ? $row['options'] : [],
|
|
104
|
+
static function ( array $option ): void {
|
|
105
|
+
Field::text( 'label', __( 'Option' ), (string) ( $option['label'] ?? '' ) );
|
|
106
|
+
Field::number( 'value', __( 'Value' ), $option['value'] ?? '', [ 'width' => 'small', 'step' => '1' ] );
|
|
107
|
+
Field::select( 'color', __( 'Colour' ), (string) ( $option['color'] ?? '' ), self::colors(), [ 'empty' => __( 'None' ), 'width' => 'small' ] );
|
|
108
|
+
},
|
|
109
|
+
[ 'label' => __( 'Options' ), 'add' => __( 'Add option' ) ]
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
[ 'add' => __( 'Add scale' ) ]
|
|
113
|
+
);
|
|
114
|
+
} );
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static function subscales( \WP_Post $post ): void {
|
|
118
|
+
self::group( __( 'Subscales' ), 'subscales', function () use ( $post ) {
|
|
119
|
+
Field::repeater(
|
|
120
|
+
'_subscales',
|
|
121
|
+
Field::rows( $post->ID, '_subscales' ),
|
|
122
|
+
static function ( array $row ): void {
|
|
123
|
+
Field::text( 'key', __( 'Key' ), (string) ( $row['key'] ?? '' ), [ 'width' => 'key' ] );
|
|
124
|
+
Field::text( 'title', __( 'Title' ), (string) ( $row['title'] ?? '' ) );
|
|
125
|
+
Field::textarea( 'description', __( 'Description' ), (string) ( $row['description'] ?? '' ), [ 'rows' => 2 ] );
|
|
126
|
+
},
|
|
127
|
+
[ 'add' => __( 'Add subscale' ) ]
|
|
128
|
+
);
|
|
129
|
+
} );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private static function outcomes( \WP_Post $post ): void {
|
|
133
|
+
self::group( __( 'Outcomes' ), 'outcomes', function () use ( $post ) {
|
|
134
|
+
Field::repeater(
|
|
135
|
+
'_outcomes',
|
|
136
|
+
Field::rows( $post->ID, '_outcomes' ),
|
|
137
|
+
static function ( array $row ): void {
|
|
138
|
+
Field::text( 'key', __( 'Key' ), (string) ( $row['key'] ?? '' ), [ 'width' => 'key' ] );
|
|
139
|
+
Field::text( 'title', __( 'Title' ), (string) ( $row['title'] ?? '' ) );
|
|
140
|
+
},
|
|
141
|
+
[ 'add' => __( 'Add outcome' ) ]
|
|
142
|
+
);
|
|
143
|
+
} );
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private static function axes( \WP_Post $post ): void {
|
|
147
|
+
self::group( __( 'Axes' ), 'axes', function () use ( $post ) {
|
|
148
|
+
Field::repeater(
|
|
149
|
+
'_axes',
|
|
150
|
+
Field::rows( $post->ID, '_axes' ),
|
|
151
|
+
static function ( array $row ): void {
|
|
152
|
+
Field::text( 'subscale', __( 'Subscale' ), (string) ( $row['subscale'] ?? '' ), [ 'list' => 'subscale-keys', 'width' => 'key' ] );
|
|
153
|
+
Field::number( 'midpoint', __( 'Midpoint' ), $row['midpoint'] ?? '', [ 'width' => 'small' ] );
|
|
154
|
+
Field::text( 'pole_low', __( 'Below midpoint' ), (string) ( $row['pole_low'] ?? '' ) );
|
|
155
|
+
Field::text( 'pole_high', __( 'At or above midpoint' ), (string) ( $row['pole_high'] ?? '' ) );
|
|
156
|
+
},
|
|
157
|
+
[ 'add' => __( 'Add axis' ) ]
|
|
158
|
+
);
|
|
159
|
+
} );
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private static function types( \WP_Post $post ): void {
|
|
163
|
+
self::group( __( 'Types' ), 'types', function () use ( $post ) {
|
|
164
|
+
Field::repeater(
|
|
165
|
+
'_types',
|
|
166
|
+
Field::rows( $post->ID, '_types' ),
|
|
167
|
+
static function ( array $row ): void {
|
|
168
|
+
Field::text( 'combination', __( 'Poles in axis order, comma separated' ), (string) ( $row['combination'] ?? '' ) );
|
|
169
|
+
Field::text( 'key', __( 'Key' ), (string) ( $row['key'] ?? '' ), [ 'width' => 'key' ] );
|
|
170
|
+
Field::text( 'title', __( 'Title' ), (string) ( $row['title'] ?? '' ) );
|
|
171
|
+
},
|
|
172
|
+
[ 'add' => __( 'Add type' ) ]
|
|
173
|
+
);
|
|
174
|
+
} );
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private static function mix( \WP_Post $post ): void {
|
|
178
|
+
self::group( __( 'Subscale Mix' ), 'mix', function () use ( $post ) {
|
|
179
|
+
Field::repeater(
|
|
180
|
+
'_mix',
|
|
181
|
+
Field::rows( $post->ID, '_mix' ),
|
|
182
|
+
static function ( array $row ): void {
|
|
183
|
+
Field::text( 'subscale', __( 'Subscale' ), (string) ( $row['subscale'] ?? '' ), [ 'list' => 'subscale-keys', 'width' => 'key' ] );
|
|
184
|
+
Field::number( 'weight', __( 'Share of the raw score' ), $row['weight'] ?? '', [ 'width' => 'small' ] );
|
|
185
|
+
},
|
|
186
|
+
[ 'add' => __( 'Add subscale' ) ]
|
|
187
|
+
);
|
|
188
|
+
} );
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private static function bands( \WP_Post $post ): void {
|
|
192
|
+
self::group( __( 'Bands' ), 'bands', function () use ( $post ) {
|
|
193
|
+
Field::repeater(
|
|
194
|
+
'_bands',
|
|
195
|
+
Field::rows( $post->ID, '_bands' ),
|
|
196
|
+
static function ( array $row ): void {
|
|
197
|
+
Field::text( 'key', __( 'Key' ), (string) ( $row['key'] ?? '' ), [ 'width' => 'key' ] );
|
|
198
|
+
Field::text( 'title', __( 'Title' ), (string) ( $row['title'] ?? '' ) );
|
|
199
|
+
Field::number( 'min', __( 'From' ), $row['min'] ?? '', [ 'width' => 'small' ] );
|
|
200
|
+
Field::number( 'max', __( 'To' ), $row['max'] ?? '', [ 'width' => 'small' ] );
|
|
201
|
+
Field::text( 'subscale', __( 'Subscale, blank for all' ), (string) ( $row['subscale'] ?? '' ), [ 'list' => 'subscale-keys', 'width' => 'key' ] );
|
|
202
|
+
},
|
|
203
|
+
[ 'add' => __( 'Add band' ) ]
|
|
204
|
+
);
|
|
205
|
+
} );
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private static function group( string $title, string $need, callable $body ): void {
|
|
209
|
+
printf(
|
|
210
|
+
'<div class="group"%s><h4>%s</h4>',
|
|
211
|
+
$need === '' ? '' : sprintf( ' data-need="%s"', esc_attr( $need ) ),
|
|
212
|
+
esc_html( $title )
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
$body();
|
|
216
|
+
|
|
217
|
+
echo '</div>';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private static function datalists( \WP_Post $post ): void {
|
|
221
|
+
Field::datalist( 'subscale-keys', Field::keys_of( Field::rows( $post->ID, '_subscales' ), 'key' ) );
|
|
222
|
+
Field::datalist( 'scale-keys', Field::keys_of( Field::rows( $post->ID, '_scales' ), 'key' ) );
|
|
223
|
+
Field::datalist( 'outcome-keys', Field::keys_of( Field::rows( $post->ID, '_outcomes' ), 'key' ) );
|
|
224
|
+
|
|
225
|
+
$report_keys = array_merge(
|
|
226
|
+
Field::keys_of( Field::rows( $post->ID, '_subscales' ), 'key' ),
|
|
227
|
+
Field::keys_of( Field::rows( $post->ID, '_bands' ), 'key' ),
|
|
228
|
+
Field::keys_of( Field::rows( $post->ID, '_types' ), 'key' ),
|
|
229
|
+
Field::keys_of( Field::rows( $post->ID, '_outcomes' ), 'key' )
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
Field::datalist( 'report-keys', array_values( array_unique( $report_keys ) ) );
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private static function colors(): array {
|
|
236
|
+
return [
|
|
237
|
+
'green-strong' => __( 'Strong green' ),
|
|
238
|
+
'green-light' => __( 'Light green' ),
|
|
239
|
+
'yellow' => __( 'Yellow' ),
|
|
240
|
+
'red-light' => __( 'Light red' ),
|
|
241
|
+
'red-strong' => __( 'Strong red' ),
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors\Interactive;
|
|
3
|
+
|
|
4
|
+
defined( 'ABSPATH' ) || exit;
|
|
5
|
+
|
|
6
|
+
final class Structure {
|
|
7
|
+
public static function register(): void {
|
|
8
|
+
foreach ( Map::with_box( 'structure' ) as $type ) {
|
|
9
|
+
add_meta_box(
|
|
10
|
+
'structure',
|
|
11
|
+
Map::get( $type )['group_label'],
|
|
12
|
+
[ __CLASS__, 'render' ],
|
|
13
|
+
$type,
|
|
14
|
+
'normal',
|
|
15
|
+
'high'
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static function render( \WP_Post $post ): void {
|
|
21
|
+
$config = Map::get( $post->post_type );
|
|
22
|
+
|
|
23
|
+
echo '<div class="interactive-panel structure">';
|
|
24
|
+
|
|
25
|
+
if ( $post->post_status === 'auto-draft' ) {
|
|
26
|
+
printf(
|
|
27
|
+
'<p class="notice notice-info">%s</p></div>',
|
|
28
|
+
esc_html( sprintf(
|
|
29
|
+
__( 'Save this first, then add %s.' ),
|
|
30
|
+
strtolower( $config['group_label'] )
|
|
31
|
+
) )
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
$children = self::children( $post->ID, $config['child'] );
|
|
38
|
+
|
|
39
|
+
echo '<div class="child-list">';
|
|
40
|
+
|
|
41
|
+
foreach ( $children as $child ) {
|
|
42
|
+
self::child( $child, $post->post_type );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
echo '</div>';
|
|
46
|
+
|
|
47
|
+
printf(
|
|
48
|
+
'<button type="button" class="button button-primary child-add" data-parent="%d" data-type="%s">%s</button>',
|
|
49
|
+
(int) $post->ID,
|
|
50
|
+
esc_attr( $post->post_type ),
|
|
51
|
+
esc_html( sprintf( __( 'Add %s' ), $config['child_label'] ) )
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
echo '</div>';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static function children( int $parent_id, string $child_type ): array {
|
|
58
|
+
return get_posts( [
|
|
59
|
+
'post_type' => $child_type,
|
|
60
|
+
'post_parent' => $parent_id,
|
|
61
|
+
'post_status' => 'publish',
|
|
62
|
+
'posts_per_page' => -1,
|
|
63
|
+
'orderby' => 'menu_order',
|
|
64
|
+
'order' => 'ASC',
|
|
65
|
+
'suppress_filters' => false,
|
|
66
|
+
] );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public static function child( \WP_Post $child, string $parent_type ): void {
|
|
70
|
+
$config = Map::get( $parent_type );
|
|
71
|
+
$items = Field::rows( $child->ID, $config['items_key'] );
|
|
72
|
+
|
|
73
|
+
Field::reset();
|
|
74
|
+
Field::push( 'children[' . $child->ID . ']' );
|
|
75
|
+
|
|
76
|
+
printf(
|
|
77
|
+
'<div class="child" data-id="%d" data-prefix="children[%d]">',
|
|
78
|
+
(int) $child->ID,
|
|
79
|
+
(int) $child->ID
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
echo '<div class="child-head">';
|
|
83
|
+
echo '<span class="rep-handle dashicons dashicons-menu"></span>';
|
|
84
|
+
printf(
|
|
85
|
+
'<input type="text" class="child-title" name="%s" data-key="title" value="%s" placeholder="%s" />',
|
|
86
|
+
esc_attr( Field::name( 'title' ) ),
|
|
87
|
+
esc_attr( $child->post_title ),
|
|
88
|
+
esc_attr( $config['child_label'] )
|
|
89
|
+
);
|
|
90
|
+
printf(
|
|
91
|
+
'<span class="child-meta"><span class="child-count">%d</span> %s</span>',
|
|
92
|
+
count( $items ),
|
|
93
|
+
esc_html( strtolower( $config['items_label'] ) )
|
|
94
|
+
);
|
|
95
|
+
echo '<button type="button" class="button-link child-toggle dashicons dashicons-arrow-down-alt2"></button>';
|
|
96
|
+
echo '<button type="button" class="button-link child-delete dashicons dashicons-trash"></button>';
|
|
97
|
+
echo '</div>';
|
|
98
|
+
|
|
99
|
+
echo '<div class="child-body">';
|
|
100
|
+
|
|
101
|
+
if ( Map::is_staged( $parent_type ) ) {
|
|
102
|
+
Field::select(
|
|
103
|
+
'type',
|
|
104
|
+
__( 'Screen' ),
|
|
105
|
+
(string) get_post_meta( $child->ID, '_section_type', true ),
|
|
106
|
+
self::screens(),
|
|
107
|
+
[ 'width' => 'wide' ]
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Field::textarea(
|
|
112
|
+
'prompt',
|
|
113
|
+
__( 'Prompt' ),
|
|
114
|
+
(string) get_post_meta( $child->ID, '_prompt', true ),
|
|
115
|
+
[ 'rows' => 2 ]
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
Field::repeater(
|
|
119
|
+
'items',
|
|
120
|
+
$items,
|
|
121
|
+
[ __CLASS__, 'item' ],
|
|
122
|
+
[
|
|
123
|
+
'label' => $config['items_label'],
|
|
124
|
+
'add' => __( 'Add question' ),
|
|
125
|
+
]
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
echo '</div>';
|
|
129
|
+
echo '</div>';
|
|
130
|
+
|
|
131
|
+
Field::reset();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public static function item( array $row ): void {
|
|
135
|
+
Field::textarea( 'text', __( 'Question' ), (string) ( $row['text'] ?? '' ), [ 'rows' => 2, 'width' => 'wide' ] );
|
|
136
|
+
|
|
137
|
+
echo '<div class="field-row">';
|
|
138
|
+
|
|
139
|
+
Field::text( 'subscale', __( 'Subscale' ), (string) ( $row['subscale'] ?? '' ), [ 'list' => 'subscale-keys', 'width' => 'key' ] );
|
|
140
|
+
Field::text( 'scale', __( 'Scale' ), (string) ( $row['scale'] ?? '' ), [ 'list' => 'scale-keys', 'width' => 'key' ] );
|
|
141
|
+
Field::number( 'weight', __( 'Weight' ), $row['weight'] ?? 1, [ 'width' => 'small' ] );
|
|
142
|
+
Field::text( 'render', __( 'Renderer' ), (string) ( $row['render'] ?? '' ), [ 'width' => 'key' ] );
|
|
143
|
+
|
|
144
|
+
echo '</div>';
|
|
145
|
+
|
|
146
|
+
Field::checkbox( 'reversed', __( 'Reverse scored' ), $row['reversed'] ?? 0 );
|
|
147
|
+
|
|
148
|
+
Field::textarea(
|
|
149
|
+
'params',
|
|
150
|
+
__( 'Renderer settings, one per line as name: value' ),
|
|
151
|
+
Field::array_to_pairs( $row['params'] ?? [] ),
|
|
152
|
+
[ 'rows' => 2 ]
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
Field::repeater(
|
|
156
|
+
'options',
|
|
157
|
+
is_array( $row['options'] ?? null ) ? $row['options'] : [],
|
|
158
|
+
static function ( array $option ): void {
|
|
159
|
+
Field::text( 'label', __( 'Option' ), (string) ( $option['label'] ?? '' ), [ 'width' => 'wide' ] );
|
|
160
|
+
|
|
161
|
+
echo '<div class="field-row">';
|
|
162
|
+
Field::number( 'value', __( 'Value' ), $option['value'] ?? '', [ 'width' => 'small', 'need' => 'option_value' ] );
|
|
163
|
+
Field::text( 'render', __( 'Renderer' ), (string) ( $option['render'] ?? '' ), [ 'width' => 'key' ] );
|
|
164
|
+
echo '</div>';
|
|
165
|
+
|
|
166
|
+
Field::checkbox( 'correct', __( 'Correct answer' ), $option['correct'] ?? 0, [ 'need' => 'option_correct' ] );
|
|
167
|
+
|
|
168
|
+
Field::textarea(
|
|
169
|
+
'points',
|
|
170
|
+
__( 'Points, one per line as outcome: number' ),
|
|
171
|
+
Field::array_to_pairs( $option['points'] ?? [] ),
|
|
172
|
+
[ 'rows' => 2, 'need' => 'option_points' ]
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
Field::textarea(
|
|
176
|
+
'params',
|
|
177
|
+
__( 'Renderer settings, one per line as name: value' ),
|
|
178
|
+
Field::array_to_pairs( $option['params'] ?? [] ),
|
|
179
|
+
[ 'rows' => 2 ]
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
[ 'label' => __( 'Options' ), 'add' => __( 'Add option' ) ]
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private static function screens(): array {
|
|
187
|
+
return [
|
|
188
|
+
'items' => __( 'Questions' ),
|
|
189
|
+
'intro' => __( 'Intro' ),
|
|
190
|
+
'interstitial' => __( 'Interstitial message' ),
|
|
191
|
+
'capture' => __( 'Details capture' ),
|
|
192
|
+
'result' => __( 'Result' ),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors;
|
|
3
|
+
|
|
4
|
+
defined( 'ABSPATH' ) || exit;
|
|
5
|
+
|
|
6
|
+
final class Legal {
|
|
7
|
+
public function __construct() {
|
|
8
|
+
add_filter( 'use_block_editor_for_post_type', [ $this, 'use_classic_editor' ], 10, 2 );
|
|
9
|
+
add_action( 'add_meta_boxes', [ $this, 'register_meta_boxes' ] );
|
|
10
|
+
add_action( 'save_post_legal_doc', [ $this, 'save_meta_boxes' ] );
|
|
11
|
+
add_filter( 'wp_insert_post_data', [ $this, 'validate_unique_doc_type_per_jurisdiction' ], 10, 2 );
|
|
12
|
+
add_action( 'admin_notices', [ $this, 'show_validation_error_notice' ] );
|
|
13
|
+
add_filter( 'quick_edit_show_taxonomy', [ $this, 'disable_taxonomy_quick_bulk_edit' ], 10, 2 );
|
|
14
|
+
add_filter( 'bulk_edit_show_taxonomy', [ $this, 'disable_taxonomy_quick_bulk_edit' ], 10, 2 );
|
|
15
|
+
add_action( 'restrict_manage_posts', [ $this, 'render_admin_column_filters' ] );
|
|
16
|
+
add_filter( 'parse_query', [ $this, 'apply_admin_column_filters' ] );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public function use_classic_editor( $use_block_editor, $post_type ) {
|
|
20
|
+
if ( $post_type === 'legal_doc' ) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return $use_block_editor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public function register_meta_boxes() {
|
|
27
|
+
remove_meta_box( 'slugdiv', 'legal_doc', 'normal' );
|
|
28
|
+
foreach ( [ 'jurisdiction', 'legal_doc_type' ] as $taxonomy ) {
|
|
29
|
+
remove_meta_box( $taxonomy . 'div', 'legal_doc', 'side' );
|
|
30
|
+
remove_meta_box( 'tagsdiv-' . $taxonomy, 'legal_doc', 'side' );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
add_meta_box(
|
|
34
|
+
'legal_doc_jurisdiction',
|
|
35
|
+
'Jurisdiction',
|
|
36
|
+
[ $this, 'render_jurisdiction_metabox' ],
|
|
37
|
+
'legal_doc',
|
|
38
|
+
'side',
|
|
39
|
+
'default'
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
add_meta_box(
|
|
43
|
+
'legal_doc_doc_type',
|
|
44
|
+
'Template Type',
|
|
45
|
+
[ $this, 'render_doc_type_metabox' ],
|
|
46
|
+
'legal_doc',
|
|
47
|
+
'side',
|
|
48
|
+
'default'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public function render_jurisdiction_metabox( $post ) {
|
|
53
|
+
wp_nonce_field( 'legal_doc_taxonomy_nonce', 'legal_doc_taxonomy_nonce' );
|
|
54
|
+
|
|
55
|
+
$terms = get_terms( [ 'taxonomy' => 'jurisdiction', 'hide_empty' => false ] );
|
|
56
|
+
$current = wp_get_post_terms( $post->ID, 'jurisdiction', [ 'fields' => 'ids' ] );
|
|
57
|
+
$selected = ! empty( $current ) ? $current[0] : '';
|
|
58
|
+
|
|
59
|
+
echo '<select name="legal_doc_jurisdiction" style="width:100%">';
|
|
60
|
+
echo '<option value="">— Select Jurisdiction —</option>';
|
|
61
|
+
foreach ( $terms as $term ) {
|
|
62
|
+
printf(
|
|
63
|
+
'<option value="%d"%s>%s</option>',
|
|
64
|
+
$term->term_id,
|
|
65
|
+
selected( $selected, $term->term_id, false ),
|
|
66
|
+
esc_html( $term->name )
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
echo '</select>';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public function render_doc_type_metabox( $post ) {
|
|
73
|
+
$terms = get_terms( [ 'taxonomy' => 'legal_doc_type', 'hide_empty' => false ] );
|
|
74
|
+
$current = wp_get_post_terms( $post->ID, 'legal_doc_type', [ 'fields' => 'ids' ] );
|
|
75
|
+
$selected = ! empty( $current ) ? $current[0] : '';
|
|
76
|
+
|
|
77
|
+
echo '<select name="legal_doc_doc_type" style="width:100%">';
|
|
78
|
+
echo '<option value="">— Select Doc Type —</option>';
|
|
79
|
+
foreach ( $terms as $term ) {
|
|
80
|
+
printf(
|
|
81
|
+
'<option value="%d"%s>%s</option>',
|
|
82
|
+
$term->term_id,
|
|
83
|
+
selected( $selected, $term->term_id, false ),
|
|
84
|
+
esc_html( $term->name )
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
echo '</select>';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public function validate_unique_doc_type_per_jurisdiction( $data, $postarr ) {
|
|
91
|
+
if ( $data['post_type'] !== 'legal_doc' ) return $data;
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
! isset( $_POST['legal_doc_taxonomy_nonce'] ) ||
|
|
95
|
+
! wp_verify_nonce( $_POST['legal_doc_taxonomy_nonce'], 'legal_doc_taxonomy_nonce' )
|
|
96
|
+
) return $data;
|
|
97
|
+
|
|
98
|
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $data;
|
|
99
|
+
|
|
100
|
+
if ( in_array( $data['post_status'], [ 'trash', 'auto-draft' ], true ) ) return $data;
|
|
101
|
+
|
|
102
|
+
$post_id = $postarr['ID'] ?? 0;
|
|
103
|
+
$jurisdiction = intval( $_POST['legal_doc_jurisdiction'] ?? 0 );
|
|
104
|
+
$doc_type_id = intval( $_POST['legal_doc_doc_type'] ?? 0 );
|
|
105
|
+
|
|
106
|
+
if ( ! $jurisdiction || ! $doc_type_id ) return $data;
|
|
107
|
+
|
|
108
|
+
$conflict = get_posts( [
|
|
109
|
+
'post_type' => 'legal_doc',
|
|
110
|
+
'post_status' => 'any',
|
|
111
|
+
'posts_per_page' => 1,
|
|
112
|
+
'post__not_in' => $post_id ? [ $post_id ] : [],
|
|
113
|
+
'fields' => 'ids',
|
|
114
|
+
'tax_query' => [
|
|
115
|
+
'relation' => 'AND',
|
|
116
|
+
[ 'taxonomy' => 'jurisdiction', 'field' => 'term_id', 'terms' => $jurisdiction ],
|
|
117
|
+
[ 'taxonomy' => 'legal_doc_type', 'field' => 'term_id', 'terms' => $doc_type_id ],
|
|
118
|
+
],
|
|
119
|
+
] );
|
|
120
|
+
|
|
121
|
+
if ( empty( $conflict ) ) return $data;
|
|
122
|
+
|
|
123
|
+
$jur_term = get_term( $jurisdiction, 'jurisdiction' );
|
|
124
|
+
$type_term = get_term( $doc_type_id, 'legal_doc_type' );
|
|
125
|
+
|
|
126
|
+
$jur_name = ( $jur_term && ! is_wp_error( $jur_term ) ) ? $jur_term->name : "#{$jurisdiction}";
|
|
127
|
+
$type_name = ( $type_term && ! is_wp_error( $type_term ) ) ? $type_term->name : "#{$doc_type_id}";
|
|
128
|
+
|
|
129
|
+
$message = sprintf(
|
|
130
|
+
'A legal doc with template type <strong>%s</strong> already exists for jurisdiction <strong>%s</strong>.',
|
|
131
|
+
esc_html( $type_name ),
|
|
132
|
+
esc_html( $jur_name )
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
set_transient( 'legal_doc_validation_error_' . get_current_user_id(), $message, 60 );
|
|
136
|
+
|
|
137
|
+
$data['post_status'] = get_post_status( $post_id ) ?: 'draft';
|
|
138
|
+
|
|
139
|
+
return $data;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public function show_validation_error_notice() {
|
|
143
|
+
$message = get_transient( 'legal_doc_validation_error_' . get_current_user_id() );
|
|
144
|
+
|
|
145
|
+
if ( ! $message ) return;
|
|
146
|
+
|
|
147
|
+
delete_transient( 'legal_doc_validation_error_' . get_current_user_id() );
|
|
148
|
+
|
|
149
|
+
printf(
|
|
150
|
+
'<div class="notice notice-error is-dismissible"><p>%s</p></div>',
|
|
151
|
+
wp_kses( $message, [ 'strong' => [] ] )
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public function save_meta_boxes( $post_id ) {
|
|
156
|
+
if (
|
|
157
|
+
! isset( $_POST['legal_doc_taxonomy_nonce'] ) ||
|
|
158
|
+
! wp_verify_nonce( $_POST['legal_doc_taxonomy_nonce'], 'legal_doc_taxonomy_nonce' )
|
|
159
|
+
) return;
|
|
160
|
+
|
|
161
|
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
|
|
162
|
+
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
|
|
163
|
+
|
|
164
|
+
if ( isset( $_POST['legal_doc_jurisdiction'] ) ) {
|
|
165
|
+
$term = intval( $_POST['legal_doc_jurisdiction'] );
|
|
166
|
+
wp_set_post_terms( $post_id, $term ? [ $term ] : [], 'jurisdiction' );
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if ( isset( $_POST['legal_doc_doc_type'] ) ) {
|
|
170
|
+
$term = intval( $_POST['legal_doc_doc_type'] );
|
|
171
|
+
wp_set_post_terms( $post_id, $term ? [ $term ] : [], 'legal_doc_type' );
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public function disable_taxonomy_quick_bulk_edit( $show, $taxonomy_name ) {
|
|
176
|
+
if ( in_array( $taxonomy_name, [ 'jurisdiction', 'legal_doc_type' ], true ) ) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return $show;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public function render_admin_column_filters( $post_type ) {
|
|
183
|
+
if ( $post_type !== 'legal_doc' ) return;
|
|
184
|
+
|
|
185
|
+
$filters = [
|
|
186
|
+
'jurisdiction' => [ 'slug' => 'filter_jurisdiction', 'label' => 'All Jurisdictions' ],
|
|
187
|
+
'legal_doc_type' => [ 'slug' => 'filter_legal_doc_type', 'label' => 'All Template Types' ],
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
foreach ( $filters as $taxonomy => $config ) {
|
|
191
|
+
$terms = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => false ] );
|
|
192
|
+
$selected = isset( $_GET[ $config['slug'] ] ) ? sanitize_key( $_GET[ $config['slug'] ] ) : '';
|
|
193
|
+
|
|
194
|
+
echo '<select name="' . esc_attr( $config['slug'] ) . '">';
|
|
195
|
+
echo '<option value="">' . esc_html( $config['label'] ) . '</option>';
|
|
196
|
+
foreach ( $terms as $term ) {
|
|
197
|
+
printf(
|
|
198
|
+
'<option value="%s"%s>%s</option>',
|
|
199
|
+
esc_attr( $term->slug ),
|
|
200
|
+
selected( $selected, $term->slug, false ),
|
|
201
|
+
esc_html( $term->name )
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
echo '</select>';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public function apply_admin_column_filters( $query ) {
|
|
209
|
+
global $pagenow;
|
|
210
|
+
|
|
211
|
+
if ( ! is_admin() || $pagenow !== 'edit.php' ) return;
|
|
212
|
+
if ( ( $query->query['post_type'] ?? '' ) !== 'legal_doc' ) return;
|
|
213
|
+
|
|
214
|
+
$filters = [
|
|
215
|
+
'filter_jurisdiction' => 'jurisdiction',
|
|
216
|
+
'filter_legal_doc_type' => 'legal_doc_type',
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
$tax_query = [];
|
|
220
|
+
|
|
221
|
+
foreach ( $filters as $param => $taxonomy ) {
|
|
222
|
+
if ( empty( $_GET[ $param ] ) ) continue;
|
|
223
|
+
|
|
224
|
+
$tax_query[] = [
|
|
225
|
+
'taxonomy' => $taxonomy,
|
|
226
|
+
'field' => 'slug',
|
|
227
|
+
'terms' => sanitize_key( $_GET[ $param ] ),
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if ( ! empty( $tax_query ) ) {
|
|
232
|
+
$query->set( 'tax_query', $tax_query );
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|