Archive for August, 2011

How to get into a WordPress site without a login, just FTP

August 22nd, 2011

Ok interesting problem for you… your client gives you the FTP information for his server but has no idea what the admin password is for the WordPress site you are supposed to be working on is. Sounds a little odd but in the case I experienced the user account was an Editor role which is, in effect, useless if you want to play with plugins or users etc…

Here’s how I got in…

WordPress stores it’s passwords as hashes in the database for security purposes. Annoying if you are trying to find out other people’s passwords though. Luckily the hashinh algorithm is standard md5 across any site you use. I have several WordPress sites of my own set up so I opened up Navicat and got the password hash for a site I know the password to.

I then opened up the functions.php file for the theme I knew was active on the clients server and added the following code:

global $wpdb;
$sql = 'SELECT * FROM ' . $wpdb->users;
echo '<pre>';
print_r($wpdb->get_results($sql));
echo '</pre>';

$sql = 'UPDATE ' . $wpdb->users . ' SET user_pass = "$P$Ba8do3KsWiaThA80UbfHygumoUFu3i1" WHERE ID = 1';
$wpdb->query($sql);

Idiot proof right! You need the first query to give you the name of the admin account. This is the one with the ID of 1 and the original hash to put back once you have your own user. The second part updates that record with your own password hash. Only run the page the once and make sure to write down the old password hash because you will lose it on the second refresh otherwise.

Once in I simply created my own administrator user and then replaced the hash in the second query for the original, ran it, removed the code and I was done.

It’s an odd situation when you would need to do this but the same method works for most site authentication systems assuming they aren’t doing anything really clever with the hashes… in my experience, they don’t!

Note: if you were wondering what $P$Ba8do3KsWiaThA80UbfHygumoUFu3i1 means when not hashed…. it’s ‘sausages’ :)

WP Ecommerce template redirect

August 18th, 2011

Today I spent a good two to three hours making zero progress on a site which I was upgrading. I am making changes to the design but sadly didn’t get that far as first I decided to update WordPress and the plugins. The upgrade to WP 3.2.1 went well as did every other plugin except WP Ecommerce. I know this plugin to be a troublemaker but sadly as it’s the only half decent cart WordPress has to offer (and it’s pretty dire really).

The issue I was facing is that we have a custom page template for the shop to include a different sidebar and some other small changes. Upon upgrading the page template decided to revert to the theme’s page.php file instead of the template-shop.php we were using previously. Lots of head scratching and shouting followed and a couple of reverts from backups but eventually I got it down to a single function in the theme.functions.php file in the wpsc-includes directory. There are a couple of fixes you could use although the most straightforward is a hack to one of their core files… Sadly for me I don’t like doing that as the next time you upgrade you get to do it all over again. Luckily they had the foresight to add an action call at the top of the function so I wrote the following.

The Code

add_action('wpsc_swap_the_template', 'include_shop');

function include_shop() {
    global $wp_query,$wpsc_query;

    $products_page_id = wpec_get_the_post_id_by_shortcode('[productspage]');
    $term = get_query_var( 'wpsc_product_category' );
    $tax_term = get_query_var ('product_tag' );
    $obj = $wp_query->get_queried_object();
    $id = isset( $obj->ID ) ? $obj->ID : null;

    if( get_query_var( 'post_type' ) == 'wpsc-product' || $term || $tax_term || ( $id == $products_page_id )){

	$shop_template = trailingslashit(TEMPLATEPATH) . 'template-shop.php';
	require_once($shop_template);
	die;
    }
}

How to integrate it

To get this to work you just need to add it to your theme functions.php file and change where I have “template-shop.php” to be the name of your own template. This may well not even be an issue unless upgrading from an old version of WPSC but this fix worked for me.

As an aside I note the following comment left by one of the developers

// have to pass 'page' as the template type. This is lame, btw, and needs a rewrite in 4.0

Note: this was an issue when migrating from WP Ecommerce versions 3.7.7 to 3.8.6

SB Comment Reviews get’s WP-Ecommerce compatibility

August 16th, 2011

My Birthday today(!) so only a quick post before I go off gallivanting with my family…

I just updated my review system plugin to incorporate custom post types. On activation it adds records into it’s settings page for the custom post types you have on the system and sets the system to off for those types. So you simply add my plugin then go to the settings page and turn the system on for the post types you like.

I did this because I needed to write a product review system for WP-Ecommerce today. Their system incorporates a star rating and you can comment on products but not both together.. ie you can’t rate a product and leave a review in one go. My plugin, as you should know, takes over the WP comments system and adds the ability to add a star rating. You might need to custom code your Ecommerce template if you want to report on the average star rating but even without it works a treat.

Enjoy!

Download

SB Comment Reviews (12.53 kB)

WordPress plugin – SB User Cols

August 14th, 2011

Just a quick one today. I had to be able to sort the users list within the admin pages by the date the users registered for the system. This meant I had to both add the column and make it sortable. WordPress is slightly flawed with the sorting in that it’s not the easiest thing in the world to do however at least it’s possible. A brief Google search turned out only requests for support on the first page so to remedy that I wrote a very simple plugin to accomplish it.

Download

SB User Cols (650 bytes)

SB Comment Reviews

August 3rd, 2011

Another little plugin for you to play with. I was, today, looking for a simple plugin to convert WordPress comments into a kind of review/ratings system. The idea being that a comment would be left against a product posting or something similar and people could then rate the page/post at the same time. I wanted the ability to add a star rating and then keep an average against posts and pages themselves.

This is only very basic for the moment but I would happily extend it according to demand. Let me know if you have any ideas for it.

Features so far…

- Optional post/page override whereby you can set this plugin to take over comments systems on pages only but not posts or vice-versa (or any combination.. no custom post types yet).

- Automatic addition of the functionality to the end of posts/pages and comment rows.

Screenshots below

Download the plugin

SB Comment Reviews (12.53 kB)