IN_SECONDS ); } return $theme_info; } /** * Clear the system status theme cache */ public static function clean_theme_cache() { delete_transient( 'wc_system_status_theme_info' ); } /** * Clear the system status plugin caches */ public static function clean_plugin_cache() { delete_transient( 'wc_system_status_active_plugins' ); delete_transient( 'wc_system_status_inactive_plugins' ); delete_transient( 'wc_system_status_dropins_mu_plugins' ); } /** * Get some setting values for the site that are useful for debugging * purposes. For full settings access, use the settings api. * * @return array */ public function get_settings() { // Get a list of terms used for product/order taxonomies. $term_response = array(); $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); foreach ( $terms as $term ) { $term_response[ $term->slug ] = strtolower( $term->name ); } // Get a list of terms used for product visibility. $product_visibility_terms = array(); $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); foreach ( $terms as $term ) { $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); } // Get list of enabled features. $enabled_features_slugs = array_keys( wp_list_filter( wc_get_container()->get( FeaturesController::class )->get_features( true, true ), array( 'is_enabled' => true ) ) ); // Return array of useful settings for debugging. return array( 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), 'currency' => get_woocommerce_currency(), 'currency_symbol' => get_woocommerce_currency_symbol(), 'currency_position' => get_option( 'woocommerce_currency_pos' ), 'thousand_separator' => wc_get_price_thousand_separator(), 'decimal_separator' => wc_get_price_decimal_separator(), 'number_of_decimals' => wc_get_price_decimals(), 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation', ), true ), 'taxonomies' => $term_response, 'product_visibility_terms' => $product_visibility_terms, 'woocommerce_com_connected' => ConnectionHelper::is_connected() ? 'yes' : 'no', 'enforce_approved_download_dirs' => wc_get_container()->get( Download_Directories::class )->get_mode() === Download_Directories::MODE_ENABLED, 'order_datastore' => WC_Data_Store::load( 'order' )->get_current_class_name(), 'HPOS_enabled' => OrderUtil::custom_orders_table_usage_is_enabled(), 'HPOS_sync_enabled' => wc_get_container()->get( Order_DataSynchronizer::class )->data_sync_is_enabled(), 'enabled_features' => $enabled_features_slugs, ); } /** * Returns security tips. * * @return array */ public function get_security_info() { $check_page = wc_get_page_permalink( 'shop' ); return array( 'secure_connection' => 'https' === substr( $check_page, 0, 5 ), 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), ); } /** * Returns a mini-report on WC pages and if they are configured correctly: * Present, visible, and including the correct shortcode or block. * * @return array */ public function get_pages() { // WC pages to check against. $check_pages = array( _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_shop_page_id', ), _x( 'Cart', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_cart_page_id', 'shortcode' => '[' . apply_filters_deprecated( 'woocommerce_cart_shortcode_tag', array( 'woocommerce_cart' ), '8.3.0', 'woocommerce_create_pages' ) . ']', 'block' => 'woocommerce/cart', 'shortcode_callback' => function ( $page ) { if ( $page ) { $shortcode = apply_filters_deprecated( 'woocommerce_cart_shortcode_tag', array( 'woocommerce_cart' ), '8.3.0', 'woocommerce_create_pages' ); if ( has_shortcode( $page->post_content, $shortcode ) ) { return $shortcode; } } return ''; }, 'block_callback' => function ( $page ) { if ( $page ) { if ( has_block( 'woocommerce/cart', $page->post_content ) ) { return 'woocommerce/cart'; } if ( CartCheckoutUtils::has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', 'cart', $page->post_content ) ) { return 'woocommerce/classic-shortcode'; } } return ''; }, ), _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_checkout_page_id', 'shortcode' => '[' . apply_filters_deprecated( 'woocommerce_checkout_shortcode_tag', array( 'woocommerce_checkout' ), '8.3.0', 'woocommerce_create_pages' ) . ']', 'block' => 'woocommerce/checkout', 'shortcode_callback' => function ( $page ) { if ( $page ) { $shortcode = apply_filters_deprecated( 'woocommerce_checkout_shortcode_tag', array( 'woocommerce_checkout' ), '8.3.0', 'woocommerce_create_pages' ); if ( has_shortcode( $page->post_content, $shortcode ) ) { return $shortcode; } } return ''; }, 'block_callback' => function ( $page ) { if ( $page ) { if ( has_block( 'woocommerce/checkout', $page->post_content ) ) { return 'woocommerce/checkout'; } if ( CartCheckoutUtils::has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', 'checkout', $page->post_content ) ) { return 'woocommerce/classic-shortcode'; } } return ''; }, ), _x( 'My account', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_myaccount_page_id', 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', ), _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_terms_page_id', ), ); $pages_output = array(); foreach ( $check_pages as $page_name => $values ) { $page_id = get_option( $values['option'] ); $page_set = false; $page_exists = false; $page_visible = false; $shortcode_present = false; $shortcode_required = false; $block_present = false; $block_required = false; $page = false; $block = ''; $shortcode = ''; // Page checks. if ( $page_id ) { $page_set = true; $page = get_post( $page_id ); if ( $page ) { $page_exists = true; if ( 'publish' === $page->post_status ) { $page_visible = true; } } } // Shortcode checks. if ( $page && isset( $values['shortcode_callback'], $values['shortcode'] ) ) { $shortcode_required = true; $result = $values['shortcode_callback']( $page ); $shortcode = $result ? $result : $values['shortcode']; $shortcode_present = (bool) $result; } elseif ( $page && isset( $values['shortcode'] ) ) { $shortcode = $values['shortcode']; $shortcode_required = true; $shortcode_present = has_shortcode( $page->post_content, trim( $shortcode, '[]' ) ); } // Block checks. if ( $page && isset( $values['block_callback'], $values['block'] ) ) { $block_required = true; $result = $values['block_callback']( $page ); $block = $result ? $result : $values['block']; $block_present = (bool) $result; } elseif ( $page && isset( $values['block'] ) ) { $block = $values['block']; $block_required = true; $block_present = has_block( $block, $page->post_content ); } // Wrap up our findings into an output array. $pages_output[] = array( 'page_name' => $page_name, 'page_id' => $page_id, 'page_set' => $page_set, 'page_exists' => $page_exists, 'page_visible' => $page_visible, 'shortcode' => $shortcode, 'block' => $block, 'shortcode_required' => $shortcode_required, 'shortcode_present' => $shortcode_present, 'block_present' => $block_present, 'block_required' => $block_required, ); } return $pages_output; } /** * Get info about the logging system. * * @return array */ protected function get_logging_info() { return array( 'logging_enabled' => LoggingUtil::logging_is_enabled(), 'default_handler' => LoggingUtil::get_default_handler(), 'retention_period_days' => LoggingUtil::get_retention_period(), 'level_threshold' => WC_Log_Levels::get_level_label( strtolower( LoggingUtil::get_level_threshold() ) ), 'log_directory_size' => size_format( LoggingUtil::get_log_directory_size() ), ); } /** * Get any query params needed. * * @return array */ public function get_collection_params() { return array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ); } /** * Prepare the system status response * * @param array $system_status System status data. * @param WP_REST_Request $request Request object. * @return WP_REST_Response */ public function prepare_item_for_response( $system_status, $request ) { $data = $this->add_additional_fields_to_object( $system_status, $request ); $data = $this->filter_response_by_context( $data, 'view' ); $response = rest_ensure_response( $data ); /** * Filter the system status returned from the REST API. * * @param WP_REST_Response $response The response object. * @param mixed $system_status System status * @param WP_REST_Request $request Request object. */ return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); } }