問題描述
我正在創建一個有多個作者的棒球網站。從過去的經驗來看,無論你親自認識某人,這並不意味着他們會遵循甚至閲讀你的指示。
話雖如此,我想要求作者決定 「用作特色圖像」 的圖像至少為 640 像素寬,最小為 360 像素高。
我要求每個帖子都有使用 WyPiekacz plugin 的精選圖片; 如果沒有精選圖片,該帖子將不會發布。我已經阻止了作者使用 Bainternet 的代碼將 removing the “From URL” tab in Add Media 熱鏈接到另一個網站的能力。
現在,我需要要求使用作為特色圖像的任何圖像至少為 640px x 360px 。我不是一個編碼器,但是我一直在玩弄,並試圖用 Maor Barazany 的代碼作為起點,但是無濟於事。他的代碼強制 minimum dimensions for any image that is uploaded 。
最佳解決方案
好的,如果你使用 WyPiekacz 插件; 正如您所説的檢查功能圖像是否上傳,您可以調整一點,以檢查是否有精選圖像,根據需要,它是最小的幾何。
$has_thumbnail = false;
if ( ( $post_id > 0 ) && function_exists( 'has_post_thumbnail' ) ) {
$has_thumbnail = has_post_thumbnail( $post_id );
}
$has_thumbnail = apply_filters( 'wypiekacz_check_thumbnail', $has_thumbnail, $post_id, $post_data );
if ( !$has_thumbnail ) {
$this->errors[] = array( 'post_thumbnail', __('Post thumbnail (Featured image) is required.', 'wypiekacz') );
}
你可以把上面的代碼改成 wypiekacz.php,
$has_thumbnail_proper_dimension = false;
if ( ( $post_id > 0 ) && function_exists( 'has_post_thumbnail' ) ) {
$has_thumbnail = has_post_thumbnail( $post_id );
list($url, $width, $height) = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), "Full");
echo $imgsrc[0];
if($width>=640 and $height>=360){
$has_thumbnail_proper_dimension=true;
}
}
$has_thumbnail = apply_filters( 'wypiekacz_check_thumbnail', $has_thumbnail, $post_id, $post_data );
if ( !$has_thumbnail ) {
$this->errors[] = array( 'post_thumbnail', __('Post thumbnail (Featured image) is required.', 'wypiekacz') );
}
if ( !$has_thumbnail_proper_dimension ) {
$this->errors[] = array( 'post_thumbnail', __('Post thumbnail (Featured image) should be atleast 640x360.', 'wypiekacz') );
}
好吧,我不明白你的意思是什麼 「媒體庫選項卡」 。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。