liveblog icon indicating copy to clipboard operation
liveblog copied to clipboard

Allow public API access to timestamp of most recent update

Open paulschreiber opened this issue 7 years ago • 2 comments

Allow public API access to timestamp of most recent update.

One way to do this:

diff --git a/liveblog/liveblog.php b/liveblog/liveblog.php
index 55d19801..c4ab144e 100644
--- a/liveblog/liveblog.php
+++ b/liveblog/liveblog.php
@@ -59,6 +59,7 @@ if ( ! class_exists( 'WPCOM_Liveblog' ) ) :
                public static $auto_archive_days       = null;
                public static $auto_archive_expiry_key = 'liveblog_autoarchive_expiry_date';
 
+               public static $latest_timestamp        = false;
 
 
                /** Load Methods **********************************************************/
@@ -986,6 +987,8 @@ if ( ! class_exists( 'WPCOM_Liveblog' ) ) :
                                self::add_default_plupload_settings();
                        }
 
+                       self::$latest_timestamp = self::$entry_query->get_latest_timestamp();
+
                        wp_localize_script(
                                self::KEY, 'liveblog_settings',
                                apply_filters(
@@ -1000,7 +1003,7 @@ if ( ! class_exists( 'WPCOM_Liveblog' ) ) :
                                                'nonce_key'                    => self::NONCE_KEY,
                                                'nonce'                        => wp_create_nonce( self::NONCE_ACTION ),
                                                'image_nonce'                  => wp_create_nonce( 'media-form' ),
-                                               'latest_entry_timestamp'       => self::$entry_query->get_latest_timestamp(),
+                                               'latest_entry_timestamp'       => self::$latest_timestamp,
                                                'latest_entry_id'              => self::$entry_query->get_latest_id(),
                                                'timestamp'                    => time(),
                                                'utc_offset'                   => get_option( 'gmt_offset' ) * 120, // in minutes; doubled, because get_comment_date() returns local time, not GMT

paulschreiber avatar Mar 21 '18 21:03 paulschreiber

What's the use case you're working on that would need this?

philipjohn avatar Oct 08 '18 08:10 philipjohn

On our live blogs, we have the string "last updated at XX:YY AM/PM" at the top of the page. When a new update is loaded, a JavaScript even fires, and we update that string.

paulschreiber avatar Oct 08 '18 13:10 paulschreiber