0
我是新來的WordPress,但我想創建一個插件,其中列出了我創建的自定義插件的所有插件設置,所以我不必每次都去,每個插件。主插件與子插件 - WP
在主插件我有這樣的:
if (!function_exists('get_plugins'))
require_once (ABSPATH."wp-admin/includes/plugin.php");
$all_plugins = get_plugins();
foreach($all_plugins as $plugin_key => $plugin_data){
if (strpos(strtolower($plugin_data['Name']),'prefix') !== false) {
//skip this one as this is the main plugin and we do not need to display any thing
if (strpos(strtolower($plugin_data['Name']),'plugins') === false) {
if (is_plugin_active($plugin_key)) {
require_once(ABSPATH . 'wp-content/plugins/'.$plugin_key);
$plugin_class_name = preg_replace('/\s+/','', str_replace("'", "", ucwords($plugin_data['Name'])));
$class_handler = new $plugin_class_name();
?>
<div id="sec-<?php echo $plugin_key ?>" class="section">
<div class="section-header">
<h3><?php echo $plugin_data['Name']?></h3>
</div>
<div class="section-content">
<?php $class_handler->show_settings() ?>
</div>
</div>
<?php
}
}
}
}
什麼上面的代碼的作用是讓所有的前綴我有插件。這工作得很好,甚至有點:$class_handler->show_settings()
作爲顯示工作得很好,但我有問題了連接排隊風格和JS ..所以這是在孩子的插件代碼:
function __construct(){
if (!function_exists('add_action')) {
echo "This page cannot be called directly.";
exit;
}
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
if(is_admin()){
//call be scripts
add_action('wp_enqueue_scripts', array($this, 'add_be_script'));
} else{
//call frontend scripts
add_action('wp_enqueue_scripts', array($this, 'add_fe_script'));
}
}
function add_be_script(){
wp_enqueue_style('wp-color-picker');
}
但顏色由於未調用函數add_be_script()
,拾取器未包含在樣式中。
任何幫助將不勝感激。
或者有'admin_enqueue_scripts' – Andy