gutenbergで作成した投稿は、gutenberg そうでなければ classic editorで開く

WordPress5.0~ で、エディターの切り替え用のコードです。

クラッシクエディタがインストール済みで、ユーザーがエディタを選択できる設定になっている必要があります。

if ( ! function_exists( 'raindrops_custom_gutenberg_edit_link' ) ) {

	/**
	 *
	 * @param type $link
	 * @param type $post_id
	 * @param type $text
	 * @return type
	 */
	function raindrops_custom_gutenberg_edit_link( $link, $post_id, $text ) {

		$which				= get_post_meta( $post_id, 'classic-editor-remember', true );
		$allow_users_option	= get_option( 'classic-editor-allow-users' );

		$disallow_old_post_open_classic_editor= apply_filters( 'disallow_old_post_open_classic_editor', false );

		if ( 'allow'== $allow_users_option ) {

			if ( ( current_user_can( 'edit_posts' ) | | current_user_can( 'edit_pages' ) ) && 'classic-editor'== $which ) {

				$gutenberg_action= sprintf(
						'<a href="%1$s" class="skin-button">%2$s</a>', esc_url( add_query_arg(
										array( 'post'=> $post_id, 'action'=> 'edit', 'classic-editor'=> '', 'classic-editor__forget'=> '' ), admin_url( 'post.php' )
						) ), esc_html__( 'Classic Editor', 'raindrops' ) );

				return $gutenberg_action;
			}
		}
		if ( ( current_user_can( 'edit_posts' ) | | current_user_can( 'edit_pages' ) ) && ! metadata_exists( 'post', $post_id, 'classic-editor-remember' ) && ! $disallow_old_post_open_classic_editor ) {

			$gutenberg_action= sprintf(
					'<a href="%1$s" class="skin-button">%2$s</a>', esc_url( add_query_arg(
									array( 'post'=> $post_id, 'action'=> 'edit', 'classic-editor'=> '', 'classic-editor__forget'=> '' ), admin_url( 'post.php' )
					) ), esc_html__( 'Classic Editor', 'raindrops' ) );

			return $gutenberg_action;
		}

		return $link;
	}
}

WordPress5.0でクラッシクエディタを有効にした場合、既存投稿はクラッシクエディタで開くようです。

WordPress 5.0-beta3-43865のちょっと手前ぐらいのバージョンから、クラッシックエディタエディタ用のリンクだけでは、旧エディタでは開けなくなっているようです。
(WordPress 4.9.8では、動作します)

開発版を使用中の場合、Classic Editorをインストールする必要がありそうです。

Gutenbergエディタは素晴らしいですが、旧エディターで作成した投稿を開いてしまうと、ブロックに変換され、投稿を壊してしまうことがあります。編集リンクにフィルターをかけて、グーテンベルグで作成された投稿の場合は、グーテンベルグエディタで、そうでない場合は、クラッシックエディターで開くように、編集リンクをカスタマイズしてみましょう。

編集リンクは、投稿の下部にあってボタンをクリックすると、編集画面が開くリンクです。

例:twentyseventeenだと日付の横が編集リンクです。

add_action( 'edit_post_link', 'custom_gutenberg_edit_link', 10 , 3 );

function custom_gutenberg_edit_link($link, $post_id, $text) {
			
	if( ( current_user_can( 'edit_posts' ) | | current_user_can( 'edit_pages' ) ) && function_exists( 'has_blocks' ) && ! has_blocks( $post_id ) ) {

		$gutenberg_action= sprintf(
			'<a href="%1$s" >%2$s</a>',	
				esc_url( add_query_arg( 
					array( 'post'=> $post_id , 'action'=> 'edit' ,'classic-editor'=> ''), 
					admin_url('post.php') 
				) ), 
				esc_html__( 'Classic Editor', 'text_domain' ) );
		
		//return $link.'&nbsp;'. $gutenberg_action;
		return $gutenberg_action;
	}
	return $link;
}

Memo: is_gutenberg_page() も役に立ちそう (gutenberg.php)

開発版 (5.0-alpha-43811) にて、

クラッシックエディタで、上記のコメントが表示されるようになりましたが、gutenbergエディタに対応していないという意味のようで、保存やカテゴリ設定は行えました。

[emulsion_relate_posts]