Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fiftin/339a1aef9b553e98369b2020fbe49a36 to your computer and use it in GitHub Desktop.
Save fiftin/339a1aef9b553e98369b2020fbe49a36 to your computer and use it in GitHub Desktop.
WordPress 4.7 CDN URL Update
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