Make WordPress Core

Ticket #29500: exportnamefilter.diff

File exportnamefilter.diff, 1.9 KB (added by alfreddatakillen, 10 years ago)

Adding a export_filename filter. And a unit test.

  • src/wp-admin/includes/export.php

    diff --git src/wp-admin/includes/export.php src/wp-admin/includes/export.php
    index 397e9e7..24d24b2 100644
     
    1616define( 'WXR_VERSION', '1.2' );
    1717
    1818/**
     19 * Returns the export download filename.
     20 */
     21function get_export_filename() {
     22        $sitename = sanitize_key( get_bloginfo( 'name' ) );
     23        if ( ! empty($sitename) ) $sitename .= '.';
     24        $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
     25        $filename = apply_filters( 'export_filename', $filename );
     26        return $filename;
     27}
     28
     29/**
    1930 * Generates the WXR export file for download
    2031 *
    2132 * @since 2.1.0
    function export_wp( $args = array() ) { 
    3950         */
    4051        do_action( 'export_wp', $args );
    4152
    42         $sitename = sanitize_key( get_bloginfo( 'name' ) );
    43         if ( ! empty($sitename) ) $sitename .= '.';
    44         $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
     53        $filename = get_export_filename();
    4554
    4655        header( 'Content-Description: File Transfer' );
    4756        header( 'Content-Disposition: attachment; filename=' . $filename );
  • new file tests/phpunit/tests/export.php

    diff --git tests/phpunit/tests/export.php tests/phpunit/tests/export.php
    new file mode 100644
    index 0000000..ed56214
    - +  
     1<?php
     2
     3/**
     4 * Test Export functions
     5 *
     6 * @group wpdb
     7 */
     8class Tests_Export extends WP_UnitTestCase {
     9
     10        public function setUp() {
     11                require_once( ABSPATH . '/wp-admin/includes/export.php' );
     12        }
     13
     14        /**
     15         * Always return test.xml
     16         * @return string
     17         */
     18        public function filename_filter( $filename ) {
     19                return 'test.xml';
     20        }
     21
     22        /**
     23         * Test that get_export_filename() will return the filtered filname.
     24         */
     25        public function test_get_export_filename_returns_filtered_string() {
     26                add_filter( 'export_filename', array( $this, 'filename_filter' ) );
     27                $this->assertEquals( get_export_filename(), 'test.xml' );
     28                remove_filter( 'export_filename', array( $this, 'filename_filter' ) );
     29        }
     30
     31}