admin管理员组文章数量:1332395
I have widget like this
class Test extends WP_Widget
{
public function __construct()
{
parent::__construct(
'proreco',
__('Product recommender', 'password_domain'),
array(
'customize_selective_refresh' => true,
)
);
}
// The widget form (for the backend )
public function form($instance)
{
// Set widget defaults
$defaults = array(
'email' => '',
'password' => '',
'limit' => '',
'date' => ''
);
// Parse current settings with defaults
extract(wp_parse_args(( array )$instance, $defaults)); ?>
<p>
<label for="<?php echo esc_attr($this->get_field_id('email')); ?>"><?php _e('Email', 'email_domain'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('email')); ?>"
name="<?php echo esc_attr($this->get_field_name('email')); ?>" type="email"
value="<?php echo esc_attr($email); ?>"/>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('password')); ?>"><?php _e('Password:', 'password_domain'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('password')); ?>"
name="<?php echo esc_attr($this->get_field_name('password')); ?>" type="password"
value="<?php echo esc_attr($password); ?>"/>
</p>
<p id="TEST"></p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>"><?php _e('Limit', 'limit_domain'); ?></label>
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>"
name="<?php echo esc_attr($this->get_field_name('limit')); ?>" type="number"
value=""/>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('date')); ?>">Date updated: </label>
<?php
echo esc_attr($date);
?>
</p>
<p>
<button onclick="ExportData()" type="button">Export database</button>
</p>
<script>
function ExportData() {
var data = {
'action': 'export_database', // the name of your PHP function!
};
jQuery.ajax({
type: "POST",
url: ajaxurl,
data: data,
dataType: 'json',
error: function (data) {
alertify.notify(data.errors, 'error', 5);
}
});
}
</script>
<?php }
public function update($new_instance, $old_instance)
{
}
public function widget($args, $instance)
{
}
}
You will se that i have ajax function export_database that use to proceed some data. Is possible to update widget properties from this custom ajax function, not just submitting the form? Here is example of my ajax funcion
function export_database()
{
// HERE I HAVE TO UPDATE WIDGET PROPERTIES
wp_die();
}
add_action('wp_ajax_export_database', 'export_database'); // for admins only
add_action('wp_ajax_nopriv_export_database', 'export_database'); // for ALL users
本文标签: pluginsUpdate widget values from ajax function
版权声明:本文标题:plugins - Update widget values from ajax function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742283218a2446478.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论