pending() ); } /** * Pure evaluation. * * @param bool $hpos Whether HPOS is the authoritative order storage. * @param bool $sync Whether compatibility mode (sync) is on. * @param int|null $pending Orders waiting to be synced; null if unknown. * @return Result[] */ public static function evaluate( bool $hpos, bool $sync, ?int $pending ): array { $url = admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=features' ); if ( $sync && null !== $pending && $pending > 0 ) { return array( new Result( 'woocommerce.hpos', Result::RECOMMENDED, /* translators: %d: number of orders */ sprintf( _n( '%d order is waiting to be synced between order tables', '%d orders are waiting to be synced between order tables', $pending, 'keepwatch' ), $pending ), __( 'Compatibility mode is on but the two order storages are not in sync yet. Do not switch order storage until the sync has finished.', 'keepwatch' ), $url, __( 'Order storage settings', 'keepwatch' ) ), ); } return array( new Result( 'woocommerce.hpos', Result::GOOD, $hpos ? __( 'Orders use High-Performance Order Storage', 'keepwatch' ) : __( 'Orders use the WordPress posts storage', 'keepwatch' ) ), ); } /** * Orders pending sync, via WooCommerce's own synchronizer when available. */ private function pending(): ?int { if ( ! function_exists( 'wc_get_container' ) ) { return null; } try { $synchronizer = wc_get_container()->get( self::SYNCHRONIZER ); if ( is_object( $synchronizer ) && is_callable( array( $synchronizer, 'get_current_orders_pending_sync_count' ) ) ) { return (int) call_user_func( array( $synchronizer, 'get_current_orders_pending_sync_count' ) ); } } catch ( \Throwable $e ) { return null; } return null; } }