Skip to content

Instantly share code, notes, and snippets.

@YuzuruSano
Created June 25, 2019 09:47
Show Gist options
  • Save YuzuruSano/e1561587c6105a5c4b150b75e69955e5 to your computer and use it in GitHub Desktop.
Save YuzuruSano/e1561587c6105a5c4b150b75e69955e5 to your computer and use it in GitHub Desktop.
class内でactionに追加されたメソッドを削除する / taxonomy expander利用時、最新バージョンでクイック編集が動作しないためactionを削除
<?php
/**
* クラス内で定義されたactionを削除する
*
* @param string $tag 削除したいfilter名
* @param string $class 削除したいメソッドを内容するclass名
* @param string $method 削除したいメソッド名
* @param intger $priority 優先度
* @return bool 削除の結果
*/
function remove_class_action($tag, $class = '', $method, $priority = null) : bool
{
global $wp_filter;
if (isset($wp_filter[$tag])) {
$len = strlen($method);
foreach ($wp_filter[$tag] as $_priority => $actions) {
if ($actions) {
foreach ($actions as $function_key => $data) {
if ($data) {
if (substr($function_key, -$len) == $method) {
if ($class !== '') {
$_class = '';
if (is_string($data['function'][0])) {
$_class = $data['function'][0];
} elseif (is_object($data['function'][0])) {
$_class = get_class($data['function'][0]);
} else {
return false;
}
if ($_class !== '' && $_class == $class) {
if (is_numeric($priority)) {
if ($_priority == $priority) {
//if (isset( $wp_filter->callbacks[$_priority][$function_key])) {}
return $wp_filter[$tag]->remove_filter($tag, $function_key, $_priority);
}
} else {
return $wp_filter[$tag]->remove_filter($tag, $function_key, $_priority);
}
}
} else {
if (is_numeric($priority)) {
if ($_priority == $priority) {
return $wp_filter[$tag]->remove_filter($tag, $function_key, $_priority);
}
} else {
return $wp_filter[$tag]->remove_filter($tag, $function_key, $_priority);
}
}
}
}
}
}
}
}
return false;
}
/**
* taxonomy expanderの影響でクイック編集が動作しないためactionを削除
*/
add_action('admin_init', function () {
remove_class_action('admin_head-edit.php', 'PS_Taxonomy_Expander', 'remove_inline_edit_post_js',10);
remove_class_action('load-edit.php', 'PS_Taxonomy_Expander', 'add_sc_inline_edit_js', 10);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment