← All changes
|
jetpack_vendor/automattic/jetpack-blaze/src/class-dashboard.php
+41
-7
13.0.2
→
16.3
View file →
| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | * Package version. |
| 21 | 21 | * |
| 22 | 22 | * @var string |
| 23 | 23 | */ |
| 24 | - const PACKAGE_VERSION = '0.14.3'; | |
| 24 | + const PACKAGE_VERSION = '0.29.8'; | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * List of dependencies needed to render the dashboard in wp-admin. |
| 28 | 28 | * |
| @@ -58,8 +58,42 @@ | ||
| 58 | 58 | */ |
| 59 | 59 | const BLAZEDASH_CACHE_BUSTER_CACHE_KEY = 'jetpack_blaze_admin_asset_cache_buster'; |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | + * Blaze dashboard admin page. Default is admin.php. | |
| 63 | + * | |
| 64 | + * @var string | |
| 65 | + */ | |
| 66 | + private $admin_page; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Blaze dashboard menu slug. Default is 'advertising'. | |
| 70 | + * | |
| 71 | + * @var string | |
| 72 | + */ | |
| 73 | + private $menu_slug; | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Blaze dashboard css prefix. Default is 'jp-blaze'. | |
| 77 | + * | |
| 78 | + * @var string | |
| 79 | + */ | |
| 80 | + private $css_prefix; | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Dashboard constructor. | |
| 84 | + * | |
| 85 | + * @param string $admin_page Dashboard admin page. Default is admin.php. | |
| 86 | + * @param string $menu_slug Dashboard menu slug. Default is 'advertising'. | |
| 87 | + * @param string $css_prefix Dashboard css prefix. Default is 'jp-blaze'. | |
| 88 | + */ | |
| 89 | + public function __construct( $admin_page = 'admin.php', $menu_slug = 'advertising', $css_prefix = 'jp-blaze' ) { | |
| 90 | + $this->admin_page = $admin_page; | |
| 91 | + $this->menu_slug = $menu_slug; | |
| 92 | + $this->css_prefix = $css_prefix; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 62 | 96 | * Override render funtion |
| 63 | 97 | * |
| 64 | 98 | * @return void |
| 65 | 99 | */ |
| @@ -64,13 +98,13 @@ | ||
| 64 | 98 | * @return void |
| 65 | 99 | */ |
| 66 | 100 | public function render() { |
| 67 | 101 | ?> |
| 68 | - <div id="wpcom" class="jp-blaze-dashboard" style="min-height: calc(100vh - 100px);"> | |
| 69 | - <div class="hide-if-js"><?php esc_html_e( 'Your Jetpack Blaze dashboard requires JavaScript to function properly.', 'jetpack-blaze' ); ?></div> | |
| 102 | + <div id="wpcom" class="<?php echo esc_attr( $this->css_prefix ); ?>-dashboard" style="min-height: calc(100vh - 100px);"> | |
| 103 | + <div class="hide-if-js"><?php esc_html_e( 'Your Jetpack Blaze dashboard requires JavaScript to function properly.', 'jetpack-blaze' ); ?></div> | |
| 70 | 104 | <div class="hide-if-no-js" style="height: 100%"> |
| 71 | 105 | <img |
| 72 | - class="jp-blaze-dashboard-loading-spinner" | |
| 106 | + class="<?php echo esc_attr( $this->css_prefix ); ?>-dashboard-loading-spinner" | |
| 73 | 107 | width="32" |
| 74 | 108 | height="32" |
| 75 | 109 | style="position: absolute; left: 50%; top: 50%;" |
| 76 | 110 | alt=<?php echo esc_attr( __( 'Loading', 'jetpack-blaze' ) ); ?> |
| @@ -89,9 +123,9 @@ | ||
| 89 | 123 | }); |
| 90 | 124 | // we intercept on all anchor tags and change it to hashbang style. |
| 91 | 125 | $("#wpcom").on('click', 'a', function (e) { |
| 92 | 126 | const link = e && e.currentTarget && e.currentTarget.attributes && e.currentTarget.attributes.href && e.currentTarget.attributes.href.value; |
| 93 | - if( link && link.startsWith( '/advertising' ) ) { | |
| 127 | + if (link && link.startsWith( '/<?php echo esc_attr( $this->menu_slug ); ?>' ) ) { | |
| 94 | 128 | location.hash = `#!${link}`; |
| 95 | 129 | return false; |
| 96 | 130 | } |
| 97 | 131 | }); |
| @@ -112,9 +146,9 @@ | ||
| 112 | 146 | * |
| 113 | 147 | * @param string $hook The current admin page. |
| 114 | 148 | */ |
| 115 | 149 | public function load_admin_scripts( $hook ) { |
| 116 | - if ( 'tools_page_advertising' !== $hook ) { | |
| 150 | + if ( ! str_ends_with( $hook, 'page_' . $this->menu_slug ) ) { | |
| 117 | 151 | return; |
| 118 | 152 | } |
| 119 | 153 | |
| 120 | 154 | $asset_handle = self::SCRIPT_HANDLE; |
| @@ -119,9 +153,9 @@ | ||
| 119 | 153 | |
| 120 | 154 | $asset_handle = self::SCRIPT_HANDLE; |
| 121 | 155 | $asset_name = 'build.min'; |
| 122 | 156 | |
| 123 | - $dashboard_config = new Dashboard_Config_Data(); | |
| 157 | + $dashboard_config = new Dashboard_Config_Data( $this->admin_page, $this->menu_slug ); | |
| 124 | 158 | |
| 125 | 159 | $config_data = $dashboard_config->get_data(); |
| 126 | 160 | |
| 127 | 161 | if ( file_exists( __DIR__ . "/../dist/{$asset_name}.js" ) ) { |