Skip to content

Commit

Permalink
Add warning in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieur-z committed May 9, 2024
1 parent 0463cf2 commit 2e0af3a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
40 changes: 40 additions & 0 deletions projects/plugins/jetpack/modules/custom-css/custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static function add_hooks() {

add_action( 'wp_enqueue_scripts', array( __CLASS__, 'wp_enqueue_scripts' ) );
add_action( 'admin_footer', array( __CLASS__, 'update_initial_state' ) );
add_action( 'wp_body_open', array( __CLASS__, 'display_frontend_warning' ) );

// Handle Sass/LESS.
add_filter( 'customize_value_custom_css', array( __CLASS__, 'customize_value_custom_css' ), 10, 2 );
Expand Down Expand Up @@ -1005,6 +1006,45 @@ public static function jetpack_content_width( $content_width ) {
return $content_width;
}

/**
* Display a deprecation warning on the frontend for site admins only
*/
public static function display_frontend_warning() {
if ( ! current_user_can( 'edit_themes' ) || ! current_user_can( 'edit_theme_options' ) ) {
return;
}

$notice = '';
$notice .= '<div class="jp-custom-css__deprecation-warning">';
$notice .= '<p>' . wp_kses(
sprintf(
// translators: 1: URL to the CSS customization panel, 2: URL to the theme stylesheet documentation.
__(
'The <i>Start Fresh</i> option in the <a href="%1$s">CSS customization panel</a> is enabled, which means the theme\'s original CSS is not applied. <b>This option will no longer be supported after August 6, 2024</b> and you\'ll need to modify your <a href="%2$s">theme stylesheet</a>.',
'jetpack'
),
esc_url( admin_url( 'customize.php?autofocus%5Bsection%5D=custom_css' ) ),
esc_url( 'https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/' )
),
array(
'i' => array(),
'b' => array(),
'a' => array(
'href' => array(),
'target' => array(),
),
)
) . '</p>';
$notice .= '<button aria-label="' . esc_html__( 'Dismiss', 'jetpack' ) . '">&times;</button>';
$notice .= '</div>';
$notice .= '<script>';
$notice .= 'document.querySelector(".jp-custom-css__deprecation-warning button").addEventListener("click", (e) => e.currentTarget.parentNode.remove() );';
$notice .= '</script>';

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $notice;
}

/**
* Update the initial state to include the `replace` option (Start Fresh) in the module data.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
/* */
/* */
.jp-custom-css__deprecation-warning {
position: absolute;
top: 2.5rem;
left: 50%;
z-index: 99999;
transform: translateX( -50% );

display: flex;
align-items: flex-start;
width: 80ch;

background-color: #fef8ee;
border: solid 1px #ccc;
border-left: solid 5px #f0b849;
box-shadow: 0 0 4px 4px rgba( 0, 0, 0, 0.1 );

font-size: 1rem;
}

.jp-custom-css__deprecation-warning p {
margin: 0;
padding: 1em;
}

.jp-custom-css__deprecation-warning button {
min-width: 48px;
min-height: 48px;

border-color: transparent;
background-color: transparent;

font-size: 1.25rem;
font-weight: bold;
}

0 comments on commit 2e0af3a

Please sign in to comment.