Create your first Widget for WordPress – PHPText

There is my first WordPress Widget – PHP Text – Text Box which accepts arbitrary PHP code and can execute it inside sidebar block.
Another requirement is that it is only be allowed to be entered by Admin User.

I have started with the original code for Text Widget and adjusted it to include such restriction.

It has superseded my IFrame solution discussed in prior post and works well except that CSS is not yet applied.

What has been demonstrated by this little project:

  • how to register your own sidebar widget
  • how to support multiple instances of the same widget in the sidebar
  • how to manage widget options from popup options window in Widget  Manager section of your Blog Admin Panel
  • how to store/read widget options
  • how to make your widget properly appear at the sidebar
  • implement some basic user rights manager

If you’d like to use it in your blog, source code is available here – WordPress PHP Text Widget.

I hope this little example would help you started with Plug-in development for your WordPress Blog.

WARNING: Any code injections allowed by dynamic content comes with possible security risk. Please be cautious about what you allow to be executed by the PHP code specified in the widget. I would strongly suggest avoiding use of external sources you have no control over.

This entry was posted in Web-design and tagged , , , , . Bookmark the permalink.

Leave a Reply

  • About

    From being a junior developer all the way to Development Manager position, I was always interested in new technologies. Passionate speaker, IT junky, developer, architect, team lead, and development manager - many hats, one goal - making software better and closer to people’s needs. For the most part I am using my blog as a scratch pad, writing small articles on things which I came across, was asked about more then once, and which would otherwise require additional research again and again.

    View Serguei Dosyukov's profile on LinkedIn
  • Testimonials

    I've been using this [theme] since the start. It is by far the most attractive, feature packed and stable of...

    Rhyull

    I’m a huge fan of this theme. I’ve got more than 90,000 pictures in my gallery3 running on a Ubuntu...

    Jklobo

    The greydragon theme is fantastic. It’s clean, stable and feature rich. It took me a while to decide to move...

    Ed

    more...

  • Categories