Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

add_action('rest_api_init', function () { register_rest_route('kleabe/v1', '/save-fcm-token', array( 'methods' => 'POST', 'callback' => 'kleabe_save_fcm_token', 'permission_callback' => '__return_true', )); }); function kleabe_save_fcm_token(WP_REST_Request $request) { $token = sanitize_text_field($request->get_param('token')); $platform = sanitize_text_field($request->get_param('platform')); $app = sanitize_text_field($request->get_param('app')); $package_name = sanitize_text_field($request->get_param('package_name')); if (empty($token)) { return new WP_REST_Response(array( 'success' => false, 'message' => 'Token mungon' ), 400); } $tokens = get_option('kleabe_fcm_tokens', array()); $exists = false; foreach ($tokens as $item) { if (isset($item['token']) && $item['token'] === $token) { $exists = true; break; } } if (!$exists) { $tokens[] = array( 'token' => $token, 'platform' => $platform ? $platform : 'android', 'app' => $app ? $app : 'kleabe', 'package_name' => $package_name ? $package_name : 'com.kleabe.app', 'created_at' => current_time('mysql') ); update_option('kleabe_fcm_tokens', $tokens, false); } return new WP_REST_Response(array( 'success' => true, 'count' => count($tokens) ), 200); } function kleabe_send_push_notification($title, $body, $url = '') { $tokens = get_option('kleabe_fcm_tokens', array()); if (empty($tokens)) { return; } $serverKey = 'VENDOS_FIREBASE_SERVER_KEY_KETU'; foreach ($tokens as $item) { if (empty($item['token'])) { continue; } $payload = array( 'to' => $item['token'], 'notification' => array( 'title' => $title, 'body' => $body ), 'data' => array( 'title' => $title, 'body' => $body, 'url' => $url ? $url : 'https://kleabe.com' ) ); wp_remote_post('https://fcm.googleapis.com/fcm/send', array( 'headers' => array( 'Authorization' => 'key=' . $serverKey, 'Content-Type' => 'application/json' ), 'body' => wp_json_encode($payload), 'timeout' => 15 )); } } add_action('init', function () { if (isset($_GET['test_push']) && current_user_can('manage_options')) { kleabe_send_push_notification( 'Test KleaBe 🔥', 'Kjo është një provë', 'https://kleabe.com' ); wp_die('Push u dërgua'); } }); add_action('admin_notices', function () { if (!current_user_can('manage_options')) { return; } $tokens = get_option('kleabe_fcm_tokens', array()); echo '

FCM Tokens: ' . count($tokens) . '

'; });