If you have an SSL certificate, and you’re having issues with tables linked to Google Spreadsheets, or if you’re creating tables linked to JSON files which require authorization, instead of modifying the code of wpDataTables (which would be overwritten with every update), you can use our hook “wpdatatables_curl_get_data”.
For JSON files, please take a look at the commented example for authentication. The custom code should be added to functions.php file of your theme, or the child theme.
function filterCURLOptions($data, $ch, $url){ // // $data (null) is set to null if there are available filter // // $ch cURL handle returned by curl_init(). // // $url (string) is URL of existing source(JSON, Google Sheet or PHP serialized array) // // Here you will insert your logic, because there are different JSON authentication // https://www.php.net/manual/en/function.curl-setopt.php // // Please note that this function is used for creating tables from JSON,Google sheets and PHP serialezed array // So you will need to filter it with some if statement based on $url parametar // // Useful links // // https://stackoverflow.com/questions/30426047/correct-way-to-set-bearer-token-with-curl // https://stackoverflow.com/questions/60183353/php-how-to-make-a-get-request-with-http-basic-authentication // https://stackoverflow.com/questions/44331346/php-api-call-with-curl-and-authentication/44332142 // https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl // Your code.... return $data; } add_filter('wpdatatables_curl_get_data','filterCURLOptions', 10, 3);
The following code is an example which is used for SSL of Google Spreadsheets:
function filterCURLOptions($data, $ch, $url){ curl_close($ch); $new_ch = curl_init(); $timeout = 5; $agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0'; curl_setopt($new_ch, CURLOPT_URL, $url); curl_setopt($new_ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($new_ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($new_ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($new_ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($new_ch, CURLOPT_USERAGENT, $agent); curl_setopt($new_ch, CURLOPT_REFERER, site_url()); curl_setopt($new_ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($new_ch); if (curl_error($new_ch)) { $error = curl_error($new_ch); curl_close($new_ch); wp_die($error); } if (strpos($data, '')) { wp_die(__('wpDataTables was unable to read your Google Spreadsheet, probably it is not published correctly. You can publish it by going to File -> Publish to the web ', 'wpdatatables')); } $info = curl_getinfo($new_ch); curl_close($new_ch); if ($info['http_code'] === 404) { return NULL; } return $data; } add_filter('wpdatatables_curl_get_data','filterCURLOptions', 10, 3);
This will work for tables made from Google Spreadsheets (regular method, not tables created with Google Sheets API), JSON files and Serialized PHP Arrays.
If your PostgreSQL is installed on Ubuntu 18.04 server, and you’re receiving the following error:
“wpDataTables could not connect to postgresql server. postgresql said: There was a problem with your SQL connection – could not find driver”
You may need to install PGSQL driver by following these steps:
[sudo] apt-get install php-pgsql
Then uncomment pgsql and pdo-pgsql extentions in php.ini and restart Apache with the following command:
[sudo] /etc/init.d/apache2 restart
- Please check is there are no JS errors in the javascript console. Please check e.g. in Chrome JS console. Usually when we investigate such things we find out that some other plugin or theme are broken, and wpDataTables JS cannot execute.
- Try to turn off option Include bootstrap on front-end in main settings of plugin.
- Please try switching the theme to a different one and see if it helps.
- Feel free to open a support ticket, providing us with the URL of the page so we could tell why does it happen.
By default, WordPress Media Library (used for attachments) allows file uploads only for users who have the upload_files capability. So, everyone who doesn’t have this capability (e.g. a subscriber) will receive an error on trying to upload a file.
To add this capability to subscribers you can e.g. use the User Role Editor plugin. Just enable the upload_files capability for the users which need it and it will work.
Other option is to add this capability dynamically via a hook. To do this you can add e.g. this code to your theme’s functions.php:
function give_permissions( $allcaps, $cap, $args ) { $allcaps['upload_files'] = true; return $allcaps; } add_filter( 'user_has_cap', 'give_permissions', 0, 3 );
Basically, it enables the upload_files capability to everyone – but you can extend this logic to allow it only for certain users at certain moments.
By default WordPress does not allow this. Reason is: logged out user has no ID (id is 0), and no permissions/capabilities enabled for him.
A solution would be to create an actual user that will be used as a single user for all logged-out users, and copy his ID (e.g. id = 100).
Then you can add a simple hook to identify logged out users as User with ID 100. To do this you can use a hook like this:
function set_loggedout_id( $user_id ){ if( empty( $user_id ) ){ $user_id = 100; } return $user_id; } add_filter( 'determine_current_user', 'set_loggedout_id', 999, 1 );
Basically, it “tells” WordPress to replace the empty ID of a logged out user with a value of 100.
Then you can allow uploading for this user.