Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

467 changes: 0 additions & 467 deletions lib/experimental/content-types/index.php

This file was deleted.

26 changes: 0 additions & 26 deletions lib/experimental/content-types/load.php

This file was deleted.

309 changes: 0 additions & 309 deletions lib/experimental/content-types/post-types.php

This file was deleted.

5 changes: 0 additions & 5 deletions lib/experimental/experiments/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ function gutenberg_initialize_experiments_settings() {
'label' => __( 'Guidelines', 'gutenberg' ),
'description' => __( 'Enables the Guidelines page under Settings and the experimental knowledge storage (wp_knowledge).', 'gutenberg' ),
),
array(
'id' => 'gutenberg-content-types',
'label' => __( 'Content types', 'gutenberg' ),
'description' => __( 'Enables a UI for creating and managing custom taxonomies and custom post types under Settings.', 'gutenberg' ),
),
array(
'id' => 'gutenberg-dashboard-widgets',
'label' => __( 'New Dashboard experience', 'gutenberg' ),
Expand Down
7 changes: 0 additions & 7 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/knowledge/index.php';
}

// Content types (only load when experiment is enabled).
if ( gutenberg_is_experiment_enabled( 'gutenberg-content-types' ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we don't really do much about here is the relevant data that remains in the database. It will remain there forever, and there's no "user" way to clean it up. I wonder if we should offer something that warns users removal will happen, and cleans up. We don't have to do anything, since this is an experiment, I imagine that's fine, but also wanted to agree on this before we go ahead. Potential cleanup would have to mean cleaning up:

  • User post types and taxonomies
  • Any meta associated with the above
  • Obsolete rewrite rules

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an experiment and IMO is better not to try to auto delete data. The most important reason is that since this was an early experiment it could lack proper validation (especially in the very first iterations) and trying to delete posts or terms created under cpts or custom taxonomies could conflict with existing ones. A theoretical example could be create product cpt -> deactivate -> install Woo and create products -> deactivate Woo. That scenario could possibly delete products that were actually created while using Woo, and the user could activate that plugin again in the future.

I think the safest script would be to delete cpts and custom taxonomies, the _gutenberg_user_content_types_flush_rewrite_rules option and trigger the update of rewrite rules flush. Something like this:

add_action( 'init', function () {
	// Only run for an administrator, on wp-admin requests.
	// On multisite, visit the admin of each site that used the experiment.
	if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
		return;
	}

	// Every user-defined type was stored as a post of one of these two
	// internal CPTs — the slugs are exclusive to the experiment, so this
	// query cannot match unrelated content. Posts and terms created under
	// user-defined types are intentionally left in place, as with any
	// deactivated plugin that registers post types.
	$records = get_posts(
		array(
			'post_type'        => array( 'wp_user_post_type', 'wp_user_taxonomy' ),
			// All statuses: deactivated types were stored as drafts.
			'post_status'      => array_keys( get_post_stati() ),
			'posts_per_page'   => -1,
			'suppress_filters' => true,
		)
	);

	if ( ! $records ) {
		add_action( 'admin_notices', function () {
			echo '<div class="notice notice-success"><p>Content types experiment cleanup: nothing left to remove — you can delete this snippet.</p></div>';
		} );
		return;
	}

	// One-shot marker the experiment used to schedule a rewrite rules flush;
	// deleting a missing option is a no-op.
	delete_option( '_gutenberg_user_content_types_flush_rewrite_rules' );

	// wp_delete_post() also removes each record's post meta.
	foreach ( $records as $record ) {
		wp_delete_post( $record->ID, true );
	}

	// Drop stale rewrite rules for the now-unregistered types; WordPress
	// regenerates this option lazily on the next request.
	delete_option( 'rewrite_rules' );

	$count = count( $records );
	add_action( 'admin_notices', function () use ( $count ) {
		echo '<div class="notice notice-success"><p>' . esc_html( sprintf( 'Content types experiment cleanup: removed %d definition records and leftover options.', $count ) ) . '</p></div>';
	} );
} );

I can add this in the clossing comment for the main issue and share in core editor slack. What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think that should suffice, sounds good!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've ever shipped a cleanup notice for experiments. It's usually better to leave this to site admins; WP CLI is better at cleaning up similar leftovers.

require __DIR__ . '/experimental/content-types/load.php';
require __DIR__ . '/experimental/content-types/index.php';
require __DIR__ . '/experimental/content-types/post-types.php';
}

// Dashboard Widgets (only load when experiment is enabled).
if ( gutenberg_is_experiment_enabled( 'gutenberg-dashboard-widgets' ) ) {
require __DIR__ . '/experimental/dashboard-widgets/load.php';
Expand Down
Loading
Loading