Make WordPress Core

Ticket #29500: 29500.1.diff

File 29500.1.diff, 1.8 KB (added by MikeHansenMe, 10 years ago)
  • tests/phpunit/tests/export/functions.export.php

     
    4141                throw new Exception( 'baba' );
    4242        }
    4343}
     44
     45
     46
     47class Test_Export_Filter extends WP_UnitTestCase {
     48 
     49    public function setUp() {
     50        require_once( ABSPATH . '/wp-admin/includes/export.php' );
     51    }
     52 
     53        /**
     54         * Always return test.xml
     55     * @return string
     56     */
     57        public function filename_filter( $filename ) {
     58                return 'test.xml';
     59        }
     60       
     61        /**
     62         * Test that get_export_filename() will return the filtered filname.
     63         */
     64        public function test_get_export_filename_returns_filtered_string() {
     65                add_filter( 'export_filename', array( $this, 'filename_filter' ) );
     66                $this->assertEquals( get_export_filename(), 'test.xml' );
     67        remove_filter( 'export_filename', array( $this, 'filename_filter' ) );
     68    }
     69}
     70 No newline at end of file
  • src/wp-admin/includes/export.php

     
    4040        do_action( 'export_wp', $args );
    4141
    4242        $sitename = sanitize_key( get_bloginfo( 'name' ) );
    43         if ( ! empty($sitename) ) $sitename .= '.';
     43        if ( ! empty( $sitename ) ) $sitename .= '.';
    4444        $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
     45        /**
     46         * Filter the export filename.
     47         *
     48         * @since 4.1.0
     49         *
     50         * @param string $filename The name of the file to export data.
     51         */
     52        $filename = apply_filters( 'export_filename', $filename );
    4553
    4654        header( 'Content-Description: File Transfer' );
    4755        header( 'Content-Disposition: attachment; filename=' . $filename );