Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Writing Your First WordPress Plugin Part 7 – Final

Posted on November 15, 2011 by Pippin in Free Members, Intermediate, Member Restricted, Tutorials, Video Tutorials, Writing Plugins 49 Comments
Home» Member Restricted » Free Members » Writing Your First WordPress Plugin Part 7 – Final
Tweet
Love It - 6
This entry is part 7 of 7 in the Writing Your First WordPress Plugins, Basic to Advanced Series
← Writing Your First WordPress Plugin Part 6
  • How to Begin Writing Your First WordPress plugin
  • Structuring Your First WordPress Plugin
  • Writing Your First WordPress Plugin Part 3
  • Writing Your First WordPress Plugin Part 4
  • Writing Your First WordPress Plugin Part 5
  • Writing Your First WordPress Plugin Part 6
  • Writing Your First WordPress Plugin Part 7 – Final

Part seven of Writing Your First WordPress Plugin concludes the series by demonstrating how to extend the plugin options that I showed you in part 6, and how to use them to control various aspects of your plugin’s output, such as turning it on or off and changing theoutput’s theme. There is not a lot of new material covered in this part, but a couple of key points are explained that will greatly assist you writing WordPress plugin option pages.


You must be logged in to view the rest of this content. Register or login from the sidebar.

Tweet Follow @pippinsplugins
options, settings

