最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - how does 'init' 'parse_request' hook work for wordpress?

programmeradmin3浏览0评论

I wanna try to collect statistics for my wordpress website with my own plugin. the information I need is stored in $_SERVER variable. by surfing the Internet, I've two useful hooks to insert my code:

  1. parse_request 2. init

Everything works fine with localhost. no data is missed, no matter it's by mobile phone or desktop, from page links or offline documents, inside apps or browser.

while it's running online, something is different. After several days collecting, i've found the collected info is not complete; sometimes i visited the website directly with mobile phone through browser or inside an app, the info will not be recorded. but I checked the access.log, it's normal. And when running on localhost, data is saved soundly. I cannot figure out why when put online, it will omit some data

function get_statistics(){
global $wpdb;
$table_name = 'table_name';
$split_str = 'separation_str';
$logdata=$_SERVER['REQUEST_TIME'].$split_str.$_SERVER['HTTP_REFERER'].$split_str.$_SERVER['HTTP_USER_AGENT'].$split_str.$_SERVER['REMOTE_ADDR'].$split_str.$_SERVER['REQUEST_URI'].$split_str.$_SERVER['HTTP_COOKIE'];
$logdata =substr($logdata,0,1500);

$wpdb->query( $wpdb->prepare( 'insert into '.$table_name.'(logdata) values(%s)', $logdata) );}
add_action('init','get_statistics',1);
发布评论

评论列表(0)

  1. 暂无评论