_x( 'Form Submissions', 'post type general name', 'airo-wp' ), 'singular_name' => _x( 'Form Submission', 'post type singular name', 'airo-wp' ), 'menu_name' => _x( 'Form Submissions', 'admin menu', 'airo-wp' ), 'name_admin_bar' => _x( 'Form Submission', 'add new on admin bar', 'airo-wp' ), 'all_items' => __( 'All Submissions', 'airo-wp' ), 'view_item' => __( 'View Submission', 'airo-wp' ), 'search_items' => __( 'Search Submissions', 'airo-wp' ), 'not_found' => __( 'No submissions found', 'airo-wp' ), 'not_found_in_trash' => __( 'No submissions found in Trash', 'airo-wp' ), ); $args = array( 'labels' => $labels, 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => 'airo-wp', // Show under airo-wp menu. 'query_var' => true, 'rewrite' => false, 'show_in_rest' => false, // Prevent REST API access. 'capability_type' => 'dsgo_form_submission', 'capabilities' => array( 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'edit_private_posts' => 'manage_options', 'edit_published_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'delete_private_posts' => 'manage_options', 'delete_published_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'create_posts' => 'do_not_allow', // Prevent manual creation - only via form submission. ), 'map_meta_cap' => false, // Disabled - all capabilities explicitly mapped to manage_options. 'has_archive' => false, 'hierarchical' => false, 'supports' => array( 'title' ), ); register_post_type( 'dsgo_form_submission', $args ); } /** * Add meta boxes to submission edit screen. */ public function add_meta_boxes() { add_meta_box( 'dsg_submission_details', __( 'Submission Details', 'airo-wp' ), array( $this, 'render_submission_details' ), 'dsgo_form_submission', 'normal', 'high' ); add_meta_box( 'dsg_submission_meta', __( 'Submission Information', 'airo-wp' ), array( $this, 'render_submission_meta' ), 'dsgo_form_submission', 'side', 'default' ); } /** * Render submission details meta box. * * @param \WP_Post $post Post object. */ public function render_submission_details( $post ) { $fields = get_post_meta( $post->ID, '_dsg_form_fields', true ); if ( empty( $fields ) || ! is_array( $fields ) ) { echo '
' . esc_html__( 'No form data available.', 'airo-wp' ) . '
'; return; } echo '| ' . esc_html__( 'Field', 'airo-wp' ) . ' | '; echo '' . esc_html__( 'Value', 'airo-wp' ) . ' | '; echo '' . esc_html__( 'Type', 'airo-wp' ) . ' | '; echo '
|---|---|---|
| ' . $name_cell . ' | '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above. echo '' . $value . ' | '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '' . esc_html( $type ) . ' | ';
echo '
' . esc_html( $form_id ) . '';
echo '' . esc_html( $ip_address ) . '';
echo '' . esc_html( $user_agent ) . '';
echo '' . esc_html( $form_id ) . '' : '—';
break;
case 'email_status':
$email_sent = get_post_meta( $post_id, '_dsg_email_sent', true );
if ( '' === $email_sent ) {
echo '—';
} elseif ( 'yes' === $email_sent ) {
echo '✓ ' . esc_html__( 'Sent', 'airo-wp' ) . '';
} else {
echo '✗ ' . esc_html__( 'Failed', 'airo-wp' ) . '';
}
break;
case 'ip_address':
$ip_address = get_post_meta( $post_id, '_dsg_submission_ip', true );
echo $ip_address ? '' . esc_html( $ip_address ) . '' : '—';
break;
}
}
/**
* Enqueue admin styles for the submission meta box.
*
* @param string $hook Current admin page hook suffix.
*/
public function enqueue_submission_styles( string $hook ): void {
if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
return;
}
wp_register_style( 'airowp-submissions', false, array(), AIRO_WP_VERSION ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_enqueue_style( 'airowp-submissions' );
wp_add_inline_style( 'airowp-submissions', '.airo-wp-submission-status{margin-bottom:1em;padding:10px;border-left:3px solid}.airo-wp-submission-status--success{background:#d4edda;border-color:#28a745}.airo-wp-submission-status--success .airo-wp-submission-status__label{color:#155724}.airo-wp-submission-status--error{background:#f8d7da;border-color:#dc3545}.airo-wp-submission-status--error .airo-wp-submission-status__label{color:#721c24}' );
}
}