Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
maybe_show_wpcom_toolbar_proxy_notice
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/**
3 * Custom notices for wp-admin/profile.php
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8/**
9 * Adds a notice for Automatticians informing them that the Toolbar always shows on the front end on Atomic sites if
10 * they are connected to Autoproxxy.
11 */
12function maybe_show_wpcom_toolbar_proxy_notice() {
13    $is_proxied = isset( $_SERVER['A8C_PROXIED_REQUEST'] )
14            ? sanitize_text_field( wp_unslash( $_SERVER['A8C_PROXIED_REQUEST'] ) )
15            : defined( 'A8C_PROXIED_REQUEST' ) && A8C_PROXIED_REQUEST;
16    $is_atomic  = defined( 'IS_ATOMIC' ) && IS_ATOMIC;
17
18    if ( $is_proxied && $is_atomic ) {
19        ?>
20        <script type="text/javascript">
21            document.addEventListener('DOMContentLoaded', function () {
22                // Find the Toolbar checkbox label container using the unique ID.
23                var toolbarCell = document.querySelector('.user-admin-bar-front-wrap')?.querySelector('td');
24                if (toolbarCell) {
25                    // Create a new paragraph for the notice.
26                    var notice = document.createElement('p');
27                    notice.className = 'description';
28                    notice.textContent = <?php echo wp_json_encode( __( 'The Toolbar is always visible on Atomic sites while connected to the Automattic proxy.', 'jetpack-mu-wpcom' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
29
30                    // Insert the new div after the checkbox and label.
31                    toolbarCell.appendChild(notice);
32                }
33            });
34        </script>
35        <?php
36    }
37}
38
39add_action( 'admin_footer-profile.php', 'maybe_show_wpcom_toolbar_proxy_notice' );