Skip to content

Instantly share code, notes, and snippets.

@seankmchenry
Last active June 28, 2016 18:37
Show Gist options
  • Save seankmchenry/8d064c11bc6d2baf7d5c76f5cc64863f to your computer and use it in GitHub Desktop.
Save seankmchenry/8d064c11bc6d2baf7d5c76f5cc64863f to your computer and use it in GitHub Desktop.
A skeleton for ACF-enabled widgets
<?php
/**
* CTA Widget
*
* @package _s
*/
class CTA_Widget extends WP_Widget {
/**
* Constructor
*/
public function __construct() {
$widget_args = array(
'classname' => 'widget-cta',
'description' => __( 'CTA widget with title, text and button.', '_s' )
);
parent::__construct( 'cta_widget', __( 'CTA Widget', '_s' ), $widget_args );
}
/**
* Display
*/
public function widget( $args, $instance ) {
// get the widget ID
// @link https://goo.gl/X1HGhg
$wid = 'widget_' . $args['widget_id']; ?>
<section class="widget widget-cta">
<?php
/* Title */
if ( get_field( 'widget_title', $wid ) ) { ?>
<h2 class="widget-title widget-cta__title">
<?php the_field( 'widget_title', $wid ); ?>
</h2>
<?php }
?>
</section>
<?php }
/**
* Form
*/
public function form( $instance ) {}
}
/**
* Register
*/
function _s_register_cta_widget() {
register_widget( 'CTA_Widget' );
}
add_action( 'widgets_init', '_s_register_cta_widget' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment