post_type; if ( in_array( $type, self::foreign_types(), true ) ) { return new \WP_Error( self::REFUSAL_CODE, sprintf( 'Item %1$d is a %2$s, which another plugin keeps in its own records and changes through its own screens. WPPilot does not read or change it as a post. Nothing was changed.', (int) $post->ID, $type ), array( 'status' => 409, 'post_type' => $type, 'reason' => 'foreign_storage', ) ); } if ( ! get_post_type_object( $type ) instanceof \WP_Post_Type ) { return new \WP_Error( self::REFUSAL_CODE, sprintf( 'Item %1$d is of the type %2$s, which nothing active on this site registers, so WPPilot cannot tell where it is really kept. Nothing was changed.', (int) $post->ID, $type ), array( 'status' => 409, 'post_type' => $type, 'reason' => 'unregistered_type', ) ); } return null; } /** * The foreign-storage types: the literal list plus WooCommerce's own list * of order types where WooCommerce is active (an extension's order type, * registered through `wc_register_order_type`, is in it). * * @return string[] */ /** * Core's own block content types: templates, template parts, synced * patterns and navigation menus. Not public, yet each is ordinary page * content the site editor writes as block markup. */ private const BLOCK_CONTENT_TYPES = array( 'wp_template', 'wp_template_part', 'wp_block', 'wp_navigation' ); /** * Why a post's body or status may not be written here, or null. * * Body and status writes are for content: a public type, or core's own * block content. Anything else that keeps a post row (Additional CSS, * global styles, another plugin's code snippets, internal records) is * left to the screens that own it, since its body may be code or its * status may switch code on. * * @param \WP_Post $post The addressed post, already past refusal(). */ public static function write_refusal( \WP_Post $post ): ?\WP_Error { $type = (string) $post->post_type; $object = get_post_type_object( $type ); if ( ( $object instanceof \WP_Post_Type && ! empty( $object->public ) ) || in_array( $type, self::BLOCK_CONTENT_TYPES, true ) ) { return null; } return new \WP_Error( self::REFUSAL_CODE, sprintf( 'Item %1$d is a %2$s, which is not site content WPPilot changes. Nothing was changed.', (int) $post->ID, $type ), array( 'status' => 409, 'post_type' => $type, 'reason' => 'not_content', ) ); } public static function foreign_types(): array { $types = self::FOREIGN_TYPES; if ( function_exists( 'wc_get_order_types' ) ) { $types = array_merge( $types, array_map( 'strval', (array) wc_get_order_types() ) ); } return array_values( array_unique( $types ) ); } }