public
anonymous / Jumbotron_widget.php
Created

  • Download Gist
Jumbotron_widget.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
<?php
register_widget('Basic_Jumbotron_Widget');
 
class Basic_Jumbotron_Widget extends WP_Widget {
function Basic_Jumbotron_Widget() {
$widget_ops = array('classname' => 'widget_basic_jumbotron', 'description' => __('Use this widget to add a jumbotron', 'basic'));
$this->WP_Widget('widget_basic_jumbotron', __('Basic: jumbotron', 'basic'), $widget_ops);
$this->alt_option_name = 'widget_basic_jumbotron';
 
add_action('save_post', array(&$this, 'flush_widget_cache'));
add_action('deleted_post', array(&$this, 'flush_widget_cache'));
add_action('switch_theme', array(&$this, 'flush_widget_cache'));
}
 
function widget($args, $instance) {
$cache = wp_cache_get('widget_basic_jumbotron', 'widget');
 
if (!is_array($cache)) {
$cache = array();
}
 
if (!isset($args['widget_id'])) {
$args['widget_id'] = null;
}
 
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
 
ob_start();
extract($args, EXTR_SKIP);
 
$title = apply_filters('widget_title', empty($instance['title']) ? __('', 'basic') : $instance['title'], $instance, $this->id_base);
if (!isset($instance['maintext'])) { $instance['maintext'] = ''; }
if (!isset($instance['link_text_white'])) { $instance['link_text_white'] = ''; }
if (!isset($instance['link_target_white'])) { $instance['link_target_white'] = ''; }
if (!isset($instance['link_text_blue'])) { $instance['link_text_blue'] = ''; }
if (!isset($instance['link_target_blue'])) { $instance['link_target_blue'] = ''; }
if (!isset($instance['link_text_green'])) { $instance['link_text_green'] = ''; }
if (!isset($instance['link_target_green'])) { $instance['link_target_green'] = ''; }
if (!isset($instance['link_text_orange'])) { $instance['link_text_orange'] = ''; }
if (!isset($instance['link_target_orange'])) { $instance['link_target_orange'] = ''; }
if (!isset($instance['link_text_red'])) { $instance['link_text_red'] = ''; }
if (!isset($instance['link_target_red'])) { $instance['link_target_red'] = ''; }
if (!isset($instance['link_text_black'])) { $instance['link_text_black'] = ''; }
if (!isset($instance['link_target_black'])) { $instance['link_target_black'] = ''; }
 
echo $before_widget;
if ($title) {
echo $before_title;
echo $title;
echo $after_title;
}
?>
<div style="text-align: center;">
<h2 style="font-weight: normal !important; text-align: center;"><?php echo $instance['maintext']; ?></h2><br>
<?php if (!empty($instance['link_target_white'])) { ?><a class="btn btn-large" href="<?php echo $instance['link_target_white']; ?>"><?php echo $instance['link_text_white']; ?></a><?php } ?>
<?php if (!empty($instance['link_target_blue'])) { ?><a class="btn btn-large btn-primary" href="<?php echo $instance['link_target_blue']; ?>"><?php echo $instance['link_text_blue']; ?></a><?php } ?>
<?php if (!empty($instance['link_target_green'])) { ?><a class="btn btn-large btn-success" href="<?php echo $instance['link_target_green']; ?>"><?php echo $instance['link_text_green']; ?></a><?php } ?>
<?php if (!empty($instance['link_target_orange'])) { ?><a class="btn btn-large btn-warning" href="<?php echo $instance['link_target_orange']; ?>"><?php echo $instance['link_text_orange']; ?></a><?php } ?>
<?php if (!empty($instance['link_target_red'])) { ?><a class="btn btn-large btn-danger" href="<?php echo $instance['link_target_red']; ?>"><?php echo $instance['link_text_red']; ?></a><?php } ?>
<?php if (!empty($instance['link_target_black'])) { ?><a class="btn btn-large btn-inverse" href="<?php echo $instance['link_target_black']; ?>"><?php echo $instance['link_text_black']; ?></a><?php } ?>
</div>
<?php
echo $after_widget;
 
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_basic_jumbotron', $cache, 'widget');
}
 
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['maintext'] = strip_tags($new_instance['maintext']);
$instance['link_text_white'] = strip_tags($new_instance['link_text_white']);
$instance['link_target_white'] = strip_tags($new_instance['link_target_white']);
$instance['link_text_blue'] = strip_tags($new_instance['link_text_blue']);
$instance['link_target_blue'] = strip_tags($new_instance['link_target_blue']);
$instance['link_text_green'] = strip_tags($new_instance['link_text_green']);
$instance['link_target_green'] = strip_tags($new_instance['link_target_green']);
$instance['link_text_orange'] = strip_tags($new_instance['link_text_orange']);
$instance['link_target_orange'] = strip_tags($new_instance['link_target_orange']);
$instance['link_text_red'] = strip_tags($new_instance['link_text_red']);
$instance['link_target_red'] = strip_tags($new_instance['link_target_red']);
$instance['link_text_black'] = strip_tags($new_instance['link_text_black']);
$instance['link_target_black'] = strip_tags($new_instance['link_target_black']);
$this->flush_widget_cache();
 
$alloptions = wp_cache_get('alloptions', 'options');
if (isset($alloptions['widget_basic_jumbotron'])) {
delete_option('widget_basic_jumbotron');
}
 
return $instance;
}
 
