Add html files names and content as new WordPress pages

I am trying to add FTP uploaded html files (*.html) as new pages in WordPress via the wp_posts table and then extract the html content from the file and insert it into the editor of the created page.

So I am trying to write a function that will first:

  • Look for files of chosen directory (exclude files I don’t want).
  • Loop through each file and add just the name of the file (not the ext) to the wp_posts table as a new
    page entry.
  • Take and extract all html data and put into the editor of the page.
    (not sure where I can do this in the table) Before adding as new insert, if name already exist, update data instead.
  • Delete files once data is inserted in table

So far I have this function i am working on:

loop through folders and sub folders with option to remove specific files.

<?php
function getHTMLFiles($dir,$exclude){ 
   $ffs = scandir($dir); //Scan my files in directory      
    foreach($ffs as $ff){ //loop through files
        if(is_array($exclude) and !in_array($ff,$exclude)){ 
          if($ff != '.' && $ff != '..'){ 
            if(!is_dir($dir.'/'.$ff)){ 
              echo ltrim($dir.'/'.$ff,'./'); //show files names
            } else { 
              echo $ff;   //show my file names
            } 
            if(is_dir($dir.'/'.$ff)) getHTMLFiles($dir.'/'.$ff,$exclude); 
          } 
       } 
    } 
} 
getHTMLFiles('/uploaded_files/',array('index.html','exclude.html')); 
?>

If anyone can help me to continue or put me in the right direction, that would be awesome!

Read more here: Add html files names and content as new WordPress pages

Leave a Reply

Your email address will not be published. Required fields are marked *