中定義所以我有這個插件代碼WordPress的 - 刪除動作插件
class WC_List_Grid {
public function __construct() {
add_action('wp' , array($this, 'setup_gridlist') , 20);
}
function setup_gridlist() {
add_action('woocommerce_before_shop_loop', array($this, 'gridlist_toggle_button'), 30);
}
function gridlist_toggle_button() {?>
<nav class="gridlist-toggle">
<a href="#" id="grid" title="<?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-grid-view"></span> <em><?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?></em></a>
<a href="#" id="list" title="<?php _e('List view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-exerpt-view"></span> <em><?php _e('List view', 'woocommerce-grid-list-toggle'); ?></em></a>
</nav>
<?php }
}
我想改變gridlist_toggle_button功能的內容。 這是我計劃如何更改該功能的內容。就像使用與原始HTML幾乎相同的html編寫另一個函數,但是我的更改有點不同。像
add_action('woocommerce_before_shop_loop','new_gridlist_toggle_button')
function new_gridlist_toggle_button() {?>
<nav class="gridlist-toggle">
<a href="#" class="grid-view" title="<?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-grid-view"></span> <em><?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?></em></a>
<a href="#" class="list-view" title="<?php _e('List view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-exerpt-view"></span> <em><?php _e('List view', 'woocommerce-grid-list-toggle'); ?></em></a>
</nav>
<?php }
}
個什麼東西,我不會改變插件文件直接
對於這一點,我想刪除其相關的行動。
add_action('woocommerce_before_shop_loop', array($this, 'gridlist_toggle_button'), 30);
這樣我可以使用我自己的代碼。但我似乎無法刪除此操作。到目前爲止,我已經嘗試過了。
方法1:
global $WC_List_Grid ;
remove_action('woocommerce_before_shop_loop', array($WC_List_Grid, 'gridlist_toggle_button'), 100);
方法2:
function remove_plugin_actions(){
global $WC_List_Grid ;
remove_action('woocommerce_before_shop_loop', array($WC_List_Grid, 'gridlist_toggle_button'), 100);
}
add_action('init','remove_plugin_actions');
方法3
remove_action('woocommerce_before_shop_loop', array('WC_List_Grid', 'gridlist_toggle_button'), 100);
他們都不似乎工作。
經過一番頭腦風暴,我認爲可能有兩個原因。
- 它不工作,因爲我想刪除的操作不直接附加到鉤子上。其行動內的行動。
- 我想通過functions.php阻止gridlist_toggle_button的輸出。但是,如果插件在functions.php之前加載,那麼被阻止的函數已被調用,因此它總是顯示輸出。
我根本不適合OOP。有人可以幫我嗎?
請檢查我更新的問題。而且我已經嘗試過這種方法,它也無法工作。 –
你試過優先考慮30還是100?你有沒有嘗試過沒有優先權? – 2016-04-15 07:25:47
嘗試所有,30和100,並沒有優先權。我認爲你的觀點「插件正在加載之前functions.php」是原因。因爲我試圖阻止gridlist_toggle_button的輸出。但正如你所建議的,如果插件在functions.php之前加載,那麼該函數已經被調用,因此它總是顯示輸出。 –