CPT Bootstrap Carousel - Version 1.9

Version Description

  • Prevented the help tab from displaying on pages other than Carousel Items
  • Made the output buffer cleaning only happen if we have images (thanks @ChrisLomax)
  • Tidied up some warnings generated when WP_DEBUG was true
  • New settings option to rely on data-attributes only, without any Javascript chunks
  • Split the plugin into multiple files to make code easier to maintain
  • Re-wrote the settings page to make things clearer
  • Added new feature to have a link button instead of clickable slider image
  • Bugfix: Carousel items with links using background images now work.
Download this release

Release Info

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

Code changes from version 1.8.1 to 1.9

Files changed (5) hide show
  1. cpt-bootstrap-carousel.php +5 -685
  2. cptbc-admin.php +155 -0
  3. cptbc-frontend.php +192 -0
  4. cptbc-settings.php +577 -0
  5. readme.txt +20 -3
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.8.1
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  Text Domain: cpt-bootstrap-carousel
@@ -76,688 +76,8 @@ function cptbc_addFeaturedImageSupport() {
76
  }
77
  add_action( 'after_setup_theme', 'cptbc_addFeaturedImageSupport');
78
 
79
- // Add column in admin list view to show featured image
80
- // http://wp.tutsplus.com/tutorials/creative-coding/add-a-custom-column-in-posts-and-custom-post-types-admin-screen/
81
- function cptbc_get_featured_image($post_ID) {
82
- $post_thumbnail_id = get_post_thumbnail_id($post_ID);
83
- if ($post_thumbnail_id) {
84
- $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
85
- return $post_thumbnail_img[0];
86
- }
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");
131
- }
132
- add_action("add_meta_boxes", "cptbc_admin_init_custpost");
133
- function cptbc_mb_save_details(){
134
- global $post;
135
- if (isset($_POST["cptbc_image_url"])) {
136
- $openblank = 0;
137
- if(isset($_POST["cptbc_image_url_openblank"]) && $_POST["cptbc_image_url_openblank"] == '1'){
138
- $openblank = 1;
139
- }
140
- update_post_meta($post->ID, "cptbc_image_url", esc_url($_POST["cptbc_image_url"]));
141
- update_post_meta($post->ID, "cptbc_image_url_openblank", $openblank);
142
- }
143
- }
144
- add_action('save_post', 'cptbc_mb_save_details');
145
-
146
- // Set up settings defaults
147
- register_activation_hook(__FILE__, 'cptbc_set_options');
148
- function cptbc_set_options (){
149
- $defaults = array(
150
- 'interval' => '5000',
151
- 'showcaption' => 'true',
152
- 'showcontrols' => 'true',
153
- 'customprev' => '',
154
- 'customnext' => '',
155
- 'orderby' => 'menu_order',
156
- 'order' => 'ASC',
157
- 'category' => '',
158
- 'before_title' => '<h4>',
159
- 'after_title' => '</h4>',
160
- 'before_caption' => '<p>',
161
- 'after_caption' => '</p>',
162
- 'image_size' => 'full',
163
- 'id' => '',
164
- 'twbs' => '3',
165
- 'use_background_images' => '0',
166
- 'background_images_height' => '500'
167
- );
168
- add_option('cptbc_settings', $defaults);
169
- }
170
- // Clean up on uninstall
171
- register_activation_hook(__FILE__, 'cptbc_deactivate');
172
- function cptbc_deactivate(){
173
- delete_option('cptbc_settings');
174
- }
175
-
176
-
177
- ///////////////////
178
- // SETTINGS PAGE
179
- ///////////////////
180
- class cptbc_settings_page {
181
- // Holds the values to be used in the fields callbacks
182
- private $options;
183
-
184
- // Start up
185
- public function __construct() {
186
- add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
187
- add_action( 'admin_init', array( $this, 'page_init' ) );
188
- }
189
-
190
- // Add settings page
191
- public function add_plugin_page() {
192
- 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'));
193
- }
194
-
195
- // Options page callback
196
- public function create_admin_page() {
197
- // Set class property
198
- $this->options = get_option( 'cptbc_settings' );
199
- if(!$this->options){
200
- cptbc_set_options ();
201
- $this->options = get_option( 'cptbc_settings' );
202
- }
203
- ?>
204
- <div class="wrap">
205
- <h2>CPT Bootstrap Carousel <?php _e('Settings', 'cpt-bootstrap-carousel'); ?></h2>
206
- <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>
207
-
208
- <form method="post" action="options.php">
209
- <?php
210
- settings_fields( 'cptbc_settings' );
211
- do_settings_sections( 'cpt-bootstrap-carousel' );
212
- submit_button();
213
- ?>
214
- </form>
215
- </div>
216
- <?php
217
- }
218
-
219
- // Register and add settings
220
- public function page_init() {
221
- register_setting(
222
- 'cptbc_settings', // Option group
223
- 'cptbc_settings', // Option name
224
- array( $this, 'sanitize' ) // Sanitize
225
- );
226
-
227
- add_settings_section(
228
- 'cptbc_settings_options', // ID
229
- '', // Title - nothing to say here.
230
- array( $this, 'cptbc_settings_options_header' ), // Callback
231
- 'cpt-bootstrap-carousel' // Page
232
- );
233
-
234
- add_settings_field(
235
- 'twbs', // ID
236
- __('Twitter Bootstrap Version', 'cpt-bootstrap-carousel'), // Title
237
- array( $this, 'twbs_callback' ), // Callback
238
- 'cpt-bootstrap-carousel', // Page
239
- 'cptbc_settings_options' // Section
240
- );
241
-
242
- add_settings_field(
243
- 'interval', // ID
244
- __('Slide Interval (milliseconds)', 'cpt-bootstrap-carousel'), // Title
245
- array( $this, 'interval_callback' ), // Callback
246
- 'cpt-bootstrap-carousel', // Page
247
- 'cptbc_settings_options' // Section
248
- );
249
-
250
- add_settings_field(
251
- 'showcaption', // ID
252
- __('Show Slide Captions?', 'cpt-bootstrap-carousel'), // Title
253
- array( $this, 'showcaption_callback' ), // Callback
254
- 'cpt-bootstrap-carousel', // Page
255
- 'cptbc_settings_options' // Section
256
- );
257
-
258
- add_settings_field(
259
- 'showcontrols', // ID
260
- __('Show Slide Controls?', 'cpt-bootstrap-carousel'), // Title
261
- array( $this, 'showcontrols_callback' ), // Callback
262
- 'cpt-bootstrap-carousel', // Page
263
- 'cptbc_settings_options' // Section
264
- );
265
-
266
- add_settings_field(
267
- 'customprev', // ID
268
- __('Custom prev button class', 'cpt-bootstrap-carousel'), // Title
269
- array( $this, 'customprev_callback' ), // Callback
270
- 'cpt-bootstrap-carousel', // Page
271
- 'cptbc_settings_options' // Section
272
- );
273
-
274
- add_settings_field(
275
- 'customnext', // ID
276
- __('Custom next button class', 'cpt-bootstrap-carousel'), // Title
277
- array( $this, 'customnext_callback' ), // Callback
278
- 'cpt-bootstrap-carousel', // Page
279
- 'cptbc_settings_options' // Section
280
- );
281
-
282
- add_settings_field(
283
- 'orderby', // ID
284
- __('Order Slides By', 'cpt-bootstrap-carousel'), // Title
285
- array( $this, 'orderby_callback' ), // Callback
286
- 'cpt-bootstrap-carousel', // Page
287
- 'cptbc_settings_options' // Section
288
- );
289
-
290
- add_settings_field(
291
- 'order', // ID
292
- __('Ordering Direction', 'cpt-bootstrap-carousel'), // Title
293
- array( $this, 'order_callback' ), // Callback
294
- 'cpt-bootstrap-carousel', // Page
295
- 'cptbc_settings_options' // Section
296
- );
297
-
298
- add_settings_field(
299
- 'category', // ID
300
- __('Restrict to Category', 'cpt-bootstrap-carousel'), // Title
301
- array( $this, 'category_callback' ), // Callback
302
- 'cpt-bootstrap-carousel', // Page
303
- 'cptbc_settings_options' // Section
304
- );
305
-
306
- add_settings_field(
307
- 'before_title', // ID
308
- __('HTML before title', 'cpt-bootstrap-carousel'), // Title
309
- array( $this, 'before_title_callback' ), // Callback
310
- 'cpt-bootstrap-carousel', // Page
311
- 'cptbc_settings_options' // Section
312
- );
313
-
314
- add_settings_field(
315
- 'after_title', // ID
316
- __('HTML after title', 'cpt-bootstrap-carousel'), // Title
317
- array( $this, 'after_title_callback' ), // Callback
318
- 'cpt-bootstrap-carousel', // Page
319
- 'cptbc_settings_options' // Section
320
- );
321
-
322
- add_settings_field(
323
- 'before_caption', // ID
324
- __('HTML before caption text', 'cpt-bootstrap-carousel'), // Title
325
- array( $this, 'before_caption_callback' ), // Callback
326
- 'cpt-bootstrap-carousel', // Page
327
- 'cptbc_settings_options' // Section
328
- );
329
-
330
- add_settings_field(
331
- 'after_caption', // ID
332
- __('HTML after caption text', 'cpt-bootstrap-carousel'), // Title
333
- array( $this, 'after_caption_callback' ), // Callback
334
- 'cpt-bootstrap-carousel', // Page
335
- 'cptbc_settings_options' // Section
336
- );
337
-
338
- add_settings_field(
339
- 'image_size', // ID
340
- __('Image Size', 'cpt-bootstrap-carousel'), // Title
341
- array( $this, 'image_size_callback' ), // Callback
342
- 'cpt-bootstrap-carousel', // Page
343
- 'cptbc_settings_options' // Section
344
- );
345
-
346
- add_settings_field(
347
- 'use_background_images', // ID
348
- __('Use background images?', 'cpt-bootstrap-carousel'), // Title
349
- array( $this, 'use_background_images_callback' ), // Callback
350
- 'cpt-bootstrap-carousel', // Page
351
- 'cptbc_settings_options' // Section
352
- );
353
-
354
- add_settings_field(
355
- 'background_images_height', // ID
356
- __('Height if using bkgrnd images (px)', 'cpt-bootstrap-carousel'), // Title
357
- array( $this, 'background_images_height_callback' ), // Callback
358
- 'cpt-bootstrap-carousel', // Page
359
- 'cptbc_settings_options' // Section
360
- );
361
-
362
- }
363
-
364
- // Sanitize each setting field as needed - @param array $input Contains all settings fields as array keys
365
- public function sanitize( $input ) {
366
- $new_input = array();
367
- foreach($input as $key => $var){
368
- if($key == 'twbs' || $key == 'interval' || $key == 'background_images_height'){
369
- $new_input[$key] = absint( $input[$key] );
370
- if($key == 'interval' && $new_input[$key] == 0){
371
- $new_input[$key] = 5000;
372
- }
373
- } else if ($key == 'before_title' || $key == 'after_title' || $key == 'before_caption' || $key == 'after_caption'){
374
- $new_input[$key] = $input[$key]; // Don't sanitise these, meant to be html!
375
- } else {
376
- $new_input[$key] = sanitize_text_field( $input[$key] );
377
- }
378
- }
379
- return $new_input;
380
- }
381
-
382
- // Print the Section text
383
- public function cptbc_settings_options_header() {
384
- // nothing to say here.
385
- }
386
-
387
- public function twbs_callback() {
388
- if(isset( $this->options['twbs'] ) && $this->options['twbs'] == '3'){
389
- $cptbc_twbs3 = ' selected="selected"';
390
- $cptbc_twbs2 = '';
391
- } else {
392
- $cptbc_twbs3 = '';
393
- $cptbc_twbs2 = ' selected="selected"';
394
- }
395
- print '<select id="twbs" name="cptbc_settings[twbs]">
396
- <option value="2"'.$cptbc_twbs2.'>2.x</option>
397
- <option value="3"'.$cptbc_twbs3.'>3.x</option>
398
- </select>';
399
- }
400
-
401
- public function interval_callback() {
402
- printf('<input type="text" id="interval" name="cptbc_settings[interval]" value="%s" size="6" />',
403
- isset( $this->options['interval'] ) ? esc_attr( $this->options['interval']) : '');
404
- }
405
-
406
- public function showcaption_callback() {
407
- if(isset( $this->options['showcaption'] ) && $this->options['showcaption'] == 'false'){
408
- $cptbc_showcaption_t = '';
409
- $cptbc_showcaption_f = ' selected="selected"';
410
- } else {
411
- $cptbc_showcaption_t = ' selected="selected"';
412
- $cptbc_showcaption_f = '';
413
- }
414
- print '<select id="showcaption" name="cptbc_settings[showcaption]">
415
- <option value="true"'.$cptbc_showcaption_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
416
- <option value="false"'.$cptbc_showcaption_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
417
- </select>';
418
- }
419
-
420
- public function showcontrols_callback() {
421
- if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'false'){
422
- $cptbc_showcontrols_t = '';
423
- $cptbc_showcontrols_f = ' selected="selected"';
424
- $cptbc_showcontrols_c = '';
425
- } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'true'){
426
- $cptbc_showcontrols_t = ' selected="selected"';
427
- $cptbc_showcontrols_f = '';
428
- $cptbc_showcontrols_c = '';
429
- } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'custom'){
430
- $cptbc_showcontrols_t = '';
431
- $cptbc_showcontrols_f = '';
432
- $cptbc_showcontrols_c = ' selected="selected"';
433
- }
434
- print '<select id="showcontrols" name="cptbc_settings[showcontrols]">
435
- <option value="true"'.$cptbc_showcontrols_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
436
- <option value="false"'.$cptbc_showcontrols_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
437
- <option value="custom"'.$cptbc_showcontrols_c.'>'.__('Custom', 'cpt-bootstrap-carousel').'</option>
438
- </select>';
439
- }
440
-
441
- public function customnext_callback() {
442
- printf('<input type="text" id="customnext" name="cptbc_settings[customnext]" value="%s" size="6" />',
443
- isset( $this->options['customnext'] ) ? esc_attr( $this->options['customnext']) : '');
444
- }
445
-
446
- public function customprev_callback() {
447
- printf('<input type="text" id="customprev" name="cptbc_settings[customprev]" value="%s" size="6" />',
448
- isset( $this->options['customprev'] ) ? esc_attr( $this->options['customprev']) : '');
449
- }
450
-
451
- public function orderby_callback() {
452
- $orderby_options = array (
453
- 'menu_order' => __('Menu order, as set in Carousel overview page', 'cpt-bootstrap-carousel'),
454
- 'date' => __('Date slide was published', 'cpt-bootstrap-carousel'),
455
- 'rand' => __('Random ordering', 'cpt-bootstrap-carousel'),
456
- 'title' => __('Slide title', 'cpt-bootstrap-carousel')
457
- );
458
- print '<select id="orderby" name="cptbc_settings[orderby]">';
459
- foreach($orderby_options as $val => $option){
460
- print '<option value="'.$val.'"';
461
- if(isset( $this->options['orderby'] ) && $this->options['orderby'] == $val){
462
- print ' selected="selected"';
463
- }
464
- print ">$option</option>";
465
- }
466
- print '</select>';
467
- }
468
-
469
- public function order_callback() {
470
- if(isset( $this->options['order'] ) && $this->options['order'] == 'DESC'){
471
- $cptbc_showcontrols_a = '';
472
- $cptbc_showcontrols_d = ' selected="selected"';
473
- } else {
474
- $cptbc_showcontrols_a = ' selected="selected"';
475
- $cptbc_showcontrols_d = '';
476
- }
477
- print '<select id="order" name="cptbc_settings[order]">
478
- <option value="ASC"'.$cptbc_showcontrols_a.'>'.__('Ascending', 'cpt-bootstrap-carousel').'</option>
479
- <option value="DESC"'.$cptbc_showcontrols_d.'>'.__('Decending', 'cpt-bootstrap-carousel').'</option>
480
- </select>';
481
- }
482
-
483
- public function category_callback() {
484
- $cats = get_terms('carousel_category');
485
- print '<select id="orderby" name="cptbc_settings[category]">
486
- <option value="">'.__('All Categories', 'cpt-bootstrap-carousel').'</option>';
487
- foreach($cats as $cat){
488
- print '<option value="'.$cat->name.'"';
489
- if(isset( $this->options['category'] ) && $this->options['category'] == $cat->name){
490
- print ' selected="selected"';
491
- }
492
- print ">".$cat->name."</option>";
493
- }
494
- print '</select>';
495
- }
496
-
497
- public function before_title_callback() {
498
- printf('<input type="text" id="before_title" name="cptbc_settings[before_title]" value="%s" size="6" />',
499
- isset( $this->options['before_title'] ) ? esc_attr( $this->options['before_title']) : '<h4>');
500
- }
501
-
502
- public function after_title_callback() {
503
- printf('<input type="text" id="after_title" name="cptbc_settings[after_title]" value="%s" size="6" />',
504
- isset( $this->options['after_title'] ) ? esc_attr( $this->options['after_title']) : '</h4>');
505
- }
506
-
507
- public function before_caption_callback() {
508
- printf('<input type="text" id="before_caption" name="cptbc_settings[before_caption]" value="%s" size="6" />',
509
- isset( $this->options['before_caption'] ) ? esc_attr( $this->options['before_caption']) : '<p>');
510
- }
511
-
512
- public function after_caption_callback() {
513
- printf('<input type="text" id="after_caption" name="cptbc_settings[after_caption]" value="%s" size="6" />',
514
- isset( $this->options['after_caption'] ) ? esc_attr( $this->options['after_caption']) : '</p>');
515
- }
516
-
517
- public function image_size_callback() {
518
- $image_sizes = get_intermediate_image_sizes();
519
- print '<select id="image_size" name="cptbc_settings[image_size]">
520
- <option value="full"';
521
- if(isset( $this->options['image_size'] ) && $this->options['image_size'] == $size){
522
- print ' selected="selected"';
523
- }
524
- echo '>Full (default)</option>';
525
- foreach($image_sizes as $size){
526
- print '<option value="'.$size.'"';
527
- if(isset( $this->options['image_size'] ) && $this->options['image_size'] == $size){
528
- print ' selected="selected"';
529
- }
530
- print ">".ucfirst($size)."</option>";
531
- }
532
- print '</select>';
533
- }
534
-
535
- public function use_background_images_callback() {
536
- print '<select id="use_background_images" name="cptbc_settings[use_background_images]">';
537
- print '<option value="0"';
538
- if(isset( $this->options['use_background_images'] ) && $this->options['use_background_images'] == 0){
539
- print ' selected="selected"';
540
- }
541
- echo '>No (default)</option>';
542
- print '<option value="1"';
543
- if(isset( $this->options['use_background_images'] ) && $this->options['use_background_images'] == 1){
544
- print ' selected="selected"';
545
- }
546
- echo '>Yes</option>';
547
- print '</select>';
548
- }
549
-
550
- public function background_images_height_callback() {
551
- printf('<input type="text" id="background_images_height" name="cptbc_settings[background_images_height]" value="%s" size="6" />',
552
- isset( $this->options['background_images_height'] ) ? esc_attr( $this->options['background_images_height']) : '500px');
553
- }
554
-
555
-
556
-
557
- }
558
-
559
- if( is_admin() ){
560
- $cptbc_settings_page = new cptbc_settings_page();
561
- }
562
-
563
- // Add settings link on plugin page
564
- function cptbc_settings_link ($links) {
565
- $settings_link = '<a href="edit.php?post_type=cptbc&page=cpt-bootstrap-carousel">'.__('Settings', 'cpt-bootstrap-carousel').'</a>';
566
- array_unshift($links, $settings_link);
567
- return $links;
568
- }
569
- $cptbc_plugin = plugin_basename(__FILE__);
570
- add_filter("plugin_action_links_$cptbc_plugin", 'cptbc_settings_link' );
571
-
572
-
573
-
574
- ///////////////////
575
- // CONTEXTUAL HELP
576
- ///////////////////
577
- function cptbc_contextual_help_tab() {
578
- $help = '<p>You can add a <strong>CPT Bootstrap Carousel</strong> image carousel using the shortcode <code>[image-carousel]</code>.</p>
579
- <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>
580
- <p>Most settings can be changed in the <a href="">settings page</a> but you can also specify options for individual carousels
581
- using the following settings:</p>
582
-
583
- <ul>
584
- <li><code>interval</code> <em>(default 5000)</em>
585
- <ul>
586
- <li>Length of time for the caption to pause on each image. Time in milliseconds.</li>
587
- </ul></li>
588
-
589
- <li><code>showcaption</code> <em>(default true)</em>
590
- <ul>
591
- <li>Whether to display the text caption on each image or not. true or false.</li>
592
- </ul></li>
593
-
594
- <li><code>showcontrols</code> <em>(default true)</em>
595
- <ul>
596
- <li>Whether to display the control arrows or not. true or false.</li>
597
- </ul></li>
598
-
599
- <li><code>orderby</code> and <code>order</code> <em>(default menu_order ASC)</em>
600
- <ul>
601
- <li>What order to display the posts in. Uses WP_Query terms.</li>
602
- </ul></li>
603
-
604
- <li><code>category</code> <em>(default all)</em>
605
- <ul>
606
- <li>Filter carousel items by a comma separated list of carousel category slugs.</li>
607
- </ul></li>
608
-
609
- <li><code>image_size</code> <em>(default full)</em>
610
- <ul>
611
- <li>WordPress image size to use, useful for small carousels</li>
612
- </ul></li>
613
-
614
- <li><code>id</code> <em>(default all)</em>
615
- <ul>
616
- <li>Specify the ID of a specific carousel post to display only one image.</li>';
617
- if(isset($_GET['post'])){
618
- $help .= '<li>The ID of the post you\'re currently editing is <strong>'.$_GET['post'].'</strong></li>';
619
- }
620
- $help .= '
621
- </ul></li>
622
-
623
- <li><code>twbs</code> <em>(default 2)</em>
624
- <ul>
625
- <li>Output markup for Twitter Bootstrap Version 2 or 3.</li>
626
- </ul></li>
627
- </ul>
628
- ';
629
- $screen = get_current_screen();
630
- $screen->add_help_tab( array(
631
- 'id' => 'cptbc_contextual_help',
632
- 'title' => __('Carousel'),
633
- 'content' => __($help)
634
- ) );
635
- }
636
- add_action('load-post.php', 'cptbc_contextual_help_tab');
637
- add_action('load-post-new.php', 'cptbc_contextual_help_tab');
638
-
639
-
640
-
641
- ///////////////////
642
- // FRONT END
643
- ///////////////////
644
-
645
- // Shortcode
646
- function cptbc_shortcode($atts, $content = null) {
647
- // Set default shortcode attributes
648
- $options = get_option( 'cptbc_settings' );
649
- if(!$options){
650
- cptbc_set_options ();
651
- $options = get_option( 'cptbc_settings' );
652
- }
653
- $options['id'] = '';
654
-
655
- // Parse incomming $atts into an array and merge it with $defaults
656
- $atts = shortcode_atts($options, $atts);
657
-
658
- return cptbc_frontend($atts);
659
- }
660
- add_shortcode('image-carousel', 'cptbc_shortcode');
661
-
662
- // Display carousel
663
- function cptbc_frontend($atts){
664
- $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
665
- $args = array(
666
- 'post_type' => 'cptbc',
667
- 'posts_per_page' => '-1',
668
- 'orderby' => $atts['orderby'],
669
- 'order' => $atts['order']
670
- );
671
- if($atts['category'] != ''){
672
- $args['carousel_category'] = $atts['category'];
673
- }
674
- if(!isset($atts['before_title'])) $atts['before_title'] = '<h4>';
675
- if(!isset($atts['after_title'])) $atts['after_title'] = '</h4>';
676
- if(!isset($atts['before_caption'])) $atts['before_caption'] = '<p>';
677
- if(!isset($atts['after_caption'])) $atts['after_caption'] = '</p>';
678
- if($atts['id'] != ''){
679
- $args['p'] = $atts['id'];
680
- }
681
-
682
- $loop = new WP_Query( $args );
683
- $images = array();
684
- while ( $loop->have_posts() ) {
685
- $loop->the_post();
686
- if ( '' != get_the_post_thumbnail(get_the_ID(), $atts['image_size']) ) {
687
- $post_id = get_the_ID();
688
- $title = get_the_title();
689
- $content = get_the_excerpt();
690
- $image = get_the_post_thumbnail( get_the_ID(), $atts['image_size'] );
691
- $image_src = wp_get_attachment_image_src(get_post_thumbnail_id(), $atts['image_size']);
692
- $image_src = $image_src[0];
693
- $url = get_post_meta(get_the_ID(), 'cptbc_image_url');
694
- $url_openblank = get_post_meta(get_the_ID(), 'cptbc_image_url_openblank');
695
- $images[] = array('post_id' => $post_id, 'title' => $title, 'content' => $content, 'image' => $image, 'img_src' => $image_src, 'url' => esc_url($url[0]), 'url_openblank' => $url_openblank[0] == "1" ? true : false);
696
- }
697
- }
698
- if(count($images) > 0){
699
- ob_start();
700
- ?>
701
- <div id="cptbc_<?php echo $id; ?>" class="carousel slide" data-ride="carousel" data-interval="<?php echo $atts['interval']; ?>">
702
- <?php if( count( $images ) > 1 ){ ?>
703
- <ol class="carousel-indicators">
704
- <?php foreach ($images as $key => $image) { ?>
705
- <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
706
- <?php } ?>
707
- </ol>
708
- <?php } ?>
709
- <div class="carousel-inner">
710
- <?php foreach ($images as $key => $image) {
711
- $linkstart = '';
712
- $linkend = '';
713
- if($image['url']) {
714
- $linkstart = '<a href="'.$image['url'].'"';
715
- if($image['url_openblank']) {
716
- $linkstart .= ' target="_blank"';
717
- }
718
- $linkstart .= '>';
719
- $linkend = '</a>';
720
- }
721
- ?>
722
- <div class="item <?php echo $key == 0 ? 'active' : ''; ?>" id="<?php echo $image['post_id']; ?>" <?php if($atts['use_background_images'] == 1){ echo ' style="height: '.$atts['background_images_height'].'px; background: url(\''.$image['img_src'].'\') no-repeat center center ; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;"'; } ?>>
723
- <?php if($atts['use_background_images'] == 0){ echo $linkstart.$image['image'].$linkend; } ?>
724
- <?php if($atts['showcaption'] === 'true' && strlen($image['title']) > 0 && strlen($image['content']) > 0) { ?>
725
- <div class="carousel-caption">
726
- <?php echo $atts['before_title'].$linkstart.$image['title'].$linkend.$atts['after_title']; ?>
727
- <?php echo $atts['before_caption'].$linkstart.$image['content'].$linkend.$atts['after_caption']; ?>
728
- </div>
729
- <?php } ?>
730
- </div>
731
- <?php } ?>
732
- </div>
733
- <?php if( count( $images ) > 1 ){ ?>
734
- <?php if($atts['showcontrols'] === 'true' && $atts['twbs'] == '3') { ?>
735
- <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
736
- <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
737
- <?php } else if($atts['showcontrols'] === 'true'){ ?>
738
- <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
739
- <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
740
- <?php } else if($atts['showcontrols'] === 'custom' && $atts['twbs'] == '3' && $atts['customprev'] != '' && $atts['customnext'] != ''){ ?>
741
- <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="<?php echo $atts['customprev'] ?> icon-prev"></span></a>
742
- <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="<?php echo $atts['customnext'] ?> icon-next"></span></a>
743
- <?php } ?>
744
- <?php } ?>
745
- </div>
746
- <script type="text/javascript">
747
- jQuery(document).ready(function() {
748
- jQuery('#cptbc_<?php echo $id; ?>').carousel({
749
- interval: <?php echo $atts['interval']; ?>
750
- });
751
- });
752
- </script>
753
- <?php }
754
- $output = ob_get_contents();
755
- ob_end_clean();
756
-
757
- // Restore original Post Data
758
- wp_reset_postdata();
759
-
760
- return $output;
761
- }
762
 
