diff --git a/README.txt b/README.txt index f433e4a..1e1a5e2 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Tags: woocommerce, discount, email, shipping, coupon Requires at least: 5.8 Tested up to: 7.1 Requires PHP: 7.4 -Stable tag: 1.5.2 +Stable tag: 1.5.3 WC requires at least: 6.0 WC tested up to: 11.1.0 License: GPLv2 or later diff --git a/ci/plugin.conf b/ci/plugin.conf index 3c86062..cf20677 100644 --- a/ci/plugin.conf +++ b/ci/plugin.conf @@ -75,7 +75,11 @@ RELEASE_REPO=kw/nolimit-discounts-dist # The frozen hash is therefore a family-wide fact, not a local one, and taking # a new one is something all six do in the same window. # -# 678f1f03 = contract 1.2.1: the glyph is centred with flex inside an explicit +# 471b0a2a = contract 1.2.2: the icon box is sized 100%/100% instead of a +# hardcoded 36x34. WordPress declares that parent three times and they +# disagree (36x34 open, 35x30 folded, 34x30 under 960px), so a fixed number is +# right in one state and wrong in the two a laptop is usually in. +# Withdrawn: 678f1f03 = 1.2.1: the glyph is centred with flex inside an explicit # 36x34 box instead of inheriting WordPress's 7px padding, which made the # pseudo-element 42px tall inside a 34px parent and pushed the sign above # centre. Kristian reported it from the live shop. @@ -87,4 +91,4 @@ RELEASE_REPO=kw/nolimit-discounts-dist # backslashes, hex digits and spaces, so there is nothing left to leave the # string with. Verified here against seven hostile inputs. # Earlier frozen hashes: 184cebdc = 1.1.0, f4862d5c = 1.0.0. -WPMGR_MENU_SHA=678f1f0368fcc781ce34c0289f6470a6bb0491bc32c0598e859c7ceba66e5e2a +WPMGR_MENU_SHA=471b0a2aab47b6b7f8d839ac8b12d60637bbe2c07df86f7e40089c677fbab3cc diff --git a/includes/shared-menu.php b/includes/shared-menu.php index 9a87024..b62c271 100644 --- a/includes/shared-menu.php +++ b/includes/shared-menu.php @@ -69,7 +69,7 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( ! defined( 'WPMGR_MENU_VERSION' ) ) { - define( 'WPMGR_MENU_VERSION', '1.2.1' ); + define( 'WPMGR_MENU_VERSION', '1.2.2' ); } if ( ! defined( 'WPMGR_MENU_SLUG' ) ) { @@ -164,19 +164,41 @@ if ( ! function_exists( 'wpmgr_ensure_menu' ) ) { * 🔴 The box is WordPress's own, measured rather than guessed, and the * glyph is centred in it geometrically rather than nudged. * - * wp-admin/css/admin-menu.css sets `#adminmenu div.wp-menu-image` to - * 36x34, and `div.wp-menu-image:before` to `padding: 7px 0` — which is - * exactly 7 + 20 + 7 for a 20px dashicon on `line-height: 1`. The first - * version of this rule set `line-height: 1.4` and inherited that padding, - * making the line box 28px and the whole pseudo-element 42px inside a 34px - * parent. Kristian reported the result: the glyph sitting above centre. + * wp-admin/css/admin-menu.css sets `div.wp-menu-image:before` to + * `padding: 7px 0` — exactly 7 + 20 + 7 for a 20px dashicon on + * `line-height: 1` in a 34px box. The first version of this rule set + * `line-height: 1.4` and inherited that padding, making the line box 28px + * and the whole pseudo-element 42px inside a 34px parent. Kristian + * reported the result: the glyph sitting above centre. * - * So: reproduce the 36x34 box, drop the padding that only existed to - * position a 20px line inside it, and centre with flex. That matters more - * for an arbitrary glyph than for a dashicon — U+221E sits on the maths - * axis rather than filling its em box, so any rule that positions by - * line-height and padding is positioning the box and hoping about the - * glyph. `align-items: center` centres what is actually drawn. + * So: drop the padding that only existed to position a 20px line, and + * centre with flex. That matters more for an arbitrary glyph than for a + * dashicon — U+221E sits on the maths axis rather than filling its em box, + * so any rule that positions by line-height and padding is positioning the + * box and hoping about the glyph. `align-items: center` centres what is + * actually drawn, which is also what keeps working if anyone returns + * something else from `wpmgr_menu_glyph`. + * + * 🔴 `100%%`, not `100%`. This is a printf format string, so a literal + * per-cent sign has to be doubled — and the first version of the + * percentage fix did not, which is a **fatal on every admin page**: + * "Uncaught ValueError: Unknown format specifier". Three sessions agreed + * on that file after reading it, linting it and running PHPCS over it, and + * all three are blind to this: the syntax is valid and the standard has + * nothing to say. Only running the function finds it, and it was the site + * test that did. The fixed-pixel version could not have had this fault, + * so it arrived with the improvement. + * + * 🔴 The size is `100%`, not the 36x34 the desktop menu happens to be. + * That stylesheet declares the parent THREE times and they disagree: + * `#adminmenu div.wp-menu-image` is 36x34, `.folded #adminmenu + * div.wp-menu-image` is 35x30, and under `@media (max-width: 960px)` + * `.auto-fold #adminmenu div.wp-menu-image` is 34x30. A pseudo-element + * fixed at 36x34 is therefore correct on a wide screen with the menu open + * and 4px too tall in both of the other states — which are the states a + * laptop is in. Percentages resolve against whichever parent is in force, + * so there is no number here to be right about. Measured by reading that + * stylesheet, not by eye. */ function wpmgr_menu_glyph_style() { $glyph = apply_filters( 'wpmgr_menu_glyph', '∞' ); @@ -187,7 +209,7 @@ if ( ! function_exists( 'wpmgr_ensure_menu' ) ) { // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- the slug is reduced to [a-z0-9_-] and the glyph to CSS numeric escapes; both are escaped for the context they are printed in, which is CSS rather than HTML. printf( - '', + '', preg_replace( '/[^a-z0-9_-]/', '', strtolower( WPMGR_MENU_SLUG ) ), wpmgr_css_escape( $glyph ) ); diff --git a/tests/smoke.php b/tests/smoke.php index 0dc1e8f..49adf63 100644 --- a/tests/smoke.php +++ b/tests/smoke.php @@ -317,6 +317,38 @@ wc_edm_is( isset( $wc_edm_mine[0]['colour'] ) ? $wc_edm_mine[0]['colour'] : null ); +// 🔴 The style function is INVOKED, not read. A version of this file shipped +// with `width:100%` inside a printf format string, where a literal per-cent +// must be doubled — an uncaught ValueError on every admin page. Three sessions +// read it, php -l was clean, PHPCS was clean, and two browsers agreed about +// the CSS, because all of them were fed the stylesheet by hand rather than +// through the PHP that produces it. Only running it finds this. +if ( function_exists( 'wpmgr_menu_glyph_style' ) ) { + $wc_edm_threw = ''; + ob_start(); + try { + wpmgr_menu_glyph_style(); + } catch ( \Throwable $e ) { + $wc_edm_threw = get_class( $e ) . ': ' . $e->getMessage(); + } + $wc_edm_style = ob_get_clean(); + + wc_edm_ok( + 'emitting the menu glyph style throws nothing', + '' === $wc_edm_threw, + $wc_edm_threw + ); + wc_edm_ok( + 'and what it emits is a style element carrying the glyph', + false !== strpos( $wc_edm_style, '' ) + && false !== strpos( $wc_edm_style, '\\221E' ), + 'emitted: ' . substr( $wc_edm_style, 0, 120 ) + ); +} else { + echo "::warning::wpmgr_menu_glyph_style() is not defined, so the glyph style was not exercised.\n"; +} + // The frozen hash of includes/shared-menu.php is asserted in ci/static.sh // against WPMGR_MENU_SHA in ci/plugin.conf, and deliberately NOT repeated // here: two copies of the same constant drift, and the one that drifts is the diff --git a/woocommerce-email-discount-manager.php b/woocommerce-email-discount-manager.php index 9b2a471..f240c02 100644 --- a/woocommerce-email-discount-manager.php +++ b/woocommerce-email-discount-manager.php @@ -4,7 +4,7 @@ * Plugin URI: https://gitea.nolimit.dk/kw/woo-discount-manager * Update URI: https://gitea.nolimit.dk/kw/nolimit-discounts-dist * Description: Apply discounts and show/hide shipping methods based on the customer's email address (full address, domain or partial match). - * Version: 1.5.2 + * Version: 1.5.3 * Author: Kristian Wind * Author URI: https://gitea.nolimit.dk/kw * License: GPL-2.0-or-later @@ -28,7 +28,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'WC_EDM_VERSION', '1.5.2' ); +define( 'WC_EDM_VERSION', '1.5.3' ); define( 'WC_EDM_PLUGIN_FILE', __FILE__ ); define( 'WC_EDM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'WC_EDM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );