'string', '_admirly_role' => 'string', '_admirly_sub' => 'string', '_admirly_rating' => 'integer', '_admirly_consent_at' => 'string', '_admirly_ip_hash' => 'string', '_admirly_source' => 'string', '_admirly_lang' => 'string', ]; public function register(): void { add_action( 'init', [ $this, 'registerPostType' ] ); add_action( 'init', [ $this, 'registerMeta' ] ); } public function registerPostType(): void { register_post_type( Plugin::CPT, [ 'labels' => [ 'name' => __( 'Admirly', 'admirly' ), 'singular_name' => __( 'Admirly', 'admirly' ), 'add_new' => __( 'New review', 'admirly' ), 'add_new_item' => __( 'Add new review', 'admirly' ), 'edit_item' => __( 'Edit review', 'admirly' ), 'all_items' => __( 'All reviews', 'admirly' ), 'search_items' => __( 'Search reviews', 'admirly' ), 'not_found' => __( 'No reviews yet.', 'admirly' ), 'not_found_in_trash' => __( 'No reviews in trash.', 'admirly' ), 'menu_name' => __( 'Admirly', 'admirly' ), ], 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_rest' => false, 'exclude_from_search' => true, 'menu_position' => 26, 'menu_icon' => 'dashicons-star-filled', 'supports' => [ 'title', 'editor' ], 'capability_type' => 'post', 'map_meta_cap' => true, 'has_archive' => false, 'rewrite' => false, ] ); } /** Meta keys with their types; extensions add their own through `admirly_meta_keys`. @return array */ public static function metaKeys(): array { /** @param array $keys meta key => type */ return (array) apply_filters( 'admirly_meta_keys', self::META ); } public function registerMeta(): void { foreach ( self::metaKeys() as $key => $type ) { register_post_meta( Plugin::CPT, $key, [ 'type' => $type, 'single' => true, 'show_in_rest' => false, 'auth_callback' => static fn() => current_user_can( 'edit_others_posts' ), ] ); } } /** Card subtitle "Role ยท Sub" (extensions may append parts). @param array $item */ public static function cardLabel( array $item ): string { $fields = Plugin::fields(); $parts = Labels::parts( $fields, (string) ( $item['role'] ?? '' ), (string) ( $item['sub'] ?? '' ) ); /** @param string[] $parts @param array $item @param array $fields */ $parts = (array) apply_filters( 'admirly_card_label_parts', $parts, $item, $fields ); return Labels::join( array_map( 'strval', $parts ) ); } /** Collects the display data of a review; extensions add their own keys through `admirly_item`. @return array */ public static function item( \WP_Post $post ): array { $name = (string) get_post_meta( $post->ID, '_admirly_name', true ); if ( $name === '' ) { $name = $post->post_title; } $item = [ 'id' => $post->ID, 'name' => $name, 'role' => (string) get_post_meta( $post->ID, '_admirly_role', true ), 'sub' => (string) get_post_meta( $post->ID, '_admirly_sub', true ), 'rating' => max( 0, min( 5, (int) get_post_meta( $post->ID, '_admirly_rating', true ) ) ), 'text' => wp_strip_all_tags( $post->post_content ), 'lang' => (string) get_post_meta( $post->ID, '_admirly_lang', true ), 'date' => get_the_date( 'F Y', $post ), 'date_iso' => get_the_date( 'c', $post ), ]; /** @param array $item @param \WP_Post $post */ return (array) apply_filters( 'admirly_item', $item, $post ); } }