"pre_option_upload_url_path" Filter No Longer Firing in WordPress 4.7
Asked Answered
H

1

6

I have the below filter added to my theme's functions.php file:

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

After upgrading to WordPress 4.7, this filter no longer fires.

Do pre_option_{option} filters no longer work in 4.7?

Any help greatly appreciated.

Hypallage answered 11/1, 2017 at 17:13 Comment(5)
We have the same problem. Did you have any solution to this?Broiler
I did actually ... The solution that worked for me in WP 4.7 add_filter('upload_dir', 'cdn_upload_url'); function cdn_upload_url($args) { if (!is_admin()) { $args['baseurl'] = 'https://your-awesome-cdn.net/wp-content/uploads'; } return $args; }Hypallage
if (!is_admin()) is important but you may want to check user roles as well. If you have an organization with editors, you may not want to have them reading from the CDN URL either since it takes a while for assets to propagate to a CDNHypallage
Gist here: [link]gist.github.com/Fliktrax/dfcf7e2a0d2d263aeed9fe4fbd7d45a1Hypallage
Updated Gist with user roles you "don't" want to URL swap: [link] gist.github.com/Fliktrax/9c5f79ad038094a2684ccd14f28fe967Hypallage
C
1

There is a hidden admin page where you can find all the options:

http://localhost/wp-admin/options.php

Find the upload_url_path option and set a value.

enter image description here


Note:

After you give it value, then the "Store uploads in this folder" which is the upload_path, and "Full URL path to files" which is the upload_url_path options will also appear on the Media Settings page:

http://localhost/wp-admin/options-media.php

enter image description here

Codeine answered 13/6, 2022 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.