Last active
          August 29, 2015 14:21 
        
      - 
      
- 
        Save alispx/6c94c99e33d0e5dd1900 to your computer and use it in GitHub Desktop. 
    Template Layers Widget
  
        
  
    
      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 | |
| /** | |
| * Template Widget | |
| * | |
| * This file is used to register and display the Layers - Your widget Name. | |
| * | |
| * @package Layers | |
| * @since Layers 1.0 | |
| */ | |
| if ( ! class_exists( 'Layers_Your_Widget' ) ) { | |
| class Layers_Your_Widget extends Layers_Widget { | |
| /** | |
| * Widget construction | |
| */ | |
| function Layers_Your_Widget() { | |
| $this->widget_title = __( 'Your Widget Title' , 'layerswp' ); | |
| $this->widget_id = 'your_widget_id'; | |
| $this->post_type = 'post'; | |
| $this->taxonomy = 'category'; | |
| $this->checkboxes = array( | |
| 'show_media', | |
| 'show_titles', | |
| 'show_excerpts', | |
| 'show_dates', | |
| 'show_author', | |
| 'show_tags', | |
| 'show_categories', | |
| 'show_call_to_action' | |
| ); // @TODO: Try make this more dynamic, or leave a different note reminding users to change this | |
| /* Widget settings. */ | |
| $widget_ops = array( | |
| 'classname' => 'obox-layers-' . $this->widget_id .'-widget', | |
| 'description' => __( 'This widget is used to display your ') . $this->widget_title . '.' | |
| ); | |
| /* Widget control settings. */ | |
| $control_ops = array( | |
| 'width' => '660', | |
| 'height' => NULL, | |
| 'id_base' => 'layers-widget-' . $this->widget_id | |
| ); | |
| /* Create the widget. */ | |
| $this->WP_Widget( | |
| 'layers-widget-' . $this->widget_id , | |
| $this->widget_title, | |
| $widget_ops, | |
| $control_ops | |
| ); | |
| /* Setup Widget Defaults */ | |
| $this->defaults = array ( | |
| 'title' => __( 'Latest Posts', 'layerswp' ), | |
| 'excerpt' => __( 'Stay up to date with all our latest news and launches. Only the best quality makes it onto our blog!', 'layerswp' ), | |
| 'text_style' => 'regular', | |
| 'category' => 0, | |
| 'show_media' => 'on', | |
| 'show_titles' => 'on', | |
| 'show_excerpts' => 'on', | |
| 'show_dates' => 'on', | |
| 'show_author' => 'on', | |
| 'show_tags' => 'on', | |
| 'show_categories' => 'on', | |
| 'excerpt_length' => 200, | |
| 'show_call_to_action' => 'on', | |
| 'call_to_action' => __( 'Read More' , 'layerswp' ), | |
| 'posts_per_page' => 6, | |
| 'design' => array( | |
| 'layout' => 'layout-boxed', | |
| 'imageratios' => 'image-square', | |
| 'textalign' => 'text-left', | |
| 'liststyle' => 'list-grid', | |
| 'columns' => '3', | |
| 'gutter' => 'on', | |
| 'background' => array( | |
| 'position' => 'center', | |
| 'repeat' => 'no-repeat' | |
| ), | |
| 'fonts' => array( | |
| 'align' => 'text-left', | |
| 'size' => 'medium', | |
| 'color' => NULL, | |
| 'shadow' => NULL | |
| ) | |
| ) | |
| ); | |
| } | |
| /** | |
| * Widget front end display | |
| */ | |
| function widget( $args, $instance ) { | |
| } | |
| /** | |
| * Widget update | |
| */ | |
| function update( $new_instance, $old_instance ) { | |
| if ( isset( $this->checkboxes ) ) { | |
| foreach( $this->checkboxes as $cb ) { | |
| if( isset( $old_instance[ $cb ] ) ) { | |
| $old_instance[ $cb ] = strip_tags( $new_instance[ $cb ] ); | |
| } | |
| } // foreach checkboxes | |
| } // if checkboxes | |
| return $new_instance; | |
| } | |
| /** | |
| * Widget form | |
| * | |
| * We use regulage HTML here, it makes reading the widget much easier than if we used just php to echo all the HTML out. | |
| * | |
| */ | |
| function form( $instance ) { | |
| // $instance Defaults | |
| $instance_defaults = $this->defaults; | |
| // If we have information in this widget, then ignore the defaults | |
| if( !empty( $instance ) ) $instance_defaults = array(); | |
| // Parse $instance | |
| $instance = wp_parse_args( $instance, $instance_defaults ); | |
| extract( $instance, EXTR_SKIP ); | |
| $design_bar_components = apply_filters( | |
| 'layers_' . $this->widget_id . '_widget_design_bar_components' , | |
| array( | |
| 'layout', | |
| 'fonts', | |
| 'custom', | |
| 'columns', | |
| 'liststyle', | |
| 'imageratios', | |
| 'background', | |
| 'advanced' | |
| ) | |
| ); | |
| $design_bar_custom_components = apply_filters( | |
| 'layers_' . $this->widget_id . '_widget_design_bar_custom_components' , | |
| array( | |
| 'display' => array( | |
| 'icon-css' => 'icon-display', | |
| 'label' => __( 'Display', 'layerswp' ), | |
| 'elements' => array( | |
| 'text_style' => array( | |
| 'type' => 'select', | |
| 'name' => $this->get_field_name( 'text_style' ) , | |
| 'id' => $this->get_field_id( 'text_style' ) , | |
| 'value' => ( isset( $text_style ) ) ? $text_style : NULL, | |
| 'label' => __( 'Title & Excerpt Position' , 'layerswp' ), | |
| 'options' => array( | |
| 'regular' => __( 'Regular' , 'layerswp' ), | |
| 'overlay' => __( 'Overlay' , 'layerswp' ) | |
| ) | |
| ), | |
| 'show_media' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_media' ) , | |
| 'id' => $this->get_field_id( 'show_media' ) , | |
| 'value' => ( isset( $show_media ) ) ? $show_media : NULL, | |
| 'label' => __( 'Show Featured Images' , 'layerswp' ) | |
| ), | |
| 'show_titles' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_titles' ) , | |
| 'id' => $this->get_field_id( 'show_titles' ) , | |
| 'value' => ( isset( $show_titles ) ) ? $show_titles : NULL, | |
| 'label' => __( 'Show Post Titles' , 'layerswp' ) | |
| ), | |
| 'show_excerpts' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_excerpts' ) , | |
| 'id' => $this->get_field_id( 'show_excerpts' ) , | |
| 'value' => ( isset( $show_excerpts ) ) ? $show_excerpts : NULL, | |
| 'label' => __( 'Show Post Excerpts' , 'layerswp' ) | |
| ), | |
| 'excerpt_length' => array( | |
| 'type' => 'number', | |
| 'name' => $this->get_field_name( 'excerpt_length' ) , | |
| 'id' => $this->get_field_id( 'excerpt_length' ) , | |
| 'min' => 0, | |
| 'max' => 10000, | |
| 'value' => ( isset( $excerpt_length ) ) ? $excerpt_length : NULL, | |
| 'label' => __( 'Excerpts Length' , 'layerswp' ) | |
| ), | |
| 'show_dates' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_dates' ) , | |
| 'id' => $this->get_field_id( 'show_dates' ) , | |
| 'value' => ( isset( $show_dates ) ) ? $show_dates : NULL, | |
| 'label' => __( 'Show Post Dates' , 'layerswp' ) | |
| ), | |
| 'show_author' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_author' ) , | |
| 'id' => $this->get_field_id( 'show_author' ) , | |
| 'value' => ( isset( $show_author ) ) ? $show_author : NULL, | |
| 'label' => __( 'Show Post Author' , 'layerswp' ) | |
| ), | |
| 'show_tags' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_tags' ) , | |
| 'id' => $this->get_field_id( 'show_tags' ) , | |
| 'value' => ( isset( $show_tags ) ) ? $show_tags : NULL, | |
| 'label' => __( 'Show Tags' , 'layerswp' ) | |
| ), | |
| 'show_categories' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_categories' ) , | |
| 'id' => $this->get_field_id( 'show_categories' ) , | |
| 'value' => ( isset( $show_categories ) ) ? $show_categories : NULL, | |
| 'label' => __( 'Show Categories' , 'layerswp' ) | |
| ), | |
| 'show_call_to_action' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_call_to_action' ) , | |
| 'id' => $this->get_field_id( 'show_call_to_action' ) , | |
| 'value' => ( isset( $show_call_to_action ) ) ? $show_call_to_action : NULL, | |
| 'label' => __( 'Show "Read More" Buttons' , 'layerswp' ) | |
| ), | |
| 'call_to_action' => array( | |
| 'type' => 'text', | |
| 'name' => $this->get_field_name( 'call_to_action' ) , | |
| 'id' => $this->get_field_id( 'call_to_action' ) , | |
| 'value' => ( isset( $call_to_action ) ) ? $call_to_action : NULL, | |
| 'label' => __( '"Read More" Text' , 'layerswp' ) | |
| ), | |
| 'show_pagination' => array( | |
| 'type' => 'checkbox', | |
| 'name' => $this->get_field_name( 'show_pagination' ) , | |
| 'id' => $this->get_field_id( 'show_pagination' ) , | |
| 'value' => ( isset( $show_pagination ) ) ? $show_pagination : NULL, | |
| 'label' => __( 'Show Pagination' , 'layerswp' ) | |
| ), | |
| ) | |
| ) | |
| ) | |
| ); | |
| $this->design_bar( | |
| 'side', // CSS Class Name | |
| array( | |
| 'name' => $this->get_field_name( 'design' ), | |
| 'id' => $this->get_field_id( 'design' ), | |
| ), // Widget Object | |
| $instance, // Widget Values | |
| $design_bar_components, // Standard Components | |
| $design_bar_custom_components // Add-on Components | |
| ); | |
| ?> | |
| <div class="layers-container-large"> | |
| <!-- All of our form logic will sit here --> | |
| <?php $this->form_elements()->header( | |
| array( | |
| 'title' => __( 'Post' , 'layerswp' ), | |
| 'icon_class' => 'post' | |
| ) | |
| ); ?> | |
| <section class="layers-accordion-section layers-content"> | |
| <div class="layers-row layers-push-bottom"> | |
| <!-- Form body elements will go here--> | |
| <p class="layers-form-item"> | |
| <?php echo $this->form_elements()->input( | |
| array( | |
| 'type' => 'text', | |
| 'name' => $this->get_field_name( 'title' ) , | |
| 'id' => $this->get_field_id( 'title' ) , | |
| 'placeholder' => __( 'Enter title here' , 'layerswp' ), | |
| 'value' => ( isset( $title ) ) ? $title : NULL , | |
| 'class' => 'layers-text layers-large' | |
| ) | |
| ); ?> | |
| </p> | |
| <p class="layers-form-item"> | |
| <?php echo $this->form_elements()->input( | |
| array( | |
| 'type' => 'textarea', | |
| 'name' => $this->get_field_name( 'excerpt' ) , | |
| 'id' => $this->get_field_id( 'excerpt' ) , | |
| 'placeholder' => __( 'Short Excerpt' , 'layerswp' ), | |
| 'value' => ( isset( $excerpt ) ) ? $excerpt : NULL , | |
| 'class' => 'layers-textarea layers-large' | |
| ) | |
| ); ?> | |
| </p> | |
| </div> | |
| </section> | |
| </div> | |
| <?php | |
| } // Form | |
| } // Class | |
| // Register our widget | |
| register_widget( 'Layers_Your_Widget' ); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment