Clean up WordPress

May 7, 2011

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. WordPress has been writing your complete external web-site path on all images and links in both the posts and postsmeta tables. If you have ever changed your web hosting (your ISP) or in any way changed the name of your web site, then all those old records are wrong. Take a look. You may be shocked at all the erroneous records. Those records are being over-written, ignored and replaced, by the, literal, first entry in the wp_options table.
you may find it mentioned that (literal) definitions for WP_SITEURL and WP_HOME can be placed in the wp-config file, to override that entry in the database. Somewhat pointless; another literal.
If you maintain a running copy on your pc, you don’t want to be editing, maintaining, two copies of your wp-config.php file, or editing the 2 recoreds in your database every time you backup your database to your pc.

Put this in your wp-config.php file, then you will never have to edit the config table in the database nor maintain 2 copies of the config file:

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

If you have wp in a folder, (“yourfolder”), 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, id, and password on your pc that you created on the server (create both a MySQL % and a localhost record in the mysql.users table) ]

Backups

We want backups, not garbage:
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. [ 384 KiB in wp ver. 3.1.2 ] the options table in the database should have 1 or 2 kb of your personalized settings, etc., but it also has almost .4 meg of non ascii, non UTF-8 garbage in about 25 records – once called “Magpie,” now, called “_transient_feed_…” and “_transient_timeout_…” (they are easy to spot in phpMyAdmin) 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 4 hundred kb. And not when it is all in uncontrolled character sets that can mess up your db.

To get rid of the .4 meg of junk in the options table in the database, comment out the 4 lines of code in wp-admin/includes/dashboard.php that call the functions retrieving it (over and over) 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 4 lines, 48, 65, 69, 85 (in ver. 3.1.2) that look like this (you comment them out with the “#”)

after line 47:
47 // Incoming Links Widget
insert if ( 4 != 4 ) { #
in front of if ( is_blog_admin() && current_user_can('publish_posts') ) {
to end up with
48 if ( 4 != 4 ) { # if ( is_blog_admin() && current_user_can('publish_posts') ) {
and, of course, since 4 does = 4, to say that they are not equal will never be true.
(this stops all remote linking and downloading from line 48 to line 61)

65 # wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ),
69 # wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress'

76 insert if ( 4 != 4 ) { #
to end up with if ( 4 != 4 ) { # if ( !isset( $widget_options['dashboard_primary'] ) ) {

88 # wp_add_dashboard_widget( 'dashboard_primary',

91 insert if ( 4 != 4 ) { #
to end up with if ( 4 != 4 ) { # if ( !isset( $widget_options['dashboard_secondary'] ) ) {

103 # wp_add_dashboard_widget( 'dashboard_secondary',

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.

Remove the WordPress link from your login/logout widget

in wp-includes/default-widgets.php

5. how to Remove the WordPress link=advertisement from your login/logout widget – [and remove the RSS links also if they are just collecting spammers]

The code is in wp-includes/default-widgets.php,
from ver.2.8.x through 3.0.x at lines 297-301, in ver. 3.1.2 at lines 296-300.

Delete line 299 to get rid of the wp link
296 <li><?php wp_loginout(); ?></li>
297 <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate ...
298 <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__(' ...
299 <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPres ...
300 <?php wp_meta(); ?>

delete lines 297 and 298 if the RSS is just attracting spammers.

Leave a Reply

We try to post all comments within 1 business day