2017-09-22 44 views
0

我有這個按鈕WordPress的功能沒有被執行

<button class="button1" id="myid1">Activate</button> 

,當用戶點擊這個按鈕,然後這個jQuery執行,我們也越來越警惕。

jQuery(document).ready(function($) { 
$(\'#myid1\').click(function(e){ 
     e.preventDefault(); 
     var $el = $(this).parents().eq(1); 
     remove_element($el); 
     var data1 = { 
     action: \'enable_function1\', 
     }; 
     $.post(ajaxurl, data1, function(response) { 
      alert(\'Congratulations,Activated' \'); 
     });    }); 
}); 

這裏是我的WordPress功能

function enable_function1() { 
    add_filter('mod_rewrite_rules', 'someotherfunction'); 
    } 

但沒有什麼是被mod_rewrite_rules

回答

3

在WordPress後臺,你需要做到這一點寫入。該行動不是函數的名稱,它的使用WordPress的識別功能,可以執行

function your_function() { 
    add_filter('mod_rewrite_rules', 'someotherfunction'); 
    } 

add_action("wp_ajax_enable_function1", "your_function"); 

add_action("wp_ajax_nopriv_enable_function1", "your_function"); 

檢查此瞭解更多詳情: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

+0

這是什麼爲.wp_ajax_nopriv_enable_function1 – swetlana

+0

它的使用(對於沒有登錄的用戶)在我發送的鏈接中閱讀註釋並結束 –

+0

不能正常工作............. – swetlana