Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions includes/tab-ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public function content(){
}

public function process_post() {
// Process Chat Model Form
// Verify nonces
$ai_chat_nonce_verified = isset( $_POST['ai_chat_nonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ai_chat_nonce'] ) ), 'ai_chat' );

$ai_transcript_nonce_verified = isset( $_POST['ai_transcript_nonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ai_transcript_nonce'] ) ), 'ai_transcript' );

if ( !$ai_chat_nonce_verified && !$ai_transcript_nonce_verified ) {
$ai_features_nonce_verified = isset( $_POST['ai_features_nonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ai_features_nonce'] ) ), 'ai_features' );

if ( !$ai_chat_nonce_verified && !$ai_transcript_nonce_verified && !$ai_features_nonce_verified ) {
return [
'is_update' => false,
'updated' => false
Expand Down Expand Up @@ -97,6 +100,28 @@ public function process_post() {
];
}

// Process Enabled Features Form
if ( $ai_features_nonce_verified ) {
$post_vars = dt_recursive_sanitize_array( $_POST );

// Get all modules
$modules = Disciple_Tools_AI_API::list_modules();

// Build network module states array
$network_module_states = [];
foreach ( $modules as $module ) {
$network_module_states[ $module['id'] ] = isset( $post_vars[ $module['id'] ] ) ? 1 : 0;
}

// Save network-level module states
update_site_option( 'DT_AI_network_modules', $network_module_states );

return [
'is_update' => true,
'updated' => true
];
}

return false;
}

Expand Down Expand Up @@ -303,6 +328,55 @@ public function list_keys( $processed ){
</table>
</form>
<br>

<!-- Enabled Features Form -->
<form method="post" id="features-form">
<?php wp_nonce_field( 'ai_features', 'ai_features_nonce' ) ?>
<table class="widefat striped">
<thead>
<tr>
<th colspan="2"><span style="font-weight: bold;">Network Default Enabled Features</span></th>
</tr>
</thead>
<tbody>
<?php
$modules = Disciple_Tools_AI_API::list_modules();

// Get network-level module states
$network_module_states = get_site_option( 'DT_AI_network_modules', [] );

foreach ( $modules as $module ) {
if ( isset( $module['visible'] ) && $module['visible'] ) {
// Check network state, default to the module's default enabled state if not set
$network_enabled = isset( $network_module_states[ $module['id'] ] )
? $network_module_states[ $module['id'] ]
: ( isset( $module['enabled'] ) ? $module['enabled'] : 0 );
?>
<tr>
<td>
<?php echo esc_attr( $module['name'] ) ?>
<br>
<small><?php echo esc_attr( $module['description'] ) ?></small>
</td>
<td>
<input type="checkbox" name="<?php echo esc_attr( $module['id'] ) ?>" <?php echo ( $network_enabled ? 'checked' : '' ) ?>>
</td>
</tr>
<?php
}
}
?>
<tr>
<td colspan="2">
<span style="float:right;">
<button class="button btn" type="submit">Save Enabled Features</button>
</span>
</td>
</tr>
</tbody>
</table>
</form>
<br>
<script>
jQuery(document).ready(function() {
const aiProviders = [<?php echo json_encode( $ai_providers ) ?>][0];
Expand Down