I'm still trying to use Cute File Browser into a WP Plugin: after solved all the issue I'm banging my head with the wp_get_current_user.
The plugin is made from a main.php:
add_shortcode("lace", "lace_shortcode");
function lace_shortcode(){
$html_code= '
<div class="filemanager">
<div class="search">
<input type="search" placeholder="Ricerca un file.." />
</div>
<div class="breadcrumbs"></div>
<ul class="data"></ul>
<div class="nothingfound">
<div class="nofiles"></div>
<span>Nessun file trovato.</span>
</div>
</div>';
wp_enqueue_script('script');
return $html_code;
}
that call script.js:
(function($){ $(document).ready(function(){
var filemanager = $('.filemanager'),
breadcrumbs = $('.breadcrumbs'),
fileList = filemanager.find('.data');
const SCANPHP_DIR = ("http://localhost/www.website.it/wp-content/plugins/lace/scan.php");
// Start by fetching the file data from scan.php with an AJAX request
$.get(SCANPHP_DIR, function(data) {
who use the info from the scan.php:
function scan($dir){
$files = array();
/$user = 'administrator';
// Is there actually such a folder/file?
if(file_exists($dir)){
foreach(scandir($dir) as $f) {
//if admin, see al folders/files, otherwise just user folders/files
if ($user!='administrator'){
if($f != $user){
continue;
}
} [...]
I need to retrieve the current WP user in order to execute correctly the plugin, but here comes the issue. I can use correctly $current_user = wp_get_current_user(); into the shortcode, but I don't know how to do that in the scan.php: if I try to use the same way, I couldn't execute it, maybe because the scan.php is loaded before the init of wordpress.
You can't access wordpress functions inside scan.php as this file is working as a standalone file as it is called through ajax.
If you want to use wordpress functions then you need to call ajax the right way.
Check this link: https://codex.wordpress.org/AJAX_in_Plugins