Skip to content

Commit 3d38b64

Browse files
Copilotswissspidy
andcommitted
Add font library advanced commands (list-families, list-categories, install)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 9a2bfbb commit 3d38b64

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/Font_Collection_Command.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,24 @@ public function list_families( $args, $assoc_args ) {
284284
// Filter by category if specified.
285285
$category = \WP_CLI\Utils\get_flag_value( $assoc_args, 'category' );
286286
if ( $category ) {
287-
$font_families = array_filter(
288-
$font_families,
289-
function ( $family ) use ( $category ) {
290-
$categories = isset( $family['category'] ) ? (array) $family['category'] : array();
291-
return in_array( $category, $categories, true );
287+
$filtered = array();
288+
foreach ( $font_families as $family ) {
289+
if ( ! is_array( $family ) ) {
290+
continue;
292291
}
293-
);
292+
$categories = isset( $family['category'] ) ? (array) $family['category'] : array();
293+
if ( in_array( $category, $categories, true ) ) {
294+
$filtered[] = $family;
295+
}
296+
}
297+
$font_families = $filtered;
294298
}
295299

296300
$items = array();
297301
foreach ( $font_families as $family ) {
302+
if ( ! is_array( $family ) ) {
303+
continue;
304+
}
298305
$category_list = isset( $family['category'] ) ? (array) $family['category'] : array();
299306
$items[] = array(
300307
'slug' => isset( $family['slug'] ) ? $family['slug'] : '',

src/Font_Face_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public function install( $args, $assoc_args ) {
466466
'post_parent' => $family_id,
467467
'post_title' => $title,
468468
'post_status' => 'publish',
469-
'post_content' => wp_json_encode( $face_settings ),
469+
'post_content' => wp_json_encode( $face_settings ) ?: '{}',
470470
);
471471

472472
$font_face_id = wp_insert_post( $post_data, true );

0 commit comments

Comments
 (0)