Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.88% |
2 / 41 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Image_Guide | |
4.88% |
2 / 41 |
|
40.00% |
2 / 5 |
115.14 | |
0.00% |
0 / 1 |
| setup | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
42 | |||
| get_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| enqueue_assets | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
| add_to_adminbar | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| is_available | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules\Image_Guide; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Admin\Admin; |
| 6 | use Automattic\Jetpack_Boost\Contracts\Feature; |
| 7 | use Automattic\Jetpack_Boost\Lib\Analytics; |
| 8 | |
| 9 | class Image_Guide implements Feature { |
| 10 | |
| 11 | public function setup() { |
| 12 | if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { |
| 13 | Image_Guide_Proxy::init(); |
| 14 | } |
| 15 | |
| 16 | // Show the UI only when the user is logged in, with sufficient permissions and isn't looking at the dashboard. |
| 17 | if ( is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | // Enqueue the tracks library. |
| 22 | add_action( 'wp_enqueue_scripts', array( Analytics::class, 'init_tracks_scripts' ) ); |
| 23 | |
| 24 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 25 | |
| 26 | /** |
| 27 | * The priority determines where the admin bar menu item is placed. |
| 28 | */ |
| 29 | add_action( 'admin_bar_menu', array( $this, 'add_to_adminbar' ), 500 ); |
| 30 | } |
| 31 | |
| 32 | public static function get_slug() { |
| 33 | return 'image_guide'; |
| 34 | } |
| 35 | |
| 36 | public function enqueue_assets() { |
| 37 | wp_enqueue_script( 'jetpack-boost-guide', plugins_url( 'dist/guide.min.js', __FILE__ ), array( 'wp-i18n' ), JETPACK_BOOST_VERSION, true ); |
| 38 | wp_enqueue_style( 'jetpack-boost-guide', plugins_url( 'dist/guide.min.css', __FILE__ ), array(), JETPACK_BOOST_VERSION, 'screen' ); |
| 39 | |
| 40 | wp_localize_script( |
| 41 | 'jetpack-boost-guide', |
| 42 | 'jetpackBoostAnalytics', |
| 43 | array( |
| 44 | 'tracksData' => Analytics::get_tracking_data(), |
| 45 | ) |
| 46 | ); |
| 47 | wp_localize_script( |
| 48 | 'jetpack-boost-guide', |
| 49 | 'jbImageGuide', |
| 50 | array( |
| 51 | 'proxyNonce' => wp_create_nonce( Image_Guide_Proxy::NONCE_ACTION ), |
| 52 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 53 | ) |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param \WP_Admin_Bar $bar |
| 59 | */ |
| 60 | public function add_to_adminbar( $bar ) { |
| 61 | // Disable in Admin Dashboard |
| 62 | if ( is_admin() ) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | $bar->add_menu( |
| 67 | array( |
| 68 | 'id' => 'jetpack-boost-guide', |
| 69 | 'parent' => null, |
| 70 | 'group' => null, |
| 71 | 'title' => 'Jetpack Boost', // "Jetpack Boost" is a product name, do not translate. |
| 72 | 'href' => admin_url( 'admin.php?page=' . Admin::MENU_SLUG ), |
| 73 | 'meta' => array( |
| 74 | 'target' => '_self', |
| 75 | 'class' => 'jetpack-boost-guide', |
| 76 | ), |
| 77 | ) |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | public static function is_available() { |
| 82 | return true; |
| 83 | } |
| 84 | } |