• Resolved schwarzgrau

    (@schwarzgrau)


    I try to use Contact Form 7 on my author.php, to get a contact-form for every author.
    I already tried propably all solutions out there and the special-mail-tag [_post_author_email] doesn’t work on the author.php if you don’t wrap it in the loop and Contact Form 7 Dynamic Text Extension writes the recipient in the html-code.

    So I tried to modify the plug-in by editing the compose_mail function in classes.php.
    I changed the line
    $recipient = $this->replace_mail_tags( $mail_template['recipient'] );
    to

    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $_GET['author_name']) : get_userdata($_GET['author']);
    		$recipient = $curauth->user_email;

    and to

    global $wp_query;
    		$postquery = $wp_query->get_queried_object();
    
    		if ($postquery instanceof WP_User) {
        		$the_email = $postquery->user_email;
    		}
    		else {
    			$the_email = get_the_author_meta( 'user_email' );
    		}
    
    		$recipient = $the_email;

    But without luck. I’m not sure if you tolerate some alterations, but if you do so, I hope you could tell me what I’m missing.

Viewing 1 replies (of 1 total)
  • Thread Starter schwarzgrau

    (@schwarzgrau)

    I managed to use contact-form 7 on my author.php. But it requires a stupid setup:
    I created a custom post type called fake ( propably not the best name choice )
    And then on the author.php I used the following code:

    $cur_id = $curauth->ID;
    $dis_name = $curauth->display_name;
    
    $fakeposts = get_posts( array(
    				'post_type' => 'fake',
    				'author' => $cur_id )
    				);
    
    if (!empty($fakeposts)) : 							// If there is a fakepost show the contact-form for it
    	foreach( $fakeposts as $post ) :
    		setup_postdata($post);
    		echo do_shortcode('[contact-form-7 id="679" title="mensch-formular"]');
    	endforeach; wp_reset_postdata();
    
    else:
    	$my_fakepost = array( 							// If there isn't a fakepost create one ...
    		'post_title'    => 'fakepost_' . $dis_name,
    		'post_content'  => 'Fakepost für ' . $dis_name,
    		'post_status'   => 'publish',
    		'post_author'   => $cur_id,
    		'post_type' => 'fake'
    	);
    
    	$post_id = wp_insert_post( $my_fakepost );
    	$fakeposts = get_posts( array(
    					'p' => $post_id,
      					'post_type' => 'fake',
     					'author' => $cur_id )
     					);
     	foreach( $fakeposts as $post ) :				// ... and show the contact form for it
    		setup_postdata($post);
    		echo do_shortcode('[contact-form-7 id="679" title="mensch-formular"]');
    	endforeach; wp_reset_postdata();
    
    endif;

    Basically it creates a fakepost for every user and shows the form inside of its loop. So the [_post_author_email] tag will work.
    Again it’s a really stupid setup, but at least it works, you need no plugin and you still can update Contact Form 7.

Viewing 1 replies (of 1 total)
  • The topic ‘Contact Form on author.php’ is closed to new replies.