*/ private static function by_id(): array { return array( /* translators: %d: order number. */ 'order' => __( 'Order #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: order number. */ 'refund' => __( 'Refund on order #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: order number. */ 'order_note' => __( 'Note on order #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: order number. */ 'order_fulfillment' => __( 'Fulfillment on order #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: variation id. */ 'product_variation' => __( 'Variation #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: coupon id. */ 'coupon' => __( 'Coupon #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %d: customer id. */ 'customer' => __( 'Customer #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), ); } /** * Label patterns by entity type, for a target named by its route slug. * * @return array */ private static function by_slug(): array { return array( /* translators: %s: setting id. */ 'wc_setting' => __( 'Store setting %s', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), /* translators: %s: payment gateway id. */ 'payment_gateway' => __( 'Payment gateway %s', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), ); } /** * The label, or null when there is nothing to name. * * @param ActionDescriptor $action The classified action. */ public function __invoke( ActionDescriptor $action ): ?string { $id = $action->entity_id; if ( 'product' === $action->entity_type && null !== $id ) { $title = get_the_title( $id ); return '' === $title /* translators: %d: product id. */ ? sprintf( __( 'Product #%d', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), $id ) /* translators: 1: product name, 2: product id. */ : sprintf( __( 'Product "%1$s" (#%2$d)', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), $title, $id ); } $by_id = self::by_id(); if ( null !== $id && isset( $by_id[ $action->entity_type ] ) ) { return sprintf( $by_id[ $action->entity_type ], $id ); } $slug = self::slug( $action ); $by_slug = self::by_slug(); if ( null !== $slug && isset( $by_slug[ $action->entity_type ] ) ) { return sprintf( $by_slug[ $action->entity_type ], $slug ); } return null; } /** * Last route segments that name a collection or an operation, not a * setting or gateway. */ private const NOT_NAMES = array( 'batch', 'settings', 'payment_gateways', 'payment-gateways', 'options', 'payments' ); /** * The last segment of the route, when it is a name and not an id. * * @param ActionDescriptor $action The classified action. */ private static function slug( ActionDescriptor $action ): ?string { if ( null !== $action->entity_slug ) { return $action->entity_slug; } if ( null === $action->route || 1 !== preg_match( '#/([a-z0-9_-]+)/?$#i', $action->route, $matches ) || ctype_digit( $matches[1] ) || in_array( strtolower( $matches[1] ), self::NOT_NAMES, true ) ) { return null; } return $matches[1]; } }