Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. /**
  2. * Add custom columns to admin comments grid
  3. * * Rate that user set.
  4. */
  5. add_filter( 'manage_edit-comments_columns', function( $default ) {
  6. $columns['smr_comment_rate'] = __( 'Rate', 'txtdmn' );
  7.  
  8. return array_slice( $default, 0, 3, true ) + $columns + array_slice( $default, 2, NULL, true );
  9. });
  10.  
  11. /**
  12. * Remove an object filter.
  13. *
  14. * @param string $tag Hook name.
  15. * @param string $class Class name. Use 'Closure' for anonymous functions.
  16. * @param string|void $method Method name. Leave empty for anonymous functions.
  17. * @param string|int|void $priority Priority
  18. * @return void
  19. */
  20. function remove_object_filter( $tag, $class, $method = NULL, $priority = NULL ) {
  21. $filters = $GLOBALS['wp_filter'][ $tag ];
  22. if ( empty ( $filters ) ) {
  23. return;
  24. }
  25. foreach ( $filters as $p => $filter ) {
  26. if ( ! is_null($priority) && ( (int) $priority !== (int) $p ) ) continue;
  27. $remove = FALSE;
  28. foreach ( $filter as $identifier => $function ) {
  29. $function = $function['function'];
  30. if (
  31. is_array( $function )
  32. && (
  33. is_a( $function[0], $class )
  34. || ( is_array( $function ) && $function[0] === $class )
  35. )
  36. ) {
  37. $remove = ( $method && ( $method === $function[1] ) );
  38. } elseif ( $function instanceof Closure && $class === 'Closure' ) {
  39. $remove = TRUE;
  40. }
  41. if ( $remove ) {
  42. unset( $GLOBALS['wp_filter'][$tag][$p][$identifier] );
  43. }
  44. }
  45. }
  46. }
  47.  
  48. // remove a static method
  49. remove_object_filter( 'a_filter_hook', 'AClass', 'a_static_method', 10 );
  50.  
  51. // remove a dynamic method
  52. remove_object_filter( 'a_filter_hook', 'AClass', 'a_dynamic_method', 10 );
  53.  
  54. // remove a closure
  55. remove_object_filter( 'a_filter_hook', 'Closure', NULL, 10 );
  56.  
  57. add_filter( 'manage_edit-comments_columns', function( $default ) {
  58. unset( $default['smr_comment_rate'] );
  59.  
  60. return $default;
  61. }, 11, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement