@wp-operations/wp-ops 0.6.0 → 0.7.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.
@@ -257,6 +257,52 @@ final class Engine {
257
257
  return $parts ? "Instructions from this platform's agents, skills and docs (the rules above still come first):\n\n" . implode( "\n\n", $parts ) : '';
258
258
  }
259
259
 
260
+ /**
261
+ * The app's metadata and links, labelled as platform.json defines them.
262
+ */
263
+ public static function details( array $app ): array {
264
+ $details = [];
265
+
266
+ foreach ( Registry::metadata_fields() as $field ) {
267
+ $value = $app['metadata'][ $field['key'] ] ?? '';
268
+
269
+ if ( 'checkbox' === $field['type'] ) {
270
+ $value = empty( $value ) ? '' : 'yes';
271
+ } elseif ( 'select' === $field['type'] && is_scalar( $value ) && isset( $field['options'][ $value ] ) ) {
272
+ $value = $field['options'][ $value ];
273
+ } elseif ( 'image' === $field['type'] && is_numeric( $value ) && (int) $value > 0 ) {
274
+ $value = (string) wp_get_attachment_url( (int) $value );
275
+ }
276
+
277
+ if ( is_array( $value ) ) {
278
+ $value = implode( ', ', array_filter( array_map( 'strval', array_filter( $value, 'is_scalar' ) ) ) );
279
+ }
280
+
281
+ $value = trim( wp_strip_all_tags( (string) $value ) );
282
+
283
+ if ( '' !== $value ) {
284
+ $details[] = sprintf( '- %s (%s): %s', $field['label'], $field['key'], $value );
285
+ }
286
+ }
287
+
288
+ foreach ( Registry::links() as $key => $link ) {
289
+ $id = (int) ( $app['links'][ $key ] ?? 0 );
290
+
291
+ if ( $id < 1 ) {
292
+ continue;
293
+ }
294
+
295
+ $term = empty( $link['taxonomy'] ) ? null : get_term( $id, (string) $link['taxonomy'] );
296
+ $name = $term instanceof \WP_Term ? $term->name : (string) get_the_title( $id );
297
+
298
+ if ( '' !== $name ) {
299
+ $details[] = sprintf( '- %s (%s): %s', (string) $link['label'], $key, $name );
300
+ }
301
+ }
302
+
303
+ return $details;
304
+ }
305
+
260
306
  private static function context( array $app, array $tree, array $files ): string {
261
307
  $mapping = Ops::mapping( (int) $app['id'], (string) $app['name'] );
262
308
  $lines = [
@@ -264,6 +310,12 @@ final class Engine {
264
310
  sprintf( 'App: %s. Folder: %s (%s). Languages: %s. Content types: %s.', $app['name'], $mapping['path'] ?: 'not mapped', $mapping['label'], implode( ', ', (array) $app['languages'] ) ?: 'default', implode( ', ', array_keys( array_diff_key( (array) $app['contents'], [ 'thumbnail_group_id' => 1 ] ) ) ) ?: 'none' ),
265
311
  ];
266
312
 
313
+ $details = self::details( $app );
314
+
315
+ if ( $details ) {
316
+ $lines[] = "The app's settings, as configured on the platform (use these values; never invent them):\n" . implode( "\n", $details );
317
+ }
318
+
267
319
  if ( $tree ) {
268
320
  $lines[] = "Files in the app folder (paths relative to it):\n" . implode( "\n", array_slice( $tree, 0, 400 ) ) . ( count( $tree ) > 400 ? "\n… " . ( count( $tree ) - 400 ) . ' more' : '' );
269
321
  } else {
@@ -3,7 +3,7 @@ Theme Name: wp-operations
3
3
  Theme URI: https://github.com/wordpress-operations/wordpress-operations
4
4
  Author: wp-operations
5
5
  Description: wp-operations: AI-powered content engine with platform builder, CMS and operations for one repository.
6
- Version: 0.1.2
6
+ Version: 0.1.3
7
7
  Requires at least: 6.4
8
8
  Requires PHP: 8.0
9
9
  License: GPL-2.0-or-later