I'm creating a wordpress theme from scratch and using the following in my wordpress functions.php file to be able to style protected posts.
The code, taken from here – tutsplus
However the code is giving my a white screen each time I try to login to the backend or update posts. Any advice on what I could be missing here would be greatly appreciated.
<?php
add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<div id="protected">
<form class="protected-post-form" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
<div class="padlock"></div>
' . __( "You'll need a password to get in here" ) . '
<label class="pass-label" for="' . $label . '">' . __( "PASSWORD:" ) . ' </label><input class="post_password" name="post_password" id="' . $label . '" type="password" placeholder="Password"/><input type="submit" name="Submit" class="button" value="' . esc_attr__( "Submit" ) . '" />
</form></div>
';
return $o;
}
?>
EDIT — After removing the theme and playing around, the error is definitely in this .functions.php file, I'm just unsure where
Make sure there is no empty lines before opening from the functions.php.
Related
thank you for the help in advance. I have been trying to find tutorial about building my own contact form for wordpress (without plugin). I thought i found one (part of the question).
<?php
/*
Plugin Name: Self Catering Contact form plugin
Plugin URI: http://example.com
Description: Simple non-bloated WordPress Contact Form use [contact_form]shortcode
Version: 1.0
Author: Agbonghama Collins
Author URI: http://w3guy.com
*/
function html_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br />';
echo '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br />';
echo '<input type="email" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject (required) <br />';
echo '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value="' . ( isset( $_POST["cf-subject"] ) ? esc_attr( $_POST["cf-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br />';
echo '<textarea rows="10" cols="35" name="cf-message">' . ( isset( $_POST["cf-message"] ) ? esc_attr( $_POST["cf-message"] ) : '' ) . '</textarea>';
echo '</p>';
echo 'Select date <br />';
echo '<p><input type="text" id="datepicker" name="datepicker" value="' . ( isset( $_POST["datepicker"] ) ? esc_attr( $_POST["datepicker"] ) : '' ) . '" size="40" />'.'</p>';
echo '<p><input type="submit" name="cf-submitted" value="Send"/></p>';
echo '</form>';
}
function deliver_mail() {
// if the submit button is clicked, send the email
if ( isset( $_POST['cf-submitted'] ) ) {
// sanitize form values
$name = sanitize_text_field( $_POST["cf-name"] );
$email = sanitize_email( $_POST["cf-email"] );
$subject = sanitize_text_field( $_POST["cf-subject"] );
$message = esc_textarea( $_POST["cf-message"] );
$datepicker = sanitize_text_field($_POST["datepicker"]);
// get the blog administrator's email address
$to = 'xx#xx.co.uk';
$headers = "From: example#yourdomainname.com" . "\r\n";
// If email has been process for sending, display a success message
if ( wp_mail( $to, $subject, $message, $headers ) ) {
echo '<div>';
echo '<p class="red">sent</p>';
echo '</div>';
} else {
echo 'An unexpected error occurred';
}
}
}
function cf_shortcode() {
ob_start();
deliver_mail();
html_form_code();
return ob_get_clean();
}
add_shortcode( 'contact_form', 'cf_shortcode' );
This is what my contact-form.php looks like. My first problem that it doesnt send the email - or it doesnt arrive even tho it says that the mail was sent. I have read a few things for example some hosting providers dont allow you to use different email address to your domain ones... Could somebody explain this?
If you still have enough patience left, could somebody guide me through how to implement datepicker (which i thought i have done), and how to handle or get the data from it to be included in the email?
Thank you very much for your time...
I would like to customize the output of comment_form() function in WordPress.
To edit fields and textarea, I used the following code and all works fine.
<?php
$req = get_option( 'require_name_email' );
$fields = array(
// redefine author field
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name:' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-user"></i></span><input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . 'aria-required="true"' . ' required /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email Address:' ) . ( $req ? ' <span class="required">*</span><br/>' : '' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-envelope"></i></span><input required id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . 'aria-required="true"' . ' required /></div></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Your Website:' ) . '</label>' .
'<div class="input-prepend"><span class="add-on"><i class="icon-globe"></i></span><input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div></p>'
);
$comments_args = array(
'fields' => $fields,
// redefine your own textarea (the comment body)
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . 'Comment' . '</label><textarea id="comment" name="comment" class="span12" rows="5" aria-required="true"></textarea></p>',
);
comment_form( $comments_args );
?>
This is the result:
Now, I would like to add two CSS class (class="btn btn-primary") for submit button; how can I do that without using jQuery?
Note:
For the solution, please read comments about answer marked with green sign.
As krizna said, you can modify your theme's comments.php file to alter the output of comment_form(). I think that might be your best bet in this situation.
If you take a look at the Function Reference for comment_form() in the Codex you'll notice that you can only modify the ID for the submit button, and not the class. There are a few tickets on Trac regarding this:
http://core.trac.wordpress.org/ticket/20446
http://core.trac.wordpress.org/ticket/15015
If modifying comments.php doesn't work for you in this situation, you can try applying one of the patches.
I'm trying to display the current date and time on my WordPress website. I want the date and time to reflect the Timezone that has been set in the WordPress admin area.
I found this code in options-general.php:
<tr>
<th scope="row"><?php _e('Date Format') ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Date Format') ?></span></legend>
<?php
$date_formats = array_unique( apply_filters( 'date_formats', array(
__('F j, Y'),
'Y/m/d',
'm/d/Y',
'd/m/Y',
) ) );
$custom = true;
foreach ( $date_formats as $format ) {
echo "\t<label title='" . esc_attr($format) . "'><input type='radio' name='date_format' value='" . esc_attr($format) . "'";
if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "==="
echo " checked='checked'";
$custom = false;
}
echo ' /> <span>' . date_i18n( $format ) . "</span></label><br />\n";
}
echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
checked( $custom );
echo '/> ' . __('Custom:') . ' </label><input type="text" name="date_format_custom" value="' . esc_attr( get_option('date_format') ) . '" class="small-text" /> <span class="example"> ' . date_i18n( get_option('date_format') ) . "</span> <span class='spinner'></span>\n";
echo "\t<p>" . __('Documentation on date and time formatting.') . "</p>\n";
?>
</fieldset>
</td>
</tr>
I tried adding:
<?php m/d/Y ?>
To my website code to output the current date but it didn't work. What am I missing?
I think you must do
<?php echo date_i18n( 'm/d/Y' ) ?>
Try with:
$format = get_option('date_format') . ' ' . get_option('time_format');
print date_i18n($format, current_time('timestamp'));
WordPress has a current_time() function that returns the blog time, which might differ from the server time if you selected a different timezone in your blog settings...
I'm using the default twenty_ten theme that comes with the latest Wordpress and modifying it. I just want to add a class to certain text inputs within the new comment form (specifically to add class="text" to make it play nice with Blueprint CSS framework).
I can't locate the place to do this. Not au fait with PHP but able to work my way around it in most cases - just can't seem to locate the form here.
Any help appreciated.
The comment form is output by the WordPress comment_form() function. To add a CSS class to specific inputs, you can change the $fields argument when it's called from the bottom of the TwentyTen comments.php file.
In the example below I've added class="text" to the author input field:
<?php
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input class="text" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
comment_form(array('fields'=>$fields));
?>
Alternatively you could create a filter in your theme's functions.php that added the input class for you:
function my_comment_fields($fields) {
foreach($fields as $field){
// Add the class to your field's input
}
return $fields;
}
add_filter('comment_form_default_fields','my_comment_fields');
Login in to you Control Panel.
Open wp-includes folder from File Manager.
Select comment-template.php and Click Edit.
Go to the line 1541 or search for ‘’ Near to this you can see “Your email address will not be published. Required fields are marked *”
$fields = array(
'author' => '<p>' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span>*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />',
Read more at aTechguide.com http://atechguide.com/edit-comment-form-wordpress
I'm trying to edit the template page which is used when a page or post is password protected. I can't seem to have much luck locating it.
do you know where it is?
It's my understanding that the password protected pages/posts use the same templates are regular pages/posts. If you're looking to change the standard message "My post is password protected. Please ask me for a password:", try adding this code snippet (changing the text to read how you want) to your theme's function.php file:
function fb_the_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
<p>' . __("My post is password protected. Please ask me for a password:") . '</p>
<p><label for="' . $label . '">' . __("Password") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
</form>';
return $output;
}
add_filter('the_password_form', 'fb_the_password_form');
I found this over at Change Wording for Password Page by WP Engineer.
In a child theme of twenty-thirteen, the above did not work. Instead, I used this code (unfortunately, I cannot remember who wrote it):
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "Some custom statement here.\nAnd a second line:\n" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form><p style="font-size:18px;margin:0px; padding: 8px; background: lightblue; height: 40px; width: 400px; text-align: center;">Some other text here</p>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>