Automattic\WooCommerce\Internal\OrderReviews

Endpoint::skip_auto_menu_for_selfpublicWC 1.0

Keep the Review Order page out of nav menus that have "Auto add new top-level pages" enabled.

The page is reachable only through the tokenised URL the email sends out; nobody navigates to it from a menu, so it should never appear there. WP's _wp_auto_add_pages_to_menu() runs on transition_post_status priority 10. Detach it just before that for our specific page, then restore it on priority 11 so other transitions are unaffected.

Compares by slug rather than by stored option id so it also fires on the very first install — before woocommerce_review_order_page_id is written.

Method of the class: Endpoint{}

No Hooks.

Returns

null. Nothing (null).

Usage

$Endpoint = new Endpoint();
$Endpoint->skip_auto_menu_for_self( $new_status, $old_status, $post ): void;
$new_status(string) (required)
New post status.
$old_status(string) (required)
Old post status.
$post(WP_Post) (required)
Post object.

Endpoint::skip_auto_menu_for_self() code WC 10.8.1

public function skip_auto_menu_for_self( $new_status, $old_status, $post ): void {
	unset( $new_status, $old_status );
	if ( ! $post instanceof \WP_Post || 'page' !== $post->post_type ) {
		return;
	}

	// Identify the page by stored option id (post-install) or by the
	// shortcode in its content (during install, before the option
	// exists). Don't compare $post->post_name to 'review-order' alone:
	// WP appends -2/-3/... if the slug already exists.
	$stored_id  = (int) get_option( 'woocommerce_review_order_page_id' );
	$is_by_id   = $stored_id > 0 && $stored_id === (int) $post->ID;
	$is_by_slug = '' === $post->post_name
		? false
		: ( 'review-order' === $post->post_name || 0 === strpos( $post->post_name, 'review-order-' ) );
	$is_by_body = false !== strpos( (string) $post->post_content, '[' . self::SHORTCODE . ']' );
	if ( ! $is_by_id && ! $is_by_slug && ! $is_by_body ) {
		return;
	}

	remove_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10 );
	add_action(
		'transition_post_status',
		static function () {
			add_action( 'transition_post_status', '_wp_auto_add_pages_to_menu', 10, 3 );
		},
		11
	);
}