function flush_widget_cache() {
wp_cache_delete('widget_basic_jumbotron', 'widget');
}
 
function form($instance) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$maintext = isset($instance['maintext']) ? esc_attr($instance['maintext']) : '';
$link_text_blue = isset($instance['link_text_white']) ? esc_attr($instance['link_text_white']) : '';
$link_target_blue = isset($instance['link_target_white']) ? esc_attr($instance['link_target_white']) : '';
$link_text_blue = isset($instance['link_text_blue']) ? esc_attr($instance['link_text_blue']) : '';
$link_target_blue = isset($instance['link_target_blue']) ? esc_attr($instance['link_target_blue']) : '';
$link_text_blue = isset($instance['link_text_green']) ? esc_attr($instance['link_text_green']) : '';
$link_target_blue = isset($instance['link_target_green']) ? esc_attr($instance['link_target_green']) : '';
$link_text_blue = isset($instance['link_text_orange']) ? esc_attr($instance['link_text_orange']) : '';
$link_target_blue = isset($instance['link_target_orange']) ? esc_attr($instance['link_target_orange']) : '';
$link_text_blue = isset($instance['link_text_red']) ? esc_attr($instance['link_text_red']) : '';
$link_target_blue = isset($instance['link_target_red']) ? esc_attr($instance['link_target_red']) : '';
$link_text_blue = isset($instance['link_text_black']) ? esc_attr($instance['link_text_black']) : '';
$link_target_blue = isset($instance['link_target_black']) ? esc_attr($instance['link_target_black']) : '';
?>
<table class="table table table-striped table-bordered">
<tbody>
<tr>
<td colspan="4">
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title (optional):', 'basic'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</td>
</tr>
<tr>
<td colspan="4">
<label for="<?php echo esc_attr($this->get_field_id('maintext')); ?>"><?php _e('Your Text', 'basic'); ?></label>
<input id="<?php echo esc_attr($this->get_field_id('maintext')); ?>" name="<?php echo esc_attr($this->get_field_name('maintext')); ?>" type="text" value="<?php echo esc_attr($maintext); ?>" />
</td>
</tr>
<tr>
<td colspan="4">
<div class="alert alert-info">Παρακάτω μπορείτε να συμπληρώσετε κείμενο και συνδέσμους για να εμφανιστούν κουμπιά με το αντίστοιχο χρώμα.
Για παράδειγμα μπορείτε να βάλετε σαν κείμενο "Δείτε τα προϊόντα μας" με σύνδεσμο "/store/products" για να παραπέμψετε τον χρήστη στη λίστα των προϊόντων σας.</div>
 
</td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_white')); ?>"><span class="btn">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_white')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_white')); ?>" type="text" value="<?php echo esc_attr($link_text_white); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_white')); ?>"><span class="btn">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_white')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_white')); ?>" type="text" value="<?php echo esc_attr($link_target_white); ?>" /></td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_blue')); ?>"><span class="btn btn-primary">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_blue')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_blue')); ?>" type="text" value="<?php echo esc_attr($link_text_blue); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_blue')); ?>"><span class="btn btn-primary">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_blue')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_blue')); ?>" type="text" value="<?php echo esc_attr($link_target_blue); ?>" /></td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_green')); ?>"><span class="btn btn-success">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_green')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_green')); ?>" type="text" value="<?php echo esc_attr($link_text_green); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_green')); ?>"><span class="btn btn-success">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_green')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_green')); ?>" type="text" value="<?php echo esc_attr($link_target_green); ?>" /></td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_orange')); ?>"><span class="btn btn-warning">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_orange')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_orange')); ?>" type="text" value="<?php echo esc_attr($link_text_orange); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_orange')); ?>"><span class="btn btn-warning">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_orange')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_orange')); ?>" type="text" value="<?php echo esc_attr($link_target_orange); ?>" /></td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_red')); ?>"><span class="btn btn-danger">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_red')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_red')); ?>" type="text" value="<?php echo esc_attr($link_text_red); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_red')); ?>"><span class="btn btn-danger">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_red')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_red')); ?>" type="text" value="<?php echo esc_attr($link_target_red); ?>" /></td>
</tr>
<tr>
<td><label for="<?php echo esc_attr($this->get_field_id('link_text_black')); ?>"><span class="btn btn-inverse">Κείμενο κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_text_black')); ?>" name="<?php echo esc_attr($this->get_field_name('link_text_black')); ?>" type="text" value="<?php echo esc_attr($link_text_black); ?>" /></td>
<td><label for="<?php echo esc_attr($this->get_field_id('link_target_black')); ?>"><span class="btn btn-inverse">Σύνδεσμος κουμπιού</span></label></td>
<td><input id="<?php echo esc_attr($this->get_field_id('link_target_black')); ?>" name="<?php echo esc_attr($this->get_field_name('link_target_black')); ?>" type="text" value="<?php echo esc_attr($link_target_black); ?>" /></td>
</tr>
</tbody>
</table>
<?php
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.