Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | /** |
| 3 | * Change the Site Editor's dashboard link. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * This file provide a feature to override the Site Editor's dashboard link. |
| 10 | * |
| 11 | * @package automattic/jetpack-mu-wpcom |
| 12 | */ |
| 13 | |
| 14 | require_once __DIR__ . '/../../utils.php'; |
| 15 | |
| 16 | add_filter( |
| 17 | 'block_editor_settings_all', |
| 18 | function ( $settings ) { |
| 19 | $calypso_origin = wpcom_get_calypso_origin(); |
| 20 | $wpcom_dashboard_link = esc_url_raw( wp_unslash( $_GET['wpcom_dashboard_link'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 21 | |
| 22 | // Point the `<` link to the `wpcom_dashboard_link` if the relative path is provided. |
| 23 | if ( ! empty( $wpcom_dashboard_link ) ) { |
| 24 | $parsed_url = wp_parse_url( $wpcom_dashboard_link ); |
| 25 | if ( ! isset( $parsed_url['host'] ) ) { |
| 26 | $settings['__experimentalDashboardLink'] = $calypso_origin . $wpcom_dashboard_link; |
| 27 | return $settings; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // On sites with Classic view, don't override the dashboard link. |
| 32 | if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) { |
| 33 | return $settings; |
| 34 | } |
| 35 | |
| 36 | if ( ! empty( $_GET['wp_theme_preview'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 37 | // Point the `<` link to the theme showcase when previewing a theme. |
| 38 | $settings['__experimentalDashboardLink'] = $calypso_origin . '/themes/' . wpcom_get_site_slug(); |
| 39 | } else { |
| 40 | // Point the `<` link to wpcom home. |
| 41 | $settings['__experimentalDashboardLink'] = $calypso_origin . '/home/' . wpcom_get_site_slug(); |
| 42 | } |
| 43 | return $settings; |
| 44 | } |
| 45 | ); |