When you enable the function that allows anyone to register on your WordPress website, WordPress sends a link which looks like this:
<https://your-domain.com/wp-login.php?
action=rp&key=DFmJxTfZvqYQKJOAhBtA&login=Alice%20Cooper>
Unfortunately, some popular email providers, such as iCloud can't read <> tag properly. As a result, a visitor who is about to register on your website receives an error "Your password reset link appears to be invalid. Please request a new link below."
How could I force WordPress to remove this tag <...> in order to send the clear link?
P.s.: I know about the so-called "caching issues." In my case, I hope anyone might advice some add_action or another solution.
Filter the wp_mail function:
add_filter( 'wp_mail','remove_tags' );
function remove_tags( $args ){
$args['message'] = str_replace( '<', '', $args['message'] );
$args['message'] = str_replace( '>', '', $args['message'] );
return $args;
}
More information here: wp_mail.
Related
Can someone help me out with Woocommerce issue. I see that they removed shortcode for forgot password, but I am in need of one, since I am trying to embed the form in pop-up.
If anyone who had a similar problem can help, it would be great.
In the end, it doesnt need to be a Woocommerce one, it can be anything.
Below custom shortcode that allow you use [lost_password_form] shortcode
<?php
function wc_custom_lost_password_form( $atts ) {
return wc_get_template( 'myaccount/form-lost-password.php', array( 'form' => 'lost_password' ) );
}
add_shortcode( 'lost_password_form', 'wc_custom_lost_password_form' );
?>
I am trying to do a redirection inside my plugin, I want to send the user directly to the edit post page, instead it is redirecting to the post list.
wp_redirect( get_edit_post_link( $post_id ) ); exit;
For your information, get_edit_post_link() is returning the right value: http://localhost/wp-admin/post.php?post=63&action=edit.
If someone is still looking for this, try:
wp_redirect( get_edit_post_link( $post_id, '' ) ); exit;
From WP docs:
context (string) (optional) How to write ampersands. Defaults to
'display' which will encode as '&'. Passing any other string
(including an empty string), will encode ampersands as '&'. Default:
'display'
I can't tell you why get_edit_post_link doesn't play nice within wp_redirect, but if you pass the edit post link path to admin_url it works:
wp_redirect( admin_url( '/post.php?post=' . get_the_ID() . '&action=edit' ) ); exit;
Check the role of the user you are testing with.
If its author, an author / contributor cannot edit other's post.
I have pretty links enabled, but when I want to retrieve url of custom post type via get_post_pemalink() I get 'not so pretty' link except pretty link.
For example:
function send_ad_analytics_mail($ID, $post) {
$link = get_post_permalink($ID);
$to = 'example#gmail.com';
$subject = 'Post is drafted';
$message = 'You can see it on ' . $link;
$headers = array(
'From: example#example.rs'
);
wp_mail($to, $subject, $message, $headers);
}
add_action('draft_business', 'send_ad_analytics_mail', 10, 2);
And I get an email like this:
You can see it on http://example.rs/?post_type=business&p=46934
But what I want is: You can see it on http://example.rs/business/new-jobs/
The issue is the hook you've chosen to use: draft_business.
I'm guessing that you've got a post type called "business".
And, the hook you are using as hooking into the Post Status Transitions for that post.
However, because you have draft_business, this is hooking the status as the post is transitioned to the status of draft. A non-published post will never have a pretty permalink, therefore this hook will never return a pretty permalink, but always an "ugly" one as you have shown.
I wrote a plugin.
One of the plugin's settings is a URL/page.
I want my client to be able to continue to use the theme's page builder, to create any buttons that will link to the URL that is entered in the plugin's settings.
The client could enter the URL manually for every button they create, but this would be tedious, and will become a massive pain should the URL in the plugin's settings change.
So, I want to be able to use the plugin's URL setting value as the URL attribute of a third-party button shortcode.
Is this possible? Something like:
[button url="{get the plugin's URL setting}"][/button]
Yes definitely possible.
You would need to add the shortcode functionality to your plugin. Best to use a unique name to avoid conflicts (not 'button').
in your plugin php file add the function and register it with the add_shortcode function like so:
function shortcodeName_function( $atts ) {
// add attribute handling and get the 'url' parameter
$output = '<button a href="'. $url . '" class="button">';
return $output;
}
add_shortcode( 'shortcodeName', 'shortcodeName_function');
Now u can use now a short code with this name, when the plugin is activated.
[shortcodeName]
See the link of the wordpress documentation for more info on parameter handling: wordpress shortcode api
EDIT: ah sorry, I think I missed the point a bit. What you could do is - store the plugin url setting in a cookie and check for the cookie value in the short code.
When shortcode have not attribute url you can provide default settings url in shortcode return output.
Like this
add_shortcode( 'button', 'shortcode_function_button');
function shortcode_function_button( $atts ){
$attr = shortcode_atts( array(
'url' => get_option( 'button_default_url' ) , // get your setting default url if shortcode have not
), $atts ); // attr url="http://example.com" then it use default
// setting url
return 'Button';
}
If already build shortcode in plugin or theme then find shortcode callback function and change atts in this way.
If probleming in find third party shortcode callback name check in your plugin file all registered shortcodes with callback.
global $shortcode_tags;
print_r( $shortcode_tags );
// show all shortcodes with callback
/*Array
(
[embed] => __return_false
[wp_caption] => img_caption_shortcode
[caption] => img_caption_shortcode
[gallery] => gallery_shortcode
[playlist] => wp_playlist_shortcode
[audio] => wp_audio_shortcode
[video] => wp_video_shortcode
[button] => button_shortcode
)*/
If do you not want to any change in thired party shortcode and manage in your plugin
Remove shortcode previously declared thired party plugin and add in your plugin top of file.
remove_shortcode('button'); // https://developer.wordpress.org/reference/functions/remove_shortcode/
Recreate same shortcode tag after remove but use own callback name and work same as thired party shortcode like this
add_shortcode( 'button', 'your_own_callback' );
function your_own_callback( $atts, $content ){
$attr = shortcode_atts( array(
'url' => get_option( 'button_default_url' ) , // Use same atts thired party using atts
), $atts );
return button_shortcode( $attr, $content); // Use thired party callback function name.
}
I programmatically log in a user in Wordpress (before headers are sent), using a session variable from a previous page. Later in this same page, in the body section, I var_dump: wp_get_current_user(). This returns the WP_User I logged in with. In the 'log in' section I have tried combinations of wp_signon(), wp_set_current_user() and wp_set_auth_cookie().
The problem comes, when I navigate away from this page, the user isn't logged in anymore. When I use wp-login.php, the user stays logged in. I've struggled with this for quite a while and can't seem to find, why the user won't stay logged in.
Can someone help please. I'll add snippets of currently used code below:
$creds = array(
"user_login" => $_SESSION['email'],
"user_password" => $newPass,
"remember" => true
);
$user = wp_signon( $creds );
if ( is_a( $user, 'WP_User' ) ) {
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID, true );
}
// Code follows ...
<body>
<?php if ( is_user_logged_in() ) var_dump(wp_get_current_user()); ?>
Where is it being executed? You'll need to put it in an action. Use:
add_action('theme_setup','your_code');
function your_code(){
//signin code block goes here
};
I eventually moved a segment of the code to another file. Something I failed to include was that I used wp_create_user on the same page. As soon as I replaced wp_set_current_user and wp_set_auth_cookie with wp_signon and moved it to a separate page, everything worked perfectly.