Last active
December 14, 2020 05:38
-
-
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 .
This file contains 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
<?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