开机自检状态更改时修订过多

时间:2019-01-23 作者:Alt C

每当我更新自定义帖子类型时,它会生成太多的修订,导致网站崩溃。(超出内存)如何调试此问题?

enter image description here

更新:我找到了罪魁祸首。是否可能有人检测到我在以下代码中做错了什么:

if (class_exists(\'wpprolister_core\')) {

    add_action(\'wp_insert_post\', \'wpprolister_updated_to_publish\', 10, 3);

    function wpprolister_updated_to_publish($post_id, $post, $update)
    {

        if (get_field(\'wpprolister_advanced_option_edit_seo\', $post_id)) {

            $metatitle     = get_field(\'wpprolister_seo_title\', $post_id);
            $metadesc      = get_field(\'wpprolister_seo_meta_description\', $post_id);
            $metakeywords  = get_field(\'wpprolister_seo_keyword\', $post_id);
            $content       = get_field(\'wpprolister_description\', $post_id);
            $image         = get_field(\'wpprolister_listing_slider_image\', $post_id);
            $attachment_id = $image[\'ID\'];

            if (!empty($image)):
                $size  = \'medium\';
                $thumb = $image[\'sizes\'][$size];
                if (defined(\'WPSEO_VERSION\')) {
                    update_post_meta($post_id, \'_yoast_wpseo_title\', $metatitle);
                    update_post_meta($post_id, \'_yoast_wpseo_metadesc\', $metadesc);
                    update_post_meta($post_id, \'_yoast_wpseo_focuskw\', $metakeywords);}
                //also update the content and featured image
                $my_post = array(
                    \'ID\'           => $post_id,
                    \'post_content\' => $content,
                );
                wp_update_post($my_post);
                update_post_meta($post_id, \'_thumbnail_id\', $attachment_id);

            endif;

        }
    }
}
我是如何解决问题的(如果我做错了,请告诉我):

remove_action(\'wp_insert_post\', \'wpprolister_updated_to_publish\');
            $my_post = array(
                \'ID\'           => $post_id,
                \'post_content\' => $content,
            );
            wp_update_post($my_post);
            add_action(\'wp_insert_post\', \'wpprolister_updated_to_publish\');

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

也许您可以尝试查看哪些函数连接到save_post 操作,然后查看这些函数正在执行的操作。也许其中有一个无限循环。尝试查看全局变量$wp_filter, 这里有更多信息,How to know what functions are hooked to an action/filter?

相关推荐

How to delete post revisions?

我没有设置修订数量的限制,这使得我的一些帖子有20多个修订,那么如何删除这些修订呢?顺便说一下,我正在使用WPMU,并且有很多博客,那么如何删除我所有博客的WordPress修订版呢?