0

I have no working code example for this, so I'm hoping to not get blasted for an an inappropriate question...

Being able to add append a timestamp to WP xml exports (WXR) would be useful.

I assume it's possible, so where might I begin?

I want to get the datestamp that forms part of the filename to also include the time (rather than just the year/month/day).

  • Do you mean a timestamp in the filename created, or a timestamp within the xml structure itself? – C C Oct 22 '16 at 15:37
  • @C C Thanks... Sorry, poorly worded question - now updated for clarity. – glvr Oct 22 '16 at 19:13
0

I don't think you need to do that, it's already there (if I understand the question correctly):

  • In the WXR file we get a timestamp like:

    that's generated with:

    <?php the_generator( 'export' ); ?>
    

    that calls get_the_generator() where the export case is:

    $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') 
        . '" created="'. date('Y-m-d H:i') . '" -->';
    

    It's possible to modify it or append to it via the get_the_generator_export filter.

  • Additionally the timestamp is added to the xml document with:

    <channel>
        ...
        <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
    
  • The generated export filename also contains a datestamp:

    $wp_filename = $sitename . 'wordpress.' . $date . '.xml';
    

Update

To modify the exported filename, one can use this filter:

/**
 * Filters the export filename.
 *
 * @since 4.4.0
 *
 * @param string $wp_filename The name of the file for download.
 * @param string $sitename    The site name.
 * @param string $date        Today's date, formatted.
 */
 $filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date );

Example:

Here we add the \TH-i-s part to the filename:

add_filter( 'export_wp_filename', function( $wp_filename, $sitename, $date )
{
    return sprintf( 
        '%swordpress.%s.xml',
        $sitename, 
        date( 'Y-m-d\TH-i-s' )
    );

}, 10, 3 ); 

This will generate a filename like:

sitename.wordpress.2016-10-22T19-26-07.xml

This will avoid a possible confusing download series like this one:

sitename.wordpress.2016-10-22.xml
sitename.wordpress.2016-10-22 (1).xml
sitename.wordpress.2016-10-22 (2).xml
sitename.wordpress.2016-10-22 (3).xml
...

Hope you can adjust this to your needs!

  • thanks. Sorry, poorly worded question - now updated for clarity. – glvr Oct 22 '16 at 19:13
  • I updated the answer @gulliver – birgire Oct 22 '16 at 19:26
  • Thanks. Appreciated. It improves the default WP timestamp, by providing immediate visual info on time-of-creation. Better than my previous situation of confusion when multiple exports are done on the same day. – glvr Oct 23 '16 at 7:17
  • I agree with you, that it's annoying to have the sitename.wordpress.2016-10-22.xml and then sitename.wordpress.2016-10-22 (1).xml and sitename.wordpress.2016-10-22(2).xml etc for downloads the same day @gulliver – birgire Oct 23 '16 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.