$o2_options * @return array */ public static function set_view_mode_option( array $o2_options ): array { if ( self::should_show_grid_view() ) { $o2_options['options']['viewMode'] = 'grid'; } return $o2_options; } /** * Drop fragment fields we don't render in a tile. Mirrors Compact_View's * slimming — tiles show title + excerpt + author + date only. * * @param array $args * @return array */ public static function slim_fragment_args( array $args ): array { if ( self::should_show_grid_view() ) { // Tiles only need `commentCount` and `tagsArray` (for project // status). Skip everything else expensive — same set compact // view skips, including `comments` since tiles never render // `.o2-post-comments`. $args['skip']['post'] = [ 'contentFiltered' => true, 'mentions' => true, 'shortcodes' => true, 'comments' => true, ]; } return $args; } /** * Produce a short tile excerpt: * - For xposts, "From +blogname" (handled by Compact_View::get_post_content_preview). * - For regular posts, the first ~28 words of the excerpt. * * Mirrors how Compact_View prepares `contentPreview` so the same field * name is available to the underscore tile template. * * @param array $fragment * @return array */ public static function format_post_preview( array $fragment ): array { if ( ! self::should_show_grid_view() ) { return $fragment; } if ( ! empty( $fragment['is_xpost'] ) ) { $fragment['contentPreview'] = Compact_View::get_post_content_preview( $fragment['contentRaw'] ?? '', true ); } else { $excerpt = wp_strip_all_tags( (string) ( $fragment['contentRaw'] ?? '' ) ); $fragment['contentPreview'] = wp_trim_words( $excerpt, 28, '…' ); } $fragment['titleFiltered'] = Compact_View::get_post_title_preview( $fragment['titleFiltered'] ?? '', (bool) ( $fragment['is_xpost'] ?? false ) ); if ( '' === trim( (string) $fragment['titleFiltered'] ) ) { $fragment['isUntitled'] = true; } // contentRaw isn't needed once we've derived contentPreview. $fragment['contentRaw'] = ''; return $fragment; } }