Last active
January 15, 2016 18:52
-
-
Save joshuadavidnelson/4107f33c28d68507ecfb to your computer and use it in GitHub Desktop.
Deprecated Widget Constructors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Correct method for WordPress 4.3 | |
* @see https://make.wordpress.org/core/2015/07/02/deprecating-php4-style-constructors-in-wordpress-4-3/ | |
* @see http://codex.wordpress.org/Widgets_API | |
*/ | |
class My_Widget extends WP_Widget { | |
/** | |
* Sets up the widgets name etc | |
*/ | |
public function __construct() { | |
$widget_args = array( 'description' => __( 'A Foo Widget', 'text_domain' ) ); | |
parent::__construct( | |
'foo_widget', // Base ID | |
__( 'Widget Title', 'text_domain' ), // Name | |
$widget_args // Args | |
); | |
} | |
/** | |
* Outputs the content of the widget | |
* | |
* @param array $args | |
* @param array $instance | |
*/ | |
public function widget( $args, $instance ) { | |
// outputs the content of the widget | |
} | |
/** | |
* Outputs the options form on admin | |
* | |
* @param array $instance The widget options | |
*/ | |
public function form( $instance ) { | |
// outputs the options form on admin | |
} | |
/** | |
* Processing widget options on save | |
* | |
* @param array $new_instance The new options | |
* @param array $old_instance The previous options | |
*/ | |
public function update( $new_instance, $old_instance ) { | |
// processes widget options to be saved | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Deprecated Method as of WordPress 4.3 | |
* @see https://make.wordpress.org/core/2015/07/02/deprecating-php4-style-constructors-in-wordpress-4-3/ | |
* @see http://codex.wordpress.org/Widgets_API | |
*/ | |
class My_Widget extends WP_Widget { | |
/** | |
* Sets up the widgets name etc | |
*/ | |
public function My_Widget() { | |
$widget_args = array( 'description' => __( 'A Foo Widget', 'text_domain' ) ); | |
$this->WP_Widget( | |
'foo_widget', // Base ID | |
__( 'Widget Title', 'text_domain' ), // Name | |
$widget_args // Args | |
); | |
} | |
/** | |
* Outputs the content of the widget | |
* | |
* @param array $args | |
* @param array $instance | |
*/ | |
public function widget( $args, $instance ) { | |
// outputs the content of the widget | |
} | |
/** | |
* Outputs the options form on admin | |
* | |
* @param array $instance The widget options | |
*/ | |
public function form( $instance ) { | |
// outputs the options form on admin | |
} | |
/** | |
* Processing widget options on save | |
* | |
* @param array $new_instance The new options | |
* @param array $old_instance The previous options | |
*/ | |
public function update( $new_instance, $old_instance ) { | |
// processes widget options to be saved | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment