• Resolved Greg Marshall

    (@timeassistant)


    Hello,

    I like your plugin, it’s very useful, but I have a small issue I’d like to query.

    I also use this plugin: https://en-gb.www.ads-software.com/plugins/post-smtp/

    I have it’s email log enabled, and it has a limit of x entries. Everytime a form is submitted the email is passed via the SMTP plugin. An entry is created in it’s log and while the email log is full an entry is deleted at the same time. Each of these is logged by your plugin. I don’t mind the created entry as that shows me the form was submitted and an email generated etc, however, I would like to exclude the deleted entry from your plugin.

    I’ve pasted some of the meta data below incase that can be used to filter it out?

    Key	Value
    id	18083
    logger	SimplePostLogger
    level	info
    date	2023-06-07 11:28:50
    message	Deleted {post_type} "{post_title}"
    initiator	wp_user
    context_message_key	post_deleted
    post_id	2949
    post_type	postman_sent_mail
    post_title	Wordfence activity for Monday, 29th of November, 2021 on domain.com
    _message_key	post_deleted
    _user_id	#
    _user_login	name
    _user_email	##@###.co.uk
    _server_remote_addr	xxx.xxx.xxx.xxx
    _server_http_referer	#
    

    I would think post type and message key would be suitable to exclude these if you could assist me with a function or filter please?

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author eskapism

    (@eskapism)

    There is a filter simple_history/log/do_log that can be used to disable logging of a specific message for a specific logger.

    In your case the code to add in functions.php or similar would be something like this I think (not tested):

    <?php
    
    // Disable logging of posts deleted by postman.
    add_filter(
      'simple_history/log/do_log',
      function ($doLog, $level, $message, $context, $logger) {
        // Bail if not correct logger.
        if ($logger->get_slug() !== 'SimplePostLogger') {
          return $doLog;
        }
    
        // Bail if not correct message.
        if ($message !== 'post_deleted') {
          return $doLog;
        }
    
        // Bail if not our wanted post type.
        if (isset($context['post_type']) && $context['post_type'] !== 'postman_sent_mail') {
          return $doLog;
        }
    
        // Do not log this message since it's from 'SimplePostLogger' with message key 'post_deleted' and the deleted post type was 'postman_sent_mail'.
        return false;
      },
      10,
      5
    );
    

    Thread Starter Greg Marshall

    (@timeassistant)

    Thanks for the help,

    I had to change it every so slightly to make it work but it does appear to be working

        if ($logger->slug !== 'SimplePostLogger') {
          return $doLog;
        }
        // Bail if not correct message.
        if ($context['_message_key'] !== 'post_deleted') {
          return $doLog;
        }

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to exclude specific entries’ is closed to new replies.