2017-12-29 15 views

答えて

0

最初の手順では、APIキーを作成します。サイトに登録する必要があるAPIキーを取得するにはIPInfoDB.

APIキーを準備したら、IPInfoDBからip2locationlite.class.phpファイルをダウンロードする必要があります。

次のステップはカスタムプラグインを作成することです。私はそれを "country_custom_plugin.php"という名前にしました。フォルダ内にカスタムプラグインを作成することは常に適切です。これにより、対応するプラグインに必要なすべてのファイルがフォルダ内に残ります。フォルダを "country_custom_plugin"と指定しました

"ip2locationlite.class.php"ファイルを "country_custom_plugin"フォルダに移動します。

/* .Hopeはこれが役立つ

Reference

add_filter('wpcf7_special_mail_tags', 'country_custom_ip_location', 10, 2); 

/*Function to get location of an user from the ip address*/ 

function country_custom_ip_location($output, $name){ 
    /*including the third party integration to get IP Location*/ 
    include_once('ip2locationlite.class.php'); 

    /*Special tag values are passed in format wpcf7.$name which we convert to _$name*/ 
    $name = preg_replace('/^wpcf7\./', '_', $name); 

    /*If location is requested in contact form enter the loop*/ 
    if ('_custom_ip_location' == $name) { 
    $ipLite = new ip2location_lite; 

    /*Entering the API key value generated*/ 
    $ipLite->setKey('"Enter your API Key Here"'); 

    /*Getting the IP address*/ 
     $ipaddress = preg_replace('/[^0-9a-f.:, ]/', '', $_SERVER['REMOTE_ADDR']); 

    /*Getting the Location*/ 
    $visitorGeolocation = $ipLite->getCity($ipaddress); 

    if (!empty($visitorGeolocation) && is_array($visitorGeolocation)) { 
     $output = $visitorGeolocation['regionName'] . ', ' . $visitorGeolocation['countryName'] . ', ' . $visitorGeolocation['countryCode']; 
    } 
    } 
    return $output; 
} 
*/

コンタクトフォーム-7のモジュールから関数を呼び出すと、関数stylus_ip_location_get_ccの結果を渡します。問題があれば教えてください。

関連する問題