{"id":5412,"date":"2015-09-07T13:01:04","date_gmt":"2015-09-07T11:01:04","guid":{"rendered":"https:\/\/www.creativejuiz.fr\/blog\/en\/?p=5412"},"modified":"2015-09-07T17:07:53","modified_gmt":"2015-09-07T15:07:53","slug":"how-to-fix-widget-error-construct-wordpress-4-3","status":"publish","type":"post","link":"https:\/\/www.creativejuiz.fr\/blog\/en\/wordpress-en\/how-to-fix-widget-error-construct-wordpress-4-3","title":{"rendered":"How to fix the Widget error in WordPress 4.3"},"content":{"rendered":"<p>With the WordPress 4.3 version is came a big wave of new topics\u00a0 about widget error on WP. Official and non-official forums are full of this kind of reaction. Indeed, WordPress decided to <a href=\"https:\/\/make.wordpress.org\/core\/2015\/07\/02\/deprecating-php4-style-constructors-in-wordpress-4-3\/\">not support anymore<\/a> the PHP 4 like constructor, as the official documentation indicated it. (it has been <a href=\"https:\/\/codex.wordpress.org\/Widgets_API\">updated<\/a>)<\/p>\n<p><!--more--><\/p>\n<h2>Use the __construct() method<\/h2>\n<p>Even if PHP5 still support the old syntax:<\/p>\n<pre class=\"code\"><code class=\"&quot;language-php\">&lt;?php\r\nclass Foo_Widget extends WP_Widget {\r\n\r\n\tfunction Foo_Widget() {\r\n\t\t$this-&gt;WP_Widget(\r\n\t\t\t'foo_widget', \/\/ Base ID\r\n\t\t\t__( 'Widget Title', 'text_domain' ), \/\/ Name\r\n\t\t\tarray( \r\n\t\t\t\t'description' =&gt; __( 'A Foo Widget', 'text_domain' ),\r\n\t\t\t\t'classname' =&gt; 'foo-widget'\r\n\t\t\t) \/\/ Args\r\n\t\t);\r\n\t}\r\n}\r\n?&gt;<\/code><\/pre>\n<p>WordPress show you an error message (if you are in debug mode) to inform you to use the <code>__construct()<\/code>parent method. It&#8217;s now therefore appropriate to use that constructor:<\/p>\n<pre class=\"code\"><code class=\"&quot;language-php\">&lt;?php\r\nclass Foo_Widget extends WP_Widget {\r\n\r\n\tfunction __construct() {\r\n\t\tparent::__construct(\r\n\t\t\t'foo_widget', \/\/ Base ID\r\n\t\t\t__( 'Widget Title', 'text_domain' ), \/\/ Name\r\n\t\t\tarray( \r\n\t\t\t\t'description' =&gt; __( 'A Foo Widget', 'text_domain' ),\r\n\t\t\t\t'classname' =&gt; 'foo-widget'\r\n\t\t\t) \/\/ Args\r\n\t\t);\r\n\t}\r\n}\r\n?&gt;<\/code><\/pre>\n<p>To your codes!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the WordPress 4.3 version is came a big wave of new topics\u00a0 about widget error on WP. Official and non-official forums are full of this kind of reaction. Indeed, WordPress decided to not support anymore the PHP 4 like constructor, as the official documentation indicated it. (it has been updated)<\/p>\n","protected":false},"author":4,"featured_media":5410,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_bluesky_dont_syndicate":"","_bluesky_syndication_accounts":"","_bluesky_syndication_text":"","footnotes":""},"categories":[651],"tags":[233,678,427],"coauthors":[597],"class_list":["post-5412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-en","tag-php","tag-tips","tag-widget"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/posts\/5412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/comments?post=5412"}],"version-history":[{"count":0,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/posts\/5412\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/media\/5410"}],"wp:attachment":[{"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/media?parent=5412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/categories?post=5412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/tags?post=5412"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.creativejuiz.fr\/blog\/en\/wp-json\/wp\/v2\/coauthors?post=5412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}