Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/dplugins-code/htdocs/code.dplugins.com/wp-includes/functions.php on line 6131

Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/dplugins-code/htdocs/code.dplugins.com/wp-includes/functions.php on line 6131
Loop include files – Code DPlugins

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