Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| WP_Dashboard_Odyssey_Widget | |
0.00% |
0 / 30 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| render | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| load_admin_scripts | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| maybe_load_admin_scripts | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| is_widget_hidden | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A class that adds Jetpack Stats widget for WP Dashboard. |
| 4 | * |
| 5 | * @package automattic/jetpack-stats-admin |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Stats_Admin; |
| 9 | |
| 10 | /** |
| 11 | * Responsible for loading Jetpack Stats widget for WP Dashboard. |
| 12 | * |
| 13 | * @package jetpack-stats-admin |
| 14 | */ |
| 15 | class WP_Dashboard_Odyssey_Widget { |
| 16 | const DASHBOARD_WIDGET_ID = 'jetpack_summary_widget'; |
| 17 | |
| 18 | /** |
| 19 | * Renders the widget and fires a dashboard widget action. |
| 20 | */ |
| 21 | public function render() { |
| 22 | // The widget is always rendered, so if it was hidden and then toggled open, we need to ask user to refresh the page to load data properly. |
| 23 | $is_toggled_open = $this->is_widget_hidden(); |
| 24 | ?> |
| 25 | <div id="dashboard_stats" class="jp-stats-widget" style="min-height: 200px;"> |
| 26 | <div class="hide-if-js"><?php esc_html_e( 'Your Jetpack Stats widget requires JavaScript to function properly.', 'jetpack-stats-admin' ); ?></div> |
| 27 | <div class="hide-if-no-js" style="height: 100%"> |
| 28 | <img |
| 29 | class="jp-stats-widget-loading-spinner" |
| 30 | width="32" |
| 31 | height="32" |
| 32 | style="position: absolute; left: calc(50% - 28px); top: calc(50% - 36px);" |
| 33 | alt=<?php echo esc_attr( __( 'Loading', 'jetpack-stats-admin' ) ); ?> |
| 34 | src="//en.wordpress.com/i/loading/loading-64.gif" |
| 35 | /> |
| 36 | <p> |
| 37 | <?php |
| 38 | if ( $is_toggled_open ) { |
| 39 | echo esc_html__( 'Please reload the page to see your stats...', 'jetpack-stats-admin' ); |
| 40 | } |
| 41 | ?> |
| 42 | </p> |
| 43 | </div> |
| 44 | </div> |
| 45 | <?php |
| 46 | /** |
| 47 | * Fires when the dashboard is loaded, but no longer used anywhere in the Jetpack plugin. |
| 48 | * The action is still available for backward compatibility. |
| 49 | * |
| 50 | * @since 3.4.0 |
| 51 | */ |
| 52 | do_action( 'jetpack_dashboard_widget' ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Load the admin scripts. |
| 57 | */ |
| 58 | public function load_admin_scripts() { |
| 59 | $config_data = ( new Odyssey_Config_Data() )->get_data(); |
| 60 | ( new Odyssey_Assets() )->load_admin_scripts( |
| 61 | 'jetpack_stats_widget', |
| 62 | 'widget-loader.min', |
| 63 | array( |
| 64 | 'config_variable_name' => 'jetpackStatsOdysseyWidgetConfigData', |
| 65 | 'config_data' => $config_data, |
| 66 | 'enqueue_css' => false, |
| 67 | ) |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Load the admin scripts when the widget is visible. |
| 73 | */ |
| 74 | public function maybe_load_admin_scripts() { |
| 75 | if ( $this->is_widget_hidden() ) { |
| 76 | return; |
| 77 | } |
| 78 | $this->load_admin_scripts(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns true if the widget is hidden for the current screen and current user. |
| 83 | * |
| 84 | * @return bool |
| 85 | */ |
| 86 | public function is_widget_hidden() { |
| 87 | $hidden = get_hidden_meta_boxes( get_current_screen() ); |
| 88 | return in_array( self::DASHBOARD_WIDGET_ID, $hidden, true ); |
| 89 | } |
| 90 | } |