CPT Bootstrap Carousel - Version 1.7

Version Description

  • Added custom classes for next/prev buttons - written by @reddo
  • Added admin column for categories
  • Made the category dropdown in the settings work (bugfix)
  • Addeed contextual help on post and page editing screens
Download this release

Release Info

Developer tallphil
Plugin Icon 128x128 CPT Bootstrap Carousel
Version 1.7
Comparing to
See all releases

Code changes from version 1.6 to 1.7

Files changed (2) hide show
  1. cpt-bootstrap-carousel.php +232 -117
  2. readme.txt +7 -1
cpt-bootstrap-carousel.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CPT Bootstrap Carousel
4
  Plugin URI: http://www.tallphil.co.uk/bootstrap-carousel/
5
  Description: A custom post type for choosing images and content which outputs <a href="http://getbootstrap.com/javascript/#carousel" target="_blank">Bootstrap Carousel</a> from a shortcode. Requires Bootstrap javascript and CSS to be loaded separately.
6
- Version: 1.6
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  Text Domain: cpt-bootstrap-carousel
@@ -87,31 +87,44 @@ function cptbc_get_featured_image($post_ID) {
87
  }
88
  function cptbc_columns_head($defaults) {
89
  $defaults['featured_image'] = __('Featured Image', 'cpt-bootstrap-carousel');
 
90
  return $defaults;
91
  }
