I'm new to WordPress but I would like to create a plugin which lists all the plugins settings of the custom plugins I'm creating, so I don't have to go in each and every plugin.
In the main plugin I have this:
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
}
}
}
}
What the above snippet does is get all the plugins with the prefix I have. This works fine and even the bit : $class_handler->show_settings()
as the display works just fine, but I'm having issue with en queuing styles and JS.. so this is the code in the child plugin:
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' );
}
but the color picker is not being included in the styles as the function add_be_script()
is not being called.
Any help would be greatly appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire