Clean up WordPress

March 20, 2010 | By greg | Posted in PHP WordPress

A few ways you can "fix" and "enhance" the core code of wordpress - things that should be done.

There are some problems with WordPress which can be easy to fix if someone would just tell you how. Some issues involve portability: when you change internet hosting providers, and when you have a copy of your web site, certainly your wordpress blog, on your pc, it is a backup copy, and a place to safely try out things like new plugins and themes etc. [running wordpress on your pc involves installing apache, mysql, php, and wordpress - another topic] You need to be able to copy, upload, your pc files to the server, and copy, download, the database from your server into your pc without hassles like these:

Make WP portable

1. In the wp-config file, you are told to enter the literal address for the definitions of WP_SITEURL, WP_HOME, and ABSPATH.
Don't. If you ever change hosting co's or maintain a running copy on your pc, you don't want to be editing files and tables every time you edit a file or import the database to your pc.

If you have wp in a folder, ("yourfolder") it should look like this

define('WP_SITEURL', 'http://'.$_SERVER["SERVER_NAME"].'/yourfolder' );
define('WP_HOME', 'http://'.$_SERVER["SERVER_NAME"].'/yourfolder' );
. . .
define('ABSPATH', dirname(__FILE__).'/');

If your copy of WP is not in a folder, if it is at the root of your site, leave out .'/yourfolder'

[NOTE: To keep things "in synch", additionally, "of course", create, use, the same wp database name on your pc that you created on the server, and same id and password in your pc copy of MySQL in the user table of the mysql (master) database on your pc as on the server. (both a % and a localhost record) ]

not garbage, backups

2. WP insists on saving your work as you are editing a post or page, every minute, and it keeps a copy of every revision you have ever created of every post and page - causing your database to be 3, 4, or more times bigger and slower (!) than it should be! [you need backups (on your pc), not old garbage]

To turn off revisions and reduce autosaved copies of posts etc. to near-zero, put this in your wp-config file.

define('AUTOSAVE_INTERVAL', 6000 ); # 6000 sec's = 100 minutes.
define('WP_POST_REVISIONS', 0 );

word processors have an auto save feature which most people set to 5, 10, or maybe 15 minutes, generaly. (You could set it to something reasonable, like 600 = 10 min)

1/3 meg of garbage in the options table

3. the options table in the database should have 4 or 5 kb of your personalized settings, etc., but it also has 1/3 to 1/2 meg of non ascii, non UTF-8 garbage in about 15-18 records - once called "Magpie," now, called "_transient_feed_..." The "ton of junk" is only to display a few sentences of info about "popular plugins" and etc. over on wp's web site which you could go there and see if you were interested. A few sentences in your database would be fine but not 3-5 hundred kb! And not when it is all in uncontrolled character sets that can mess up your db.

To get rid of the .3 meg of (non-ascii) junk in the options table in the database, comment out the 5 lines of code in wp-admin/includes/dashboard.php that call the functions retrieving it and displaying a few sentences of it. Then, use a tool like phpMyAdmin (in Cpanel or Plesk) to delete it out of the options table.

these 5 lines, 46, 49, 50, 73, 85 that look like this (you comment them out with the "#")

46 #wp_add_dashboard_widget( 'dashboard_incoming_links', ... 'incoming links' -nice, but...
49 #if ( current_user_can( 'activate_plugins' ) )
50 # wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ) ... 'Most Popular Plugins'
73 #wp_add_dashboard_widget( 'dashboard_primary', $widget_options ... 'WordPress Development Blog'
85 #wp_add_dashboard_widget( 'dashboard_secondary', $widget_options ... 'Other WordPress News'

garbage in your database _posts table

4. When you upload images for your articles, [posts, pages], WP stores the full-length path name in the database which is a total waste, especially since wp has already written functions to over-ride the path stored in the database and replace it with the one spelled out in your config file or in the options table [which you can set/reset in the dashboard]. Were it not for that, your images would disappear when you move to a new hosting co or change the name of your web site, or when your current hosting co. moves you do a different server or in any other way changes the path below your site, or when you display your site on your pc while disconnected from the internet.

To clean up your database, strip the leading path off your images in the database: in phpMyAdmin (in Cpanel or Plesk) or some other tool execute commands like

SELECT * FROM ev_posts
WHERE guid LIKE '%http://website.com%' AND post_status = 'publish'

first to see what you are faced with, then

UPDATE ev_posts SET guid = REPLACE(guid, 'http://website.com/yourfolder/', '')
WHERE post_status = 'publish'

Do the select first to see what you will be changing and to pick one and change it manually and look at the article on your site and verify that the image still shows up. If it does not, put it back and try to think of what went wrong.

One Response to “ Clean up WordPress ”

  1. fred on May 31, 2010 at 1:10 am

    I clicked here from Moodle forums. In your opinion, can a novice (never taken a programming course) fairly well put up and maintain a Moodle webpage? Have you considered blogging about Moodle?

    Yes and Yes. You may need help rarely, but you should be ok. I have not gotten started yet with Moodle blogging, but, when I do, I will do it here. -Greg

Leave a Reply

Website url (required)

Comment / Question