Wordfence date format
-
Hi,
This is purely a cosmetic request – in the Wordfence > Live Traffic page the Time column ignores WordPress’ the regional settings set under Settings > General.
Can Wordfence please print the Time column in the correct format? Is there a hack I can do until this bug is fixed?
Ta,
Gavin-
This topic was modified 7 years, 2 months ago by
gavsterau.
-
This topic was modified 7 years, 2 months ago by
-
Hate following up my own post.
In one browser I’m getting the correct date format (dd/mm/yyyy), but in another I’m getting the wrong format (mm/dd/yyyy).
Any ideas on how to debug this?
Ta, Gavin
Hi @gavsterau,
I wrote some changes that will pull the date/time format from WordPress settings.
Here are the following changes (All files mentioned are in
wp-content/plugins/wordfence/)1. Edit
lib/wordfenceClass.php:Find
wp_enqueue_script('wordfenceAdminjs',and add something before and after it, like so:wp_enqueue_script('format.date', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/format.date.js'), array(), WORDFENCE_VERSION); wp_enqueue_script('wordfenceAdminjs', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/admin.js'), array('jquery', 'jquery-ui-core', 'jquery-ui-menu', 'format.date'), WORDFENCE_VERSION); wp_localize_script('wordfenceAdminjs', 'settings', [ 'format' => get_option('date_format') . ' ' . get_option('time_format') ]);2. Still editing
lib/wordfenceClass.php:Find
wp_enqueue_script('wordfence-live-traffic-js',and add something before and after it, like so:wp_enqueue_script('format.date', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/format.date.js'), array(), WORDFENCE_VERSION); wp_enqueue_script('wordfence-live-traffic-js', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/admin.liveTraffic.js'), array('jquery', 'jquery-ui-tooltip', 'format.date'), WORDFENCE_VERSION); wp_localize_script('wordfence-live-traffic-js', 'settings', [ 'format' => get_option('date_format') . ' ' . get_option('time_format') ]);3. Create the file
js/format.date.1543941426.js:Copy and paste into this file:
function date(n,t){var e,r,u=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur","January","February","March","April","May","June","July","August","September","October","November","December"],o=/\\?(.?)/gi,i=function(n,t){return r[n]?r[n]():t},c=function(n,t){for(n=String(n);n.length<t;)n="0"+n;return n};r={d:function(){return c(r.j(),2)},D:function(){return r.l().slice(0,3)},j:function(){return e.getDate()},l:function(){return u[r.w()]+"day"},N:function(){return r.w()||7},S:function(){var n=r.j(),t=n%10;return t<=3&&1===parseInt(n%100/10,10)&&(t=0),["st","nd","rd"][t-1]||"th"},w:function(){return e.getDay()},z:function(){var n=new Date(r.Y(),r.n()-1,r.j()),t=new Date(r.Y(),0,1);return Math.round((n-t)/864e5)},W:function(){var n=new Date(r.Y(),r.n()-1,r.j()-r.N()+3),t=new Date(n.getFullYear(),0,4);return c(1+Math.round((n-t)/864e5/7),2)},F:function(){return u[6+r.n()]},m:function(){return c(r.n(),2)},M:function(){return r.F().slice(0,3)},n:function(){return e.getMonth()+1},t:function(){return new Date(r.Y(),r.n(),0).getDate()},L:function(){var n=r.Y();return n%4==0&n%100!=0|n%400==0},o:function(){var n=r.n(),t=r.W();return r.Y()+(12===n&&t<9?1:1===n&&t>9?-1:0)},Y:function(){return e.getFullYear()},y:function(){return r.Y().toString().slice(-2)},a:function(){return e.getHours()>11?"pm":"am"},A:function(){return r.a().toUpperCase()},B:function(){var n=3600*e.getUTCHours(),t=60*e.getUTCMinutes(),r=e.getUTCSeconds();return c(Math.floor((n+t+r+3600)/86.4)%1e3,3)},g:function(){return r.G()%12||12},G:function(){return e.getHours()},h:function(){return c(r.g(),2)},H:function(){return c(r.G(),2)},i:function(){return c(e.getMinutes(),2)},s:function(){return c(e.getSeconds(),2)},u:function(){return c(1e3*e.getMilliseconds(),6)},e:function(){throw new Error("Not supported (see source code of date() for timezone on how to add support)")},I:function(){return new Date(r.Y(),0)-Date.UTC(r.Y(),0)!=new Date(r.Y(),6)-Date.UTC(r.Y(),6)?1:0},O:function(){var n=e.getTimezoneOffset(),t=Math.abs(n);return(n>0?"-":"+")+c(100*Math.floor(t/60)+t%60,4)},P:function(){var n=r.O();return n.substr(0,3)+":"+n.substr(3,2)},T:function(){return"UTC"},Z:function(){return 60*-e.getTimezoneOffset()},c:function(){return"Y-m-d\\TH:i:sP".replace(o,i)},r:function(){return"D, d M Y H:i:s O".replace(o,i)},U:function(){return e/1e3|0}};var a,f;return a=n,e=void 0===(f=t)?new Date:f instanceof Date?new Date(f):new Date(1e3*f),a.replace(o,i)}4. Edit
js/admin.1543941426.js:Find
showTimestamp: function(and replace this function with:showTimestamp: function(timestamp, serverTime, format) { serverTime = serverTime === undefined ? new Date().getTime() / 1000 : serverTime; format = format === undefined ? '${dateTime} (${timeAgo} ago)' : format; return jQuery.tmpl(format, { dateTime: date(settings.format, timestamp), timeAgo: this.makeTimeAgo(serverTime - timestamp) }); },5. Edit
js/admin.liveTraffic.1543941426.js:Find
self.timestamp = ko.pureComputed(function() {and replace this function with:self.timestamp = ko.pureComputed(function() { return date(settings.format, self.ctime()); }, self);6. Visit your live traffic (Press CTRL + F5 to refresh cache)
You can now change your WordPress date and time format settings, and the Wordfence live traffic should display the updated format.
I’ll send a feature request to the Wordfence team and see what they think about it.
Please give me a few moments and I’ll post again with a link to download these updated files (if you would like to replace these files instead of manually editing them).
Thanks!
Dave
Hi again!
As promised, here are the files that I changed bundled in a zip.
https://puu.sh/Ctr0K/496ee82297.zip
You only need to drag the two folders (
lib,js) into/wp-content/plugins/wordfence/and they should replace.Please make sure you are on the latest version of Wordfence. (The number beside the JavaScript files in your installation should be
1543941426)—–
In one browser I’m getting the correct date format (dd/mm/yyyy), but in another I’m getting the wrong format (mm/dd/yyyy).What is happening is that date/time stamps are rendered by your browser. In Chrome, you can change the format by changing your default language (for example English – United States -> English – United Kingdom).
However, if you apply the patch, it will always follow the format you have set within WordPress options.
Dave
Why should we modify these files manually? Should not Wordfence automatically respect WordPress date/time format settings?
For me Blocking page shows date/time in correct format but Live Traffic page doesn’t respect my custom settings. It always shows date/time in 12:00 AM/PM format.
It should be definitely fixed.
Hi @yet-another-wp-user,
This is only a hot-fix that I wrote because gavsterau asked for a hack.
I’ve already posted a feature request to the team, so maybe this is something they can consider in future versions of Wordfence.
Thanks for your patience.
Dave
OK. I hope they’ll fix it soon.
Thanks very much for your replies.
The ID (datestamp I assume) on my JS files is 1546968199, not 1543941426.
1543941426 == GMT: Tuesday, December 4, 2018 4:37:06 PM
1546968199 == GMT: Tuesday, January 8, 2019 5:23:19 PMWill above still work?
Hi @gavsterau,
Wordfence was updated since my last post.
I’ve created a new patch for you for
1546968199.Wordfence-1546968199: https://puu.sh/CtV6t/e6f2a961c5.zip
1. Unzip
wordfence-patch-1546968199.zip
2. Drag and droplibandjsinto/wp-content/plugins/wordfence/
3. Press CTRL + F5 in your live traffic to refresh the view without cacheDave
The topic ‘Wordfence date format’ is closed to new replies.