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 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)
Parameters Parameters
- $widget_id
-
(string) (Required)
- $callback
-
(callable) (Required)
- $check_urls
-
(array) (Optional) RSS feeds
Default value: array()
Return Return
(bool) False on failure. True on success.
Source Source
File: wp-admin/includes/dashboard.php
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | 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; } |
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |