• Resolved byronj

    (@byronj)


    I am trying to convert the meta_value of one of my meta_keys from Epoch time to a date string. I cannot seem to access the object of the selected meta fields that I choose within the export screen.

    Is it possible to filter this data prior to exporting? I also do not want to update the value within the database itself, therefore I’m trying to avoid using update_user_meta().

    Here is the function I have created thus far, though I realize “export_user_data_user_field” is probably the wrong object.

    function format_expire_date($date) {
    
        $users = get_users();
        $user_group = array(); 
    
        foreach ( $users as $user ) {
             $user_id = $user->ID;
             $key = '_expire_user_date';
             $single = true;
             $epoch = get_user_meta( $user_id, $key, $single ); 
    
             $formatted_date = date('d-m-Y H:i:s', $epoch);
    
            $date->set( 'meta_key', '_expire_user_date' );
            $date->set( 'meta_value', $formatted_date );
    
        } 
    
        return $date;
    
    }
    add_filter('export_user_data_user_field', 'format_expire_date');

    https://ww.wp.xz.cn/plugins/export-user-data/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author qstudio

    (@qlstudio)

    This proposed filter would need to match the field name in order to work – and would need to take into consideration other aspects such as BP fields and time since update fields – but it’s possible.

    Another route would be to filter the returned value from the function used to grab the field data – which might be get_user_meta ( via get_metadata ) – but you’d need to dig into the filters available to see if that could work.

    Thread Starter byronj

    (@byronj)

    Thanks for the quick response.

    I see that “export_user_data_user_field” is used to filter the standard user fields, though which filter will allow me to modify the select custom meta fields to be exported?

    The filter that appears to allow access to these fields is “export_user_data_special_fields”, though it does not return the custom meta keys that I select to be exported.

    Plugin Author qstudio

    (@qlstudio)

    The existing filters only deal with filtering the fields to be used, not altering the value of those fields before export – that was never part of the plan for this plugin.

    I would look into how you can filter teh values returned from top level WP functions to find a way to filter the values, as we do not make any direct calls to the database to get data.

    Thread Starter byronj

    (@byronj)

    Thanks again for the quick responses.

    I ended up creating a new meta_key that stores the re-formatted version of the timestamp. With this approach I can allow the client to export the formatted field without tampering with the original epoch field.

    Great export plugin, the best I have seen for exporting user data.

    Plugin Author qstudio

    (@qlstudio)

    Good news and a solid solution by the sounds of it.

    Q

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Convert Epoch time using filters’ is closed to new replies.