__( 'Articles', 'karma-docs' ), 'singular_name' => __( 'Article', 'karma-docs' ), 'menu_name' => __( 'Docs', 'karma-docs' ), 'all_items' => __( 'All Articles', 'karma-docs' ), 'add_new' => __( 'Add Article', 'karma-docs' ), 'add_new_item' => __( 'Add New Article', 'karma-docs' ), 'edit_item' => __( 'Edit Article', 'karma-docs' ), 'new_item' => __( 'New Article', 'karma-docs' ), 'view_item' => __( 'View Article', 'karma-docs' ), 'search_items' => __( 'Search Articles', 'karma-docs' ), 'not_found' => __( 'No articles found.', 'karma-docs' ), 'not_found_in_trash' => __( 'No articles found in Trash.', 'karma-docs' ), 'parent_item_colon' => __( 'Parent Article:', 'karma-docs' ), ); $supports = array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'page-attributes', 'custom-fields' ); if ( Settings::get( 'enable_comments' ) ) { $supports[] = 'comments'; } register_post_type( self::ARTICLE, array( 'labels' => $labels, 'public' => true, 'hierarchical' => true, 'show_ui' => true, 'show_in_menu' => 'karma-docs', 'show_in_rest' => true, 'rest_base' => 'kdocs-articles', 'menu_icon' => 'dashicons-book-alt', 'supports' => $supports, 'has_archive' => true, 'rewrite' => false, 'query_var' => 'kdocs_article', 'capability_type' => 'post', 'map_meta_cap' => true, 'template' => array(), ) ); } /** * Registers article meta exposed to REST / the block editor. */ public function register_meta() { $auth = static function () { return current_user_can( 'edit_posts' ); }; $fields = array( '_kdocs_views' => 'integer', '_kdocs_helpful_yes' => 'integer', '_kdocs_helpful_no' => 'integer', '_kdocs_icon' => 'string', '_kdocs_access' => 'string', '_kdocs_roles' => 'array', '_kdocs_reviewed_at' => 'string', '_kdocs_hide_toc' => 'boolean', '_kdocs_featured' => 'boolean', '_kdocs_related' => 'array', // SEO, used when no SEO plugin is active. '_kdocs_seo_title' => 'string', '_kdocs_seo_description' => 'string', '_kdocs_canonical' => 'string', '_kdocs_noindex' => 'boolean', ); foreach ( $fields as $key => $type ) { $args = array( 'type' => $type, 'single' => true, 'show_in_rest' => true, 'auth_callback' => $auth, ); if ( '_kdocs_icon' === $key ) { $args['sanitize_callback'] = array( Icons::class, 'sanitize' ); } elseif ( '_kdocs_canonical' === $key ) { $args['sanitize_callback'] = 'esc_url_raw'; } elseif ( in_array( $key, array( '_kdocs_seo_title', '_kdocs_seo_description' ), true ) ) { $args['sanitize_callback'] = 'sanitize_text_field'; } if ( 'array' === $type ) { $args['show_in_rest'] = array( 'schema' => array( 'type' => 'array', 'items' => array( 'type' => '_kdocs_roles' === $key ? 'string' : 'integer' ), ), ); $args['default'] = array(); } register_post_meta( self::ARTICLE, $key, $args ); } } }