Results 1 to 8 of 8

Thread: Writing my own plugin

  1. #1
    samh is offline Here For The Peanuts
    Join Date
    Oct 2009
    Location
    London
    Posts
    193

    Default Writing my own plugin

    So I've decided to write a plugin. Well, I need a specific plugin for my site that is so so simple but I'm pretty sure it doesn't exist yet. But it's so simple it's stupid.

    Anyway...what I need is a plugin that will simply, when activated, display an image that links to something at the end of each post. Now, there's a reason why I'm not just using another plugin that allows you to add HTML at the bottom of each post and that's because a) I'm running a MU install and I want it to be available for our users to switch on/off and b) because I wanna learn how to write a plugin!

    I am aware of some of the tutorials out there that explain the process of writing a pluging but I've not been able to find anything specific to this. Perhaps I'm just using the wrong combination of keywords, I just don't know!

    If you're aware of a tutorial that would walk me through this then that would be amazing, or alternatively if you fancy making this thread the tutorial itself then that would obviously be most incredible ;)

    I'm excited by the way as to what we'll be using this plugin for :)

    Cheers, Sam
    Personally: @srhas Professionally: @FootballUtd

  2. #2
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    862

    Default

    1. http://codex.wordpress.org/Writing_a_Plugin

    2. http://codex.wordpress.org/Plugin_API

    3. Specifically, http://codex.wordpress.org/Plugin_API#Filters

    4. hook_name == "the_content".

    That should be enough to get the functionality of your plugin working. Creating a Settings menu and such is slightly harder. I wrote a tutorial that should help somewhat, but it's a bit advanced, not necessarily for beginners: http://ottodestruct.com/blog/2009/wo...-api-tutorial/

    However, it is pretty much plug and play code I'm describing there, simply putting very similar code like it directly into a plugin will work.

    Bonus code to start with:
    PHP Code:
    <?php
    /*
    Plugin Name: Magical Fairy Plugin
    Description: Adds happy fairy juice after every post!
    */

    add_filter('the_content','fairy_juice');

    function 
    fairy_juice($content) {
    $content .= '<p>Fairy Time! Rainbows and Unicorns! Wheee!</p>';
    return 
    $content;
    }

  3. #3
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    I think this is the bestest plugin ever.

  4. #4
    samh is offline Here For The Peanuts
    Join Date
    Oct 2009
    Location
    London
    Posts
    193

    Default

    I'm on my phone so can't really digest all this now...but Otto, huge thanks for the effort you've gone to there

    And andrea, funnily enough otto has actually read my mind...that is the exact plugin I was going to release to the community. I trust you'll be downloading and plugging through your blog?!
    Personally: @srhas Professionally: @FootballUtd

  5. #5
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    Dude, you know it.

    Can we add glitter?

  6. #6
    samh is offline Here For The Peanuts
    Join Date
    Oct 2009
    Location
    London
    Posts
    193

    Default

    Quote Originally Posted by andrea_r View Post
    Dude, you know it.

    Can we add glitter?
    PUshing your luck I think now....



    ;)
    Personally: @srhas Professionally: @FootballUtd

  7. #7
    Cais's Avatar
    Cais is offline Big Tipper
    Join Date
    Feb 2009
    Location
    Mississauga, ON, CANADA
    Posts
    349

    Default

    Well, it has to have glitter ... doesn't it?

    ... or would that be a new plugin, Sparkling Fairy Juice?

  8. #8
    samh is offline Here For The Peanuts
    Join Date
    Oct 2009
    Location
    London
    Posts
    193

    Default

    Righteo one and all - it would seem that I've created a plugin. Actually that's an entirely a lie. I didn't have time to do it but I was able to hand it over to one of my dev guys, non-wp experienced, and he has done it for me.

    You can see the plugin in action at the bottom of this following post:

    http://westhamprocess.com/2009/11/23...nce-this-year/
    (just scroll to the Chat&Banter button after the post)


    Now obviously the plugin itself is just stupidly simple (and image, a link and some text) and massive kudos needs to go to the retweet@ guys for what they've created. We just wanted that as a plugin (at least that's how our users perceive it!)

    If I'm allowed to, I'll happily attach the plugin folder here - let me know if that's ok, I'm not sure of the etiquette?!

    (ps i created that table in that post with WP-Table Reloaded....it works fine with WPMu and I've been impressed with it thus far)
    Personally: @srhas Professionally: @FootballUtd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •