parent
79aea38c69
commit
1206bb8fd3
@ -1,40 +1,185 @@ |
||||
<?php |
||||
|
||||
add_filter('woocommerce_currency_symbol', 'change_aed_currency_symbol', 10, 2); |
||||
|
||||
function change_aed_currency_symbol($currency_symbol, $currency) { |
||||
if ($currency == 'AED') { |
||||
$currency_symbol = 'AED'; |
||||
} |
||||
return $currency_symbol; |
||||
} |
||||
|
||||
add_filter('timber/context', function($context) { |
||||
// Передаем все нужные константы в контекст Twig |
||||
$context['CONSTANTS'] = [ |
||||
'DOMAIN' => defined('SITE_DOMAIN') ? SITE_DOMAIN : null, |
||||
]; |
||||
|
||||
return $context; |
||||
}); |
||||
|
||||
|
||||
// Отключаем канонические ссылки и hreflang от Yoast SEO |
||||
add_filter('wpseo_canonical', '__return_false'); |
||||
add_filter('wpseo_opengraph_url', '__return_false'); // Отключаем OG URL |
||||
add_filter('wpseo_add_x_default_hreflang', '__return_false'); // Отключаем hreflang от Yoast |
||||
add_filter('wpseo_disable_adjacent_rel_links', '__return_true'); // Отключаем соседние rel-ссылки |
||||
|
||||
// Добавляем каноническую ссылку |
||||
add_action('wp_head', 'custom_canonical_url', 5); |
||||
function custom_canonical_url() { |
||||
// Защищаем от дублирования |
||||
static $canonical_added = false; |
||||
if ($canonical_added) { |
||||
return; |
||||
} |
||||
$canonical_added = true; |
||||
|
||||
$current_url = home_url(add_query_arg('', $_SERVER['REQUEST_URI'])); |
||||
echo '<link rel="canonical" href="' . esc_url($current_url) . '" />' . "\n"; |
||||
<?php |
||||
|
||||
add_filter('woocommerce_currency_symbol', 'change_aed_currency_symbol', 10, 2); |
||||
|
||||
function change_aed_currency_symbol($currency_symbol, $currency) { |
||||
if ($currency == 'AED') { |
||||
$currency_symbol = 'AED'; |
||||
} |
||||
return $currency_symbol; |
||||
} |
||||
|
||||
add_filter('timber/context', function($context) { |
||||
// Передаем все нужные константы в контекст Twig |
||||
$context['CONSTANTS'] = [ |
||||
'DOMAIN' => defined('SITE_DOMAIN') ? SITE_DOMAIN : null, |
||||
]; |
||||
|
||||
return $context; |
||||
}); |
||||
|
||||
|
||||
// Отключаем канонические ссылки и hreflang от Yoast SEO |
||||
add_filter('wpseo_canonical', '__return_false'); |
||||
add_filter('wpseo_opengraph_url', '__return_false'); // Отключаем OG URL |
||||
add_filter('wpseo_add_x_default_hreflang', '__return_false'); // Отключаем hreflang от Yoast |
||||
add_filter('wpseo_disable_adjacent_rel_links', '__return_true'); // Отключаем соседние rel-ссылки |
||||
|
||||
// Добавляем каноническую ссылку |
||||
add_action('wp_head', 'custom_canonical_url', 5); |
||||
function custom_canonical_url() { |
||||
if (!is_admin()) { |
||||
// Защищаем от дублирования |
||||
static $canonical_added = false; |
||||
if ($canonical_added) { |
||||
return; |
||||
} |
||||
$canonical_added = true; |
||||
|
||||
// Формируем текущий URL без лишних параметров |
||||
$current_url = trailingslashit(home_url($_SERVER['REQUEST_URI'])); |
||||
// Удаляем возможные параметры запроса, если они не нужны |
||||
$current_url = strtok($current_url, '?'); |
||||
echo '<link rel="canonical" href="' . esc_url($current_url) . '" />' . "\n"; |
||||
} |
||||
} |
||||
|
||||
add_action('wp_head', 'add_facebook_pixel'); |
||||
function add_facebook_pixel() { |
||||
?> |
||||
<!-- Meta Pixel Code --> |
||||
<script> |
||||
!function(f,b,e,v,n,t,s) |
||||
{if(f.fbq)return;n=f.fbq=function(){n.callMethod? |
||||
n.callMethod.apply(n,arguments):n.queue.push(arguments)}; |
||||
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; |
||||
n.queue=[];t=b.createElement(e);t.async=!0; |
||||
t.src=v;s=b.getElementsByTagName(e)[0]; |
||||
s.parentNode.insertBefore(t,s)}(window, document,'script', |
||||
'https://connect.facebook.net/en_US/fbevents.js'); |
||||
fbq('init', '1791804684725971'); |
||||
fbq('track', 'PageView'); |
||||
</script> |
||||
<noscript> |
||||
<img height="1" width="1" style="display:none" |
||||
src="https://www.facebook.com/tr?id=1791804684725971&ev=PageView&noscript=1"/> |
||||
</noscript> |
||||
<!-- End Meta Pixel Code --> |
||||
<?php |
||||
} |
||||
|
||||
add_action('woocommerce_thankyou', 'send_purchase_to_metrika'); |
||||
function send_purchase_to_metrika($order_id) { |
||||
if (!$order_id) return; // Проверка, что заказ существует |
||||
|
||||
$order = wc_get_order($order_id); |
||||
if ($order->get_status() !== 'processing' && $order->get_status() !== 'completed') return; // Отправляем только для оплаченных заказов |
||||
|
||||
$items = []; |
||||
foreach ($order->get_items() as $item) { |
||||
$product = $item->get_product(); |
||||
$items[] = [ |
||||
'id' => $product->get_id(), |
||||
'name' => $product->get_name(), |
||||
'price' => $product->get_price(), |
||||
'quantity' => $item->get_quantity() |
||||
]; |
||||
} |
||||
|
||||
// Получаем валюту заказа |
||||
$currency = $order->get_currency(); |
||||
?> |
||||
<script> |
||||
window.dataLayer = window.dataLayer || []; |
||||
dataLayer.push({ |
||||
'ecommerce': { |
||||
'purchase': { |
||||
'actionField': { |
||||
'id': '<?php echo $order_id; ?>',
|
||||
'revenue': '<?php echo $order->get_total(); ?>',
|
||||
'currency': '<?php echo $currency; ?>'
|
||||
}, |
||||
'products': <?php echo json_encode($items); ?> |
||||
} |
||||
} |
||||
}); |
||||
|
||||
// Яндекс.Метрика |
||||
yaCounter96481053.reachGoal('purchase', { |
||||
'order_id': '<?php echo $order_id; ?>',
|
||||
'order_price': '<?php echo $order->get_total(); ?>',
|
||||
'currency': '<?php echo $currency; ?>',
|
||||
'items': <?php echo json_encode($items); ?> |
||||
}); |
||||
|
||||
// Facebook Pixel |
||||
fbq('track', 'Purchase', { |
||||
value: <?php echo $order->get_total(); ?>,
|
||||
currency: '<?php echo $currency; ?>',
|
||||
content_ids: [<?php echo implode(',', array_column($items, 'id')); ?>],
|
||||
content_type: 'product' |
||||
}); |
||||
</script> |
||||
<?php |
||||
} |
||||
|
||||
// Отключаем кэширование для страниц товаров |
||||
add_action('template_redirect', function() { |
||||
if (is_product()) { |
||||
header('Cache-Control: no-cache, no-store, must-revalidate'); |
||||
header('Pragma: no-cache'); |
||||
header('Expires: 0'); |
||||
} |
||||
}); |
||||
|
||||
// Обработчик AJAX |
||||
add_action('wp_ajax_woocommerce_ajax_add_to_cart', 'woocommerce_ajax_add_to_cart'); |
||||
add_action('wp_ajax_nopriv_woocommerce_ajax_add_to_cart', 'woocommerce_ajax_add_to_cart'); |
||||
|
||||
function woocommerce_ajax_add_to_cart() { |
||||
error_log('AJAX handler called'); // Отладка: логируем вызов |
||||
|
||||
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0; |
||||
$quantity = isset($_POST['quantity']) ? absint($_POST['quantity']) : 1; |
||||
|
||||
error_log('Received product_id: ' . $product_id . ', quantity: ' . $quantity); // Отладка |
||||
|
||||
if (!$product_id) { |
||||
error_log('Invalid product_id received'); // Отладка |
||||
wp_send_json_error(array('message' => 'Неверный ID товара')); |
||||
wp_die(); |
||||
} |
||||
|
||||
$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity); |
||||
|
||||
if ($passed_validation) { |
||||
$added = WC()->cart->add_to_cart($product_id, $quantity); |
||||
if ($added) { |
||||
error_log('Product added to cart: ' . $product_id); // Отладка |
||||
// Подготавливаем фрагменты корзины |
||||
ob_start(); |
||||
woocommerce_mini_cart(); |
||||
$mini_cart = ob_get_clean(); |
||||
|
||||
// Фрагменты для стандартной корзины и кастомного счетчика |
||||
$fragments = array( |
||||
'div.widget_shopping_cart_content' => '<div class="widget_shopping_cart_content">' . $mini_cart . '</div>', |
||||
'.mini-profile__button--counter' => '<div class="mini-profile__button--counter">' . WC()->cart->get_cart_contents_count() . '</div>' |
||||
); |
||||
|
||||
wp_send_json_success(array( |
||||
'message' => 'Товар успешно добавлен в корзину', |
||||
'fragments' => apply_filters('woocommerce_add_to_cart_fragments', $fragments), |
||||
'cart_hash' => apply_filters('woocommerce_add_to_cart_hash', WC()->cart->get_cart_hash(), array()) |
||||
)); |
||||
} else { |
||||
error_log('Failed to add product to cart: ' . $product_id); // Отладка |
||||
wp_send_json_error(array('message' => 'Не удалось добавить товар в корзину')); |
||||
} |
||||
} else { |
||||
error_log('Validation failed for product: ' . $product_id); // Отладка |
||||
wp_send_json_error(array('message' => 'Ошибка валидации товара')); |
||||
} |
||||
|
||||
wp_die(); |
||||
} |
@ -1,189 +1,188 @@ |
||||
<<<<<<< Updated upstream |
||||
<?php |
||||
|
||||
|
||||
add_filter('timber/context', function($context) { |
||||
$context['email_list'] = get_field('email_list', 'options'); |
||||
$context['adres'] = get_field('adres', 'options'); |
||||
$context['social'] = get_field('social', 'options'); |
||||
$context['links'] = get_field('links', 'options'); |
||||
return $context; |
||||
}); |
||||
|
||||
define('BOT_USERNAME', 'cosmopet_test_AE_bot'); |
||||
|
||||
|
||||
function getTelegramUserData() { |
||||
if (isset($_COOKIE['tg_user'])) { |
||||
$auth_data_json = urldecode($_COOKIE['tg_user']); |
||||
$auth_data = json_decode($auth_data_json, true); |
||||
return $auth_data; |
||||
} |
||||
return false; |
||||
} |
||||
/* |
||||
if ($_GET['logout']) { |
||||
setcookie('tg_user', ''); |
||||
header('Location: login.php'); |
||||
} |
||||
*/ |
||||
function tgWidget() { |
||||
$tg_user = getTelegramUserData(); |
||||
if ($tg_user !== false) { |
||||
$first_name = htmlspecialchars($tg_user['first_name']); |
||||
$last_name = htmlspecialchars($tg_user['last_name']); |
||||
if (isset($tg_user['username'])) { |
||||
$username = htmlspecialchars($tg_user['username']); |
||||
$html = "<h1>Hello, <a href=\"https://t.me/{$username}\">{$first_name} {$last_name}</a>!</h1>"; |
||||
} else { |
||||
$html = "<h1>Hello, {$first_name} {$last_name}!</h1>"; |
||||
} |
||||
if (isset($tg_user['photo_url'])) { |
||||
$photo_url = htmlspecialchars($tg_user['photo_url']); |
||||
$html .= "<img src=\"{$photo_url}\">"; |
||||
} |
||||
$html .= "<p><a href=\"?logout=1\">Log out</a></p>"; |
||||
} else { |
||||
$bot_username = BOT_USERNAME; |
||||
$html = '<script async src="https://telegram.org/js/telegram-widget.js?2" data-telegram-login="'.$bot_username.'" data-size="large" data-onauth="onTelegramAuth(user)"></script>'; |
||||
} |
||||
if(!is_user_logged_in()) { |
||||
echo $html; |
||||
} |
||||
} |
||||
|
||||
add_action( 'wp_ajax_ontelegramauth', 'onTelegramAuth' ); |
||||
add_action( 'wp_ajax_nopriv_ontelegramauth', 'onTelegramAuth' ); |
||||
|
||||
function onTelegramAuth(){ |
||||
$tg_id = $_POST['userid']; |
||||
$tg_username = $_POST['username']; |
||||
$user = get_users( |
||||
array( |
||||
'meta_key' => 'tg_account', |
||||
'meta_value' => $tg_id |
||||
) |
||||
); |
||||
// $user = get_users( |
||||
// array( |
||||
// 'meta_key' => 'tg_username', |
||||
// 'meta_value' => $tg_username |
||||
// ) |
||||
// ); |
||||
|
||||
// Генерация пароля |
||||
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#!()'; |
||||
$pass = array(); |
||||
$alphaLength = strlen($alphabet) - 1; |
||||
for ($i = 0; $i < 12; $i++) { |
||||
$n = rand(0, $alphaLength); |
||||
$pass[] = $alphabet[$n]; |
||||
} |
||||
$pass = implode($pass); |
||||
|
||||
if($user) { |
||||
$user_login = $user[0]->data->user_login; |
||||
$user_id = get_user_by( 'login', $user_login )->ID; |
||||
wp_set_password( $pass, get_user_by( 'login', $user_login )->ID ); |
||||
wp_signon( |
||||
array( |
||||
'user_login' => $user_login, |
||||
'user_password' => $pass, |
||||
'remember' => 'on', |
||||
) |
||||
); |
||||
} else { |
||||
$user_id = wp_create_user( $tg_username, $pass, ''); |
||||
add_user_meta( $user_id, 'tg_account', $tg_id); |
||||
add_user_meta( $user_id, 'tg_username', $tg_username); |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'first_name' => $_POST['fname'], |
||||
'last_name' => $_POST['lname'] |
||||
] ); |
||||
wp_set_auth_cookie( $user_id, true ); |
||||
} |
||||
|
||||
} |
||||
|
||||
add_action( 'wp_ajax_linktelegram', 'linkTelegram' ); |
||||
add_action( 'wp_ajax_nopriv_linktelegram', 'linkTelegram' ); |
||||
|
||||
function linkTelegram(){ |
||||
$tg_id = $_POST['userid']; |
||||
$user_id = get_current_user_id(); |
||||
|
||||
add_user_meta( $user_id, 'tg_account', $tg_id); |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'first_name' => $_POST['fname'], |
||||
'last_name' => $_POST['lname'] |
||||
] ); |
||||
} |
||||
|
||||
add_action( 'wp_ajax_email_link', 'emailLink' ); |
||||
add_action( 'wp_ajax_nopriv_email_link', 'emailLink' ); |
||||
function emailLink(){ |
||||
|
||||
$email = $_POST['email']; |
||||
$user_id = get_current_user_id(); |
||||
|
||||
if(email_exists($email)){ |
||||
header("Content-Type: application/json"); |
||||
echo json_encode(array( |
||||
'error' => esc_html__( 'Email is already registered', 'woodmart' ) |
||||
)); |
||||
exit(); |
||||
} else { |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'user_email' => $email |
||||
] ); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
// Добавляем колонку Telegram в список пользователей |
||||
add_filter('manage_users_columns', 'add_tg_account_column'); |
||||
function add_tg_account_column($columns) { |
||||
$columns['tg_username'] = 'Telegram'; |
||||
return $columns; |
||||
} |
||||
|
||||
// Заполняем колонку данными |
||||
add_filter('manage_users_custom_column', 'add_tg_account_column_content', 10, 3); |
||||
function add_tg_account_column_content($value, $column_name, $user_id) { |
||||
if ('tg_username' == $column_name) { |
||||
$tg_account = get_user_meta($user_id, 'tg_username', true); |
||||
if ($tg_account) { |
||||
return '<a href="https://t.me/"' . esc_attr($tg_account) . '" target="_blank">@' . esc_html($tg_account) . '</a>'; |
||||
} |
||||
return '<span style="color:#ccc;">не указан</span>'; |
||||
} |
||||
return $value; |
||||
} |
||||
|
||||
// Делаем колонку сортируемой |
||||
add_filter('manage_users_sortable_columns', 'make_tg_account_column_sortable'); |
||||
function make_tg_account_column_sortable($columns) { |
||||
$columns['tg_username'] = 'tg_username'; |
||||
return $columns; |
||||
} |
||||
|
||||
// Обрабатываем сортировку |
||||
add_action('pre_get_users', 'handle_tg_account_sorting'); |
||||
function handle_tg_account_sorting($query) { |
||||
if (!is_admin() || !$query->is_main_query()) { |
||||
return; |
||||
} |
||||
|
||||
if ('tg_username' === $query->get('orderby')) { |
||||
$query->set('meta_key', 'tg_username'); |
||||
$query->set('orderby', 'meta_value'); |
||||
} |
||||
} |
||||
|
||||
<?php |
||||
|
||||
|
||||
add_filter('timber/context', function($context) { |
||||
$context['email_list'] = get_field('email_list', 'options'); |
||||
$context['adres'] = get_field('adres', 'options'); |
||||
$context['social'] = get_field('social', 'options'); |
||||
$context['links'] = get_field('links', 'options'); |
||||
return $context; |
||||
}); |
||||
|
||||
define('BOT_USERNAME', 'cosmopet_test_AE_bot'); |
||||
|
||||
|
||||
function getTelegramUserData() { |
||||
if (isset($_COOKIE['tg_user'])) { |
||||
$auth_data_json = urldecode($_COOKIE['tg_user']); |
||||
$auth_data = json_decode($auth_data_json, true); |
||||
return $auth_data; |
||||
} |
||||
return false; |
||||
} |
||||
/* |
||||
if ($_GET['logout']) { |
||||
setcookie('tg_user', ''); |
||||
header('Location: login.php'); |
||||
} |
||||
*/ |
||||
function tgWidget() { |
||||
$tg_user = getTelegramUserData(); |
||||
if ($tg_user !== false) { |
||||
$first_name = htmlspecialchars($tg_user['first_name']); |
||||
$last_name = htmlspecialchars($tg_user['last_name']); |
||||
if (isset($tg_user['username'])) { |
||||
$username = htmlspecialchars($tg_user['username']); |
||||
$html = "<h1>Hello, <a href=\"https://t.me/{$username}\">{$first_name} {$last_name}</a>!</h1>"; |
||||
} else { |
||||
$html = "<h1>Hello, {$first_name} {$last_name}!</h1>"; |
||||
} |
||||
if (isset($tg_user['photo_url'])) { |
||||
$photo_url = htmlspecialchars($tg_user['photo_url']); |
||||
$html .= "<img src=\"{$photo_url}\">"; |
||||
} |
||||
$html .= "<p><a href=\"?logout=1\">Log out</a></p>"; |
||||
} else { |
||||
$bot_username = BOT_USERNAME; |
||||
$html = '<script async src="https://telegram.org/js/telegram-widget.js?2" data-telegram-login="'.$bot_username.'" data-size="large" data-onauth="onTelegramAuth(user)"></script>'; |
||||
} |
||||
if(!is_user_logged_in()) { |
||||
echo $html; |
||||
} |
||||
} |
||||
|
||||
add_action( 'wp_ajax_ontelegramauth', 'onTelegramAuth' ); |
||||
add_action( 'wp_ajax_nopriv_ontelegramauth', 'onTelegramAuth' ); |
||||
|
||||
function onTelegramAuth(){ |
||||
$tg_id = $_POST['userid']; |
||||
$tg_username = $_POST['username']; |
||||
$user = get_users( |
||||
array( |
||||
'meta_key' => 'tg_account', |
||||
'meta_value' => $tg_id |
||||
) |
||||
); |
||||
// $user = get_users( |
||||
// array( |
||||
// 'meta_key' => 'tg_username', |
||||
// 'meta_value' => $tg_username |
||||
// ) |
||||
// ); |
||||
|
||||
// Генерация пароля |
||||
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#!()'; |
||||
$pass = array(); |
||||
$alphaLength = strlen($alphabet) - 1; |
||||
for ($i = 0; $i < 12; $i++) { |
||||
$n = rand(0, $alphaLength); |
||||
$pass[] = $alphabet[$n]; |
||||
} |
||||
$pass = implode($pass); |
||||
|
||||
if($user) { |
||||
$user_login = $user[0]->data->user_login; |
||||
$user_id = get_user_by( 'login', $user_login )->ID; |
||||
wp_set_password( $pass, get_user_by( 'login', $user_login )->ID ); |
||||
wp_signon( |
||||
array( |
||||
'user_login' => $user_login, |
||||
'user_password' => $pass, |
||||
'remember' => 'on', |
||||
) |
||||
); |
||||
} else { |
||||
$user_id = wp_create_user( $tg_username, $pass, ''); |
||||
add_user_meta( $user_id, 'tg_account', $tg_id); |
||||
add_user_meta( $user_id, 'tg_username', $tg_username); |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'first_name' => $_POST['fname'], |
||||
'last_name' => $_POST['lname'] |
||||
] ); |
||||
wp_set_auth_cookie( $user_id, true ); |
||||
} |
||||
|
||||
} |
||||
|
||||
add_action( 'wp_ajax_linktelegram', 'linkTelegram' ); |
||||
add_action( 'wp_ajax_nopriv_linktelegram', 'linkTelegram' ); |
||||
|
||||
function linkTelegram(){ |
||||
$tg_id = $_POST['userid']; |
||||
$user_id = get_current_user_id(); |
||||
|
||||
add_user_meta( $user_id, 'tg_account', $tg_id); |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'first_name' => $_POST['fname'], |
||||
'last_name' => $_POST['lname'] |
||||
] ); |
||||
} |
||||
|
||||
add_action( 'wp_ajax_email_link', 'emailLink' ); |
||||
add_action( 'wp_ajax_nopriv_email_link', 'emailLink' ); |
||||
function emailLink(){ |
||||
|
||||
$email = $_POST['email']; |
||||
$user_id = get_current_user_id(); |
||||
|
||||
if(email_exists($email)){ |
||||
header("Content-Type: application/json"); |
||||
echo json_encode(array( |
||||
'error' => esc_html__( 'Email is already registered', 'woodmart' ) |
||||
)); |
||||
exit(); |
||||
} else { |
||||
wp_update_user( [ |
||||
'ID' => $user_id, |
||||
'user_email' => $email |
||||
] ); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
// Добавляем колонку Telegram в список пользователей |
||||
add_filter('manage_users_columns', 'add_tg_account_column'); |
||||
function add_tg_account_column($columns) { |
||||
$columns['tg_username'] = 'Telegram'; |
||||
return $columns; |
||||
} |
||||
|
||||
// Заполняем колонку данными |
||||
add_filter('manage_users_custom_column', 'add_tg_account_column_content', 10, 3); |
||||
function add_tg_account_column_content($value, $column_name, $user_id) { |
||||
if ('tg_username' == $column_name) { |
||||
$tg_account = get_user_meta($user_id, 'tg_username', true); |
||||
if ($tg_account) { |
||||
return '<a href="https://t.me/"' . esc_attr($tg_account) . '" target="_blank">@' . esc_html($tg_account) . '</a>'; |
||||
} |
||||
return '<span style="color:#ccc;">не указан</span>'; |
||||
} |
||||
return $value; |
||||
} |
||||
|
||||
// Делаем колонку сортируемой |
||||
add_filter('manage_users_sortable_columns', 'make_tg_account_column_sortable'); |
||||
function make_tg_account_column_sortable($columns) { |
||||
$columns['tg_username'] = 'tg_username'; |
||||
return $columns; |
||||
} |
||||
|
||||
// Обрабатываем сортировку |
||||
add_action('pre_get_users', 'handle_tg_account_sorting'); |
||||
function handle_tg_account_sorting($query) { |
||||
if (!is_admin() || !$query->is_main_query()) { |
||||
return; |
||||
} |
||||
|
||||
if ('tg_username' === $query->get('orderby')) { |
||||
$query->set('meta_key', 'tg_username'); |
||||
$query->set('orderby', 'meta_value'); |
||||
} |
||||
} |
||||
|
||||
?> |
Loading…
Reference in new issue