具有以下功能:
<?php
class Planner_plugin{
public function __construct(){
add_shortcode(\'planner::display\', array($this, \'display_planner\'));
register_activation_hook( __FILE__, array( \'Planner_plugin\' , \'install\'));
add_action(\'wp_enqueue_scripts\', array($this,\'planner_load_scripts\')); // chargement du script
...
}
public function planner_load_scripts(){
wp_register_style(\'planner_css\', plugins_url(\'css/style.css\', __FILE__)); //my style
wp_register_style(\'opensans_css\', plugins_url(\'css/open-sans_Font.css\', __FILE__)); //Open sans font
wp_register_style(\'fa_css\', plugins_url(\'css/font-awesome.min.css\', __FILE__));
wp_register_script(\'planner_script\', plugins_url(\'js/calendar.js\', __FILE__), array( \'jquery\' ), \'\', true ); // my script who generate a planner
wp_enqueue_style(\'planner_css\');
wp_enqueue_style(\'opensans_css\');
wp_enqueue_style(\'fa_css\');
wp_enqueue_script(\'planner_script\');
wp_localize_script(\'planner_script\',\'wp_included_vars\', array(
\'date\' => strtotime(\'now\')
)
);
}
...
}
$plugin = new Planner_Plugin();
?>
生成所有内容后,我将有多个事件侦听器寄存器(6次),因此每当我在组件中执行操作时,它都会触发我的函数6次。但是钩子;wp\\U enqueue\\U脚本“;只能触发一次,不是吗?我该怎么解决这个问题?
在我的课堂上,我也有这个:
function display_planner(){
?>
<div class="planner">
<div class="calendar">
<div class="calendar-header">
<div class="headerWrapper">
<a class="btn btn-prev previousYear">
<i class="icon-angle-left"></i>
</a>
<span class="currentYear">July</span>
<a class="btn btn-next nextYear">
<i class="icon-angle-right"></i>
</a>
</div>
<div class="headerWrapper">
<a class="btn btn-prev previousMonth">
<i class="icon-angle-left"></i>
</a>
<span class="currentMonth"></span>
<a class="btn btn-next nextMonth">
<i class="icon-angle-right"></i>
</a>
</div>
</div>
</div>
</div>
<?php
}
所以,当我刷新页面时,它会将多个事件侦听器放置到上个月/年和下个月/年,正如我所说的。但是我有太多的javascript代码,它们也会生成我的日历,通过javascript,它只会添加一次。