Title: cannot &#8220;remove_action&#8221;
Last modified: October 29, 2016

---

# cannot “remove_action”

 *  Resolved [formless](https://wordpress.org/support/users/formless/)
 * (@formless)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/)
 * Hi!
 * First, Thank you for your great plugin!
 * I wanna remove some actions when DOING_CRON is true.
    But the code below did 
   not work on ‘init’ hook with priority of 1000.
 * `remove_action('add_post_meta', array( WpSecurityAuditLog::GetInstance()->sensors-
   >HookEvents(), 'EventPostMetaCreated' ), 10, 3);`
 * Any hint or clue is appreciated.
    Thanks in advance!
 * Regards

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [WPWhiteSecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * (@wpwhitesecurity)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8375073)
 * Hello formless,
 * Thank you for using the plugin.
 * First off, what do you want to do?
 *  Thread Starter [formless](https://wordpress.org/support/users/formless/)
 * (@formless)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8375627)
 * Hi [@wpwhitesecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * Thank you for your reply!
    and sorry for my bad explanation.
 * I am running a cronjob (wp-cron) which does bluk delete using ‘wp_delete_post’.
   
   It deletes 100 and more posts at once, then all the ‘delete_post_meta’ logs are
   recorded by WSAL. But each post have nearly 50 post metas, so I wanna stop WSAL
   recording logs for deleting postmeta while cronjob is working.
 * I’ve tried these below.
    but they did not work.
 * **Pattern A -> not work**
 *     ```
       add_action('init', 'stop_WSAL_for_cronjob', 1000);
       function stop_WSAL_for_cronjob(){
       	if ( !defined( 'DOING_CRON' ) ){ return; }
       	remove_action('add_post_meta',  array( WSAL_Sensors_MetaData::HookEvents(), 'EventPostMetaCreated' ), 10, 3);
       	remove_action('update_post_meta', array( WSAL_Sensors_MetaData::HookEvents(), 'EventPostMetaUpdating' ), 10, 3);
       	remove_action('updated_post_meta', array( WSAL_Sensors_MetaData::HookEvents(), 'EventPostMetaUpdated'), 10, 4);
       	remove_action('deleted_post_meta', array( WSAL_Sensors_MetaData::HookEvents(),  'EventPostMetaDeleted'), 10, 4);
       }
       ```
   
 * **Pattern B -> not work**
 *     ```
       add_action('init', 'stop_WSAL_for_cronjob', 1000);
       function stop_WSAL_for_cronjob(){
       	if ( !defined( 'DOING_CRON' ) ){ return; }
       	remove_action('add_post_meta',  array( WpSecurityAuditLog::GetInstance()->sensors->HookEvents(), 'EventPostMetaCreated' ), 10, 3);
       	remove_action('update_post_meta', array( WpSecurityAuditLog::GetInstance()->sensors->HookEvents(), 'EventPostMetaUpdating' ), 10, 3);
       	remove_action('updated_post_meta', array( WpSecurityAuditLog::GetInstance()->sensors->HookEvents(), 'EventPostMetaUpdated'), 10, 4);
       	remove_action('deleted_post_meta', array( WpSecurityAuditLog::GetInstance()->sensors->HookEvents(),  'EventPostMetaDeleted'), 10, 4);
       }
       ```
   
 * I want to know the right way to remove_action().
 *  [WPWhiteSecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * (@wpwhitesecurity)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8381083)
 * Hi Formless,
 * You should use this type of code:
 *     ```
       add_action('init', 'stop_WSAL_action');
   
       function stop_WSAL_action()
       {
           if (class_exists('WpSecurityAuditLog')) {
               $sensors = WpSecurityAuditLog::GetInstance()->sensors->GetSensors();
               foreach ($sensors as $sensor) {
                   if (get_class($sensor) == "WSAL_Sensors_MetaData") {
                       remove_action('deleted_post_meta', array($sensor, 'EventPostMetaDeleted'), 10);
                   }
               }
           }
       }
       ```
   
 * Try it and let me know if you have any queries.
 *  Thread Starter [formless](https://wordpress.org/support/users/formless/)
 * (@formless)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8384877)
 * Hi [@wpwhitesecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * Thank you for the code.
    It worked perfect!
 *  [WPWhiteSecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * (@wpwhitesecurity)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8385389)
 * I am glad it worked for you and thank you for using our plugin. Would appreciate
   if you can spare a minute and [rate our plugin](https://wordpress.org/support/plugin/wp-security-audit-log/reviews/).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘cannot “remove_action”’ is closed to new replies.

 * ![](https://ps.w.org/wp-security-audit-log/assets/icon-256x256.png?rev=2961534)
 * [WP Activity Log](https://wordpress.org/plugins/wp-security-audit-log/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-security-audit-log/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-security-audit-log/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-security-audit-log/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-security-audit-log/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-security-audit-log/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [WPWhiteSecurity](https://wordpress.org/support/users/wpwhitesecurity/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-remove_action/#post-8385389)
 * Status: resolved