tab.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | use IlluminateAgnostic\Arr\Support\Arr; |
| 4 | use Kubio\Core\Utils; |
| 5 | use Kubio\FileLog; |
| 6 | use Kubio\Flags; |
| 7 | |
| 8 | add_filter( |
| 9 | 'kubio/admin-page/info_page_tabs', |
| 10 | function( $tabs ) { |
| 11 | if ( ! Flags::getSetting( 'enableAICapabilities', false ) || ( Flags::getSetting( 'aiStage2' ) && kubio_is_free() ) ) { |
| 12 | return $tabs; |
| 13 | } |
| 14 | |
| 15 | $tabs = array_merge( |
| 16 | $tabs, |
| 17 | array( |
| 18 | 'ai-info' => array( |
| 19 | 'type' => 'page', |
| 20 | 'label' => __( 'Kubio AI', 'kubio' ), |
| 21 | 'tab-partial' => __DIR__ . '/partials/main.php', |
| 22 | 'subtitle' => __( 'Build smarter & faster with Kubio AI', 'kubio' ), |
| 23 | ), |
| 24 | ) |
| 25 | ); |
| 26 | |
| 27 | if ( defined( 'KUBIO_AI_LOG' ) && KUBIO_AI_LOG ) { |
| 28 | $tabs = array_merge( |
| 29 | $tabs, |
| 30 | array( |
| 31 | 'ai-logs' => array( |
| 32 | 'type' => 'page', |
| 33 | 'label' => 'Kubio AI Logs', |
| 34 | 'tab-partial' => __DIR__ . '/partials/log.php', |
| 35 | 'subtitle' => 'Kubio AI internal logs' . '<br/>' . sprintf( 'Cloud URL: %s', preg_replace( '#\?(.*)#', '', Utils::getCloudURL() ) ), |
| 36 | ), |
| 37 | ) |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | return $tabs; |
| 42 | } |
| 43 | ); |
| 44 | |
| 45 | add_action( |
| 46 | 'wp_ajax_kubio_clear_ai_logs', |
| 47 | function() { |
| 48 | |
| 49 | $nonce = Arr::get( $_REQUEST, '_wpnonce', '' ); |
| 50 | if ( ! wp_verify_nonce( $nonce, 'kubio_clear_ai_logs' ) ) { |
| 51 | wp_die( |
| 52 | __( 'Unauthorized', 'kubio' ), |
| 53 | __( 'Unauthorized', 'kubio' ), |
| 54 | array( |
| 55 | 'response' => 401, |
| 56 | ) |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | $logs_file = FileLog::get_log_files( 'AI' ); |
| 61 | |
| 62 | foreach ( $logs_file as $file ) { |
| 63 | unlink( $file ); |
| 64 | } |
| 65 | |
| 66 | wp_redirect( wp_get_referer() ); |
| 67 | exit(); |
| 68 | } |
| 69 | ); |
| 70 |