• Resolved randy394

    (@randy394)


    I have the following code in my functions.php to redirect the URL of all media attachments to the Amazon CDN. It used to work perfect, and still works on a mirror test site, but suddenly stopped on the master site.

    Uploads WILL go to it; however, it won’t return the proper path in, for example, the Media Library.

    I tried adding it to the default theme and no luck there either. I’ve tried de-activating all plugins and, too, not luck. So, I’m left to believe it’s something in WordPress’s core interfering.

    I even tried restoring some backups from when it was working… nothing.

    Is there somewhere known that would cause this not to work?

    // Change Media Uploads To Amazon Cloudfare CDN
    
    function cdn_url() {
      return 'https://d2w3ygkvuq5sxd.cloudfront.net/blogs/wp-content/uploads';
    }
    add_filter( 'pre_option_upload_url_path', 'cdn_url' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter randy394

    (@randy394)

    I was able to figure this out. I had to edit the upload_url_path field in wp_options manually to point to the URL.

    I don’t understand the reason why it suddenly stopped working, nor why this field is blank in the test site where the CDN still works properly. Both sites had the corrent URL entered on the Settings > Media page. Nonetheless, it is fixed.

    You have (sort of) a solution, but it seems that I’m in the same situation that you are in. An issue that arises with your solution is that it renders the Media Library uploads unusable while uploading assets as an Admin user. The “pre_option_upload_url_path” filter is all but forgotten in WP 4.7, and though I have had support questions pending, no one has come forward to attempt a solution.

    I hacked the /wp-includes/functions.php file and replaced the entire “wp_upload_dir” function with the older WP version and it is now working. (1875 to 1919 in WP4.7)

    Yes … this is a hack, but I can now use the following code in my theme’s functions.php file:

    function cdn_upload_url() {
    	if ( ! is_admin() ) {
        	return 'https://d24fxnpb2c5viy.cloudfront.net';
    	}
    }
    add_filter( 'pre_option_upload_url_path', 'cdn_upload_url' , 10);

    If you do this, remember to delete the “upload_url_path” entry from your database.

    Hopefully we will be recognized as legitimate on the support group at some point.

    • This reply was modified 7 years, 10 months ago by jamiedusa.
    • This reply was modified 7 years, 10 months ago by jamiedusa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘pre_option_upload_url_path For CDN No Longer Working’ is closed to new replies.