admin管理员组文章数量:1134244
I'm sorry for my english... I am using the following code to create separate media directories for each author.. ( Thanks to )
function per_user_upload_dir( $original ){
$modified = $original;
if ( is_user_logged_in() && current_user_can('instructor') ) {
$current_user = wp_get_current_user();
$subdir = 'user_docs/'.$current_user->user_login;
$modified['subdir'] = $subdir;
$modified['url'] = $original['baseurl'] . '/' . $subdir;
$modified['path'] = $original['basedir'] . DIRECTORY_SEPARATOR . $subdir;
}
return $modified;
}
add_filter( 'upload_dir', 'per_user_upload_dir');
It works well, but the site dies with errors if we activate woocommerce
[03-Aug-2023 09:01:18 UTC] PHP Fatal error: Uncaught Error: Call to undefined function is_user_logged_in() in /home/mydomain/data/www/mydomain/wp-content/plugins/!functions/my-functions.php:53 Stack trace: #0 /home/mydomain/data/www/mydomain/wp-includes/class-wp-hook.php(308): per_user_upload_dir(Array) #1 /home/mydomain/data/www/mydomain/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #2 /home/mydomain/data/www/mydomain/wp-includes/functions.php(2363): apply_filters('upload_dir', Array) #3 /home/mydomain/data/www/mydomain/wp-content/plugins/woocommerce/includes/class-woocommerce.php(305): wp_upload_dir(NULL, false) #4 /home/mydomain/data/www/mydomain/wp-content/plugins/woocommerce/includes/class-woocommerce.php(183): WooCommerce->define_constants() #5 /home/mydomain/data/www/mydomain/wp-content/plugins/woocommerce/includes/class-woocommerce.php(144): WooCommerce->__construct() #6 /home/terraturis in /home/mydomain/data/www/mydomain/wp-content/plugins/!functions/my-functions.php on line 53
I would be grateful for any solution.
Thank you!
本文标签: Problem with quotisuserloggedin()quot and woocommerce (Code for custom media upload for each author)
版权声明:本文标题:Problem with "is_user_logged_in()" and woocommerce (Code for custom media upload for each author.) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736849506a1955439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论