WordPress as Social Media Bookmark Tool

Alan has been on top of some things happening with pinboard.in. It seems that public links to tags, searches, etc. have been shut off due to hackers attacking those urls. That’s been the social bookmarking site of choice for a number of people in my internet circles. I’m not super-social but it is important to me to be able to share tagged content with other people. That’s the whole point and I can’t expect people to get pinboard accounts just to see my links. Alan and I have both been down the road with various social bookmarking services (del.icio.us, diigo, etc.). I even opted to change my pinboard account from a “forever” account to paying every few years to try to better support the product.

I use pinboard to provision my weekly posts and it’s been good enough. Every few months, I’ll think that it’d have been nice to be able to bookmark an image or do something slightly non-standard that I can’t do in pinboard . . . the itch to customize . . . and I’ll start thinking about why I don’t just do it in WordPress with a custom post type and use the Press This1 plugin for the interaction. In the past, I’ve managed to ignore the itch. Pinboard was good enough. Social enough. This issue

I don’t really know if this the best solution but I do know I don’t want another service that will eventually end up doing things I don’t want.2 I thought I could do what I wanted without much drama or effort. It took me about 45 minutes but probably should have only taken 5 for someone who is a good programmer. I was dabbling in the LLM programming space which cost me a chunk of time before I ended up bailing for Stackoverflow.

The basic pattern is this.

  1. Create a custom post type called bookmark that supports categories and tags.
  2. Alter the Press This plugin so that it saves content to the bookmark custom post type.
  3. Write the source URL of the “pressed” page to a custom field.
  4. Filter the links for the bookmark custom post type so they go to the “pressed” page URL. This will make all the title links go to the source URL rather than to the post URL (the way WP normally works).

You can see the plugin here.

The portion that changes the Press This post type is below and the solution was found in good old Stackoverflow. It’s not a good solution if you use Press This for other content but no one does that these days. It also writes the URL to the custom field named press-it-url. I think there’s a better way to do this with the form post that passes in the URL prior to this action but . . . I don’t care enough to change it at this point. I did my regex testing in https://regex101.com/.

/**
 * from https://wordpress.stackexchange.com/questions/192059/save-press-this-posts-in-a-custom-post-type
 */
add_filter( 'press_this_save_post', function( $data )
{
  
  $pattern = '/Source: <em><a href=."([^"]+)"/';//regex to get source URL

   // Using preg_match to extract the URL
   if (preg_match($pattern, $data['post_content'], $matches)) {
       $url = $matches[1]; // The URL will be captured in the first capture group
       //write_log( "Extracted URL: " . $url);
       update_post_meta( $data['ID'], 'press-it-url', $url );//write source URL to custom field 
   } else {
       //write_log("No URL found.");
   }

    //---------------------------------------------------------------
    //
    $new_cpt    = 'bookmark';              // new post type   
    //---------------------------------------------------------------

    $post_object = get_post_type_object( $new_cpt );

    // Change the post type if current user can
    if( 
           isset( $post_object->cap->create_posts ) 
        && current_user_can( $post_object->cap->create_posts ) 
    ) 
        $data['post_type']  = $new_cpt;


    return $data;

}, 999 );

The actual overwriting of the post links is done like so.

//overwrite normal post link with the URL that was bookmarked

function bmi_custom_bookmark_permalink($post_link, $post) {
    // Check if the post type is 'bookmark'
    if ('bookmark' === get_post_type($post)) {
        // Retrieve the custom field 'press-this-url'
        $custom_url = get_post_meta($post->ID, 'press-it-url', true);

        // If the custom field is not empty, replace the post link with the custom URL
        if (!empty($custom_url)) {
            return esc_url($custom_url);
        }
    }

    // If no link, return the original post link
    return $post_link;
}
add_filter('post_type_link', 'bmi_custom_bookmark_permalink', 10, 2);

You can see my one bookmark here.

There’s some stuff I will probably tweak with making Press This automatically close on save and there’s something I can do to make the login more persistent. I also need to write an importer . . . I’ll probably do that.

If nothing else, I exercised my mind a bit and got to write a post responding to a post like in the old days. Even if no one (including myself) uses this, it’s a bit of thinking put on the Internet and a connection made with an old friend I don’t get to see much but who continues to inspire me to do good things. Cog to the blog.


1 I do worry a bit about this being abandoned but I could always flip it to something else- like Gravity Forms. I opted to stick with this because most people don’t want to pay for Gravity Forms.

2 WP itself is too close to that already. I may have to go to Classic Press if this drama keeps up.

4 thoughts on “WordPress as Social Media Bookmark Tool”

  1. The new days can be both new and old, my friend. Its workable, I have some reservations about WordPress too. What does it grab for a description? I like Pinboard’s bookmark because I can highlight text on the page to pre-populate the description. I’d also prefer to use tags and/or categories.

    I kind of prefer to lean on Dr Pinboard to fix the ship!

    Bionic to the blog! Worth more than 6 million dollars to see this post.

    1. Same deal. If you highlight it, it will be in the description as a block quote. It does currently add a source link after that which could be removed but I was find with.

      It supports tags and categories currently. It has the additional option of adding images. I always thought the Press This was a great tool.

  2. Oh! This would be great, IMO. Especially if you do it with Classic Press. I’m in. I love the idea. It also creates a self-hosted bookmark collection that’s got lots of potential for sorting, tagging, etc of notes for one’s own use.

Comments are closed.