You should allow for a custom field in your unity profile which will be linked to the WordPress profile. You could then run a JavaScript function to call an AJAX script to execute a PHP file inside WordPress to update a specific profile.
Here’s some pseudo-code:
JavaScript
function updateProfile(parameters) {
var xhttp = new XMLHttpRequest();
xhttp.open('GET', 'https://www.example.com/receiver.php' + parameters, true);
xhttp.send();
}
// Usage
updateProfile('?username=whatever&points=4');
PHP (receiver.php
):
<?php
global $wpdb;
$username = $_POST['username'];
$points = (int) $_POST['points'];
$wpdb->query("UPDATE some_table SET points = points + $points WHERE username = $username");
Note you’ll need to sanitise your input and you’ll neet to link the pints to the username. You can add add_user_meta()
function for this.
Note that this is a basic approach. The receiver.php
file can be part of a plugin, so you’ll actually call example.com/wp-content/plugins/unity-plugin/receiver.php
in your AJAX call.