adding new view file and widget options
authorAnthony Talarico <talarico@gaslightmedia.com>
Sat, 19 Oct 2019 23:31:26 +0000 (19:31 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Sat, 19 Oct 2019 23:31:26 +0000 (19:31 -0400)
extending the widget class to add admin side input fields and addding another view file

models/Glmclientinfo_Widget.php
views/footer.php [new file with mode: 0644]

index 9d748e7..686fbc1 100644 (file)
@@ -41,7 +41,9 @@ class Glmclientinfo_Widget
         parent::__construct(
             'GlmClientInfo_Widget',
             __('Client Info Widget', 'text_domain'),
-            array('description' => __('A Gaslight Widget', 'text_domain'))
+            array(
+                'description' => __('A Gaslight Widget', 'text_domain'),
+            )
         );
     }
 
@@ -59,9 +61,34 @@ class Glmclientinfo_Widget
     public function widget($args, $instance)
     {
         $path = plugin_dir_path(__FILE__);
-        include $path . '../views/vCard.php';
+        include $path . "../views/".$instance['view_file'] . ".php";
     }
 
+    public function form( $instance ) {
+        $view_file = ! empty( $instance['view_file'] ) ? $instance['view_file'] : esc_html__( 'footer', 'text_domain' );
+        ?>
+        <p>
+        <label for="<?php echo esc_attr( $this->get_field_id( 'view_file' ) ); ?>">
+        <?php esc_attr_e( 'View File:', 'text_domain' ); ?>
+        </label> 
+        
+        <input 
+            class="widefat" 
+            id="<?php echo esc_attr( $this->get_field_id( 'view_file' ) ); ?>" 
+            name="<?php echo esc_attr( $this->get_field_name( 'view_file' ) ); ?>" 
+            type="text" 
+            value="<?php echo esc_attr( $view_file ); ?>">
+        </p>
+        <?php
+    }
+
+       // save options
+       public function update( $new_instance, $old_instance ) {
+        $instance = array();
+        $instance['view_file'] = ( ! empty( $new_instance['view_file'] ) ) ? strip_tags( $new_instance['view_file'] ) : '';
+            
+        return $instance;
+    }
     /**
      * Return the quicksite option for the given key
      *
diff --git a/views/footer.php b/views/footer.php
new file mode 100644 (file)
index 0000000..98afe60
--- /dev/null
@@ -0,0 +1,14 @@
+<div class="glm-footer-client-info">
+    <?php foreach( get_option('glmclientinfo_settings') as $setting => $value){ ?>
+            <div class="glm-client-info-field glm-client-info-<?php echo $setting; ?>">
+                <?php if( $value !== '') { ?>
+                        <div class="glm-client-info-name" ><?php echo $setting; ?>:</div>
+                    <?php if( $setting === "phone" || $setting === "tollfree"){ ?>
+                        <a href="tel:<?php echo str_replace(array('.', ',','-'), '' , $value); ?>"><?php echo $value; ?></a>
+                    <?php } else { ?>
+                        <div class="glm-client-info-value"><?php echo $value;?></div>
+                    <?php } ?>
+                <?php } ?>
+            </div>
+      <?php } ?>
+</div>
\ No newline at end of file