PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.9
1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 0.8.6 All 33 releases
desktop-mode / includes / widgets / widget-comments.php

widget-comments.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.9, at includes/widgets/widget-comments.php

85 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Recent Comments Widget.
4 *
5 * Shows a live feed of recent comments with status badges
6 * (Approved / Pending / Spam), the commenter name, the post title
7 * it belongs to, and a time-ago stamp. Pending count badge
8 * on the card header keeps moderators on top of the queue at a glance.
9 *
10 * Data source: WordPress REST API /wp/v2/comments (logged-in).
11 * Refresh: every 60 seconds via setInterval.
12 * Requires: OpenStation 0.18.0+ (openstation_register_widget).
13 *
14 * @package OpenStation
15 */
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Register the JS + CSS assets.
21 */
22 function openstation_register_comments_widget_assets() {
23 $suffix = openstation_asset_suffix();
24 $version = defined( 'OPENSTATION_VERSION' ) ? OPENSTATION_VERSION : '0';
25
26 $js_path = OPENSTATION_DIR . 'assets/js/widget-recent-comments' . $suffix . '.js';
27 $css_path = OPENSTATION_DIR . 'assets/js/widget-recent-comments' . $suffix . '.css';
28
29 wp_register_style(
30 'os-comments-widget',
31 OPENSTATION_URL . 'assets/js/widget-recent-comments' . $suffix . '.css',
32 array(),
33 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
34 );
35
36 wp_register_script(
37 'os-comments-widget',
38 OPENSTATION_URL . 'assets/js/widget-recent-comments' . $suffix . '.js',
39 array( 'wp-api-fetch' ),
40 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
41 true
42 );
43 }
44 add_action( 'init', 'openstation_register_comments_widget_assets', 5 );
45
46 /**
47 * Eagerly enqueue the CSS on shell pages so there is no flash of
48 * unstyled content while the lazy JS bundle loads.
49 */
50 function openstation_enqueue_comments_widget_styles() {
51 if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled() ) {
52 return;
53 }
54 if ( function_exists( 'openstation_is_chromeless_request' ) && openstation_is_chromeless_request() ) {
55 return;
56 }
57 wp_enqueue_style( 'os-comments-widget' );
58 }
59 add_action( 'admin_enqueue_scripts', 'openstation_enqueue_comments_widget_styles', 20 );
60
61 /**
62 * Register the widget definition.
63 */
64 function openstation_register_comments_widget() {
65 if ( ! function_exists( 'openstation_register_widget' ) ) {
66 return;
67 }
68 openstation_register_widget(
69 'desktop-mode/recent-comments',
70 array(
71 'label' => __( 'Recent Comments', 'desktop-mode' ),
72 'description' => __( 'Live feed of the latest comments with pending count.', 'desktop-mode' ),
73 'icon' => 'dashicons-admin-comments',
74 'script' => 'os-comments-widget',
75 'movable' => true,
76 'resizable' => true,
77 'min_width' => 280,
78 'min_height' => 220,
79 'default_width' => 320,
80 'default_height' => 380,
81 )
82 );
83 }
84 add_action( 'init', 'openstation_register_comments_widget', 6 );
85