Jump to content

Proper coding 'grammar'


akarimov

Recommended Posts

I got the following code. I need to insert a "get_footer();" tag, but the code won't run. How do I code insert it properly?

 

				$random_password = wp_generate_password( 12, false );
			$status = wp_create_user( $username, $random_password, $email );
			if ( is_wp_error($status) ) 
				echo "Username already exists. Please try another one.";
---------------------------------INSERT get_footer(); HERE.-------------------------------------------
			else {
				$from = get_option('admin_email');
				$headers = 'From: '.$from . "\r\n";
				$subject = "Registration successful";
				$msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $random_password";
				wp_mail( $email, $subject, $msg, $headers );

				echo "Please check your email for login details.";
				get_footer();
			}

Link to comment
https://forums.phpfreaks.com/topic/249191-proper-coding-grammar/
Share on other sites

get_footer() statement is in multiple place in that code, and it works fine.

When I try to put get_footer() under echo "Usern ... her one." line - it gives me an error.

 

and yes, this is for wordpress

 

I need get_footer() to run under first condition, and it okay under second condition.

MasterACE's solution will work.  My suggestion is that you don't need to run get_footer() in every different senerio on the page.  Rather, run it at the bottom of the page, as it is served no matter what.  If there is ever a function that you must include in every if/else statement, putting it below all of the statements will get the same effect, but with less code.

My suggestion is that you don't need to run get_footer() in every different senerio on the page.  Rather, run it at the bottom of the page, as it is served no matter what.  If there is ever a function that you must include in every if/else statement, putting it below all of the statements will get the same effect, but with less code.

that is a far better solution. Rather than the 'quick fix'.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.