Thank you for your snippet 🙂

It seems that when you edit a post and click "Update" or "Save" it's not detected as an admin's action if you are inside `rest_pre_dispatch` hook (I think inside every hook before `init`)

In my case I've added before your first `if` these lines

```PHP
$requestFromBackend = is_rest() && strpos($admin_url, '/wp-admin/') > 0 && !strpos($admin_url, '/wp-admin/admin-ajax.php');

if($requestFromBackend) {
return true;
}
```

and add this function
```PHP
function is_rest() {
$prefix = rest_get_url_prefix( );
if (defined('REST_REQUEST') && REST_REQUEST // (#1)
|| isset($_GET['rest_route']) // (#2)
&& strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0)
return true;
// (#3)
global $wp_rewrite;
if ($wp_rewrite === null) $wp_rewrite = new WP_Rewrite();

// (#4)
$rest_url = wp_parse_url( trailingslashit( rest_url( ) ) );
$current_url = wp_parse_url( add_query_arg( array( ) ) );
return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
}
```