49 comments on “Writing Your First WordPress Plugin Part 7 – Final”

  1. fettabachi says:
    November 18, 2011 at 10:30 am

    I’ve really enjoyed this tutorial series and want to thank you for the effort you’ve put into providing content of this quality. I commend you for your teaching style and look forward to exploring your site and the rest of your tutorials as well.

    As someone who is relatively new to Web development and very new to the world of WordPress, I’m having difficulty seeing the big picture of using WP as a CMS and what, when and where to use all of the pieces that are available to me with WP such as function.php, widgets, plugins, actions, hooks etc. Is there a logical path I can take that will help me put it all together and become proficient with it?

    Reply
    • Pippin says:
      November 18, 2011 at 10:35 am

      I’m Glad you’ve enjoyed the series! The first thing to understand with WordPress as a CMS, is realizing that it IS a true Content Management System. A year or two back WordPress was kind of a “hacked” CMS, but with a lot of the advancements the core development theme have made, primarily with custom post types, WordPress is no longer anything less than a true CMS.

      So where do you start? The first thing I would tell you is just become very comfortable with the WordPress UI. Once that is done, then move on to understanding plugins. Not necessarily how to write them, but at least understanding the things they can do for you. After that it’s just time and experience. The more you use it, the more you will get accustomed and comfortable with it.

  2. gilgimech says:
    November 26, 2011 at 11:26 am

    Great tutorial! But I’m having one issue.

    I followed your directions for the enable checkbox, but I’m getting an error when the checkbox is unchecked:
    Uninitialized string offset: 0
    Shouldn’t there be an add_option() hook to setup the option? Because as it stands the enable option has no value when unchecked. Which seems to be causing the error.

    Reply
    • Pippin says:
      November 26, 2011 at 2:48 pm

      add_option() is not necessary because the register_setting() function takes care of all of that. Does your checkbox value save okay?

  3. gilgimech says:
    November 26, 2011 at 3:19 pm

    Oh yeah. It works fine. The error is just bugging me. I would like to fix it but I’m not sure how.

    Reply
    • Pippin says:
      November 26, 2011 at 4:50 pm

      Try changing checked(1, $mfwp_options['enable']); to:

      if(isset($mfwp_options['enable']) { checked(1, $mfwp_options['enable']); }

    • yellowhousedesign says:
      June 1, 2012 at 9:44 am

      Hi all,
      I know this is a bit of an older topic, but just found http://iamcam.wordpress.com/2008/01/15/unchecked-checkbox-values/ which is working wonders for me to make sure a checkbox value is either 0 or 1. Thanks!

    • Pippin says:
      June 3, 2012 at 2:24 pm

      Thanks for pointing that out.

  4. gilgimech says:
    November 26, 2011 at 5:07 pm

    Cool,
    That half worked. I also had to change

    if($mfwp_options['enable'] == true) {
    // . . ..
    }

    to

    if(isset($mfwp_options['enable']) && $mfwp_options['enable'] == true) {
    // . . ..
    }

    I was getting an error in both spots.

    Reply
    • Pippin says:
      November 26, 2011 at 5:10 pm

      Good job, thanks for noticing that.

    • designerken says:
      May 17, 2012 at 11:08 am

      Can this new check be described a bit more since the video and the text differ?

      I had the error when unchecked: Undefined index: enable

      When I used the isset function it solved it but I just wanted to know what is going on here.
      Here is my stab at it…Is it checking for the variable ‘enable’ in the options field to see if it is defined AND set to value of 1 equaling to value of ‘true’. If both of these are true then show the box checked, otherwise it is unchecked?

    • Pippin says:
      May 17, 2012 at 4:56 pm

      Your stab at it is correct. The error that you were noticing was coming up because the variable we were checking against didn’t actually exist. The isset() function lets us safely check whether a var exists,

  5. gilgimech says:
    November 26, 2011 at 5:28 pm

    Even better wrap it in the if loop

    if(isset($mfwp_options['enable'])) {
    if(is_singular() && $mfwp_options['enable'] == true) {
    // . . ..
    }
    }

    Reply
  6. vbcruiser says:
    November 28, 2011 at 5:28 am

    This has been the best plugin development tutorial series I’ve come across with such detail. Well done. Your an excellent teacher and I’ll be getting all your plugins.

    Thanks for the insight into the WP plugin development world.

    Reply
    • Pippin says:
      November 28, 2011 at 10:08 am

      Glad you’ve found it useful :)

  7. jkk says:
    December 31, 2011 at 1:56 am

    Hello Pippin; Thanks again for your tutorials. When I finished the tutorial, I tried to create Options Page, following all the steps. But my options won’t save., when I save they revert to blank. I posted the entire code I am using at the following pastebin link. Please check and let me know what do I missed.

    Here is the link. Thank you.

    http://pastebin.com/AuPW5dSE

    Reply
    • Pippin says:
      January 2, 2012 at 8:56 am

      I think the problem is with your add_settings_field() functions. The first parameter, which is the option ID, needs to be an array that matches the options array. Currently you have this:
      add_settings_field('enable_checkbox'...
      It should be this:
      add_settings_field('mfop_theme_options[enable_checkbox]'...

  8. jkk says:
    January 2, 2012 at 7:33 pm

    Thanks you.

    Reply
    • Pippin says:
      January 2, 2012 at 7:45 pm

      I assume that worked?

  9. jkk says:
    January 3, 2012 at 2:56 am

    Thanks again, Pippin.

    After many iterations, I think I was missing the validation code,and it I worked when I added the following simple but effective “return” code (I am sure it need more validation and sanitation, but so far so good and it works).

    function mfop_options_validate_cb($mfop_options) {
    return $mfop_options;
    }

    Reply
    • Pippin says:
      January 3, 2012 at 8:33 am

      Oh yes, sorry, I should have spotted that. If you use a validation function, it must (at least) return the same data that was passed to it.

  10. sagarnangare says:
    April 1, 2012 at 4:57 am

    Simply Amazing tutorial!!

    Reply
  11. Zach says:
    April 19, 2012 at 1:45 pm

    Just wanted to say thanks for the series – very helpful!

    Reply
  12. designerken says:
    May 15, 2012 at 3:36 pm

    Great series Pippin,

    What about using add_action() and add_filter() before the function? I have seen it done both after and before is there a WP standard or is it a personal preference and is there difference when doing it before as opposed to after?

    Reply
    • Pippin says:
      May 15, 2012 at 6:19 pm

      Before and after which function? I personally prefer to do it at the start and end of most functions, especially those that output HTML.

    • designerken says:
      May 15, 2012 at 7:36 pm

      Maybe I am confused? Here is an example with the add_filter before a function. Will it work just as well after the function mybloginfo()? Does its placement matter outside the mybloginfo function? I am just trying to understand why sometimes I see it before a function and sometimes after.


      add_filter('bloginfo', 'mybloginfo', 1, 2);
      add_filter('bloginfo_url', 'mybloginfo', 1, 2);

      function mybloginfo($result='', $show='') {
      switch ($show) {
      case 'wpurl':
      $result = SITE_URL;
      break;
      case 'template_directory':
      $result = TEMPL_DIR;
      break;
      default:
      }
      return $result;
      }

    • Pippin says:
      May 15, 2012 at 9:37 pm

      Oh, I understand what you mean. Sorry I was confused. The way you have it will work just fine.

  13. kasun says:
    August 21, 2012 at 5:58 am

    great! tutorial. thanks :)

    Reply
  14. Keith says:
    August 22, 2012 at 12:14 pm

    Very good series and one of the best I’ve come across.

    With that said, one thing I would have liked to see included is the ability to store the data in a new table and not the options table.

    I think if that was covered, then it would have been an even better series.

    http://codex.wordpress.org/Creating_Tables_with_Plugins

    Reply
    • Pippin says:
      August 22, 2012 at 4:51 pm

      In general, custom tables should be avoided in plugins, simply because they are rarely needed. Most of the time, custom post types can be used for just about anything you want.

      There are some cases where custom tables are the right way to go, however. Do you have a scenario in mind?

    • Keith says:
      August 23, 2012 at 9:05 am

      The reason I mentioned it is because if the plugin requires you to store lots of additional data then custom tables could be used. I’m currently about to create an R.S.V.P plugin which requires me to store lots of invitation information and personal messages for the bride and groom.

    • Pippin says:
      August 23, 2012 at 7:52 pm

      I can see that being an applicable situation for custom tables.

  15. jvandercar says:
    August 23, 2012 at 11:04 am

    This tutorial has been great! Thanks, Pippin. i did notice a correction that needs to be made in the option tag of the foreach loop.

    selected=”selected”

    should read

    Otherwise, the last listed option is marked as selected. Again, thank you for your resources here. They have been a great help in orienting me to the realm of plugins.

    Reply
    • jvandercar says:
      September 6, 2012 at 3:53 pm

      Oops, my php code got stripped. The replacement for “selected” should be a php code that calls the $selected variable, which would define the selected value for that option.

    • Pippin says:
      September 6, 2012 at 6:56 pm

      Yes, you’re absolutely right, that should be replaced with the selected() function.

  16. udanaudayanga says:
    September 3, 2012 at 1:35 pm

    This tutorial series is awesome. No words to appreciate. For few days I was looking for a good tutorial about WP plugin development. This is the best tutorial I found. I don’t think I need to find any more.

    Thanks Again. Keep up the good work!

    Reply
  17. kshitiz says:
    September 13, 2012 at 4:57 am

    Hi,

    please tell me where is the download link for the entire code.

    Reply
    • Pippin says:
      September 13, 2012 at 12:02 pm

      It’s at the bottom of the post, where it says “Download Complete Plugin”.

  18. illit says:
    September 15, 2012 at 8:04 am

    Hi GREAT tutorial series how would i add a function to change text my plugin to a set font that i include in the fonts folder within my plugin..

    i am trying to break down and duplicate the script found at http://alturl.com/43fo7 to create this work cloud from custom added text.

    Reply
    • Pippin says:
      September 15, 2012 at 7:17 pm

      To do that you just need to load the custom CSS with your @font-face declarations.

  19. chalist says:
    September 17, 2012 at 1:54 pm

    it’s perfect. i really enjoyed.
    thanks a lot for your good site and tuts

    Reply
  20. Ifiok Jr. says:
    September 18, 2012 at 4:16 am

    Awesome Tutorials!
    I’m glad I stumbled across your website :D

    Reply
  21. jason_the_adams says:
    October 22, 2012 at 6:23 pm

    Thanks for the tutorials, Pippin! When I have more time in a month, I’ll definitely pay for a subscription. :)

    I only have one point of curiosity: When referring to the $mfwp_options[] dictionary, you’re only using quotes when referring to it in PHP. Why don’t you have to use quotes in html?

    Thanks again!

    Reply
    • Pippin says:
      October 22, 2012 at 9:06 pm

      That’s just a syntax thing. PHP requires it, HTML doesn’t.

  22. Rosemaphine says:
    December 31, 2012 at 10:58 am

    Awesome tutorial series! Thank you so much Pippin.

    Reply
  23. syom777 says:
    February 11, 2013 at 4:19 pm

    Very helpful tutorial. Very clean explanation.

    It will be very cool if you also have tutorial, which shows how to deal with databases and how to create a new tables etc. …

    Anyway thank you very much for this tutorial.

    Reply
    • Pippin says:
      February 11, 2013 at 8:58 pm

      I wrote a tutorial that shows how to create them: http://pippinsplugins.com/create-database-tables-when-plugin-is-activated/

      There is a great series on WP.TutsPlus on the topic: http://wp.tutsplus.com/series/custom-database-tables/

  24. kartikn says:
    February 27, 2013 at 12:59 pm

    Hi Pippin – Just wanted to say a big thanks for this brilliant series on WP Plugins. I have really enjoyed your video tutorials. The quality of the video and audio was really clear and your voice and accent are very easy to understand. Of course the actual tutorial content itself is really good, clear and easy to understand. You have a talent for teaching and clearly are very passionate about writing good WP Code. Thanks again.

    Reply
    • Pippin says:
      February 27, 2013 at 3:44 pm

      Great to hear!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • Writing Your First WordPress Plugin Part 6

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Submitting Your First Pull Request to a WordPress Plugin on Github (2)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

  • Plugin Development 101 – Intro to Loading Scripts and Styles (16)

    In this part of Plugin...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • @jaredatch @kimparsell :D
    May 23, 2013
  • @jaredatch there is, as long as there is at least one ticket
    May 23, 2013
  • RT @Astoundify: We are hiring p/t tech support rep for our support forum if your interested email contact [at] http://t.co/bcXNhcwZx5
    May 23, 2013

Topics

add_options_page get_user_meta featured register_setting contextual help attachments add_shortcode hook meta box Tom McFarlin wp_enqueue_script the_content shortcodes attachment Related posts image plugin forms do_action short codes mail chimp login authors recent posts comments apply_filters post types bbpress short code taxonomies custom post type Ajax images gallery Stripe jquery taxonomy widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2011 Pippin's Plugins