返回介绍

wp_dashboard_cached_rss_widget()

发布于 2017-09-11 11:45:01 字数 3112 浏览 1140 评论 0 收藏 0

wp_dashboard_cached_rss_widget( string $widget_id,  callable $callback,  array $check_urls = array() )

Checks to see if all of the feed url in $check_urls are cached.


description

If $check_urls is empty, look for the rss feed url found in the dashboard widget options of $widget_id. If cached, call $callback, a function that echoes out output for this widget. If not cache, echo a "Loading…" stub which is later replaced by Ajax call (see top of /wp-admin/index.php)


参数

$widget_id

(string) (Required)

$callback

(callable) (Required)

$check_urls

(array) (Optional) RSS feeds

Default value: array()


返回值

(bool) False on failure. True on success.


源代码

File: wp-admin/includes/dashboard.php

function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
	$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
	$doing_ajax = wp_doing_ajax();

	if ( empty($check_urls) ) {
		$widgets = get_option( 'dashboard_widget_options' );
		if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
			echo $loading;
			return false;
		}
		$check_urls = array( $widgets[$widget_id]['url'] );
	}

	$locale = get_user_locale();
	$cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
	if ( false !== ( $output = get_transient( $cache_key ) ) ) {
		echo $output;
		return true;
	}

	if ( ! $doing_ajax ) {
		echo $loading;
		return false;
	}

	if ( $callback && is_callable( $callback ) ) {
		$args = array_slice( func_get_args(), 3 );
		array_unshift( $args, $widget_id, $check_urls );
		ob_start();
		call_user_func_array( $callback, $args );
		set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
	}

	return true;
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_doing_ajax()
  • wp-includes/l10n.php: get_user_locale()
  • wp-includes/l10n.php: __()
  • wp-includes/option.php: get_transient()
  • wp-includes/option.php: set_transient()
  • wp-includes/option.php: get_option()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/dashboard.php: wp_dashboard_primary()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文