Giter Club home page Giter Club logo

import-bookmarks's Introduction

Import Bookmarks

Import browser bookmarks into WordPress.

Export bookmarks from your browser and import them as WordPress posts. Supports Custom Post Types and Post Formats.

Installation

In WP Admin, go to Plugins > Add New, and search for "import bookmarks." Install and activate. Or install from https://wordpress.org/plugins/import-bookmarks/.

Usage

In WP Admin, head over to Import > Import Bookmarks, select a bookmarks file (in HTML format, as exported from your browser of choice) to upload, and choose the destination post type and status.

Note: all bookmarks in the export file will be imported as WordPress posts. You may find you have to delete some afterward, or manually tweak the bookmarks file's content before.

Custom Post Types

Bookmarks can be added as regular Posts or instances of a Custom Post Type (created through, e.g., Custom Post UI, or another plugin).

This plugin, on its own, will not register a new Custom Post Type (nor modify existing ones).

Post Statuses

Newly added bookmarks can be marked "Published," "Draft," "Pending review" or "Private."

Post Formats

Newly added bookmarks can be given any Post Format. Note: it's your active theme that decides what this means for your site. If unsure, you'll probably want to use either "Link" or "Standard." Lastly, only Post Types that support Post Formats are actually affected.

Dates and Archives

Post dates are set to the date the bookmark was created. Monthly archives, etc., work just fine.

Duplicated entries are not (yet) detected.

A possible use case would be to periodically "dump" all of your bookmarks into a WordPress-powered "linklog," then clear them all from your browser—rinse, repeat. (However, if you did want to import the same link twice, e.g., with a different title, that would be perfectly fine.)

Advanced: Modifying the Format of Imported Bookmarks

Use the import_bookmarks_post_content filter to customize imported bookmarks' markup with minimal PHP.

Some examples of what's possible. (These would typically go into your [child] theme's functions.php.) Note: core hooks like publish_{$post->post_type} allow even more customization, but that's outside the scope of this readme.

In the future, some of these options might make it into the plugin itself.

// Force open links in new tab.
add_filter( 'import_bookmarks_post_content', function( $post_content, $bookmark ) {
    $post_title    = sanitize_text_field( $bookmark['title'] );
    $post_content  = sanitize_text_field( $bookmark['note'] );
    $post_content .= "\n\n<a href='" . esc_url( $bookmark['uri'] ) .
        "' target='_blank' rel='noopener noreferrer'>" . $post_title . '</a>';
    $post_content  = trim( $post_content );

    return $post_content;
}, 10, 2 );
// Add (some!) Gutenberg support. Note: unlike Gutenberg's 'Convert to blocks',
// this'll not autodetect and apply, e.g., WordPress embeds.
add_filter( 'import_bookmarks_post_content', function( $post_content, $bookmark, $post_type ) {
    if ( function_exists( 'use_block_editor_for_post_type' ) &&
         use_block_editor_for_post_type( $post_type ) ) {
        // Convert to paragraph blocks.
        $post_content = str_replace(
            "\n\n",
            "</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>",
            $post_content
        );
        $post_content = "<!-- wp:paragraph -->\n<p>" . $post_content . "</p>\n<!-- /wp:paragraph -->";
    }

    return $post_content;
}, 10, 3 );
// Do something else entirely.
add_filter( 'import_bookmarks_post_content', function( $post_content, $bookmark ) {
    $post_content  = sanitize_text_field( $bookmark['title'] );
    $post_content .= "\n\n" . make_clickable( esc_url( $bookmark['uri'] ) );
    $post_content  = trim( $post_content );

    return $post_content;
}, 10, 2 );

Credits

Icon, Copyright 2016 Nick Roach Licensed under the terms of the GNU GPL, Version 2 Source: https://www.elegantthemes.com/blog/freebie-of-the-week/beautiful-flat-icons-for-free

import-bookmarks's People

Contributors

janboddez avatar lotharthesavior avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

import-bookmarks's Issues

Add Support to Gutenberg

@janboddez

I noticed, while testing the plugin, that it create posts that end up creating the default post content. We could add "links" in case the "block editor" is active in the WordPress instance.

Let me know if this is something that you consider for this plugin.

Add option to detect duplicate entries

The import_bookmarks_uri custom field may be used to detect duplicate URLs for post types that support custom fields. An option to detect duplicate entries this way should be switchable, however. (There may be valid reasons to link to the same web page more than once.)

Get rid of set_time_limit()

The set_time_limit( 0 ); inside the import() method should probably go and may actually not be needed. On a temporary shared hosting setup, the plugin is able to process a few hundred bookmarks in well under 10 seconds (the typical PHP timeout is 30 seconds).

If PHP does choke on larger sets of bookmarks, though, the 'final' solution would likely be to have JavaScript send 'chunks' of 10 or so bookmarks off to the server one by one. (This has the added benefit of being able to show a progress bar.)

Import bookmarks from other sources.

As a user, I would like to be able to integrate this bookmark with an API that is cross browser and cross platform. Firefox uses for itself Pocket by default, and that is a very interesting option for bookmarking technologies.
Because Pocket has an API, we could use it, so the user could also import from there.

Let me know your thoughts.

Replace empty return statements with proper error messages

Uploading an invalid file will result in a 'white screen of death', or rather, cause PHP to exit. In fact, all return; lines inside the import() function should really be replaced with something like wp_redirect( admin_url( 'tools.php?page=import-bookmarks&message=warning' ) ); exit;. Upon being redirected, the user should then be shown at a least a warning that something went wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.