ategories as $category) { if (is_array($category)) { // New format: {id, name, url} $id = isset($category['id']) ? absint($category['id']) : 0; if ($id > 0) { $item = ['id' => $id]; if (isset($category['name'])) { $item['name'] = sanitize_text_field($category['name']); } if (isset($category['url'])) { $item['url'] = esc_url_raw($category['url']); } $sanitized[] = $item; } } else { // Old format: just ID $id = absint($category); if ($id > 0) { $sanitized[] = $id; } } } return array_values($sanitized); } /** * Sanitize visibility custom post types array * Handles both old format (slug-only) and new format (objects with metadata) * * @since 2.5.0 * @param array $post_types Array of post types (slugs or objects) * @return array Sanitized post types array */ private static function sanitize_visibility_post_types(array $post_types): array { $sanitized = []; foreach ($post_types as $post_type) { if (is_array($post_type)) { // New format: {name (slug), label} $slug = isset($post_type['name']) ? sanitize_key($post_type['name']) : ''; if (!empty($slug)) { $item = ['name' => $slug]; if (isset($post_type['label'])) { $item['label'] = sanitize_text_field($post_type['label']); } $sanitized[] = $item; } } else { // Old format: just slug $slug = sanitize_key($post_type); if (!empty($slug)) { $sanitized[] = $slug; } } } return array_values($sanitized); } }