bonny / WordPress-Simple-History

🔍🕵️‍♀️ WordPress audit log that track user changes in WordPress admin using a nice activity feed.
https://simple-history.com
311 stars 68 forks source link

See if filter `simple_history/log_query_inner_where` can be brought back #455

Closed bonny closed 3 months ago

bonny commented 3 months ago

This was probably removed when doing the big sql query rewrite https://github.com/bonny/WordPress-Simple-History/issues/409

Related: #341

bonny commented 3 months ago

The format has changed, so the inner query can be modified with a new filter:

// Modify query so it returns nothing.
add_filter('simple_history/log_query_inner_where_array', function($inner_where, $args) {
  $inner_where[] = "1 = 0";
  return $inner_where;
}, 10, 2);
1ucay commented 3 months ago

Nice, thank you, working ok!

add_filter( 'simple_history/log_query_inner_where_array', function( $inner_where, $args ) {

    $simple_history = \Simple_History\Simple_History::get_instance();
    $contexts_table_name = $simple_history->get_contexts_table_name();

    $inner_where[] = sprintf(
        'id IN ( SELECT history_id FROM %1$s AS c WHERE c.key = "_user_id" AND c.value != "%2$s" )',
        $contexts_table_name,
        1
    );

    $inner_where[] = sprintf(
        'id IN ( SELECT history_id FROM %1$s AS c WHERE c.key = "post_type" AND c.value IN ("%2$s") )',
        $contexts_table_name,
        implode( '","', array( 'post', 'page', 'event' ) )
    );

    return $inner_where;
}, 10, 2 );