I want to copy two files (rate-my-post-fa_IR.po and rate-my-post-fa_IR.mo)
in the Rate my post plugin from the template I designed.
I couldn’t find the code to copy the file from the WordPress theme to the plugin but the code below does something similar to what I want to do.
This code copies a file from the plugin to the template, and I want to do the exact opposite:
function file_replace() {
$plugin_dir = plugin_dir_path( __FILE__ ) . 'library/front-page.php';
$theme_dir = get_stylesheet_directory() . '/front-page.php';
if (!copy($plugin_dir, $theme_dir)) {
echo "failed to copy $plugin_dir to $theme_dir...n";
}
}
add_action( 'wp_head', 'file_replace' );
Source:
https://developer.wordpress.org/reference/functions/register_activation_hook/
https://developer.wordpress.org/reference/hooks/after_setup_theme/
2
Answers
Are there any error logs? HaveTry this to check which message pops up for you already checked if your application’s user has write permissions on the folder? And the files already exist (which will be overwritten) what is their permission?:
Try this to check which message pops up for you:
You will see that it can happen to show that it is a write permission error on the folder. So a little PHP CHMOD might help.