db = RT_WA_Analytics_DB::instance(); $this->settings = RT_WA_Analytics_Settings::instance(); } public function render_settings_content() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'zaaed-click2chat' ) ); } $settings = $this->settings; $active_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( isset( $_POST['save_settings'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $this->settings->save_settings(); } if ( isset( $_POST['generate_api_key'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $this->settings->generate_api_key(); } if ( isset( $_POST['revoke_api_key'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $key_id = isset( $_POST['key_id'] ) ? absint( wp_unslash( $_POST['key_id'] ) ) : 0; $this->settings->revoke_api_key( $key_id ); } if ( isset( $_POST['delete_api_key'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $raw = isset( $_POST['delete_key_id'] ) ? sanitize_text_field( wp_unslash( $_POST['delete_key_id'] ) ) : ''; $ids = array_filter( array_map( 'intval', explode( ',', $raw ) ) ); foreach ( $ids as $id ) { $this->settings->delete_api_key( $id ); } } if ( isset( $_POST['delete_revoked_api_keys'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $this->settings->delete_revoked_api_keys(); } if ( isset( $_POST['reset_plugin'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $this->settings->reset_plugin(); } if ( isset( $_POST['cleanup_database'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $this->settings->cleanup_database(); } if ( isset( $_POST['generate_demo_data'] ) && wp_verify_nonce( $nonce, 'rt_wa_settings' ) ) { $demo = new RT_WA_Analytics_Demo(); $count = $demo->generate(); if ( $count > 0 ) { // translators: 1: number of visitors generated, 2: number of leads generated. add_settings_error( 'rt_wa_messages', 'demo_data', sprintf( __( 'Demo data generated: %1$d visitors with sessions, events, and page views; %2$d leads.', 'zaaed-click2chat' ), $count, $demo->leads_generated ), 'success' ); } else { add_settings_error( 'rt_wa_messages', 'demo_data', __( 'Failed to generate demo data.', 'zaaed-click2chat' ), 'error' ); } } $api_keys = $this->db->get_api_keys(); $total_visitors = $this->db->get_total_visitors(); $total_sessions = $this->db->get_total_sessions(); $total_events = $this->db->get_total_events(); include RT_WA_ANALYTICS_PATH . 'modules/settings/views/settings.php'; } }