WordPress wp_get_current_user - REST API | admin-ajax.php - creating a function
Budget: $10 – $30 USD
I have a WordPress template that displays files from the logged in user's directory (see screen).
The name of the user's directory is the same as his login in the database. I need to get a variable with the user's login to display the files of the currently logged in user.
Then substitute the variable in the directory path like this.
$initial_directory = ("/public_html/wp-content/uploads/user_dirs/$user_login/");
I used wp_get_current_user and it works.
The problem is that the manager has to refresh the view every 3 seconds. While after the initial loading of the page, the correct user directory is displayed, after the automatic refresh of the page, no longer.
This is probably because the script can't get the $user_login variable without reloading the page.
wp_get_current_user is defined in the functions.php file while the table view is refreshed from another php file
Your task is to write the correct function and solve this problem.
I suggest using the WordPress REST API. Apparently, this way you can extract session data of a logged-in user.
https://wordpress.stackexchange.com/questions/303900/how-to-get-user-id-from-wordpress-database-inside-ajax-function?rq=1
The second option is to get session data from admin-ajax.php
https://wordpress.stackexchange.com/questions/303900/how-to-get-user-id-from-wordpress-database-inside-ajax-function?rq=1
I don't have enough PHP experience to do this, so I'm looking for a contractor.
The name of the user's directory is the same as his login in the database. I need to get a variable with the user's login to display the files of the currently logged in user.
Then substitute the variable in the directory path like this.
$initial_directory = ("/public_html/wp-content/uploads/user_dirs/$user_login/");
I used wp_get_current_user and it works.
The problem is that the manager has to refresh the view every 3 seconds. While after the initial loading of the page, the correct user directory is displayed, after the automatic refresh of the page, no longer.
This is probably because the script can't get the $user_login variable without reloading the page.
wp_get_current_user is defined in the functions.php file while the table view is refreshed from another php file
Your task is to write the correct function and solve this problem.
I suggest using the WordPress REST API. Apparently, this way you can extract session data of a logged-in user.
https://wordpress.stackexchange.com/questions/303900/how-to-get-user-id-from-wordpress-database-inside-ajax-function?rq=1
The second option is to get session data from admin-ajax.php
https://wordpress.stackexchange.com/questions/303900/how-to-get-user-id-from-wordpress-database-inside-ajax-function?rq=1
I don't have enough PHP experience to do this, so I'm looking for a contractor.