Support » Plugins and Hacks » [Plugin: wp-tell-a-friend-popup-form] Help getting correct attachment->ID

[Plugin: wp-tell-a-friend-popup-form] Help getting correct attachment->ID

  • I’m trying to modify this plugin: http://wordpress.org/extend/plugins/wp-tell-a-friend-popup-form/ so that the popup will silently attach the PDF associated with the post that the email is sent from.

    The plugin’s TellAFriend() function is being called from the single.php template. Here’s the file that contains that script

    function TellAFriend()
        $TellAFriendLink = "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
        <a href='javascript:TellAFriend_OpenForm("TellAFriend_BoxContainer","TellAFriend_BoxContainerBody","TellAFriend_BoxContainerFooter");'><?php echo get_option('TellAFriend_Caption'); ?></a>
        <div style="display: none;" id="TellAFriend_BoxContainer">
          <div id="TellAFriend_BoxContainerHeader">
            <div id="TellAFriend_BoxTitle"><?php echo get_option('TellAFriend_Title'); ?></div>
            <div id="TellAFriend_BoxClose"><a href="javascript:TellAFriend_HideForm('TellAFriend_BoxContainer','TellAFriend_BoxContainerFooter');">Close</a></div>
          <div id="TellAFriend_BoxContainerBody">
            <form action="#" name="TellAFriend_Form" id="TellAFriend_Form">
              <div id="TellAFriend_BoxAlert"> <span id="TellAFriend_alertmessage"></span> </div>
              <div id="TellAFriend_BoxLabel"> Your Name </div>
              <div id="TellAFriend_BoxLabel">
                <input name="TellAFriend_name" class="TellAFriend_TextBox" type="text" id="TellAFriend_name" maxlength="120">
              <div id="TellAFriend_BoxLabel"> Recipient Email Address </div>
              <div id="TellAFriend_BoxLabel">
                <input name="TellAFriend_email" class="TellAFriend_TextBox" type="text" id="TellAFriend_email" maxlength="120">
              <div id="TellAFriend_BoxLabel"> Enter Message </div>
              <div id="TellAFriend_BoxLabel">
                <textarea name="TellAFriend_message" class="TellAFriend_TextArea" rows="3" id="TellAFriend_message"></textarea>
              <div id="TellAFriend_BoxLabel">
                <input type="button" name="button" class="TellAFriend_Button green-button" value="Submit" onClick="javascript:TellAFriend_Submit(this.parentNode,'<?php echo get_option('siteurl'); ?>/wp-content/plugins/wp-tell-a-friend-popup-form/');">
              <input type="hidden" name="TellAFriend_Link" id="TellAFriend_Link" value="<?php echo $TellAFriendLink; ?>"  />
        <div style="display: none;" id="TellAFriend_BoxContainerFooter"></div>

    From what I can tell, here’s the script that puts the email together. I added this to get the attachment:

    global $post;
    if ( $attachments = get_posts( array(
                    'post_type' => 'attachment',
                    'post_mime_type' => array('application/pdf'),
                    'numberposts' => 1,
                    'post_status' => null,
                    'post_parent' => $post->ID
                foreach ($attachments as $attachment) {
                    $attachments = array(get_attached_file( $attachment->ID ));

    And here’s where the email is put together:

    if($ToEmail <> "")
        @wp_mail(stripslashes($ToEmail), stripslashes($Subject), stripslashes($Usermail_Content), stripslashes($headers), $attachments );
        if($AdminEmail <> "")
            @wp_mail(stripslashes($AdminEmail), stripslashes($Subject), stripslashes($Adminmail_Content), stripslashes($headers), $attachments );
        echo "Message sent successfully.";
        echo "There was a problem with the request.";

    I have the $attachment-> variable printing in the email to troubleshoot. It’s returning 667 and the PDF with that ID for every post, regardless of which post i’m on. So, it’s pulling the PDf correctly, it’s just the wrong post’s attachment. I’m expecting it to return the correct attachment for the current post I’m on.

    What am I doing wrong that it’s not pulling the correct attachment->ID?

  • The topic ‘[Plugin: wp-tell-a-friend-popup-form] Help getting correct attachment->ID’ is closed to new replies.