• Resolved nick6352683

    (@nick6352683)


    Any possibility to add the feature to export reusable blocks from the Tools -> Export screen? With WP 5.0.x we can only export one reus. block at a time, but with a WP 4.9 + Gut. setup we can export ALL reusable blocks at once…

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Mel Choyce-Dwan

    (@melchoyce)

    This is a good idea 👍

    Thread Starter nick6352683

    (@nick6352683)

    Thanks Mel, but it should have been working to begin with as my understanding is that the reusable blocks are saved as CPT. So this can be enabled very easily during the CPT code registration process. Unless there was a specific reason why this is not working, … it will save some of us a lot of time, transferring blocks from one site to the other.

    Thanks again,
    Nick.

    Hi @nick6352683,

    I experimented with enabling export for reusable blocks.

    
    function srbe_support_reusable_block_export( $post_type_args, $post_type ) {
    	if ( 'wp_block' === $post_type ) {
    		$post_type_args['can_export'] = true;
    	}
    	return $post_type_args;
    }
    add_filter( 'register_post_type_args', 'srbe_support_reusable_block_export', 10, 2 );
    

    With the above code, reusable blocks are included in exported content, but posts imported from the same export do not have their reusable block references preserved (i.e., editing one of these posts shows “Block has been deleted or is unavailable” where the reusable block should be). This was with exporting All Content. I’m not sure whether it is possible to export reusable blocks only but will explore this further and post if I learn more.

    Here’s a bit more info:
    wp-admin/export.php adds a radio button for each post type that is marked as exportable and not marked as builtin. Radio buttons for the builtin types for Posts, Pages, and Media are hard-coded.

    Unfortunately, the reusable block post type “wp_block” is marked as builtin, so it won’t get a radio button even if it is marked exportable.

    There is a workaround though. If we use the code in my previous comment to mark the “wp_block” post type as exportable, we can manually enter the URL to download an export of just reusable blocks:
    <domain-name>/wp-admin/export.php?download&content=wp_block

    This is not a great solution but may get you where you want to go.

    cc @noisysocks in case he’d like to correct or add anything.

    Thread Starter nick6352683

    (@nick6352683)

    This is why I love WordPress… you hit a wall, you ask for a solution, and there is almost always somebody anywhere in the planet lending help to a total stranger.

    Brandon, I want to sincerely thank you for your solution to my issue, I will try it first thing in the morning as it’s almost midnight here… If you don’t hear from me, it’s because you were correct.

    FYI, another solution for me was to have a WP 4.9 + Gut. setup, create the reusable blocks in that setting, and use the Tools->Export function and put all of them in one json file. Using your solution though, will save me some time from needless setting up a site just to create those blocks for export.

    Once again, thanks a bunch,
    Nick.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exporting Reusable blocks from the Export Screen’ is closed to new replies.