Support » Plugin: WP-EMail » [Plugin: WP-EMail] Plugin not working with custom post type

  • Hi,

    I created a custom post type and put the mail button in a single post of the type.
    In the regular posts it is working well, but in the custom post type I gt error 404 of a pgae not found.
    I tried to resave the permalinks with no help.
    I use the Custom Post Permalinks plugin to give my custom posts type a different permalink structure, so it might be that the wp-email cannot handle this?

    I will be happy if someone has a solution for that.

    Thanks

    http://wordpress.org/extend/plugins/wp-email/

Viewing 13 replies - 16 through 28 (of 28 total)
  • Plugin Author Lester Chan

    (@gamerz)

    Yeap, I just realized that, the fix is for user not using nice permalink. I need to find a way to generate permalinks for custom post type.

    I am using custom permalinks and the fixes at the links above have worked for me.. I haven’t had a chance to download your new zip and test it on my site yet though.

    one bug I have noticed though is that for some reason that I haven’t quite figured out yet, once in a while, seemingly randomly, all of my permalinks will suddenly be hosed and everything will redirect to the home page (not good!!) .. To fix I have to disable wp-email, resave my permalinks, and reenable wp-email..

    ??? Haven’t had any time to chase this out and it only seemed to happen in my first setups of the plugin so I’m not sure what to make of it.

    Thanks a lot for working on this Lester, I know continuing to support free software when your paid work is calling can be tricky!!

    Plugin Author Lester Chan

    (@gamerz)

    Thanks worldwisewebs, I try my best, was in the midst of debugging it when i was called for a urgent project development =(

    danbejarano

    (@danbejarano)

    Thank you Lester for helping the community.
    This I found in a review about custom post types.

    Help! I’m getting a 404!

    If you’re getting a 404 message when trying to view a post, don’t worry. This is supposed to happen when setting up new post types. The easiest way to fix this is to simply visit your Settings > Permalinks page. You don’t have to save your permalinks but just visit the page. This will flush your rewrite rules.

    If you’re a plugin author, you can save yourself some support questions by flushing the rewrite rules on activation of your plugin.

    source: http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

    danbejarano

    (@danbejarano)

    How about: add_action('admin_init', 'flush_rewrite_rules');

    Thread Starter maorb

    (@maorb)

    @danbejarano flushing rewrites does not help in this case.

    Thread Starter maorb

    (@maorb)

    This issue is still not solved, unfortunately.

    Thread Starter maorb

    (@maorb)

    Well, I finally had a bit of time to dig Lester Chan’s code and I’m happy to say I have a working solution.
    I really do not like to follow others code and do reverse engineering, but in this case there was no choice, since I needed this feature for my client and it appeared that Lester has no time to check this.

    To remind you, the problem was when trying to use the plugin with Custom Post Type and with non-default permalinks structure.

    My solution deals only with using the stand alone page, and not with the popup option (In the matter of fact, I am using the stand alone email page and taking the div with the form in order to pop it up into a nice colorbox window, since popups are so 90’s and part of the time blocked..)

    Line numbers inside the code are referring to latest WP-Email ver2.5.2.
    Go to line 234, you will find this block of code in lines 234-261

    switch($email_type) {
    		// E-Mail Standalone Page
    		case 1:
    			if(!empty($using_permalink)) {
    				if(substr($email_link, -1, 1) != '/') {
    					$email_link= $email_link.'/';
    				}
    				if(is_page()) {
    					if(empty($email_page_text)) {
    						$email_text = stripslashes($email_options['page_text']);
    					} else {
    						$email_text = $email_page_text;
    					}
    					$email_link = $email_link.'emailpage/';
    				} else {
    					$email_link = $email_link.'email/';
    				}
    			} else {
    				if(is_page()) {
    					if(empty($email_page_text)) {
    						$email_text = stripslashes($email_options['page_text']);
    					} else {
    						$email_text = $email_page_text;
    					}
    				}
    				$email_link = $email_link.'&email=1';
    			}
    			break;

    You should replace it with this:

    switch($email_type) {
    		// E-Mail Standalone Page
    		case 1:
    			if(!empty($using_permalink)) {
    				if(substr($email_link, -1, 1) != '/') {
    					$email_link= $email_link.'/';
    				}
    				if(is_page()) {
    					if(empty($email_page_text)) {
    						$email_text = stripslashes($email_options['page_text']);
    					} else {
    						$email_text = $email_page_text;
    					}
    					$email_link = $email_link.'emailpage/';
    				}
    				elseif (is_singular() && !is_singular('post'))	{
    					$email_link = $email_link.'?email=1';
    				}
    				else {
    					$email_link = $email_link.'email/';
    				}
    			} else {
    				if(is_page()) {
    					if(empty($email_page_text)) {
    						$email_text = stripslashes($email_options['page_text']);
    					} else {
    						$email_text = $email_page_text;
    					}
    				}
    				$email_link = $email_link.'&email=1';
    			}
    			break;

    What I have actually changed, is adding these lines to 249-251 –

    elseif (is_singular() && !is_singular('post'))	{
    					$email_link = $email_link.'?email=1';
    				}

    It will tell WP that if you are in a case of using non-default permalinks, and you are on a single page of a non-post type (aka, custom post type), than to populate the email page with a query variable ?email=1.

    Well, it works for me, and opening the standalone and also of course my nice colorbox.

    I hope it will help some of you.
    Lester Chan, if you add this as a version fix, I’d be happy if you could grant me a small credit of thanks inside the plugin 🙂

    Plugin Author Lester Chan

    (@gamerz)

    Thanks for the time maorb! I think that is still a partial fix as url now has been appended with email=1 instead of just /email/.This is top of my list of my WP plugins as this affected WP-Print as well. I just need to find time =(

    Thread Starter maorb

    (@maorb)

    Yes, it does adds ?email=1 instead of /email/. There should be no issue using the query variable in the url. It is better to have this instead of pretty permalink that leads to 404 page…

    Plugin Author Lester Chan

    (@gamerz)

    Agreed, I have problems finding the api that leads to the permalink generation for custom post types.

    What WP-Email does it gets the permalink, extract the approiate permalink, append /email to it and add back to the rewrite rule.

    Thread Starter maorb

    (@maorb)

    Maybe you could try asking in WordPress Stackexchange, someone might know to lead you with this issue?

    Hi there
    has there been any progress on this? I also need it to work for WP-Print

    thanks very much for your work on this matter.

Viewing 13 replies - 16 through 28 (of 28 total)
  • The topic ‘[Plugin: WP-EMail] Plugin not working with custom post type’ is closed to new replies.