WC_REST_System_Status_V2_Controller::get_pages()
Returns a mini-report on WC pages and if they are configured correctly: Present, visible, and including the correct shortcode or block.
Метод класса: WC_REST_System_Status_V2_Controller{}
Хуки из метода
Возвращает
Массив
.
Использование
$WC_REST_System_Status_V2_Controller = new WC_REST_System_Status_V2_Controller(); $WC_REST_System_Status_V2_Controller->get_pages();
Код WC_REST_System_Status_V2_Controller::get_pages() WC REST System Status V2 Controller::get pages WC 9.2.3
public function get_pages() { // WC pages to check against. $check_pages = array( _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_shop_page_id', 'shortcode' => '', 'block' => '', ), _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', ), _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', ), _x( 'My account', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_myaccount_page_id', 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', 'block' => '', ), _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( 'option' => 'woocommerce_terms_page_id', 'shortcode' => '', 'block' => '', ), ); $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; // 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 ( $values['shortcode'] && $page ) { $shortcode_required = true; if ( has_shortcode( $page->post_content, trim( $values['shortcode'], '[]' ) ) ) { $shortcode_present = true; } // Compatibility with the classic shortcode block which can be used instead of shortcodes. if ( ! $shortcode_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) { $shortcode_present = has_block( 'woocommerce/classic-shortcode', $page->post_content ); } } // Block checks. if ( $values['block'] && $page ) { $block_required = true; $block_present = has_block( $values['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' => $values['shortcode'], 'block' => $values['block'], 'shortcode_required' => $shortcode_required, 'shortcode_present' => $shortcode_present, 'block_present' => $block_present, 'block_required' => $block_required, ); } return $pages_output; }