duanfei1930 2013-07-03 12:14
浏览 45

复制功能返回错误

I'm making a Wordpress theme, basically for portfolios.

Making plugins into the theme is bad, since changing themes can become a problem for the user and yourself if you do so. So I'm cooking up some script, that takes a plugins folder I made in my theme, which has the plugins that I would have built into the theme, but I'm making them install themselves when you select my theme. So these plugins will be updatable through the dashboard, and auto installed (if not already installed), into the site. Good idea no? (I got it from a forums post, but I dont think its been done as far as I know).

So I have a plugins folder in my theme, which has the plugins I want to auto install. I want to copy the plugins(single files or directories) into the wp-content/plugins folder and then install/activate them.

The problem is when I try to copy, it gives an error

Warning:  copy(http://127.0.0.1/inside-theme/wordpress/wp-content/plugins): failed to open stream: HTTP wrapper does not support writeable connections in C:\**path-to-www-**\www\inside-theme\wordpress\wp-content\themes\Inside Theme\header.php on line 105

If you're wondering about why it's in header.php, I'm just doing this for testing purposes to see if it copies. I will put it in a hook after.

Here is my code I'm using to copy the plugins,

    $dir = get_template_directory() . '/plugins/'; // the plugins folder in the theme
                $plugins_in_theme = scandir($dir); // $dir's contents
                $plugins_dir = plugins_url(); // url to the wp-content/plugins/

                print_r($plugins_in_theme); // just to check the output, not important
                foreach ($plugins_in_theme as $plugin) {
                    if ($plugin != '.' || '..') {
                        if (!file_exists($plugins_dir . $plugin)) {
                            if (is_dir($plugin)) {
                                recurse_copy($dir . $plugin, $plugins_dir);
                            } else {
                                copy($dir . $plugin, $plugins_dir);
                            }
                        } 
                    }
                }

recurse_copy() is a function I picked up off another stackoverflow question for copying directories since copy() only copies files, not folders. Also note that, it gives multiple errors, with the functions.php of my theme mentioned in most errors, which is where I put the recursive_copy() function. (Is that ok? It's my first theme..)

function recurse_copy($src,$dst) { //for copying directories
$dir = opendir($src); 
@mkdir($dst); 
while(false !== ( $file = readdir($dir)) ) { 
    if (( $file != '.' ) && ( $file != '..' )) { 
        if ( is_dir($src . '/' . $file) ) { 
            recurse_copy($src . '/' . $file,$dst . '/' . $file); 
        } 
        else { 
            copy($src . '/' . $file,$dst . '/' . $file); 
        } 
    } 
} 
closedir($dir); 
} 

So how can I remove this error and get it to work?

Extra details, I'm using windows xp and I'm using the 'handcrafted wp' parent theme, I AM RUNNING THIS LOCALLY. (on local host)

Hope I was clear.

  • 写回答

1条回答 默认 最新

  • dongshai8330 2013-11-29 12:55
    关注

    You are using $plugins_dir = plugins_url(); in the code which returns http://yoursite/wp-content/plugins/ However, copy function works with directories not URLs, so it's better to use, ABSPATH, dirname( __FILE__ ) . '/blablabla.php' and other functions returning directories not URLs. Click here to learn more about PHP copy function

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大