【发布时间】:2020-06-15 20:26:00
【问题描述】:
我正在编写一个 wordpress 函数来在帖子发布后触发一个函数我正在使用 add_action("save_post", "") 但我只希望我的函数仅在用户只点击发布按钮
这是我写的
add_action("save_post", "test");
function test( $post_id ) {
if( !(wp_is_post_revision( $post_id ) ) || wp_is_post_autosave( $post_id ) ) {
return;
}
$post_log = get_stylesheet_directory() . "/post.txt";
$message = get_the_title($post_id) . ' was saved';
if( file_exists ( $post_log )) {
$file = fopen( $post_log, 'a');
fwrite($file, $message."\n");
} else {
$file = fopen( $post_log, "w");
fwrite($file, $message."\n");
}
fclose($file);
}
但是通过此代码,我的 post.txt 文件中的每个帖子都会保存两次结果,其中一个用于自动保存草稿,另一个用于常规保存。
【问题讨论】:
-
你在哪里运行这个?直接在浏览器中?在 Node.js 中?在浏览器中但使用 Webpack 之类的东西进行转换?其他地方?
-
所以“直接在浏览器中”。
-
但是,当我尝试使用 parcel localhost 打开的 html 格式的相同文件时,它可以正常工作,但在任何其他服务器上都无法正常工作
-
您使用的是什么版本的 GSAP? GSAP installation page 和其中的视频很可能可以帮助您正确导入 GSAP,尤其是安装助手。