array( 'name' => __( 'Forms', 'flexsolutions-form-builder' ), 'singular_name' => __( 'Form', 'flexsolutions-form-builder' ), 'menu_name' => __( 'Flexsolutions Form Builder', 'flexsolutions-form-builder' ), 'add_new_item' => __( 'Add New Form', 'flexsolutions-form-builder' ), 'edit_item' => __( 'Edit Form', 'flexsolutions-form-builder' ), 'new_item' => __( 'New Form', 'flexsolutions-form-builder' ), 'search_items' => __( 'Search Forms', 'flexsolutions-form-builder' ), 'not_found' => __( 'No forms found.', 'flexsolutions-form-builder' ), 'not_found_in_trash' => __( 'No forms found in Trash.', 'flexsolutions-form-builder' ), 'all_items' => __( 'All Forms', 'flexsolutions-form-builder' ), ), // Not publicly queryable: forms are only shown through the shortcode or block. 'public' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'menu_icon' => 'dashicons-email-alt', 'menu_position' => 30, 'has_archive' => false, 'rewrite' => false, 'query_var' => false, 'hierarchical' => false, 'supports' => array( 'title', 'revisions' ), // Exposed to REST only so the block editor can list forms. The custom // controller restricts reads to users who can edit forms. 'show_in_rest' => true, 'rest_base' => 'tflexforms-forms', 'rest_controller_class' => Forms_Rest_Controller::class, 'capability_type' => array( 'tflexforms_form', 'tflexforms_forms' ), 'map_meta_cap' => true, 'delete_with_user' => false, ) ); // Arguments arrive loosely typed from core, so cast rather than type-hint. $auth = static fn( $allowed, $meta_key, $post_id ): bool => current_user_can( 'edit_post', (int) $post_id ); register_post_meta( self::POST_TYPE, self::META_TEMPLATE, array( 'type' => 'string', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Form::class, 'sanitize_template' ), 'auth_callback' => $auth, ) ); register_post_meta( self::POST_TYPE, self::META_MAIL, array( 'type' => 'object', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Form::class, 'sanitize_mail_settings' ), 'auth_callback' => $auth, ) ); register_post_meta( self::POST_TYPE, self::META_MESSAGES, array( 'type' => 'object', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Form::class, 'sanitize_messages' ), 'auth_callback' => $auth, ) ); register_post_meta( self::POST_TYPE, self::META_SETTINGS, array( 'type' => 'object', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Form::class, 'sanitize_settings' ), 'auth_callback' => $auth, ) ); // Form schema JSON (docs/form-schema.md). Like all post meta it is // unslashed on save, so pass wp_slash( $json ) to update_post_meta(). register_post_meta( self::POST_TYPE, self::META_SCHEMA, array( 'type' => 'string', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Form_Schema::class, 'sanitize_meta' ), 'auth_callback' => $auth, ) ); // Style tab settings (Style::defaults() shape). register_post_meta( self::POST_TYPE, Style::META, array( 'type' => 'object', 'single' => true, 'show_in_rest' => false, 'sanitize_callback' => array( Style::class, 'sanitize' ), 'auth_callback' => $auth, ) ); } }