Agentic
4 months ago
BlockTemplates
4 weeks ago
EmailImprovements
1 year ago
EmailPreview
4 weeks ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
4 weeks ago
Onboarding
5 months ago
Orders
4 weeks ago
ProductForm
2 years ago
ProductReviews
4 weeks ago
RemoteFreeExtensions
4 weeks ago
Schedulers
4 weeks ago
Settings
2 weeks ago
Suggestions
4 weeks ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
4 weeks ago
CategoryLookup.php
4 years ago
Coupons.php
1 year ago
CouponsMovedTrait.php
5 months ago
CustomerEffortScoreTracks.php
7 months ago
Events.php
2 months ago
FeaturePlugin.php
4 months ago
Homescreen.php
1 month ago
Loader.php
4 weeks ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
4 weeks ago
RemoteInboxNotifications.php
3 years ago
Settings.php
2 weeks ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
2 weeks ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
SiteHealth.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customize Site Health recommendations for WooCommerce. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * SiteHealth class. |
| 12 | */ |
| 13 | class SiteHealth { |
| 14 | /** |
| 15 | * Class instance. |
| 16 | * |
| 17 | * @var SiteHealth instance |
| 18 | */ |
| 19 | protected static $instance = null; |
| 20 | |
| 21 | /** |
| 22 | * Get class instance. |
| 23 | */ |
| 24 | public static function get_instance() { |
| 25 | if ( ! self::$instance ) { |
| 26 | self::$instance = new self(); |
| 27 | } |
| 28 | return self::$instance; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Hook into WooCommerce. |
| 33 | */ |
| 34 | public function __construct() { |
| 35 | add_filter( 'site_status_should_suggest_persistent_object_cache', array( $this, 'should_suggest_persistent_object_cache' ) ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Counts specific types of WooCommerce entities to determine if a persistent object cache would be beneficial. |
| 40 | * |
| 41 | * Note that if all measured WooCommerce entities are below their thresholds, this will return null so that the |
| 42 | * other normal WordPress checks will still be run. |
| 43 | * |
| 44 | * @param true|null $check A non-null value will short-circuit WP's normal tests for this. |
| 45 | * |
| 46 | * @return true|null True if the store would benefit from a persistent object cache. Otherwise null. |
| 47 | */ |
| 48 | public function should_suggest_persistent_object_cache( $check ) { |
| 49 | // Skip this if some other filter has already determined yes. |
| 50 | if ( true === $check ) { |
| 51 | return $check; |
| 52 | } |
| 53 | |
| 54 | $thresholds = array( |
| 55 | 'orders' => 100, |
| 56 | 'products' => 100, |
| 57 | ); |
| 58 | |
| 59 | foreach ( $thresholds as $key => $threshold ) { |
| 60 | try { |
| 61 | switch ( $key ) { |
| 62 | case 'orders': |
| 63 | $orders_query = new \WC_Order_Query( |
| 64 | array( |
| 65 | 'status' => 'any', |
| 66 | 'limit' => 1, |
| 67 | 'paginate' => true, |
| 68 | 'return' => 'ids', |
| 69 | ) |
| 70 | ); |
| 71 | $orders_results = $orders_query->get_orders(); |
| 72 | if ( $orders_results->total >= $threshold ) { |
| 73 | $check = true; |
| 74 | } |
| 75 | break; |
| 76 | |
| 77 | case 'products': |
| 78 | $products_query = new \WC_Product_Query( |
| 79 | array( |
| 80 | 'status' => 'any', |
| 81 | 'limit' => 1, |
| 82 | 'paginate' => true, |
| 83 | 'return' => 'ids', |
| 84 | ) |
| 85 | ); |
| 86 | $products_results = $products_query->get_products(); |
| 87 | if ( $products_results->total >= $threshold ) { |
| 88 | $check = true; |
| 89 | } |
| 90 | break; |
| 91 | } |
| 92 | } catch ( \Exception $exception ) { |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | if ( ! is_null( $check ) ) { |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return $check; |
| 102 | } |
| 103 | } |
| 104 |