I have read that there are two ways for integrating a plugin on a Wordpress theme.
I think the first method is the best; but I do not know exactly how to do it...
After copying the plugin to the plugin directory of Wordpress... How do I enable it? Do you know another way to do this?
Then I expose what I've tried to do, that ye may prove if is right what I think:
First method: copy my plugin to wp-content/plugins.
- Bundling the plugin as is, and using code to copy it to the plugins folder and call
activate_plugin
to install it.
All I know is how to copy the plugin directory:
function recurse_copy($src,$dst) {
$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);
}
// I copy my plugin to wp-content/plugins
recurse_copy($path."/plugins/myplugin_Directory", WP_PLUGIN_DIR . "/myplugin_Directory");
Second method: using my plugin instead a plugins inside wp-content-plugins.
- Using a copy of the plugin in the theme folder and change the references (paths) to all dependencies for to be used the resources from the theme directory.
Example for the second method: (put this in functions.php
)
add_action('after_setup_theme', 'load_MyPlugin');
function load_MyPlugin() {
if (!class_exists('MyPluginClass')) {
include_once(get_template_directory_uri() . '/plugins/myplugin_Directory/index.php');
}
}