{"id":46414,"date":"2025-08-16T08:44:26","date_gmt":"2025-08-16T08:44:26","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46414"},"modified":"2025-08-16T08:44:26","modified_gmt":"2025-08-16T08:44:26","slug":"loop-include-files","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/loop-include-files\/","title":{"rendered":"Loop include files"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"instead-of-adding-one-by-one-you-can-include-all-files-inside-inc-folder\">Instead of adding one by one you can include all files inside&nbsp;<code>\/inc\/<\/code>&nbsp;folder<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&lt;?php\n\nfunction load_dp_inc_files()\n{\n    $dirPath = __DIR__ . '\/inc\/';\n    $files = scandir($dirPath);\n    foreach ($files as $file) {\n        $filePath = $dirPath . '\/' . $file;\n        if (is_file($filePath)) {\n            require_once($filePath);\n        }\n    }\n}\n\nadd_action('init', 'load_dp_inc_files');\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you need to load only php files<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&lt;?php\n\n\/\/ Load all INC Files \n\nfunction load_dp_blocks_inc_files()\n{\n    $dirPath = __DIR__ . '\/inc\/';\n    $files = scandir($dirPath);\n    foreach ($files as $file) {\n        $filePath = $dirPath . $file; \/\/ Removed the extra '\/' since it's already in $dirPath\n        if (is_file($filePath) &amp;&amp; pathinfo($filePath, PATHINFO_EXTENSION) === 'php') {\n            require_once($filePath);\n        }\n    }\n}\n\nadd_action('init', 'load_dp_blocks_inc_files');<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Instead of adding one by one you can include all files inside&nbsp;\/inc\/&nbsp;folder If you need to load only php files<\/p>\n","protected":false},"author":1,"featured_media":46597,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Loop include files - Code DPlugins","description":"Instead of adding one by one you can include all files inside&nbsp; \/inc\/ &nbsp;folder If you need to load only php files"},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[79,54,122,124,125,93],"dpc_library":[],"class_list":["post-46414","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-css","tag-developer","tag-development","tag-include","tag-js","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46414"}],"version-history":[{"count":0,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46414\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46597"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46414"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46414"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}