Skip to content

Commit ff36248

Browse files
dd32claude
andauthored
Jetpack CRM: Ensure admin color schemes have at least 4 color entries (WordPress#1700)
* Jetpack CRM: Ensure admin color schemes have at least 4 color entries Workaround for zero-bs-crm accessing index 3 of admin color scheme colors array when some schemes only define 3 colors. Only applies when CRM is active (ZBS_PLUGIN_DIR defined). See Automattic/jetpack#47143 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix PHPCS linting errors in crm.php - One argument per line in multi-line function calls - Avoid count() inside loop condition Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 681ae82 commit ff36248

File tree

1 file changed

+40
-0
lines changed
  • public_html/wp-content/mu-plugins/jetpack-tweaks

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace WordCamp\Jetpack_Tweaks;
4+
5+
defined( 'WPINC' ) || die();
6+
7+
/**
8+
* Ensure admin color schemes have at least 4 color entries.
9+
*
10+
* Workaround for zero-bs-crm accessing index 3 of `$_wp_admin_css_colors[scheme]->colors`
11+
* when some color schemes only define 3 colors.
12+
*
13+
* @see ZeroBSCRM.AdminStyling.php:264
14+
* @see https://github.com/Automattic/jetpack/pull/47143
15+
*/
16+
add_action(
17+
'admin_head',
18+
function () {
19+
if ( ! defined( 'ZBS_PLUGIN_DIR' ) ) {
20+
return;
21+
}
22+
23+
global $_wp_admin_css_colors;
24+
25+
$current_color = get_user_option( 'admin_color' );
26+
27+
if ( ! isset( $_wp_admin_css_colors[ $current_color ] ) ) {
28+
return;
29+
}
30+
31+
$colors = &$_wp_admin_css_colors[ $current_color ]->colors;
32+
$color_count = count( $colors );
33+
34+
while ( $color_count < 4 ) {
35+
$colors[] = end( $colors );
36+
$color_count++;
37+
}
38+
},
39+
9
40+
);

0 commit comments

Comments
 (0)