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-post-stats.php

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

88 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — Post Stats Widget.
4 *
5 * Bar chart of posts published per month for the last 6 months,
6 * broken down by published / draft / pending status.
7 *
8 * Refresh: every 5 minutes.
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 the JS + CSS assets.
19 *
20 * @since 0.26.0
21 */
22 function desktop_mode_register_post_stats_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-post-stats' . $suffix . '.js';
27 $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-post-stats' . $suffix . '.css';
28
29 wp_register_style(
30 'desktop-mode-post-stats-widget',
31 DESKTOP_MODE_URL . 'assets/js/widget-post-stats' . $suffix . '.css',
32 array(),
33 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
34 );
35
36 wp_register_script(
37 'desktop-mode-post-stats-widget',
38 DESKTOP_MODE_URL . 'assets/js/widget-post-stats' . $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', 'desktop_mode_register_post_stats_widget_assets', 5 );
45
46 /**
47 * Eagerly enqueue the CSS on shell pages.
48 *
49 * @since 0.26.0
50 */
51 function desktop_mode_enqueue_post_stats_widget_styles() {
52 if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
53 return;
54 }
55 if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) {
56 return;
57 }
58 wp_enqueue_style( 'desktop-mode-post-stats-widget' );
59 }
60 add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_post_stats_widget_styles', 20 );
61
62 /**
63 * Register the widget definition.
64 *
65 * @since 0.26.0
66 */
67 function desktop_mode_register_post_stats_widget() {
68 if ( ! function_exists( 'desktop_mode_register_widget' ) ) {
69 return;
70 }
71 desktop_mode_register_widget(
72 'desktop-mode/post-stats',
73 array(
74 'label' => __( 'Post Stats', 'desktop-mode' ),
75 'description' => __( 'Bar chart of posts per month over the last 6 months.', 'desktop-mode' ),
76 'icon' => 'dashicons-chart-bar',
77 'script' => 'desktop-mode-post-stats-widget',
78 'movable' => true,
79 'resizable' => true,
80 'min_width' => 260,
81 'min_height' => 200,
82 'default_width' => 320,
83 'default_height' => 260,
84 )
85 );
86 }
87 add_action( 'init', 'desktop_mode_register_post_stats_widget', 6 );
88