2014-09-28 52 views
0

我使用下面的代碼需要一個特徵圖像創建儀表板WordPress的帖子的時候......需要特色圖片中的Wordpress郵報的functions.php

function featured_image_requirement() { 
    if(!has_post_thumbnail()) { 
      wp_die('You forgot to set the featured image. Click the back button on your browser and set it.'); 
    } 
} 
add_action('pre_post_update', 'featured_image_requirement'); 

這項工作......但也有兩個問題/錯誤。

帖子而非頁數

首先,我只希望這個工作的崗位,而不是網頁。所以,當我去編輯我有的任何頁面,並嘗試提交...我收到需要特色圖片的錯誤消息。所以,我無法保存任何我的網頁... 如何改變上述所以它只能編輯POST(而不是PAGE)

儲存草稿時,工作代碼...

第二個問題是WordPress自動保存草稿的問題。當我編輯一個頁面時,PUBLISH按鈕會淡出(並且變得不可點擊),因爲頁面是「保存草稿...」。這是WordPress的一個有用的功能。但是,由於我啓用了上面的腳本,因此節省的延遲時間非常長。有時發佈按鈕根本不可點擊。

任何人都知道如何在不需要所需功能的情況下「保存草稿」?

+0

的第一個參數的鉤子將是帖子的'ID',然後你可以使用這個號碼,以檢查它是否是一個頁面或交:'函數featured_image_requirement($ post_ID){if(get_post_type($ post_ID)=='post'){// not a page}} – Cyclonecode 2015-09-29 17:58:08

回答

0

我不確定這是否是拼寫錯誤,但是您要添加兩次動作,所以應該只有一次。

總之,你可以試試這個:

function featured_image_requirement() { 
    global $post; 
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 
    return; 
    if ($post - > post_status == "publish" && !has_post_thumbnail()) { 
    wp_die('You forgot to set the featured image. Click the back button on your browser and set it.'); 
    } 
} 
add_action('pre_post_update', 'featured_image_requirement'); 
+0

這個解決方案並沒有解決我遇到的任何問題。 – Jabbamonkey 2014-10-08 19:13:42

相關問題