Forum Replies Created

Viewing 6 replies - 31 through 36 (of 36 total)
  • Thread Starter farnely

    (@farnely)

    I don’t see why a timestamp would be handled differently either!

    I know the function is being called because ‘field-meta-updated’ values are created when other non-date fields are changed. Following your suggestion, I changed my snippet to include a single line field as well (custom-field-2) and added various statements using error_log(). I then changed both fields on the frontend, both fields updated correctly in the database I’ve noted the results within the code so it’s hopefully clearer what happened.

    add_action('updated_post_meta','func_meta_changed', 10, 4);
    function func_meta_changed($meta_id, $post_id, $meta_key, $meta_value) {
    
        $the_keys = array ($meta_key);
        
        foreach ( $the_keys as $each ) {
            error_log('meta changed: ' . $each, 1, '[email protected]');
            //OUTCOME: report created for custom-field-2 (and an expected hidden meta key I have no control over)
            //COMMENT: report should have been created for custom-field-1 too
        }
        
        $type = get_post_type( $post_id );
        if ( empty( $type) ) {
            error_log("post type not available", 1, "[email protected]");
            //OUTCOME: no report generated
        }
            
        if ( $type  == 'my-custom-post' ) {
                
            if ('custom-field-1' != $meta_key) {
                add_post_meta($post_id, 'field-meta-updated', 'Field 1');
                error_log("custom-field-1 not meta_key", 1, "[email protected]");
                //OUTCOME: report generated
            }
    
            if ('custom-field-1' == $meta_key) {
                add_post_meta($post_id, 'field-meta-updated', 'Field 1');
                error_log("custom-field-1 change recorded", 1, "[email protected]");
                //OUTCOME: no report generated
            }
    
            if ('custom-field-2' != $meta_key) {
                add_post_meta($post_id, 'field-meta-updated', 'Field 2');
                error_log("custom-field-2 not meta_key", 1, "[email protected]");
                //OUTCOME: report generated
                //COMMENT: clearly not right!
            }
    
            if ('custom-field-2' == $meta_key) {
                add_post_meta($post_id, 'field-meta-updated', 'Field 2');
                error_log("custom-field-2 change recorded", 1, "[email protected]");
                //OUTCOME: report generated
            }
        }
    }

    I think my logic for the error_log() statements is correct but don’t understand why I’m getting confirmation that custom-field-1 (the date field) was changed AND that it wasn’t yet the data for custom-field-2 is correct. Can you see anything that might be skewing the error reports?

    I’d appreciate any further insight or suggestions you might have to get to the bottom of this.

    Thread Starter farnely

    (@farnely)

    Thank you for clarifying and I appreciate your swift response.

    Thread Starter farnely

    (@farnely)

    You can ignore this; duff info on stackflow – sorry!

    Thread Starter farnely

    (@farnely)

    I have an update for you: at the time the email was sent during the manual scan, a PHP notice appeared in my debug.log starting “PHP Notice: Trying to get property ‘access_token’ of non-object in” and referring to a file in my SMTP plugin. I’m not getting any notices like this when other plugins send emails. Hope this helps.

    Thread Starter farnely

    (@farnely)

    Well realtime would be awesome but I’d be very happy with hourly scans. Do you have a timeframe for implementing better scanning options?

    Thread Starter farnely

    (@farnely)

    Thanks for coming back to me.

    I read about the plugin here https://www.wpwhitesecurity.com/wordpress-plugins/website-file-changes-monitor/ so because it says “get alerted whenever files are added, modified or deleted” it was a bit of a surprise to then find that actually the alert is at the most a daily one.

    I would really like to have the ability to run scans multiple times a day, maybe even hourly (for obvious reasons!). Is this something you foresee happening?

Viewing 6 replies - 31 through 36 (of 36 total)