My first Wordpress plugin
2005.03.15Today 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 post was written 3 years, 3 months ago on March 15th, 2005 late afternoon.



Michael Heilemann
3 years, 3 months ago
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.
Michele
3 years, 3 months ago
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…
Jeff Smith
3 years, 3 months ago
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!
Chris J. Davis
3 years, 3 months ago
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.
NIMA
3 years, 3 months ago
Thanks Michele, I will implement this somehow into my new design!
AsceticMonk
3 years, 3 months ago
Nice, downloading right now!
I will probably use this on my site as well.
Thanks Michele for your work!
Sean
3 years, 3 months ago
Very nice. Thanks
Michele
3 years, 3 months ago
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.
Aaron
3 years, 3 months ago
Haha, this is great. I am thinking of implementing this into the minutes. I dont know yet. Hmm.
Chris Boulton
3 years, 3 months ago
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
(subscribed to comments)
Metaactive
3 years, 3 months ago
Good concept,must install….
Matthias Heil
3 years, 3 months ago
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…-)
(subscribed to comments)
Matthias Heil
3 years, 3 months ago
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…-(
(subscribed to comments)
Michele
3 years, 3 months ago
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.
Matthias Heil
3 years, 3 months ago
Here it is:
http://www.matthiasheil.de/wordpress/wp-content/plugins/mf_favorites.txt
Thanks ever so much for your help!
(subscribed to comments)
Ian
3 years, 3 months ago
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?’
Matthias Heil
3 years, 3 months ago
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?
(subscribed to comments)
Aaron
3 years, 3 months ago
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.
Michele
3 years, 3 months ago
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… ;)
Aaron
3 years, 3 months ago
I just sent you an e-mail.
Shawn Grimes
3 years, 3 months ago
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.
Michele
3 years, 3 months ago
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…
Matthias Heil
3 years, 3 months ago
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.
(subscribed to comments)
Michele
3 years, 3 months ago
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’.
Matthias Heil
3 years, 3 months ago
Excellent - no error message anymore… - Could you give a dummy like me a few code examples for the favorites list?-)
(subscribed to comments)
Matthias Heil
3 years, 3 months ago
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?-)
(subscribed to comments)
Michele
3 years, 3 months ago
Download the plugin again, I fixed the problem.
Would you like to cut the length of the title?
Matthias Heil
3 years, 3 months ago
Well-done again, Michele!
>Would you…
Yes, exactly…
(subscribed to comments)
Bill
3 years, 2 months ago
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.
(subscribed to comments)
Michele
3 years, 2 months ago
At first, I’d say it’s something with your privileges: your level have to be greater than 8.
Check and let me know…
Bill
3 years, 2 months ago
I’m user level 10.
(subscribed to comments)
Bill
3 years, 2 months ago
Sorry for bothering you. It just suddenly worked. Thanks! :)
(subscribed to comments)
clint
3 years, 1 month ago
sweet! gonna give this un a spin!
thanks michele
smerickson
3 years, 1 month ago
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.
Michele
3 years, 1 month ago
@ 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…
smerickson
3 years, 1 month ago
Thanks Michele. That worked. But I also had to change the variable $mff_dbv and set it to 0. Great plugin!!
chiara
3 years, 1 month ago
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!
Michele
3 years, 1 month ago
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
Gianko
2 years, 5 months ago
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)
Michele
2 years, 5 months ago
It seem like the plugin hasn’t installed itself in the db, yet.
Try to manually run this MySQL query:
CREATE TABLE `wp_mf_fav` (
`id` INT UNSIGNED NOT NULL ,
`fav` TINYINT DEFAULT '0' NOT NULL ,
`avg` FLOAT UNSIGNED DEFAULT '0' NOT NULL ,
`count` INT UNSIGNED DEFAULT '0' NOT NULL ,
PRIMARY KEY ( `id` )
);
Gianko
2 years, 5 months ago
Thanks.. gonna try that.. I don’t know much about MySQL
iwo
2 years ago
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.
(subscribed to comments)
Michele
2 years ago
@ 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!iwo
2 years ago
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.
(subscribed to comments)
Michele
2 years ago
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.
iwo
2 years ago
Thank you, I will be checking up on to see if you ever get around to it. Thanks again.
(subscribed to comments)
Pablo Fernando Sanchez
1 year, 12 months ago
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.
(subscribed to comments)
Robin
1 year, 4 months ago
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.
Michel Fortin
9 months, 1 week ago
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!
(subscribed to comments)
Elle
7 months, 3 weeks ago
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
(subscribed to comments)