92
  function cptbc_columns_content($column_name, $post_ID) {
93
  if ($column_name == 'featured_image') {
94
  $post_featured_image = cptbc_get_featured_image($post_ID);
95
  if ($post_featured_image) {
96
- echo '<a href="'.get_edit_post_link($post_ID).'"><img src="' . $post_featured_image . '" /></a>';
97
  }
98
- }
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
  add_filter('manage_cptbc_posts_columns', 'cptbc_columns_head');
101
  add_action('manage_cptbc_posts_custom_column', 'cptbc_columns_content', 10, 2);
102
 
103
  // Extra admin field for image URL
104
  function cptbc_image_url(){
105
- global $post;
106
- $custom = get_post_custom($post->ID);
107
- $cptbc_image_url = isset($custom['cptbc_image_url']) ? $custom['cptbc_image_url'][0] : '';
108
- $cptbc_image_url_openblank = isset($custom['cptbc_image_url_openblank']) ? $custom['cptbc_image_url_openblank'][0] : '0';
109
- ?>
110
- <label><?php _e('Image URL', 'cpt-bootstrap-carousel'); ?>:</label>
111
- <input name="cptbc_image_url" value="<?php echo $cptbc_image_url; ?>" /> <br />
112
- <small><em><?php _e('(optional - leave blank for no link)', 'cpt-bootstrap-carousel'); ?></em></small><br /><br />
113
- <label><input type="checkbox" name="cptbc_image_url_openblank" <?php if($cptbc_image_url_openblank == 1){ echo ' checked="checked"'; } ?> value="1" /> <?php _e('Open link in new window?', 'cpt-bootstrap-carousel'); ?></label>
114
- <?php
115
  }
116
  function cptbc_admin_init_custpost(){
117
  add_meta_box("cptbc_image_url", "Image Link URL", "cptbc_image_url", "cptbc", "side", "low");
@@ -137,6 +150,8 @@ function cptbc_set_options (){
137
  'interval' => '5000',
138
  'showcaption' => 'true',
139
  'showcontrols' => 'true',
 
 
140
  'orderby' => 'menu_order',
141
  'order' => 'ASC',
142
  'category' => '',
@@ -158,118 +173,134 @@ function cptbc_deactivate(){
158
  class cptbc_settings_page {
159
  // Holds the values to be used in the fields callbacks
160
  private $options;
161
-
162
  // Start up
163
  public function __construct() {
164
- add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
165
- add_action( 'admin_init', array( $this, 'page_init' ) );
166
  }
167
-
168
  // Add settings page
169
  public function add_plugin_page() {
170
  add_submenu_page('edit.php?post_type=cptbc', __('Settings', 'cpt-bootstrap-carousel'), __('Settings', 'cpt-bootstrap-carousel'), 'manage_options', 'cpt-bootstrap-carousel', array($this,'create_admin_page'));
171
  }
172
-
173
  // Options page callback
174
  public function create_admin_page() {
175
- // Set class property
176
- $this->options = get_option( 'cptbc_settings' );
177
  if(!$this->options){
178
  cptbc_set_options ();
179
  $this->options = get_option( 'cptbc_settings' );
180
  }
181
- ?>
182
- <div class="wrap">
183
  <?php screen_icon('edit');?> <h2>CPT Bootstrap Carousel <?php _e('Settings', 'cpt-bootstrap-carousel'); ?></h2>
184
  <p><?php printf(__('You can set the default behaviour of your carousels here. All of these settings can be overridden by using %s shortcode attributes %s.', 'cpt-bootstrap-carousel'),'<a href="http://wordpress.org/plugins/cpt-bootstrap-carousel/" target="_blank">', '</a>'); ?></p>
185
-
186
- <form method="post" action="options.php">
187
- <?php
188
- settings_fields( 'cptbc_settings' );
189
- do_settings_sections( 'cpt-bootstrap-carousel' );
190
- submit_button();
191
- ?>
192
- </form>
193
- </div>
194
- <?php
195
  }
196
-
197
  // Register and add settings
198
  public function page_init() {
199
- register_setting(
200
- 'cptbc_settings', // Option group
201
- 'cptbc_settings', // Option name
202
- array( $this, 'sanitize' ) // Sanitize
203
- );
204
-
205
- add_settings_section(
206
- 'cptbc_settings_options', // ID
207
- '', // Title - nothing to say here.
208
- array( $this, 'cptbc_settings_options_header' ), // Callback
209
- 'cpt-bootstrap-carousel' // Page
210
- );
211
-
212
- add_settings_field(
213
- 'twbs', // ID
214
- __('Twitter Bootstrap Version', 'cpt-bootstrap-carousel'), // Title
215
- array( $this, 'twbs_callback' ), // Callback
216
- 'cpt-bootstrap-carousel', // Page
217
- 'cptbc_settings_options' // Section
218
- );
219
-
220
- add_settings_field(
221
- 'interval', // ID
222
- __('Slide Interval (milliseconds)', 'cpt-bootstrap-carousel'), // Title
223
- array( $this, 'interval_callback' ), // Callback
224
- 'cpt-bootstrap-carousel', // Page
225
- 'cptbc_settings_options' // Section
226
- );
227
 
228
- add_settings_field(
229
- 'showcaption', // ID
230
- __('Show Slide Captions?', 'cpt-bootstrap-carousel'), // Title
231
- array( $this, 'showcaption_callback' ), // Callback
232
- 'cpt-bootstrap-carousel', // Page
233
- 'cptbc_settings_options' // Section
234
- );
235
 
236
- add_settings_field(
237
- 'showcontrols', // ID
238
- __('Show Slide Controls?', 'cpt-bootstrap-carousel'), // Title
239
- array( $this, 'showcontrols_callback' ), // Callback
240
- 'cpt-bootstrap-carousel', // Page
241
- 'cptbc_settings_options' // Section
242
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
- add_settings_field(
245
- 'orderby', // ID
246
- __('Order Slides By', 'cpt-bootstrap-carousel'), // Title
247
- array( $this, 'orderby_callback' ), // Callback
248
- 'cpt-bootstrap-carousel', // Page
249
- 'cptbc_settings_options' // Section
250
- );
251
 
252
- add_settings_field(
253
- 'order', // ID
254
- __('Ordering Direction', 'cpt-bootstrap-carousel'), // Title
255
- array( $this, 'order_callback' ), // Callback
256
- 'cpt-bootstrap-carousel', // Page
257
- 'cptbc_settings_options' // Section
258
- );
259
 
260
- add_settings_field(
261
- 'category', // ID
262
- __('Restrict to Category', 'cpt-bootstrap-carousel'), // Title
263
- array( $this, 'category_callback' ), // Callback
264
- 'cpt-bootstrap-carousel', // Page
265
- 'cptbc_settings_options' // Section
266
- );
267
-
268
  }
269
-
270
  // Sanitize each setting field as needed - @param array $input Contains all settings fields as array keys
271
  public function sanitize( $input ) {
272
- $new_input = array();
273
  foreach($input as $key => $var){
274
  if($key == 'twbs' || $key == 'interval'){
275
  $new_input[$key] = absint( $input[$key] );
@@ -280,14 +311,14 @@ class cptbc_settings_page {
280
  $new_input[$key] = sanitize_text_field( $input[$key] );
281
  }
282
  }
283
- return $new_input;
284
  }
285
-
286
  // Print the Section text
287
  public function cptbc_settings_options_header() {
288
- // nothing to say here.
289
  }
290
-
291
  public function twbs_callback() {
292
  if(isset( $this->options['twbs'] ) && $this->options['twbs'] == '3'){
293
  $cptbc_twbs3 = ' selected="selected"';
@@ -303,8 +334,8 @@ class cptbc_settings_page {
303
  }
304
 
305
  public function interval_callback() {
306
- printf('<input type="text" id="interval" name="cptbc_settings[interval]" value="%s" size="6" />',
307
- isset( $this->options['interval'] ) ? esc_attr( $this->options['interval']) : '');
308
  }
309
 
310
  public function showcaption_callback() {
@@ -325,22 +356,39 @@ class cptbc_settings_page {
325
  if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'false'){
326
  $cptbc_showcontrols_t = '';
327
  $cptbc_showcontrols_f = ' selected="selected"';
328
- } else {
 
329
  $cptbc_showcontrols_t = ' selected="selected"';
330
  $cptbc_showcontrols_f = '';
 
 
 
 
 
331
  }
332
  print '<select id="showcontrols" name="cptbc_settings[showcontrols]">
333
  <option value="true"'.$cptbc_showcontrols_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
334
  <option value="false"'.$cptbc_showcontrols_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
 
335
  </select>';
336
  }
337
 
 
 
 
 
 
 
 
 
 
 
338
  public function orderby_callback() {
339
  $orderby_options = array (
340
  'menu_order' => __('Menu order, as set in Carousel overview page', 'cpt-bootstrap-carousel'),
341
  'date' => __('Date slide was published', 'cpt-bootstrap-carousel'),
342
  'rand' => __('Random ordering', 'cpt-bootstrap-carousel'),
343
- 'title' => __('Slide title', 'cpt-bootstrap-carousel')
344
  );
345
  print '<select id="orderby" name="cptbc_settings[orderby]">';
346
  foreach($orderby_options as $val => $option){
@@ -372,20 +420,20 @@ class cptbc_settings_page {
372
  print '<select id="orderby" name="cptbc_settings[category]">
373
  <option value="">'.__('All Categories', 'cpt-bootstrap-carousel').'</option>';
374
  foreach($cats as $cat){
375
- print '<option value="'.$cat->term_id.'"';
376
- if(isset( $this->options['category'] ) && $this->options['category'] == $cat->term_id){
377
  print ' selected="selected"';
378
  }
379
  print ">".$cat->name."</option>";
380
  }
381
  print '</select>';
382
  }
383
-
384
 
385
  }
386
 
387
  if( is_admin() ){
388
- $cptbc_settings_page = new cptbc_settings_page();
389
  }
390
 
391
  // Add settings link on plugin page
@@ -399,6 +447,65 @@ add_filter("plugin_action_links_$cptbc_plugin", 'cptbc_settings_link' );
399
 
400
 
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
 
403
 
404
 
@@ -408,7 +515,7 @@ add_filter("plugin_action_links_$cptbc_plugin", 'cptbc_settings_link' );
408
 
409
  // Shortcode
410
  function cptbc_shortcode($atts, $content = null) {
411
- // Set default shortcode attributes
412
  $options = get_option( 'cptbc_settings' );
413
  if(!$options){
414
  cptbc_set_options ();
@@ -426,7 +533,12 @@ add_shortcode('image-carousel', 'cptbc_shortcode');
426
  // Display carousel
427
  function cptbc_frontend($atts){
428
  $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
429
- $args = array( 'post_type' => 'cptbc', 'posts_per_page' => '-1', 'orderby' => $atts['orderby'], 'order' => $atts['order']);
 
 
 
 
 
430
  if($atts['category'] != ''){
431
  $args['carousel_category'] = $atts['category'];
432
  }
@@ -450,10 +562,10 @@ function cptbc_frontend($atts){
450
  if(count($images) > 0){
451
  ob_start();
452
  ?>
453
- <div id="cptbc_<?php echo $id; ?>" class="carousel slide">
454
  <ol class="carousel-indicators">
455
  <?php foreach ($images as $key => $image) { ?>
456
- <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" data-interval="<?php echo $atts['interval']; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
457
  <?php } ?>
458
  </ol>
459
  <div class="carousel-inner">
@@ -486,6 +598,9 @@ function cptbc_frontend($atts){
486
  <?php } else if($atts['showcontrols'] === 'true'){ ?>
487
  <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
488
  <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
 
 
 
489
  <?php } ?>
490
  </div>
491
  <script type="text/javascript">
@@ -500,9 +615,9 @@ function cptbc_frontend($atts){
500
  ob_end_clean();
501
 
502
  // Restore original Post Data
503
- wp_reset_postdata();
504
 
505
  return $output;
506
  }
507
 
508
- ?>
3
  Plugin Name: CPT Bootstrap Carousel
4
  Plugin URI: http://www.tallphil.co.uk/bootstrap-carousel/
5
  Description: A custom post type for choosing images and content which outputs <a href="http://getbootstrap.com/javascript/#carousel" target="_blank">Bootstrap Carousel</a> from a shortcode. Requires Bootstrap javascript and CSS to be loaded separately.
6
+ Version: 1.7
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  Text Domain: cpt-bootstrap-carousel
87
  }
88
  function cptbc_columns_head($defaults) {
89
  $defaults['featured_image'] = __('Featured Image', 'cpt-bootstrap-carousel');
90
+ $defaults['category'] = __('Category', 'cpt-bootstrap-carousel');
91
  return $defaults;
92
  }
93
  function cptbc_columns_content($column_name, $post_ID) {
94
  if ($column_name == 'featured_image') {
95
  $post_featured_image = cptbc_get_featured_image($post_ID);
96
  if ($post_featured_image) {
97
+ echo '<a href="'.get_edit_post_link($post_ID).'"><img src="' . $post_featured_image . '" alt="" style="max-width:100%;" /></a>';
98
  }
99
+ }
100
+ if ($column_name == 'category') {
101
+ $post_categories = get_the_terms($post_ID, 'carousel_category');
102
+ if ($post_categories) {
103
+ $output = '';
104
+ foreach($post_categories as $cat){
105
+ $output .= $cat->name.', ';
106
+ }
107
+ echo trim($output, ', ');
108
+ } else {
109
+ echo 'No categories';
110
+ }
111
+ }
112
  }
113
  add_filter('manage_cptbc_posts_columns', 'cptbc_columns_head');
114
  add_action('manage_cptbc_posts_custom_column', 'cptbc_columns_content', 10, 2);
115
 
116
  // Extra admin field for image URL
117
  function cptbc_image_url(){
118
+ global $post;
119
+ $custom = get_post_custom($post->ID);
120
+ $cptbc_image_url = isset($custom['cptbc_image_url']) ? $custom['cptbc_image_url'][0] : '';
121
+ $cptbc_image_url_openblank = isset($custom['cptbc_image_url_openblank']) ? $custom['cptbc_image_url_openblank'][0] : '0';
122
+ ?>
123
+ <label><?php _e('Image URL', 'cpt-bootstrap-carousel'); ?>:</label>
124
+ <input name="cptbc_image_url" value="<?php echo $cptbc_image_url; ?>" /> <br />
125
+ <small><em><?php _e('(optional - leave blank for no link)', 'cpt-bootstrap-carousel'); ?></em></small><br /><br />
126
+ <label><input type="checkbox" name="cptbc_image_url_openblank" <?php if($cptbc_image_url_openblank == 1){ echo ' checked="checked"'; } ?> value="1" /> <?php _e('Open link in new window?', 'cpt-bootstrap-carousel'); ?></label>
127
+ <?php
128
  }
129
  function cptbc_admin_init_custpost(){
130
  add_meta_box("cptbc_image_url", "Image Link URL", "cptbc_image_url", "cptbc", "side", "low");
150
  'interval' => '5000',
151
  'showcaption' => 'true',
152
  'showcontrols' => 'true',
153
+ 'customprev' => '',
154
+ 'customnext' => '',
155
  'orderby' => 'menu_order',
156
  'order' => 'ASC',
157
  'category' => '',
173
  class cptbc_settings_page {
174
  // Holds the values to be used in the fields callbacks
175
  private $options;
176
+
177
  // Start up
178
  public function __construct() {
179
+ add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
180
+ add_action( 'admin_init', array( $this, 'page_init' ) );
181
  }
182
+
183
  // Add settings page
184
  public function add_plugin_page() {
185
  add_submenu_page('edit.php?post_type=cptbc', __('Settings', 'cpt-bootstrap-carousel'), __('Settings', 'cpt-bootstrap-carousel'), 'manage_options', 'cpt-bootstrap-carousel', array($this,'create_admin_page'));
186
  }
187
+
188
  // Options page callback
189
  public function create_admin_page() {
190
+ // Set class property
191
+ $this->options = get_option( 'cptbc_settings' );
192
  if(!$this->options){
193
  cptbc_set_options ();
194
  $this->options = get_option( 'cptbc_settings' );
195
  }
196
+ ?>
197
+ <div class="wrap">
198
  <?php screen_icon('edit');?> <h2>CPT Bootstrap Carousel <?php _e('Settings', 'cpt-bootstrap-carousel'); ?></h2>
199
  <p><?php printf(__('You can set the default behaviour of your carousels here. All of these settings can be overridden by using %s shortcode attributes %s.', 'cpt-bootstrap-carousel'),'<a href="http://wordpress.org/plugins/cpt-bootstrap-carousel/" target="_blank">', '</a>'); ?></p>
200
+
201
+ <form method="post" action="options.php">
202
+ <?php
203
+ settings_fields( 'cptbc_settings' );
204
+ do_settings_sections( 'cpt-bootstrap-carousel' );
205
+ submit_button();
206
+ ?>
207
+ </form>
208
+ </div>
209
+ <?php
210
  }
211
+
212
  // Register and add settings
213
  public function page_init() {
214
+ register_setting(
215
+ 'cptbc_settings', // Option group
216
+ 'cptbc_settings', // Option name
217
+ array( $this, 'sanitize' ) // Sanitize
218
+ );
219
+
220
+ add_settings_section(
221
+ 'cptbc_settings_options', // ID
222
+ '', // Title - nothing to say here.
223
+ array( $this, 'cptbc_settings_options_header' ), // Callback
224
+ 'cpt-bootstrap-carousel' // Page
225
+ );
226
+
227
+ add_settings_field(
228
+ 'twbs', // ID
229
+ __('Twitter Bootstrap Version', 'cpt-bootstrap-carousel'), // Title
230
+ array( $this, 'twbs_callback' ), // Callback
231
+ 'cpt-bootstrap-carousel', // Page
232
+ 'cptbc_settings_options' // Section
233
+ );
234
+
235
+ add_settings_field(
236
+ 'interval', // ID
237
+ __('Slide Interval (milliseconds)', 'cpt-bootstrap-carousel'), // Title
238
+ array( $this, 'interval_callback' ), // Callback
239
+ 'cpt-bootstrap-carousel', // Page
240
+ 'cptbc_settings_options' // Section
241
+ );
242
 
243
+ add_settings_field(
244
+ 'showcaption', // ID
245
+ __('Show Slide Captions?', 'cpt-bootstrap-carousel'), // Title
246
+ array( $this, 'showcaption_callback' ), // Callback
247
+ 'cpt-bootstrap-carousel', // Page
248
+ 'cptbc_settings_options' // Section
249
+ );
250
 
251
+ add_settings_field(
252
+ 'showcontrols', // ID
253
+ __('Show Slide Controls?', 'cpt-bootstrap-carousel'), // Title
254
+ array( $this, 'showcontrols_callback' ), // Callback
255
+ 'cpt-bootstrap-carousel', // Page
256
+ 'cptbc_settings_options' // Section
257
+ );
258
+
259
+ add_settings_field(
260
+ 'customprev', // ID
261
+ __('Custom prev button class', 'cpt-bootstrap-carousel'), // Title
262
+ array( $this, 'customprev_callback' ), // Callback
263
+ 'cpt-bootstrap-carousel', // Page
264
+ 'cptbc_settings_options' // Section
265
+ );
266
+
267
+ add_settings_field(
268
+ 'customnext', // ID
269
+ __('Custom next button class', 'cpt-bootstrap-carousel'), // Title
270
+ array( $this, 'customnext_callback' ), // Callback
271
+ 'cpt-bootstrap-carousel', // Page
272
+ 'cptbc_settings_options' // Section
273
+ );
274
 
275
+ add_settings_field(
276
+ 'orderby', // ID
277
+ __('Order Slides By', 'cpt-bootstrap-carousel'), // Title
278
+ array( $this, 'orderby_callback' ), // Callback
279
+ 'cpt-bootstrap-carousel', // Page
280
+ 'cptbc_settings_options' // Section
281
+ );
282
 
283
+ add_settings_field(
284
+ 'order', // ID
285
+ __('Ordering Direction', 'cpt-bootstrap-carousel'), // Title
286
+ array( $this, 'order_callback' ), // Callback
287
+ 'cpt-bootstrap-carousel', // Page
288
+ 'cptbc_settings_options' // Section
289
+ );
290
 
291
+ add_settings_field(
292
+ 'category', // ID
293
+ __('Restrict to Category', 'cpt-bootstrap-carousel'), // Title
294
+ array( $this, 'category_callback' ), // Callback
295
+ 'cpt-bootstrap-carousel', // Page
296
+ 'cptbc_settings_options' // Section
297
+ );
298
+
299
  }
300
+
301
  // Sanitize each setting field as needed - @param array $input Contains all settings fields as array keys
302
  public function sanitize( $input ) {
303
+ $new_input = array();
304
  foreach($input as $key => $var){
305
  if($key == 'twbs' || $key == 'interval'){
306
  $new_input[$key] = absint( $input[$key] );
311
  $new_input[$key] = sanitize_text_field( $input[$key] );
312
  }
313
  }
314
+ return $new_input;
315
  }
316
+
317
  // Print the Section text
318
  public function cptbc_settings_options_header() {
319
+ // nothing to say here.x
320
  }
321
+
322
  public function twbs_callback() {
323
  if(isset( $this->options['twbs'] ) && $this->options['twbs'] == '3'){
324
  $cptbc_twbs3 = ' selected="selected"';
334
  }
335
 
336
  public function interval_callback() {
337
+ printf('<input type="text" id="interval" name="cptbc_settings[interval]" value="%s" size="6" />',
338
+ isset( $this->options['interval'] ) ? esc_attr( $this->options['interval']) : '');
339
  }
340
 
341
  public function showcaption_callback() {
356
  if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'false'){
357
  $cptbc_showcontrols_t = '';
358
  $cptbc_showcontrols_f = ' selected="selected"';
359
+ $cptbc_showcontrols_c = '';
360
+ } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'true'){
361
  $cptbc_showcontrols_t = ' selected="selected"';
362
  $cptbc_showcontrols_f = '';
363
+ $cptbc_showcontrols_c = '';
364
+ } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'custom'){
365
+ $cptbc_showcontrols_t = '';
366
+ $cptbc_showcontrols_f = '';
367
+ $cptbc_showcontrols_c = ' selected="selected"';
368
  }
369
  print '<select id="showcontrols" name="cptbc_settings[showcontrols]">
370
  <option value="true"'.$cptbc_showcontrols_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
371
  <option value="false"'.$cptbc_showcontrols_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
372
+ <option value="custom"'.$cptbc_showcontrols_c.'>'.__('Custom', 'cpt-bootstrap-carousel').'</option>
373
  </select>';
374
  }
375
 
376
+ public function customnext_callback() {
377
+ printf('<input type="text" id="customnext" name="cptbc_settings[customnext]" value="%s" size="6" />',
378
+ isset( $this->options['customnext'] ) ? esc_attr( $this->options['customnext']) : '');
379
+ }
380
+
381
+ public function customprev_callback() {
382
+ printf('<input type="text" id="customprev" name="cptbc_settings[customprev]" value="%s" size="6" />',
383
+ isset( $this->options['customprev'] ) ? esc_attr( $this->options['customprev']) : '');
384
+ }
385
+
386
  public function orderby_callback() {
387
  $orderby_options = array (
388
  'menu_order' => __('Menu order, as set in Carousel overview page', 'cpt-bootstrap-carousel'),
389
  'date' => __('Date slide was published', 'cpt-bootstrap-carousel'),
390
  'rand' => __('Random ordering', 'cpt-bootstrap-carousel'),
391
+ 'title' => __('Slide title', 'cpt-bootstrap-carousel')
392
  );
393
  print '<select id="orderby" name="cptbc_settings[orderby]">';
394
  foreach($orderby_options as $val => $option){
420
  print '<select id="orderby" name="cptbc_settings[category]">
421
  <option value="">'.__('All Categories', 'cpt-bootstrap-carousel').'</option>';
422
  foreach($cats as $cat){
423
+ print '<option value="'.$cat->name.'"';
424
+ if(isset( $this->options['category'] ) && $this->options['category'] == $cat->name){
425
  print ' selected="selected"';
426
  }
427
  print ">".$cat->name."</option>";
428
  }
429
  print '</select>';
430
  }
431
+
432
 
433
  }
434
 
435
  if( is_admin() ){
436
+ $cptbc_settings_page = new cptbc_settings_page();
437
  }
438
 
439
  // Add settings link on plugin page
447
 
448
 
449
 
450
+ ///////////////////
451
+ // CONTEXTUAL HELP
452
+ ///////////////////
453
+ function cptbc_contextual_help_tab() {
454
+ $help = '<p>You can add a <strong>CPT Bootstrap Carousel</strong> image carousel using the shortcode <code>[image-carousel]</code>.</p>
455
+ <p>You can read the full plugin documentation on the <a href="http://wordpress.org/plugins/cpt-bootstrap-carousel/" target="_blank">WordPress plugins page</a></p>
456
+ <p>Most settings can be changed in the <a href="">settings page</a> but you can also specify options for individual carousels
457
+ using the following settings:</p>
458
+
459
+ <ul>
460
+ <li><code>interval</code> <em>(default 5000)</em>
461
+ <ul>
462
+ <li>Length of time for the caption to pause on each image. Time in milliseconds.</li>
463
+ </ul></li>
464
+
465
+ <li><code>showcaption</code> <em>(default true)</em>
466
+ <ul>
467
+ <li>Whether to display the text caption on each image or not. true or false.</li>
468
+ </ul></li>
469
+
470
+ <li><code>showcontrols</code> <em>(default true)</em>
471
+ <ul>
472
+ <li>Whether to display the control arrows or not. true or false.</li>
473
+ </ul></li>
474
+
475
+ <li><code>orderby</code> and <code>order</code> <em>(default menu_order ASC)</em>
476
+ <ul>
477
+ <li>What order to display the posts in. Uses WP_Query terms.</li>
478
+ </ul></li>
479
+
480
+ <li><code>category</code> <em>(default all)</em>
481
+ <ul>
482
+ <li>Filter carousel items by a comma separated list of carousel category slugs.</li>
483
+ </ul></li>
484
+
485
+ <li><code>id</code> <em>(default all)</em>
486
+ <ul>
487
+ <li>Specify the ID of a specific carousel post to display only one image.</li>';
488
+ if(isset($_GET['post'])){
489
+ $help .= '<li>The ID of the post you\'re currently editing is <strong>'.$_GET['post'].'</strong></li>';
490
+ }
491
+ $help .= '
492
+ </ul></li>
493
+
494
+ <li><code>twbs</code> <em>(default 2)</em>
495
+ <ul>
496
+ <li>Output markup for Twitter Bootstrap Version 2 or 3.</li>
497
+ </ul></li>
498
+ </ul>
499
+ ';
500
+ $screen = get_current_screen();
501
+ $screen->add_help_tab( array(
502
+ 'id' => 'cptbc_contextual_help',
503
+ 'title' => __('Carousel'),
504
+ 'content' => __($help)
505
+ ) );
506
+ }
507
+ add_action('load-post.php', 'cptbc_contextual_help_tab');
508
+ add_action('load-post-new.php', 'cptbc_contextual_help_tab');
509
 
510
 
511
 
515
 
516
  // Shortcode
517
  function cptbc_shortcode($atts, $content = null) {
518
+ // Set default shortcode attributes
519
  $options = get_option( 'cptbc_settings' );
520
  if(!$options){
521
  cptbc_set_options ();
533
  // Display carousel
534
  function cptbc_frontend($atts){
535
  $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
536
+ $args = array(
537
+ 'post_type' => 'cptbc',
538
+ 'posts_per_page' => '-1',
539
+ 'orderby' => $atts['orderby'],
540
+ 'order' => $atts['order']
541
+ );
542
  if($atts['category'] != ''){
543
  $args['carousel_category'] = $atts['category'];
544
  }
562
  if(count($images) > 0){
563
  ob_start();
564
  ?>
565
+ <div id="cptbc_<?php echo $id; ?>" class="carousel slide" data-ride="carousel" data-interval="<?php echo $atts['interval']; ?>">
566
  <ol class="carousel-indicators">
567
  <?php foreach ($images as $key => $image) { ?>
568
+ <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
569
  <?php } ?>
570
  </ol>
571
  <div class="carousel-inner">
598
  <?php } else if($atts['showcontrols'] === 'true'){ ?>
599
  <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
600
  <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
601
+ <?php } else if($atts['showcontrols'] === 'custom' && $atts['twbs'] == '3' && $atts['customprev'] != '' && $atts['customnext'] != ''){ ?>
602
+ <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="<?php echo $atts['customprev'] ?> icon-prev"></span></a>
603
+ <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="<?php echo $atts['customnext'] ?> icon-next"></span></a>
604
  <?php } ?>
605
  </div>
606
  <script type="text/javascript">
615
  ob_end_clean();
616
 
617
  // Restore original Post Data
618
+ wp_reset_postdata();
619
 
620
  return $output;
621
  }
622
 
623
+ ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://www.tallphil.co.uk/bootstrap-carousel/
4
  Tags: carousel, slider, image, bootstrap
5
  Requires at least: 3.0.1
6
  Tested up to: 3.8.1
7
- Stable tag: 1.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -147,6 +147,12 @@ You need to make sure that each image is the same height. You can do this by set
147
 
148
  == Changelog ==
149
 
 
 
 
 
 
 
150
  = 1.6 =
151
  * Made the title and caption linked if we have a URL
152
  * Stopped the caption div from displaying if there is not caption
4
  Tags: carousel, slider, image, bootstrap
5
  Requires at least: 3.0.1
6
  Tested up to: 3.8.1
7
+ Stable tag: 1.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
147
 
148
  == Changelog ==
149
 
150
+ = 1.7 =
151
+ * Added custom classes for next/prev buttons - written by @reddo
152
+ * Added admin column for categories
153
+ * Made the category dropdown in the settings work (bugfix)
154
+ * Addeed contextual help on post and page editing screens
155
+
156
  = 1.6 =
157
  * Made the title and caption linked if we have a URL
158
  * Stopped the caption div from displaying if there is not caption