onlineth You could add something like the following to the beginning of your index.php and API.php and Admin.php:
$_SERVER['REMOTE_ADDR'] = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']);
Although, you would want to make sure all users connecting to your site were directed through cloudflare.