WordPress.org

Ready to get started?Download WordPress

Forums

Press This Reloaded
[resolved] Press This Custom Post Types (13 posts)

  1. Derek Perkins
    Member
    Posted 3 years ago #

    scribu - You seem to always be writing the plugins that I really care about. How tough would it be to allow me to Press custom post types? I'd love to be able to have a bookmarklet that would let me post videos or other data. I'd also love to have a hook in there so that I could add data from the current page into my custom meta boxes or automatically add items to the taxonomy based on page info.

    Thanks for the great stuff!

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Add this code to your functions.php file:

    function press_this_ptype($link) {
    	$post_type = 'example';
    
    	$link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link);
    	$link = str_replace('?u=', '&u=', $link);
    
    	return $link;
    }
    add_filter('shortcut_link', 'press_this_ptype', 11);

    Then, re-add the bookmarklet from WP Admin -> Tools.

  3. thecorkboard
    Member
    Posted 3 years ago #

    Ahh... perfect.

    I've been thinking about the Press This limitations with CPTs (custom post types). Now, let me add something else into the mix:

    How about the ability to create multiple Press This pages in the dashboard and assign them to certain post types?

    In a glorious ajax-y world, you'd only have to use one Press This and magically you could switch between CPTs - but I imagine Scribu's no wizard..... wait, are you?

    Anywho,
    Thanks for the hard work.
    ~Kyle~

  4. Derek Perkins
    Member
    Posted 3 years ago #

    I was looking to filter the shortcut_link like scribu mentioned and do some custom functions, like checking for the site and if youtube.com for example, I'd prefill some fields differently for a video cpt, etc.

    I agree though, that I'd rather have multiple Press This bookmarklets, one for each cpt. Another option would be having an intermediary page where you choose from a list of custom post types.

  5. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    You can have multiple Press This bookmarklets for different post types already.

    Just change the post type in the snippet above and save a new bookmarklet.

  6. thecorkboard
    Member
    Posted 3 years ago #

    Works well. Thanks!

  7. thecorkboard
    Member
    Posted 3 years ago #

    Doesn't seem to work with the Links Manager:

    //Extra "Press This" Pages
    function press_this_ptype($link) {
    	$post_type = 'link';
    
    	$link = str_replace('post-new.php', "link-add.php", $link);
    	$link = str_replace('?u=', '&u=', $link);
    
    	return $link;
    }
    add_filter('shortcut_link', 'press_this_ptype', 11);

    Outputs:

    Not Found

    The requested URL /wp-admin/link-add.php&u=http://www.google.com/&t=Google&s=&v=4 was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  8. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Well, of course not, since links (bookmarks) aren't a custom post type (yet).

  9. thecorkboard
    Member
    Posted 3 years ago #

    But aren't links treated as post types just like posts & pages?

  10. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    No, that's what I said. They are stored in a separate database table and are handled by different code.

  11. thecorkboard
    Member
    Posted 3 years ago #

    Ok, must have been mislead at some resource. Hope the links manager => Press This connection is made somehow in the future.

    Thanks for your hard work.

  12. lalaalaaa
    Member
    Posted 3 years ago #

    Hi, I tried the code above, but got a 404 error... I removed the line $link = str_replace('?u=', '&u=', $link); and I could get to the Post page, but it posted as a Post still, instead of the Bookmark post type.

    I then changed the $link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link); to press-this.php -- but it still posts as a Post, not the custom type

    Final code changes that I made:

    <?php
    function press_this_ptype($link) {
    	$post_type = 'bookmark';
    	$link = str_replace('press-this.php', "press-this.php?post_type=$post_type", $link);
    	//$link = str_replace('?u=', '&u=', $link);
    	return $link;
    }
    add_filter('shortcut_link', 'press_this_ptype', 11);
    ?>

    Any help would be greatly appreciated!

    ====================================================================
    EDIT: I had a typo earlier in my function.php file -- the original code worked perfectly for me!

  13. nickoonce
    Member
    Posted 3 years ago #

    First, THANK YOU Scribu. This is an excellent improvement on Press This.

    Like Ploobers, I'd like to be able to use the hooks to populate custom fields. Specifically, I have custom meta fields for SourceLink and SourceName. Do you have any idea how I might be able to populate those fields automatically?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic