質問: new categorycollapse();' ) ); ?>
回答: //これは動作しバグのないコードです。<?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();' ) ); ?>