Last active
October 15, 2019 19:58
-
-
Save Fliktrax/9c5f79ad038094a2684ccd14f28fe967 to your computer and use it in GitHub Desktop.
WordPress 4.7 CDN URL Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('upload_dir', 'cdn_upload_url'); | |
function cdn_upload_url($args) | |
{ | |
$current_user = wp_get_current_user(); | |
$current_user_id = $current_user->ID; | |
$is_id_user = ($current_user_id > 0) ? true : false; | |
switch($is_id_user) | |
{ | |
case true: | |
$admin_users = array('administrator', 'editor', 'author'); //Add roles that you don't want to CDN swap | |
$user_roles = wp_get_current_user()->roles; | |
$admin_roles = array_intersect($user_roles, $admin_users); | |
if(count($admin_roles) > 0) return $args; | |
break; | |
default: | |
$args['baseurl'] = 'https://your.awesomecdn.net/wp-content/uploads'; //Change to your base CDN directory - no trailing slash | |
return $args; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment