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-jazz-quote.php

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

121 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — Jazz Quote Widget.
4 *
5 * A love letter to WordPress's jazz musician release naming tradition.
6 * Shows the current WP version, its jazz musician codename, and a
7 * rotating daily quote from that musician.
8 *
9 * Requires: Desktop Mode 0.18.0+ (desktop_mode_register_widget).
10 *
11 * @package WPDesktopMode
12 * @since 0.26.0
13 */
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Register JS + CSS assets.
19 *
20 * @since 0.26.0
21 */
22 function desktop_mode_register_jazz_quote_widget_assets() {
23 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
24 $version = defined( 'DESKTOP_MODE_VERSION' ) ? DESKTOP_MODE_VERSION : '0';
25
26 $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-jazz-quote' . $suffix . '.js';
27 $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-jazz-quote' . $suffix . '.css';
28
29 wp_register_style(
30 'desktop-mode-jazz-quote-widget',
31 DESKTOP_MODE_URL . 'assets/js/widget-jazz-quote' . $suffix . '.css',
32 array(),
33 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
34 );
35
36 wp_register_script(
37 'desktop-mode-jazz-quote-widget',
38 DESKTOP_MODE_URL . 'assets/js/widget-jazz-quote' . $suffix . '.js',
39 array(),
40 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
41 true
42 );
43 }
44 add_action( 'init', 'desktop_mode_register_jazz_quote_widget_assets', 5 );
45
46 /**
47 * Inline the WordPress version on the MAIN desktop shell script.
48 *
49 * wp_add_inline_script() only outputs when the attached handle is
50 * actually enqueued. The widget JS loads lazily via the shell's
51 * server-sync, so attaching the inline script to the widget handle
52 * would mean it never appears. Instead we attach it to the main
53 * desktop handle which is always enqueued on shell pages.
54 *
55 * window.desktopModeJazzQuote is therefore available from page load,
56 * before the widget bundle is ever fetched.
57 *
58 * @since 0.26.0
59 */
60 function desktop_mode_jazz_quote_inline_version() {
61 if ( ! desktop_mode_is_enabled() ) {
62 return;
63 }
64 if ( desktop_mode_is_chromeless_request() ) {
65 return;
66 }
67 $main_handle = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
68 ? 'desktop-mode'
69 : 'desktop-mode';
70
71 wp_add_inline_script(
72 $main_handle,
73 'window.desktopModeJazzQuote = { wpVersion: ' . wp_json_encode( get_bloginfo( 'version' ) ) . ' };',
74 'before'
75 );
76 }
77 add_action( 'admin_enqueue_scripts', 'desktop_mode_jazz_quote_inline_version', 15 );
78
79 /**
80 * Eagerly enqueue the CSS on shell pages.
81 *
82 * @since 0.26.0
83 */
84 function desktop_mode_enqueue_jazz_quote_widget_styles() {
85 if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
86 return;
87 }
88 if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) {
89 return;
90 }
91 wp_enqueue_style( 'desktop-mode-jazz-quote-widget' );
92 }
93 add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_jazz_quote_widget_styles', 20 );
94
95 /**
96 * Register the widget definition.
97 *
98 * @since 0.26.0
99 */
100 function desktop_mode_register_jazz_quote_widget() {
101 if ( ! function_exists( 'desktop_mode_register_widget' ) ) {
102 return;
103 }
104 desktop_mode_register_widget(
105 'desktop-mode/jazz-quote',
106 array(
107 'label' => __( 'Jazz Quote', 'desktop-mode' ),
108 'description' => __( 'A daily quote from the jazz musician behind your WordPress version.', 'desktop-mode' ),
109 'icon' => 'dashicons-format-audio',
110 'script' => 'desktop-mode-jazz-quote-widget',
111 'movable' => true,
112 'resizable' => true,
113 'min_width' => 220,
114 'min_height' => 160,
115 'default_width' => 300,
116 'default_height' => 220,
117 )
118 );
119 }
120 add_action( 'init', 'desktop_mode_register_jazz_quote_widget', 6 );
121