My first Wordpress plugin
Today, I was supposed to go snowboarding, but since nobody would’ve come and as I feel a little sick, I was home all morning with not much to do.
In that free time I decided to write a little plugin for Wordpress I wanted for a long time, but was unable to find anywhere else. Michael promised to release it, but never did so, and same did Chris.
So, here it comes my favorite posts plugin: MF Favorites.
It lets you add a little heart to mark favorite posts and, if you’re an admin, you can click on the heart to toggle the status of a particular post.
It comes with two images — a-favorite-heart and not-a-favorite-heart — that suit my color scheme, but you can change them with almost every image-editing software simply by changing the hues saturation.
I tested it only on my weblog, so you should consider it as alpha software. But since it’s a very tiny script, there should be no problem.
Please, let me know if you find bugs or have problems.
++UPDATE++ 2005/04/02: Version 0.2 of MF Favorites released!
I’ve added a way to show a list of your favorite posts and fixed a couple of bugs.
To show the list, simply call mff_show_favs() wherever you want the list to appear.
By default, it will show the last 10 posts wrapped in <li></li>. So you’ll have to put it in an unordered list: <ul></ul>.
You can alse change a couple of parameters: mff_show_favs( number_of_posts_to_show_zero_for_all, before_each_post, after_each_post ).
As always, let me know if you have problems, suggestions or comments.
This entry was posted on Tuesday, March 15th, 2005 at 17:11
Tags: development, plugin, wordpress
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
This is great. I’m sorry for never releasing it, but I didn’t write it, and so didn’t feel I should go ahead and put it up ahead of its author.
You know, sometimes you have to get your hands dirty, and that was the right time. So I’m quite happy you nor Chris never released it, because now I know how to write a Wordpress plugin and it only took me less than 2 hours.
Anyway, thanks for stopping by…
This looks like a great plugin Michele. I’m going to test this out on my site, and if it works well, I’ll probably incorporate it into my redesign for CSS Reboot. Thanks!
Very nice job. I have released my plugin to select people, but have yet to release it properly. I guess I could go ahead and finish the last piece and release it.
And yes, sometimes you must get your hands dirty. I am glad to see you are starting to do that yourself.
Thanks Michele, I will implement this somehow into my new design!
Nice, downloading right now! I will probably use this on my site as well. Thanks Michele for your work!
Very nice. Thanks
It’s great to know that you like my plugin and I hope it will serve great on each one of your websites – at least on the one on which you decide to use it ;) .
Let me know if you have any problems.
Haha, this is great. I am thinking of implementing this into the minutes. I dont know yet. Hmm.
GO go go Michele!
I’ve been wanting this for AGES! I was gonna start harassing Chris for his version of it soon too :P
If I got no where with that I was going to try and write it myself but you just saved me some time..
Cheers! :D
Good concept,must install….
Nice plugin – thanks ever so much. I’m using 1.5 and had to tweak your script a bit. First, the SQL was not created (had to do this manually in phpMyAdmin and had to rename the table name respectively delete the prefix bit). Second, I don’t like the box around the icon, and added border=”0″ after each *.gif reference in your script – now works flawlessly…-)
Sorry, that was a little too quick. The icon shows up and when I click it something is happening, but the icon color neither changes nor is the respective post marked as a favorite when not logged in as an admin…-(
It might be because you changed the code. If you can send me your modified file, I’ll have a look at it and tell you what’s wrong.
Here it is:
http://www.matthiasheil.de/wordpress/wp-content/plugins/mf_favorites.txt
Thanks ever so much for your help!
Michele, Great job on the plugin. How difficult would it be to allow user’s to click on the any heart to see ‘all’ the posts that have been marked as ‘favorites?’
Yes, that’s the logical next step. Michele says that this is what’s next on his “to do” list – marvellous plugin (as it makes it much easier for visitors to keep track of the postings you think are the best ones), integrates beautifully with the template I’m using!-)
And thanks, Michele, for your EXEMPLARY support!
I’ve been thinking that it would be a good idea to have the icon displayed in single post mode, too. Can I just call the function in wordpress’ single.php template or might that cause a problem?
I finally implemented it to my site. I also made a few Heart replacements. I also have them for download as a zip with .ai and .eps files.
Ian: As Matthias said, it’s the next thing I’m going to do – maybe even today.
Matthias: Sure you can. You can put it wherever there’s a “Loop” open. For example, I use it on index.php, single.php, archive.php and search.php.
Aaron: I left a comment on your blog, but thanks again: my heart was a bit crappy… ;)
I just sent you an e-mail.
Hey Michele, Great job on your first plugin buddy. I’m using it right now, but I’ve used some different images I made and instead of being a favorite so to speak, i’m using it to mark posts that are important to me. Thanks for releasing this. I’ll be looking forward to more from you my friend.
If you were waiting for a way to show a list of your favorite posts, you should download the new release.
Read the above post for details…
I get this when I replace the older plugin script with the newer one: WordPress database error: [Table ‘usr_web19_1.wp_mf_fav’ doesn’t exist] SELECT count(*) FROM wp_mf_fav WHERE id=726
(sorry, misspelt url)
…the error message shows where the heart used to show up.
It’s because when you had that problem with the plugin a couple of weeks ago, I changed the plugin for you.
You should change the name of the ‘mf_fav’ table in your database to ‘wp_mf_fav’.
Excellent – no error message anymore… – Could you give a dummy like me a few code examples for the favorites list?-)
Sorted it out – partly… – Look at the favorites list underneath my feature article and click on one of them: they’re all linked to …/{$link} and hence produce an empty page instead of the one expected… what am I doing wrong?-)
http://www.matthiasheil.de/wordpress/index.php
I would really like to have an option cutting down the length of one favorite entry to a maximum number of letters (IYKWIM)… it’s not too long until Christmas, is it?-)
Download the plugin again, I fixed the problem.
Would you like to cut the length of the title?
Well-done again, Michele!
>Would you… Yes, exactly…
For some reason whenever I try to set a post as favorite now, it rebukes me with “Come on, don’t be a dumbass!” I’m logged in and everything. This worked when I first installed it, btw. I’m not sure what’s going on.
At first, I’d say it’s something with your privileges: your level have to be greater than 8.
Check and let me know…
I’m user level 10.
Sorry for bothering you. It just suddenly worked. Thanks! :)
sweet! gonna give this un a spin!
thanks michele
hmm.. I seem to be having the same problem as Bill (above) did. The script keeps calling me a dumass. I have a user level of 10. Any reasons why the script might break when I try to toggle the heart? Thanks.
@ clint: Let me know what you think!
@ smerickson: maybe there’s a problem with user_leve variable. Try adding this after line 193 in mf_favorites.php:
global $user_level;If it still doesn’t work, add this, after the line you’ve just added:
get_currentuserinfo();Let me know if it works…
Thanks Michele. That worked. But I also had to change the variable $mff_dbv and set it to 0. Great plugin!!
I got the same problem and this was my solution: 1) the name of the table to create with phpmyadmin was “wp_mf_fav” 2) as smerickson said, variable $mff_dbv set to 0 and not to 1
:D Michele, I love your plugin!
Hmm…I guess I have to work a little bit more on it and release a new version. Thanks for your reports.
@ chiara: glad you love it… :D
Hello, I’m getting this error before the pic:
WordPress database error: [Table 'blog.wp_mf_fav' doesn't exist] SELECT count(*) FROM wp_mf_fav WHERE id=290
can you please help me?
(I’m on WP 1.5.2)
It seem like the plugin hasn’t installed itself in the db, yet.
Try to manually run this MySQL query:
CREATE TABLEwp_mf_fav(idINT UNSIGNED NOT NULL ,favTINYINT DEFAULT '0' NOT NULL ,avgFLOAT UNSIGNED DEFAULT '0' NOT NULL ,countINT UNSIGNED DEFAULT '0' NOT NULL , PRIMARY KEY (id) );Thanks.. gonna try that.. I don’t know much about MySQL
Is there anyway I can make this work for any user, that would really help me….please let me know. I tried modifying the php but I am not good enought to pull it of. Please help.
@ iwo: look for this towards the end of the file:
/* All the settings are stored in a single array */ $mff_settings=array(); $mff_settings=get_settings('mffav'); $mff_settings['can_toggle']=8;And replace 8 with something like
-1. It should work…let me know!Wow, I definitly appreciate the quick response but I have already tried this as I played around with the php, this definitly allows everyone to mark their favorites but the output is for an aggregate, I mean for everone. I would like it to be user based. I am displaying the output in the author.php and I would want each user to have his own favorites on that page. I think this would require using more of the database but I am not sure, my knowledge of programming is still very limited.
Now, I see what you’re trying to achieve: different favorites for each user, right?
It would need a couple of things being added: a column on the table to store the user and quite a different management in the plugin. At the moment, I’m a bit busy, but as soon as I have some spare time I might look into this.
Thank you, I will be checking up on to see if you ever get around to it. Thanks again.
Hi! I just wanted to drop by and say thank you for making this plugin. We are using it at NoticIEEEro, our blog and news centre for IEEE Region 9, Latin America and the Caribbean.
I installed it but cannot figure out how to use it. How do I select posts as a Favorite? It wasn’t clear to me for some reason.
Hi Michele,
The request iwo made (about making the pluging work individually, with each user) is something I’m looking for as well. Have you made this modification? If not, do you know where I can get such a plugin?
Thanks!
Does this plugin have the ability to let users view their own favorites??? I’m looking for that type of plugin (and hopefully one I can edit to let them save my posts, which are about products, as their wishlist, not only favs).
Let me know if so, and let me know if you ever add that function, if not!!!
–Elle