Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 34
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
wpcom_register_export_media_files_page
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
wpcom_render_export_media_files_page
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Export Media Files feature for WordPress.com sites.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8/**
9 * Registers the Export Media Files admin page.
10 */
11function wpcom_register_export_media_files_page() {
12    add_submenu_page(
13        'tools.php',
14        __( 'Export Media Files', 'jetpack-mu-wpcom' ),
15        __( 'Export Media Files', 'jetpack-mu-wpcom' ),
16        'export',
17        'export-media-files',
18        'wpcom_render_export_media_files_page'
19    );
20}
21add_action( 'admin_menu', 'wpcom_register_export_media_files_page', 8 );
22
23/**
24 * Renders the Export Media Files admin page.
25 */
26function wpcom_render_export_media_files_page() {
27    if ( ! current_user_can( 'export' ) ) {
28        wp_die( esc_html__( 'Sorry, you are not allowed to export content for this site.', 'jetpack-mu-wpcom' ) );
29    }
30
31    // Get the site ID
32    $site_id = get_current_blog_id();
33
34    // Check if this is an Atomic site
35    $is_atomic = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM );
36
37    // For Atomic sites, point to WordPress.com backup instead of wp-admin VaultPress
38    if ( $is_atomic ) {
39        // Get the site domain for the WordPress.com backup URL
40        $site_domain = wp_parse_url( home_url(), PHP_URL_HOST );
41        $backup_url  = 'https://wordpress.com/backup/' . $site_domain;
42        ?>
43        <div class="wrap">
44            <h1><?php esc_html_e( 'Export Media Files', 'jetpack-mu-wpcom' ); ?></h1>
45            <p><?php esc_html_e( 'Export your site’s media files and manage backups from Jetpack VaultPress Backup.', 'jetpack-mu-wpcom' ); ?></p>
46            <a href="<?php echo esc_url( $backup_url ); ?>" class="button button-primary"><?php esc_html_e( 'Go to Backup', 'jetpack-mu-wpcom' ); ?></a>
47        </div>
48        <?php
49        return;
50    }
51
52    // Load the WPCOM media export library
53    require_once WP_CONTENT_DIR . '/lib/wpcom-media-export.php';
54
55    // Get media export URL for Simple sites
56    $media_export_url = wpcom_get_media_export_url( $site_id );
57    ?>
58    <div class="wrap">
59        <h1><?php esc_html_e( 'Export Media Files', 'jetpack-mu-wpcom' ); ?></h1>
60
61        <?php if ( $media_export_url ) : ?>
62            <p><?php esc_html_e( 'Download all the media library files (images, videos, audio, and documents) from your site.', 'jetpack-mu-wpcom' ); ?>
63            <a href="https://wordpress.com/support/export-your-media-library/" target="_blank" data-target="wpcom-help-center"><?php esc_html_e( 'Learn more', 'jetpack-mu-wpcom' ); ?></a></p>
64
65            <p><a href="<?php echo esc_url( $media_export_url ); ?>" class="button button-primary"><?php esc_html_e( 'Download', 'jetpack-mu-wpcom' ); ?></a></p>
66
67            <p><?php esc_html_e( 'To export your entire site content—including posts and pages—please use the', 'jetpack-mu-wpcom' ); ?>
68            <a href="<?php echo esc_url( admin_url( 'export.php' ) ); ?>"><?php esc_html_e( 'Export tool', 'jetpack-mu-wpcom' ); ?></a>.</p>
69        <?php else : ?>
70            <p><?php esc_html_e( 'Your site does not have any media files to export.', 'jetpack-mu-wpcom' ); ?></p>
71        <?php endif; ?>
72    </div>
73    <?php
74}