Label keyed by the symbol that proves it is running. */ private const OWNERS = [ 'acf_get_field_groups' => 'ACF', 'pods' => 'Pods', 'RWMB_Loader' => 'Meta Box', 'cptui_get_post_type_data' => 'CPT UI', 'Jet_Engine' => 'JetEngine', ]; /** * Most post types or taxonomies to name before summarising the rest. * * A site with sixty post types would otherwise spend most of the context * budget listing them. What was left out is counted rather than dropped * silently: an assistant handed a short list assumes it is complete and * stops looking, where one told there are 48 more asks. * * @since 1.4.0 * @var int */ private const MAX_NAMED = 12; /** * Build the content-model section. * * @return array{post_types: list, post_types_more?: int, taxonomies: list, taxonomies_more?: int, owners?: list} * @since 1.4.0 */ public function read(): array { $post_types = $this->post_types(); $taxonomies = $this->taxonomies(); $model = [ 'post_types' => array_slice( $post_types, 0, self::MAX_NAMED ), 'taxonomies' => array_slice( $taxonomies, 0, self::MAX_NAMED ), ]; $post_types_more = count( $post_types ) - self::MAX_NAMED; if ( $post_types_more > 0 ) { $model['post_types_more'] = $post_types_more; } $taxonomies_more = count( $taxonomies ) - self::MAX_NAMED; if ( $taxonomies_more > 0 ) { $model['taxonomies_more'] = $taxonomies_more; } $owners = $this->owners(); if ( $owners !== [] ) { $model['owners'] = $owners; } return $model; } /** * The post types worth naming. * * Public types only, plus `attachment` dropped: the assistant reaches media * through the media abilities, not by treating it as a content type, and * naming it here invites the wrong tool. Everything non-public is * infrastructure the model has no business writing to. * * @return list Public post type slugs, without `attachment`. * @since 1.4.0 */ private function post_types(): array { $types = get_post_types( [ 'public' => true ], 'names' ); return array_values( array_diff( array_map( 'strval', $types ), [ 'attachment' ] ) ); } /** * The taxonomies worth naming. * * @return list Public taxonomy slugs. * @since 1.4.0 */ private function taxonomies(): array { $taxonomies = get_taxonomies( [ 'public' => true ], 'names' ); return array_values( array_map( 'strval', $taxonomies ) ); } /** * Which plugins model content on this site. * * @return list Labels of the content-modelling plugins running here. * @since 1.4.0 */ private function owners(): array { $owners = []; foreach ( self::OWNERS as $symbol => $label ) { if ( Symbols::defined( (string) $symbol ) ) { $owners[] = $label; } } return $owners; } }