701 posts
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 6-7 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()  {
7 posts UnlimitDesign
  • Bought between 100 and 499 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 200 and 499 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

2045 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • United States
Landonw 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 6-7 years
  • Referred between 1 and 9 users
chrismccoy says

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

?

ive seen people do both.

2045 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • United States
Landonw 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.

1601 posts Building the Web.
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Has been a member for 4-5 years
+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

2045 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • United States
Landonw 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.

3192 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee 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?

2045 posts
  • Has been a member for 4-5 years
  • Bought between 50 and 99 items
  • Exclusive Author
  • United States
Landonw 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.

1601 posts Building the Web.
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Has been a member for 4-5 years
+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
by