'Encabezados' ) ); } // Registro de patrones add_action( 'init', 'wemcor_register_block_patterns' ); function wemcor_register_block_patterns() { if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) { return; } //leemos directorio de templates para cargar todos los patterns require_once ABSPATH . 'wp-admin/includes/file.php'; $files = list_files( dirname(__FILE__) . '/templates/', 1); foreach($files as $file) { // /home/customer/www/test.wemcor.es/public_html/wp-content/mu-plugins/templates/template-fashion.json $name = explode("/", $file); wemcor_register_pattern( end($name) ); } } function wemcor_register_pattern( $file ) { $url = WPMU_PLUGIN_URL . '/templates/' . $file; $json = file_get_contents($url); $json_data = json_decode($json, true); //rename $name = str_replace('-', ' ', $file); $name = str_replace('.json', '', $name); register_block_pattern( 'wem-gutenberg-blocks-patterns/'.$file, array( 'title' => ucfirst($name), 'content' => $json_data['content'], 'categories' => [ 'wem-templates' ], ) ); }