ThemeForest

what method do you use when extending a widget?

701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
chrismccoy says

When you create your own custom widget, do you use

function Widget_Name

or do you use __construct, whats the difference between them both?

class Custom_Widget extends WP_Widget {

//function Custom_Widget() {

function __construct()  {
5 posts UnlimitDesign
  • Bought between 100 and 499 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 250 000 and 1 000 000 dollars
UDTHEMES says

I wouldn’t worry about it Chris. I personally would choose function Widget_Name

2000 posts
  • United States
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Exclusive Author
ThemeOcean says

I use __construct() because it’s proper PHP coding :)

However, there are no differences between __construct and just using the name of your class.

701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
chrismccoy says

and what about parent::WP_Widget and $this->WP_Widget

?

ive seen people do both.

2000 posts
  • United States
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Exclusive Author
ThemeOcean says
chrismccoy said
and what about parent::WP_Widget and $this->WP_Widget

?

ive seen people do both.

This http://php.net/manual/en/keyword.parent.php explains it well.

If you extend a class, the class you’re extending becomes the parent. $this (or self:: if it’s a static class) means the class you’re using it in.

1422 posts
  • Microlancer Beta Tester
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 100 000 and 250 000 dollars
+2 more
ZoomIt says
LandonWilson said
However, there are no differences between __construct and just using the name of your class.

PHP4 -> constructor function name = name of the class

PHP5 -> constructor function name = __construct

2000 posts
  • United States
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Exclusive Author
ThemeOcean says
ZoomIt said
LandonWilson said
However, there are no differences between __construct and just using the name of your class.

PHP4 -> constructor function name = name of the class

PHP5 -> constructor function name = __construct

I don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.

2935 posts
  • Community Superstar
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • Has been a member for 2-3 years
  • United States
  • Exclusive Author
chrisakelley says
LandonWilson said
ZoomIt said
LandonWilson said
However, there are no differences between __construct and just using the name of your class.

PHP4 -> constructor function name = name of the class

PHP5 -> constructor function name = __construct
I don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.

php4 isn’t support by WordPress anymore so why support it in themes?

2000 posts
  • United States
  • Bought between 50 and 99 items
  • Has been a member for 3-4 years
  • Exclusive Author
ThemeOcean says
OrganicBeeMedia said
LandonWilson said
ZoomIt said
LandonWilson said
However, there are no differences between __construct and just using the name of your class.

PHP4 -> constructor function name = name of the class

PHP5 -> constructor function name = __construct
I don’t think anyone supports PHP4 anymore. It’s way too outdated to worry about.
php4 isn’t support by WordPress anymore so why support it in themes?

Well, someone could be using an old version of WordPress, but I’d rather white those people out and tell them to upgrade rather than give myself a back ache.

1422 posts
  • Microlancer Beta Tester
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 100 000 and 250 000 dollars
+2 more
ZoomIt says

I’m not supporting PHP4 .

I’m just pointing out the difference because that was the topic :P

by
by
by
by
by