
內容簡介
總結文案:
「URL To Featured Image」允許您使用來自互聯網任何地方託管的圖像作為任何帖子、頁面或自定義帖子類型的特色圖像(帖子縮略圖)。這是完美的選擇:
- 將CDN託管圖像用作縮略圖。
- 通過不上傳大圖像節省服務器空間。
- 從外部來源動態更新特色圖像。
問題與答案:
1. 如何使用「URL To Featured Image」插件?
- 在文章編輯器中提供了一個簡單的URL字段。
- 與文章、頁面和自定義帖子類型相容。
- 不需要額外的數據庫表。
- 完全兼容WordPress主題和循環。
- 使用標準的WordPress功能,如`the_post_thumbnail()`。
2. 這個插件如何運作?
- 當顯示帖子時,插件將默認的WordPress特色圖像替換為透過URL提供的圖像。
3. 描述可用的自訂鉤子和過濾器:
- `friss_utfi_post_type_exclusions`:過濾URL To Featured Image元框不應出現的帖子類型。
- `friss_utfi_url_allowed`:在獲取前過濾是否允許外部圖像URL。
- `friss_utfi_allowed_mime_types`:過濾外部圖像允許的MIME類型。
- `friss_utfi_max_image_size`:在獲取外部圖像時過濾允許的最大圖像尺寸。
- `friss_utfi_image_data`:過濾從外部URL獲取的原始圖像數據。
- `friss_utfi_external_featured_image_alt`:為外部特色圖像過濾替代文本。
- `friss_utfi_external_featured_image_styles`:過濾應用於外部特色圖像的內聯CSS樣式。
外掛標籤
開發者團隊
原文外掛簡介
URL To Featured Image allows you to use an image hosted anywhere on the internet as the featured image (post thumbnail) for any post, page, or custom post type.
Perfect for:
– Using CDN-hosted images as thumbnails.
– Saving server space by not uploading large images.
– Dynamically updating featured images from an external source.
Key Features:
– Simple URL field in the post editor.
– Works with posts, pages, and custom post types.
– No extra database tables.
– Fully compatible with WordPress themes and loops.
– Uses standard WordPress functions like the_post_thumbnail().
– Ability to save the target image in the media libary if needed
How it works:
When displaying the post, the plugin replaces the default WordPress featured image with the one provided via the URL.
Custom Hooks
Filters
friss_utfi_post_type_exclusions
Filters the post types where the URL To Featured Image metabox should not appear.
Parameters:
(array) $exclusions_list List of post types where the metabox is excluded.
(object) $post Current post.
Return: (array) Modified exclusions list.
friss_utfi_url_allowed
Filters whether an external image URL is allowed before fetching.
Parameters:
(bool) $authorization Whether the URL is allowed.
(string) $url The external image URL.
(array) $parts Parsed URL parts (from wp_parse_url).
Return: (bool) True to allow, false to block.
friss_utfi_allowed_mime_types
Filters the allowed MIME types for external images.
Parameters:
(array) $mime_types Allowed MIME types.
Return: (array) Modified list of MIME types.
friss_utfi_max_image_size
Filters the maximum allowed image size when fetching external images.
Parameters:
(int) $size Max file size in bytes.
Return: (int) Modified maximum size.
friss_utfi_image_data
Filters the raw image data fetched from the external URL.
Parameters:
(string) $image_data Raw image data (string).
(object) $post Current post object.
Return: (string) Modified image data.
friss_utfi_external_featured_image_alt
Filters the alt text for the external featured image.
Parameters:
(string) $alt_text The alt text (default: post title).
(int) $post_id Current post ID.
Return: (string) Modified alt text.
friss_utfi_post_thumbnail_html_preserve_existing_markup
Controls whether the existing markup is preserved before regenerating the HTML via the post_thumbnail_html filter hook.
Parameters:
(bool) $preserve_existing_markup Whether to preserve or not the existing image tag markup.
(int) $post_id Current post ID.
Return: (bool) True to preserve, false to skip this step.
friss_utfi_post_thumbnail_html_attributes
Filters the image tag attributes for the recreated html content generated by the post_thumbnail_html filter hook.
Parameters:
(array) $attributes The attributes array to filter.
(int) $post_id Current post ID.
Return: (array) Modified attributes array.
friss_utfi_allowed_img_attributes
Filters the whitelist of allowed attributes kept on the generated tag when rendering the external featured image.
Parameters:
(array) $allowed_attributes List of allowed attribute names (default: src, alt, width, height, class, loading, decoding).
(int) $post_id Current post ID.
Return: (array) Modified list of attribute names.
friss_utfi_external_featured_image_styles
Filters the inline CSS styles applied to the external featured image.
By default, the plugin enforces responsive behavior (max-width:100%; height:auto;).
Parameters:
(string) $default_styles The default style string.
(int) $post_id Current post ID.
Return: (string) Modified CSS styles.
friss_utfi_active_post_types
Filters the final list of active post types for which the URL To Featured Image feature is enabled.
Parameters:
(array) $active_post_types Current list of active post type slugs.
Return: (array) Modified list.
friss_utfi_active_post_types_posttype_exclusions
Filters the list of post types excluded before computing active post types.
Parameters:
(array) $exclusions Current exclusions (internal post types or ones you want suppressed).
Return: (array) Modified exclusions list.
