WordPress

Tag: WordPress

Image of locks

Locked out of WordPress? Create new Admin Account via FTP

Have you ever found yourself locked out of your WordPress admin-level account and email recovery won’t work for you? Well, if you have FTP access, you can create a new account that will get you into the system and allow you to set things right.

By placing the following code into a plugin folder or adding it to the current theme’s functions.php file, a new user will be added to WordPress as soon as the next page is drawn on your site.

function add_admin_acct(){
$login = 'myacct1';
$passw = 'mypass1';
$email = 'myacct1@mydomain.com';

if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','add_admin_acct');

As you can imagine, this is pretty scary stuff so ensure that you remove these lines of code from your site as soon as you’ve been able to log into the site. Oh, and guard FTP access credentials to your site to ensure some bad guy doesn’t do the same thing to get access to YOUR site. That means no more FTP while on WiFi at Starbucks or other public hotspot unless you are running over a VPN to secure your connections!

Tip found on Stephanis.info.
Image © Copyright RAY JONES and licensed for reuse under this Creative Commons Licence

Custom Redirects in .htaccess Disappearing from WordPress Site?

A number of WordPress that we manage have been “losing” the custom 301 directives that we or our clients have been putting into the .htaccess file. This has been a very random and disconcerting issue.

Recently, we discovered that this was happening whenever someone saved the Permalinks Settings in WordPress.

Alternative solution? Make the file read-only until you need to edit it again. Or at least set up the permissions so that the webserver can’t overwrite the file. Problem solved…

In most cases this means setting the permissions on this file to 660 or 644 as described in this Codex article.

Tracking Session Variables in WordPress

Recently, a discussion came up about some new feature that will need to be added to a client website and it quickly became clear that we need to track the some variables in the session state. Now, I had always been told that WordPress, in trying to present a stateless solution, didn’t support tracking sessions variables without custom cookies.

Well after a little Googling (thank you Larry and Sergey) i found the following article on Session Variables in WordPress and it has a very elegant and simple solution to the problem.

Just add the following code to your theme’s function.php and you are good to go:
function THEMENAME_init_session()
{
session_start();
}
add_action('init', 'THEMENAME_init_session', 1);

This is exactly what I needed so now we’ll be able to store and access $_SESSION[] variables.

Moving Drupal 7 to WordPress 3.3

Having to move data from Drupal 7 to WordPress 3.x is not as easy as I had hoped it would be. Initially found a plugin that didn’t work. Then found a project on GitHub but it was for Drupal 5 or Drupal 6 (not sure really) but the jump to 7 comes with enough schema changes that the above wasn’t going to work.

While not a perfect script, this certainly did give me the ability to move articles/posts/pages from a Drupal 7 site to a current WordPress site. You’ll find the original article at http://fuzzythinking.davidmullens.com/content/moving-from-drupal-7-to-wordpress-3-3/

I made some changes here and there to accommodate the vagaries of the original database I was working with and to correct the types of quote marks used for data fields but other than that, it worked pretty well. If you need access to it, here’s the details (in case his original post disappears):

AS ALWAYS, BACK UP YOUR DATABASES FIRST!

#Run these in blocks and remember to change wordpress to the name of your wordpress
#database/schema and drupal to the name of your drupal database/schema.
#
# Block 1
# TAGS
# Using REPLACE prevents script from breaking if Drupal contains duplicate terms.
REPLACE INTO wordpress.wp_terms
(term_id, `name`, slug, term_group)
SELECT DISTINCT
d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_'), 0
FROM drupal.taxonomy_term_data d
INNER JOIN drupal.taxonomy_term_hierarchy h
USING(tid)
# INNER JOIN drupal.term_node n
# USING(tid)
WHERE (1
# This helps eliminate spam tags from import; uncomment if necessary.
# AND LENGTH(d.name) < 50 ) ; INSERT INTO wordpress.wp_term_taxonomy (term_id, taxonomy, description, parent) SELECT DISTINCT d.tid `term_id`, ‘post_tag’ `taxonomy`, d.description `description`, h.parent `parent` FROM drupal.taxonomy_term_data d INNER JOIN drupal.taxonomy_term_hierarchy h USING(tid) # INNER JOIN drupal.term_node n # USING(tid) WHERE (1 # This helps eliminate spam tags from import; uncomment if necessary. # AND LENGTH(d.name) < 50 ) ; #Block 2 INSERT INTO wordpress.wp_posts (id, post_author, post_date, post_content, post_title, post_excerpt, post_name, post_modified, post_type, `post_status`) SELECT DISTINCT n.nid `id`, n.uid `post_author`, FROM_UNIXTIME(n.created) `post_date`, r.body_value `post_content`, n.title `post_title`, r.body_summary `post_excerpt`, n.type `post_type`, r.entity_id `rid`, <- There is an issue here. Haven’t had a chance to fix this yet. IF(n.status = 1, 'publish', 'private') `post_status` FROM drupal.node n, drupal.field_data_body r WHERE n.vid = r.entity_id ; #Block 3 # POST/TAG RELATIONSHIPS INSERT INTO wordpress.wp_term_relationships (object_id, term_taxonomy_id) SELECT DISTINCT nid, tid FROM drupal.term_node ; #Block 4 # Update tag counts. UPDATE wordpress.wp_term_taxonomy tt SET `count` = ( SELECT COUNT(tr.object_id) FROM wordpress.wp_term_relationships tr WHERE tr.term_taxonomy_id = tt.term_taxonomy_id ) ;

In my case, I ended up not running the taxonomy or the comments commands as we didn't have any comments to worry about and the taxonomy failed hard.

Either way, thanks to the writer at this blog post for pointing me in the right direction so I could stop wasteing time getting this data converted.

More Fun with php.ini: Allow WordPress Plugin to Access Data On Remote Server

Have you ever found that a WordPress plugin that works fine on one web host isn’t working as you would have expected when you move it to a new webhost? We recently experienced this with a plugin that reaches out to a remote server to collect XML data to be displayed by the plugin. The problem manifested itself as a blank page where the plugin’s shortcode SHOULD have displayed formatted version of the remote data. 

The quickest way to diagnose issues like this is to modify the wp-config.php so that the line “define(‘WP_DEBUG’, false);” reads as “define(‘WP_DEBUG’, true);” temporarily so you can view the errors that WordPress by default will hide from you.

Doing so in this case returned the following error:

Read more

Make Sure WordPress Has Enough Memory

I’ve just wrapped up spending an inordinate amount of time trying to debug a problem with some client sites that were hosted on WestHost. These sites are cookie cutters in that the theme and the plugins are the same as was running on other hosting companies (BlueHost, HostMonster, HostGator, iPage, etc) but on this new (to me) hosting company, whenever I’d go into the Pages administration of the WordPress dashboard, it would throw a 500 server error. 

Turning on debug in wp-config.php would show errors talking about deprecated functions but nothing that SHOULD throw the 500 server we were experiencing. What was odd was that one of the affected plugins was WordPress SEO from Yoast; the irony being that the only reason I went to WestHost was becuase of the recommendation by Joost de Valk himself (owner/developer at Yoast). All the affected plugins were:

Read more

Allowing WWW and Domain Only Access to WordPress Site

Say you have a client who’s come to you to build them a new website; great, congratulations. You do some research and find out that the links on their old site all pointed at the raw domain (no www preceeding it). You’ve also decided that based on their needs, the new site should be set up on the WordPress platform.

Easy peasy, right? Well not so fast there… Let’s say you built the new site, took it live and everyone on the Internet can see the new site BUT your client. More accurately, your client can’t see the site when they are at work but can from any other location. Hmmm…

Read more

Definitive guide to rel=”author” and rel=”me” on WordPress?

Joost de Valk of Yoast fame, has written the definitive guide to rel=”author” and rel=”me” integration into WordPress. Or should I say it almost is the definitive guide.

There are few things here that need to be considered:

  • If you are running his WordPress SEO plugin, you need to be sure that under Indexation | Archive section that you have unselected the “Disable the Author Archives” page (which is on by default to the best of my knowledge).
  • Ensure that you have SOMETHING in your author bio box. If not, nothing (image, bio and the all-important link to the Google Profile page) will show on the author’s archive page. It doesn’t have to be much but the default behavior if the Biographical Information in your profile on the WordPress site.

Read more