index = $index; } /** * Every post the current user can edit that has blocks with an active * rule, most recently changed first. * * `kind` is "template", "pattern" or "post" (any other content type). * * @return array */ public function all(): array { $items = array(); foreach ( $this->index->live_posts() as $post_id => $index ) { $blocks = (int) ( $index['blocks'] ?? 0 ) - (int) ( $index['menu_items'] ?? 0 ); if ( $blocks < 1 || ! current_user_can( 'edit_post', $post_id ) ) { continue; } $post = get_post( $post_id ); if ( null === $post ) { continue; } $type = get_post_type_object( $post->post_type ); $items[] = array( 'id' => (int) $post_id, 'title' => trim( html_entity_decode( wp_strip_all_tags( $post->post_title ), ENT_QUOTES, 'UTF-8' ) ), 'type' => null !== $type ? (string) $type->labels->singular_name : $post->post_type, 'kind' => self::kind( $post->post_type ), 'blocks' => $blocks, 'edit_url' => (string) get_edit_post_link( $post_id, 'raw' ), 'modified' => (int) strtotime( $post->post_modified_gmt . ' UTC' ), ); } usort( $items, static function ( array $a, array $b ): int { return array( $b['modified'], $a['id'] ) <=> array( $a['modified'], $b['id'] ); } ); return $items; } /** * How a post type is counted on the Dashboard. * * @param string $post_type Post type. * @return string "template", "pattern" or "post". */ public static function kind( string $post_type ): string { if ( in_array( $post_type, self::TEMPLATE_TYPES, true ) ) { return 'template'; } return self::PATTERN_TYPE === $post_type ? 'pattern' : 'post'; } }