Server IP : 172.67.157.199 / Your IP : 3.145.81.9 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/wp-content/plugins/coblocks/includes/block-migrate/ |
Upload File : |
<?php /** * Facilitates force migration of certain blocks into core blocks. * * @package CoBlocks */ /** * Require needed classes. */ require_once COBLOCKS_PLUGIN_DIR . 'includes/block-migrate/class-coblocks-block-migration-runner.php'; require_once COBLOCKS_PLUGIN_DIR . 'includes/block-migrate/class-coblocks-block-migration.php'; /** * Require migration classes. */ require_once COBLOCKS_PLUGIN_DIR . 'includes/block-migrate/class-coblocks-alert-migration.php'; require_once COBLOCKS_PLUGIN_DIR . 'includes/block-migrate/class-coblocks-author-migration.php'; /** * Hook into the post object before it's returned to the editor. * * This allows us to "force migrate" our blocks by removing and parsing the * previous output for attributes and re-serializing the block to * only include its comment delimiters. */ add_action( 'the_post', function( WP_Post &$post ) { if ( ! function_exists( 'is_admin' ) || ! function_exists( 'get_current_screen' ) || is_null( get_current_screen() ) ) { return; } if ( ! is_admin() || ! get_current_screen()->is_block_editor ) { return; } // Bail if DOMDocument is not available. if ( ! class_exists( 'DOMDocument' ) ) { return; } // Parse the blocks so we can search them in a standard way. $parsed_blocks = parse_blocks( $post->post_content ); // Load our available migrations. $migration_runner = new CoBlocks_Block_Migration_Runner(); array_map( array( $migration_runner, 'register' ), array( CoBlocks_Alert_Migration::class, CoBlocks_Author_Migration::class, ) ); $parsed_blocks = array_map( array( $migration_runner, 'migrate_block' ), $parsed_blocks ); // re-serialize the blocks so WordPress can continue processing as usual. $post->post_content = serialize_blocks( $parsed_blocks ); } );