I have been trying to have some custom info in the table. I manage to do awesome stuff but I encounter a wall right now. I'm trying to use the function of wordpress current_user_can() to show a button or not in the table. If I run the php file is showing as I expected. But when I open it through the wpdatatables generator it doesn't recognize the user. How can I make it possible so the AJAX call that is doing to retrieve the data I can use the user info inside that PHP? In some forums, I found that the AJAX call must have nonce to be able to access the user info. But that part is way higher that my knowledge can handle.
In order to dynamically pass data, while using PHP serialized array - or in other words, when you create tables from PHP files, here is what they advised.
There is a hook available in the Premium version:
wpdatatables_filter_url_php_array
In hook, you will do something like this
function test ($url,$id) {
// all data from current user
// you can fetch only what you need
$userData = wp_get_current_user()->data;
if(isset($userData)){
$url .= '?' . http_build_query($userData);
}
return $url;
}
add_filter('wpdatatables_filter_url_php_array', 'test', 2 , 10)
In the PHP file, you will use the $_GET method to take the values from the URL which is filtered with the hook
// you can check then for ID or user_login or user_pass or user_nicename or user_email ...
if(isset($_GET['user_login'])){
//do somthing
}
I try to be detailed as I can so you can do this easily.
Hi!!! sorry for the late response... COVID hit the family. Anyway, the code works perfectly.
Here is a version of the code that I use:
function passIDToDataTable ($url,$id) { // all data from current user // you can fetch only what you need $userId = get_current_user_id(); if(isset($userId)){ $url .= '&userID=' . $userId; } return $url; } add_filter('wpdatatables_filter_url_php_array', 'passIDToDataTable', 2 , 10);
I have been trying to have some custom info in the table. I manage to do awesome stuff but I encounter a wall right now. I'm trying to use the function of wordpress current_user_can() to show a button or not in the table. If I run the php file is showing as I expected. But when I open it through the wpdatatables generator it doesn't recognize the user. How can I make it possible so the AJAX call that is doing to retrieve the data I can use the user info inside that PHP? In some forums, I found that the AJAX call must have nonce to be able to access the user info. But that part is way higher that my knowledge can handle.
Hi, Victor
To be honest, i will have to check this with our developers.
They will help me confirm , and we will do our best to help you.
This is already higher than my skill level - but they will tell me if we need any additional details, in order to advise
As soon as they respond, i will report back.
Thank you
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi, Victor
Sorry about the waiting time.
I just wanted to say our developers will advise us very soon - we will report back as quick as possible.
Thank you for your patience.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi, Victor
I got confirmation from our devs on this.
In order to dynamically pass data, while using PHP serialized array - or in other words, when you create tables from PHP files, here is what they advised.
There is a hook available in the Premium version:
In hook, you will do something like this
In the PHP file, you will use the $_GET method to take the values from the URL which is filtered with the hook
I try to be detailed as I can so you can do this easily.
Let me know is it working as you need. Thank you
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi!!! Thanks for your reply... I will work with those codes... I'll update as soon as I have something.
Hi, Victor
No problem
Let us know how it goes .
Thank you
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi!!! sorry for the late response... COVID hit the family. Anyway, the code works perfectly.
Here is a version of the code that I use: