Loop include files

Instead of adding one by one you can include all files inside /inc/ folder

<?php

function load_dp_inc_files()
{
    $dirPath = __DIR__ . '/inc/';
    $files = scandir($dirPath);
    foreach ($files as $file) {
        $filePath = $dirPath . '/' . $file;
        if (is_file($filePath)) {
            require_once($filePath);
        }
    }
}

add_action('init', 'load_dp_inc_files');

If you need to load only php files

<?php

// Load all INC Files 

function load_dp_blocks_inc_files()
{
    $dirPath = __DIR__ . '/inc/';
    $files = scandir($dirPath);
    foreach ($files as $file) {
        $filePath = $dirPath . $file; // Removed the extra '/' since it's already in $dirPath
        if (is_file($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) === 'php') {
            require_once($filePath);
        }
    }
}

add_action('init', 'load_dp_blocks_inc_files');
Click to Copy