Created
May 31, 2023 10:44
-
-
Save chrishadley/1a7f0326f3d83f4375b4163fa4269d17 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
/** | |
* HeroThemes Example Widget | |
*/ | |
class My_Widget extends WP_Widget { | |
//set up widget | |
public function __construct() { | |
$widget_ops = array( | |
'classname' => 'rest-api-test-widget', | |
'description' => 'This example provides a framework for how we will build our widget' | |
); | |
parent::__construct( 'my_widget', 'My Widget', $widget_ops ); | |
} | |
/** | |
* Outputs the content of the widget | |
* @param array $args | |
* @param array $instance | |
*/ | |
public function widget( $args, $instance ) { | |
//outputs the content of the widget | |
echo $args['before_widget']; | |
if( !empty( $instance['title'] ) ) { | |
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; | |
} | |
// Main Widget Content Goes Here | |
echo $args['after_widget']; | |
} | |
/** | |
* Outputs the options form on admin | |
* @param array $instance The widget options | |
*/ | |
public function form( $instance ) { | |
//outputs the options form on admin | |
$title = ( !empty( $instance['title'] ) ) ? $instance['title'] : ''; ?> | |
<label for="<?php echo $this->get_field_name( 'title' ); ?>">Title: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" | |
name="<?php echo $this->get_field_name( 'title' ); ?>" | |
type="text" value="<?php echo esc_attr( $title ); ?>" /> | |
<?php | |
} | |
} | |
add_action( 'widgets_init', function(){ register_widget( 'My_Widget' ); } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment