Skip to content

Instantly share code, notes, and snippets.

@spencerfinnell
Created January 31, 2017 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spencerfinnell/8712fb2d04ee9dab560288d6ec2bae15 to your computer and use it in GitHub Desktop.
Save spencerfinnell/8712fb2d04ee9dab560288d6ec2bae15 to your computer and use it in GitHub Desktop.
<?php
/**
* Custom Call to Action
*
* @since 1.0.0
*/
class Custom_Widget_Call_To_Action extends Listify_Widget {
/**
* Register widget and settings.
*
* @since 1.0.0
*/
public function __construct() {
$this->widget_id = 'custom_listify_call_to_action';
$this->widget_name = __( 'Custom: Call to Action', 'listify' );
$this->widget_description = __( 'Display the Call to Action', 'listify' );
$this->settings = array(
'color-text' => array(
'type' => 'colorpicker',
'std' => get_theme_mod( 'color-cta-text', '#717a8f' ),
'label' => __( 'Text Color:', 'listify' )
),
'color-background' => array(
'type' => 'colorpicker',
'std' => get_theme_mod( 'color-cta-background', '#f9f9f9' ),
'label' => __( 'Background Color:', 'listify' )
),
'title' => array(
'type' => 'text',
'std' => get_theme_mod( 'call-to-action-title', sprintf( '%s is the best way to find & discover great local businesses', get_bloginfo( 'name' ) ) ),
'label' => __( 'Title:', 'listify' )
),
'description' => array(
'type' => 'textarea',
'std' => get_theme_mod( 'call-to-action-description', 'It just gets better and better' ),
'label' => __( 'Description:', 'listify' )
),
'button-text' => array(
'type' => 'text',
'std' => get_theme_mod( 'call-to-action-button-text', 'Create Your Account' ),
'label' => __( 'Button Text:', 'listify' )
),
'button-href' => array(
'type' => 'text',
'std' => get_theme_mod( 'call-to-action-button-href', '#' ),
'label' => __( 'Button URL:', 'listify' )
),
'button-subtext' => array(
'type' => 'text',
'std' => get_theme_mod( 'call-to-action-button-subtext', 'and get started in minutes' ),
'label' => __( 'Button Subtext:', 'listify' )
),
'button-popup' => array(
'type' => 'checkbox',
'std' => 0,
'label' => __( 'Open button URL in a popup', 'listify' )
)
);
parent::__construct();
}
/**
* Output the widget content on the page.
*
* @since 1.0.0
*
* @param array $args
* @param array $instance
*/
function widget( $args, $instance ) {
$text_color = isset( $instance[ 'color-text' ] ) ? $instance[ 'color-text' ] : '#717a8f';
$background_color = isset( $instance[ 'color-background' ] ) ? $instance[ 'color-background' ] : '#ffffff';
$title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
$description = isset( $instance[ 'description' ] ) ? esc_attr( $instance[ 'description' ] ) : false;
$button_href = isset( $instance[ 'button-href' ] ) ? esc_url( $instance[ 'button-href' ] ) : false;
$button_text = isset( $instance[ 'button-text' ] ) ? esc_attr( $instance[ 'button-text' ] ) : false;
$button_subtext = isset( $instance[ 'button-subtext' ] ) ? esc_attr( $instance[ 'button-subtext' ] ) : false;
$button_popup = isset( $instance[ 'button-popup' ] ) && 1 == $instance[ 'button-popup' ] ? true : false;
echo $args[ 'before_widget' ];
echo 'My custom widget!';
echo $args[ 'after_widget' ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment