【发布时间】:2023-04-06 16:15:01
【问题描述】:
当用户保存一些自定义字段的值时,我想在 wordpress 上传文件夹中动态创建一个文件。这是我尝试的,但文件不会被写入:
function generate_options_css() {
$upload_dir = wp_upload_dir();
$ss_dir = get_stylesheet_directory();
ob_start(); // Capture all output into buffer
require($ss_dir . '/custom-styles.php'); // Grab the custom-style.php file
$css = ob_get_clean(); // Store output in a variable, then flush the buffer
file_put_contents($upload_dir . '/custom-styles.css', $css, LOCK_EX); // Save it as a css file
}
add_action( 'acf/save_post', 'generate_options_css' ); //Parse the output and write the CSS file on post save
【问题讨论】:
-
网页用户对目标文件夹是否有足够的写入权限?
-
嗯,知道如何给用户写权限。在以前的版本中,我已经将文件写入主题文件夹,没有问题。
-
取决于您的服务器运行的操作系统
-
每个项目都在另一个共享主机上。