Skip to content

Commit

Permalink
Add code to load all downloaded blocks into the site
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaetitia committed Mar 23, 2024
1 parent 2d85185 commit fcd1479
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions special-projects-blocks-monorepo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Plugin Name: Dynamic Table of Contents
* Description: Creates a table of contents that's dynamically (PHP) rendered.
* Requires at least: 6.1
* Requires PHP: 8.0
* Version: 0.3
* Author: WordPress Special Projects Team
* Author URI: https://wpspecialprojects.wordpress.com/
* Update URI: https://github.com/a8cteam51/special-projects-blocks-monorepo/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: dynamic-table-of-contents
*
* @package wpsp
*/


/**
* Load all existing blocks within subfolders
* It assumes that the PHP file name is exactly like the directory name + .php.
*
* Example: /dynamic-table-of-contents/dynamic-table-of-contents.php
*/
function load_add_downloaded_blocks(){
$dirs = glob( dirname( __FILE__ ) . '/*', GLOB_ONLYDIR );

foreach ( $dirs as $dir ) {
if ( file_exists( $dir . DIRECTORY_SEPARATOR . basename( $dir ) . '.php' ) ) {
require $dir . DIRECTORY_SEPARATOR . basename( $dir ) . '.php';
}
}
}

add_action('init', 'load_add_downloaded_blocks');

0 comments on commit fcd1479

Please sign in to comment.