--- a/woo-rede/Includes/LknIntegrationRedeForWoocommerce.php
+++ b/woo-rede/Includes/LknIntegrationRedeForWoocommerce.php
@@ -184,6 +184,9 @@
$this->loader->add_filter('plugin_action_links_' . INTEGRATION_REDE_FOR_WOOCOMMERCE_FILE_BASENAME, $this, 'lknIntegrationRedeForWoocommercePluginRowMeta', 10, 2);
$this->loader->add_filter('plugin_action_links_' . INTEGRATION_REDE_FOR_WOOCOMMERCE_FILE_BASENAME, $this, 'lknIntegrationRedeForWoocommercePluginRowMetaPro', 10, 2);
+ // Adicionar link do Changelog
+ $this->loader->add_filter('plugin_row_meta', $this, 'add_changelog_link', 10, 2);
+
$this->loader->add_action('rest_api_init', $this->LknIntegrationRedeForWoocommerceEndpointClass, 'registerorderRedeCaptureEndPoint');
$this->loader->add_filter('woocommerce_gateway_title', $this, 'customize_wc_payment_gateway_pix_name', 10, 2);
@@ -1493,4 +1496,23 @@
'message' => __('Card brand not found', 'woo-rede'),
];
}
+
+ /**
+ * Adiciona link do Changelog na página de plugins
+ */
+ public function add_changelog_link($plugin_meta, $plugin_file)
+ {
+ // Verificar se é o nosso plugin
+ if (strpos($plugin_file, 'integration-rede-for-woocommerce.php') !== false) {
+ $changelog_link = sprintf(
+ '<a href="%1$s" target="_blank">%2$s</a>',
+ 'https://br.wordpress.org/plugins/woo-rede/#developers',
+ __('Changelog', 'woo-rede')
+ );
+
+ $plugin_meta[] = $changelog_link;
+ }
+
+ return $plugin_meta;
+ }
}
--- a/woo-rede/Includes/LknIntegrationRedeForWoocommerceWcEndpoint.php
+++ b/woo-rede/Includes/LknIntegrationRedeForWoocommerceWcEndpoint.php
@@ -39,7 +39,7 @@
register_rest_route('redeIntegration', '/clearOrderLogs', array(
'methods' => 'DELETE',
'callback' => array($this, 'clearOrderLogs'),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => array($this, 'check_clear_logs_permissions'),
));
register_rest_route('woorede', '/s', array(
@@ -55,22 +55,87 @@
));
}
+ /**
+ * Verifica se o usuário tem permissão para limpar logs de pedidos
+ *
+ * @return bool True se autorizado, false caso contrário
+ */
+ public function check_clear_logs_permissions()
+ {
+ // Verifica se o usuário está logado e tem permissão para gerenciar WooCommerce
+ return current_user_can('manage_woocommerce') || current_user_can('manage_options');
+ }
+
public function clearOrderLogs($request)
{
- $args = array(
- 'limit' => -1, // Sem limite, pega todas as ordens
- 'meta_key' => 'lknWcRedeOrderLogs', // Meta key específica
- 'meta_compare' => 'EXISTS', // Verifica se a meta key existe
- );
-
- $orders = wc_get_orders($args);
-
- foreach ($orders as $order) {
- $order->delete_meta_data('lknWcRedeOrderLogs');
- $order->save();
+ // Verificação adicional de segurança
+ if (!current_user_can('manage_woocommerce') && !current_user_can('manage_options')) {
+ return new WP_Error(
+ 'insufficient_permissions',
+ __('You do not have permission to clear order logs.', 'woo-rede'),
+ array('status' => 403)
+ );
+ }
+
+ // Log da ação para auditoria
+ if (function_exists('wc_get_logger')) {
+ $logger = wc_get_logger();
+ $current_user = wp_get_current_user();
+ $logger->info('Order logs cleared by user', array(
+ 'source' => 'rede-security-audit',
+ 'user_id' => $current_user->ID,
+ 'user_login' => $current_user->user_login,
+ 'user_ip' => isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : 'unknown',
+ 'timestamp' => current_time('mysql')
+ ));
}
- return new WP_REST_Response($orders, 200);
+ $deleted_count = 0;
+ $batch_size = 50; // Processa 50 pedidos por vez para evitar esgotamento de memória
+ $offset = 0;
+
+ do {
+ $args = array(
+ 'limit' => $batch_size,
+ 'offset' => $offset,
+ 'meta_key' => 'lknWcRedeOrderLogs',
+ 'meta_compare' => 'EXISTS',
+ 'return' => 'ids', // Retorna apenas IDs para economizar memória
+ );
+
+ $order_ids = wc_get_orders($args);
+
+ if (empty($order_ids)) {
+ break; // Não há mais pedidos para processar
+ }
+
+ foreach ($order_ids as $order_id) {
+ $order = wc_get_order($order_id);
+ if ($order) {
+ $order->delete_meta_data('lknWcRedeOrderLogs');
+ $order->save();
+ $deleted_count++;
+ }
+
+ // Libera memória do objeto order
+ unset($order);
+ }
+
+ $offset += $batch_size;
+
+ // Força limpeza de memória entre lotes
+ if (function_exists('gc_collect_cycles')) {
+ gc_collect_cycles();
+ }
+
+ } while (count($order_ids) === $batch_size);
+
+ return new WP_REST_Response(array(
+ 'success' => true,
+ /* translators: %d: number of orders from which logs were cleared */
+ 'message' => sprintf(__('Logs cleared from %d orders.', 'woo-rede'), $deleted_count),
+ 'orders_affected' => $deleted_count
+ ), 200);
}
public function maxipagoDebitListener($request)
--- a/woo-rede/integration-rede-for-woocommerce.php
+++ b/woo-rede/integration-rede-for-woocommerce.php
@@ -15,7 +15,7 @@
* @wordpress-plugin
* Plugin Name: Integration Rede Itaú for WooCommerce — Payment PIX, Credit Card and Debit
* Description: Receba pagamentos por meio de cartões de crédito e débito, de diferentes bandeiras, usando a tecnologia de autenticação 3DS e recursos avançados de proteção contra fraudes.
- * Version: 5.1.5
+ * Version: 5.1.6
* Author: Link Nacional
* Author URI: https://linknacional.com.br/wordpress
* License: GPL-3.0+
--- a/woo-rede/lkn-integration-rede-for-woocommerce-file.php
+++ b/woo-rede/lkn-integration-rede-for-woocommerce-file.php
@@ -17,7 +17,7 @@
* Rename this for your plugin and update it as you release new versions.
*/
if (! defined('INTEGRATION_REDE_FOR_WOOCOMMERCE_VERSION')) {
- define('INTEGRATION_REDE_FOR_WOOCOMMERCE_VERSION', '5.1.5');
+ define('INTEGRATION_REDE_FOR_WOOCOMMERCE_VERSION', '5.1.6');
}
if (! defined('INTEGRATION_REDE_FOR_WOOCOMMERCE_FILE')) {