I planned to develop wordpress themes commercially.. I just want to know the easy method to add plugins to my wordpress theme which I am developing.. can any one suggest me the simple steps.. and I need possible methods that I can use effectively..
I planned to develop wordpress themes commercially.. I just want to know the easy method to add plugins to my wordpress theme which I am developing.. can any one suggest me the simple steps.. and I need possible methods that I can use effectively..
Share Improve this question asked Sep 2, 2011 at 5:35 Wordpress ThemesWordpress Themes 611 gold badge1 silver badge2 bronze badges 1- possible duplicate of Add Plugins to Wordpress Theme – Chip Bennett Commented Sep 2, 2011 at 12:40
2 Answers
Reset to default 5You can always include the files of the plugins in your theme functions.php file. Of course you should put it into some reasonable structure to not get your theme bloated with the files and the code :).
- https://stackoverflow/questions/6974006/wordpress-package-plugin-with-theme
- How to bundle a plugin with a theme, or vice versa
You can use code like this (used in Carrington theme) to load all the plugins included in the folder "plugin" within your theme folder...
/**
* Load theme plugins
*
**/
function cfct_load_plugins() {
$files = cfct_files(CFCT_PATH.'plugins');
if (count($files)) {
foreach ($files as $file) {
if (file_exists(CFCT_PATH.'plugins/'.$file)) {
include_once(CFCT_PATH.'plugins/'.$file);
}
// child theme support
if (file_exists(STYLESHEETPATH.'/plugins/'.$file)) {
include_once(STYLESHEETPATH.'/plugins/'.$file);
}
}
}
}
/**
* Get a list of php files within a given path as well as files in corresponding child themes
*
* @param sting $path Path to the directory to search
* @return array Files within the path directory
*
**/
function cfct_files($path) {
$files = apply_filters('cfct_files_'.$path, false);
if ($files) {
return $files;
}
$files = wp_cache_get('cfct_files_'.$path, 'cfct');
if ($files) {
return $files;
}
$files = array();
$paths = array($path);
if (STYLESHEETPATH.'/' != CFCT_PATH) {
// load child theme files
$paths[] = STYLESHEETPATH.'/'.str_replace(CFCT_PATH, '', $path);
}
foreach ($paths as $path) {
if (is_dir($path) && $handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
$path = trailingslashit($path);
if (is_file($path.$file) && strtolower(substr($file, -4, 4)) == ".php") {
$files[] = $file;
}
}
closedir($handle);
}
}
$files = array_unique($files);
wp_cache_set('cfct_files_'.$path, $files, 'cfct', 3600);
return $files;
}
...then you use function cfct_load_plugins();
during the theme initialization.
The simplest solution is just to use normal wordpress plugins ^^. Writing a specialized plugin system for your own theme is just totally unnecessary, makes your theme more bloated and increase development and maintaining cost. In this case the KISS principle wins.
Regards,
Hai
Another point to consider when replacing plug-ins with custom methods would be updates. Many plug-in updates are to address security issues, or to resolve issues caused by WordPress Updates.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745069802a4609477.html
评论列表(0条)