Hi there, I’d like to prevent auto moderation for particular activity posts, but when I use this it doesn’t work
remove_action( ‘bp_activity_posted_update’, ‘on_activity_post’) , 10, 3 );
I can see that it is because the hook is called within the class, within a namespace, but I cant quite figure out how to target it.
Do you have any tips on how to remove this?
Thanks!
Hi Nick,
Do you want to disable it for all activity updates? If yes, Please visit Dashboard->Moderation->Settings-> untick BuddyPress ActivityIf no, Please help me understand better.
Thank you
BrajeshNo, I only want to disable it for very particular activity updates. I have all the conditional code that I need, but can’t figure out how to do remove_action because of the namespace/class structure. I know that you can sometimes do something like
$myclass = new Class
remove_action(‘hook’, array($myclass, ‘function’),10);But I can’t figure out how to even get the variable that contains the instance of the class.
Or, if it were a public static function, it would be possible to do something like:
remove_action(‘hook’, array(‘ClassName’, ‘function’),10);
Any suggestions would be appreciated!
Hi Nick,
We do not keep the instance or use singleton, so you won’t be able to unhook.That’s why we have added the option to disable it.
Here is the code that you might use
add_filter( 'bpmts_is_item_reportable', function ( $is_reportable, $item_type, $item_id ){ if( 'bp_activity' != $item_type ) { return $is_reportable; } // $item_id is activity id. // do something with it and set the $is_reportable to false to skip the item. return $is_reportable; }, 10, 4);
If you update the $is_reportable to false for some activity type, It won’t be put in auto moderation.
There is a side effect though. It will mark that activity type non reportable and user’s won’t be able to report it.
A solution that I see is to use a similar filter for disabling auto moderation by type.We will be certainly adding it in next update. For the time being, Please use the above code(and adapat as you need).
Regards
BrajeshThanks very much! I’ll give that a try.
Though as it turns out, I found this code which worked nicely! I’m sure it’ll be a good function to just have as a general utility snippet on my site.
function remove_class_action ($action,$class,$method) { global $wp_filter ; if (isset($wp_filter[$action])) { $len = strlen($method) ; foreach ($wp_filter[$action] as $pri => $actions) { foreach ($actions as $name => $def) { if (substr($name,-$len) == $method) { if (is_array($def['function'])) { if (get_class($def['function'][0]) == $class) { if (is_object($wp_filter[$action]) && isset($wp_filter[$action]->callbacks)) { unset($wp_filter[$action]->callbacks[$pri][$name]) ; } else { unset($wp_filter[$action][$pri][$name]) ; } } } } } } } }
Hi Nick,
Thank you for the reply.I will not recommend using the suggested stackexchange approach. It is a hack and you should avoid such hacks as they may break in future.
Regards
Brajesh
You must be logged in to reply to this topic.