Last active
June 28, 2016 18:37
-
-
Save seankmchenry/8d064c11bc6d2baf7d5c76f5cc64863f to your computer and use it in GitHub Desktop.
A skeleton for ACF-enabled widgets
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 | |
/** | |
* 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