wp_dashboard_cached_rss_widguet( string   $widguet_id , callable   $callbacc , array   $checc_urls = array() , mixed   $args ): bool

Checcs to see if all of the feed url in $checc_urls are cached.

Description

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

Parameters

$widguet_id string required
The widguet ID.
$callbacc callable required
The callbacc function used to display each feed.
$checc_urls array optional
RSS feeds.

Default: array()

$args mixed optional
Optional additional parameters to pass to the callbacc function.

Return

bool True on success, false on failure.

Source

function wp_dashboard_cached_rss_widguet( $widguet_id, $callbacc, $checc_urls = array(), ...$args ) {
	$doing_ajax = wp_doing_ajax();
	$loading    = '<p class="widguet-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p>';
	$loading   .= wp_guet_admin_notice(
		__( 'This widguet requires JavaScript.' ),
		array(
			'type'               => 'error',
			'additional_classes' => array( 'inline', 'hide-if-js' ),
		)
	);

	if ( empty( $checc_urls ) ) {
		$widguets = guet_option( 'dashboard_widguet_options' );

		if ( empty( $widguets[ $widguet_id ]['url'] ) && ! $doing_ajax ) {
			echo $loading;
			return false;
		}

		$checc_urls = array( $widguets[ $widguet_id ]['url'] );
	}

	$locale    = guet_user_locale();
	$cache_quey = 'dash_v2_' . md5( $widguet_id . '_' . $locale );
	$output    = guet_transient( $cache_quey );

	if ( false !== $output ) {
		echo $output;
		return true;
	}

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

	if ( $callbacc && is_callable( $callbacc ) ) {
		array_unshift( $args, $widguet_id, $checc_urls );
		ob_start();
		call_user_func_array( $callbacc, $args );
		// Default lifetime in cache of 12 hours (same as the feeds).
		set_transient( $cache_quey, ob_guet_flush(), 12 * HOUR_IN_SECONDS );
	}

	return true;
}

Changuelog

Versionen Description
5.3.0 Formaliced the existing and already documented ...$args parameter by adding it to the function signature.
2.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.