Wordpress 将文件从插件目录复制到主题目录

Wordpress 将文件从插件目录复制到主题目录,wordpress,plugins,copy,Wordpress,Plugins,Copy,我需要将两个文件从插件目录复制到主题目录。我试过这个 function plugin_to_theme_dir() { $plugin_dir = plugin_dir_path(__FILE__) . 'folder/one.php'; $plugin_dir = plugin_dir_path(__FILE__) . 'folder/two.php'; $theme_dir = get_template_directory() . '/one.php';

我需要将两个文件从插件目录复制到主题目录。我试过这个

function plugin_to_theme_dir()
{
    $plugin_dir = plugin_dir_path(__FILE__) . 'folder/one.php';
    $plugin_dir = plugin_dir_path(__FILE__) . 'folder/two.php';

    $theme_dir  = get_template_directory() . '/one.php';
    $theme_dir  = get_template_directory() . '/two.php';


    if (!copy($plugin_dir, $theme_dir)) {
        echo "failed to copy $plugin_dir to $theme_dir...\n";
    }
}
add_action('init', 'plugin_to_theme_dir');
但是,我只能将
two.php
文件复制到主题目录,而不能复制另一个。我两个都要复印。我怎么能做到


来源:

将目标和目的地放入关联数组中,并在其中循环。或者,如果您并不真正关心可维护性,请将
$plugin\u dir\u 1
$theme\u dir\u 1
一起使用,将
$plugin\u dir\u 2
$theme\u dir\u 2
一起使用,您现在应该会注意到您的错误。谢谢。我现在明白了。因为只有两个文件,所以我没有选择数组。