$message, 'context' => $context, 'time' => self::now_utc_plus_one() ], false ); } if ( class_exists( '\WC_Logger' ) ) { $logger = wc_get_logger(); $logger->error($message, array_merge(['source' => 'minicrm-integration'], $context)); return; } $context_str = ''; if ( ! empty($context) ) { $context_str = ' | ' . wp_json_encode($context); } error_log('[minicrm-integration] ' . $message . $context_str); } /** * Current time in UTC+1 (Y-m-d H:i:s) using wp_date(). */ private static function now_utc_plus_one() { return wp_date( 'Y-m-d H:i:s', time() + HOUR_IN_SECONDS, new DateTimeZone( 'UTC' ) ); } /** * Show latest MiniCRM sync error in the admin UI so someone can act on it. */ public static function render_admin_notice() { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $error = get_option( 'minicrm_integration_last_error' ); if ( ! $error || empty( $error['message'] ) ) { return; } $message = esc_html( $error['message'] ); $time = ! empty( $error['time'] ) ? esc_html( $error['time'] ) : ''; $context = ''; if ( ! empty( $error['context'] ) ) { $context = '
' . esc_html( wp_json_encode( $error['context'], JSON_PARTIAL_OUTPUT_ON_ERROR ) ) . '
'; } $dismiss_url = wp_nonce_url( add_query_arg( 'minicrm_clear_error', '1' ), 'minicrm_clear_error', 'minicrm_nonce' ); printf( '

MiniCRM integráció hiba: %s%s%s

Megjegyezve, elrejtés

', $message, $time ? ' (' . $time . ')' : '', $context, esc_url( $dismiss_url ) ); } /** * Clear error notice when user dismisses via link. */ public static function handle_admin_notice_dismiss() { if ( ! isset( $_GET['minicrm_clear_error'], $_GET['minicrm_nonce'] ) ) { return; } if ( ! wp_verify_nonce( $_GET['minicrm_nonce'], 'minicrm_clear_error' ) ) { return; } delete_option( 'minicrm_integration_last_error' ); wp_safe_redirect( remove_query_arg( [ 'minicrm_clear_error', 'minicrm_nonce' ] ) ); exit; } }