在上传目录中为WordPress插件创建新的上传文件夹

WordPress插件开发过程中,可能需要创建独立的文件夹来保存插件上传的文件,那么你可以在插件的文件中添加类似下面的函数来实现:

function myplugin_activate() {
 
    $upload = wp_upload_dir();
    $upload_dir = $upload['basedir'];
    $upload_dir = $upload_dir . '/mypluginfiles';
    if (! is_dir($upload_dir)) {
       mkdir( $upload_dir, 0700 );
    }
}
 
register_activation_hook( __FILE__, 'myplugin_activate' );

函数的作用是定义插件的上传路径为WordPress默认上传路径下的 mypluginfiles 文件夹,如果不存在该文件夹,就在插件启用的时候新建一个,并且赋予 0700 操作权限。

来源:

https://www.wpdaxue.com/create-a-folder-within-uploads-directory.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32267.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?