WC_REST_System_Status_V2_Controller::get_pages()publicWC 1.0

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 8.7.0

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 checks.
		if ( $page_id ) {
			$page_set = true;
		}
		if ( get_post( $page_id ) ) {
			$page_exists = true;
		}
		if ( 'publish' === get_post_status( $page_id ) ) {
			$page_visible = true;
		}

		// Shortcode checks.
		if ( $values['shortcode'] && get_post( $page_id ) ) {
			$shortcode_required = true;
			$page               = get_post( $page_id );
			if ( strstr( $page->post_content, $values['shortcode'] ) ) {
				$shortcode_present = true;
			}
		}

		// Block checks.
		if ( $values['block'] && get_post( $page_id ) ) {
			$block_required = true;
			$block_present = WC_Blocks_Utils::has_block_in_page( $page_id, $values['block'] );

			// Compatibility with the classic shortcode block which can be used instead of shortcodes.
			if ( ! $block_present && ( 'woocommerce/checkout' === $values['block'] || 'woocommerce/cart' === $values['block'] ) ) {
				$block_present = WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/classic-shortcode', true );
			}
		}

		// 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;
}