Browse Source

desk: add shortcodes [dw_til]/[dw_bookmarks]/[dw_recently_edited] (block-ready)

Wrap the echoing TIL/bookmarks helpers (ob_start) and the inline Recently-Edited
sticky loop from page-desk.php as shortcodes, so they can be dropped into block
content when the Desk sidebars migrate. No visual change yet — page-desk.php
still renders via the direct function calls.
windhamdavid 1 week ago
parent
commit
2fe55480bd
1 changed files with 44 additions and 0 deletions
  1. 44 0
      inc/utils.php

+ 44 - 0
inc/utils.php

@@ -142,6 +142,50 @@ function bookmarks_all() {
 	}
 }
 
+/*============================================
+    Desk block-migration shortcodes
+    Wrap the echoing helpers (and the inline "Recently Edited" loop from
+    page-desk.php) so they can be dropped into block content.
+==============================================*/
+function dw_til_shortcode() {
+	ob_start();
+	pull_til();
+	return ob_get_clean();
+}
+add_shortcode( 'dw_til', 'dw_til_shortcode' );
+
+function dw_bookmarks_shortcode() {
+	ob_start();
+	bookmarks_pull();
+	return ob_get_clean();
+}
+add_shortcode( 'dw_bookmarks', 'dw_bookmarks_shortcode' );
+
+function dw_recently_edited_shortcode() {
+	$sticky = get_option( 'sticky_posts' );
+	if ( empty( $sticky ) ) {
+		return '';
+	}
+	$posts = get_posts( array(
+		'post_type'      => 'post',
+		'orderby'        => 'modified',
+		'posts_per_page' => 5,
+		'post__in'       => $sticky,
+	) );
+	if ( ! $posts ) {
+		return '';
+	}
+	$out = '<ul>';
+	foreach ( $posts as $p ) {
+		$out .= '<li style="color:#777">'
+			. get_the_modified_date( 'y/m/d', $p ) . ' ( ' . get_the_date( 'y/m/d', $p ) . ' ) - '
+			. '<a href="' . esc_url( get_permalink( $p ) ) . '">' . esc_html( get_the_title( $p ) ) . '</a></li>';
+	}
+	$out .= '</ul>';
+	return $out;
+}
+add_shortcode( 'dw_recently_edited', 'dw_recently_edited_shortcode' );
+
 function now() {
 	require_once('lib/html_dom.php');
 	$url = 'https://davidawindham.com/til/lists/now';