• Resolved formless

    (@formless)


    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)
  • Plugin Author WPWhiteSecurity

    (@wpwhitesecurity)

    Hello formless,

    Thank you for using the plugin.

    First off, what do you want to do?

    Thread Starter formless

    (@formless)

    Hi @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().

    Plugin Author WPWhiteSecurity

    (@wpwhitesecurity)

    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

    (@formless)

    Hi @wpwhitesecurity

    Thank you for the code.
    It worked perfect!

    Plugin Author WPWhiteSecurity

    (@wpwhitesecurity)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘cannot “remove_action”’ is closed to new replies.