admin管理员组文章数量:1130349
This is my first page of the plugin
<?php
/*
Plugin Name: guard_search plugin
Description: Search Plugon
Author: mazhar
*/
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url('admin-ajax.php' )));
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/css/jquery.formstyler.css');
wp_enqueue_style('jquery.formstyler');
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
wp_enqueue_style('jquery.formstyler');
wp_register_script('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/js/bootstrap.min.js');
wp_enqueue_script('prefix_bootstrap');
wp_register_style('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/css/bootstrap.min.css');
wp_enqueue_style('prefix_bootstrap');
add_action( 'wp_ajax_models_click', 'models_click');
add_action( 'wp_ajax_nopriv_models_click', 'models_click');
add_action( 'wp_ajax_reset_years', 'reset_years');
add_action( 'wp_ajax_nopriv_reset_years', 'reset_years');
This is my ajax.js where the problems lies where styler is undefined(problem) which is the part of jquery's formstyller plugin mentioned in my first page.
jQuery(document).ready(function() {
jQuery('input, select').styler({
selectSearch: true,
});
});
1) My first question is how will i use jquery in my first page.
2) My second question is if i may how can i transport jquery.formstyller plugin in my ajax.js.
This is my first page of the plugin
<?php
/*
Plugin Name: guard_search plugin
Description: Search Plugon
Author: mazhar
*/
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url('admin-ajax.php' )));
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/css/jquery.formstyler.css');
wp_enqueue_style('jquery.formstyler');
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
wp_enqueue_style('jquery.formstyler');
wp_register_script('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/js/bootstrap.min.js');
wp_enqueue_script('prefix_bootstrap');
wp_register_style('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/css/bootstrap.min.css');
wp_enqueue_style('prefix_bootstrap');
add_action( 'wp_ajax_models_click', 'models_click');
add_action( 'wp_ajax_nopriv_models_click', 'models_click');
add_action( 'wp_ajax_reset_years', 'reset_years');
add_action( 'wp_ajax_nopriv_reset_years', 'reset_years');
This is my ajax.js where the problems lies where styler is undefined(problem) which is the part of jquery's formstyller plugin mentioned in my first page.
jQuery(document).ready(function() {
jQuery('input, select').styler({
selectSearch: true,
});
});
1) My first question is how will i use jquery in my first page.
2) My second question is if i may how can i transport jquery.formstyller plugin in my ajax.js.
Share Improve this question asked Oct 30, 2018 at 7:39 mazttmaztt 1056 bronze badges1 Answer
Reset to default 1You will have to load jquery.formstyler first to use it in your ajax.js. You can add it as another dependancie like jquery itself.
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery', 'jquery.formstyler' ) );
Also you have a little syntax issue in:
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
It should be register script, not style. same with the line below wp_enqueue_style('jquery.formstyler');.
add as wp_enqueue_script('jquery.formstyler'); script instead as style!
This is my first page of the plugin
<?php
/*
Plugin Name: guard_search plugin
Description: Search Plugon
Author: mazhar
*/
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url('admin-ajax.php' )));
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/css/jquery.formstyler.css');
wp_enqueue_style('jquery.formstyler');
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
wp_enqueue_style('jquery.formstyler');
wp_register_script('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/js/bootstrap.min.js');
wp_enqueue_script('prefix_bootstrap');
wp_register_style('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/css/bootstrap.min.css');
wp_enqueue_style('prefix_bootstrap');
add_action( 'wp_ajax_models_click', 'models_click');
add_action( 'wp_ajax_nopriv_models_click', 'models_click');
add_action( 'wp_ajax_reset_years', 'reset_years');
add_action( 'wp_ajax_nopriv_reset_years', 'reset_years');
This is my ajax.js where the problems lies where styler is undefined(problem) which is the part of jquery's formstyller plugin mentioned in my first page.
jQuery(document).ready(function() {
jQuery('input, select').styler({
selectSearch: true,
});
});
1) My first question is how will i use jquery in my first page.
2) My second question is if i may how can i transport jquery.formstyller plugin in my ajax.js.
This is my first page of the plugin
<?php
/*
Plugin Name: guard_search plugin
Description: Search Plugon
Author: mazhar
*/
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery' ) );
wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url('admin-ajax.php' )));
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/css/jquery.formstyler.css');
wp_enqueue_style('jquery.formstyler');
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
wp_enqueue_style('jquery.formstyler');
wp_register_script('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/js/bootstrap.min.js');
wp_enqueue_script('prefix_bootstrap');
wp_register_style('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/css/bootstrap.min.css');
wp_enqueue_style('prefix_bootstrap');
add_action( 'wp_ajax_models_click', 'models_click');
add_action( 'wp_ajax_nopriv_models_click', 'models_click');
add_action( 'wp_ajax_reset_years', 'reset_years');
add_action( 'wp_ajax_nopriv_reset_years', 'reset_years');
This is my ajax.js where the problems lies where styler is undefined(problem) which is the part of jquery's formstyller plugin mentioned in my first page.
jQuery(document).ready(function() {
jQuery('input, select').styler({
selectSearch: true,
});
});
1) My first question is how will i use jquery in my first page.
2) My second question is if i may how can i transport jquery.formstyller plugin in my ajax.js.
Share Improve this question asked Oct 30, 2018 at 7:39 mazttmaztt 1056 bronze badges1 Answer
Reset to default 1You will have to load jquery.formstyler first to use it in your ajax.js. You can add it as another dependancie like jquery itself.
wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery', 'jquery.formstyler' ) );
Also you have a little syntax issue in:
wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');
It should be register script, not style. same with the line below wp_enqueue_style('jquery.formstyler');.
add as wp_enqueue_script('jquery.formstyler'); script instead as style!
本文标签: jquery in wordpress plugin with depdendency
版权声明:本文标题:jquery in wordpress plugin with depdendency 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749221472a2335020.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论