763
- ?>
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.9
7
  Author: Phil Ewels
8
  Author URI: http://phil.ewels.co.uk
9
  Text Domain: cpt-bootstrap-carousel
76
  }
77
  add_action( 'after_setup_theme', 'cptbc_addFeaturedImageSupport');
78
 
79
+ // Load in the pages doing everything else!
80
+ require_once('cptbc-admin.php');
81
+ require_once('cptbc-settings.php');
82
+ require_once('cptbc-frontend.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
 
cptbc-admin.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*****************************************************
3
+ * CPT Bootstrap Carousel
4
+ * http://www.tallphil.co.uk/bootstrap-carousel/
5
+ * ----------------------------------------------------
6
+ * cptbc-admin.php
7
+ * Code to customise the WordPress admin pages
8
+ ******************************************************/
9
+
10
+ ///////////////////
11
+ // ADMIN PAGES
12
+ ///////////////////
13
+
14
+ // Add column in admin list view to show featured image
15
+ // http://wp.tutsplus.com/tutorials/creative-coding/add-a-custom-column-in-posts-and-custom-post-types-admin-screen/
16
+ function cptbc_get_featured_image($post_ID) {
17
+ $post_thumbnail_id = get_post_thumbnail_id($post_ID);
18
+ if ($post_thumbnail_id) {
19
+ $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
20
+ return $post_thumbnail_img[0];
21
+ }
22
+ }
23
+ function cptbc_columns_head($defaults) {
24
+ $defaults['featured_image'] = __('Featured Image', 'cpt-bootstrap-carousel');
25
+ $defaults['category'] = __('Category', 'cpt-bootstrap-carousel');
26
+ return $defaults;
27
+ }
28
+ function cptbc_columns_content($column_name, $post_ID) {
29
+ if ($column_name == 'featured_image') {
30
+ $post_featured_image = cptbc_get_featured_image($post_ID);
31
+ if ($post_featured_image) {
32
+ echo '<a href="'.get_edit_post_link($post_ID).'"><img src="' . $post_featured_image . '" alt="" style="max-width:100%;" /></a>';
33
+ }
34
+ }
35
+ if ($column_name == 'category') {
36
+ $post_categories = get_the_terms($post_ID, 'carousel_category');
37
+ if ($post_categories) {
38
+ $output = '';
39
+ foreach($post_categories as $cat){
40
+ $output .= $cat->name.', ';
41
+ }
42
+ echo trim($output, ', ');
43
+ } else {
44
+ echo 'No categories';
45
+ }
46
+ }
47
+ }
48
+ add_filter('manage_cptbc_posts_columns', 'cptbc_columns_head');
49
+ add_action('manage_cptbc_posts_custom_column', 'cptbc_columns_content', 10, 2);
50
+
51
+ // Extra admin field for image URL
52
+ function cptbc_image_url(){
53
+ global $post;
54
+ $custom = get_post_custom($post->ID);
55
+ $cptbc_image_url = isset($custom['cptbc_image_url']) ? $custom['cptbc_image_url'][0] : '';
56
+ $cptbc_image_url_openblank = isset($custom['cptbc_image_url_openblank']) ? $custom['cptbc_image_url_openblank'][0] : '0';
57
+ $cptbc_image_link_text = isset($custom['cptbc_image_link_text']) ? $custom['cptbc_image_link_text'][0] : '';
58
+ ?>
59
+ <label><?php _e('Image URL', 'cpt-bootstrap-carousel'); ?>:</label>
60
+ <input name="cptbc_image_url" value="<?php echo $cptbc_image_url; ?>" /> <br />
61
+ <small><em><?php _e('(optional - leave blank for no link)', 'cpt-bootstrap-carousel'); ?></em></small><br /><br />
62
+
63
+ <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><br /><br />
64
+
65
+ <label><?php _e('Button Text', 'cpt-bootstrap-carousel'); ?>:</label>
66
+ <input name="cptbc_image_link_text" value="<?php echo $cptbc_image_link_text; ?>" /> <br />
67
+ <small><em><?php _e('(optional - leave blank for default, only shown if using link buttons)', 'cpt-bootstrap-carousel'); ?></em></small>
68
+ <?php
69
+ }
70
+ function cptbc_admin_init_custpost(){
71
+ add_meta_box("cptbc_image_url", "Image Link URL", "cptbc_image_url", "cptbc", "side", "low");
72
+ }
73
+ add_action("add_meta_boxes", "cptbc_admin_init_custpost");
74
+ function cptbc_mb_save_details(){
75
+ global $post;
76
+ if (isset($_POST["cptbc_image_url"])) {
77
+ $openblank = 0;
78
+ if(isset($_POST["cptbc_image_url_openblank"]) && $_POST["cptbc_image_url_openblank"] == '1'){
79
+ $openblank = 1;
80
+ }
81
+ update_post_meta($post->ID, "cptbc_image_url", esc_url($_POST["cptbc_image_url"]));
82
+ update_post_meta($post->ID, "cptbc_image_url_openblank", $openblank);
83
+ update_post_meta($post->ID, "cptbc_image_link_text", sanitize_text_field($_POST["cptbc_image_link_text"]));
84
+ }
85
+ }
86
+ add_action('save_post', 'cptbc_mb_save_details');
87
+
88
+
89
+ ///////////////////
90
+ // CONTEXTUAL HELP
91
+ ///////////////////
92
+ function cptbc_contextual_help_tab() {
93
+ $screen = get_current_screen();
94
+ if( $screen->post_type === 'cptbc'){
95
+ $help = '<p>You can add a <strong>CPT Bootstrap Carousel</strong> image carousel using the shortcode <code>[image-carousel]</code>.</p>
96
+ <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>
97
+ <p>Most settings can be changed in the <a href="">settings page</a> but you can also specify options for individual carousels
98
+ using the following settings:</p>
99
+
100
+ <ul>
101
+ <li><code>interval</code> <em>(default 5000)</em>
102
+ <ul>
103
+ <li>Length of time for the caption to pause on each image. Time in milliseconds.</li>
104
+ </ul></li>
105
+
106
+ <li><code>showcaption</code> <em>(default true)</em>
107
+ <ul>
108
+ <li>Whether to display the text caption on each image or not. true or false.</li>
109
+ </ul></li>
110
+
111
+ <li><code>showcontrols</code> <em>(default true)</em>
112
+ <ul>
113
+ <li>Whether to display the control arrows or not. true or false.</li>
114
+ </ul></li>
115
+
116
+ <li><code>orderby</code> and <code>order</code> <em>(default menu_order ASC)</em>
117
+ <ul>
118
+ <li>What order to display the posts in. Uses WP_Query terms.</li>
119
+ </ul></li>
120
+
121
+ <li><code>category</code> <em>(default all)</em>
122
+ <ul>
123
+ <li>Filter carousel items by a comma separated list of carousel category slugs.</li>
124
+ </ul></li>
125
+
126
+ <li><code>image_size</code> <em>(default full)</em>
127
+ <ul>
128
+ <li>WordPress image size to use, useful for small carousels</li>
129
+ </ul></li>
130
+
131
+ <li><code>id</code> <em>(default all)</em>
132
+ <ul>
133
+ <li>Specify the ID of a specific carousel post to display only one image.</li>';
134
+ if(isset($_GET['post'])){
135
+ $help .= '<li>The ID of the post you\'re currently editing is <strong>'.$_GET['post'].'</strong></li>';
136
+ }
137
+ $help .= '
138
+ </ul></li>
139
+
140
+ <li><code>twbs</code> <em>(default 2)</em>
141
+ <ul>
142
+ <li>Output markup for Twitter Bootstrap Version 2 or 3.</li>
143
+ </ul></li>
144
+ </ul>
145
+ ';
146
+ $screen->add_help_tab( array(
147
+ 'id' => 'cptbc_contextual_help',
148
+ 'title' => __('Carousel'),
149
+ 'content' => __($help)
150
+ ) );
151
+ }
152
+ } // if( $screen->post_type === 'cptbc'){
153
+ add_action('load-post.php', 'cptbc_contextual_help_tab');
154
+ add_action('load-post-new.php', 'cptbc_contextual_help_tab');
155
+
cptbc-frontend.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*****************************************************
3
+ * CPT Bootstrap Carousel
4
+ * http://www.tallphil.co.uk/bootstrap-carousel/
5
+ * ----------------------------------------------------
6
+ * cptbc-frontend.php
7
+ * Code to handle front-end rendering of the carousel
8
+ ******************************************************/
9
+
10
+ ///////////////////
11
+ // FRONT END
12
+ ///////////////////
13
+
14
+ // Shortcode
15
+ function cptbc_shortcode($atts, $content = null) {
16
+ // Set default shortcode attributes
17
+ $options = get_option( 'cptbc_settings' );
18
+ if(!$options){
19
+ cptbc_set_options ();
20
+ $options = get_option( 'cptbc_settings' );
21
+ }
22
+ $options['id'] = '';
23
+
24
+ // Parse incomming $atts into an array and merge it with $defaults
25
+ $atts = shortcode_atts($options, $atts);
26
+
27
+ return cptbc_frontend($atts);
28
+ }
29
+ add_shortcode('image-carousel', 'cptbc_shortcode');
30
+
31
+ // Display carousel
32
+ function cptbc_frontend($atts){
33
+
34
+ // Build the attributes
35
+ $id = rand(0, 999); // use a random ID so that the CSS IDs work with multiple on one page
36
+ $args = array(
37
+ 'post_type' => 'cptbc',
38
+ 'posts_per_page' => '-1',
39
+ 'orderby' => $atts['orderby'],
40
+ 'order' => $atts['order']
41
+ );
42
+ if($atts['category'] != ''){
43
+ $args['carousel_category'] = $atts['category'];
44
+ }
45
+ if(!isset($atts['before_title'])) $atts['before_title'] = '<h4>';
46
+ if(!isset($atts['after_title'])) $atts['after_title'] = '</h4>';
47
+ if(!isset($atts['before_caption'])) $atts['before_caption'] = '<p>';
48
+ if(!isset($atts['after_caption'])) $atts['after_caption'] = '</p>';
49
+ if(!isset($atts['image_size'])) $atts['image_size'] = 'full';
50
+ if(!isset($atts['use_background_images'])) $atts['use_background_images'] = '0';
51
+ if(!isset($atts['use_javascript_animation'])) $atts['use_javascript_animation'] = '1';
52
+ if(!isset($atts['select_background_images_style_size'])) $atts['select_background_images_style_size'] = 'cover';
53
+ if($atts['id'] != ''){
54
+ $args['p'] = $atts['id'];
55
+ }
56
+
57
+ // Collect the carousel content. Needs printing in two loops later (bullets and content)
58
+ $loop = new WP_Query( $args );
59
+ $images = array();
60
+ $output = '';
61
+ while ( $loop->have_posts() ) {
62
+ $loop->the_post();
63
+ if ( '' != get_the_post_thumbnail(get_the_ID(), $atts['image_size']) ) {
64
+ $post_id = get_the_ID();
65
+ $title = get_the_title();
66
+ $content = get_the_excerpt();
67
+ $image = get_the_post_thumbnail( get_the_ID(), $atts['image_size'] );
68
+ $image_src = wp_get_attachment_image_src(get_post_thumbnail_id(), $atts['image_size']);
69
+ $image_src = $image_src[0];
70
+ $url = get_post_meta(get_the_ID(), 'cptbc_image_url', true);
71
+ $url_openblank = get_post_meta(get_the_ID(), 'cptbc_image_url_openblank', true);
72
+ $link_text = get_post_meta(get_the_ID(), 'cptbc_image_link_text', true);
73
+ $images[] = array('post_id' => $post_id, 'title' => $title, 'content' => $content, 'image' => $image, 'img_src' => $image_src, 'url' => esc_url($url), 'url_openblank' => $url_openblank == "1" ? true : false, 'link_text' => $link_text);
74
+ }
75
+ }
76
+
77
+ // Check we actually have something to show
78
+ if(count($images) > 0){
79
+ ob_start();
80
+ ?>
81
+ <div id="cptbc_<?php echo $id; ?>" class="carousel slide" <?php if($atts['use_javascript_animation'] == '0'){ echo ' data-ride="carousel"'; } ?> data-interval="<?php echo $atts['interval']; ?>">
82
+
83
+ <?php // First content - the carousel indicators
84
+ if( count( $images ) > 1 ){ ?>
85
+ <ol class="carousel-indicators">
86
+ <?php foreach ($images as $key => $image) { ?>
87
+ <li data-target="#cptbc_<?php echo $id; ?>" data-slide-to="<?php echo $key; ?>" <?php echo $key == 0 ? 'class="active"' : ''; ?>></li>
88
+ <?php } ?>
89
+ </ol>
90
+ <?php } ?>
91
+
92
+ <div class="carousel-inner">
93
+ <?php
94
+ // Carousel Content
95
+ foreach ($images as $key => $image) {
96
+
97
+ // Build anchor link so it can be reused
98
+ $linkstart = '';
99
+ $linkend = '';
100
+ if($image['url'] && $atts['link_button'] == 0) {
101
+ $linkstart = '<a href="'.$image['url'].'"';
102
+ if($image['url_openblank']) {
103
+ $linkstart .= ' target="_blank"';
104
+ }
105
+ $linkstart .= '>';
106
+ $linkend = '</a>';
107
+ } ?>
108
+
109
+ <div class="item <?php echo $key == 0 ? 'active' : ''; ?>" id="<?php echo $image['post_id']; ?>" <?php if($atts['use_background_images'] == 1){ echo ' style="height: '.$atts['background_images_height'].'px; background: url(\''.$image['img_src'].'\') no-repeat center center ; -webkit-background-size: ' . $atts['select_background_images_style_size'] . '; -moz-background-size: ' . $atts['select_background_images_style_size'] . '; -o-background-size: ' . $atts['select_background_images_style_size'] . '; background-size: ' . $atts['select_background_images_style_size'] . ';"'; } ?>>
110
+ <?php
111
+ // Regular behaviour - display image with link around it
112
+ if($atts['use_background_images'] == 0){
113
+ echo $linkstart.$image['image'].$linkend;
114
+ // Backgorund images mode - need block level link inside carousel link if we have a linl
115
+ } else if($image['url'] && $atts['link_button'] == 0) {
116
+ echo '<a href="'.$image['url'].'"';
117
+ if($image['url_openblank']) {
118
+ $linkstart .= ' target="_blank"';
119
+ }
120
+ echo ' style="display:block; width:100%; height:100%;">&nbsp;</a>';
121
+ }
122
+ // The Caption div
123
+ if(($atts['showcaption'] === 'true' && strlen($image['title']) > 0 && strlen($image['content']) > 0) || ($image['url'] && $atts['link_button'] == 1)) {
124
+ echo '<div class="carousel-caption">';
125
+ // Title
126
+ if(strlen($image['title']) > 0){
127
+ echo $atts['before_title'].$linkstart.$image['title'].$linkend.$atts['after_title'];
128
+ }
129
+ // Caption
130
+ if(strlen($image['content']) > 0){
131
+ echo $atts['before_caption'].$linkstart.$image['content'].$linkend.$atts['after_caption'];
132
+ }
133
+ // Link Button
134
+ if($image['url'] && $atts['link_button'] == 1){
135
+ if(isset($atts['link_button_before'])) echo $atts['link_button_before'];
136
+ $target = '';
137
+ if($image['url_openblank']) {
138
+ $target = ' target="_blank"';
139
+ }
140
+ echo '<a href="'.$image['url'].'" '.$target.' class="'.$atts['link_button_class'].'">';
141
+ if(isset($image['link_text']) && strlen($image['link_text']) > 0) {
142
+ echo $image['link_text'];
143
+ } else {
144
+ echo $atts['link_button_text'];
145
+ }
146
+ echo '</a>';
147
+ if(isset($atts['link_button_after'])) echo $atts['link_button_after'];
148
+ }
149
+ echo '</div>';
150
+ } ?>
151
+ </div>
152
+ <?php } ?>
153
+ </div>
154
+
155
+ <?php // Previous / Next controls
156
+ if( count( $images ) > 1 ){
157
+ if($atts['showcontrols'] === 'true' && $atts['twbs'] == '3') { ?>
158
+ <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
159
+ <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
160
+ <?php } else if($atts['showcontrols'] === 'true'){ ?>
161
+ <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev">‹</a>
162
+ <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next">›</a>
163
+ <?php } else if($atts['showcontrols'] === 'custom' && $atts['twbs'] == '3' && $atts['customprev'] != '' && $atts['customnext'] != ''){ ?>
164
+ <a class="left carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="prev"><span class="<?php echo $atts['customprev'] ?> icon-prev"></span></a>
165
+ <a class="right carousel-control" href="#cptbc_<?php echo $id; ?>" data-slide="next"><span class="<?php echo $atts['customnext'] ?> icon-next"></span></a>
166
+ <?php }
167
+ } ?>
168
+
169
+ </div>
170
+
171
+ <?php // Javascript animation fallback
172
+ if($atts['use_javascript_animation'] == '1'){ ?>
173
+ <script type="text/javascript">
174
+ jQuery(document).ready(function() {
175
+ jQuery('#cptbc_<?php echo $id; ?>').carousel({
176
+ interval: <?php echo $atts['interval']; ?>
177
+ });
178
+ });
179
+ </script>
180
+ <?php }
181
+
182
+ // Collect the output
183
+ $output = ob_get_contents();
184
+ ob_end_clean();
185
+ }
186
+
187
+ // Restore original Post Data
188
+ wp_reset_postdata();
189
+
190
+ return $output;
191
+ }
192
+
cptbc-settings.php ADDED
@@ -0,0 +1,577 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*****************************************************
3
+ * CPT Bootstrap Carousel
4
+ * http://www.tallphil.co.uk/bootstrap-carousel/
5
+ * ----------------------------------------------------
6
+ * cptbc-settings.php
7
+ * Code to handle the Settings page
8
+ ******************************************************/
9
+
10
+ ///////////////////
11
+ // SETTINGS PAGE
12
+ ///////////////////
13
+
14
+ // Set up settings defaults
15
+ register_activation_hook(__FILE__, 'cptbc_set_options');
16
+ function cptbc_set_options (){
17
+ $defaults = array(
18
+ 'interval' => '5000',
19
+ 'showcaption' => 'true',
20
+ 'showcontrols' => 'true',
21
+ 'customprev' => '',
22
+ 'customnext' => '',
23
+ 'orderby' => 'menu_order',
24
+ 'order' => 'ASC',
25
+ 'category' => '',
26
+ 'before_title' => '<h4>',
27
+ 'after_title' => '</h4>',
28
+ 'before_caption' => '<p>',
29
+ 'after_caption' => '</p>',
30
+ 'image_size' => 'full',
31
+ 'link_button' => '1',
32
+ 'link_button_text' => 'Read more',
33
+ 'link_button_class' => 'btn btn-default pull-right',
34
+ 'link_button_before' => '',
35
+ 'link_button_after' => '',
36
+ 'id' => '',
37
+ 'twbs' => '3',
38
+ 'use_background_images' => '0',
39
+ 'background_images_height' => '500',
40
+ 'background_images_style_size' => 'cover',
41
+ 'use_javascript_animation' => '1',
42
+ );
43
+ add_option('cptbc_settings', $defaults);
44
+ }
45
+ // Clean up on uninstall
46
+ register_activation_hook(__FILE__, 'cptbc_deactivate');
47
+ function cptbc_deactivate(){
48
+ delete_option('cptbc_settings');
49
+ }
50
+
51
+
52
+ // Render the settings page
53
+ class cptbc_settings_page {
54
+ // Holds the values to be used in the fields callbacks
55
+ private $options;
56
+
57
+ // Start up
58
+ public function __construct() {
59
+ add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
60
+ add_action( 'admin_init', array( $this, 'page_init' ) );
61
+ }
62
+
63
+ // Add settings page
64
+ public function add_plugin_page() {
65
+ 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'));
66
+ }
67
+
68
+ // Options page callback
69
+ public function create_admin_page() {
70
+ // Set class property
71
+ $this->options = get_option( 'cptbc_settings' );
72
+ if(!$this->options){
73
+ cptbc_set_options ();
74
+ $this->options = get_option( 'cptbc_settings' );
75
+ }
76
+ ?>
77
+ <div class="wrap">
78
+ <h2>CPT Bootstrap Carousel <?php _e('Settings', 'cpt-bootstrap-carousel'); ?></h2>
79
+ <p><?php printf(__('You can set the default behaviour of your carousels here. Most 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>
80
+
81
+ <form method="post" action="options.php">
82
+ <?php
83
+ settings_fields( 'cptbc_settings' );
84
+ do_settings_sections( 'cpt-bootstrap-carousel' );
85
+ submit_button();
86
+ ?>
87
+ </form>
88
+ </div>
89
+ <?php
90
+ }
91
+
92
+ // Register and add settings
93
+ public function page_init() {
94
+ register_setting(
95
+ 'cptbc_settings', // Option group
96
+ 'cptbc_settings', // Option name
97
+ array( $this, 'sanitize' ) // Sanitize
98
+ );
99
+
100
+ // Sections
101
+ add_settings_section(
102
+ 'cptbc_settings_behaviour', // ID
103
+ __('Carousel Behaviour', 'cpt-bootstrap-carousel'), // Title
104
+ array( $this, 'cptbc_settings_behaviour_header' ), // Callback
105
+ 'cpt-bootstrap-carousel' // Page
106
+ );
107
+ add_settings_section(
108
+ 'cptbc_settings_setup', // ID
109
+ __('Carousel Setup', 'cpt-bootstrap-carousel'), // Title
110
+ array( $this, 'cptbc_settings_setup' ), // Callback
111
+ 'cpt-bootstrap-carousel' // Page
112
+ );
113
+ add_settings_section(
114
+ 'cptbc_settings_link_buttons', // ID
115
+ __('Link Buttons', 'cpt-bootstrap-carousel'), // Title
116
+ array( $this, 'cptbc_settings_link_buttons_header' ), // Callback
117
+ 'cpt-bootstrap-carousel' // Page
118
+ );
119
+ add_settings_section(
120
+ 'cptbc_settings_markup', // ID
121
+ __('Custom Markup', 'cpt-bootstrap-carousel'), // Title
122
+ array( $this, 'cptbc_settings_markup_header' ), // Callback
123
+ 'cpt-bootstrap-carousel' // Page
124
+ );
125
+
126
+ // Behaviour Fields
127
+ add_settings_field(
128
+ 'interval', // ID
129
+ __('Slide Interval (milliseconds)', 'cpt-bootstrap-carousel'), // Title
130
+ array( $this, 'interval_callback' ), // Callback
131
+ 'cpt-bootstrap-carousel', // Page
132
+ 'cptbc_settings_behaviour' // Section
133
+ );
134
+ add_settings_field(
135
+ 'showcaption', // ID
136
+ __('Show Slide Captions?', 'cpt-bootstrap-carousel'), // Title
137
+ array( $this, 'showcaption_callback' ), // Callback
138
+ 'cpt-bootstrap-carousel', // Page
139
+ 'cptbc_settings_behaviour' // Section
140
+ );
141
+ add_settings_field(
142
+ 'showcontrols', // ID
143
+ __('Show Slide Controls?', 'cpt-bootstrap-carousel'), // Title
144
+ array( $this, 'showcontrols_callback' ), // Callback
145
+ 'cpt-bootstrap-carousel', // Page
146
+ 'cptbc_settings_behaviour' // Section
147
+ );
148
+ add_settings_field(
149
+ 'orderby', // ID
150
+ __('Order Slides By', 'cpt-bootstrap-carousel'), // Title
151
+ array( $this, 'orderby_callback' ), // Callback
152
+ 'cpt-bootstrap-carousel', // Page
153
+ 'cptbc_settings_behaviour' // Section
154
+ );
155
+ add_settings_field(
156
+ 'order', // ID
157
+ __('Ordering Direction', 'cpt-bootstrap-carousel'), // Title
158
+ array( $this, 'order_callback' ), // Callback
159
+ 'cpt-bootstrap-carousel', // Page
160
+ 'cptbc_settings_behaviour' // Section
161
+ );
162
+ add_settings_field(
163
+ 'category', // ID
164
+ __('Restrict to Category', 'cpt-bootstrap-carousel'), // Title
165
+ array( $this, 'category_callback' ), // Callback
166
+ 'cpt-bootstrap-carousel', // Page
167
+ 'cptbc_settings_behaviour' // Section
168
+ );
169
+
170
+ // Carousel Setup Section
171
+ add_settings_field(
172
+ 'twbs', // ID
173
+ __('Twitter Bootstrap Version', 'cpt-bootstrap-carousel'), // Title
174
+ array( $this, 'twbs_callback' ), // Callback
175
+ 'cpt-bootstrap-carousel', // Page
176
+ 'cptbc_settings_setup' // Section
177
+ );
178
+ add_settings_field(
179
+ 'image_size', // ID
180
+ __('Image Size', 'cpt-bootstrap-carousel'), // Title
181
+ array( $this, 'image_size_callback' ), // Callback
182
+ 'cpt-bootstrap-carousel', // Page
183
+ 'cptbc_settings_setup' // Section
184
+ );
185
+
186
+ add_settings_field(
187
+ 'use_background_images', // ID
188
+ __('Use background images?', 'cpt-bootstrap-carousel'), // Title
189
+ array( $this, 'use_background_images_callback' ), // Callback
190
+ 'cpt-bootstrap-carousel', // Page
191
+ 'cptbc_settings_setup' // Section
192
+ );
193
+ add_settings_field(
194
+ 'background_images_height', // ID
195
+ __('Height if using bkgrnd images (px)', 'cpt-bootstrap-carousel'), // Title
196
+ array( $this, 'background_images_height_callback' ), // Callback
197
+ 'cpt-bootstrap-carousel', // Page
198
+ 'cptbc_settings_setup' // Section
199
+ );
200
+ add_settings_field(
201
+ 'background_images_style_size', // ID
202
+ __('Background images size style', 'cpt-bootstrap-carousel'), // Title
203
+ array( $this, 'background_images_style_size_callback' ), // Callback
204
+ 'cpt-bootstrap-carousel', // Page
205
+ 'cptbc_settings_setup' // Section
206
+ );
207
+ add_settings_field(
208
+ 'use_javascript_animation', // ID
209
+ __('Use Javascript to animate carousel?', 'cpt-bootstrap-carousel'), // Title
210
+ array( $this, 'use_javascript_animation_callback' ), // Callback
211
+ 'cpt-bootstrap-carousel', // Page
212
+ 'cptbc_settings_setup' // Section
213
+ );
214
+
215
+ // Link buttons
216
+ add_settings_field(
217
+ 'link_button', // ID
218
+ __('Show links as button in caption', 'cpt-bootstrap-carousel'), // Title
219
+ array( $this, 'link_button_callback' ), // Callback
220
+ 'cpt-bootstrap-carousel', // Page
221
+ 'cptbc_settings_link_buttons' // Section
222
+ );
223
+ add_settings_field(
224
+ 'link_button_text', // ID
225
+ __('Default text for link buttons', 'cpt-bootstrap-carousel'), // Title
226
+ array( $this, 'link_button_text_callback' ), // Callback
227
+ 'cpt-bootstrap-carousel', // Page
228
+ 'cptbc_settings_link_buttons' // Section
229
+ );
230
+ add_settings_field(
231
+ 'link_button_class', // ID
232
+ __('Class for link buttons', 'cpt-bootstrap-carousel'), // Title
233
+ array( $this, 'link_button_class_callback' ), // Callback
234
+ 'cpt-bootstrap-carousel', // Page
235
+ 'cptbc_settings_link_buttons' // Section
236
+ );
237
+ add_settings_field(
238
+ 'link_button_before', // ID
239
+ __('HTML before link buttons', 'cpt-bootstrap-carousel'), // Title
240
+ array( $this, 'link_button_before_callback' ), // Callback
241
+ 'cpt-bootstrap-carousel', // Page
242
+ 'cptbc_settings_link_buttons' // Section
243
+ );
244
+ add_settings_field(
245
+ 'link_button_after', // ID
246
+ __('HTML after link buttons', 'cpt-bootstrap-carousel'), // Title
247
+ array( $this, 'link_button_after_callback' ), // Callback
248
+ 'cpt-bootstrap-carousel', // Page
249
+ 'cptbc_settings_link_buttons' // Section
250
+ );
251
+
252
+ // Markup Section
253
+ add_settings_field(
254
+ 'customprev', // ID
255
+ __('Custom prev button class', 'cpt-bootstrap-carousel'), // Title
256
+ array( $this, 'customprev_callback' ), // Callback
257
+ 'cpt-bootstrap-carousel', // Page
258
+ 'cptbc_settings_markup' // Section
259
+ );
260
+ add_settings_field(
261
+ 'customnext', // ID
262
+ __('Custom next button class', 'cpt-bootstrap-carousel'), // Title
263
+ array( $this, 'customnext_callback' ), // Callback
264
+ 'cpt-bootstrap-carousel', // Page
265
+ 'cptbc_settings_markup' // Section
266
+ );
267
+ add_settings_field(
268
+ 'before_title', // ID
269
+ __('HTML before title', 'cpt-bootstrap-carousel'), // Title
270
+ array( $this, 'before_title_callback' ), // Callback
271
+ 'cpt-bootstrap-carousel', // Page
272
+ 'cptbc_settings_markup' // Section
273
+ );
274
+ add_settings_field(
275
+ 'after_title', // ID
276
+ __('HTML after title', 'cpt-bootstrap-carousel'), // Title
277
+ array( $this, 'after_title_callback' ), // Callback
278
+ 'cpt-bootstrap-carousel', // Page
279
+ 'cptbc_settings_markup' // Section
280
+ );
281
+ add_settings_field(
282
+ 'before_caption', // ID
283
+ __('HTML before caption text', 'cpt-bootstrap-carousel'), // Title
284
+ array( $this, 'before_caption_callback' ), // Callback
285
+ 'cpt-bootstrap-carousel', // Page
286
+ 'cptbc_settings_markup' // Section
287
+ );
288
+ add_settings_field(
289
+ 'after_caption', // ID
290
+ __('HTML after caption text', 'cpt-bootstrap-carousel'), // Title
291
+ array( $this, 'after_caption_callback' ), // Callback
292
+ 'cpt-bootstrap-carousel', // Page
293
+ 'cptbc_settings_markup' // Section
294
+ );
295
+
296
+ }
297
+
298
+ // Sanitize each setting field as needed - @param array $input Contains all settings fields as array keys
299
+ public function sanitize( $input ) {
300
+ $new_input = array();
301
+ foreach($input as $key => $var){
302
+ if($key == 'twbs' || $key == 'interval' || $key == 'background_images_height'){
303
+ $new_input[$key] = absint( $input[$key] );
304
+ if($key == 'interval' && $new_input[$key] == 0){
305
+ $new_input[$key] = 5000;
306
+ }
307
+ } else if ($key == 'link_button_before' || $key == 'link_button_after' || $key == 'before_title' || $key == 'after_title' || $key == 'before_caption' || $key == 'after_caption'){
308
+ $new_input[$key] = $input[$key]; // Don't sanitise these, meant to be html!
309
+ } else {
310
+ $new_input[$key] = sanitize_text_field( $input[$key] );
311
+ }
312
+ }
313
+ return $new_input;
314
+ }
315
+
316
+ // Print the Section text
317
+ public function cptbc_settings_behaviour_header() {
318
+ echo '<p>'.__('Basic setup of how each Carousel will function, what controls will show and which images will be displayed.', 'cpt-bootstrap-carousel').'</p>';
319
+ }
320
+ public function cptbc_settings_setup() {
321
+ echo '<p>'.__('Change the setup of the carousel - how it functions.', 'cpt-bootstrap-carousel').'</p>';
322
+ }
323
+ public function cptbc_settings_link_buttons_header() {
324
+ echo '<p>'.__('Options for using a link button instead of linking the image directly.', 'cpt-bootstrap-carousel').'</p>';
325
+ }
326
+ public function cptbc_settings_markup_header() {
327
+ echo '<p>'.__('Customise which CSS classes and HTML tags the Carousel uses.', 'cpt-bootstrap-carousel').'</p>';
328
+ }
329
+
330
+ // Callback functions - print the form inputs
331
+ // Carousel behaviour
332
+ public function interval_callback() {
333
+ printf('<input type="text" id="interval" name="cptbc_settings[interval]" value="%s" size="15" />',
334
+ isset( $this->options['interval'] ) ? esc_attr( $this->options['interval']) : '');
335
+ echo '<p class="description">'.__('How long each image shows for before it slides. Set to 0 to disable animation.', 'cpt-bootstrap-carousel').'</p>';
336
+ }
337
+ public function showcaption_callback() {
338
+ if(isset( $this->options['showcaption'] ) && $this->options['showcaption'] == 'false'){
339
+ $cptbc_showcaption_t = '';
340
+ $cptbc_showcaption_f = ' selected="selected"';
341
+ } else {
342
+ $cptbc_showcaption_t = ' selected="selected"';
343
+ $cptbc_showcaption_f = '';
344
+ }
345
+ print '<select id="showcaption" name="cptbc_settings[showcaption]">
346
+ <option value="true"'.$cptbc_showcaption_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
347
+ <option value="false"'.$cptbc_showcaption_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
348
+ </select>';
349
+ }
350
+ public function showcontrols_callback() {
351
+ if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'false'){
352
+ $cptbc_showcontrols_t = '';
353
+ $cptbc_showcontrols_f = ' selected="selected"';
354
+ $cptbc_showcontrols_c = '';
355
+ } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'true'){
356
+ $cptbc_showcontrols_t = ' selected="selected"';
357
+ $cptbc_showcontrols_f = '';
358
+ $cptbc_showcontrols_c = '';
359
+ } else if(isset( $this->options['showcontrols'] ) && $this->options['showcontrols'] == 'custom'){
360
+ $cptbc_showcontrols_t = '';
361
+ $cptbc_showcontrols_f = '';
362
+ $cptbc_showcontrols_c = ' selected="selected"';
363
+ }
364
+ print '<select id="showcontrols" name="cptbc_settings[showcontrols]">
365
+ <option value="true"'.$cptbc_showcontrols_t.'>'.__('Show', 'cpt-bootstrap-carousel').'</option>
366
+ <option value="false"'.$cptbc_showcontrols_f.'>'.__('Hide', 'cpt-bootstrap-carousel').'</option>
367
+ <option value="custom"'.$cptbc_showcontrols_c.'>'.__('Custom', 'cpt-bootstrap-carousel').'</option>
368
+ </select>';
369
+ }
370
+ public function orderby_callback() {
371
+ $orderby_options = array (
372
+ 'menu_order' => __('Menu order, as set in Carousel overview page', 'cpt-bootstrap-carousel'),
373
+ 'date' => __('Date slide was published', 'cpt-bootstrap-carousel'),
374
+ 'rand' => __('Random ordering', 'cpt-bootstrap-carousel'),
375
+ 'title' => __('Slide title', 'cpt-bootstrap-carousel')
376
+ );
377
+ print '<select id="orderby" name="cptbc_settings[orderby]">';
378
+ foreach($orderby_options as $val => $option){
379
+ print '<option value="'.$val.'"';
380
+ if(isset( $this->options['orderby'] ) && $this->options['orderby'] == $val){
381
+ print ' selected="selected"';
382
+ }
383
+ print ">$option</option>";
384
+ }
385
+ print '</select>';
386
+ }
387
+ public function order_callback() {
388
+ if(isset( $this->options['order'] ) && $this->options['order'] == 'DESC'){
389
+ $cptbc_showcontrols_a = '';
390
+ $cptbc_showcontrols_d = ' selected="selected"';
391
+ } else {
392
+ $cptbc_showcontrols_a = ' selected="selected"';
393
+ $cptbc_showcontrols_d = '';
394
+ }
395
+ print '<select id="order" name="cptbc_settings[order]">
396
+ <option value="ASC"'.$cptbc_showcontrols_a.'>'.__('Ascending', 'cpt-bootstrap-carousel').'</option>
397
+ <option value="DESC"'.$cptbc_showcontrols_d.'>'.__('Decending', 'cpt-bootstrap-carousel').'</option>
398
+ </select>';
399
+ }
400
+ public function category_callback() {
401
+ $cats = get_terms('carousel_category');
402
+ print '<select id="orderby" name="cptbc_settings[category]">
403
+ <option value="">'.__('All Categories', 'cpt-bootstrap-carousel').'</option>';
404
+ foreach($cats as $cat){
405
+ print '<option value="'.$cat->name.'"';
406
+ if(isset( $this->options['category'] ) && $this->options['category'] == $cat->name){
407
+ print ' selected="selected"';
408
+ }
409
+ print ">".$cat->name."</option>";
410
+ }
411
+ print '</select>';
412
+ }
413
+
414
+ // Setup Section
415
+ public function twbs_callback() {
416
+ if(isset( $this->options['twbs'] ) && $this->options['twbs'] == '3'){
417
+ $cptbc_twbs3 = ' selected="selected"';
418
+ $cptbc_twbs2 = '';
419
+ } else {
420
+ $cptbc_twbs3 = '';
421
+ $cptbc_twbs2 = ' selected="selected"';
422
+ }
423
+ print '<select id="twbs" name="cptbc_settings[twbs]">
424
+ <option value="2"'.$cptbc_twbs2.'>2.x</option>
425
+ <option value="3"'.$cptbc_twbs3.'>3.x (Default)</option>
426
+ </select>';
427
+ echo '<p class="description">'.__("Set according to which version of Bootstrap you're using.", 'cpt-bootstrap-carousel').'</p>';
428
+ }
429
+ public function image_size_callback() {
430
+ $image_sizes = get_intermediate_image_sizes();
431
+ print '<select id="image_size" name="cptbc_settings[image_size]">
432
+ <option value="full"';
433
+ if(isset( $this->options['image_size'] ) && $this->options['image_size'] == 'full'){
434
+ print ' selected="selected"';
435
+ }
436
+ echo '>Full (default)</option>';
437
+ foreach($image_sizes as $size){
438
+ print '<option value="'.$size.'"';
439
+ if(isset( $this->options['image_size'] ) && $this->options['image_size'] == $size){
440
+ print ' selected="selected"';
441
+ }
442
+ print ">".ucfirst($size)."</option>";
443
+ }
444
+ print '</select>';
445
+ echo '<p class="description">'.__("If your carousels are small, you can a smaller image size to increase page load times.", 'cpt-bootstrap-carousel').'</p>';
446
+ }
447
+ public function use_background_images_callback() {
448
+ print '<select id="use_background_images" name="cptbc_settings[use_background_images]">';
449
+ print '<option value="0"';
450
+ if(isset( $this->options['use_background_images'] ) && $this->options['use_background_images'] == 0){
451
+ print ' selected="selected"';
452
+ }
453
+ echo '>No (default)</option>';
454
+ print '<option value="1"';
455
+ if(isset( $this->options['use_background_images'] ) && $this->options['use_background_images'] == 1){
456
+ print ' selected="selected"';
457
+ }
458
+ echo '>Yes</option>';
459
+ print '</select>';
460
+ echo '<p class="description">'.__("Experimental feature - Use CSS background images so that pictures auto-fill the space available.", 'cpt-bootstrap-carousel').'</p>';
461
+ }
462
+ public function background_images_height_callback() {
463
+ printf('<input type="text" id="background_images_height" name="cptbc_settings[background_images_height]" value="%s" size="15" />',
464
+ isset( $this->options['background_images_height'] ) ? esc_attr( $this->options['background_images_height']) : '500px');
465
+ echo '<p class="description">'.__("If using background images above, how tall do you want the carousel to be?", 'cpt-bootstrap-carousel').'</p>';
466
+ }
467
+
468
+ public function use_javascript_animation_callback() {
469
+ print '<select id="use_javascript_animation" name="cptbc_settings[use_javascript_animation]">';
470
+ print '<option value="1"';
471
+ if(isset( $this->options['use_javascript_animation'] ) && $this->options['use_javascript_animation'] == 1){
472
+ print ' selected="selected"';
473
+ }
474
+ echo '>Yes (default)</option>';
475
+ print '<option value="0"';
476
+ if(isset( $this->options['use_javascript_animation'] ) && $this->options['use_javascript_animation'] == 0){
477
+ print ' selected="selected"';
478
+ }
479
+ echo '>No</option>';
480
+ print '</select>';
481
+ echo '<p class="description">'.__("The Bootstrap Carousel is designed to work usign data-attributes. Sometimes the animation doesn't work correctly with this, so the default is to include a small portion of Javascript to fire the carousel. You can choose not to include this here.", 'cpt-bootstrap-carousel').'</p>';
482
+ }
483
+ public function background_images_style_size_callback() {
484
+ print '<select id="select_background_images_style_size" name="cptbc_settings[select_background_images_style_size]">';
485
+ print '<option value="cover"';
486
+ if(isset( $this->options['select_background_images_style_size'] ) && $this->options['select_background_images_style_size'] === 'cover'){
487
+ print ' selected="selected"';
488
+ }
489
+ echo '>Cover (default)</option>';
490
+ print '<option value="contain"';
491
+ if(isset( $this->options['select_background_images_style_size'] ) && $this->options['select_background_images_style_size'] === 'contain'){
492
+ print ' selected="selected"';
493
+ }
494
+ echo '>Contain</option>';
495
+ print '<option value="auto"';
496
+ if(isset( $this->options['select_background_images_style_size'] ) && $this->options['select_background_images_style_size'] === 'auto'){
497
+ print ' selected="selected"';
498
+ }
499
+ echo '>Auto</option>';
500
+ print '</select>';
501
+ echo '<p class="description">'.__('If you find that your images are not scaling correctly when using background images try switching the style to \'contain\' or \'auto\'', 'cpt-bootstrap-carousel').'</p>';
502
+ }
503
+
504
+ // Link buttons section
505
+ public function link_button_callback(){
506
+ print '<select id="link_button" name="cptbc_settings[link_button]">';
507
+ print '<option value="1"';
508
+ if(isset( $this->options['link_button'] ) && $this->options['link_button'] == 1){
509
+ print ' selected="selected"';
510
+ }
511
+ echo '>Yes</option>';
512
+ print '<option value="0"';
513
+ if(!isset( $this->options['link_button'] ) || $this->options['link_button'] == 0){
514
+ print ' selected="selected"';
515
+ }
516
+ echo '>No (Default)</option>';
517
+ print '</select>';
518
+ echo '<p class="description">'.__("If a URL is set for a carousel image, this option will create a button in the caption instead of linking the image itself.", 'cpt-bootstrap-carousel').'</p>';
519
+ }
520
+ public function link_button_text_callback() {
521
+ printf('<input type="text" id="link_button_text" name="cptbc_settings[link_button_text]" value="%s" size="20" />',
522
+ isset( $this->options['link_button_text'] ) ? esc_attr( $this->options['link_button_text']) : 'Read more');
523
+ }
524
+ public function link_button_class_callback() {
525
+ printf('<input type="text" id="link_button_class" name="cptbc_settings[link_button_class]" value="%s" size="20" />',
526
+ isset( $this->options['link_button_class'] ) ? esc_attr( $this->options['link_button_class']) : 'btn btn-default pull-right');
527
+ echo '<p class="description">'.__("Bootstrap style buttons must have the class <code>btn</code> and then one of the following: <code>btn-default</code>, <code>btn-primary</code>, <code>btn-success</code>, <code>btn-warning</code>, <code>btn-danger</code> or <code>btn-info</code>. No <code>.</code> prefixes. <code>pull-right</code> to float the button on the right. See the ", 'cpt-bootstrap-carousel').' <a href="http://getbootstrap.com/css/#buttons-options" target="_blank">Bootstrap documentation</a>.</p>';
528
+ }
529
+ public function link_button_before_callback() {
530
+ printf('<input type="text" id="link_button_before" name="cptbc_settings[link_button_before]" value="%s" size="20" />',
531
+ isset( $this->options['link_button_before'] ) ? esc_attr( $this->options['link_button_before']) : '');
532
+ }
533
+ public function link_button_after_callback() {
534
+ printf('<input type="text" id="link_button_after" name="cptbc_settings[link_button_after]" value="%s" size="20" />',
535
+ isset( $this->options['link_button_after'] ) ? esc_attr( $this->options['link_button_after']) : '');
536
+ }
537
+
538
+ // Markup section
539
+ public function before_title_callback() {
540
+ printf('<input type="text" id="before_title" name="cptbc_settings[before_title]" value="%s" size="15" />',
541
+ isset( $this->options['before_title'] ) ? esc_attr( $this->options['before_title']) : '<h4>');
542
+ }
543
+ public function customnext_callback() {
544
+ printf('<input type="text" id="customnext" name="cptbc_settings[customnext]" value="%s" size="15" />',
545
+ isset( $this->options['customnext'] ) ? esc_attr( $this->options['customnext']) : '');
546
+ }
547
+ public function customprev_callback() {
548
+ printf('<input type="text" id="customprev" name="cptbc_settings[customprev]" value="%s" size="15" />',
549
+ isset( $this->options['customprev'] ) ? esc_attr( $this->options['customprev']) : '');
550
+ }
551
+ public function after_title_callback() {
552
+ printf('<input type="text" id="after_title" name="cptbc_settings[after_title]" value="%s" size="15" />',
553
+ isset( $this->options['after_title'] ) ? esc_attr( $this->options['after_title']) : '</h4>');
554
+ }
555
+ public function before_caption_callback() {
556
+ printf('<input type="text" id="before_caption" name="cptbc_settings[before_caption]" value="%s" size="15" />',
557
+ isset( $this->options['before_caption'] ) ? esc_attr( $this->options['before_caption']) : '<p>');
558
+ }
559
+ public function after_caption_callback() {
560
+ printf('<input type="text" id="after_caption" name="cptbc_settings[after_caption]" value="%s" size="15" />',
561
+ isset( $this->options['after_caption'] ) ? esc_attr( $this->options['after_caption']) : '</p>');
562
+ }
563
+
564
+ }
565
+
566
+ if( is_admin() ){
567
+ $cptbc_settings_page = new cptbc_settings_page();
568
+ }
569
+
570
+ // Add settings link on plugin page
571
+ function cptbc_settings_link ($links) {
572
+ $settings_link = '<a href="edit.php?post_type=cptbc&page=cpt-bootstrap-carousel">'.__('Settings', 'cpt-bootstrap-carousel').'</a>';
573
+ array_unshift($links, $settings_link);
574
+ return $links;
575
+ }
576
+ $cptbc_plugin = plugin_basename(__FILE__);
577
+ add_filter("plugin_action_links_$cptbc_plugin", 'cptbc_settings_link' );
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: tallphil
3
  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: 4.0
7
- Stable tag: 1.8.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -64,10 +64,13 @@ As of version 1.5, nearly all of these options can be set in the CPT Bootstrap C
64
 
65
  = Credits =
66
 
67
- This plugin was written by @tallphil with help and suggestions from several others including (but not limited to) @reddo, @joshgerdes, @atnon, @grahamharper, @rchq, @oheijo, @smtk, @cla63 and @cookierebes.
68
 
69
  The Serbo-Croation translation was kindly provided by Borisa Djuraskovic from http://www.webhostinghub.com
70
 
 
 
 
71
 
72
  == Installation ==
73
 
@@ -113,6 +116,10 @@ First of all, install and activate the plugin. Go to 'Carousel' in the WordPress
113
  Absolutely - you just need to use the [do_shortcode](http://codex.wordpress.org/Function_Reference/do_shortcode) WordPress function. For example:
114
  `<?php echo do_shortcode('[image-carousel]'); ?>`
115
 
 
 
 
 
116
  = Can I change the order that the images display in? =
117
 
118
  You can specify the order that the carousel displays images by changing the setting in the Settings page, or by using the `orderby` and `order` shortcode attributes. The settings page has common settings, or you can use any terms described for the [WP_Query orderby terms](http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for the shortcode.
@@ -149,6 +156,16 @@ You need to make sure that each image is the same height. You can do this by set
149
 
150
  == Changelog ==
151
 
 
 
 
 
 
 
 
 
 
 
152
  = 1.8.1 =
153
  * Bugfix. Apologies to anyone who ran into it and thanks to kylewhenderson for the spot.
154
 
3
  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: 4.2
7
+ Stable tag: 1.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
64
 
65
  = Credits =
66
 
67
+ This plugin was written by @tallphil with help and suggestions from several others including (but not limited to) @reddo, @joshgerdes, @atnon, @grahamharper, @rchq, @oheijo, @smtk, @cla63, @cookierebes and @sipman.
68
 
69
  The Serbo-Croation translation was kindly provided by Borisa Djuraskovic from http://www.webhostinghub.com
70
 
71
+ = Contributing =
72
+
73
+ If you would like to contribute to this plugin, please go to the [GitHub repository](https://github.com/ewels/cpt-bootstrap-carousel) and make a personal fork of the development version. You can then make your changes and submit a pull request. I will happily review the code and then merge when we're both happy. You can read more details [here](https://github.com/ewels/cpt-bootstrap-carousel/blob/master/CONTRIBUTING.md).
74
 
75
  == Installation ==
76
 
116
  Absolutely - you just need to use the [do_shortcode](http://codex.wordpress.org/Function_Reference/do_shortcode) WordPress function. For example:
117
  `<?php echo do_shortcode('[image-carousel]'); ?>`
118
 
119
+ = I get grey bars at the side of my images / The image isn't aligned (or doesn't reach the far side of the carousel) =
120
+
121
+ This happens when the carousel is bigger than your images. Either upload higher resolution images, or select the "Use background images?" option in the settings (this will stretch the images though, so they may get a little blurry).
122
+
123
  = Can I change the order that the images display in? =
124
 
125
  You can specify the order that the carousel displays images by changing the setting in the Settings page, or by using the `orderby` and `order` shortcode attributes. The settings page has common settings, or you can use any terms described for the [WP_Query orderby terms](http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters) for the shortcode.
156
 
157
  == Changelog ==
158
 
159
+ = 1.9 =
160
+ * Prevented the help tab from displaying on pages other than Carousel Items
161
+ * Made the output buffer cleaning only happen if we have images (thanks @ChrisLomax)
162
+ * Tidied up some warnings generated when WP_DEBUG was true
163
+ * New settings option to rely on data-attributes only, without any Javascript chunks
164
+ * Split the plugin into multiple files to make code easier to maintain
165
+ * Re-wrote the settings page to make things clearer
166
+ * Added new feature to have a link button instead of clickable slider image
167
+ * Bugfix: Carousel items with links using background images now work.
168
+
169
  = 1.8.1 =
170
  * Bugfix. Apologies to anyone who ran into it and thanks to kylewhenderson for the spot.
171