1 || ( $parents && ! self::is_leanmerce_parent( $parents[0] ) ) ) { self::$status = 'BLOCKED — SHARED_PARENT_COLLISION'; add_action( 'admin_notices', array( self::class, 'notice' ) ); return false; } if ( $parents ) { // Another Leanmerce plugin created the parent: leave its icon, callback, // capability and menu order untouched. Child ownership is independent. return true; } $capability = current_user_can( Capabilities::MANAGE_SETTINGS ) ? Capabilities::MANAGE_SETTINGS : Capabilities::RUN_DIAGNOSTICS; if ( ! current_user_can( $capability ) ) { return false; } add_menu_page( __( 'Leanmerce', 'leanmerce-commerce-assistant' ), __( 'Leanmerce', 'leanmerce-commerce-assistant' ), $capability, self::PARENT_SLUG, array( self::class, 'landing' ), self::icon_data_uri(), 58.6 ); self::$created = true; return true; } /** @param string[] $slugs Plugin-owned legacy routes. */ public static function routes_available( array $slugs ): bool { global $submenu, $wp_filter; foreach ( (array) $submenu as $rows ) { foreach ( $rows as $row ) { if ( in_array( $row[2], $slugs, true ) ) { return self::route_collision(); } } } foreach ( $slugs as $slug ) { if ( isset( $wp_filter[ get_plugin_page_hookname( $slug, self::PARENT_SLUG ) ] ) || isset( $wp_filter[ get_plugin_page_hookname( $slug, '' ) ] ) ) { return self::route_collision(); } } return true; } private static function route_collision(): bool { self::$status = 'BLOCKED — SHARED_PARENT_COLLISION'; add_action( 'admin_notices', array( self::class, 'notice' ) ); return false; } /** * Recognize the common Leanmerce menu from WordPress's registered menu row. * * Leanmerce sibling plugins may use different callbacks, class names and * source files across versions. A specific callback or PHP file hash is NOT * the shared admin menu contract. The slug and branded WordPress menu title * identify the shared navigation container; each child still enforces its * own capability and request authorization. Unknown or duplicate menu roots * remain fail-closed without taking ownership of an existing registration. * * @param array $row Registered WordPress top-level menu row. */ private static function is_leanmerce_parent( array $row ): bool { if ( self::PARENT_SLUG !== ( $row[2] ?? null ) ) { return false; } foreach ( array( 0, 3 ) as $field ) { if ( ! isset( $row[ $field ] ) || ! is_string( $row[ $field ] ) ) { continue; } if ( 'Leanmerce' === trim( wp_strip_all_tags( $row[ $field ] ) ) ) { return true; } } return false; } public static function remove_own_duplicate(): void { if ( self::$created ) { remove_submenu_page( self::PARENT_SLUG, self::PARENT_SLUG ); } } public static function icon_data_uri(): string { // Exact embedded bytes from the pinned Purchase Planner 1.0.1 registry. $svg = ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Local pinned SVG transport required by WordPress menu icons. } public static function landing(): void { global $submenu; if ( ! current_user_can( Capabilities::MANAGE_SETTINGS ) && ! current_user_can( Capabilities::RUN_DIAGNOSTICS ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'leanmerce-commerce-assistant' ), '', array( 'response' => 403 ) ); } echo '
Leanmerce: ' . esc_html( self::$status ) . ' ' . esc_html( self::status_message() ) . '