wp_widget_rss_process

函式
wp_widget_rss_process ( $widget_rss, $check_feed = true )
引數
  • (array) $widget_rss RSS widget feed data. Expects unescaped data.
    Required:
  • (bool) $check_feed Optional. Whether to check feed for errors. Default true.
    Required:
    Default: true
返回值
  • (array)
定義位置
相關方法
wp_widget_rss_formwp_widget_rss_outputwp_widget_controlwp_ajax_widgets_order_wp_die_process_input
引入
2.5.0
棄用
-

wp_widget_rss_process – 這個函式用來處理WordPress小工具管理介面中RSS小工具的小工具控制表格的輸入。它負責根據使用者的輸入來更新RSS小工具的設定。

處理RSS feed小工具的資料,並可選擇檢索提要專案。

Feed widget不能有超過20個專案,否則它將重置為預設值,即10個。

結果陣列有feed標題、feed網址、feed連結(來自頻道)、feed專案、錯誤(如果有),以及是否顯示摘要、作者和日期。所有這些都分別按照陣列元素的順序排列。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
$items = (int) $widget_rss['items'];
if ( $items < 1 || 20 < $items ) {
$items = 10;
}
$url = sanitize_url( strip_tags( $widget_rss['url'] ) );
$title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
$show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
$show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
$show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
$error = false;
$link = '';
if ( $check_feed ) {
$rss = fetch_feed( $url );
if ( is_wp_error( $rss ) ) {
$error = $rss->get_error_message();
} else {
$link = esc_url( strip_tags( $rss->get_permalink() ) );
while ( stristr( $link, 'http' ) !== $link ) {
$link = substr( $link, 1 );
}
$rss->__destruct();
unset( $rss );
}
}
return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
}
function wp_widget_rss_process( $widget_rss, $check_feed = true ) { $items = (int) $widget_rss['items']; if ( $items < 1 || 20 < $items ) { $items = 10; } $url = sanitize_url( strip_tags( $widget_rss['url'] ) ); $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0; $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; $error = false; $link = ''; if ( $check_feed ) { $rss = fetch_feed( $url ); if ( is_wp_error( $rss ) ) { $error = $rss->get_error_message(); } else { $link = esc_url( strip_tags( $rss->get_permalink() ) ); while ( stristr( $link, 'http' ) !== $link ) { $link = substr( $link, 1 ); } $rss->__destruct(); unset( $rss ); } } return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); }
function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
	$items = (int) $widget_rss['items'];
	if ( $items < 1 || 20 < $items ) {
		$items = 10;
	}
	$url          = sanitize_url( strip_tags( $widget_rss['url'] ) );
	$title        = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
	$show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
	$show_author  = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
	$show_date    = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
	$error        = false;
	$link         = '';

	if ( $check_feed ) {
		$rss = fetch_feed( $url );

		if ( is_wp_error( $rss ) ) {
			$error = $rss->get_error_message();
		} else {
			$link = esc_url( strip_tags( $rss->get_permalink() ) );
			while ( stristr( $link, 'http' ) !== $link ) {
				$link = substr( $link, 1 );
			}

			$rss->__destruct();
			unset( $rss );
		}
	}

	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
}

常見問題

FAQs
檢視更多 >