I just upgraded my site to a new version WordPress 3.9.2. I noticed that one of my page is not working the way it usually does. This page is password protected and I made changes on how it looks. When I upgraded, it doesn't work anymore. In the password protected page, I have this code:
<?php
echo "<script type='text/javascript'>\nwindow.location = 'http://www.google.com'</script>";
?>
The purpose of that one is to redirect to another page. And they go hand in hand with this code below.
Here is my old code:
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<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>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
Before the upgrade, after inputting the password it redirects me to another page, which is how I wanted it to work. But take note of the action attribute of form. In the WP 3.9.2, wp-pass.php does not exist anymore so I was looking for another code. I saw this line:
action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '"
But after inputting the password, it redirects me to the wp-login which is not what I wanted. I need help with this, which works the same way with the old code I'm using. I am not going to downgrade my WP or install any plugin. I just want the value of the action="" changed. Thanks!
I already found the answer. Maybe my files weren't compatible that's why it didn't work but here is the full code.
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<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>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
NOTE : I am using WordPress 3.9.2
I had the same problem and i found a solution
1) Set your page private with a password
2) Insert this form in an other page (typique postpass wordpress form) :
<form action="https://exemple.com/wp-login.php?action=postpass" class="post-password-form" method="post" id="go-pro-espace">
<input name="post_password" id="exemple" type="password" size="20" /><br />
<input type="submit" value="submit">
</form>
3) Change your /wp-login.php file (root directory, at this time, this is located line 460) :
from:
wp_safe_redirect( wp_get_referer() );
to:
wp_safe_redirect( "https://exemple.fr/your-protected-page" );
Take a look to the answer: Wordpress protected page, POST form on a other page
Related
This is my code:
public function settings_inline_style_callback() {
$type = esc_html( $this->options['inline_style'] );
$temp0 = '<input type="radio" name="My_options[inline_style]" id="inline_style_';
$temp1 = '<label for="inline_style_';
$html = $temp0 . '0" value="0" ' . checked( $type, '0', false ) . ' />';
$html .= $temp1 . '0">External CSS style</label><br />';
$html .= $temp0 . '1" value="1" ' . checked( $type, '1', false ) . ' />';
$html .= $temp1 . '1">Inline CSS style</label>';
echo $html;
}
The WordPress plugin review team said the escape was not done properly. They said you have to escape WHEN you echo. Not when you save to the variable. (in this line: echo $html;)
I am new to WordPress and PHP. I do not understand the problem with this code.
How should I modify this code?
Thank you very much for your help.
So this is because the esc_html function only works when running during echo. Below is a way you can do your code.
printf(
'<input type="radio" name="My_options[inline_style]" id="inline_style_0" value="0" %s/>
<label for="inline_style_0">External CSS style</label><br />
<input type="radio" name="My_options[inline_style]" id="inline_style_1" value="1" %s/>
<label for="inline_style_1">Inline CSS style</label>',
checked(esc_html($this->options['inline_style']), '0', false),
checked(esc_html($this->options['inline_style']), '1', false),
);
I created a search form for my custom post types and I want to be able to place it anywhere on my site, so I created a shortcode. The vanilla form works fine, but in a shortcode, it's displaying duplicate fields. Can anyone see why it would do this? The top 3 fields are duplicates of the fields in the lower form. You can see the result at http://autismva.teebark.com/resource-finder-3.
You can see the vanilla form at http://autismva.teebark.com/resource-finder2
function resource_search_form( $form ) {
$form = '<form id="category-select" class="category-select" method="post" action="' . esc_url(admin_url('admin-post.php')) . '" >' .
wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ) . '<br>' .
wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ) . '<br>' .
wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ) . '<br>' .
'<input type="text" name="s" placeholder="Search by keyword" /><br>
<input type="text" name="tag_name" placeholder="Search by tag" />
<input type="hidden" name="action" value="resource_search_cat2" />
<button type="submit" > Search </button>
</form>';
return $form;
}
add_shortcode('resource_search', 'resource_search_form');
**The vanilla form:**
<form id="category-select" class="category-select" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" >
<?php wp_dropdown_categories( 'show_count=1&hierarchical=1&depth=2&show_option_none=Select by category&name=$cat_id&taxonomy=resource_cat' ); ?><br>
<?php wp_dropdown_categories( 'show_count=0&hierarchical=1&depth=1&show_option_none=Select by age&name=$age_id&taxonomy=resource_age' ); ?><br>
<?php wp_dropdown_categories( 'show_count=0&exclude=128&show_option_none=Select by region&name=$region_id&taxonomy=resource_region' ); ?><br>
<input type="text" name="s" placeholder="Search by keyword" /><br>
<input type="text" name="tag_name" placeholder="Search by tag" />
<input type="hidden" name="action" value="resource_search_cat2" />
<button type="submit" > Search </button>
</form>
I hope this will work for you.
// write this action in your "after_setup_theme" hook
add_action( ' woocommerce_single_product_summary ' , ' your_function_name ' , 10 );
//define your function that contains the removal action hook.
function your_function_name()
{
remove_action( ' woocommerce_single_product_summary ' , ' woocommerce_template_single_add_to_cart ' , 30 );
}
I am new to wordpress. I am trying to call function myprefix_edit_user_cb() to get the edit form after user clicks on edit.
function getdata()
{
$blogusers = get_users();
foreach ( $blogusers as $user ) {
echo '<span>' . esc_html( $user->user_email ) . '</span>';
$editUrl = ??
echo "<a href='".$editUrl. "'>Edit User</a>";
echo '<br>';
}
}
with function:
function myprefix_edit_user_cb(){
$user = intval($_REQUEST['user']);
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<label>Username</label>
<input type="text" value="' .$user->user_login . '"
<input type="submit">
';
}
According to me you need to put some request flag with your edit url.
Try the below code.
function getdata(){
$blogusers = get_users();
foreach ( $blogusers as $user ) {
echo '<span>' . esc_html( $user->user_email ) . '</span>';
$deleteUrl = add_query_arg(array('action'=>'myprefix_delete_user', 'user_id'=>$user->ID));
$editUrl = add_query_arg(array('action'=>'myprefix_edit_user', 'user'=>$user));
echo "<a href='".$deleteUrl. "'>Delete User</a>";
echo "<a href='".$editUrl. "&edit=1'>Edit User</a>";
echo '<br>';
}
}
with action and callback function with flag :
add_action('init','myprefix_edit_user_cb');
function myprefix_edit_user_cb(){
$user = intval($_REQUEST['user']);
if($user == '')
return;
if($_REQUEST['edit'] == 1 )
{
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<label>Username</label>
<input type="text" value="' .$user->user_login . '"
<input type="submit">
';
}
}
What you are asking all depends on where you would like to allow the user to be edited. Here is my preferred option (assuming you are doing everything on the front side of the website):
Create a page with a page template.
By default most themes come with some basic templates for how a page will look. Seeing as you may wish to add an edit form to a page, creating a custom page template would be a straight forward move. A good tutorial for creating these can be found here. Once created you would add some code like this to the template:
<?php if (isset($_GET['user_id'])): ?>
<?php $user = get_user_by('id', intval($_GET['user_id'])); ?>
<form action="#" method="post">
<label>Username</label>
<input type="text" value="<?= esc_attr($selected_user->user_login); ?>" />
<input type="submit" />
...
</form>
<?php else: ?>
<p>Error, please specify a user id!</p>
<?php endif; ?>
Which would do a basic test to make sure user_id had been passed to the page, then load the form accordingly (to improve on this I would also check to see if get_user_by returns an object before showing an edit form just in-case the user_id is invalid). In the provided example a URL (with permalinks set to page-name) would look like this:
https://example.com/edit-page/?user_id=55
There are ways of making the URL cleaner, however for now I am just trying to make sure your question is answered with a correct working example.
Koda
I have code like this using WordPress:
function an_max_form($id,$maxList)
{
global $wpdb;
$table_name = $wpdb->prefix . "maxform_r";
$maxrow = $wpdb->get_row( $wpdb->prepare( "SELECT id,maxlist FROM %s", $table_name ) );
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
<input type="hidden" name="id" value="' . (isset( $_POST['id'] ) ? $id : $maxrow->id ) . '" />
<div>
<label for="maxList">Maximum List</label>
</div>
<div>
<input type="text" name="maxList" value="' . (isset( $_POST['maxList'] ) ? $maxList : $maxrow->maxlist ) . '"/>
</div>
<div>
<input type="submit" name="submit" value="Save" />
</div>
</form>
';
}
This form will fetch 1 row from the database and populate it into this form. But why my form doesn't return any value. I tried to debug it using echo $maxrow->id but still empty. Anyone know what is wrong with my coding?
I tried to make a comment form in WordPress as much as customizable it can be. I'm using SI Captcha plugin with this form. My question is: "It's possible to make my own form to insert my custom fields with wp_insert_comment, in comment tables of WordPress?".
I don't want to use $args and comment_form($args). I want to make my own form. Is it possible?
My extra fields will be city and captcha.
What I tried till now:
$comment_args = array( 'title_reply'=>'Comentarii', 'comment_notes_before' => '', 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '
<div class="comment_left">
<p class="comment-form-author">'. ( $req ? '<span>*</span>' : '' ) . '
<input id="author" name="author" placeholder="Nume" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" ' . $aria_req . ' />
</p>', 'email' => '
<p class="comment-form-city">' . ( $req ? '<span>*</span>' : '' ) . '
<input id="email" name="email" placeholder="E-mail" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" ' . $aria_req . ' />'.'</p>', 'city' => '
<p class="comment-form-email">' . ( $req ? '<span>*</span>' : '' ) . '
<input id="city" name="city" placeholder="Oras" type="text" value="' . esc_attr( $commenter['comment_author_city'] ) . '" size="30" ' . $aria_req . ' />'.'</p>
</div>', 'url' => '' ) ), 'comment_field' => '
<div class="comment_right">
<p>' . '
<textarea id="comment" name="comment" placeholder="Mesajul tau" cols="45" rows="8" aria-required="true"></textarea>' . '
</p>
</div>', 'comment_notes_after' => '', 'label_submit'=>__('Scrie o parere') ); comment_form($comment_args);
I also have to say that wp_insert_comment it's working with a custom form, but how do I add the extra field with add_comment_meta. I tried this next function but is not working:
add_action( 'comment_post', 'save_comment_meta_data', 1 );
function save_comment_meta_data( $comment_id ) {
add_comment_meta( $comment_id, 'city', $_POST[ 'city' ] );
}