PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.6
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.6
1.1.10 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 All 34 releases
desktop-mode / includes / widgets / widget-comments.php

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

92 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — 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: Desktop Mode 0.18.0+ (desktop_mode_register_widget).
13 *
14 * @package WPDesktopMode
15 * @since 0.26.0
16 */
17
18 defined( 'ABSPATH' ) || exit;
19
20 /**
21 * Register the JS + CSS assets.
22 *
23 * @since 0.26.0
24 */
25 function desktop_mode_register_comments_widget_assets() {
26 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
27 $version = defined( 'DESKTOP_MODE_VERSION' ) ? DESKTOP_MODE_VERSION : '0';
28
29 $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-recent-comments' . $suffix . '.js';
30 $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-recent-comments' . $suffix . '.css';
31
32 wp_register_style(
33 'desktop-mode-comments-widget',
34 DESKTOP_MODE_URL . 'assets/js/widget-recent-comments' . $suffix . '.css',
35 array(),
36 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
37 );
38
39 wp_register_script(
40 'desktop-mode-comments-widget',
41 DESKTOP_MODE_URL . 'assets/js/widget-recent-comments' . $suffix . '.js',
42 array( 'wp-api-fetch' ),
43 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
44 true
45 );
46 }
47 add_action( 'init', 'desktop_mode_register_comments_widget_assets', 5 );
48
49 /**
50 * Eagerly enqueue the CSS on shell pages so there is no flash of
51 * unstyled content while the lazy JS bundle loads.
52 *
53 * @since 0.26.0
54 */
55 function desktop_mode_enqueue_comments_widget_styles() {
56 if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
57 return;
58 }
59 if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) {
60 return;
61 }
62 wp_enqueue_style( 'desktop-mode-comments-widget' );
63 }
64 add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_comments_widget_styles', 20 );
65
66 /**
67 * Register the widget definition.
68 *
69 * @since 0.26.0
70 */
71 function desktop_mode_register_comments_widget() {
72 if ( ! function_exists( 'desktop_mode_register_widget' ) ) {
73 return;
74 }
75 desktop_mode_register_widget(
76 'desktop-mode/recent-comments',
77 array(
78 'label' => __( 'Recent Comments', 'desktop-mode' ),
79 'description' => __( 'Live feed of the latest comments with pending count.', 'desktop-mode' ),
80 'icon' => 'dashicons-admin-comments',
81 'script' => 'desktop-mode-comments-widget',
82 'movable' => true,
83 'resizable' => true,
84 'min_width' => 280,
85 'min_height' => 220,
86 'default_width' => 320,
87 'default_height' => 380,
88 )
89 );
90 }
91 add_action( 'init', 'desktop_mode_register_comments_widget', 6 );
92