Je reçois cette erreur à cause de l’un des plugins sur lesquels je compte.
Remarque: wp_enqueue_style a été appelé de manière incorrecte. Les scripts et les styles ne doivent pas être enregistrés ou mis en file d'attente avant les scripts wp_enqueue_scripts, admin_enqueue_scripts ou init.
Que signifie cette erreur et comment la résolvez-vous? Attention, ce n'est pas une erreur critique. Il n'apparaît que lorsque WP est en mode débogage.
Le plugin-code complet est ci-dessous.
C'est un plug-in qui facilite le traitement des chats très compliqués et hiérarchisés. Je le publie pas juste pour des raisons de débogage où l’erreur bloddy est mais aussi pour espérer que cela aide quelqu'un.
<?php /*
**************************************************************************
Plugin Name: Category Collapse
Description: Makes children categories hidden on the Write screens until an icon is clicked.
Version: 2009.02.12
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************/
class CategoryCollapse {
// Plugin initialization
function CategoryCollapse() {
if ( !is_admin() ) return;
wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
add_action( 'admin_head', array(&$this, 'edit_form_advanced') );
}
// Output the Javascript (it's not in an external file due to the dynamic image URLs)
function edit_form_advanced() { ?>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function($){
$("#categorychecklist li").addClass("catcolpadding");
$("#categorychecklist ul.children").hide().parent("li").removeClass("catcolpadding").addClass("cathaschildren catcollapsed").prepend('<img class="catcoltoggler" src="<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>" alt="+" title="Show Children" />');
$("#categorychecklist .catcoltoggler").click(function(){
var parent = $(this).parent("li.cathaschildren");
if ( parent.hasClass("catcollapsed") ) {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/minus.gif'); ?>", alt: "-", title: "Hide Children" });
parent.removeClass("catcollapsed").addClass("catuncollapsed").children("ul.children").slideDown();
} else {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>", alt: "+", title: "Show Children" });
parent.removeClass("catuncollapsed").addClass("catcollapsed").children("ul.children").slideUp();
}
});
$(".cat-checklist li").addClass("catcolpadding");
$(".cat-checklist ul.children").hide().parent("li").removeClass("catcolpadding").addClass("cathaschildren catcollapsed").prepend('<img class="catcoltoggler" src="<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>" alt="+" title="Show Children" />');
$(".cat-checklist .catcoltoggler").click(function(){
var parent = $(this).parent("li.cathaschildren");
if ( parent.hasClass("catcollapsed") ) {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/minus.gif'); ?>", alt: "-", title: "Hide Children" });
parent.removeClass("catcollapsed").addClass("catuncollapsed").children("ul.children").slideDown();
} else {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>", alt: "+", title: "Show Children" });
parent.removeClass("catuncollapsed").addClass("catcollapsed").children("ul.children").slideUp();
}
});
});
/* ]]> */
</script>
<?php
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $CategoryCollapse; $CategoryCollapse = new CategoryCollapse();' ) );
?>
Le problème est que l'appel wp_enqueue_style()
est à l'intérieur de la fonction membre category_collapse()
de la classe CategoryCollapse()
et que la classe CategoryCollapse()
est en cours d'instanciation par un rappel intégré dans l'action hook plugins_loaded
.
Cela signifie que la fonction wp_enqueue_style()
tente de s'exécuter au point plugins_loaded
, QUI DÉCLENCHE BEFORE init
, wp_enqueue_scripts
ET admin_enqueue_scripts
.
Pour réparer, remplacez ceci:
wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
...avec ça:
function wpse49339_enqueue_styles() {
wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
}
add_action( 'wp_enqueue_scripts', 'wpse49339_enqueue_styles' );
De cette façon, l'appel wp_enqueue_style()
sera connecté à wp_enqueue_scripts
au lieu de déclencher directement à plugins_loaded
.
// voici le code de travail et sans bug
<?php /*
**************************************************************************
Plugin Name: Category Collapse
Description: Makes children categories hidden on the Write screens until an icon is clicked.
Version: 2009.02.12
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************/
class CategoryCollapse {
// Plugin initialization
function CategoryCollapse() {
if ( !is_admin() ) return;
//begin modifitication
//per bennet's suggestion on http://wordpress.stackexchange.com/questions/49339/notice-that-the-wp-enqueue-style-is-not-being-called-correctly/49344#49344
//the following org code is commented out
//wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
//and replaced with this;
function wpse49339_enqueue_styles() {
wp_enqueue_style( 'category-collapse', plugins_url('/category-collapse/category-collapse.css'), array(), '2009.02.12', 'screen' );
}
add_action( 'wp_enqueue_scripts', 'wpse49339_enqueue_styles' );
//end modification
add_action( 'admin_head', array(&$this, 'edit_form_advanced') );
}
// Output the Javascript (it's not in an external file due to the dynamic image URLs)
function edit_form_advanced() { ?>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function($){
$("#categorychecklist li").addClass("catcolpadding");
$("#categorychecklist ul.children").hide().parent("li").removeClass("catcolpadding").addClass("cathaschildren catcollapsed").prepend('<img class="catcoltoggler" src="<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>" alt="+" title="Show Children" />');
$("#categorychecklist .catcoltoggler").click(function(){
var parent = $(this).parent("li.cathaschildren");
if ( parent.hasClass("catcollapsed") ) {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/minus.gif'); ?>", alt: "-", title: "Hide Children" });
parent.removeClass("catcollapsed").addClass("catuncollapsed").children("ul.children").slideDown();
} else {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>", alt: "+", title: "Show Children" });
parent.removeClass("catuncollapsed").addClass("catcollapsed").children("ul.children").slideUp();
}
});
$(".cat-checklist li").addClass("catcolpadding");
$(".cat-checklist ul.children").hide().parent("li").removeClass("catcolpadding").addClass("cathaschildren catcollapsed").prepend('<img class="catcoltoggler" src="<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>" alt="+" title="Show Children" />');
$(".cat-checklist .catcoltoggler").click(function(){
var parent = $(this).parent("li.cathaschildren");
if ( parent.hasClass("catcollapsed") ) {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/minus.gif'); ?>", alt: "-", title: "Hide Children" });
parent.removeClass("catcollapsed").addClass("catuncollapsed").children("ul.children").slideDown();
} else {
$(this).attr({ src: "<?php echo plugins_url('/category-collapse/images/plus.gif'); ?>", alt: "+", title: "Show Children" });
parent.removeClass("catuncollapsed").addClass("catcollapsed").children("ul.children").slideUp();
}
});
});
/* ]]> */
</script>
<?php
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $CategoryCollapse; $CategoryCollapse = new CategoryCollapse();' ) );
?>