10up / windows-azure-storage

Use the Microsoft Azure Storage service to host your website's media files.
https://wordpress.org/plugins/windows-azure-storage/
BSD 2-Clause "Simplified" License
62 stars 46 forks source link

moving assets to azure storage #189

Open carlituxman opened 1 year ago

carlituxman commented 1 year ago

Is your enhancement related to a problem? Please describe.

I just trying moving uploads folder from existing wordpress to azure storage. But _wp_attached_file posts has a relative path, then wp attach site url

Then you can force moved previous uploads:

Now:

function windows_azure_storage_wp_get_attachment_url( $url, $post_id ) {
    $media_info = get_post_meta( $post_id, 'windows_azure_storage_info', true );

    if ( ! empty( $media_info ) && isset( $media_info['url'] ) ) {
        return $media_info['url'];
    } else {
        return $url;
    }
}

Designs

No response

Describe alternatives you've considered

function windows_azure_storage_wp_get_attachment_url( $url, $post_id ) {
    $media_info = get_post_meta( $post_id, 'windows_azure_storage_info', true );

    if ( ! empty( $media_info ) && isset( $media_info['url'] ) ) {
        return $media_info['url'];
    } else {
            // **_---> RETURN base_url from AZURE with moved image_**

            if(defined('AZURE_STORAGE_URL'))
            { 
                $upload_file_name = get_post_meta( $post_id, '_wp_attached_file', true );
                return AZURE_STORAGE_URL . $upload_file_name;
            }
            else
            {
                return $url;
            }

    }
}

Code of Conduct