Archive for the ‘web’ Category

Woocommerce logout without wp-login.php

December 13th, 2017 No comments

Consider the following scenario; you have a Woocommerce store up and running and you need to apply some basic security features. Restricting access to wp-admin.php and wp-login.php is at the top of my list, which can be achieved with a couple of rules in .htaccess.

Once you do this, your store should a slightly more secure and everything works fine! Up until you try to logout. Logging out requires visiting wp-login.php which is now restricted, resulting to an error and hence the user cannot log out. A workaround is detect when the Woocommerce directs to /customer-logout and log out the user using wp_logout() command. Finally, you can redirect the user to a page of your choice using wp_redirect(). I chose to redirect to My Account. The code was re-purposed from a popular demand to “Logout the user without confirmation“, which I used to achieve what I wanted.

So, include the following code to your theme’s functions.php and you should be good to go.

// Logout without confirmation.
function logout_without_confirmation() {
    global $wp;
    if ( isset( $wp->query_vars['customer-logout'] ) ) {
        wp_redirect(wc_get_page_permalink( 'myaccount' ));
add_action( 'template_redirect', 'logout_without_confirmation' );
Categories: web Tags:

wp_insert_post removes style elements

April 29th, 2010 1 comment

Recently I was using the wp_insert_post function of wordpress to make a post through a plugin. The problem is that this function removed the styling element I included. For example I used this:

<div id="myid">Hello</div>

and after posting this through wp_insert_post it got like this:


I search for a solution for a couple of days but I couldn’t find a straight answer. Anyway, as it turned out it’s not such a hard problem. I am not a wordpress wizard (not even close :P) but I believe I solved my problem.

Locate the file /wp-includes/kses.php . This function is called when you make a post to filter out all the bad things that may be a risk for your blog. At line 44 (on my file) you can see an array of allowedPostTags. If you take a look you can see that what I was trying to add i.e. the id it is not conained in the div sub-array. That is the reason why it was removed. So I believe you can do 2 things:

  • You can use an allowed tag instead. This is what I did. I noticed that div class was an allowed tag so I used that instead of div id. Not much difference for me 🙂 and it worked.
  • I believe you can also manually add the id tag in the div sub-array in the same way as the other tags are added and it wont be removed. I have’t tested that but I am pretty sure it would work

Anyway, that’s all. I hope you can solve your problem. Let me know in the comments if you need some help.

See ya.

Incoming search terms:

  • wp_insert_post (16)
Categories: web Tags: