wp_dashboard_rss_control

函式
wp_dashboard_rss_control ( $widget_id, $form_inputs = array() )
引數
  • (string) $widget_id
    Required:
  • (array) $form_inputs
    Required:
    Default: array()
定義位置
相關方法
wp_dashboard_primary_controlwp_dashboard_secondary_controlwp_dashboard_rss_outputwp_dashboard_secondarywp_dashboard_recent_comments_control
引入
2.5.0
棄用
-

wp_dashboard_rss_control:此函式用於建立rss儀表盤小工具的表單。它生成用於新增或編輯RSS提要URL和標題的表單欄位。

RSS儀表盤小工具控制元件。

設定$args,作為wp_widget_rss_form()的輸入。處理POST資料 處理來自RSS型別小工具的POST資料。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
$widget_options = get_option( 'dashboard_widget_options' );
if ( ! $widget_options ) {
$widget_options = array();
}
if ( ! isset( $widget_options[ $widget_id ] ) ) {
$widget_options[ $widget_id ] = array();
}
$number = 1; // Hack to use wp_widget_rss_form().
$widget_options[ $widget_id ]['number'] = $number;
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
$_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
$widget_options[ $widget_id ]['number'] = $number;
// Title is optional. If black, fill it if possible.
if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
$rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
if ( is_wp_error( $rss ) ) {
$widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
} else {
$widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
$rss->__destruct();
unset( $rss );
}
}
update_option( 'dashboard_widget_options', $widget_options );
$locale = get_user_locale();
$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
delete_transient( $cache_key );
}
wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
}
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { $widget_options = get_option( 'dashboard_widget_options' ); if ( ! $widget_options ) { $widget_options = array(); } if ( ! isset( $widget_options[ $widget_id ] ) ) { $widget_options[ $widget_id ] = array(); } $number = 1; // Hack to use wp_widget_rss_form(). $widget_options[ $widget_id ]['number'] = $number; if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) { $_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] ); $widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] ); $widget_options[ $widget_id ]['number'] = $number; // Title is optional. If black, fill it if possible. if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) { $rss = fetch_feed( $widget_options[ $widget_id ]['url'] ); if ( is_wp_error( $rss ) ) { $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) ); } else { $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) ); $rss->__destruct(); unset( $rss ); } } update_option( 'dashboard_widget_options', $widget_options ); $locale = get_user_locale(); $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); delete_transient( $cache_key ); } wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs ); }
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
	$widget_options = get_option( 'dashboard_widget_options' );

	if ( ! $widget_options ) {
		$widget_options = array();
	}

	if ( ! isset( $widget_options[ $widget_id ] ) ) {
		$widget_options[ $widget_id ] = array();
	}

	$number = 1; // Hack to use wp_widget_rss_form().

	$widget_options[ $widget_id ]['number'] = $number;

	if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
		$_POST['widget-rss'][ $number ]         = wp_unslash( $_POST['widget-rss'][ $number ] );
		$widget_options[ $widget_id ]           = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
		$widget_options[ $widget_id ]['number'] = $number;

		// Title is optional. If black, fill it if possible.
		if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
			$rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
			if ( is_wp_error( $rss ) ) {
				$widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
			} else {
				$widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
				$rss->__destruct();
				unset( $rss );
			}
		}

		update_option( 'dashboard_widget_options', $widget_options );

		$locale    = get_user_locale();
		$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
		delete_transient( $cache_key );
	}

	wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
}

常見問題

FAQs
檢視更多 >