WordPress 6.2 新增了一个移动文件夹函数 move_dir。
函数原型:
move_dir( string $from, string $to, bool $overwrite = false ): true|WP_Error
如果,目标文件夹不存在,就直接移动原文件夹到目标文件夹。
如果,目标文件夹已存在, 当参数 $overwrite 为 false 时,函数会失败;当$overwrite 为 true 时,会先删除目标文件夹,再把原文件夹移过去。
如果,希望原文件夹和目标文件夹合并,可以使用 copy_dir 函数,可以参考:《WordPress函数:copy_dir 复制文件夹》。使用 copy_dir 同样会有同名文件覆盖的问题。move_dir 和 copy_dir 功能强大,使用当谨慎。
使用举例:
if (!WP_Filesystem()) {
exit;
}
$td = get_template_directory();
move_dir($td . '/from', $td . '/to', true);
使用 move_dir 需要先调用 WP_Filesystem() 。
-
WordPress函数:translate_nooped_plural 翻译并注册字符串WordPress函数:translate_nooped_plural 翻译并注册字符串
-
WordPress函数:number_format_i18n 数字国际化WordPress函数:number_format_i18n 数字国际化
-
WordPress函数:date_i18n 日期国际化WordPress函数:date_i18n 日期国际化
-
WordPress函数:esc_html_e 转义翻译的字符串并显示WordPress函数:esc_html_e 转义翻译的字符串并显示
-
WordPress函数:esc_attr_e 属性转义、翻译、显示WordPress函数:esc_attr_e 属性转义、翻译、显示
-
WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示
暂无评论,抢个沙发...