0

Bit of a long shot but wondering if someone can point me in the right direction for how this could be achieved.

My plan is to build a font end importer / uploader possibly using ACF, where a user can upload their exported browser bookmarks file.

Then the main challenge which would be to extract each url from the bookmarks.html file and convert this into multiple Wordpress posts.

Ive managed to nearly achieve this (only when importing via the backend) using this plugin: https://wordpress.org/plugins/import-html-pages/

But.. I need to bring the upload / import to the frontend and instead of the whole html file becoming one post or page, actually seprate out each link to individual posts.

Any help or ideas to start me off would be great. Thanks.

1 Answer 1

1

UPLOAD

The simplest way would be to use a form plugin. People like Contact Form 7, WPForms, other people like Gravity Forms. If you want the uploads to be from Wordpress users only. You can hide the form in a password page, generate forms through shortcode on PHP conditional. etc.

You can create your own HTML form, using a shortcode or whatever, then just read the file instead of saving it to do your importing.

(Just some ideas, many more out there. Not much context of your project in post, so basically a blank slate of method you could choose).

IMPORT

So you have the .html export, either saved from a plugin and you can tap into it with a hook (sometimes like _after_post_submit), or it's unsaved in PHP temp from a basic html form, and you just want to read and delete it. Doesn't matter, the methods the same:

To find the links in the html file, you can use PHP DOMDocument Class, a library like php-selector, or just go vanilla and use basic fopen() and preg_match_all()

You'd have to create a method of identifying how the .html is built to know which browser its from, and thus what your DOM query, or regex pattern, will work.

Thereafter you'd have an array of links. Cycling through the array, check if a post of same link exists or not, then continue on and insert individually with wp_insert_post()


Please note that this is a broad answer for a broad question. Post some snippets of code you've tried, hurtles faced, etc. and they'll be much more help available to you.

A great tip while starting any project is to write a comment list of what you want, then start filling in the code.

// create a upload form for users

// on form submit, save file

// open saved file

// find out which browser exported from

// ..etc.
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.