WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: cubePM] the_author() appears twice, once before use? (2 posts)

  1. RGBY
    Member
    Posted 1 year ago #

    New user but haven't been able to solve a problem I have despite searching the forums.

    I am editing the cubePM plugin to suit my needs a bit better, the modification is to basically have a custom widget to send the post author a message about the current post.

    I have managed to create a new shortcode and have the new form working, you can select the username you want to send to and the message will send.

    I decided to automatically fill in the recipient field with the_author(); This works fine but for some reason the_author() gets published above the form?

    My code in the plugin which generates the form:

    function cpm_page_new_form2(){
    	if(isset($_REQUEST['cpm_recipient'])){
    		$cpm_recipient = $_REQUEST['cpm_recipient'];
    	}
    	else{
    		$cpm_recipient = '';
    	}
    	if(isset($_REQUEST['cpm_subject'])){
    		$cpm_subject = $_REQUEST['cpm_subject'];
    	}
    	else{
    		$cpm_subject = '';
    	}
    	if(isset($_REQUEST['cpm_message'])){
    		$cpm_message = $_REQUEST['cpm_message'];
    	}
    	else{
    		$cpm_message = '';
    	}
    	$html = '<form method="post" action="?cpm_action=new">';
    	$html .= '<input type="hidden" name="cpm_form_submit" value="1" />';
    	$html .= '<p><input type="hidden" name="cpm_recipient" id="cpm_recipient" value="'.the_author().'" /></p>';
    	$html .= '<p><label for="cpm_subject">'.__('Subject', 'cubepm').':</label><br /><input type="text" name="cpm_subject" id="cpm_subject" value="'.$cpm_subject.'" /></p>';
    	$html .= '<p><label for="cpm_message">'.__('Message', 'cubepm').':</label><br /><textarea name="cpm_message" id="cpm_message">'.$cpm_message.'</textarea></p>';
    	$html .= '<p><input type="submit" name="cpm_submit" id="cpm_submit" value="'.__('Send PM', 'cubepm').' »" /></p>';
    	$html .= '</form>';
    	return $html;
    }

    the output in html

    <div class="singletab">
    	Tyler168
    	<div class="cubepm">
    		<div class="cpm-header"></div>
    		<h2>Send PM</h2>
    		<form method="post" action="?cpm_action=new">
    			<input type="hidden" name="cpm_form_submit" value="1" />
    			<p><input type="hidden" name="cpm_recipient" id="cpm_recipient" value="Tyler168" /></p>
    			<p><label for="cpm_subject">Subject:</label><br />
    			<input type="text" name="cpm_subject" id="cpm_subject" value="" /></p>
    			<p><label for="cpm_message">Message:</label><br />
    			<textarea name="cpm_message" id="cpm_message"></textarea></p>
    			<p><input type="submit" name="cpm_submit" id="cpm_submit" value="Send PM »" /></p>
    		</form>
    	</div>
    </div>

    If I swap the_author() for something basic like name then the form will have the recipient 'name' and the_author() does no appear above the form.

    Really confused by this one, it's my first serious attempt at modifying a plugin, and this is the last hurdle for me.

    If it gets sorted I will be emailing the creator with my new version to release.

    Any help greatly appreciated

  2. RGBY
    Member
    Posted 1 year ago #

    fixed it, as is always the way as soon as I posted I changed it to get_the_author()

Topic Closed

This topic has been closed to new replies.

About this Topic