tab.php
75 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 ) ) { |
| 12 | return $tabs; |
| 13 | } |
| 14 | |
| 15 | $skip_ai_tab = apply_filters( 'kubio/admin-page/skip_ai_tab_in_stage_2', true ); |
| 16 | if ( ( Flags::getSetting( 'aiStage2' ) && $skip_ai_tab ) ) { |
| 17 | return $tabs; |
| 18 | } |
| 19 | |
| 20 | $tabs = array_merge( |
| 21 | $tabs, |
| 22 | array( |
| 23 | 'ai-info' => array( |
| 24 | 'type' => 'page', |
| 25 | 'label' => __( 'Kubio AI', 'kubio' ), |
| 26 | 'tab-partial' => __DIR__ . '/partials/main.php', |
| 27 | 'subtitle' => __( 'Build smarter & faster with Kubio AI', 'kubio' ), |
| 28 | ), |
| 29 | ) |
| 30 | ); |
| 31 | |
| 32 | if ( defined( 'KUBIO_AI_LOG' ) && KUBIO_AI_LOG ) { |
| 33 | $tabs = array_merge( |
| 34 | $tabs, |
| 35 | array( |
| 36 | 'ai-logs' => array( |
| 37 | 'type' => 'page', |
| 38 | 'label' => 'Kubio AI Logs', |
| 39 | 'tab-partial' => __DIR__ . '/partials/log.php', |
| 40 | 'subtitle' => 'Kubio AI internal logs' . '<br/>' . sprintf( 'Cloud URL: %s', preg_replace( '#\?(.*)#', '', Utils::getCloudURL() ) ), |
| 41 | ), |
| 42 | ) |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return $tabs; |
| 47 | } |
| 48 | ); |
| 49 | |
| 50 | add_action( |
| 51 | 'wp_ajax_kubio_clear_ai_logs', |
| 52 | function () { |
| 53 | // phpcs:ignore WordPress.Security.NonceVerification |
| 54 | $nonce = Arr::get( $_REQUEST, '_wpnonce', '' ); |
| 55 | if ( ! wp_verify_nonce( $nonce, 'kubio_clear_ai_logs' ) ) { |
| 56 | wp_die( |
| 57 | esc_html__( 'Unauthorized', 'kubio' ), |
| 58 | esc_html__( 'Unauthorized', 'kubio' ), |
| 59 | array( |
| 60 | 'response' => 401, |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | $logs_file = FileLog::get_log_files( 'AI' ); |
| 66 | |
| 67 | foreach ( $logs_file as $file ) { |
| 68 | wp_delete_file( $file ); |
| 69 | } |
| 70 | |
| 71 | wp_redirect( wp_get_referer() ); |
| 72 | exit(); |
| 73 | } |
| 74 | ); |
| 75 |