If you mess up your WordPress theme’s widgets (I was playing with the code and screwed up) and can’t add or remove them, try following the advice here. The manual reset saved me a ton of time.
Tag: WordPress (page 8 of 13)
A few weeks ago, my hosting service received a complaint that my blog was sending spam. I don’t spam, so I checked out what was going on.
I had been using Mark’s Subscribe to Comments plugin which has one flaw: the released version does not support double-opt in. At the time I replied to my hosting company with an explanation and I disabled that plugin. I also went onto SpamCop and replied to the complaint with what I had done to resolve this.
Being tagged a spammer is serious stuff.
Double-opt in is when someone signs up for an e-mail and the first and only e-mail that goes out is one that says “Hey, someone just signed you up for this. If it’s really you, please confirm by clicking on this link. If it’s not you, then please ignore/delete this e-mail and the system will never send you an e-mail again.”
Until the subscriber clicks on that double-opt in link, the person is NOT subscribed. It’s e-mail subscription etiquette 101 and should be adhered to. I am NOT a bulk e-mailer but you have to be responsible on the Internet. SpamHaus has a good explanation here under “confirmed opt-in”.
This is a known issue and now the SVN copy of that plugin now supports Double-Opt in. I got my copy by using this command in my wp-content/plugins directory:
cd wp-content/plugins svn co http://svn.wp-plugins.org/subscribe-to-comments/branches/development stc
That put the svn copy into wp-content/plugins/stc. I went into the admin portion of the plugin and enabled Double-Opt in. A quick test later confirmed that it’s working. Once the 2.2 version is released, I’ll stop using the SVN copy and sync up with the WordPress.ORG copy.
One last item was that I deleted the e-mail of the subscriber who complained and now people who leave comments and want an e-mail on follow up comments will now work in a responsible way.
WordPress 2.7.1 is available. See changed files here. Updating WordPress is as easy as svn sw http://svn.automattic.com/wordpress/tags/2.7.1
Opensource software is best.
Using a comment callback function in WordPress 2.7, I was trying to customize the threaded comments and ran into a problem. So I left a comment on Jeremy’s blog. He contacted me and was able to find the problem and provide a fix. His post has been updated with that small change and it’s all good.
Very cool, you can’t get that kind of response from any software company. I’ll keep playing around with the comment format, but now I can implement anything I like and take full advantage of the threaded comment feature.
I’ve been on vacation since right before Christmas and have enjoyed the time off. Monday I go back to work all refreshed and ready to go.
After our New Years Eve party, I spent the day doing somethings that had meant to do for a while: PHP coding for my WordPress blog. My PHP fu is not that great but this is how I learn and as hobby’s go, it’s almost productive. Starting with easy ones and working my way down, the list looks like this.
1. Clean up my theme directory.
I make changes to my theme all the time and left junk in the theme directory. There is junk in there from plugins that I was experimenting with, looks that I was trying to accomplsh, etc. I can’t remember it all but I know what I need to keep and my backups are good and current.
2. Setup my Flickr badge as a WordPress plugin to put a widget in the sidebar.
I was using a text widget and hard coded the CSS into my theme’s header.php so that the page would validate properly. That worked but if I changed themes, the styling went out the window. I had wanted to see how to create a widget plugin that inserted the CSS using the wp_head action. By looking at existing plugins I saw how and it’s not hard at all.
Now I can keep the widget no matter which theme I choose and it always validates. Next up to add options in the widget. I’m looking at the Flickr Widget to see how it’s done there. Having GPL’ed code available to examine makes life so much easier.
I want to get an options page just for giggles; I don’t plan on distributing the code since I’m re-using Flickr’s code from here.
3. And now the big one: Fix my comment CSS and get WordPress 2.7 threaded comment callback working properly.
WordPress 2.7 comes with the option of using threaded comments and getting the default output just needs these lines:
<ul class="commentlist"> <?php wp_list_comments(); ?> </ul>
This produces good valid XHTML output and all that is required is to style it anyway you want. With some CSS I get this:
It’s really easy to do and between Otto and Chris Harrison’s posts, getting it looking good is simple. If you want to learn then visit those two sites and start playing with your theme.
Now if you want to explicitly control the output for threaded comments, you need to use a callback as outlined in Jeremy’s post. I’m adding a comment count and trying to keep the look close to the original theme’s styling. By inserting the theme’s original comment code I can maintain the look.
In my comments.php file I comment out the old line and add one to use the callback.
<ul class="commentlist"> <?php // wp_list_comments(array('avatar_size'=>40,'reply_text'=>'Reply to this comment')); ?> <?php wp_list_comments('callback=custom_comment'); ?> </ul>
In my function.php file I’m adding this code. Be warned, I am not a PHP programmer and if anyone sees something really gross please feel free to criticize. The $cmtorder is more of a placeholder and I’m not using it yet.
<?php function custom_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <?php global $cmtcount; ?> <?php $pageadd = 1; if(get_option('page_comments')) : $page = get_query_var('cpage'); $pageadd = (get_option('comments_per_page') * ($page - 1)) + 1; $cmtorder = get_option('comment_order'); endif; ?> <li id="comment-<?php comment_ID() ?>" class="<?php echo tj_comment_class() ?>"> <div class="commentNumber">#<a href="#comment-<?php comment_ID() ?>"><?php echo $cmtcount + $pageadd; ?></a></div> <div class="comment_mod"> <?php if ($comment->comment_approved == '0') : ?> <em>Your comment is awaiting moderation.</em> <?php endif; ?> </div> <div class="comment_text"> <?php comment_text() ?> </div> <div class="comment_author"> <?php if (function_exists('get_avatar')) { ?> <?php echo get_avatar($comment, '32'); ?> <?php } ?> <p><strong><?php comment_author_link() ?></strong></p> <p><small><?php comment_date('j M y') ?> at <?php comment_time() ?> <? edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?></small></p> </div> <div class="clear"></div> <?php echo comment_reply_link(array('before' => '<div class="reply">', 'after' => '</div>', 'reply_text' => 'Reply to this comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] )); ?> <?php $cmtcount = $cmtcount + 1; ?> <?php } ?>
This gets the comments formatted close to the theme’s original comments but adds threading. I added the comment count as a “why not?” If you turn on paged comments the comment counter still work. I have not worked out changing the order yet, I’d like to see it working in reverse order if set.
The code is a bit ugly and I’ll clean it up later. It works and I’m not getting and errors in my log so I’m happy for now. The CSS is good and the generated XHTML code is valid.
My only problem is that the javascript reply to comment box is not working exactly the way I want it to.
When you click on the “Reply to this comment” link, the comment box show up outside of that comment’s <li> … </li>. This is probably due to how I’m using comment_reply_link() but right now the codex is a little bit sparse on that topic. I’ve looked at the source code and by changing the parameters, I do get different results, just not the results I want. If I don’t use the callback, the comment box appears within that comment’s <li> … </li>.
I’ll keep playing with it and will be switching them back and forth until I like the output.
I just did another ‘svn up’ and the WordPress version is now 2.7. In a little while I’ll switch this blog to 2.7 using ‘svn sw http://svn.automattic.com/wordpress/branches/2.7’.
I’ve had this blog on WordPress 2.7-beta using SVN for a while. So when it went release candidate, all I had to do was another just run another “svn up”.
The comment enhancements are cool and Otto provided a good write up for modifying the files to take advantage of it. Implementing it and staying XHTML valid was not a problem.
My problem was that without styling it, the new comments looked like crap.
Lucky on the WordPress support forums I found that Chris Harrison mapped out all the CSS for the comment list. Adding the elements that he provided let me easily make changes and get the comments close to the original look.
I still need to play around with it but so far I’m satisfied with the results.
I’ve been using WordPress 2.7 beta for a week now and the new layout is very easy to get used to. So far so good.
I think a lot of people will revolt, cry, wail, and moan complain about the GUI changes and will probably demand their money back. But 2.7 is looking to be the best version yet.
WordPress blogs are based on MySQL and all the dynamic content is stored in a database. After trying out plugins, odd themes, and generally screwing around, my database has items in it that I can’t even recall what they were or if I need them.
One way to clean out the database is to export the blog to an XML file. This will produce the posts, pages, and all the comments and not export the ton of junk in the database. This way I create a clean empty blog, add the users, set up the theme and look I want and import the data.
This produces a very clean installation. It also removes me as the author for the comments I’ve left on my own blog. The table wp_comments table has a user_id field that the XML file does not have.
What I wanted to do is run a MySQL command that will find all instances in wp_comments which match my e-mail address, and update that record with my user_id on the blog. I could do this one at a time using phpMyAdmin but that’s pretty inefficient, not geeky, and time consuming.
After some research I found out to run these commands:
$ mysql -p USE blogdatabase; Database changed SELECT * FROM wp_users WHERE user_email = 'notreally@myemail.com';
That gets me the ID number for my user. Since it’s the first user created the ID is 2.
UPDATE wp_comments SET user_id = 2 WHERE comment_author_email = 'notreally@myemail.com'; Query OK, 113 rows affected (0.00 sec) Rows matched: 113 Changed: 113 Warnings: 0
This updates the wp_comments table so comments left by me using my e-mail address.
Well I ripped the band-aid off and did the upgrade. It feels like 2.5.5 or something, not as big a deal as 2.3 to 2.5 was.
I keep almost all of my files in wp-content so upgrading was not difficult. I shut down my web server, renamed the old directory for the blog root, and used SVN to get a copy of 2.6 and moved the old contents to wp-content.
Once that was done, I started up the web server and ran the wp-admin/upgrade.php. It was quick and painless. Everyone should backup their 2.5.1 installation (files and database) and do the upgrade once 2.6 is tar’ed up and placed on the web site.
Some changes:
- The plugins management screen now lets you activate and deactivate selected plugins instead of doing them one at a time.
- The Widgets in the design tab now work and move as you’d expect them. In 2.5.1 they would jump around when I moved them. I hardly ever play with them so that never bothered me.
- Selecting a theme brings up a preview before you activate it.
- Publishing via XMLRPC can now be turned off without killing trackbacks and pingbacks.
- Atom feeds can be now turned off.
- Post versions are now a feature.
- Google Gears.
- SSL admin works well! See Ryan’s post here. I’m using it now and it’s very seamless. It breaks Simple Tags suggested tags, but I’m sure that will be fixed eventually.
There are lots more changes of course; I’m just using it now. So far it’s definitely worthwhile upgrade.