// Handle add perspective form if ( $perspectives_table_exists && isset($_POST['add_perspective']) && !empty($_POST['perspective_name']) && !empty($_POST['perspective_type']) ) { $name = sanitize_text_field($_POST['perspective_name']); $type = sanitize_text_field($_POST['perspective_type']); $states = isset($_POST['perspective_states']) ? sanitize_text_field($_POST['perspective_states']) : null; $is_default = !empty($_POST['perspective_default']) ? 1 : 0; $target_project_id = $is_default ? null : $project_id; // Only allow user to add non-fixed perspectives if ($type === 'fixed') { echo '

Cannot add new fixed perspectives.

'; } else { $result = $wpdb->insert($perspectives_table, [ 'project_id' => $target_project_id, 'name' => $name, 'type' => $type, 'states' => $states, 'default' => $is_default, 'created_at' => current_time('mysql'), ]); if ($result === false) { echo '

Failed to add perspective: ' . esc_html($wpdb->last_error) . '

'; } else { echo '

Perspective added.

'; } } }