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.