Skip to content

Instantly share code, notes, and snippets.

@mt8
Last active December 14, 2020 05:38
Show Gist options
  • Save mt8/a5d55d8ae2ffbbdc7703fdbb0da022d6 to your computer and use it in GitHub Desktop.
Save mt8/a5d55d8ae2ffbbdc7703fdbb0da022d6 to your computer and use it in GitHub Desktop.
[WordPress] Change the theme/plugin zip update folder to /tmp instead of /uploads .
<?php
add_filter( 'upload_dir', function ( $dir ) {
global $pagenow;
if ( ! isset( $pagenow ) || 'update.php' !== $pagenow ) {
return $dir;
}
if ( ! isset( $_REQUEST['action'] ) || 'upload-theme' !== $_REQUEST['action'] ) {
return $dir;
}
if ( false === function_exists( 'is_user_logged_in' ) ) {
return $dir;
}
if ( false === is_user_logged_in() ) {
return $dir;
}
if ( false === current_user_can( 'upload_themes' ) ) {
return $dir;
}
if ( false === $_REQUEST[ '_wpnonce' ] ) {
return $dir;
}
if ( false === ( wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'theme-upload' ) ) ) {
return $dir;
}
$dir['path'] = get_temp_dir();
$dir['subdir'] = '';
$dir['basedir'] = $dir['path'];
return $dir;
} );
add_filter( 'upload_dir', function ( $dir ) {
global $pagenow;
if ( ! isset( $pagenow ) || 'update.php' !== $pagenow ) {
return $dir;
}
if ( ! isset( $_REQUEST['action'] ) || 'upload-plugin' !== $_REQUEST['action'] ) {
return $dir;
}
if ( false === function_exists( 'is_user_logged_in' ) ) {
return $dir;
}
if ( false === is_user_logged_in() ) {
return $dir;
}
if ( false === current_user_can( 'upload_plugins' ) ) {
return $dir;
}
if ( false === $_REQUEST[ '_wpnonce' ] ) {
return $dir;
}
if ( false === ( wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'plugin-upload' ) ) ) {
return $dir;
}
$dir['path'] = get_temp_dir();
$dir['subdir'] = '';
$dir['basedir'] = $dir['path'];
return $dir;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment