• Resolved Derek Perkins

    (@ploobers)


    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!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author scribu

    (@scribu)

    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.

    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~

    Thread Starter Derek Perkins

    (@ploobers)

    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.

    Plugin Author scribu

    (@scribu)

    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.

    Works well. Thanks!

    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=https://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.

    Plugin Author scribu

    (@scribu)

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

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

    Plugin Author scribu

    (@scribu)

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

    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.

    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!

    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?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Plugin: Press This Reloaded] Press This Custom Post Types’ is closed to new replies.