| @@ -1,16 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Post Stats Widget. | |
| 3 | + * OpenStation — Post Stats Widget. | |
| 4 | 4 | * |
| 5 | 5 | * Bar chart of posts published per month for the last 6 months, |
| 6 | 6 | * broken down by published / draft / pending status. |
| 7 | 7 | * |
| 8 | 8 | * Refresh: every 5 minutes. |
| 9 | - * Requires: Desktop Mode 0.18.0+ (desktop_mode_register_widget). | |
| 9 | + * Requires: OpenStation 0.18.0+ (openstation_register_widget). | |
| 10 | 10 | * |
| 11 | - * @package WPDesktopMode | |
| 12 | - * @since 0.26.0 | |
| 11 | + * @package OpenStation | |
| 13 | 12 | */ |
| 14 | 13 | |
| 15 | 14 | defined( 'ABSPATH' ) || exit; |
| 16 | 15 | |
| @@ -21,18 +20,16 @@ | ||
| 21 | 20 | * refresh — with a single GROUP BY that's shared through a transient. |
| 22 | 21 | * |
| 23 | 22 | * Route: GET /desktop-mode/v1/post-stats |
| 24 | 23 | * Permission: edit_posts. |
| 25 | - * | |
| 26 | - * @since 0.9.7 | |
| 27 | 24 | */ |
| 28 | -function desktop_mode_register_post_stats_rest_route() { | |
| 25 | +function openstation_register_post_stats_rest_route() { | |
| 29 | 26 | register_rest_route( |
| 30 | 27 | 'desktop-mode/v1', |
| 31 | 28 | '/post-stats', |
| 32 | 29 | array( |
| 33 | 30 | 'methods' => WP_REST_Server::READABLE, |
| 34 | - 'callback' => 'desktop_mode_post_stats_callback', | |
| 31 | + 'callback' => 'openstation_post_stats_callback', | |
| 35 | 32 | 'permission_callback' => static function () { |
| 36 | 33 | return current_user_can( 'edit_posts' ); |
| 37 | 34 | }, |
| 38 | 35 | ) |
| @@ -37,9 +34,9 @@ | ||
| 37 | 34 | }, |
| 38 | 35 | ) |
| 39 | 36 | ); |
| 40 | 37 | } |
| 41 | -add_action( 'rest_api_init', 'desktop_mode_register_post_stats_rest_route' ); | |
| 38 | +add_action( 'rest_api_init', 'openstation_register_post_stats_rest_route' ); | |
| 42 | 39 | |
| 43 | 40 | /** |
| 44 | 41 | * Aggregate post counts per month × status for the last 6 months. |
| 45 | 42 | * |
| @@ -52,13 +49,11 @@ | ||
| 52 | 49 | * Cached for 5 minutes per scope — the data is a trailing-6-month |
| 53 | 50 | * aggregate, the widget refreshes every 5 minutes, and every viewer |
| 54 | 51 | * in the same capability scope can share one computation. |
| 55 | 52 | * |
| 56 | - * @since 0.9.7 | |
| 57 | - * | |
| 58 | 53 | * @return array{months:array<int,array{ym:string,publish:int,draft:int,pending:int}>} |
| 59 | 54 | */ |
| 60 | -function desktop_mode_post_stats_callback() { | |
| 55 | +function openstation_post_stats_callback() { | |
| 61 | 56 | global $wpdb; |
| 62 | 57 | |
| 63 | 58 | $see_others = current_user_can( 'edit_others_posts' ); |
| 64 | 59 | $cache_key = $see_others |
| @@ -144,67 +139,61 @@ | ||
| 144 | 139 | } |
| 145 | 140 | |
| 146 | 141 | /** |
| 147 | 142 | * Register the JS + CSS assets. |
| 148 | - * | |
| 149 | - * @since 0.26.0 | |
| 150 | 143 | */ |
| 151 | -function desktop_mode_register_post_stats_widget_assets() { | |
| 152 | - $suffix = desktop_mode_asset_suffix(); | |
| 153 | - $version = defined( 'DESKTOP_MODE_VERSION' ) ? DESKTOP_MODE_VERSION : '0'; | |
| 144 | +function openstation_register_post_stats_widget_assets() { | |
| 145 | + $suffix = openstation_asset_suffix(); | |
| 146 | + $version = defined( 'OPENSTATION_VERSION' ) ? OPENSTATION_VERSION : '0'; | |
| 154 | 147 | |
| 155 | - $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-post-stats' . $suffix . '.js'; | |
| 156 | - $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-post-stats' . $suffix . '.css'; | |
| 148 | + $js_path = OPENSTATION_DIR . 'assets/js/widget-post-stats' . $suffix . '.js'; | |
| 149 | + $css_path = OPENSTATION_DIR . 'assets/js/widget-post-stats' . $suffix . '.css'; | |
| 157 | 150 | |
| 158 | 151 | wp_register_style( |
| 159 | - 'desktop-mode-post-stats-widget', | |
| 160 | - DESKTOP_MODE_URL . 'assets/js/widget-post-stats' . $suffix . '.css', | |
| 152 | + 'os-post-stats-widget', | |
| 153 | + OPENSTATION_URL . 'assets/js/widget-post-stats' . $suffix . '.css', | |
| 161 | 154 | array(), |
| 162 | 155 | file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version |
| 163 | 156 | ); |
| 164 | 157 | |
| 165 | 158 | wp_register_script( |
| 166 | - 'desktop-mode-post-stats-widget', | |
| 167 | - DESKTOP_MODE_URL . 'assets/js/widget-post-stats' . $suffix . '.js', | |
| 159 | + 'os-post-stats-widget', | |
| 160 | + OPENSTATION_URL . 'assets/js/widget-post-stats' . $suffix . '.js', | |
| 168 | 161 | array( 'wp-api-fetch' ), |
| 169 | 162 | file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version, |
| 170 | 163 | true |
| 171 | 164 | ); |
| 172 | 165 | } |
| 173 | -add_action( 'init', 'desktop_mode_register_post_stats_widget_assets', 5 ); | |
| 166 | +add_action( 'init', 'openstation_register_post_stats_widget_assets', 5 ); | |
| 174 | 167 | |
| 175 | 168 | /** |
| 176 | 169 | * Eagerly enqueue the CSS on shell pages. |
| 177 | - * | |
| 178 | - * @since 0.26.0 | |
| 179 | 170 | */ |
| 180 | -function desktop_mode_enqueue_post_stats_widget_styles() { | |
| 181 | - if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) { | |
| 171 | +function openstation_enqueue_post_stats_widget_styles() { | |
| 172 | + if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled() ) { | |
| 182 | 173 | return; |
| 183 | 174 | } |
| 184 | - if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) { | |
| 175 | + if ( function_exists( 'openstation_is_chromeless_request' ) && openstation_is_chromeless_request() ) { | |
| 185 | 176 | return; |
| 186 | 177 | } |
| 187 | - wp_enqueue_style( 'desktop-mode-post-stats-widget' ); | |
| 178 | + wp_enqueue_style( 'os-post-stats-widget' ); | |
| 188 | 179 | } |
| 189 | -add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_post_stats_widget_styles', 20 ); | |
| 180 | +add_action( 'admin_enqueue_scripts', 'openstation_enqueue_post_stats_widget_styles', 20 ); | |
| 190 | 181 | |
| 191 | 182 | /** |
| 192 | 183 | * Register the widget definition. |
| 193 | - * | |
| 194 | - * @since 0.26.0 | |
| 195 | 184 | */ |
| 196 | -function desktop_mode_register_post_stats_widget() { | |
| 197 | - if ( ! function_exists( 'desktop_mode_register_widget' ) ) { | |
| 185 | +function openstation_register_post_stats_widget() { | |
| 186 | + if ( ! function_exists( 'openstation_register_widget' ) ) { | |
| 198 | 187 | return; |
| 199 | 188 | } |
| 200 | - desktop_mode_register_widget( | |
| 189 | + openstation_register_widget( | |
| 201 | 190 | 'desktop-mode/post-stats', |
| 202 | 191 | array( |
| 203 | 192 | 'label' => __( 'Post Stats', 'desktop-mode' ), |
| 204 | 193 | 'description' => __( 'Bar chart of posts per month over the last 6 months.', 'desktop-mode' ), |
| 205 | 194 | 'icon' => 'dashicons-chart-bar', |
| 206 | - 'script' => 'desktop-mode-post-stats-widget', | |
| 195 | + 'script' => 'os-post-stats-widget', | |
| 207 | 196 | 'movable' => true, |
| 208 | 197 | 'resizable' => true, |
| 209 | 198 | 'min_width' => 260, |
| 210 | 199 | 'min_height' => 200, |
| @@ -212,5 +201,5 @@ | ||
| 212 | 201 | 'default_height' => 260, |
| 213 | 202 | ) |
| 214 | 203 | ); |
| 215 | 204 | } |
| 216 | -add_action( 'init', 'desktop_mode_register_post_stats_widget', 6 ); | |
| 205 | +add_action( 'init', 'openstation_register_post_stats_widget', 6 ); | |