Last active
April 11, 2018 11:12
-
-
Save widoz/639d16724606bddcaffa to your computer and use it in GitHub Desktop.
Wp Filesystem
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 | |
/** | |
* Switch Upload Dir & Url | |
* | |
* @since 1.0.0 | |
* | |
* @param string $file The file path. | |
* @param string $switch The reference to the string to replace. Allowed 'dir>url', 'url>dir'. | |
* | |
* @return string The file url | |
*/ | |
function xxx_switch_upload_dir_path_url( $file, $switch = 'dir>url' ) { | |
// Get upload dir data. | |
$_upload_dir = wp_upload_dir(); | |
// Initialize the new file path. | |
$_file = ''; | |
if ( 'dir>url' === $switch ) { | |
$_file = str_replace( $_upload_dir['basedir'], $_upload_dir['baseurl'], $file ); | |
} else if ( 'url>dir' === $switch ) { | |
$_file = str_replace( $_upload_dir['baseurl'], $_upload_dir['basedir'], $file ); | |
} else { | |
$_file = $file; | |
} | |
if ( $_file ) { | |
return $_file; | |
} | |
} |
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_size_limit', function ($byte) | |
{ | |
// 10MB | |
return 10000000; | |
}); |
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 | |
/** | |
* WP Direct FileSystem instance | |
*/ | |
function wpFilesystem() | |
{ | |
if (!class_exists('WP_Filesystem_Direct')) { | |
require_once untrailingslashit(ABSPATH) . '/wp-admin/includes/class-wp-filesystem-base.php'; | |
require_once untrailingslashit(ABSPATH) . '/wp-admin/includes/class-wp-filesystem-direct.php'; | |
} | |
return new \WP_Filesystem_Direct(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment