单击时修改Wordpress样式

时间:2018-07-23 14:18:21

标签: jquery css wordpress button admin

我尝试使后端的o按钮更改前端的样式/元素(切换电话号码)。 我写了这个:

/* Your code to add menu on admin bar */

add_action('admin_bar_menu', 'add_item', 100);

function add_item( $admin_bar ){
global $pagenow;
$admin_bar->add_menu( array( 'id'=>'tel-switch','title'=>'1234567','href'=>'#','meta' => array('class' => 'tel-switch') ) );
}

/* Here you trigger the ajax handler function using jQuery */

add_action( 'admin_footer', 'tel_switch_js' );
add_action( 'wp_footer', 'tel_switch_js' );

function tel_switch_js() { ?>
  <script type="text/javascript" >
   jQuery("li#wp-admin-bar-tel-switch .ab-item").on( "click", function() {
        var element = document.getElementById("wp-admin-bar-tel-switch");
        element.classList.toggle("nummer-active");

        var element = document.getElementById("header-tel-switch");
        element.classList.toggle("nummer-active");

    /* since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php */
    jQuery.post(ajaxurl, data, function(response) {
       alert( response );
    });

  });
</script> <?php
}

/* Here you hook and define ajax handler function */

add_action( 'wp_ajax_tel_switch', 'tel_switch_callback' );

function tel_switch_callback() {
 global $wpdb;
 $response = "Alternative Telephone Number aktive";
 echo $response;
 wp_die(); /* this is required to terminate immediately and return a proper response */
} 

到目前为止,上帝,但是我该如何保存更改(备用电话号码),以便在刷新任何页面后它都不会更改?只能由管理员手动激活和取消激活。

0 个答案:

没有答案