In order to rename you have to alter your code like bellow. You code was missing absolute path of the directory. That’s why your code was not working. Adding ABSPATH
will fix the code.
rename( ABSPATH . "wp-content/uploads/Directory/Clients/$Client_Name", ABSPATH . "wp-content/uploads/Directory/Clients/$New_Name" );
Why not you use WP_Filesystem_Direct
. It’s better and fatal-safe. You can easily use that by including these to file to your functions.php
require_once(ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php');
require_once(ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php');
Now from you given code, alter that like this:
if(isset($_POST['Edit_Client']) == '1'){
$current = ABSPATH . "wp-content/uploads/Directory/Clients/$Client_Name";
$destination = ABSPATH . "wp-content/uploads/Directory/Clients/$New_Name";
WP_Filesystem_Direct::move($current,$destination);
}
WP_Filesystem_Direct
will automatically check whatever approach will be better. It will try to rename first. If fails then It will make a copy and delete old folder.
Read more about WP_Filesystem_Direct::move & WP_Filesystem_Direct