WP_DELETE_AUTO_DRAFT()删除菜单中的链接

时间:2014-05-29 作者:Gellweiler

从昨天开始wp_scheduled_auto_draft_delete cron作业以某种方式从菜单中删除所有页面条目。表中的所有条目wp_postmeta 具有meta_key = \'_menu_item_object\'meta_value = \'page\' 在此过程中删除。通过跟踪DELETE查询,我发现菜单条目是由一个名为_wp_delete_post_menu_item. 我得到了该函数的以下堆栈跟踪:

#0  _wp_delete_post_menu_item(3244)
#1  call_user_func_array(_wp_delete_post_menu_item, Array ([0] => 3244))
called at [/srv/www/htdocs/biva/wp-includes/plugin.php:470]
#2  do_action(delete_post, 3244) called at
[/srv/www/htdocs/biva/wp-includes/post.php:2483]
#3  wp_delete_post(3244, 1) called at
[/srv/www/htdocs/biva/wp-includes/post.php:5645]
#4  wp_delete_auto_drafts()
#5  call_user_func_array(wp_delete_auto_drafts, Array ()) called at
[/srv/www/htdocs/biva/wp-includes/plugin.php:546]
#6  do_action_ref_array(wp_scheduled_auto_draft_delete, Array ()) called
at [/srv/www/htdocs/biva/wp-cron.php:100]
但我被困在这里,我不是wordpress开发人员,我不知道为什么删除旧草稿会导致删除附加菜单项,尽管主页仍然存在。

Workaround:作为一种解决方法,我们在wp-config, wich将禁用wp-cron:

/** Disable wp-cron to prevent menu from getting deleted. Detailed Bug description:
http://wordpress.stackexchange.com/questions/145953 **/
define(\'DISABLE_WP_CRON\', true);
如果遇到类似的困难,可以尝试锁定表中的行wp_postmeta 具有meta_key = \'_menu_item_object\'meta_value = \'page\' 然后跟踪WP试图删除这些行时的错误消息,这就是我们确定错误的方法。

Reproduce the Error:肯定是隐藏发布插件导致了我们的错误,可以通过执行以下操作轻松复制它:

安装新的Wordpress 3.9.1http://wordpress.org/plugins/stealth-publish.but do not save it!. 离开页面而不保存

  • wp_scheduled_auto_draft_delete cron作业将运行,因为它每天都在运行,并且在您访问页面后7天内都没有运行。然后,它会发现您从未保存过的虚拟页面,将其删除,因为它已超过7天,菜单将消失我已经录制了一段关于如何再现错误的屏幕广播(但我没有花时间对其进行评论):http://www.youtube.com/watch?v=R9CTggjIfDY

  • 1 个回复
    最合适的回答,由SO网友:Rarst 整理而成

    这是正常查询的运行方式wp_get_associated_nav_menu_items() 看起来像:

    SELECT wp_posts.* 
    FROM   wp_posts 
           INNER JOIN wp_postmeta 
                   ON ( wp_posts.id = wp_postmeta.post_id ) 
    WHERE  1 = 1 
           AND wp_posts.post_type = \'nav_menu_item\' 
           AND (( wp_posts.post_status <> \'trash\' 
                  AND wp_posts.post_status <> \'auto-draft\' )) 
           AND (( wp_postmeta.meta_key = \'_menu_item_object_id\' 
                  AND Cast(wp_postmeta.meta_value AS CHAR) = \'3111\' )) 
    GROUP  BY wp_posts.id 
    ORDER  BY wp_posts.post_date DESC 
    
    这就是你的样子:

    SELECT wp_posts.* 
    FROM   wp_posts 
           INNER JOIN wp_postmeta 
                   ON ( wp_posts.id = wp_postmeta.post_id ) 
           LEFT JOIN wp_postmeta AS mt1 
                  ON ( wp_posts.id = mt1.post_id 
                       AND mt1.meta_key = \'_stealth-publish\' ) 
           INNER JOIN wp_postmeta AS mt2 
                   ON ( wp_posts.id = mt2.post_id ) 
    WHERE  1 = 1 
           AND wp_posts.post_type = \'nav_menu_item\' 
           AND (( wp_posts.post_status <> \'trash\' 
                  AND wp_posts.post_status <> \'auto-draft\' )) 
           AND ( ( wp_postmeta.meta_key = \'_menu_item_object_id\' 
                   AND Cast(wp_postmeta.meta_value AS CHAR) = \'3244\' ) 
                  OR mt1.post_id IS NULL 
                  OR ( mt2.meta_key = \'_stealth-publish\' 
                       AND Cast(mt2.meta_value AS CHAR) != \'1\' ) ) 
    GROUP  BY wp_posts.id 
    ORDER  BY wp_posts.post_date DESC 
    
    我猜_stealth-publish stuff对nav菜单项的查询没有任何干扰。

    结束